iPXE
xen.h
Go to the documentation of this file.
00001 #ifndef _IPXE_XEN_H
00002 #define _IPXE_XEN_H
00003 
00004 /** @file
00005  *
00006  * Xen interface
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 /* Define Xen interface version before including any Xen header files */
00013 #define __XEN_INTERFACE_VERSION__ 0x00040400
00014 
00015 #include <stdint.h>
00016 #include <ipxe/bitops.h>
00017 #include <ipxe/uaccess.h>
00018 #include <xen/xen.h>
00019 #include <xen/event_channel.h>
00020 
00021 /* Memory barrier macros used by ring.h */
00022 #define xen_mb() mb()
00023 #define xen_rmb() rmb()
00024 #define xen_wmb() wmb()
00025 
00026 struct xen_hypercall;
00027 
00028 /** A Xen grant table */
00029 struct xen_grant {
00030         /** Grant table entries */
00031         struct grant_entry_v1 *table;
00032         /** Total grant table length */
00033         size_t len;
00034         /** Entry size shift (for later version tables) */
00035         unsigned int shift;
00036         /** Number of grant table entries in use */
00037         unsigned int used;
00038         /** Most recently used grant reference */
00039         unsigned int ref;
00040 };
00041 
00042 /** A XenStore */
00043 struct xen_store {
00044         /** XenStore domain interface */
00045         struct xenstore_domain_interface *intf;
00046         /** Event channel */
00047         evtchn_port_t port;
00048 };
00049 
00050 /** A Xen hypervisor */
00051 struct xen_hypervisor {
00052         /** Hypercall table */
00053         struct xen_hypercall *hypercall;
00054         /** Shared info page */
00055         struct shared_info *shared;
00056         /** Grant table */
00057         struct xen_grant grant;
00058         /** XenStore */
00059         struct xen_store store;
00060 };
00061 
00062 /**
00063  * Test and clear pending event
00064  *
00065  * @v xen               Xen hypervisor
00066  * @v port              Event channel port
00067  * @ret pending         Event was pending
00068  */
00069 static inline __attribute__ (( always_inline )) int
00070 xenevent_pending ( struct xen_hypervisor *xen, evtchn_port_t port ) {
00071 
00072         return test_and_clear_bit ( port, xen->shared->evtchn_pending );
00073 }
00074 
00075 #include <bits/xen.h>
00076 
00077 /**
00078  * Convert a Xen status code to an iPXE status code
00079  *
00080  * @v xenrc             Xen status code (negated)
00081  * @ret rc              iPXE status code (before negation)
00082  *
00083  * Xen status codes are defined in the file include/xen/errno.h in the
00084  * Xen repository.  They happen to match the Linux error codes, some
00085  * of which can be found in our include/ipxe/errno/linux.h.
00086  */
00087 #define EXEN( xenrc ) EPLATFORM ( EINFO_EPLATFORM, -(xenrc) )
00088 
00089 #endif /* _IPXE_XEN_H */