#ifndef _SYS_XENDEV_H
#define _SYS_XENDEV_H
#include <sys/hypervisor.h>
#include <sys/taskq.h>
#ifndef __xpv
#include <public/io/ring.h>
#include <public/event_channel.h>
#include <public/grant_table.h>
#endif
#include <xen/sys/xenbus_impl.h>
#ifdef __cplusplus
extern "C" {
#endif
#define XBP_HP_STATUS "hotplug-status"
#define XBV_HP_STATUS_CONN "connected"
#define XBP_DEV_TYPE "device-type"
#define XBV_DEV_TYPE_CD "cdrom"
#define XBP_SECTOR_SIZE "sector-size"
#define XBP_SECTORS "sectors"
#define XBP_INFO "info"
#define XBP_FB "feature-barrier"
#define XBP_RING_REF "ring-ref"
#define XBP_EVENT_CHAN "event-channel"
#define XBP_PROTOCOL "protocol"
#define XBP_MEDIA_REQ_SUP "media-req-sup"
#define XBP_MEDIA_REQ "media-req"
#define XBV_MEDIA_REQ_NONE "none"
#define XBV_MEDIA_REQ_LOCK "lock"
#define XBV_MEDIA_REQ_EJECT "eject"
typedef enum {
XEN_INVAL = -1,
XEN_CONSOLE = 0,
XEN_VNET,
XEN_VBLK,
XEN_XENBUS,
XEN_DOMCAPS,
XEN_BALLOON,
XEN_EVTCHN,
XEN_PRIVCMD,
XEN_BLKTAP,
XEN_LASTCLASS
} xendev_devclass_t;
typedef enum {
XEN_HP_ADD,
XEN_HP_REMOVE
} xendev_hotplug_cmd_t;
typedef enum {
Unrecognized,
Connected
} xendev_hotplug_state_t;
struct xendev_ppd {
kmutex_t xd_evt_lk;
int xd_evtchn;
struct intrspec xd_ispec;
xendev_devclass_t xd_devclass;
domid_t xd_domain;
int xd_vdevnum;
kmutex_t xd_ndi_lk;
struct xenbus_device xd_xsdev;
struct xenbus_watch xd_hp_watch;
struct xenbus_watch xd_bepath_watch;
ddi_callback_id_t xd_oe_ehid;
ddi_callback_id_t xd_hp_ehid;
ddi_taskq_t *xd_oe_taskq;
ddi_taskq_t *xd_hp_taskq;
ddi_taskq_t *xd_xb_watch_taskq;
list_t xd_xb_watches;
};
#define XS_OE_STATE "SUNW,xendev:otherend_state"
#define XS_HP_STATE "SUNW,xendev:hotplug_state"
#define VDEV_NOXS (-1)
void xendev_enum_class(dev_info_t *, xendev_devclass_t);
void xendev_enum_all(dev_info_t *, boolean_t);
xendev_devclass_t xendev_nodename_to_devclass(char *);
int xendev_devclass_ipl(xendev_devclass_t);
struct intrspec *xendev_get_ispec(dev_info_t *, uint_t);
void xvdi_suspend(dev_info_t *);
int xvdi_resume(dev_info_t *);
int xvdi_alloc_evtchn(dev_info_t *);
int xvdi_bind_evtchn(dev_info_t *, evtchn_port_t);
void xvdi_free_evtchn(dev_info_t *);
int xvdi_add_event_handler(dev_info_t *, char *,
void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *),
void *arg);
void xvdi_remove_event_handler(dev_info_t *, char *);
int xvdi_get_evtchn(dev_info_t *);
int xvdi_get_vdevnum(dev_info_t *);
char *xvdi_get_xsname(dev_info_t *);
char *xvdi_get_oename(dev_info_t *);
domid_t xvdi_get_oeid(dev_info_t *);
void xvdi_dev_error(dev_info_t *, int, char *);
void xvdi_fatal_error(dev_info_t *, int, char *);
void xvdi_notify_oe(dev_info_t *);
int xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t);
struct xenbus_device *xvdi_get_xsd(dev_info_t *);
int xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState);
dev_info_t *xvdi_create_dev(dev_info_t *, xendev_devclass_t,
domid_t, int);
int xvdi_init_dev(dev_info_t *);
void xvdi_uninit_dev(dev_info_t *);
dev_info_t *xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int);
extern int xvdi_add_xb_watch_handler(dev_info_t *, const char *,
const char *, xvdi_xb_watch_cb_t cb, void *);
extern void xvdi_remove_xb_watch_handlers(dev_info_t *);
#define SRINGPAD 48
typedef struct comif_sring {
RING_IDX req_prod, req_event;
RING_IDX rsp_prod, rsp_event;
uint8_t pad[SRINGPAD];
char ring[1];
} comif_sring_t;
typedef struct comif_ring_fe {
RING_IDX req_prod_pvt;
RING_IDX rsp_cons;
unsigned int nr_ents;
comif_sring_t *sring;
} comif_ring_fe_t;
typedef struct comif_ring_be {
RING_IDX rsp_prod_pvt;
RING_IDX req_cons;
unsigned int nr_ents;
comif_sring_t *sring;
} comif_ring_be_t;
typedef union comif_ring {
comif_ring_fe_t fr;
comif_ring_be_t br;
} comif_ring_t;
typedef struct xendev_req {
unsigned long next;
void *req;
} xendev_req_t;
typedef struct xendev_ring {
ddi_dma_handle_t xr_dma_hdl;
ddi_acc_handle_t xr_acc_hdl;
grant_handle_t xr_grant_hdl;
caddr_t xr_vaddr;
paddr_t xr_paddr;
grant_ref_t xr_gref;
int xr_entry_size;
int xr_frontend;
comif_ring_t xr_sring;
} xendev_ring_t;
int xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *,
xendev_ring_t **);
void xvdi_free_ring(xendev_ring_t *);
int xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t,
xendev_ring_t **);
void xvdi_unmap_ring(xendev_ring_t *);
uint_t xvdi_ring_avail_slots(xendev_ring_t *);
int xvdi_ring_has_unconsumed_requests(xendev_ring_t *);
int xvdi_ring_has_incomp_request(xendev_ring_t *);
int xvdi_ring_has_unconsumed_responses(xendev_ring_t *);
void* xvdi_ring_get_request(xendev_ring_t *);
int xvdi_ring_push_request(xendev_ring_t *);
void* xvdi_ring_get_response(xendev_ring_t *);
int xvdi_ring_push_response(xendev_ring_t *);
#ifdef __cplusplus
}
#endif
#endif