xref: /illumos-gate/usr/src/uts/i86xpv/sys/xen_mmu.h (revision 4eaa471005973e11a6110b69fe990530b3b95a38)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_XEN_MMU_H
27 #define	_SYS_XEN_MMU_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Platform-dependent MMU routines and types for the hypervisor.
35  *
36  * WARNING: this header file is used by both dboot and i86pc, so don't go using
37  * normal kernel headers.
38  */
39 
40 #if (defined(_BOOT) && defined(_BOOT_TARGET_amd64)) || \
41 	(!defined(_BOOT) && defined(__amd64))
42 #define	__target_amd64
43 #endif
44 
45 typedef uint64_t maddr_t;
46 #define	mfn_to_ma(mfn)	((maddr_t)(mfn) << MMU_PAGESHIFT)
47 
48 #ifdef __xpv
49 
50 #ifdef __target_amd64
51 
52 #define	IN_HYPERVISOR_VA(va) \
53 	((va) >= HYPERVISOR_VIRT_START && (va) < HYPERVISOR_VIRT_END)
54 
55 #else /* __target_amd64 */
56 
57 #define	IN_HYPERVISOR_VA(va) ((va) >= xen_virt_start)
58 
59 /*
60  * Do this to help catch any uses.
61  */
62 #undef	HYPERVISOR_VIRT_START
63 #undef	machine_to_phys_mapping
64 
65 #endif /* __target_amd64 */
66 
67 #undef __target_amd64
68 
69 paddr_t ma_to_pa(maddr_t);
70 maddr_t pa_to_ma(paddr_t);
71 #endif /* __xpv */
72 
73 extern uintptr_t xen_virt_start;
74 extern pfn_t *mfn_to_pfn_mapping;
75 
76 #ifndef _BOOT
77 
78 /*
79  * On the hypervisor we need:
80  * - a way to map a machine address (ie, not pseudo-physical).
81  * - to relocate initial hypervisor data structures into kernel VA range.
82  * - a way to translate between physical addresses and machine addresses.
83  * - a way to change the machine address behind a physical address.
84  */
85 typedef ulong_t mfn_t;
86 extern mfn_t *mfn_list;
87 extern mfn_t *mfn_list_pages;
88 extern mfn_t *mfn_list_pages_page;
89 extern ulong_t mfn_count;
90 extern mfn_t cached_max_mfn;
91 
92 /*
93  * locks for mfn_list[] and machine_to_phys_mapping[] when migration / suspend
94  * events happen
95  */
96 extern void xen_block_migrate(void);
97 extern void xen_allow_migrate(void);
98 extern void xen_start_migrate(void);
99 extern void xen_end_migrate(void);
100 
101 /*
102  * Conversion between machine (hardware) addresses and pseudo-physical
103  * addresses.
104  */
105 #ifdef __xpv
106 pfn_t mfn_to_pfn(mfn_t);
107 mfn_t pfn_to_mfn(pfn_t);
108 #endif
109 
110 struct page;
111 
112 void xen_relocate_start_info(void);
113 
114 /*
115  * interfaces to create/destroy pfn_t values for devices or foreign memory
116  *
117  * xen_assign_pfn() creates (or looks up) a local pfn value to use for things
118  * like a foreign domain memory mfn or a device mfn.
119  *
120  * xen_release_pfn() destroys the association between a pfn and foreign mfn.
121  */
122 pfn_t xen_assign_pfn(mfn_t mfn);
123 void xen_release_pfn(pfn_t);
124 uint_t pfn_is_foreign(pfn_t);
125 void reassign_pfn(pfn_t pfn, mfn_t mfn);
126 
127 #define	MFN_INVALID	(-(mfn_t)1)
128 
129 #endif /* !_BOOT */
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif	/* _SYS_XEN_MMU_H */
136