| 1 | /****************************************************************************** |
|---|
| 2 | * include/asm-x86/hap.h |
|---|
| 3 | * |
|---|
| 4 | * hardware-assisted paging |
|---|
| 5 | * Copyright (c) 2007 Advanced Micro Devices (Wei Huang) |
|---|
| 6 | * |
|---|
| 7 | * Parts of this code are Copyright (c) 2006 by XenSource Inc. |
|---|
| 8 | * Parts of this code are Copyright (c) 2006 by Michael A Fetterman |
|---|
| 9 | * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al. |
|---|
| 10 | * |
|---|
| 11 | * This program is free software; you can redistribute it and/or modify |
|---|
| 12 | * it under the terms of the GNU General Public License as published by |
|---|
| 13 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 14 | * (at your option) any later version. |
|---|
| 15 | * |
|---|
| 16 | * This program is distributed in the hope that it will be useful, |
|---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 19 | * GNU General Public License for more details. |
|---|
| 20 | * |
|---|
| 21 | * You should have received a copy of the GNU General Public License |
|---|
| 22 | * along with this program; if not, write to the Free Software |
|---|
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 24 | */ |
|---|
| 25 | |
|---|
| 26 | #ifndef _XEN_HAP_H |
|---|
| 27 | #define _XEN_HAP_H |
|---|
| 28 | |
|---|
| 29 | #define HERE_I_AM \ |
|---|
| 30 | debugtrace_printk("HERE I AM: %s %s %d\n", __func__, __FILE__, __LINE__) |
|---|
| 31 | #define HAP_PRINTK(_f, _a...) \ |
|---|
| 32 | debugtrace_printk("hap: %s(): " _f, __func__, ##_a) |
|---|
| 33 | #define HAP_ERROR(_f, _a...) \ |
|---|
| 34 | printk("hap error: %s(): " _f, __func__, ##_a) |
|---|
| 35 | |
|---|
| 36 | /************************************************/ |
|---|
| 37 | /* hap domain page mapping */ |
|---|
| 38 | /************************************************/ |
|---|
| 39 | static inline void * |
|---|
| 40 | hap_map_domain_page(mfn_t mfn) |
|---|
| 41 | { |
|---|
| 42 | return map_domain_page(mfn_x(mfn)); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | static inline void |
|---|
| 46 | hap_unmap_domain_page(void *p) |
|---|
| 47 | { |
|---|
| 48 | unmap_domain_page(p); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | static inline void * |
|---|
| 52 | hap_map_domain_page_global(mfn_t mfn) |
|---|
| 53 | { |
|---|
| 54 | return map_domain_page_global(mfn_x(mfn)); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | static inline void |
|---|
| 58 | hap_unmap_domain_page_global(void *p) |
|---|
| 59 | { |
|---|
| 60 | unmap_domain_page_global(p); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | /************************************************/ |
|---|
| 64 | /* locking for hap code */ |
|---|
| 65 | /************************************************/ |
|---|
| 66 | #define hap_lock_init(_d) \ |
|---|
| 67 | do { \ |
|---|
| 68 | spin_lock_init(&(_d)->arch.paging.hap.lock); \ |
|---|
| 69 | (_d)->arch.paging.hap.locker = -1; \ |
|---|
| 70 | (_d)->arch.paging.hap.locker_function = "nobody"; \ |
|---|
| 71 | } while (0) |
|---|
| 72 | |
|---|
| 73 | #define hap_locked_by_me(_d) \ |
|---|
| 74 | (current->processor == (_d)->arch.paging.hap.locker) |
|---|
| 75 | |
|---|
| 76 | #define hap_lock(_d) \ |
|---|
| 77 | do { \ |
|---|
| 78 | if ( unlikely((_d)->arch.paging.hap.locker == current->processor) )\ |
|---|
| 79 | { \ |
|---|
| 80 | printk("Error: hap lock held by %s\n", \ |
|---|
| 81 | (_d)->arch.paging.hap.locker_function); \ |
|---|
| 82 | BUG(); \ |
|---|
| 83 | } \ |
|---|
| 84 | spin_lock(&(_d)->arch.paging.hap.lock); \ |
|---|
| 85 | ASSERT((_d)->arch.paging.hap.locker == -1); \ |
|---|
| 86 | (_d)->arch.paging.hap.locker = current->processor; \ |
|---|
| 87 | (_d)->arch.paging.hap.locker_function = __func__; \ |
|---|
| 88 | } while (0) |
|---|
| 89 | |
|---|
| 90 | #define hap_unlock(_d) \ |
|---|
| 91 | do { \ |
|---|
| 92 | ASSERT((_d)->arch.paging.hap.locker == current->processor); \ |
|---|
| 93 | (_d)->arch.paging.hap.locker = -1; \ |
|---|
| 94 | (_d)->arch.paging.hap.locker_function = "nobody"; \ |
|---|
| 95 | spin_unlock(&(_d)->arch.paging.hap.lock); \ |
|---|
| 96 | } while (0) |
|---|
| 97 | |
|---|
| 98 | /************************************************/ |
|---|
| 99 | /* hap domain level functions */ |
|---|
| 100 | /************************************************/ |
|---|
| 101 | void hap_domain_init(struct domain *d); |
|---|
| 102 | int hap_domctl(struct domain *d, xen_domctl_shadow_op_t *sc, |
|---|
| 103 | XEN_GUEST_HANDLE(void) u_domctl); |
|---|
| 104 | int hap_enable(struct domain *d, u32 mode); |
|---|
| 105 | void hap_final_teardown(struct domain *d); |
|---|
| 106 | void hap_teardown(struct domain *d); |
|---|
| 107 | void hap_vcpu_init(struct vcpu *v); |
|---|
| 108 | |
|---|
| 109 | extern struct paging_mode hap_paging_real_mode; |
|---|
| 110 | extern struct paging_mode hap_paging_protected_mode; |
|---|
| 111 | extern struct paging_mode hap_paging_pae_mode; |
|---|
| 112 | extern struct paging_mode hap_paging_long_mode; |
|---|
| 113 | #endif /* XEN_HAP_H */ |
|---|
| 114 | |
|---|
| 115 | /* |
|---|
| 116 | * Local variables: |
|---|
| 117 | * mode: C |
|---|
| 118 | * c-set-style: "BSD" |
|---|
| 119 | * c-basic-offset: 4 |
|---|
| 120 | * indent-tabs-mode: nil |
|---|
| 121 | * End: |
|---|
| 122 | */ |
|---|