Home | History | Annotate | Line # | Download | only in include
xenpmap.h revision 1.21
      1 /*	$NetBSD: xenpmap.h,v 1.21 2008/10/24 22:06:06 jym 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 
     35 #ifndef _XEN_XENPMAP_H_
     36 #define _XEN_XENPMAP_H_
     37 #include "opt_xen.h"
     38 
     39 #define	INVALID_P2M_ENTRY	(~0UL)
     40 
     41 void xpq_queue_machphys_update(paddr_t, paddr_t);
     42 void xpq_queue_invlpg(vaddr_t);
     43 void xpq_queue_pte_update(paddr_t, pt_entry_t);
     44 void xpq_queue_pt_switch(paddr_t);
     45 void xpq_flush_queue(void);
     46 void xpq_queue_set_ldt(vaddr_t, uint32_t);
     47 void xpq_queue_tlb_flush(void);
     48 void xpq_queue_pin_table(paddr_t);
     49 void xpq_queue_unpin_table(paddr_t);
     50 int  xpq_update_foreign(paddr_t, pt_entry_t, int);
     51 
     52 extern unsigned long *xpmap_phys_to_machine_mapping;
     53 
     54 /*
     55  * On Xen-2, the start of the day virtual memory starts at KERNTEXTOFF
     56  * (0xc0100000). On Xen-3 for domain0 it starts at KERNBASE (0xc0000000).
     57  * So the offset between physical and virtual address is different on
     58  * Xen-2 and Xen-3 for domain0.
     59  * starting with xen-3.0.2, we can add notes so that virtual memory starts
     60  * at KERNBASE for domU as well.
     61  */
     62 #if defined(XEN3) && (defined(DOM0OPS) || !defined(XEN_COMPAT_030001))
     63 #define XPMAP_OFFSET	0
     64 #else
     65 #define	XPMAP_OFFSET	(KERNTEXTOFF - KERNBASE)
     66 #endif
     67 
     68 #define mfn_to_pfn(mfn) (machine_to_phys_mapping[(mfn)])
     69 #define pfn_to_mfn(pfn) (xpmap_phys_to_machine_mapping[(pfn)])
     70 
     71 static __inline paddr_t
     72 xpmap_mtop(paddr_t mpa)
     73 {
     74 	return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
     75 	    XPMAP_OFFSET) | (mpa & ~PG_FRAME);
     76 }
     77 
     78 static __inline paddr_t
     79 xpmap_mtop_masked(paddr_t mpa)
     80 {
     81 	return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
     82 	    XPMAP_OFFSET);
     83 }
     84 
     85 static __inline paddr_t
     86 xpmap_ptom(paddr_t ppa)
     87 {
     88 	return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa -
     89 	    XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT)
     90 		| (ppa & ~PG_FRAME);
     91 }
     92 
     93 static __inline paddr_t
     94 xpmap_ptom_masked(paddr_t ppa)
     95 {
     96 	return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa -
     97 	    XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT);
     98 }
     99 
    100 #ifdef XEN3
    101 static inline void
    102 MULTI_update_va_mapping(
    103 	multicall_entry_t *mcl, vaddr_t va,
    104 	pt_entry_t new_val, unsigned long flags)
    105 {
    106 	mcl->op = __HYPERVISOR_update_va_mapping;
    107 	mcl->args[0] = va;
    108 #if defined(__x86_64__)
    109 	mcl->args[1] = new_val;
    110 	mcl->args[2] = flags;
    111 #else
    112 	mcl->args[1] = (new_val & 0xffffffff);
    113 #ifdef PAE
    114 	mcl->args[2] = (new_val >> 32);
    115 #else
    116 	mcl->args[2] = 0;
    117 #endif
    118 	mcl->args[3] = flags;
    119 #endif
    120 }
    121 
    122 static inline void
    123 MULTI_update_va_mapping_otherdomain(
    124 	multicall_entry_t *mcl, vaddr_t va,
    125 	pt_entry_t new_val, unsigned long flags, domid_t domid)
    126 {
    127 	mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
    128 	mcl->args[0] = va;
    129 #if defined(__x86_64__)
    130 	mcl->args[1] = new_val;
    131 	mcl->args[2] = flags;
    132 	mcl->args[3] = domid;
    133 #else
    134 	mcl->args[1] = (new_val & 0xffffffff);
    135 #ifdef PAE
    136 	mcl->args[2] = (new_val >> 32);
    137 #else
    138 	mcl->args[2] = 0;
    139 #endif
    140 	mcl->args[3] = flags;
    141 	mcl->args[4] = domid;
    142 #endif
    143 }
    144 #if defined(__x86_64__)
    145 #define MULTI_UVMFLAGS_INDEX 2
    146 #define MULTI_UVMDOMID_INDEX 3
    147 #else
    148 #define MULTI_UVMFLAGS_INDEX 3
    149 #define MULTI_UVMDOMID_INDEX 4
    150 #endif
    151 
    152 #if defined(__x86_64__)
    153 void xen_set_user_pgd(paddr_t);
    154 #endif
    155 
    156 #endif /* XEN3 */
    157 
    158 #endif /* _XEN_XENPMAP_H_ */
    159