]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ppc/pmap.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / ppc / pmap.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
ff6e181a
A
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
11 * file.
1c79356b 12 *
ff6e181a
A
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
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
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.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * @OSF_COPYRIGHT@
25 */
26/*
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.
30 *
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.''
38 *
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.
42 *
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.
45 *
46 * Utah $Hdr: pmap.h 1.13 91/09/25$
47 * Author: Mike Hibler, Bob Wheeler, University of Utah CSS, 9/90
48 */
49
50#ifndef _PPC_PMAP_H_
51#define _PPC_PMAP_H_
52
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>
58#include <vm/pmap.h>
91447636 59#include <ppc/mappings.h>
1c79356b 60
55e303ae
A
61#define maxPPage32 0x000FFFFF /* Maximum page number in 32-bit machines */
62
63typedef uint32_t shexlock;
64
65#pragma pack(4) /* Make sure the structure stays as we defined it */
66
67struct sgc {
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 */
75};
76#pragma pack()
77
78typedef struct sgc sgc;
79
91447636
A
80#pragma pack(4) /* Make sure the structure stays as we defined it */
81struct pmap_vmm_stats {
82 unsigned int vxsGpf; /* Guest faults */
83 unsigned int vxsGpfMiss; /* Faults that miss in hash table */
84
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 */
88
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 */
92
93 unsigned int vxsGrl; /* Guest remove local mappings requests */
94 unsigned int vxsGrlActive; /* Active mappings removed */
95
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 */
102
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 */
108
109 unsigned int vxsGsu; /* Guest mapping suspends */
110 unsigned int vxsGsuHit; /* Suspend hits entry (active only) */
111 unsigned int vxsGsuMiss; /* Suspend misses entry */
112
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 */
116};
117#pragma pack()
118typedef struct pmap_vmm_stats pmap_vmm_stats;
119
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.
131 */
132
133#pragma pack(4)
134struct 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)))
147};
148#pragma pack()
149typedef struct pmap_vmm_ext pmap_vmm_ext;
150
55e303ae 151#pragma pack(4) /* Make sure the structure stays as we defined it */
1c79356b 152struct pmap {
55e303ae
A
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 */
91447636 163#define pmapVMgsaa 0x00000020 /* Guest shadow assist active */
55e303ae
A
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 */
170
171#define pmapSegCacheCnt 16 /* Maximum number of cache entries */
172#define pmapSegCacheUse 16 /* Number of cache entries to use */
173
174 struct pmap *freepmap; /* Free pmaps */
91447636
A
175 pmap_vmm_ext *pmapVmmExt; /* VMM extension block, for VMM host and guest pmaps */
176 addr64_t pmapVmmExtPhys; /* VMM extension block physical address */
55e303ae
A
177/* 0x038 */
178 uint64_t pmapSCSubTag; /* Segment cache sub-tags. This is a 16 entry 4 bit array */
179/* 0x040 */
180 sgc pmapSegCache[pmapSegCacheCnt]; /* SLD values cached for quick load */
181
182/* 0x140 */
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 */
194
195 unsigned int pmapRsv3[3];
196
197/* 0x1C0 */
198
199 struct pmap_statistics stats; /* statistics */
1c79356b
A
200
201/* Need to pad out to a power of 2 - right now it is 512 bytes */
202#define pmapSize 512
203};
55e303ae
A
204#pragma pack()
205
206#pragma pack(4)
207struct pmapTransTab {
208 addr64_t pmapPAddr; /* Physcial address of pmap */
209 unsigned int pmapVAddr; /* Virtual address of pmap */
210};
211#pragma pack() /* Make sure the structure stays as we defined it */
212
213typedef struct pmapTransTab pmapTransTab;
1c79356b 214
91447636
A
215/*
216 * Address Chunk IDentified Table
217 */
218
219struct acidTabEnt {
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 */
223};
224
225typedef struct acidTabEnt acidTabEnt;
226
227extern acidTabEnt *acidTab; /* Pointer to acid table */
228extern acidTabEnt *acidFree; /* List of free acid entries */
229
1c79356b
A
230#define PMAP_NULL ((pmap_t) 0)
231
1c79356b 232extern pmap_t cursor_pmap; /* The pmap to start allocations with */
55e303ae
A
233extern pmap_t sharedPmap;
234extern unsigned int sharedPage;
235extern int ppc_max_adrsp; /* Maximum number of concurrent address spaces allowed. */
236extern addr64_t vm_max_address; /* Maximum effective address supported */
237extern addr64_t vm_max_physical; /* Maximum physical address supported */
238extern pmapTransTab *pmapTrans; /* Space to pmap translate table */
1c79356b
A
239#define PMAP_SWITCH_USER(th, map, my_cpu) th->map = map;
240
1c79356b
A
241#define PMAP_CONTEXT(pmap,th)
242
243#define pmap_kernel_va(VA) \
55e303ae 244 (((VA) >= VM_MIN_KERNEL_ADDRESS) && ((VA) <= vm_last_addr))
1c79356b
A
245
246#define PPC_SID_KERNEL 0 /* Must change KERNEL_SEG_REG0_VALUE if !0 */
55e303ae
A
247
248#define maxAdrSp 16384
249#define maxAdrSpb 14
91447636
A
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
3a60a9f5 254#define pmapSmallBlock 65536
1c79356b
A
255
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()
261
9bccf70c
A
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
267
268/* corresponds to cached, coherent, not writethru, not guarded */
55e303ae
A
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)
9bccf70c 276
1c79356b
A
277/*
278 * prototypes.
279 */
1c79356b
A
280extern vm_offset_t phystokv(vm_offset_t pa); /* Get kernel virtual address from physical */
281extern vm_offset_t kvtophys(vm_offset_t va); /* Get physical address from kernel virtual */
282extern vm_offset_t pmap_map(vm_offset_t va,
283 vm_offset_t spa,
284 vm_offset_t epa,
285 vm_prot_t prot);
286extern kern_return_t pmap_add_physical_memory(vm_offset_t spa,
287 vm_offset_t epa,
288 boolean_t available,
289 unsigned int attr);
55e303ae 290extern void pmap_bootstrap(uint64_t msize,
1c79356b 291 vm_offset_t *first_avail,
55e303ae 292 unsigned int kmapsize);
1c79356b 293
91447636 294extern vm_offset_t pmap_boot_map(vm_size_t size);
1c79356b 295
55e303ae
A
296extern void sync_cache64(addr64_t pa, unsigned length);
297extern void sync_ppage(ppnum_t pa);
298extern void sync_cache_virtual(vm_offset_t va, unsigned length);
1c79356b 299extern void flush_dcache(vm_offset_t va, unsigned length, boolean_t phys);
55e303ae 300extern void flush_dcache64(addr64_t va, unsigned length, boolean_t phys);
1c79356b 301extern void invalidate_dcache(vm_offset_t va, unsigned length, boolean_t phys);
55e303ae 302extern void invalidate_dcache64(addr64_t va, unsigned length, boolean_t phys);
1c79356b 303extern void invalidate_icache(vm_offset_t va, unsigned length, boolean_t phys);
55e303ae 304extern void invalidate_icache64(addr64_t va, unsigned length, boolean_t phys);
91447636
A
305extern void pmap_sync_page_data_phys(ppnum_t pa);
306extern void pmap_sync_page_attributes_phys(ppnum_t pa);
3a60a9f5
A
307extern 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);
308extern 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);
55e303ae
A
309
310extern kern_return_t pmap_nest(pmap_t grand, pmap_t subord, addr64_t vstart, addr64_t nstart, uint64_t size);
91447636 311extern kern_return_t pmap_unnest(pmap_t grand, addr64_t vaddr);
55e303ae 312extern ppnum_t pmap_find_phys(pmap_t pmap, addr64_t va);
91447636
A
313extern void MapUserMemoryWindowInit(void);
314extern addr64_t MapUserMemoryWindow(vm_map_t map, addr64_t va);
315extern boolean_t pmap_eligible_for_execute(ppnum_t pa);
316extern int pmap_list_resident_pages(
317 struct pmap *pmap,
318 vm_offset_t *listp,
319 int space);
320extern void pmap_init_sharedpage(vm_offset_t cpg);
321extern void pmap_map_sharedpage(task_t task, pmap_t pmap);
322extern void pmap_unmap_sharedpage(pmap_t pmap);
323
324
1c79356b
A
325
326#endif /* _PPC_PMAP_H_ */
327