Home | History | Annotate | Line # | Download | only in x86
xenfunc.c revision 1.17.2.2
      1 /*	$NetBSD: xenfunc.c,v 1.17.2.2 2018/07/28 04:37:43 pgoyette Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2004 Christian Limpach.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  */
     27 
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.17.2.2 2018/07/28 04:37:43 pgoyette Exp $");
     30 
     31 #include <sys/param.h>
     32 
     33 #include <uvm/uvm_extern.h>
     34 
     35 #include <machine/intr.h>
     36 #include <machine/vmparam.h>
     37 #include <machine/pmap.h>
     38 #include <xen/xen.h>
     39 #include <xen/hypervisor.h>
     40 //#include <xen/evtchn.h>
     41 #include <xen/xenpmap.h>
     42 #include <machine/pte.h>
     43 
     44 void xen_set_ldt(vaddr_t, uint32_t);
     45 
     46 void
     47 invlpg(vaddr_t addr)
     48 {
     49 	int s = splvm(); /* XXXSMP */
     50 	xpq_queue_invlpg(addr);
     51 	splx(s);
     52 }
     53 
     54 void
     55 lldt(u_short sel)
     56 {
     57 #ifndef __x86_64__
     58 	struct cpu_info *ci;
     59 
     60 	ci = curcpu();
     61 
     62 	if (ci->ci_curldt == sel)
     63 		return;
     64 	if (sel == GSEL(GLDT_SEL, SEL_KPL))
     65 		xen_set_ldt((vaddr_t)ldtstore, NLDT);
     66 	else
     67 		xen_set_ldt(ci->ci_gdt[IDXSELN(sel)].ld.ld_base,
     68 		    ci->ci_gdt[IDXSELN(sel)].ld.ld_entries);
     69 	ci->ci_curldt = sel;
     70 #endif
     71 }
     72 
     73 void
     74 ltr(u_short sel)
     75 {
     76 	panic("XXX ltr not supported\n");
     77 }
     78 
     79 void
     80 lcr0(u_long val)
     81 {
     82 	panic("XXX lcr0 not supported\n");
     83 }
     84 
     85 u_long
     86 rcr0(void)
     87 {
     88 	/* XXX: handle X86_CR0_TS ? */
     89 	return 0;
     90 }
     91 
     92 #ifndef __x86_64__
     93 void
     94 lcr3(vaddr_t val)
     95 {
     96 	int s = splvm(); /* XXXSMP */
     97 	xpq_queue_pt_switch(xpmap_ptom_masked(val));
     98 	splx(s);
     99 }
    100 #endif
    101 
    102 void
    103 tlbflush(void)
    104 {
    105 	int s = splvm(); /* XXXSMP */
    106 	xpq_queue_tlb_flush();
    107 	splx(s);
    108 }
    109 
    110 void
    111 tlbflushg(void)
    112 {
    113 	tlbflush();
    114 }
    115 
    116 register_t
    117 rdr0(void)
    118 {
    119 
    120 	return HYPERVISOR_get_debugreg(0);
    121 }
    122 
    123 void
    124 ldr0(register_t val)
    125 {
    126 
    127 	HYPERVISOR_set_debugreg(0, val);
    128 }
    129 
    130 register_t
    131 rdr1(void)
    132 {
    133 
    134 	return HYPERVISOR_get_debugreg(1);
    135 }
    136 
    137 void
    138 ldr1(register_t val)
    139 {
    140 
    141 	HYPERVISOR_set_debugreg(1, val);
    142 }
    143 
    144 register_t
    145 rdr2(void)
    146 {
    147 
    148 	return HYPERVISOR_get_debugreg(2);
    149 }
    150 
    151 void
    152 ldr2(register_t val)
    153 {
    154 
    155 	HYPERVISOR_set_debugreg(2, val);
    156 }
    157 
    158 register_t
    159 rdr3(void)
    160 {
    161 
    162 	return HYPERVISOR_get_debugreg(3);
    163 }
    164 
    165 void
    166 ldr3(register_t val)
    167 {
    168 
    169 	HYPERVISOR_set_debugreg(3, val);
    170 }
    171 register_t
    172 rdr6(void)
    173 {
    174 
    175 	return HYPERVISOR_get_debugreg(6);
    176 }
    177 
    178 void
    179 ldr6(register_t val)
    180 {
    181 
    182 	HYPERVISOR_set_debugreg(6, val);
    183 }
    184 
    185 register_t
    186 rdr7(void)
    187 {
    188 
    189 	return HYPERVISOR_get_debugreg(7);
    190 }
    191 
    192 void
    193 ldr7(register_t val)
    194 {
    195 
    196 	HYPERVISOR_set_debugreg(7, val);
    197 }
    198 
    199 void
    200 wbinvd(void)
    201 {
    202 
    203 	xpq_flush_cache();
    204 }
    205 
    206 vaddr_t
    207 rcr2(void)
    208 {
    209 	return curcpu()->ci_vcpu->arch.cr2;
    210 }
    211 
    212 #ifdef __x86_64__
    213 void
    214 setusergs(int gssel)
    215 {
    216 	HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, gssel);
    217 }
    218 #endif
    219