1 /* $NetBSD: xenpmap.h,v 1.19 2008/01/23 19:46:45 bouyer 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 virual 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 virual 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 static __inline paddr_t 69 xpmap_mtop(paddr_t mpa) 70 { 71 return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) + 72 XPMAP_OFFSET) | (mpa & ~PG_FRAME); 73 } 74 75 static __inline paddr_t 76 xpmap_mtop_masked(paddr_t mpa) 77 { 78 return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) + 79 XPMAP_OFFSET); 80 } 81 82 static __inline paddr_t 83 xpmap_ptom(paddr_t ppa) 84 { 85 return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa - 86 XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT) 87 | (ppa & ~PG_FRAME); 88 } 89 90 static __inline paddr_t 91 xpmap_ptom_masked(paddr_t ppa) 92 { 93 return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa - 94 XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT); 95 } 96 97 #ifdef XEN3 98 static inline void 99 MULTI_update_va_mapping( 100 multicall_entry_t *mcl, vaddr_t va, 101 pt_entry_t new_val, unsigned long flags) 102 { 103 mcl->op = __HYPERVISOR_update_va_mapping; 104 mcl->args[0] = va; 105 #if defined(__x86_64__) 106 mcl->args[1] = new_val; 107 mcl->args[2] = flags; 108 #else 109 mcl->args[1] = (new_val & 0xffffffff); 110 #ifdef PAE 111 mcl->args[2] = (new_val >> 32); 112 #else 113 mcl->args[2] = 0; 114 #endif 115 mcl->args[3] = flags; 116 #endif 117 } 118 119 static inline void 120 MULTI_update_va_mapping_otherdomain( 121 multicall_entry_t *mcl, vaddr_t va, 122 pt_entry_t new_val, unsigned long flags, domid_t domid) 123 { 124 mcl->op = __HYPERVISOR_update_va_mapping_otherdomain; 125 mcl->args[0] = va; 126 #if defined(__x86_64__) 127 mcl->args[1] = new_val; 128 mcl->args[2] = flags; 129 mcl->args[3] = domid; 130 #else 131 mcl->args[1] = (new_val & 0xffffffff); 132 #ifdef PAE 133 mcl->args[2] = (new_val >> 32); 134 #else 135 mcl->args[2] = 0; 136 #endif 137 mcl->args[3] = flags; 138 mcl->args[4] = domid; 139 #endif 140 } 141 #if defined(__x86_64__) 142 #define MULTI_UVMFLAGS_INDEX 2 143 #define MULTI_UVMDOMID_INDEX 3 144 #else 145 #define MULTI_UVMFLAGS_INDEX 3 146 #define MULTI_UVMDOMID_INDEX 4 147 #endif 148 149 #if defined(__x86_64__) 150 void xen_set_user_pgd(paddr_t); 151 #endif 152 153 #endif /* XEN3 */ 154 155 #endif /* _XEN_XENPMAP_H_ */ 156