1 /* $NetBSD: xenpmap.h,v 1.27 2011/04/29 22:45:41 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 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 30 #ifndef _XEN_XENPMAP_H_ 31 #define _XEN_XENPMAP_H_ 32 33 #ifdef _KERNEL_OPT 34 #include "opt_xen.h" 35 #endif 36 37 #define INVALID_P2M_ENTRY (~0UL) 38 39 void xpq_queue_machphys_update(paddr_t, paddr_t); 40 void xpq_queue_invlpg(vaddr_t); 41 void xpq_queue_pte_update(paddr_t, pt_entry_t); 42 void xpq_queue_pt_switch(paddr_t); 43 void xpq_flush_queue(void); 44 void xpq_queue_set_ldt(vaddr_t, uint32_t); 45 void xpq_queue_tlb_flush(void); 46 void xpq_queue_pin_table(paddr_t, int); 47 void xpq_queue_unpin_table(paddr_t); 48 int xpq_update_foreign(paddr_t, pt_entry_t, int); 49 50 #define xpq_queue_pin_l1_table(pa) \ 51 xpq_queue_pin_table(pa, MMUEXT_PIN_L1_TABLE) 52 #define xpq_queue_pin_l2_table(pa) \ 53 xpq_queue_pin_table(pa, MMUEXT_PIN_L2_TABLE) 54 #define xpq_queue_pin_l3_table(pa) \ 55 xpq_queue_pin_table(pa, MMUEXT_PIN_L3_TABLE) 56 #define xpq_queue_pin_l4_table(pa) \ 57 xpq_queue_pin_table(pa, MMUEXT_PIN_L4_TABLE) 58 59 extern unsigned long *xpmap_phys_to_machine_mapping; 60 61 /* 62 * On Xen-2, the start of the day virtual memory starts at KERNTEXTOFF 63 * (0xc0100000). On Xen-3 for domain0 it starts at KERNBASE (0xc0000000). 64 * So the offset between physical and virtual address is different on 65 * Xen-2 and Xen-3 for domain0. 66 * starting with xen-3.0.2, we can add notes so that virtual memory starts 67 * at KERNBASE for domU as well. 68 */ 69 #if defined(DOM0OPS) || !defined(XEN_COMPAT_030001) 70 #define XPMAP_OFFSET 0 71 #else 72 #define XPMAP_OFFSET (KERNTEXTOFF - KERNBASE) 73 #endif 74 75 #define mfn_to_pfn(mfn) (machine_to_phys_mapping[(mfn)]) 76 #define pfn_to_mfn(pfn) (xpmap_phys_to_machine_mapping[(pfn)]) 77 78 static __inline paddr_t 79 xpmap_mtop_masked(paddr_t mpa) 80 { 81 return ( 82 ((paddr_t)machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) 83 + XPMAP_OFFSET); 84 } 85 86 static __inline paddr_t 87 xpmap_mtop(paddr_t mpa) 88 { 89 return (xpmap_mtop_masked(mpa) | (mpa & ~PG_FRAME)); 90 } 91 92 static __inline paddr_t 93 xpmap_ptom_masked(paddr_t ppa) 94 { 95 return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa - 96 XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT); 97 } 98 99 static __inline paddr_t 100 xpmap_ptom(paddr_t ppa) 101 { 102 return (xpmap_ptom_masked(ppa) | (ppa & ~PG_FRAME)); 103 } 104 105 static inline void 106 MULTI_update_va_mapping( 107 multicall_entry_t *mcl, vaddr_t va, 108 pt_entry_t new_val, unsigned long flags) 109 { 110 mcl->op = __HYPERVISOR_update_va_mapping; 111 mcl->args[0] = va; 112 #if defined(__x86_64__) 113 mcl->args[1] = new_val; 114 mcl->args[2] = flags; 115 #else 116 mcl->args[1] = (new_val & 0xffffffff); 117 #ifdef PAE 118 mcl->args[2] = (new_val >> 32); 119 #else 120 mcl->args[2] = 0; 121 #endif 122 mcl->args[3] = flags; 123 #endif 124 } 125 126 static inline void 127 MULTI_update_va_mapping_otherdomain( 128 multicall_entry_t *mcl, vaddr_t va, 129 pt_entry_t new_val, unsigned long flags, domid_t domid) 130 { 131 mcl->op = __HYPERVISOR_update_va_mapping_otherdomain; 132 mcl->args[0] = va; 133 #if defined(__x86_64__) 134 mcl->args[1] = new_val; 135 mcl->args[2] = flags; 136 mcl->args[3] = domid; 137 #else 138 mcl->args[1] = (new_val & 0xffffffff); 139 #ifdef PAE 140 mcl->args[2] = (new_val >> 32); 141 #else 142 mcl->args[2] = 0; 143 #endif 144 mcl->args[3] = flags; 145 mcl->args[4] = domid; 146 #endif 147 } 148 #if defined(__x86_64__) 149 #define MULTI_UVMFLAGS_INDEX 2 150 #define MULTI_UVMDOMID_INDEX 3 151 #else 152 #define MULTI_UVMFLAGS_INDEX 3 153 #define MULTI_UVMDOMID_INDEX 4 154 #endif 155 156 #if defined(__x86_64__) 157 void xen_set_user_pgd(paddr_t); 158 #endif 159 160 #endif /* _XEN_XENPMAP_H_ */ 161