Home | History | Annotate | Line # | Download | only in x86
xenfunc.c revision 1.4
      1 /*	$NetBSD: xenfunc.c,v 1.4 2008/02/17 14:03:16 bouyer Exp $	*/
      2 
      3 /*
      4  *
      5  * Copyright (c) 2004 Christian Limpach.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *      This product includes software developed by Christian Limpach.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: xenfunc.c,v 1.4 2008/02/17 14:03:16 bouyer Exp $");
     36 
     37 #include <sys/param.h>
     38 
     39 #include <uvm/uvm_extern.h>
     40 
     41 #include <machine/intr.h>
     42 #include <machine/vmparam.h>
     43 #include <machine/pmap.h>
     44 #include <xen/xen.h>
     45 #include <xen/hypervisor.h>
     46 //#include <xen/evtchn.h>
     47 #include <xen/xenpmap.h>
     48 #include <machine/pte.h>
     49 
     50 #ifdef XENDEBUG_LOW
     51 #define	__PRINTK(x) printk x
     52 #else
     53 #define	__PRINTK(x)
     54 #endif
     55 
     56 void xen_set_ldt(vaddr_t, uint32_t);
     57 
     58 void
     59 invlpg(vaddr_t addr)
     60 {
     61 	int s = splvm();
     62 	xpq_queue_invlpg(addr);
     63 	xpq_flush_queue();
     64 	splx(s);
     65 }
     66 
     67 #ifndef __x86_64__
     68 void
     69 lldt(u_short sel)
     70 {
     71 
     72 	/* __PRINTK(("ldt %x\n", IDXSELN(sel))); */
     73 	if (sel == GSEL(GLDT_SEL, SEL_KPL))
     74 		xen_set_ldt((vaddr_t)ldt, NLDT);
     75 	else
     76 		xen_set_ldt(cpu_info_primary.ci_gdt[IDXSELN(sel)].ld.ld_base,
     77 		    cpu_info_primary.ci_gdt[IDXSELN(sel)].ld.ld_entries);
     78 }
     79 #endif
     80 
     81 void
     82 ltr(u_short sel)
     83 {
     84 	__PRINTK(("XXX ltr not supported\n"));
     85 }
     86 
     87 void
     88 lcr0(u_int val)
     89 {
     90 	__PRINTK(("XXX lcr0 not supported\n"));
     91 }
     92 
     93 u_int
     94 rcr0(void)
     95 {
     96 	__PRINTK(("XXX rcr0 not supported\n"));
     97 	return 0;
     98 }
     99 
    100 #ifndef __x86_64__
    101 void
    102 lcr3(vaddr_t val)
    103 {
    104 	int s = splvm();
    105 	xpq_queue_pt_switch(xpmap_ptom_masked(val));
    106 	xpq_flush_queue();
    107 	splx(s);
    108 }
    109 #endif
    110 
    111 void
    112 tlbflush(void)
    113 {
    114 	int s = splvm();
    115 	xpq_queue_tlb_flush();
    116 	xpq_flush_queue();
    117 	splx(s);
    118 }
    119 
    120 void
    121 tlbflushg(void)
    122 {
    123 	tlbflush();
    124 }
    125 
    126 vaddr_t
    127 rdr6(void)
    128 {
    129 	u_int val;
    130 
    131 	val = HYPERVISOR_get_debugreg(6);
    132 	return val;
    133 }
    134 
    135 void
    136 ldr6(vaddr_t val)
    137 {
    138 
    139 	HYPERVISOR_set_debugreg(6, val);
    140 }
    141 
    142 void
    143 wbinvd(void)
    144 {
    145 
    146 	xpq_flush_cache();
    147 }
    148 
    149 vaddr_t
    150 rcr2(void)
    151 {
    152 #ifdef XEN3
    153 	return HYPERVISOR_shared_info->vcpu_info[0].arch.cr2; /* XXX curcpu */
    154 #else
    155 	return 0;
    156 #endif
    157 }
    158