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