1 #ifndef _IPXE_XEN_H 2 #define _IPXE_XEN_H 3 4 /** @file 5 * 6 * Xen interface 7 * 8 */ 9 10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); 11 12 /* Define Xen interface version before including any Xen header files */ 13 #define __XEN_INTERFACE_VERSION__ 0x00040400 14 15 #include <stdint.h> 16 #include <ipxe/bitops.h> 17 #include <ipxe/uaccess.h> 18 #include <xen/xen.h> 19 #include <xen/event_channel.h> 20 21 /* Memory barrier macros used by ring.h */ 22 #define xen_mb() mb() 23 #define xen_rmb() rmb() 24 #define xen_wmb() wmb() 25 26 struct xen_hypercall; 27 28 /** A Xen grant table */ 29 struct xen_grant { 30 /** Grant table entries */ 31 struct grant_entry_v1 *table; 32 /** Total grant table length */ 33 size_t len; 34 /** Entry size shift (for later version tables) */ 35 unsigned int shift; 36 /** Number of grant table entries in use */ 37 unsigned int used; 38 /** Most recently used grant reference */ 39 unsigned int ref; 40 }; 41 42 /** A XenStore */ 43 struct xen_store { 44 /** XenStore domain interface */ 45 struct xenstore_domain_interface *intf; 46 /** Event channel */ 47 evtchn_port_t port; 48 }; 49 50 /** A Xen hypervisor */ 51 struct xen_hypervisor { 52 /** Hypercall table */ 53 struct xen_hypercall *hypercall; 54 /** Shared info page */ 55 struct shared_info *shared; 56 /** Grant table */ 57 struct xen_grant grant; 58 /** XenStore */ 59 struct xen_store store; 60 }; 61 62 /** 63 * Test and clear pending event 64 * 65 * @v xen Xen hypervisor 66 * @v port Event channel port 67 * @ret pending Event was pending 68 */ 69 static inline __attribute__ (( always_inline )) int xenevent_pending(struct xen_hypervisor * xen,evtchn_port_t port)70xenevent_pending ( struct xen_hypervisor *xen, evtchn_port_t port ) { 71 72 return test_and_clear_bit ( port, xen->shared->evtchn_pending ); 73 } 74 75 #include <bits/xen.h> 76 77 /** 78 * Convert a Xen status code to an iPXE status code 79 * 80 * @v xenrc Xen status code (negated) 81 * @ret rc iPXE status code (before negation) 82 * 83 * Xen status codes are defined in the file include/xen/errno.h in the 84 * Xen repository. They happen to match the Linux error codes, some 85 * of which can be found in our include/ipxe/errno/linux.h. 86 */ 87 #define EXEN( xenrc ) EPLATFORM ( EINFO_EPLATFORM, -(xenrc) ) 88 89 #endif /* _IPXE_XEN_H */ 90