#ifndef _SYS_USB_XHCI_XHCI_H
#define _SYS_USB_XHCI_XHCI_H
#include <sys/conf.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/taskq_impl.h>
#include <sys/sysmacros.h>
#include <sys/usb/hcd/xhci/xhcireg.h>
#include <sys/usb/usba.h>
#include <sys/usb/usba/hcdi.h>
#include <sys/usb/hubd/hub.h>
#include <sys/usb/usba/hubdi.h>
#include <sys/usb/hubd/hubdvar.h>
#ifdef __cplusplus
extern "C" {
#endif
#define XHCI_TRB_MAX_TRANSFER 65536
#define XHCI_DMA_ALIGN 64
#define XHCI_DEF_DMA_SGL 1
#define XHCI_TRANSFER_DMA_SGL 63
#define XHCI_MAX_TRANSFER 524288
#define XHCI_PROP_REROUTE_DISABLE 0
#define XHCI_PROP_REROUTE_DEFAULT 1
#define XHCI_ISOC_MAX_TRB 64
#ifdef DEBUG
#define XHCI_DMA_SYNC(dma, flag) VERIFY0(ddi_dma_sync( \
(dma).xdb_dma_handle, 0, 0, \
(flag)))
#else
#define XHCI_DMA_SYNC(dma, flag) ((void) ddi_dma_sync( \
(dma).xdb_dma_handle, 0, 0, \
(flag)))
#endif
#define XHCI_MAX_TDSIZE 31
#define XHCI_POWER_GOOD 10
#define XHCI_NINTR 1
#define XHCI_IMOD_DEFAULT 0x000003F8U
#define XHCI_CONTEXT_DEF_CERR 3
#define XHCI_CONTEXT_ISOCH_CERR 0
#define XHCI_CONTEXT_MPS_MASK 0x07ff
#define XHCI_CONTEXT_BURST_MASK 0x1800
#define XHCI_CONTEXT_BURST_SHIFT 11
#define XHCI_CONTEXT_DEF_MULT 0
#define XHCI_CONTEXT_DEF_MAX_ESIT 0
#define XHCI_CONTEXT_DEF_CTRL_ATL 8
#define XHCI_INTR_IN_NTRANSFERS 8
#define XHCI_ISOC_IN_NTRANSFERS 2
#define XHCI_PERIODIC_IN_NTRANSFERS \
MAX(XHCI_ISOC_IN_NTRANSFERS, XHCI_INTR_IN_NTRANSFERS)
#define XHCI_ROUTE_MASK(x) ((x) & 0xfffff)
#define XHCI_TICK_TIMEOUT_US (MICROSEC)
#define XHCI_HUB_INTR_CHANGE_MASK (XHCI_PS_CSC | XHCI_PS_PEC | \
XHCI_PS_WRC | XHCI_PS_OCC | XHCI_PS_PRC | XHCI_PS_PLC | XHCI_PS_CEC)
typedef enum xhci_quirk {
XHCI_QUIRK_NO_MSI = 0x01,
XHCI_QUIRK_32_ONLY = 0x02,
XHCI_QUIRK_INTC_EHCI = 0x04
} xhci_quirk_t;
typedef enum xhci_cap_flags {
XCAP_AC64 = 0x001,
XCAP_BNC = 0x002,
XCAP_CSZ = 0x004,
XCAP_PPC = 0x008,
XCAP_PIND = 0x010,
XCAP_LHRC = 0x020,
XCAP_LTC = 0x040,
XCAP_NSS = 0x080,
XCAP_PAE = 0x100,
XCAP_SPC = 0x200,
XCAP_SEC = 0x400,
XCAP_CFC = 0x800
} xchi_cap_flags_t;
typedef enum xhci_cap2_flags {
XCAP2_U3C = 0x01,
XCAP2_CMC = 0x02,
XCAP2_FMC = 0x04,
XCAP2_CTC = 0x08,
XCAP2_LEC = 0x10,
XCAP2_CIC = 0x20
} xhci_cap2_flags_t;
typedef struct xhci_capability {
uint8_t xcap_usb_vers;
uint16_t xcap_hci_vers;
uint32_t xcap_pagesize;
uint8_t xcap_max_slots;
uint16_t xcap_max_intrs;
uint8_t xcap_max_ports;
boolean_t xcap_ist_micro;
uint8_t xcap_ist;
uint16_t xcap_max_esrt;
boolean_t xcap_scratch_restore;
uint16_t xcap_max_scratch;
uint8_t xcap_u1_lat;
uint16_t xcap_u2_lat;
xchi_cap_flags_t xcap_flags;
uint8_t xcap_max_psa;
uint16_t xcap_xecp_off;
xhci_cap2_flags_t xcap_flags2;
int xcap_intr_types;
} xhci_capability_t;
typedef struct xhci_dma_buffer {
caddr_t xdb_va;
size_t xdb_len;
ddi_acc_handle_t xdb_acc_handle;
ddi_dma_handle_t xdb_dma_handle;
int xdb_ncookies;
ddi_dma_cookie_t xdb_cookies[XHCI_TRANSFER_DMA_SGL];
} xhci_dma_buffer_t;
#pragma pack(1)
typedef struct xhci_trb {
uint64_t trb_addr;
uint32_t trb_status;
uint32_t trb_flags;
} xhci_trb_t;
#pragma pack()
typedef struct xhci_transfer {
list_node_t xt_link;
hrtime_t xt_sched_time;
xhci_dma_buffer_t xt_buffer;
uint_t xt_ntrbs;
uint_t xt_short;
uint_t xt_timeout;
usb_cr_t xt_cr;
boolean_t xt_data_tohost;
xhci_trb_t *xt_trbs;
uint64_t *xt_trbs_pa;
usb_isoc_pkt_descr_t *xt_isoc;
usb_opaque_t xt_usba_req;
} xhci_transfer_t;
#define XHCI_IS_ONESHOT_XFER(xt) ((xt)->xt_usba_req != NULL)
typedef struct xhci_ring {
xhci_dma_buffer_t xr_dma;
uint_t xr_ntrb;
xhci_trb_t *xr_trb;
uint_t xr_head;
uint_t xr_tail;
uint8_t xr_cycle;
} xhci_ring_t;
#define XHCI_MAX_SLOTS 256
#define XHCI_DCBAA_SCRATCHPAD_INDEX 0
typedef struct xhci_dcbaa {
uint64_t *xdc_base_addrs;
xhci_dma_buffer_t xdc_dma;
} xhci_dcbaa_t;
typedef struct xhci_scratchpad {
uint64_t *xsp_addrs;
xhci_dma_buffer_t xsp_addr_dma;
xhci_dma_buffer_t *xsp_scratch_dma;
} xhci_scratchpad_t;
#define XHCI_DEVICE_CONTEXT_32 1024
#define XHCI_DEVICE_CONTEXT_64 2048
#define XHCI_NUM_ENDPOINTS 31
#define XHCI_DEFAULT_ENDPOINT 0
#pragma pack(1)
typedef struct xhci_slot_context {
uint32_t xsc_info;
uint32_t xsc_info2;
uint32_t xsc_tt;
uint32_t xsc_state;
uint32_t xsc_reserved[4];
} xhci_slot_context_t;
typedef struct xhci_endpoint_context {
uint32_t xec_info;
uint32_t xec_info2;
uint64_t xec_dequeue;
uint32_t xec_txinfo;
uint32_t xec_reserved[3];
} xhci_endpoint_context_t;
typedef struct xhci_input_context {
uint32_t xic_drop_flags;
uint32_t xic_add_flags;
uint32_t xic_reserved[6];
} xhci_input_context_t;
#pragma pack()
#define XHCI_EVENT_NSEGS 1
#pragma pack(1)
typedef struct xhci_event_segment {
uint64_t xes_addr;
uint16_t xes_size;
uint16_t xes_rsvd0;
uint32_t xes_rsvd1;
} xhci_event_segment_t;
#pragma pack()
typedef struct xhci_event_ring {
xhci_event_segment_t *xev_segs;
xhci_dma_buffer_t xev_dma;
xhci_ring_t xev_ring;
} xhci_event_ring_t;
typedef enum xhci_command_ring_state {
XHCI_COMMAND_RING_IDLE = 0x00,
XHCI_COMMAND_RING_RUNNING = 0x01,
XHCI_COMMAND_RING_ABORTING = 0x02,
XHCI_COMMAND_RING_ABORT_DONE = 0x03
} xhci_command_ring_state_t;
typedef struct xhci_command_ring {
xhci_ring_t xcr_ring;
kmutex_t xcr_lock;
kcondvar_t xcr_cv;
list_t xcr_commands;
timeout_id_t xcr_timeout;
xhci_command_ring_state_t xcr_state;
} xhci_command_ring_t;
typedef enum xhci_command_state {
XHCI_COMMAND_S_INIT = 0x00,
XHCI_COMMAND_S_QUEUED = 0x01,
XHCI_COMMAND_S_RECEIVED = 0x02,
XHCI_COMMAND_S_DONE = 0x03,
XHCI_COMMAND_S_RESET = 0x04
} xhci_command_state_t;
typedef struct xhci_command {
list_node_t xco_link;
kcondvar_t xco_cv;
xhci_trb_t xco_req;
xhci_trb_t xco_res;
xhci_command_state_t xco_state;
} xhci_command_t;
typedef enum xhci_endpoint_state {
XHCI_ENDPOINT_PERIODIC = 0x01,
XHCI_ENDPOINT_HALTED = 0x02,
XHCI_ENDPOINT_QUIESCE = 0x04,
XHCI_ENDPOINT_TIMED_OUT = 0x08,
XHCI_ENDPOINT_TEARDOWN = 0x10,
XHCI_ENDPOINT_POLLED = 0x20,
XHCI_ENDPOINT_OPEN = 0x40,
} xhci_endpoint_state_t;
#define XHCI_ENDPOINT_SERIALIZE (XHCI_ENDPOINT_QUIESCE | \
XHCI_ENDPOINT_TIMED_OUT)
#define XHCI_ENDPOINT_DONT_SCHEDULE (XHCI_ENDPOINT_HALTED | \
XHCI_ENDPOINT_QUIESCE | \
XHCI_ENDPOINT_TIMED_OUT)
struct xhci_device;
struct xhci;
typedef struct xhci_endpoint_params {
boolean_t xepp_configured;
uint_t xepp_eptype;
uint_t xepp_burst;
uint_t xepp_ival;
uint_t xepp_max_esit;
uint_t xepp_avgtrb;
uint_t xepp_mps;
uint_t xepp_mult;
uint_t xepp_cerr;
} xhci_endpoint_params_t;
typedef struct xhci_endpoint {
struct xhci *xep_xhci;
struct xhci_device *xep_xd;
uint_t xep_num;
uint_t xep_type;
xhci_endpoint_state_t xep_state;
kcondvar_t xep_state_cv;
timeout_id_t xep_timeout;
list_t xep_transfers;
usba_pipe_handle_data_t *xep_pipe;
xhci_ring_t xep_ring;
xhci_endpoint_params_t xep_params;
} xhci_endpoint_t;
typedef struct xhci_device {
list_node_t xd_link;
usb_port_t xd_port;
uint8_t xd_slot;
boolean_t xd_addressed;
usba_device_t *xd_usbdev;
xhci_dma_buffer_t xd_ictx;
kmutex_t xd_imtx;
xhci_input_context_t *xd_input;
xhci_slot_context_t *xd_slotin;
xhci_endpoint_context_t *xd_endin[XHCI_NUM_ENDPOINTS];
xhci_dma_buffer_t xd_octx;
xhci_slot_context_t *xd_slotout;
xhci_endpoint_context_t *xd_endout[XHCI_NUM_ENDPOINTS];
xhci_endpoint_t *xd_endpoints[XHCI_NUM_ENDPOINTS];
} xhci_device_t;
typedef enum xhci_periodic_state {
XHCI_PERIODIC_POLL_IDLE = 0x0,
XHCI_PERIODIC_POLL_ACTIVE,
XHCI_PERIODIC_POLL_NOMEM,
XHCI_PERIODIC_POLL_STOPPING
} xhci_periodic_state_t;
typedef struct xhci_periodic_pipe {
xhci_periodic_state_t xpp_poll_state;
usb_opaque_t xpp_usb_req;
size_t xpp_tsize;
uint_t xpp_ntransfers;
xhci_transfer_t *xpp_transfers[XHCI_PERIODIC_IN_NTRANSFERS];
} xhci_periodic_pipe_t;
typedef struct xhci_pipe {
list_node_t xp_link;
hrtime_t xp_opentime;
usba_pipe_handle_data_t *xp_pipe;
xhci_endpoint_t *xp_ep;
xhci_periodic_pipe_t xp_periodic;
} xhci_pipe_t;
typedef struct xhci_usba {
usba_hcdi_ops_t *xa_ops;
ddi_dma_attr_t xa_dma_attr;
usb_dev_descr_t xa_dev_descr;
usb_ss_hub_descr_t xa_hub_descr;
usba_pipe_handle_data_t *xa_intr_cb_ph;
usb_intr_req_t *xa_intr_cb_req;
list_t xa_devices;
list_t xa_pipes;
} xhci_usba_t;
typedef enum xhci_attach_seq {
XHCI_ATTACH_FM = 0x1 << 0,
XHCI_ATTACH_PCI_CONFIG = 0x1 << 1,
XHCI_ATTACH_REGS_MAP = 0x1 << 2,
XHCI_ATTACH_INTR_ALLOC = 0x1 << 3,
XHCI_ATTACH_INTR_ADD = 0x1 << 4,
XHCI_ATTACH_SYNCH = 0x1 << 5,
XHCI_ATTACH_INTR_ENABLE = 0x1 << 6,
XHCI_ATTACH_STARTED = 0x1 << 7,
XHCI_ATTACH_USBA = 0x1 << 8,
XHCI_ATTACH_ROOT_HUB = 0x1 << 9
} xhci_attach_seq_t;
typedef enum xhci_state_flags {
XHCI_S_ERROR = 0x1 << 0
} xhci_state_flags_t;
typedef struct xhci {
dev_info_t *xhci_dip;
xhci_attach_seq_t xhci_seq;
int xhci_fm_caps;
ddi_acc_handle_t xhci_cfg_handle;
uint16_t xhci_vendor_id;
uint16_t xhci_device_id;
caddr_t xhci_regs_base;
ddi_acc_handle_t xhci_regs_handle;
uint_t xhci_regs_capoff;
uint_t xhci_regs_operoff;
uint_t xhci_regs_runoff;
uint_t xhci_regs_dooroff;
xhci_capability_t xhci_caps;
xhci_quirk_t xhci_quirks;
ddi_intr_handle_t xhci_intr_hdl;
int xhci_intr_num;
int xhci_intr_type;
uint_t xhci_intr_pri;
int xhci_intr_caps;
xhci_dcbaa_t xhci_dcbaa;
xhci_scratchpad_t xhci_scratchpad;
xhci_command_ring_t xhci_command;
xhci_event_ring_t xhci_event;
taskq_ent_t xhci_tqe;
kmutex_t xhci_lock;
kcondvar_t xhci_statecv;
xhci_state_flags_t xhci_state;
xhci_usba_t xhci_usba;
} xhci_t;
typedef enum xhci_reg_type {
XHCI_R_CAP,
XHCI_R_OPER,
XHCI_R_RUN,
XHCI_R_DOOR
} xhci_reg_type_t;
typedef struct xhci_polled {
xhci_t *xhci_polled_xhci;
usba_pipe_handle_data_t *xhci_polled_input_pipe_handle;
xhci_endpoint_t *xhci_polled_endpoint;
uchar_t xhci_polled_buf[8];
uint_t xhci_polled_entry;
int xhci_polled_persistent_error;
} xhci_polled_t;
extern xhci_t *xhci_hcdi_get_xhcip_from_dev(usba_device_t *);
extern xhci_device_t *xhci_device_lookup_by_slot(xhci_t *, int);
extern void xhci_quirks_populate(xhci_t *);
extern void xhci_reroute_intel(xhci_t *);
extern uint_t xhci_intr(caddr_t, caddr_t);
extern boolean_t xhci_ddi_intr_disable(xhci_t *);
extern boolean_t xhci_ddi_intr_enable(xhci_t *);
extern int xhci_intr_conf(xhci_t *);
extern int xhci_check_dma_handle(xhci_t *, xhci_dma_buffer_t *);
extern void xhci_dma_acc_attr(xhci_t *, ddi_device_acc_attr_t *);
extern void xhci_dma_dma_attr(xhci_t *, ddi_dma_attr_t *);
extern void xhci_dma_scratchpad_attr(xhci_t *, ddi_dma_attr_t *);
extern void xhci_dma_transfer_attr(xhci_t *, ddi_dma_attr_t *, uint_t);
extern void xhci_dma_free(xhci_dma_buffer_t *);
extern boolean_t xhci_dma_alloc(xhci_t *, xhci_dma_buffer_t *, ddi_dma_attr_t *,
ddi_device_acc_attr_t *, boolean_t, size_t, boolean_t);
extern uint64_t xhci_dma_pa(xhci_dma_buffer_t *);
extern xhci_transfer_t *xhci_transfer_alloc(xhci_t *, xhci_endpoint_t *, size_t,
uint_t, int);
extern void xhci_transfer_free(xhci_t *, xhci_transfer_t *);
extern void xhci_transfer_copy(xhci_transfer_t *, void *, size_t, boolean_t);
extern int xhci_transfer_sync(xhci_t *, xhci_transfer_t *, uint_t);
extern void xhci_transfer_trb_fill_data(xhci_endpoint_t *, xhci_transfer_t *,
int, boolean_t);
extern void xhci_transfer_calculate_isoc(xhci_device_t *, xhci_endpoint_t *,
uint_t, uint_t *, uint_t *);
extern int xhci_context_init(xhci_t *);
extern void xhci_context_fini(xhci_t *);
extern boolean_t xhci_context_slot_output_init(xhci_t *, xhci_device_t *);
extern void xhci_context_slot_output_fini(xhci_t *, xhci_device_t *);
extern int xhci_command_ring_init(xhci_t *);
extern void xhci_command_ring_fini(xhci_t *);
extern boolean_t xhci_command_event_callback(xhci_t *, xhci_trb_t *trb);
extern void xhci_command_init(xhci_command_t *);
extern void xhci_command_fini(xhci_command_t *);
extern int xhci_command_enable_slot(xhci_t *, uint8_t *);
extern int xhci_command_disable_slot(xhci_t *, uint8_t);
extern int xhci_command_set_address(xhci_t *, xhci_device_t *, boolean_t);
extern int xhci_command_configure_endpoint(xhci_t *, xhci_device_t *);
extern int xhci_command_evaluate_context(xhci_t *, xhci_device_t *);
extern int xhci_command_reset_endpoint(xhci_t *, xhci_device_t *,
xhci_endpoint_t *);
extern int xhci_command_set_tr_dequeue(xhci_t *, xhci_device_t *,
xhci_endpoint_t *);
extern int xhci_command_stop_endpoint(xhci_t *, xhci_device_t *,
xhci_endpoint_t *);
extern int xhci_event_init(xhci_t *);
extern void xhci_event_fini(xhci_t *);
extern boolean_t xhci_event_process_trb(xhci_t *, xhci_trb_t *);
extern boolean_t xhci_event_process(xhci_t *);
extern void xhci_ring_free(xhci_ring_t *);
extern int xhci_ring_reset(xhci_t *, xhci_ring_t *);
extern int xhci_ring_alloc(xhci_t *, xhci_ring_t *);
extern xhci_trb_t *xhci_ring_event_advance(xhci_ring_t *);
extern boolean_t xhci_ring_trb_tail_valid(xhci_ring_t *, uint64_t);
extern int xhci_ring_trb_valid_range(xhci_ring_t *, uint64_t, uint_t);
extern boolean_t xhci_ring_trb_space(xhci_ring_t *, uint_t);
extern void xhci_ring_trb_fill(xhci_ring_t *, uint_t, xhci_trb_t *, uint64_t *,
boolean_t);
extern void xhci_ring_trb_produce(xhci_ring_t *, uint_t);
extern boolean_t xhci_ring_trb_consumed(xhci_ring_t *, uint64_t);
extern void xhci_ring_trb_put(xhci_ring_t *, xhci_trb_t *);
extern void xhci_ring_skip(xhci_ring_t *);
extern void xhci_ring_skip_transfer(xhci_ring_t *, xhci_transfer_t *);
extern int xhci_check_regs_acc(xhci_t *);
extern uint8_t xhci_get8(xhci_t *, xhci_reg_type_t, uintptr_t);
extern uint16_t xhci_get16(xhci_t *, xhci_reg_type_t, uintptr_t);
extern uint32_t xhci_get32(xhci_t *, xhci_reg_type_t, uintptr_t);
extern uint64_t xhci_get64(xhci_t *, xhci_reg_type_t, uintptr_t);
extern void xhci_put8(xhci_t *, xhci_reg_type_t, uintptr_t, uint8_t);
extern void xhci_put16(xhci_t *, xhci_reg_type_t, uintptr_t, uint16_t);
extern void xhci_put32(xhci_t *, xhci_reg_type_t, uintptr_t, uint32_t);
extern void xhci_put64(xhci_t *, xhci_reg_type_t, uintptr_t, uint64_t);
extern void xhci_fm_runtime_reset(xhci_t *);
extern int xhci_endpoint_init(xhci_t *, xhci_device_t *,
usba_pipe_handle_data_t *);
extern int xhci_endpoint_reopen(xhci_t *, xhci_device_t *,
xhci_endpoint_t *, usba_pipe_handle_data_t *);
extern void xhci_endpoint_close(xhci_t *, xhci_endpoint_t *);
extern int xhci_endpoint_unconfigure(xhci_t *, xhci_device_t *,
xhci_endpoint_t *);
extern void xhci_endpoint_fini(xhci_device_t *, int);
extern int xhci_endpoint_update_default(xhci_t *, xhci_device_t *,
xhci_endpoint_t *);
extern void xhci_endpoint_timeout_cancel(xhci_t *, xhci_endpoint_t *);
extern int xhci_endpoint_setup_default_context(xhci_t *, xhci_device_t *,
xhci_endpoint_t *);
extern uint_t xhci_endpoint_pipe_to_epid(usba_pipe_handle_data_t *);
extern boolean_t xhci_endpoint_is_periodic_in(xhci_endpoint_t *);
extern void xhci_endpoint_serialize(xhci_t *, xhci_endpoint_t *);
extern int xhci_endpoint_quiesce(xhci_t *, xhci_device_t *, xhci_endpoint_t *);
extern int xhci_endpoint_schedule(xhci_t *, xhci_device_t *, xhci_endpoint_t *,
xhci_transfer_t *, boolean_t);
extern int xhci_endpoint_ring(xhci_t *, xhci_device_t *, xhci_endpoint_t *);
extern boolean_t xhci_endpoint_transfer_callback(xhci_t *, xhci_trb_t *);
extern xhci_transfer_t *xhci_endpoint_determine_transfer(xhci_t *,
xhci_endpoint_t *, xhci_trb_t *, uint_t *);
extern int xhci_hcd_init(xhci_t *);
extern void xhci_hcd_fini(xhci_t *);
extern int xhci_root_hub_init(xhci_t *);
extern int xhci_root_hub_fini(xhci_t *);
extern int xhci_root_hub_ctrl_req(xhci_t *, usba_pipe_handle_data_t *,
usb_ctrl_req_t *);
extern void xhci_root_hub_psc_callback(xhci_t *);
extern int xhci_root_hub_intr_root_enable(xhci_t *, usba_pipe_handle_data_t *,
usb_intr_req_t *);
extern void xhci_root_hub_intr_root_disable(xhci_t *);
extern int xhci_hcdi_console_input_init(usba_pipe_handle_data_t *, uchar_t **,
usb_console_info_impl_t *);
extern int xhci_hcdi_console_input_fini(usb_console_info_impl_t *);
extern int xhci_hcdi_console_input_enter(usb_console_info_impl_t *);
extern int xhci_hcdi_console_read(usb_console_info_impl_t *, uint_t *);
extern int xhci_hcdi_console_input_exit(usb_console_info_impl_t *);
extern int xhci_hcdi_console_output_init(usba_pipe_handle_data_t *,
usb_console_info_impl_t *);
extern int xhci_hcdi_console_output_fini(usb_console_info_impl_t *);
extern int xhci_hcdi_console_output_enter(usb_console_info_impl_t *);
extern int xhci_hcdi_console_write(usb_console_info_impl_t *, uchar_t *,
uint_t, uint_t *);
extern int xhci_hcdi_console_output_exit(usb_console_info_impl_t *);
extern void xhci_log(xhci_t *xhcip, const char *fmt, ...) __KPRINTFLIKE(2);
extern void xhci_error(xhci_t *xhcip, const char *fmt, ...) __KPRINTFLIKE(2);
extern void *xhci_soft_state;
#ifdef __cplusplus
}
#endif
#endif