]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pmap.h
xnu-344.21.73.tar.gz
[apple/xnu.git] / osfmk / ppc / pmap.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Copyright (c) 1990 The University of Utah and
30 * the Center for Software Science at the University of Utah (CSS).
31 * All rights reserved.
32 *
33 * Permission to use, copy, modify and distribute this software is hereby
34 * granted provided that (1) source code retains these copyright, permission,
35 * and disclaimer notices, and (2) redistributions including binaries
36 * reproduce the notices in supporting documentation, and (3) all advertising
37 * materials mentioning features or use of this software display the following
38 * acknowledgement: ``This product includes software developed by the Center
39 * for Software Science at the University of Utah.''
40 *
41 * THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
42 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
43 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
44 *
45 * CSS requests users of this software to return to css-dist@cs.utah.edu any
46 * improvements that they make and grant CSS redistribution rights.
47 *
48 * Utah $Hdr: pmap.h 1.13 91/09/25$
49 * Author: Mike Hibler, Bob Wheeler, University of Utah CSS, 9/90
50 */
51
52 #ifndef _PPC_PMAP_H_
53 #define _PPC_PMAP_H_
54
55 #include <mach/vm_types.h>
56 #include <mach/machine/vm_types.h>
57 #include <mach/vm_prot.h>
58 #include <mach/vm_statistics.h>
59 #include <kern/queue.h>
60 #include <vm/pmap.h>
61
62 #define maxPPage32 0x000FFFFF /* Maximum page number in 32-bit machines */
63
64 typedef uint32_t shexlock;
65
66 #pragma pack(4) /* Make sure the structure stays as we defined it */
67
68 struct sgc {
69 uint64_t sgcESID; /* ESID portion of segment cache */
70 #define sgcESmsk 0xFFFFFFFFF0000000ULL /* ESID portion of segment register cache */
71 uint64_t sgcVSID; /* VSID portion of segment cache */
72 #define sgcVSmsk 0xFFFFFFFFFFFFF000ULL /* VSID mask */
73 #define sgcVSKeys 0x0000000000000C00ULL /* Protection keys */
74 #define sgcVSKeyUsr 53 /* User protection key */
75 #define sgcVSNoEx 0x0000000000000200ULL /* No execute */
76 };
77 #pragma pack()
78
79 typedef struct sgc sgc;
80
81 #pragma pack(4) /* Make sure the structure stays as we defined it */
82 struct pmap {
83 queue_head_t pmap_link; /* MUST BE FIRST */
84 addr64_t pmapvr; /* Virtual to real conversion mask */
85 shexlock pmapSXlk; /* Shared/Exclusive lock for mapping changes */
86 unsigned int space; /* space for this pmap */
87 #define invalSpace 0x00000001 /* Predefined always invalid space */
88 int ref_count; /* reference count */
89 unsigned int pmapFlags; /* Flags */
90 #define pmapKeys 0x00000007 /* Keys and no execute bit to use with this pmap */
91 #define pmapKeyDef 0x00000006 /* Default keys - Sup = 1, user = 1, no ex = 0 */
92 #define pmapVMhost 0x00000010 /* pmap with Virtual Machines attached to it */
93 unsigned int spaceNum; /* Space number */
94 unsigned int pmapCCtl; /* Cache control */
95 #define pmapCCtlVal 0xFFFF0000 /* Valid entries */
96 #define pmapCCtlLck 0x00008000 /* Lock bit */
97 #define pmapCCtlLckb 16 /* Lock bit */
98 #define pmapCCtlGen 0x00007FFF /* Generation number */
99
100 #define pmapSegCacheCnt 16 /* Maximum number of cache entries */
101 #define pmapSegCacheUse 16 /* Number of cache entries to use */
102
103 struct pmap *freepmap; /* Free pmaps */
104
105 unsigned int pmapRsv1[3];
106 /* 0x038 */
107 uint64_t pmapSCSubTag; /* Segment cache sub-tags. This is a 16 entry 4 bit array */
108 /* 0x040 */
109 sgc pmapSegCache[pmapSegCacheCnt]; /* SLD values cached for quick load */
110
111 /* 0x140 */
112 /* if fanout is 4, then shift is 1, if fanout is 8 shift is 2, etc */
113 #define kSkipListFanoutShift 1
114 /* with n lists, we can handle (fanout**n) pages optimally */
115 #define kSkipListMaxLists 12
116 unsigned char pmapCurLists; /* 0x140 - max #lists any mapping in this pmap currently has */
117 unsigned char pmapRsv2[3];
118 uint32_t pmapRandNum; /* 0x144 - used by mapSetLists() as a random number generator */
119 addr64_t pmapSkipLists[kSkipListMaxLists]; /* 0x148 - the list headers */
120 /* following statistics conditionally gathered */
121 uint64_t pmapSearchVisits; /* 0x1A8 - nodes visited searching pmaps */
122 uint32_t pmapSearchCnt; /* 0x1B0 - number of calls to mapSearch or mapSearchFull */
123
124 unsigned int pmapRsv3[3];
125
126 /* 0x1C0 */
127
128 struct pmap_statistics stats; /* statistics */
129 decl_simple_lock_data(,lock) /* lock on map */
130
131 /* Need to pad out to a power of 2 - right now it is 512 bytes */
132 #define pmapSize 512
133 };
134 #pragma pack()
135
136 #pragma pack(4)
137 struct pmapTransTab {
138 addr64_t pmapPAddr; /* Physcial address of pmap */
139 unsigned int pmapVAddr; /* Virtual address of pmap */
140 };
141 #pragma pack() /* Make sure the structure stays as we defined it */
142
143 typedef struct pmapTransTab pmapTransTab;
144
145 #define PMAP_NULL ((pmap_t) 0)
146
147 extern pmap_t kernel_pmap; /* The kernel's map */
148 extern pmap_t cursor_pmap; /* The pmap to start allocations with */
149 extern pmap_t sharedPmap;
150 extern unsigned int sharedPage;
151 extern int ppc_max_adrsp; /* Maximum number of concurrent address spaces allowed. */
152 extern addr64_t vm_max_address; /* Maximum effective address supported */
153 extern addr64_t vm_max_physical; /* Maximum physical address supported */
154 extern pmapTransTab *pmapTrans; /* Space to pmap translate table */
155 #define PMAP_SWITCH_USER(th, map, my_cpu) th->map = map;
156
157 #define PMAP_ACTIVATE(pmap, th, cpu)
158 #define PMAP_DEACTIVATE(pmap, th, cpu)
159 #define PMAP_CONTEXT(pmap,th)
160
161 #define pmap_kernel_va(VA) \
162 (((VA) >= VM_MIN_KERNEL_ADDRESS) && ((VA) <= vm_last_addr))
163
164 #define PPC_SID_KERNEL 0 /* Must change KERNEL_SEG_REG0_VALUE if !0 */
165
166 #define maxAdrSp 16384
167 #define maxAdrSpb 14
168 #define copyIOaddr 0x00000000E0000000ULL
169
170 #define pmap_kernel() (kernel_pmap)
171 #define pmap_resident_count(pmap) ((pmap)->stats.resident_count)
172 #define pmap_remove_attributes(pmap,start,end)
173 #define pmap_copy(dpmap,spmap,da,len,sa)
174 #define pmap_update()
175
176 #define PMAP_DEFAULT_CACHE 0
177 #define PMAP_INHIBIT_CACHE 1
178 #define PMAP_GUARDED_CACHE 2
179 #define PMAP_ACTIVATE_CACHE 4
180 #define PMAP_NO_GUARD_CACHE 8
181
182 /* corresponds to cached, coherent, not writethru, not guarded */
183 #define VM_WIMG_DEFAULT (VM_MEM_COHERENT)
184 #define VM_WIMG_COPYBACK (VM_MEM_COHERENT)
185 #define VM_WIMG_IO (VM_MEM_COHERENT | \
186 VM_MEM_NOT_CACHEABLE | VM_MEM_GUARDED)
187 #define VM_WIMG_WTHRU (VM_MEM_WRITE_THROUGH | VM_MEM_COHERENT | VM_MEM_GUARDED)
188 /* write combining mode, aka store gather */
189 #define VM_WIMG_WCOMB (VM_MEM_NOT_CACHEABLE | VM_MEM_COHERENT)
190
191 /*
192 * prototypes.
193 */
194 extern vm_offset_t phystokv(vm_offset_t pa); /* Get kernel virtual address from physical */
195 extern vm_offset_t kvtophys(vm_offset_t va); /* Get physical address from kernel virtual */
196 extern vm_offset_t pmap_map(vm_offset_t va,
197 vm_offset_t spa,
198 vm_offset_t epa,
199 vm_prot_t prot);
200 extern kern_return_t pmap_add_physical_memory(vm_offset_t spa,
201 vm_offset_t epa,
202 boolean_t available,
203 unsigned int attr);
204 extern void pmap_bootstrap(uint64_t msize,
205 vm_offset_t *first_avail,
206 unsigned int kmapsize);
207 extern void pmap_switch(pmap_t);
208
209 extern vm_offset_t pmap_extract(pmap_t pmap,
210 vm_offset_t va);
211
212 extern void pmap_remove_all(vm_offset_t pa);
213
214 extern boolean_t pmap_verify_free(ppnum_t pa);
215 extern void sync_cache(vm_offset_t pa, unsigned length);
216 extern void sync_cache64(addr64_t pa, unsigned length);
217 extern void sync_ppage(ppnum_t pa);
218 extern void sync_cache_virtual(vm_offset_t va, unsigned length);
219 extern void flush_dcache(vm_offset_t va, unsigned length, boolean_t phys);
220 extern void flush_dcache64(addr64_t va, unsigned length, boolean_t phys);
221 extern void invalidate_dcache(vm_offset_t va, unsigned length, boolean_t phys);
222 extern void invalidate_dcache64(addr64_t va, unsigned length, boolean_t phys);
223 extern void invalidate_icache(vm_offset_t va, unsigned length, boolean_t phys);
224 extern void invalidate_icache64(addr64_t va, unsigned length, boolean_t phys);
225 extern void pmap_sync_caches_phys(ppnum_t pa);
226 extern void pmap_map_block(pmap_t pmap, addr64_t va, ppnum_t pa, vm_size_t size, vm_prot_t prot, int attr, unsigned int flags);
227 extern int pmap_map_block_rc(pmap_t pmap, addr64_t va, ppnum_t pa, vm_size_t size, vm_prot_t prot, int attr, unsigned int flags);
228
229 extern kern_return_t pmap_nest(pmap_t grand, pmap_t subord, addr64_t vstart, addr64_t nstart, uint64_t size);
230 extern ppnum_t pmap_find_phys(pmap_t pmap, addr64_t va);
231 extern addr64_t MapUserAddressSpace(vm_map_t map, addr64_t va, unsigned int size);
232 extern void ReleaseUserAddressSpace(addr64_t kva);
233 extern kern_return_t pmap_attribute_cache_sync(ppnum_t pp, vm_size_t size,
234 vm_machine_attribute_t attribute,
235 vm_machine_attribute_val_t* value);
236 extern int pmap_canExecute(ppnum_t pa);
237
238 #endif /* _PPC_PMAP_H_ */
239