#ifndef _LDC_H
#define _LDC_H
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/ioctl.h>
#include <sys/processor.h>
#include <sys/ontrap.h>
typedef uint64_t ldc_handle_t;
typedef uint64_t ldc_mem_handle_t;
typedef uint64_t ldc_dring_handle_t;
typedef enum {
LDC_MODE_RAW,
LDC_MODE_UNRELIABLE,
_LDC_MODE_RESERVED_,
LDC_MODE_RELIABLE
} ldc_mode_t;
#define LDC_ELEM_SIZE 8
#define LDC_PACKET_SIZE (LDC_ELEM_SIZE * 8)
#define LDC_PAYLOAD_SIZE_RAW (LDC_PACKET_SIZE)
#define LDC_PAYLOAD_SIZE_UNRELIABLE (LDC_PACKET_SIZE - LDC_ELEM_SIZE)
#define LDC_PAYLOAD_SIZE_RELIABLE (LDC_PACKET_SIZE - (LDC_ELEM_SIZE * 2))
typedef enum {
LDC_INIT = 1,
LDC_OPEN,
LDC_READY,
LDC_UP
} ldc_status_t;
#define LDC_SUCCESS 0
#define LDC_FAILURE 1
typedef enum {
LDC_CB_ENABLE,
LDC_CB_DISABLE
} ldc_cb_mode_t;
#define LDC_EVT_DOWN 0x1
#define LDC_EVT_RESET 0x2
#define LDC_EVT_UP 0x4
#define LDC_EVT_READ 0x8
#define LDC_EVT_WRITE 0x10
typedef enum {
LDC_DEV_GENERIC = 1,
LDC_DEV_BLK,
LDC_DEV_BLK_SVC,
LDC_DEV_NT,
LDC_DEV_NT_SVC,
LDC_DEV_SERIAL
} ldc_dev_t;
typedef struct ldc_cnex {
dev_info_t *dip;
int (*reg_chan)();
int (*unreg_chan)();
int (*add_intr)();
int (*rem_intr)();
int (*clr_intr)();
} ldc_cnex_t;
typedef struct ldc_attr {
ldc_dev_t devclass;
uint64_t instance;
ldc_mode_t mode;
uint64_t mtu;
} ldc_attr_t;
typedef struct ldc_mem_cookie {
uint64_t addr;
uint64_t size;
} ldc_mem_cookie_t;
#define LDC_SHADOW_MAP 0x1
#define LDC_DIRECT_MAP 0x2
#define LDC_IO_MAP 0x4
#define LDC_DIRECT_MAP_SIZE_DEFAULT (64 * 1024 * 1024)
#define LDC_MEM_R 0x1
#define LDC_MEM_W 0x2
#define LDC_MEM_X 0x4
#define LDC_MEM_RW (LDC_MEM_R|LDC_MEM_W)
#define LDC_MEM_RWX (LDC_MEM_R|LDC_MEM_W|LDC_MEM_X)
#define LDC_COPY_IN 0x0
#define LDC_COPY_OUT 0x1
typedef enum {
LDC_UNBOUND,
LDC_BOUND,
LDC_MAPPED
} ldc_mstatus_t;
typedef struct ldc_mem_info {
uint8_t mtype;
uint8_t perm;
caddr_t vaddr;
uintptr_t raddr;
ldc_mstatus_t status;
} ldc_mem_info_t;
typedef struct ldc_info {
uint64_t direct_map_size_max;
} ldc_info_t;
int ldc_register(ldc_cnex_t *cinfo);
int ldc_unregister(ldc_cnex_t *cinfo);
int ldc_init(uint64_t id, ldc_attr_t *attr, ldc_handle_t *handle);
int ldc_fini(ldc_handle_t handle);
int ldc_open(ldc_handle_t handle);
int ldc_close(ldc_handle_t handle);
int ldc_up(ldc_handle_t handle);
int ldc_down(ldc_handle_t handle);
int ldc_reg_callback(ldc_handle_t handle,
uint_t(*callback)(uint64_t event, caddr_t arg), caddr_t arg);
int ldc_unreg_callback(ldc_handle_t handle);
int ldc_set_cb_mode(ldc_handle_t handle, ldc_cb_mode_t imode);
int ldc_chkq(ldc_handle_t handle, boolean_t *hasdata);
int ldc_read(ldc_handle_t handle, caddr_t buf, size_t *size);
int ldc_write(ldc_handle_t handle, caddr_t buf, size_t *size);
int ldc_status(ldc_handle_t handle, ldc_status_t *status);
int ldc_mem_alloc_handle(ldc_handle_t handle, ldc_mem_handle_t *mhandle);
int ldc_mem_free_handle(ldc_mem_handle_t mhandle);
int ldc_mem_bind_handle(ldc_mem_handle_t mhandle, caddr_t vaddr, size_t len,
uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *cookie, uint32_t *ccount);
int ldc_mem_unbind_handle(ldc_mem_handle_t mhandle);
int ldc_mem_info(ldc_mem_handle_t mhandle, ldc_mem_info_t *minfo);
int ldc_mem_nextcookie(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie);
int ldc_mem_copy(ldc_handle_t handle, caddr_t vaddr, uint64_t off, size_t *len,
ldc_mem_cookie_t *cookies, uint32_t ccount, uint8_t direction);
int ldc_mem_rdwr_cookie(ldc_handle_t handle, caddr_t vaddr, size_t *size,
caddr_t paddr, uint8_t direction);
int ldc_mem_map(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie,
uint32_t ccount, uint8_t mtype, uint8_t perm, caddr_t *vaddr,
caddr_t *raddr);
int ldc_mem_unmap(ldc_mem_handle_t mhandle);
int ldc_mem_acquire(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
int ldc_mem_release(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
int ldc_mem_dring_create(uint32_t len, uint32_t dsize,
ldc_dring_handle_t *dhandle);
int ldc_mem_dring_destroy(ldc_dring_handle_t dhandle);
int ldc_mem_dring_bind(ldc_handle_t handle, ldc_dring_handle_t dhandle,
uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *dcookie, uint32_t *ccount);
int ldc_mem_dring_nextcookie(ldc_dring_handle_t mhandle,
ldc_mem_cookie_t *cookie);
int ldc_mem_dring_unbind(ldc_dring_handle_t dhandle);
int ldc_mem_dring_info(ldc_dring_handle_t dhandle, ldc_mem_info_t *minfo);
int ldc_mem_dring_map(ldc_handle_t handle, ldc_mem_cookie_t *cookie,
uint32_t ccount, uint32_t len, uint32_t dsize, uint8_t mtype,
ldc_dring_handle_t *dhandle);
int ldc_mem_dring_unmap(ldc_dring_handle_t dhandle);
int ldc_mem_dring_acquire(ldc_dring_handle_t dhandle, uint64_t start,
uint64_t end);
int ldc_mem_dring_release(ldc_dring_handle_t dhandle, uint64_t start,
uint64_t end);
int ldc_info(ldc_handle_t handle, ldc_info_t *info);
#define LDC_ON_TRAP(otd) \
(on_trap((otd), OT_DATA_ACCESS) != 0 ? \
(no_trap(), EACCES) : 0)
#define LDC_NO_TRAP() \
(no_trap(), 0)
#ifdef __cplusplus
}
#endif
#endif