/* SPDX-License-Identifier: GPL-2.0-only */

#ifndef HABMM_H
#define HABMM_H

#include "linux/habmmid.h"

#define HAB_API_VER_DEF(_MAJOR_, _MINOR_) \
		((_MAJOR_&0xFF)<<16 | (_MINOR_&0xFFF))
#define HAB_API_VER	HAB_API_VER_DEF(1, 0)

#include <linux/types.h>




#define HABMM_SOCKET_OPEN_FLAGS_SINGLE_BE_SINGLE_FE        0x00000000

#define HABMM_SOCKET_OPEN_FLAGS_SINGLE_BE_SINGLE_DOMU      0x00000001

#define HABMM_SOCKET_OPEN_FLAGS_SINGLE_BE_MULTI_DOMUS      0x00000002


#define HABMM_SOCKET_OPEN_FLAGS_UNINTERRUPTIBLE 0x00000004
int32_t habmm_socket_open(int32_t *handle, uint32_t mm_ip_id,
		uint32_t timeout, uint32_t flags);



int32_t habmm_socket_close(int32_t handle);





#define HABMM_SOCKET_SEND_FLAGS_NON_BLOCKING 0x00000001


#define HABMM_SOCKET_SEND_FLAGS_XING_VM_STAT 0x00000002


#define HABMM_SOCKET_XVM_SCHE_TEST 0x00000004


#define HABMM_SOCKET_XVM_SCHE_TEST_ACK 0x00000008


#define HABMM_SOCKET_XVM_SCHE_RESULT_REQ 0x00000010


#define HABMM_SOCKET_XVM_SCHE_RESULT_RSP 0x00000020

struct habmm_xing_vm_stat {
	uint64_t tx_sec;
	uint64_t tx_usec;
	uint64_t rx_sec;
	uint64_t rx_usec;
};

int32_t habmm_socket_send(int32_t handle, void *src_buff, uint32_t size_bytes,
		uint32_t flags);





#define HABMM_SOCKET_RECV_FLAGS_NON_BLOCKING 0x00000001


#define HABMM_SOCKET_RECV_FLAGS_UNINTERRUPTIBLE 0x00000002


#define HABMM_SOCKET_RECV_FLAGS_TIMEOUT 0x00000004

int32_t habmm_socket_recv(int32_t handle, void *dst_buff, uint32_t *size_bytes,
		uint32_t timeout, uint32_t flags);


int32_t habmm_socket_sendto(int32_t handle, void *src_buff, uint32_t size_bytes,
		int32_t remote_handle, uint32_t flags);



int32_t habmm_socket_recvfrom(int32_t handle, void *dst_buff,
	uint32_t *size_bytes, uint32_t timeout,
	int32_t *remote_handle, uint32_t flags);


#define HABMM_EXP_MEM_TYPE_DMA 0x00000001


#define HABMM_EXPIMP_FLAGS_FD     0x00010000
#define HABMM_EXPIMP_FLAGS_DMABUF 0x00020000

#define HAB_MAX_EXPORT_SIZE 0x8000000


int32_t habmm_export(int32_t handle, void *buff_to_share, uint32_t size_bytes,
		uint32_t *export_id, uint32_t flags);


int32_t habmm_unexport(int32_t handle, uint32_t export_id, uint32_t flags);




#define HABMM_IMPORT_FLAGS_CACHED 0x00000001

int32_t habmm_import(int32_t handle, void **buff_shared, uint32_t size_bytes,
		uint32_t export_id, uint32_t flags);


int32_t habmm_unimport(int32_t handle, uint32_t export_id, void *buff_shared,
		uint32_t flags);


#define VMNAME_SIZE 12

struct hab_socket_info {
	int32_t vmid_remote; 
	int32_t vmid_local;
	
	char    vmname_remote[VMNAME_SIZE];
	char    vmname_local[VMNAME_SIZE];
};

int32_t habmm_socket_query(int32_t handle, struct hab_socket_info *info,
		uint32_t flags);

#endif 
