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 /* 238863SEdward.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> 33*10175SStuart.Maybee@Sun.COM #ifndef __xpv 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 /* 458863SEdward.Pilatowicz@Sun.COM * Xenbus property interfaces, initialized by framework 468863SEdward.Pilatowicz@Sun.COM */ 478863SEdward.Pilatowicz@Sun.COM #define XBP_HP_STATUS "hotplug-status" /* backend prop: str */ 488863SEdward.Pilatowicz@Sun.COM #define XBV_HP_STATUS_CONN "connected" /* backend prop val */ 498863SEdward.Pilatowicz@Sun.COM #define XBP_DEV_TYPE "device-type" /* backend prop: str */ 508863SEdward.Pilatowicz@Sun.COM #define XBV_DEV_TYPE_CD "cdrom" /* backend prop val */ 518863SEdward.Pilatowicz@Sun.COM 528863SEdward.Pilatowicz@Sun.COM /* 538863SEdward.Pilatowicz@Sun.COM * Xenbus property interfaces, initialized by backend disk driver 548863SEdward.Pilatowicz@Sun.COM */ 559889SLarry.Liu@Sun.COM #define XBP_SECTOR_SIZE "sector-size" /* backend prop: uint */ 568863SEdward.Pilatowicz@Sun.COM #define XBP_SECTORS "sectors" /* backend prop: uint64 */ 578863SEdward.Pilatowicz@Sun.COM #define XBP_INFO "info" /* backend prop: uint */ 588863SEdward.Pilatowicz@Sun.COM #define XBP_FB "feature-barrier" /* backend prop: boolean int */ 598863SEdward.Pilatowicz@Sun.COM 608863SEdward.Pilatowicz@Sun.COM /* 618863SEdward.Pilatowicz@Sun.COM * Xenbus property interfaces, initialized by frontend disk driver 628863SEdward.Pilatowicz@Sun.COM */ 638863SEdward.Pilatowicz@Sun.COM #define XBP_RING_REF "ring-ref" /* frontend prop: long */ 648863SEdward.Pilatowicz@Sun.COM #define XBP_EVENT_CHAN "event-channel" /* frontend prop: long */ 658863SEdward.Pilatowicz@Sun.COM #define XBP_PROTOCOL "protocol" /* frontend prop: string */ 668863SEdward.Pilatowicz@Sun.COM 678863SEdward.Pilatowicz@Sun.COM /* 688863SEdward.Pilatowicz@Sun.COM * Xenbus CDROM property interfaces, used by backend and frontend 698863SEdward.Pilatowicz@Sun.COM * 708863SEdward.Pilatowicz@Sun.COM * XBP_MEDIA_REQ_SUP 718863SEdward.Pilatowicz@Sun.COM * - Backend xenbus property located at: 728863SEdward.Pilatowicz@Sun.COM * backend/vbd/<domU_id>/<domU_dev>/media-req-sup 738863SEdward.Pilatowicz@Sun.COM * - Set by the backend, consumed by the frontend. 748863SEdward.Pilatowicz@Sun.COM * - Cosumed by the frontend. 758863SEdward.Pilatowicz@Sun.COM * - A boolean integer property indicating backend support 768863SEdward.Pilatowicz@Sun.COM * for the XBP_MEDIA_REQ property. 778863SEdward.Pilatowicz@Sun.COM * 788863SEdward.Pilatowicz@Sun.COM * XBP_MEDIA_REQ 798863SEdward.Pilatowicz@Sun.COM * - Frontend xenbus property located at: 808863SEdward.Pilatowicz@Sun.COM * /local/domain/<domU_id>/device/vbd/<domU_dev>/media-req 818863SEdward.Pilatowicz@Sun.COM * - Set and consumed by both the frontend and backend. 828863SEdward.Pilatowicz@Sun.COM * - Possible values: 838863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_NONE, XBV_MEDIA_REQ_LOCK, and XBV_MEDIA_REQ_EJECT 848863SEdward.Pilatowicz@Sun.COM * - Only applies to CDROM devices. 858863SEdward.Pilatowicz@Sun.COM * 868863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_NONE 878863SEdward.Pilatowicz@Sun.COM * - XBP_MEDIA_REQ property valud 888863SEdward.Pilatowicz@Sun.COM * - Set and consumed by both the frontend and backend. 898863SEdward.Pilatowicz@Sun.COM * - Indicates that there are no currently outstanding media requet 908863SEdward.Pilatowicz@Sun.COM * operations. 918863SEdward.Pilatowicz@Sun.COM * 928863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_LOCK 938863SEdward.Pilatowicz@Sun.COM * - XBP_MEDIA_REQ property valud 948863SEdward.Pilatowicz@Sun.COM * - Set by the frontend, consumed by the backend. 958863SEdward.Pilatowicz@Sun.COM * - Indicates to the backend that the currenct media is locked 968863SEdward.Pilatowicz@Sun.COM * and changes to the media (via xm block-configure for example) 978863SEdward.Pilatowicz@Sun.COM * should not be allowed. 988863SEdward.Pilatowicz@Sun.COM * 998863SEdward.Pilatowicz@Sun.COM * XBV_MEDIA_REQ_EJECT 1008863SEdward.Pilatowicz@Sun.COM * - XBP_MEDIA_REQ property valud 1018863SEdward.Pilatowicz@Sun.COM * - Set by the frontend, consumed by the backend. 1028863SEdward.Pilatowicz@Sun.COM * - Indicates to the backend that the currenct media should be ejected. 1038863SEdward.Pilatowicz@Sun.COM * This means that the backend should close it's connection to 1048863SEdward.Pilatowicz@Sun.COM * the frontend device, close it's current backing store device/file, 1058863SEdward.Pilatowicz@Sun.COM * and then set the media-req property to XBV_MEDIA_REQ_NONE. (to 1068863SEdward.Pilatowicz@Sun.COM * indicate that the eject operation is complete.) 1078863SEdward.Pilatowicz@Sun.COM */ 1088863SEdward.Pilatowicz@Sun.COM #define XBP_MEDIA_REQ_SUP "media-req-sup" /* backend prop: boolean int */ 1098863SEdward.Pilatowicz@Sun.COM #define XBP_MEDIA_REQ "media-req" /* frontend prop: str */ 1108863SEdward.Pilatowicz@Sun.COM #define XBV_MEDIA_REQ_NONE "none" /* frontend prop val */ 1118863SEdward.Pilatowicz@Sun.COM #define XBV_MEDIA_REQ_LOCK "lock" /* frontend prop val */ 1128863SEdward.Pilatowicz@Sun.COM #define XBV_MEDIA_REQ_EJECT "eject" /* frontend prop val */ 1138863SEdward.Pilatowicz@Sun.COM 1148863SEdward.Pilatowicz@Sun.COM /* 1155084Sjohnlev * Xen device class codes 1165084Sjohnlev */ 1175084Sjohnlev typedef enum { 1185084Sjohnlev XEN_INVAL = -1, 1195084Sjohnlev XEN_CONSOLE = 0, 1205084Sjohnlev XEN_VNET, 1215084Sjohnlev XEN_VBLK, 1225084Sjohnlev XEN_XENBUS, 1235084Sjohnlev XEN_DOMCAPS, 1245084Sjohnlev XEN_BALLOON, 1255084Sjohnlev XEN_EVTCHN, 1265084Sjohnlev XEN_PRIVCMD, 1277756SMark.Johnson@Sun.COM XEN_BLKTAP, 1285084Sjohnlev XEN_LASTCLASS 1295084Sjohnlev } xendev_devclass_t; 1305084Sjohnlev 1315084Sjohnlev /* 1325084Sjohnlev * Hotplug request sent to userland event handler. 1335084Sjohnlev */ 1345084Sjohnlev typedef enum { 1355084Sjohnlev XEN_HP_ADD, 1365084Sjohnlev XEN_HP_REMOVE 1375084Sjohnlev } xendev_hotplug_cmd_t; 1385084Sjohnlev 1395084Sjohnlev /* 1405084Sjohnlev * Hotplug status. 1415084Sjohnlev * 1425084Sjohnlev * In fact, the Xen tools can write any arbitrary string into the 1435084Sjohnlev * hotplug-status node. We represent the known values here - anything 1445084Sjohnlev * else will be 'Unrecognized'. 1455084Sjohnlev */ 1465084Sjohnlev typedef enum { 1475084Sjohnlev Unrecognized, 1485084Sjohnlev Connected 1495084Sjohnlev } xendev_hotplug_state_t; 1505084Sjohnlev 1515084Sjohnlev struct xendev_ppd { 1527756SMark.Johnson@Sun.COM kmutex_t xd_evt_lk; 1535084Sjohnlev int xd_evtchn; 1545084Sjohnlev struct intrspec xd_ispec; 1557756SMark.Johnson@Sun.COM 1565084Sjohnlev xendev_devclass_t xd_devclass; 1575084Sjohnlev domid_t xd_domain; 1585084Sjohnlev int xd_vdevnum; 1597756SMark.Johnson@Sun.COM 1607756SMark.Johnson@Sun.COM kmutex_t xd_ndi_lk; 1615084Sjohnlev struct xenbus_device xd_xsdev; 1625084Sjohnlev struct xenbus_watch xd_hp_watch; 1635084Sjohnlev struct xenbus_watch xd_bepath_watch; 1645084Sjohnlev ddi_callback_id_t xd_oe_ehid; 1655084Sjohnlev ddi_callback_id_t xd_hp_ehid; 1665084Sjohnlev ddi_taskq_t *xd_oe_taskq; 1675084Sjohnlev ddi_taskq_t *xd_hp_taskq; 1688863SEdward.Pilatowicz@Sun.COM ddi_taskq_t *xd_xb_watch_taskq; 1698863SEdward.Pilatowicz@Sun.COM list_t xd_xb_watches; 1705084Sjohnlev }; 1715084Sjohnlev 1725084Sjohnlev #define XS_OE_STATE "SUNW,xendev:otherend_state" 1735084Sjohnlev #define XS_HP_STATE "SUNW,xendev:hotplug_state" 1745084Sjohnlev 1756175Sjohnlev /* 1766175Sjohnlev * A device with xd_vdevnum == VDEV_NOXS does not participate in 1776175Sjohnlev * xenstore. 1786175Sjohnlev */ 1796175Sjohnlev #define VDEV_NOXS (-1) 1806175Sjohnlev 1815084Sjohnlev void xendev_enum_class(dev_info_t *, xendev_devclass_t); 1825084Sjohnlev void xendev_enum_all(dev_info_t *, boolean_t); 1835084Sjohnlev xendev_devclass_t xendev_nodename_to_devclass(char *); 1845084Sjohnlev int xendev_devclass_ipl(xendev_devclass_t); 1855084Sjohnlev struct intrspec *xendev_get_ispec(dev_info_t *, uint_t); 1865084Sjohnlev void xvdi_suspend(dev_info_t *); 1875084Sjohnlev int xvdi_resume(dev_info_t *); 1885084Sjohnlev int xvdi_alloc_evtchn(dev_info_t *); 1895084Sjohnlev int xvdi_bind_evtchn(dev_info_t *, evtchn_port_t); 1905084Sjohnlev void xvdi_free_evtchn(dev_info_t *); 1915084Sjohnlev int xvdi_add_event_handler(dev_info_t *, char *, 1927756SMark.Johnson@Sun.COM void (*)(dev_info_t *, ddi_eventcookie_t, void *, void *), 1937756SMark.Johnson@Sun.COM void *arg); 1945084Sjohnlev void xvdi_remove_event_handler(dev_info_t *, char *); 1955084Sjohnlev int xvdi_get_evtchn(dev_info_t *); 1965084Sjohnlev int xvdi_get_vdevnum(dev_info_t *); 1975084Sjohnlev char *xvdi_get_xsname(dev_info_t *); 1985084Sjohnlev char *xvdi_get_oename(dev_info_t *); 1995084Sjohnlev domid_t xvdi_get_oeid(dev_info_t *); 2005084Sjohnlev void xvdi_dev_error(dev_info_t *, int, char *); 2015084Sjohnlev void xvdi_fatal_error(dev_info_t *, int, char *); 2025084Sjohnlev void xvdi_notify_oe(dev_info_t *); 2035084Sjohnlev int xvdi_post_event(dev_info_t *, xendev_hotplug_cmd_t); 2045084Sjohnlev struct xenbus_device *xvdi_get_xsd(dev_info_t *); 2055084Sjohnlev int xvdi_switch_state(dev_info_t *, xenbus_transaction_t, XenbusState); 2065084Sjohnlev dev_info_t *xvdi_create_dev(dev_info_t *, xendev_devclass_t, 2075084Sjohnlev domid_t, int); 2085084Sjohnlev int xvdi_init_dev(dev_info_t *); 2095084Sjohnlev void xvdi_uninit_dev(dev_info_t *); 2105084Sjohnlev dev_info_t *xvdi_find_dev(dev_info_t *, xendev_devclass_t, domid_t, int); 2115084Sjohnlev 2128863SEdward.Pilatowicz@Sun.COM extern int xvdi_add_xb_watch_handler(dev_info_t *, const char *, 2138863SEdward.Pilatowicz@Sun.COM const char *, xvdi_xb_watch_cb_t cb, void *); 2148863SEdward.Pilatowicz@Sun.COM extern void xvdi_remove_xb_watch_handlers(dev_info_t *); 2158863SEdward.Pilatowicz@Sun.COM 2165084Sjohnlev /* 2175084Sjohnlev * common ring interfaces 2185084Sjohnlev */ 2195084Sjohnlev 2205084Sjohnlev /* 2215084Sjohnlev * we need the pad between ring index 2225084Sjohnlev * and the real ring containing requests/responses, 2235084Sjohnlev * so that we can map comif_sring_t structure to 2245084Sjohnlev * any xxxif_sring_t structure defined via macros in ring.h 2255084Sjohnlev */ 2265084Sjohnlev #define SRINGPAD 48 2275084Sjohnlev 2285084Sjohnlev typedef struct comif_sring { 2295084Sjohnlev RING_IDX req_prod, req_event; 2305084Sjohnlev RING_IDX rsp_prod, rsp_event; 2315084Sjohnlev uint8_t pad[SRINGPAD]; 2325084Sjohnlev /* 2335084Sjohnlev * variable length 2345084Sjohnlev * stores real request/response entries 2355084Sjohnlev * entry size is fixed per ring 2365084Sjohnlev */ 2375084Sjohnlev char ring[1]; 2385084Sjohnlev } comif_sring_t; 2395084Sjohnlev 2405084Sjohnlev typedef struct comif_ring_fe { 2415084Sjohnlev /* 2425084Sjohnlev * keep the member names as defined in ring.h 2435084Sjohnlev * in order to make use of the pre-defined macros 2445084Sjohnlev */ 2455084Sjohnlev RING_IDX req_prod_pvt; 2465084Sjohnlev RING_IDX rsp_cons; 2475084Sjohnlev unsigned int nr_ents; 2485084Sjohnlev comif_sring_t *sring; 2495084Sjohnlev } comif_ring_fe_t; 2505084Sjohnlev 2515084Sjohnlev typedef struct comif_ring_be { 2525084Sjohnlev /* 2535084Sjohnlev * keep the member names as defined in ring.h 2545084Sjohnlev * in order to make use of the pre-defined macros 2555084Sjohnlev */ 2565084Sjohnlev RING_IDX rsp_prod_pvt; 2575084Sjohnlev RING_IDX req_cons; 2585084Sjohnlev unsigned int nr_ents; 2595084Sjohnlev comif_sring_t *sring; 2605084Sjohnlev } comif_ring_be_t; 2615084Sjohnlev 2625084Sjohnlev typedef union comif_ring { 2635084Sjohnlev comif_ring_fe_t fr; 2645084Sjohnlev comif_ring_be_t br; 2655084Sjohnlev } comif_ring_t; 2665084Sjohnlev 2675084Sjohnlev typedef struct xendev_req { 2685084Sjohnlev unsigned long next; 2695084Sjohnlev void *req; 2705084Sjohnlev } xendev_req_t; 2715084Sjohnlev 2725084Sjohnlev typedef struct xendev_ring { 2735084Sjohnlev ddi_dma_handle_t xr_dma_hdl; 2745084Sjohnlev ddi_acc_handle_t xr_acc_hdl; 2755084Sjohnlev grant_handle_t xr_grant_hdl; 2765084Sjohnlev caddr_t xr_vaddr; 2775084Sjohnlev paddr_t xr_paddr; 2785084Sjohnlev grant_ref_t xr_gref; 2795084Sjohnlev int xr_entry_size; 2805084Sjohnlev int xr_frontend; 2815084Sjohnlev comif_ring_t xr_sring; 2825084Sjohnlev } xendev_ring_t; 2835084Sjohnlev 2845084Sjohnlev int xvdi_alloc_ring(dev_info_t *, size_t, size_t, grant_ref_t *, 2855084Sjohnlev xendev_ring_t **); 2865084Sjohnlev void xvdi_free_ring(xendev_ring_t *); 2875084Sjohnlev int xvdi_map_ring(dev_info_t *, size_t, size_t, grant_ref_t, 2885084Sjohnlev xendev_ring_t **); 2895084Sjohnlev void xvdi_unmap_ring(xendev_ring_t *); 2905084Sjohnlev uint_t xvdi_ring_avail_slots(xendev_ring_t *); 2915084Sjohnlev int xvdi_ring_has_unconsumed_requests(xendev_ring_t *); 2925084Sjohnlev int xvdi_ring_has_incomp_request(xendev_ring_t *); 2935084Sjohnlev int xvdi_ring_has_unconsumed_responses(xendev_ring_t *); 2945084Sjohnlev void* xvdi_ring_get_request(xendev_ring_t *); 2955084Sjohnlev int xvdi_ring_push_request(xendev_ring_t *); 2965084Sjohnlev void* xvdi_ring_get_response(xendev_ring_t *); 2975084Sjohnlev int xvdi_ring_push_response(xendev_ring_t *); 2985084Sjohnlev 2995084Sjohnlev #ifdef __cplusplus 3005084Sjohnlev } 3015084Sjohnlev #endif 3025084Sjohnlev 3035084Sjohnlev #endif /* _SYS_XENDEV_H */ 304