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