1 #ifndef __COMMON_X86_PV_H 2 #define __COMMON_X86_PV_H 3 4 #include "xc_sr_common_x86.h" 5 6 /* Virtual address ranges reserved for hypervisor. */ 7 #define HYPERVISOR_VIRT_START_X86_64 0xFFFF800000000000ULL 8 #define HYPERVISOR_VIRT_END_X86_64 0xFFFF87FFFFFFFFFFULL 9 10 #define HYPERVISOR_VIRT_START_X86_32 0x00000000F5800000ULL 11 #define HYPERVISOR_VIRT_END_X86_32 0x00000000FFFFFFFFULL 12 13 /* 14 * Convert an mfn to a pfn, given Xen's m2p table. 15 * 16 * Caller must ensure that the requested mfn is in range. 17 */ 18 xen_pfn_t mfn_to_pfn(struct xc_sr_context *ctx, xen_pfn_t mfn); 19 20 /* 21 * Query whether a particular mfn is valid in the physmap of a guest. 22 */ 23 bool mfn_in_pseudophysmap(struct xc_sr_context *ctx, xen_pfn_t mfn); 24 25 /* 26 * Debug a particular mfn by walking the p2m and m2p. 27 */ 28 void dump_bad_pseudophysmap_entry(struct xc_sr_context *ctx, xen_pfn_t mfn); 29 30 /* 31 * Convert a PV cr3 field to an mfn. 32 * 33 * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into 34 * a 32bit architectural cr3. 35 */ 36 xen_pfn_t cr3_to_mfn(struct xc_sr_context *ctx, uint64_t cr3); 37 38 /* 39 * Convert an mfn to a PV cr3 field. 40 * 41 * Adjusts for Xen's extended-cr3 format to pack a 44bit physical address into 42 * a 32bit architectural cr3. 43 */ 44 uint64_t mfn_to_cr3(struct xc_sr_context *ctx, xen_pfn_t mfn); 45 46 /* Bits 12 through 51 of a PTE point at the frame */ 47 #define PTE_FRAME_MASK 0x000ffffffffff000ULL 48 49 /* 50 * Extract an mfn from a Pagetable Entry. May return INVALID_MFN if the pte 51 * would overflow a 32bit xen_pfn_t. 52 */ pte_to_frame(uint64_t pte)53static inline xen_pfn_t pte_to_frame(uint64_t pte) 54 { 55 uint64_t frame = (pte & PTE_FRAME_MASK) >> PAGE_SHIFT; 56 57 #ifdef __i386__ 58 if ( frame >= INVALID_MFN ) 59 return INVALID_MFN; 60 #endif 61 62 return frame; 63 } 64 65 /* 66 * Change the frame in a Pagetable Entry while leaving the flags alone. 67 */ merge_pte(uint64_t pte,xen_pfn_t mfn)68static inline uint64_t merge_pte(uint64_t pte, xen_pfn_t mfn) 69 { 70 return (pte & ~PTE_FRAME_MASK) | ((uint64_t)mfn << PAGE_SHIFT); 71 } 72 73 /* 74 * Get current domain information. 75 * 76 * Fills ctx->x86_pv 77 * - .width 78 * - .levels 79 * - .fpp 80 * - .p2m_frames 81 * 82 * Used by the save side to create the X86_PV_INFO record, and by the restore 83 * side to verify the incoming stream. 84 * 85 * Returns 0 on success and non-zero on error. 86 */ 87 int x86_pv_domain_info(struct xc_sr_context *ctx); 88 89 /* 90 * Maps the Xen M2P. 91 * 92 * Fills ctx->x86_pv. 93 * - .max_mfn 94 * - .m2p 95 * 96 * Returns 0 on success and non-zero on error. 97 */ 98 int x86_pv_map_m2p(struct xc_sr_context *ctx); 99 100 #endif 101 /* 102 * Local variables: 103 * mode: C 104 * c-file-style: "BSD" 105 * c-basic-offset: 4 106 * tab-width: 4 107 * indent-tabs-mode: nil 108 * End: 109 */ 110