15084Sjohnlev /* 25084Sjohnlev * CDDL HEADER START 35084Sjohnlev * 45084Sjohnlev * The contents of this file are subject to the terms of the 55084Sjohnlev * Common Development and Distribution License (the "License"). 65084Sjohnlev * You may not use this file except in compliance with the License. 75084Sjohnlev * 85084Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95084Sjohnlev * or http://www.opensolaris.org/os/licensing. 105084Sjohnlev * See the License for the specific language governing permissions 115084Sjohnlev * and limitations under the License. 125084Sjohnlev * 135084Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each 145084Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155084Sjohnlev * If applicable, add the following below this CDDL HEADER, with the 165084Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying 175084Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner] 185084Sjohnlev * 195084Sjohnlev * CDDL HEADER END 205084Sjohnlev */ 215084Sjohnlev 225084Sjohnlev /* 23*8863SEdward.Pilatowicz@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 245084Sjohnlev * Use is subject to license terms. 255084Sjohnlev */ 265084Sjohnlev 275084Sjohnlev #ifndef _SYS_XENDEV_H 285084Sjohnlev #define _SYS_XENDEV_H 295084Sjohnlev 305084Sjohnlev 315084Sjohnlev #include <sys/hypervisor.h> 325084Sjohnlev #include <sys/taskq.h> 335741Smrj #ifdef XPV_HVM_DRIVER 345741Smrj #include <public/io/ring.h> 355741Smrj #include <public/event_channel.h> 365741Smrj #include <public/grant_table.h> 375741Smrj #endif 385084Sjohnlev #include <xen/sys/xenbus_impl.h> 395084Sjohnlev 405084Sjohnlev #ifdef __cplusplus 415084Sjohnlev extern "C" { 425084Sjohnlev #endif 435084Sjohnlev 445084Sjohnlev /* 45*8863SEdward.Pilatowicz@Sun.COM * Xenbus property interfaces, initialized by framework 46*8863SEdward.Pilatowicz@Sun.COM */ 47*8863SEdward.Pilatowicz@Sun.COM #define XBP_HP_STATUS "hotplug-status" /* backend prop: str */ 48*8863SEdward.Pilatowicz@Sun.COM #define XBV_HP_STATUS_CONN "connected" /* backend prop val */ 49*8863SEdward.Pilatowicz@Sun.COM #define XBP_DEV_TYPE "device-type" /* backend prop: str */ 50*8863SEdward.Pilatowicz@Sun.COM #define XBV_DEV_TYPE_CD "cdrom" /* backend prop val */ 51*8863SEdward.Pilatowicz@Sun.COM 52*8863SEdward.Pilatowicz@Sun.COM /* 53*8863SEdward.Pilatowicz@Sun.COM * Xenbus property interfaces, initialized by backend disk driver 54*8863SEdward.Pilatowicz@Sun.COM */ 55*8863SEdward.Pilatowicz@Sun.COM #define XBP_SECTORS "sectors" /* backend prop: uint64 */ 56*8863SEdward.Pilatowicz@Sun.COM #define XBP_INFO "info" /* backend prop: uint */ 57*8863SEdward.Pilatowicz@Sun.COM #define XBP_FB "feature-barrier" /* backend prop: boolean int */ 58*8863SEdward.Pilatowicz@Sun.COM 59*8863SEdward.Pilatowicz@Sun.COM /* 60*8863SEdward.Pilatowicz@Sun.COM * Xenbus property interfaces, initialized by frontend disk driver 61*8863SEdward.Pilatowicz@Sun.COM */ 62*8863SEdward.Pilatowicz@Sun.COM #define XBP_RING_REF "ring-ref" /* frontend prop: long */ 63*8863SEdward.Pilatowicz@Sun.COM #define XBP_EVENT_CHAN "event-channel" /* frontend prop: long */ 64*8863SEdward.Pilatowicz@Sun.COM #define XBP_PROTOCOL "protocol" /* frontend prop: string */ 65*8863SEdward.Pilatowicz@Sun.COM 66*8863SEdward.Pilatowicz@Sun.COM /* 67*8863SEdward.Pilatowicz@Sun.COM * Xenbus CDROM property interfaces, used by backend and frontend 68*8863SEdward.Pilatowicz@Sun.COM * 69*8863SEdward.Pilatowicz@Sun.COM * XBP_MEDIA_REQ_SUP 70*8863SEdward.Pilatowicz@Sun.COM * - Backend xenbus property located at: 71*8863SEdward.Pilatowicz@Sun.COM * backend/vbd/<domU_id>/<domU_dev>/media-req-sup 72*8863SEdward.Pilatowicz@Sun.COM * - Set by the backend, consumed by the frontend. 73*8863SEdward.Pilatowicz@Sun.COM * - Cosumed by the frontend. 74*8863SEdward.Pilatowicz@Sun.COM * - A boolean integer property indicating backend support 75*8863SEdward.Pilatowicz@Sun.COM * for the XBP_MEDIA_REQ property. 76*8863SEdward.Pilatowicz@Sun.COM * 77*8863SEdward.Pilatowicz@Sun.COM * XBP_MEDIA_REQ 78*8863SEdward.Pilatowicz@Sun.COM * - Frontend xenbus property located at: 79*8863SEdward.Pilatowicz@Sun.COM * /local/domain/<domU_id>/device/vbd/<domU_dev>/media-req 80*8863SEdward.Pilatowicz@Sun.COM * - Set and consumed by both the frontend and backend. 81*8863SEdward.Pilatowicz@Sun.COM * - Possible values: 82*8863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_NONE, XBV_MEDIA_REQ_LOCK, and XBV_MEDIA_REQ_EJECT 83*8863SEdward.Pilatowicz@Sun.COM * - Only applies to CDROM devices. 84*8863SEdward.Pilatowicz@Sun.COM * 85*8863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_NONE 86*8863SEdward.Pilatowicz@Sun.COM * - XBP_MEDIA_REQ property valud 87*8863SEdward.Pilatowicz@Sun.COM * - Set and consumed by both the frontend and backend. 88*8863SEdward.Pilatowicz@Sun.COM * - Indicates that there are no currently outstanding media requet 89*8863SEdward.Pilatowicz@Sun.COM * operations. 90*8863SEdward.Pilatowicz@Sun.COM * 91*8863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_LOCK 92*8863SEdward.Pilatowicz@Sun.COM * - XBP_MEDIA_REQ property valud 93*8863SEdward.Pilatowicz@Sun.COM * - Set by the frontend, consumed by the backend. 94*8863SEdward.Pilatowicz@Sun.COM * - Indicates to the backend that the currenct media is locked 95*8863SEdward.Pilatowicz@Sun.COM * and changes to the media (via xm block-configure for example) 96*8863SEdward.Pilatowicz@Sun.COM * should not be allowed. 97*8863SEdward.Pilatowicz@Sun.COM * 98*8863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_EJECT 99*8863SEdward.Pilatowicz@Sun.COM * - XBP_MEDIA_REQ property valud 100*8863SEdward.Pilatowicz@Sun.COM * - Set by the frontend, consumed by the backend. 101*8863SEdward.Pilatowicz@Sun.COM * - Indicates to the backend that the currenct media should be ejected. 102*8863SEdward.Pilatowicz@Sun.COM * This means that the backend should close it's connection to 103*8863SEdward.Pilatowicz@Sun.COM * the frontend device, close it's current backing store device/file, 104*8863SEdward.Pilatowicz@Sun.COM * and then set the media-req property to XBV_MEDIA_REQ_NONE. (to 105*8863SEdward.Pilatowicz@Sun.COM * indicate that the eject operation is complete.) 106*8863SEdward.Pilatowicz@Sun.COM */ 107*8863SEdward.Pilatowicz@Sun.COM #define XBP_MEDIA_REQ_SUP "media-req-sup" /* backend prop: boolean int */ 108*8863SEdward.Pilatowicz@Sun.COM #define XBP_MEDIA_REQ "media-req" /* frontend prop: str */ 109*8863SEdward.Pilatowicz@Sun.COM #define XBV_MEDIA_REQ_NONE "none" /* frontend prop val */ 110*8863SEdward.Pilatowicz@Sun.COM #define XBV_MEDIA_REQ_LOCK "lock" /* frontend prop val */ 111*8863SEdward.Pilatowicz@Sun.COM #define XBV_MEDIA_REQ_EJECT "eject" /* frontend prop val */ 112*8863SEdward.Pilatowicz@Sun.COM 113*8863SEdward.Pilatowicz@Sun.COM /* 1145084Sjohnlev * Xen device class codes 1155084Sjohnlev */ 1165084Sjohnlev typedef enum { 1175084Sjohnlev XEN_INVAL = -1, 1185084Sjohnlev XEN_CONSOLE = 0, 1195084Sjohnlev XEN_VNET, 1205084Sjohnlev XEN_VBLK, 1215084Sjohnlev XEN_XENBUS, 1225084Sjohnlev XEN_DOMCAPS, 1235084Sjohnlev XEN_BALLOON, 1245084Sjohnlev XEN_EVTCHN, 1255084Sjohnlev XEN_PRIVCMD, 1267756SMark.Johnson@Sun.COM XEN_BLKTAP, 1275084Sjohnlev XEN_LASTCLASS 1285084Sjohnlev } xendev_devclass_t; 1295084Sjohnlev 1305084Sjohnlev /* 1315084Sjohnlev * Hotplug request sent to userland event handler. 1325084Sjohnlev */ 1335084Sjohnlev typedef enum { 1345084Sjohnlev XEN_HP_ADD, 1355084Sjohnlev XEN_HP_REMOVE 1365084Sjohnlev } xendev_hotplug_cmd_t; 1375084Sjohnlev 1385084Sjohnlev /* 1395084Sjohnlev * Hotplug status. 1405084Sjohnlev * 1415084Sjohnlev * In fact, the Xen tools can write any arbitrary string into the 1425084Sjohnlev * hotplug-status node. We represent the known values here - anything 1435084Sjohnlev * else will be 'Unrecognized'. 1445084Sjohnlev */ 1455084Sjohnlev typedef enum { 1465084Sjohnlev Unrecognized, 1475084Sjohnlev Connected 1485084Sjohnlev } xendev_hotplug_state_t; 1495084Sjohnlev 1505084Sjohnlev struct xendev_ppd { 1517756SMark.Johnson@Sun.COM kmutex_t xd_evt_lk; 1525084Sjohnlev int xd_evtchn; 1535084Sjohnlev struct intrspec xd_ispec; 1547756SMark.Johnson@Sun.COM 1555084Sjohnlev xendev_devclass_t xd_devclass; 1565084Sjohnlev domid_t xd_domain; 1575084Sjohnlev int xd_vdevnum; 1587756SMark.Johnson@Sun.COM 1597756SMark.Johnson@Sun.COM kmutex_t xd_ndi_lk; 1605084Sjohnlev struct xenbus_device xd_xsdev; 1615084Sjohnlev struct xenbus_watch xd_hp_watch; 1625084Sjohnlev struct xenbus_watch xd_bepath_watch; 1635084Sjohnlev ddi_callback_id_t xd_oe_ehid; 1645084Sjohnlev ddi_callback_id_t xd_hp_ehid; 1655084Sjohnlev ddi_taskq_t *xd_oe_taskq; 1665084Sjohnlev ddi_taskq_t *xd_hp_taskq; 167*8863SEdward.Pilatowicz@Sun.COM ddi_taskq_t *xd_xb_watch_taskq; 168*8863SEdward.Pilatowicz@Sun.COM list_t xd_xb_watches; 1695084Sjohnlev }; 1705084Sjohnlev 1715084Sjohnlev #define XS_OE_STATE "SUNW,xendev:otherend_state" 1725084Sjohnlev #define XS_HP_STATE "SUNW,xendev:hotplug_state" 1735084Sjohnlev 1746175Sjohnlev /* 1756175Sjohnlev * A device with xd_vdevnum == VDEV_NOXS does not participate in 1766175Sjohnlev * xenstore. 1776175Sjohnlev */ 1786175Sjohnlev #define VDEV_NOXS (-1) 1796175Sjohnlev 1805084Sjohnlev void xendev_enum_class(dev_info_t *, xendev_devclass_t); 1815084Sjohnlev void xendev_enum_all(dev_info_t *, boolean_t); 1825084Sjohnlev xendev_devclass_t xendev_nodename_to_devclass(char *); 1835084Sjohnlev int xendev_devclass_ipl(xendev_devclass_t); 1845084Sjohnlev struct intrspec *xendev_get_ispec(dev_info_t *, uint_t); 1855084Sjohnlev void xvdi_suspend(dev_info_t *); 1865084Sjohnlev int xvdi_resume(dev_info_t *); 1875084Sjohnlev int xvdi_alloc_evtchn(dev_info_t *); 1885084Sjohnlev int xvdi_bind_evtchn(dev_info_t *, evtchn_port_t); 1895084Sjohnlev void xvdi_free_evtchn(dev_info_t *); 1905084Sjohnlev int xvdi_add_event_handler(dev_info_t *, char *, 1917756SMark.Johnson@Sun.COM void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *), 1927756SMark.Johnson@Sun.COM void *arg); 1935084Sjohnlev void xvdi_remove_event_handler(dev_info_t *, char *); 1945084Sjohnlev int xvdi_get_evtchn(dev_info_t *); 1955084Sjohnlev int xvdi_get_vdevnum(dev_info_t *); 1965084Sjohnlev char *xvdi_get_xsname(dev_info_t *); 1975084Sjohnlev char *xvdi_get_oename(dev_info_t *); 1985084Sjohnlev domid_t xvdi_get_oeid(dev_info_t *); 1995084Sjohnlev void xvdi_dev_error(dev_info_t *, int, char *); 2005084Sjohnlev void xvdi_fatal_error(dev_info_t *, int, char *); 2015084Sjohnlev void xvdi_notify_oe(dev_info_t *); 2025084Sjohnlev int xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t); 2035084Sjohnlev struct xenbus_device *xvdi_get_xsd(dev_info_t *); 2045084Sjohnlev int xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState); 2055084Sjohnlev dev_info_t *xvdi_create_dev(dev_info_t *, xendev_devclass_t, 2065084Sjohnlev domid_t, int); 2075084Sjohnlev int xvdi_init_dev(dev_info_t *); 2085084Sjohnlev void xvdi_uninit_dev(dev_info_t *); 2095084Sjohnlev dev_info_t *xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int); 2105084Sjohnlev 211*8863SEdward.Pilatowicz@Sun.COM extern int xvdi_add_xb_watch_handler(dev_info_t *, const char *, 212*8863SEdward.Pilatowicz@Sun.COM const char *, xvdi_xb_watch_cb_t cb, void *); 213*8863SEdward.Pilatowicz@Sun.COM extern void xvdi_remove_xb_watch_handlers(dev_info_t *); 214*8863SEdward.Pilatowicz@Sun.COM 2155084Sjohnlev /* 2165084Sjohnlev * common ring interfaces 2175084Sjohnlev */ 2185084Sjohnlev 2195084Sjohnlev /* 2205084Sjohnlev * we need the pad between ring index 2215084Sjohnlev * and the real ring containing requests/responses, 2225084Sjohnlev * so that we can map comif_sring_t structure to 2235084Sjohnlev * any xxxif_sring_t structure defined via macros in ring.h 2245084Sjohnlev */ 2255084Sjohnlev #define SRINGPAD 48 2265084Sjohnlev 2275084Sjohnlev typedef struct comif_sring { 2285084Sjohnlev RING_IDX req_prod, req_event; 2295084Sjohnlev RING_IDX rsp_prod, rsp_event; 2305084Sjohnlev uint8_t pad[SRINGPAD]; 2315084Sjohnlev /* 2325084Sjohnlev * variable length 2335084Sjohnlev * stores real request/response entries 2345084Sjohnlev * entry size is fixed per ring 2355084Sjohnlev */ 2365084Sjohnlev char ring[1]; 2375084Sjohnlev } comif_sring_t; 2385084Sjohnlev 2395084Sjohnlev typedef struct comif_ring_fe { 2405084Sjohnlev /* 2415084Sjohnlev * keep the member names as defined in ring.h 2425084Sjohnlev * in order to make use of the pre-defined macros 2435084Sjohnlev */ 2445084Sjohnlev RING_IDX req_prod_pvt; 2455084Sjohnlev RING_IDX rsp_cons; 2465084Sjohnlev unsigned int nr_ents; 2475084Sjohnlev comif_sring_t *sring; 2485084Sjohnlev } comif_ring_fe_t; 2495084Sjohnlev 2505084Sjohnlev typedef struct comif_ring_be { 2515084Sjohnlev /* 2525084Sjohnlev * keep the member names as defined in ring.h 2535084Sjohnlev * in order to make use of the pre-defined macros 2545084Sjohnlev */ 2555084Sjohnlev RING_IDX rsp_prod_pvt; 2565084Sjohnlev RING_IDX req_cons; 2575084Sjohnlev unsigned int nr_ents; 2585084Sjohnlev comif_sring_t *sring; 2595084Sjohnlev } comif_ring_be_t; 2605084Sjohnlev 2615084Sjohnlev typedef union comif_ring { 2625084Sjohnlev comif_ring_fe_t fr; 2635084Sjohnlev comif_ring_be_t br; 2645084Sjohnlev } comif_ring_t; 2655084Sjohnlev 2665084Sjohnlev typedef struct xendev_req { 2675084Sjohnlev unsigned long next; 2685084Sjohnlev void *req; 2695084Sjohnlev } xendev_req_t; 2705084Sjohnlev 2715084Sjohnlev typedef struct xendev_ring { 2725084Sjohnlev ddi_dma_handle_t xr_dma_hdl; 2735084Sjohnlev ddi_acc_handle_t xr_acc_hdl; 2745084Sjohnlev grant_handle_t xr_grant_hdl; 2755084Sjohnlev caddr_t xr_vaddr; 2765084Sjohnlev paddr_t xr_paddr; 2775084Sjohnlev grant_ref_t xr_gref; 2785084Sjohnlev int xr_entry_size; 2795084Sjohnlev int xr_frontend; 2805084Sjohnlev comif_ring_t xr_sring; 2815084Sjohnlev } xendev_ring_t; 2825084Sjohnlev 2835084Sjohnlev int xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *, 2845084Sjohnlev xendev_ring_t **); 2855084Sjohnlev void xvdi_free_ring(xendev_ring_t *); 2865084Sjohnlev int xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t, 2875084Sjohnlev xendev_ring_t **); 2885084Sjohnlev void xvdi_unmap_ring(xendev_ring_t *); 2895084Sjohnlev uint_t xvdi_ring_avail_slots(xendev_ring_t *); 2905084Sjohnlev int xvdi_ring_has_unconsumed_requests(xendev_ring_t *); 2915084Sjohnlev int xvdi_ring_has_incomp_request(xendev_ring_t *); 2925084Sjohnlev int xvdi_ring_has_unconsumed_responses(xendev_ring_t *); 2935084Sjohnlev void* xvdi_ring_get_request(xendev_ring_t *); 2945084Sjohnlev int xvdi_ring_push_request(xendev_ring_t *); 2955084Sjohnlev void* xvdi_ring_get_response(xendev_ring_t *); 2965084Sjohnlev int xvdi_ring_push_response(xendev_ring_t *); 2975084Sjohnlev 2985084Sjohnlev #ifdef __cplusplus 2995084Sjohnlev } 3005084Sjohnlev #endif 3015084Sjohnlev 3025084Sjohnlev #endif /* _SYS_XENDEV_H */ 303