2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Copyright (c) 1990 The University of Utah and
28 * the Center for Software Science at the University of Utah (CSS).
29 * All rights reserved.
31 * Permission to use, copy, modify and distribute this software is hereby
32 * granted provided that (1) source code retains these copyright, permission,
33 * and disclaimer notices, and (2) redistributions including binaries
34 * reproduce the notices in supporting documentation, and (3) all advertising
35 * materials mentioning features or use of this software display the following
36 * acknowledgement: ``This product includes software developed by the Center
37 * for Software Science at the University of Utah.''
39 * THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
40 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
41 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * CSS requests users of this software to return to css-dist@cs.utah.edu any
44 * improvements that they make and grant CSS redistribution rights.
46 * Utah $Hdr: pmap.h 1.13 91/09/25$
47 * Author: Mike Hibler, Bob Wheeler, University of Utah CSS, 9/90
53 #include <mach/vm_types.h>
54 #include <mach/machine/vm_types.h>
55 #include <mach/vm_prot.h>
56 #include <mach/vm_statistics.h>
57 #include <kern/queue.h>
59 #include <ppc/mappings.h>
61 #define maxPPage32 0x000FFFFF /* Maximum page number in 32-bit machines */
63 typedef uint32_t shexlock
;
65 #pragma pack(4) /* Make sure the structure stays as we defined it */
68 uint64_t sgcESID
; /* ESID portion of segment cache */
69 #define sgcESmsk 0xFFFFFFFFF0000000ULL /* ESID portion of segment register cache */
70 uint64_t sgcVSID
; /* VSID portion of segment cache */
71 #define sgcVSmsk 0xFFFFFFFFFFFFF000ULL /* VSID mask */
72 #define sgcVSKeys 0x0000000000000C00ULL /* Protection keys */
73 #define sgcVSKeyUsr 53 /* User protection key */
74 #define sgcVSNoEx 0x0000000000000200ULL /* No execute */
78 typedef struct sgc sgc
;
80 #pragma pack(4) /* Make sure the structure stays as we defined it */
81 struct pmap_vmm_stats
{
82 unsigned int vxsGpf
; /* Guest faults */
83 unsigned int vxsGpfMiss
; /* Faults that miss in hash table */
85 unsigned int vxsGrm
; /* Guest mapping remove requests */
86 unsigned int vxsGrmMiss
; /* Remove misses in hash table */
87 unsigned int vxsGrmActive
; /* Remove hits that are active */
89 unsigned int vxsGra
; /* Guest remove all mappings requests */
90 unsigned int vxsGraHits
; /* Remove hits in hash table */
91 unsigned int vxsGraActive
; /* Remove hits that are active */
93 unsigned int vxsGrl
; /* Guest remove local mappings requests */
94 unsigned int vxsGrlActive
; /* Active mappings removed */
96 unsigned int vxsGrs
; /* Guest mapping resumes */
97 unsigned int vxsGrsHitAct
; /* Resume hits active entry */
98 unsigned int vxsGrsHitSusp
; /* Resume hits suspended entry */
99 unsigned int vxsGrsMissGV
; /* Resume misses on guest virtual */
100 unsigned int vxsGrsHitPE
; /* Resume hits on host virtual */
101 unsigned int vxsGrsMissPE
; /* Resume misses on host virtual */
103 unsigned int vxsGad
; /* Guest mapping adds */
104 unsigned int vxsGadHit
; /* Add hits entry (active or dormant) */
105 unsigned int vxsGadFree
; /* Add takes free entry in group */
106 unsigned int vxsGadDormant
; /* Add steals dormant entry in group */
107 unsigned int vxsGadSteal
; /* Add steals active entry in group */
109 unsigned int vxsGsu
; /* Guest mapping suspends */
110 unsigned int vxsGsuHit
; /* Suspend hits entry (active only) */
111 unsigned int vxsGsuMiss
; /* Suspend misses entry */
113 unsigned int vxsGtd
; /* Guest test ref&chg */
114 unsigned int vxsGtdHit
; /* Test r&c hits entry (active only) */
115 unsigned int vxsGtdMiss
; /* Test r&c misses entry */
118 typedef struct pmap_vmm_stats pmap_vmm_stats
;
120 /* Not wanting to tax all of our customers for the sins of those that use virtual operating
121 systems, we've built the hash table from its own primitive virtual memory. We first
122 allocate a pmap_vmm_ext with sufficient space following to accomodate the hash table
123 index (one 64-bit physical address per 4k-byte page of hash table). The allocation
124 must not cross a 4k-byte page boundary (we'll be accessing the block with relocation
125 off), so we'll try a couple of times, then just burn a whole page. We stuff the effective
126 address of the cache-aligned index into hIdxBase; the physical-mode code locates the index
127 by adding the size of a pmap_vmm_extension to its translated physical address, then rounding
128 up to the next 32-byte boundary. Now we grab enough virtual pages to contain the hash table,
129 and fill in the index with the page's physical addresses. For the final touch that's sure
130 to please, we initialize the hash table. Mmmmm, golden brown perfection.
134 struct pmap_vmm_ext
{
135 addr64_t vmxSalt
; /* This block's virt<->real conversion salt */
136 addr64_t vmxHostPmapPhys
; /* Host pmap physical address */
137 struct pmap
*vmxHostPmap
; /* Host pmap effective address */
138 addr64_t
*vmxHashPgIdx
; /* Hash table physical index base address */
139 vm_offset_t
*vmxHashPgList
; /* List of virtual pages comprising the hash table */
140 unsigned int *vmxActiveBitmap
; /* Bitmap of active mappings in hash table */
141 pmap_vmm_stats vmxStats
; /* Stats for VMM assists */
142 #define VMX_HPIDX_OFFSET ((sizeof(pmap_vmm_ext) + 127) & ~127)
143 /* The hash table physical index begins at the first
144 128-byte boundary after the pmap_vmm_ext struct */
145 #define VMX_HPLIST_OFFSET (VMX_HPIDX_OFFSET + (GV_HPAGES * sizeof(addr64_t)))
146 #define VMX_ACTMAP_OFFSET (VMX_HPLIST_OFFSET + (GV_HPAGES * sizeof(vm_offset_t)))
149 typedef struct pmap_vmm_ext pmap_vmm_ext
;
151 #pragma pack(4) /* Make sure the structure stays as we defined it */
153 queue_head_t pmap_link
; /* MUST BE FIRST */
154 addr64_t pmapvr
; /* Virtual to real conversion mask */
155 shexlock pmapSXlk
; /* Shared/Exclusive lock for mapping changes */
156 unsigned int space
; /* space for this pmap */
157 #define invalSpace 0x00000001 /* Predefined always invalid space */
158 int ref_count
; /* reference count */
159 unsigned int pmapFlags
; /* Flags */
160 #define pmapKeys 0x00000007 /* Keys and no execute bit to use with this pmap */
161 #define pmapKeyDef 0x00000006 /* Default keys - Sup = 1, user = 1, no ex = 0 */
162 #define pmapVMhost 0x00000010 /* pmap with Virtual Machines attached to it */
163 #define pmapVMgsaa 0x00000020 /* Guest shadow assist active */
164 unsigned int spaceNum
; /* Space number */
165 unsigned int pmapCCtl
; /* Cache control */
166 #define pmapCCtlVal 0xFFFF0000 /* Valid entries */
167 #define pmapCCtlLck 0x00008000 /* Lock bit */
168 #define pmapCCtlLckb 16 /* Lock bit */
169 #define pmapCCtlGen 0x00007FFF /* Generation number */
171 #define pmapSegCacheCnt 16 /* Maximum number of cache entries */
172 #define pmapSegCacheUse 16 /* Number of cache entries to use */
174 struct pmap
*freepmap
; /* Free pmaps */
175 pmap_vmm_ext
*pmapVmmExt
; /* VMM extension block, for VMM host and guest pmaps */
176 addr64_t pmapVmmExtPhys
; /* VMM extension block physical address */
178 uint64_t pmapSCSubTag
; /* Segment cache sub-tags. This is a 16 entry 4 bit array */
180 sgc pmapSegCache
[pmapSegCacheCnt
]; /* SLD values cached for quick load */
183 /* if fanout is 4, then shift is 1, if fanout is 8 shift is 2, etc */
184 #define kSkipListFanoutShift 1
185 /* with n lists, we can handle (fanout**n) pages optimally */
186 #define kSkipListMaxLists 12
187 unsigned char pmapCurLists
; /* 0x140 - max #lists any mapping in this pmap currently has */
188 unsigned char pmapRsv2
[3];
189 uint32_t pmapRandNum
; /* 0x144 - used by mapSetLists() as a random number generator */
190 addr64_t pmapSkipLists
[kSkipListMaxLists
]; /* 0x148 - the list headers */
191 /* following statistics conditionally gathered */
192 uint64_t pmapSearchVisits
; /* 0x1A8 - nodes visited searching pmaps */
193 uint32_t pmapSearchCnt
; /* 0x1B0 - number of calls to mapSearch or mapSearchFull */
195 unsigned int pmapRsv3
[3];
199 struct pmap_statistics stats
; /* statistics */
201 /* Need to pad out to a power of 2 - right now it is 512 bytes */
207 struct pmapTransTab
{
208 addr64_t pmapPAddr
; /* Physcial address of pmap */
209 unsigned int pmapVAddr
; /* Virtual address of pmap */
211 #pragma pack() /* Make sure the structure stays as we defined it */
213 typedef struct pmapTransTab pmapTransTab
;
216 * Address Chunk IDentified Table
220 unsigned int acidVAddr
; /* Virtual address of pmap or pointer to next free entry */
221 unsigned int acidGas
; /* reserved */
222 addr64_t acidPAddr
; /* Physcial address of pmap */
225 typedef struct acidTabEnt acidTabEnt
;
227 extern acidTabEnt
*acidTab
; /* Pointer to acid table */
228 extern acidTabEnt
*acidFree
; /* List of free acid entries */
230 #define PMAP_NULL ((pmap_t) 0)
232 extern pmap_t cursor_pmap
; /* The pmap to start allocations with */
233 extern pmap_t sharedPmap
;
234 extern unsigned int sharedPage
;
235 extern int ppc_max_adrsp
; /* Maximum number of concurrent address spaces allowed. */
236 extern addr64_t vm_max_address
; /* Maximum effective address supported */
237 extern addr64_t vm_max_physical
; /* Maximum physical address supported */
238 extern pmapTransTab
*pmapTrans
; /* Space to pmap translate table */
239 #define PMAP_SWITCH_USER(th, map, my_cpu) th->map = map;
241 #define PMAP_CONTEXT(pmap,th)
243 #define pmap_kernel_va(VA) \
244 (((VA) >= VM_MIN_KERNEL_ADDRESS) && ((VA) <= vm_last_addr))
246 #define PPC_SID_KERNEL 0 /* Must change KERNEL_SEG_REG0_VALUE if !0 */
248 #define maxAdrSp 16384
250 #define USER_MEM_WINDOW_VADDR 0x00000000E0000000ULL
251 #define PHYS_MEM_WINDOW_VADDR 0x0000000100000000ULL
252 #define IO_MEM_WINDOW_VADDR 0x0000000080000000ULL
253 #define IO_MEM_WINDOW_SIZE 0x0000000080000000ULL
254 #define pmapSmallBlock 65536
256 #define pmap_kernel() (kernel_pmap)
257 #define pmap_resident_count(pmap) ((pmap)->stats.resident_count)
258 #define pmap_remove_attributes(pmap,start,end)
259 #define pmap_copy(dpmap,spmap,da,len,sa)
260 #define pmap_update()
262 #define PMAP_DEFAULT_CACHE 0
263 #define PMAP_INHIBIT_CACHE 1
264 #define PMAP_GUARDED_CACHE 2
265 #define PMAP_ACTIVATE_CACHE 4
266 #define PMAP_NO_GUARD_CACHE 8
268 /* corresponds to cached, coherent, not writethru, not guarded */
269 #define VM_WIMG_DEFAULT (VM_MEM_COHERENT)
270 #define VM_WIMG_COPYBACK (VM_MEM_COHERENT)
271 #define VM_WIMG_IO (VM_MEM_COHERENT | \
272 VM_MEM_NOT_CACHEABLE | VM_MEM_GUARDED)
273 #define VM_WIMG_WTHRU (VM_MEM_WRITE_THROUGH | VM_MEM_COHERENT | VM_MEM_GUARDED)
274 /* write combining mode, aka store gather */
275 #define VM_WIMG_WCOMB (VM_MEM_NOT_CACHEABLE | VM_MEM_COHERENT)
280 extern vm_offset_t
phystokv(vm_offset_t pa
); /* Get kernel virtual address from physical */
281 extern vm_offset_t
kvtophys(vm_offset_t va
); /* Get physical address from kernel virtual */
282 extern vm_offset_t
pmap_map(vm_offset_t va
,
286 extern kern_return_t
pmap_add_physical_memory(vm_offset_t spa
,
290 extern void pmap_bootstrap(uint64_t msize
,
291 vm_offset_t
*first_avail
,
292 unsigned int kmapsize
);
294 extern vm_offset_t
pmap_boot_map(vm_size_t size
);
296 extern void sync_cache64(addr64_t pa
, unsigned length
);
297 extern void sync_ppage(ppnum_t pa
);
298 extern void sync_cache_virtual(vm_offset_t va
, unsigned length
);
299 extern void flush_dcache(vm_offset_t va
, unsigned length
, boolean_t phys
);
300 extern void flush_dcache64(addr64_t va
, unsigned length
, boolean_t phys
);
301 extern void invalidate_dcache(vm_offset_t va
, unsigned length
, boolean_t phys
);
302 extern void invalidate_dcache64(addr64_t va
, unsigned length
, boolean_t phys
);
303 extern void invalidate_icache(vm_offset_t va
, unsigned length
, boolean_t phys
);
304 extern void invalidate_icache64(addr64_t va
, unsigned length
, boolean_t phys
);
305 extern void pmap_sync_page_data_phys(ppnum_t pa
);
306 extern void pmap_sync_page_attributes_phys(ppnum_t pa
);
307 extern void pmap_map_block(pmap_t pmap
, addr64_t va
, ppnum_t pa
, uint32_t size
, vm_prot_t prot
, int attr
, unsigned int flags
);
308 extern int pmap_map_block_rc(pmap_t pmap
, addr64_t va
, ppnum_t pa
, uint32_t size
, vm_prot_t prot
, int attr
, unsigned int flags
);
310 extern kern_return_t
pmap_nest(pmap_t grand
, pmap_t subord
, addr64_t vstart
, addr64_t nstart
, uint64_t size
);
311 extern kern_return_t
pmap_unnest(pmap_t grand
, addr64_t vaddr
);
312 extern ppnum_t
pmap_find_phys(pmap_t pmap
, addr64_t va
);
313 extern void MapUserMemoryWindowInit(void);
314 extern addr64_t
MapUserMemoryWindow(vm_map_t map
, addr64_t va
);
315 extern boolean_t
pmap_eligible_for_execute(ppnum_t pa
);
316 extern int pmap_list_resident_pages(
320 extern void pmap_init_sharedpage(vm_offset_t cpg
);
321 extern void pmap_map_sharedpage(task_t task
, pmap_t pmap
);
322 extern void pmap_unmap_sharedpage(pmap_t pmap
);
326 #endif /* _PPC_PMAP_H_ */