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