15741Smrj /* 25741Smrj * CDDL HEADER START 35741Smrj * 45741Smrj * The contents of this file are subject to the terms of the 55741Smrj * Common Development and Distribution License (the "License"). 65741Smrj * You may not use this file except in compliance with the License. 75741Smrj * 85741Smrj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95741Smrj * or http://www.opensolaris.org/os/licensing. 105741Smrj * See the License for the specific language governing permissions 115741Smrj * and limitations under the License. 125741Smrj * 135741Smrj * When distributing Covered Code, include this CDDL HEADER in each 145741Smrj * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155741Smrj * If applicable, add the following below this CDDL HEADER, with the 165741Smrj * fields enclosed by brackets "[]" replaced with your own identifying 175741Smrj * information: Portions Copyright [yyyy] [name of copyright owner] 185741Smrj * 195741Smrj * CDDL HEADER END 205741Smrj */ 215741Smrj 225741Smrj /* 2310175SStuart.Maybee@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 245741Smrj * Use is subject to license terms. 255741Smrj */ 265741Smrj 275741Smrj /* 285741Smrj * 295741Smrj * Communication to/from hypervisor. 305741Smrj * 315741Smrj * Copyright (c) 2002-2004, K A Fraser 325741Smrj * 335741Smrj * Permission is hereby granted, free of charge, to any person obtaining a copy 345741Smrj * of this source file (the "Software"), to deal in the Software without 355741Smrj * restriction, including without limitation the rights to use, copy, modify, 365741Smrj * merge, publish, distribute, sublicense, and/or sell copies of the Software, 375741Smrj * and to permit persons to whom the Software is furnished to do so, subject to 385741Smrj * the following conditions: 395741Smrj * 405741Smrj * The above copyright notice and this permission notice shall be included in 415741Smrj * all copies or substantial portions of the Software. 425741Smrj * 435741Smrj * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 445741Smrj * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 455741Smrj * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 465741Smrj * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 475741Smrj * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 485741Smrj * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 495741Smrj * IN THE SOFTWARE. 505741Smrj */ 515741Smrj 525741Smrj #ifndef _SYS_HYPERVISOR_H 535741Smrj #define _SYS_HYPERVISOR_H 545741Smrj 555741Smrj #ifdef __cplusplus 565741Smrj extern "C" { 575741Smrj #endif 585741Smrj 5910175SStuart.Maybee@Sun.COM #define xen_mb membar_enter 6010175SStuart.Maybee@Sun.COM #define xen_wmb membar_producer 6110175SStuart.Maybee@Sun.COM 6210175SStuart.Maybee@Sun.COM #ifndef __xpv 635741Smrj #include <sys/xpv_support.h> 645741Smrj #else 655741Smrj #include <sys/xpv_impl.h> 665741Smrj #endif 675741Smrj #include <sys/xen_errno.h> 685741Smrj 695741Smrj #if !defined(_ASM) 705741Smrj 715741Smrj #include <sys/processor.h> 725741Smrj #include <sys/cpuvar.h> 7310175SStuart.Maybee@Sun.COM #ifdef __xpv 745741Smrj #include <sys/xen_mmu.h> 755741Smrj #endif 765741Smrj #include <sys/systm.h> 775741Smrj #include <xen/public/callback.h> 785741Smrj #include <xen/public/event_channel.h> 795741Smrj #include <xen/public/grant_table.h> 805741Smrj #include <xen/public/io/blkif.h> 815741Smrj #include <xen/public/io/xenbus.h> 825741Smrj #include <xen/public/memory.h> 835741Smrj #include <xen/public/nmi.h> 845741Smrj #include <xen/public/physdev.h> 855741Smrj #include <xen/public/sched.h> 865741Smrj #include <xen/public/platform.h> 875741Smrj #include <xen/public/vcpu.h> 885741Smrj #include <xen/public/version.h> 895741Smrj #include <xen/public/hvm/params.h> 90*11120SMark.Johnson@Sun.COM #include <xen/public/arch-x86/xen-mca.h> 915741Smrj 925741Smrj extern shared_info_t *HYPERVISOR_shared_info; 935741Smrj extern void *HYPERVISOR_console_page; 945741Smrj 955741Smrj /* -- move these definitions elsewhere -- */ 965741Smrj 975741Smrj extern int xen_debug_handler(void *); 985741Smrj extern void xen_printf(const char *, ...) __KPRINTFLIKE(1); 995741Smrj #pragma rarely_called(xen_printf) 1005741Smrj 1015741Smrj extern void xen_callback(void); 1025741Smrj extern void xen_failsafe_callback(void); 1035741Smrj 1045741Smrj extern hrtime_t xpv_gethrtime(void); 1055741Smrj extern hrtime_t xpv_getsystime(void); 1065741Smrj 1075741Smrj extern void xpv_time_suspend(void); 1085741Smrj extern void xpv_time_resume(void); 1095741Smrj 1105741Smrj extern void startup_xen_version(void); 1117532SSean.Ye@Sun.COM extern void startup_xen_mca(void); 1125741Smrj 1135741Smrj extern void mach_cpucontext_reset(cpu_t *); 1145741Smrj extern void mach_cpucontext_restore(cpu_t *); 1155741Smrj 1165741Smrj extern void mp_enter_barrier(void); 1175741Smrj extern void mp_leave_barrier(void); 1185741Smrj 1195741Smrj extern cpuset_t cpu_suspend_lost_set; 1205741Smrj 1215741Smrj extern int xen_gdt_setprot(cpu_t *, uint_t); 1225741Smrj extern int xen_ldt_setprot(user_desc_t *, size_t, uint_t); 1235741Smrj 1247532SSean.Ye@Sun.COM /* -- while you're down there, move these too -- */ 1257532SSean.Ye@Sun.COM 1267532SSean.Ye@Sun.COM typedef struct xen_mc_lcpu_cookie *xen_mc_lcpu_cookie_t; 1277532SSean.Ye@Sun.COM 1287532SSean.Ye@Sun.COM extern xen_mc_lcpu_cookie_t xen_physcpu_next(xen_mc_lcpu_cookie_t); 1297532SSean.Ye@Sun.COM extern const char *xen_physcpu_vendorstr(xen_mc_lcpu_cookie_t); 1307532SSean.Ye@Sun.COM extern int xen_physcpu_family(xen_mc_lcpu_cookie_t); 1317532SSean.Ye@Sun.COM extern int xen_physcpu_model(xen_mc_lcpu_cookie_t); 1327532SSean.Ye@Sun.COM extern int xen_physcpu_stepping(xen_mc_lcpu_cookie_t); 1337532SSean.Ye@Sun.COM extern id_t xen_physcpu_chipid(xen_mc_lcpu_cookie_t); 1347532SSean.Ye@Sun.COM extern id_t xen_physcpu_coreid(xen_mc_lcpu_cookie_t); 1357532SSean.Ye@Sun.COM extern id_t xen_physcpu_strandid(xen_mc_lcpu_cookie_t); 13610942STom.Pothier@Sun.COM extern id_t xen_physcpu_initial_apicid(xen_mc_lcpu_cookie_t); 1377532SSean.Ye@Sun.COM extern boolean_t xen_physcpu_is_cmt(xen_mc_lcpu_cookie_t); 1387532SSean.Ye@Sun.COM extern id_t xen_physcpu_logical_id(xen_mc_lcpu_cookie_t); 1397532SSean.Ye@Sun.COM extern uint64_t xen_physcpu_mcg_cap(xen_mc_lcpu_cookie_t); 1407532SSean.Ye@Sun.COM 1417756SMark.Johnson@Sun.COM extern int xen_map_gref(uint_t cmd, gnttab_map_grant_ref_t *mapop, 1427756SMark.Johnson@Sun.COM uint_t count, boolean_t uvaddr); 1437756SMark.Johnson@Sun.COM 1445741Smrj /* 1455741Smrj * Wrappered versions of the hypercalls that diagnose/panic on failure 1465741Smrj */ 1475741Smrj extern void xen_set_gdt(ulong_t *, int); 1485741Smrj extern void xen_set_ldt(user_desc_t *, uint_t); 1495741Smrj extern void xen_stack_switch(ulong_t, ulong_t); 1505741Smrj extern long xen_set_trap_table(trap_info_t *); 1515741Smrj 1525741Smrj #if defined(__amd64) 1535741Smrj extern void xen_set_segment_base(int, ulong_t); 1545741Smrj #endif /* __amd64 */ 1555741Smrj extern long xen_vcpu_up(processorid_t); 1565741Smrj extern long xen_vcpu_down(processorid_t); 1575741Smrj extern void xen_enable_user_iopl(void); 1585741Smrj extern void xen_disable_user_iopl(void); 1595741Smrj 1607532SSean.Ye@Sun.COM extern int xen_get_mc_physcpuinfo(xen_mc_logical_cpu_t *, uint_t *); 1617532SSean.Ye@Sun.COM extern uint_t xen_phys_ncpus; 1627532SSean.Ye@Sun.COM extern xen_mc_logical_cpu_t *xen_phys_cpus; 1637532SSean.Ye@Sun.COM 16410175SStuart.Maybee@Sun.COM extern uint_t xpv_nr_phys_cpus(void); 16510175SStuart.Maybee@Sun.COM extern pgcnt_t xpv_nr_phys_pages(void); 16610175SStuart.Maybee@Sun.COM extern uint64_t xpv_cpu_khz(void); 16710175SStuart.Maybee@Sun.COM 16810175SStuart.Maybee@Sun.COM 1695741Smrj /* 1705741Smrj * A quick way to ask if we're DOM0 or not .. 1715741Smrj */ 17210175SStuart.Maybee@Sun.COM #ifndef __xpv 1735741Smrj 1745741Smrj #define DOMAIN_IS_INITDOMAIN(info) (__lintzero) 1755741Smrj #define DOMAIN_IS_PRIVILEGED(info) (__lintzero) 1765741Smrj 1775741Smrj #else 1785741Smrj 1795741Smrj #define DOMAIN_IS_INITDOMAIN(info) \ 1805741Smrj (((info)->flags & SIF_INITDOMAIN) == SIF_INITDOMAIN) 1815741Smrj 1825741Smrj #define DOMAIN_IS_PRIVILEGED(info) \ 1835741Smrj (((info)->flags & SIF_PRIVILEGED) == SIF_PRIVILEGED) 1845741Smrj 1855741Smrj #endif 1865741Smrj 1875741Smrj /* 1885741Smrj * start of day information passed up from the hypervisor 1895741Smrj */ 1905741Smrj extern start_info_t *xen_info; 1915741Smrj 1925741Smrj extern long __hypercall0(int); 1935741Smrj extern long __hypercall1(int, ulong_t); 1945741Smrj extern long __hypercall2(int, ulong_t, ulong_t); 1955741Smrj extern long __hypercall3(int, ulong_t, ulong_t, ulong_t); 1965741Smrj extern long __hypercall4(int, ulong_t, ulong_t, ulong_t, ulong_t); 1975741Smrj extern long __hypercall5(int, ulong_t, ulong_t, ulong_t, ulong_t, ulong_t); 1985741Smrj 1995741Smrj extern int __hypercall0_int(int); 2005741Smrj extern int __hypercall1_int(int, ulong_t); 2015741Smrj extern int __hypercall2_int(int, ulong_t, ulong_t); 2025741Smrj extern int __hypercall3_int(int, ulong_t, ulong_t, ulong_t); 2035741Smrj extern int __hypercall4_int(int, ulong_t, ulong_t, ulong_t, ulong_t); 2045741Smrj extern int __hypercall5_int(int, ulong_t, ulong_t, ulong_t, ulong_t, ulong_t); 2055741Smrj 2065741Smrj extern long HYPERVISOR_set_trap_table(trap_info_t *); 2075741Smrj extern int HYPERVISOR_mmu_update(mmu_update_t *, int, int *, domid_t); 2085741Smrj extern long HYPERVISOR_set_gdt(ulong_t *, int); 2095741Smrj extern long HYPERVISOR_stack_switch(ulong_t, ulong_t); 2105741Smrj #if defined(__amd64) 2115741Smrj extern long HYPERVISOR_set_callbacks(ulong_t, ulong_t, ulong_t); 2125741Smrj #else 2135741Smrj extern long HYPERVISOR_set_callbacks(ulong_t, ulong_t, ulong_t, ulong_t); 2145741Smrj #endif 2155741Smrj extern long HYPERVISOR_fpu_taskswitch(int); 2165741Smrj /* *** __HYPERVISOR_sched_op_compat *** OBSOLETED */ 2175741Smrj extern long HYPERVISOR_platform_op(xen_platform_op_t *); 2185741Smrj /* *** __HYPERVISOR_set_debugreg *** NOT IMPLEMENTED */ 2195741Smrj /* *** __HYPERVISOR_get_debugreg *** NOT IMPLEMENTED */ 2205741Smrj extern long HYPERVISOR_update_descriptor(maddr_t, uint64_t); 2215741Smrj extern long HYPERVISOR_memory_op(int, void *); 2225741Smrj extern long HYPERVISOR_multicall(void *, uint_t); 2235741Smrj extern int HYPERVISOR_update_va_mapping(ulong_t, uint64_t, ulong_t); 2245741Smrj extern long HYPERVISOR_set_timer_op(uint64_t); 2255741Smrj /* *** __HYPERVISOR_event_channel_op_compat *** OBSOLETED */ 2265741Smrj extern long HYPERVISOR_xen_version(int, void *); 2275741Smrj extern long HYPERVISOR_console_io(int, int, char *); 2285741Smrj /* *** __HYPERVISOR_physdev_op_compat *** OBSOLETED */ 2295741Smrj extern long HYPERVISOR_grant_table_op(unsigned int, void *, unsigned int); 2305741Smrj extern long HYPERVISOR_vm_assist(unsigned int, unsigned int); 2315741Smrj extern int HYPERVISOR_update_va_mapping_otherdomain(ulong_t, 2325741Smrj uint64_t, ulong_t, domid_t); 2335741Smrj /* *** __HYPERVISOR_iret *** IN i86xpv/sys/machprivregs.h */ 2345741Smrj extern long HYPERVISOR_vcpu_op(int, int, void *); 2355741Smrj #if defined(__amd64) 2365741Smrj extern long HYPERVISOR_set_segment_base(int, ulong_t); 2375741Smrj #endif /* __amd64 */ 2385741Smrj extern int HYPERVISOR_mmuext_op(struct mmuext_op *, int, uint_t *, domid_t); 2395741Smrj extern long HYPERVISOR_nmi_op(int cmd, void *); 2405741Smrj extern long HYPERVISOR_sched_op(int, void *); 2415741Smrj extern long HYPERVISOR_callback_op(int, void *); 2425741Smrj /* *** __HYPERVISOR_xenoprof_op *** NOT IMPLEMENTED */ 2435741Smrj extern long HYPERVISOR_event_channel_op(int, void *); /* does return long */ 2445741Smrj extern long HYPERVISOR_physdev_op(int, void *); 2455741Smrj extern long HYPERVISOR_hvm_op(int cmd, void *); 2465741Smrj /* *** __HYPERVISOR_kexec_op *** NOT IMPLEMENTED */ 247*11120SMark.Johnson@Sun.COM #if defined(__xpv) 248*11120SMark.Johnson@Sun.COM extern long HYPERVISOR_mca(uint32_t, xen_mc_t *); 249*11120SMark.Johnson@Sun.COM #endif 2505741Smrj 2515741Smrj /* 2525741Smrj * HYPERCALL HELPER ROUTINES 2535741Smrj * These don't have their own unique hypercalls. 2545741Smrj */ 2555741Smrj extern long HYPERVISOR_yield(void); 2565741Smrj extern long HYPERVISOR_block(void); 2575741Smrj extern long HYPERVISOR_shutdown(uint_t); 2585741Smrj extern long HYPERVISOR_poll(evtchn_port_t *, uint_t, uint64_t); 2595741Smrj extern long HYPERVISOR_suspend(ulong_t); 2605741Smrj 2615741Smrj #endif /* !_ASM */ 2625741Smrj 2635741Smrj #ifdef __cplusplus 2645741Smrj } 2655741Smrj #endif 2665741Smrj 2675741Smrj #endif /* _SYS_HYPERVISOR_H */ 268