1*f183eaeeSriastradh /* $NetBSD: hypervisor.h,v 1.60 2024/07/16 22:44:38 riastradh Exp $ */ 28f162b7eSbouyer 38f162b7eSbouyer /* 48f162b7eSbouyer * Copyright (c) 2006 Manuel Bouyer. 58f162b7eSbouyer * 68f162b7eSbouyer * Redistribution and use in source and binary forms, with or without 78f162b7eSbouyer * modification, are permitted provided that the following conditions 88f162b7eSbouyer * are met: 98f162b7eSbouyer * 1. Redistributions of source code must retain the above copyright 108f162b7eSbouyer * notice, this list of conditions and the following disclaimer. 118f162b7eSbouyer * 2. Redistributions in binary form must reproduce the above copyright 128f162b7eSbouyer * notice, this list of conditions and the following disclaimer in the 138f162b7eSbouyer * documentation and/or other materials provided with the distribution. 148f162b7eSbouyer * 158f162b7eSbouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 168f162b7eSbouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 178f162b7eSbouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 188f162b7eSbouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 198f162b7eSbouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 208f162b7eSbouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 218f162b7eSbouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 228f162b7eSbouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 238f162b7eSbouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 248f162b7eSbouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 258f162b7eSbouyer * 268f162b7eSbouyer */ 2741d325dcScl 2841d325dcScl /* 2941d325dcScl * 3041d325dcScl * Communication to/from hypervisor. 3141d325dcScl * 32e9666f30Sbouyer * Copyright (c) 2002-2004, K A Fraser 3341d325dcScl * 3441d325dcScl * Permission is hereby granted, free of charge, to any person obtaining a copy 35e9666f30Sbouyer * of this source file (the "Software"), to deal in the Software without 36e9666f30Sbouyer * restriction, including without limitation the rights to use, copy, modify, 37e9666f30Sbouyer * merge, publish, distribute, sublicense, and/or sell copies of the Software, 38e9666f30Sbouyer * and to permit persons to whom the Software is furnished to do so, subject to 39e9666f30Sbouyer * the following conditions: 4041d325dcScl * 4141d325dcScl * The above copyright notice and this permission notice shall be included in 4241d325dcScl * all copies or substantial portions of the Software. 4341d325dcScl * 4441d325dcScl * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 4541d325dcScl * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 4641d325dcScl * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 4741d325dcScl * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 4841d325dcScl * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 49e9666f30Sbouyer * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 50e9666f30Sbouyer * IN THE SOFTWARE. 5141d325dcScl */ 5241d325dcScl 5341d325dcScl 5441d325dcScl #ifndef _XEN_HYPERVISOR_H_ 5541d325dcScl #define _XEN_HYPERVISOR_H_ 5641d325dcScl 578f162b7eSbouyer #include "opt_xen.h" 581fe45bddScherry #include "isa.h" 591fe45bddScherry #include "pci.h" 6041d325dcScl 61e43896b3Sbouyer #include <machine/vmparam.h> 62e43896b3Sbouyer 63c24c993fSbouyer struct cpu_info; 64c24c993fSbouyer 65c24c993fSbouyer int xen_hvm_init(void); 66c24c993fSbouyer int xen_hvm_init_cpu(struct cpu_info *); 67c24c993fSbouyer void xen_mainbus_attach(device_t, device_t, void *); 68c24c993fSbouyer 69edf6d721Scl struct hypervisor_attach_args { 70edf6d721Scl const char *haa_busname; 71edf6d721Scl }; 72edf6d721Scl 73fb65e916Scl struct xencons_attach_args { 74edf6d721Scl const char *xa_device; 7541d325dcScl }; 7641d325dcScl 7741d325dcScl struct xen_npx_attach_args { 78edf6d721Scl const char *xa_device; 7941d325dcScl }; 8041d325dcScl 8141d325dcScl 82e9666f30Sbouyer #define u8 uint8_t 830ebd7623Scl #define u16 uint16_t 840ebd7623Scl #define u32 uint32_t 850ebd7623Scl #define u64 uint64_t 86e9666f30Sbouyer #define s8 int8_t 87e9666f30Sbouyer #define s16 int16_t 88e9666f30Sbouyer #define s32 int32_t 89e9666f30Sbouyer #define s64 int64_t 900ebd7623Scl 918ea97067Scherry #include <sys/atomic.h> 92ac8432e2Scherry 93ac8432e2Scherry #include <xen/include/public/xen.h> 94ac8432e2Scherry #include <xen/include/public/sched.h> 95ac8432e2Scherry #include <xen/include/public/platform.h> 96cc63733cScegger #if __XEN_INTERFACE_VERSION__ < 0x00030204 97ac8432e2Scherry #include <xen/include/public/dom0_ops.h> 98cc63733cScegger #endif 99ac8432e2Scherry #include <xen/include/public/event_channel.h> 100ac8432e2Scherry #include <xen/include/public/physdev.h> 101ac8432e2Scherry #include <xen/include/public/memory.h> 102ac8432e2Scherry #include <xen/include/public/io/netif.h> 103ac8432e2Scherry #include <xen/include/public/io/blkif.h> 104d5c9d50fSbouyer #include <xen/include/public/arch-x86/hvm/start_info.h> 1050ebd7623Scl 106050f9f2dScherry #if __XEN_INTERFACE_VERSION < 0x00030208 1078ea97067Scherry /* Undo namespace damage from xen/include/public/io/ring.h 1088ea97067Scherry * The proper fix is to get upstream to stop assuming that all OSs use 1098ea97067Scherry * mb(), rmb(), wmb(). 1108ea97067Scherry */ 1118ea97067Scherry #undef xen_mb 1128ea97067Scherry #undef xen_rmb 1138ea97067Scherry #undef xen_wmb 1148ea97067Scherry 115*f183eaeeSriastradh void xen_mb(void); 116805a95beSriastradh #define xen_rmb() membar_acquire() 117805a95beSriastradh #define xen_wmb() membar_release() 118050f9f2dScherry #endif /* __XEN_INTERFACE_VERSION */ 1198ea97067Scherry 120c24c993fSbouyer #include <machine/xen/hypercalls.h> 1214e541343Sbouyer 122e9666f30Sbouyer #undef u8 1230ebd7623Scl #undef u16 1240ebd7623Scl #undef u32 1250ebd7623Scl #undef u64 126e9666f30Sbouyer #undef s8 127e9666f30Sbouyer #undef s16 128e9666f30Sbouyer #undef s32 129e9666f30Sbouyer #undef s64 13041d325dcScl 13141d325dcScl 1324e541343Sbouyer 13341d325dcScl /* 13441d325dcScl * a placeholder for the start of day information passed up from the hypervisor 13541d325dcScl */ 13641d325dcScl union start_info_union 13741d325dcScl { 13841d325dcScl start_info_t start_info; 139e43896b3Sbouyer char padding[PAGE_SIZE]; 14041d325dcScl }; 14141d325dcScl extern union start_info_union start_info_union; 14241d325dcScl #define xen_start_info (start_info_union.start_info) 14341d325dcScl 144e43896b3Sbouyer CTASSERT(sizeof(start_info_t) <= PAGE_SIZE); 145e43896b3Sbouyer 146d5c9d50fSbouyer extern struct hvm_start_info *hvm_start_info; 147d5c9d50fSbouyer 1488f162b7eSbouyer /* For use in guest OSes. */ 1490f256b9dStron extern volatile shared_info_t *HYPERVISOR_shared_info; 15041d325dcScl 151d5c9d50fSbouyer /* console */ 152d5c9d50fSbouyer extern volatile struct xencons_interface *xencons_interface; 153d5c9d50fSbouyer 1545bed9654Scegger 1555bed9654Scegger /* Structural guest handles introduced in 0x00030201. */ 1565bed9654Scegger #if __XEN_INTERFACE_VERSION__ >= 0x00030201 1575bed9654Scegger #define xenguest_handle(hnd) (hnd).p 1585bed9654Scegger #else 1595bed9654Scegger #define xenguest_handle(hnd) hnd 1605bed9654Scegger #endif 1615bed9654Scegger 16241d325dcScl /* hypervisor.c */ 163e9666f30Sbouyer struct intrframe; 164396b8b4aScherry struct cpu_info; 165e9666f30Sbouyer void do_hypervisor_callback(struct intrframe *regs); 16663697482Sbouyer #if defined(XENPV) && (NPCI > 0 || NISA > 0) 16763697482Sbouyer void hypervisor_prime_pirq_event(int, unsigned int); 16863697482Sbouyer void hypervisor_ack_pirq_event(unsigned int); 16963697482Sbouyer #endif /* XENPV && ( NPCI > 0 || NISA > 0 ) */ 170e9666f30Sbouyer 17154fb8a39Sbouyer extern int xen_version; 17254fb8a39Sbouyer #define XEN_MAJOR(x) (((x) & 0xffff0000) >> 16) 17354fb8a39Sbouyer #define XEN_MINOR(x) ((x) & 0x0000ffff) 17454fb8a39Sbouyer 1753b2f43a7Spgoyette /* 1763b2f43a7Spgoyette * Does the hypervisor we're running on support an api 1773b2f43a7Spgoyette * call at the requested version number ? 1783b2f43a7Spgoyette */ 1793b2f43a7Spgoyette #define XEN_VERSION_SUPPORTED(major, minor) \ 1803b2f43a7Spgoyette (XEN_MAJOR(xen_version) > (major) || \ 1813b2f43a7Spgoyette (XEN_MAJOR(xen_version) == (major) && \ 1823b2f43a7Spgoyette XEN_MINOR(xen_version) >= (minor))) 1833b2f43a7Spgoyette 184e9666f30Sbouyer /* hypervisor_machdep.c */ 185de4e5faeScherry void hypervisor_send_event(struct cpu_info *, unsigned int); 186e9666f30Sbouyer void hypervisor_unmask_event(unsigned int); 187e9666f30Sbouyer void hypervisor_mask_event(unsigned int); 188e9666f30Sbouyer void hypervisor_clear_event(unsigned int); 189c24c993fSbouyer void hypervisor_enable_sir(unsigned int); 190ff4bde10Sknakahara void hypervisor_set_ipending(uint64_t, int, int); 1916004aef4Sbouyer void hypervisor_machdep_attach(void); 192eba16022Sjym void hypervisor_machdep_resume(void); 193e9666f30Sbouyer 1948519a649Sbouyer /* 1958519a649Sbouyer * Force a proper event-channel callback from Xen after clearing the 1968519a649Sbouyer * callback mask. We do this in a very simple manner, by making a call 1978519a649Sbouyer * down into Xen. The pending flag will be checked by Xen on return. 1988519a649Sbouyer */ 199fbae48b9Sperry static __inline void hypervisor_force_callback(void) 2008519a649Sbouyer { 2018f162b7eSbouyer (void)HYPERVISOR_xen_version(0, (void*)0); 2028519a649Sbouyer } __attribute__((no_instrument_function)) /* used by mcount */ 2038519a649Sbouyer 204fbae48b9Sperry static __inline void 2058519a649Sbouyer hypervisor_notify_via_evtchn(unsigned int port) 2068519a649Sbouyer { 2078519a649Sbouyer evtchn_op_t op; 2088519a649Sbouyer 2098519a649Sbouyer op.cmd = EVTCHNOP_send; 2108f162b7eSbouyer op.u.send.port = port; 2118519a649Sbouyer (void)HYPERVISOR_event_channel_op(&op); 2128519a649Sbouyer } 2138519a649Sbouyer 214d5c9d50fSbouyer void xen_init_ksyms(void); 215cdf4177dSbouyer void xen_map_vcpu(struct cpu_info *); 216d5c9d50fSbouyer 217ea9d7f76Sbouyer void xen_early_console(void); 218ea9d7f76Sbouyer 21941d325dcScl #endif /* _XEN_HYPERVISOR_H_ */ 220