]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/mappings.h
xnu-344.tar.gz
[apple/xnu.git] / osfmk / ppc / mappings.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Header files for the hardware virtual memory mapping stuff
24 */
25 #ifndef _PPC_MAPPINGS_H_
26 #define _PPC_MAPPINGS_H_
27
28 typedef struct PCA { /* PTEG Control Area */
29 unsigned int PCAlock; /* PCA lock */
30 union flgs {
31 unsigned int PCAallo; /* Allocation controls */
32 struct PCAalflgs { /* Keep these in order!!! */
33 unsigned char PCAfree; /* Indicates the slot is free */
34 unsigned char PCAauto; /* Indicates that the PTE was autogenned */
35 unsigned char PCAslck; /* Indicates that the slot is locked */
36 unsigned char PCAsteal; /* Steal scan start position */
37 } PCAalflgs;
38 } flgs;
39 unsigned int PCAgas[6]; /* Filler to 32 byte boundary */
40 unsigned int PCAhash[8]; /* PTEG hash chains */
41 } PCA;
42
43 #define MAPFLAGS 0x0000001F
44 #define BMAP 0x00000001
45
46 typedef struct mapping {
47 struct mapping *next; /* MUST BE FIRST - chain off physent */
48 struct mapping *hashnext; /* Next mapping in same hash group */
49 unsigned int *PTEhash; /* Pointer to the head of the mapping hash list */
50 unsigned int *PTEent; /* Pointer to PTE if exists */
51 struct phys_entry *physent; /* Quick pointer back to the physical entry */
52 unsigned int PTEv; /* Virtual half of HW PTE */
53 unsigned int PTEr; /* Real half of HW PTE. This is used ONLY if
54 there is no physical entry associated
55 with this mapping, ie.e, physent==0 */
56 struct pmap *pmap; /* Quick pointer back to the containing pmap */
57 } mapping;
58
59 /*
60 * This control block maps odd size blocks of memory. The mapping must
61 * be V=F (Virtual = Fixed), i.e., virtually and physically contiguous
62 * multiples of hardware size pages.
63 *
64 * This control block overlays the mapping CB and is allocated from the
65 * same pool.
66 *
67 * It is expected that only a small number of these exist for each address
68 * space and will typically be for I/O areas. It is further assumed that
69 * there is a minimum size (ODDBLKMIN) for these blocks. If smaller, the
70 * block will be split into N normal page mappings.
71 *
72 * Binary tree for fast lookups.
73 */
74
75
76 typedef struct blokmap {
77 struct blokmap *next; /* Next block in list */
78 unsigned int start; /* Start of block */
79 unsigned int end; /* End of block */
80 unsigned int PTEr; /* Real half of HW PTE at base address */
81 unsigned int space; /* Cached VSID */
82 unsigned int blkFlags; /* Flags for this block */
83 #define blkPerm 0x80000000
84 #define blkRem 0x40000000
85 #define blkPermbit 0
86 #define blkRembit 1
87 unsigned int current; /* Partial block remove current start */
88 unsigned int gas4; /* Reserved */
89 } blokmap;
90
91 #define ODDBLKMIN (8 * PAGE_SIZE)
92 #define BLKREMMAX 128
93
94 #define MAPPING_NULL ((struct mapping *) 0)
95
96 #define mapDirect 0x08
97 #define mapRWNA 0x00000000
98 #define mapRWRO 0x00000001
99 #define mapRWRW 0x00000002
100 #define mapRORO 0x00000003
101
102
103 typedef struct mfmapping {
104 struct pmap *pmap;
105 vm_offset_t offset;
106 } mfmapping;
107
108 typedef struct mappingflush {
109 PCA *pcaptr;
110 unsigned int mappingcnt;
111 struct mfmapping mapping[8];
112 } mappingflush;
113
114 typedef struct mappingctl {
115 unsigned int mapclock; /* Mapping allocation lock */
116 unsigned int mapcrecurse; /* Mapping allocation recursion control */
117 struct mappingblok *mapcnext; /* First mapping block with free entries */
118 struct mappingblok *mapclast; /* Last mapping block with free entries */
119 struct mappingblok *mapcrel; /* List of deferred block releases */
120 unsigned int mapcfree; /* Total free entries on list */
121 unsigned int mapcinuse; /* Total entries in use */
122 unsigned int mapcreln; /* Total blocks on pending release list */
123 int mapcholdoff; /* Hold off clearing release list */
124 unsigned int mapcfreec; /* Total calls to mapping free */
125 unsigned int mapcallocc; /* Total calls to mapping alloc */
126 unsigned int mapcmin; /* Minimum free mappings to keep */
127 unsigned int mapcmaxalloc; /* Maximum number of mappings allocated at one time */
128 struct mappingflush mapcflush;
129 unsigned int mapcgas[1]; /* Pad to 64 bytes */
130 } mappingctl;
131
132 #define MAPPERBLOK 127
133 #define MAPALTHRSH (4*MAPPERBLOK)
134 #define MAPFRTHRSH (2 * ((MAPALTHRSH + MAPPERBLOK - 1) / MAPPERBLOK))
135 typedef struct mappingblok {
136 unsigned int mapblokfree[4]; /* Bit map of free mapping entrys */
137 unsigned int mapblokvrswap; /* Virtual address XORed with physical address */
138 unsigned int mapblokflags; /* Various flags */
139 #define mbPerm 0x80000000 /* Block is permanent */
140 struct mappingblok *nextblok; /* Pointer to the next mapping block */
141 } mappingblok;
142
143 extern mappingctl mapCtl; /* Mapping allocation control */
144
145 extern void mapping_phys_init(struct phys_entry *pp, unsigned int pa, unsigned int wimg); /* Initializes hw specific storage attributes */
146 extern boolean_t mapping_remove(pmap_t pmap, vm_offset_t va); /* Remove a single mapping for this VADDR */
147 extern void mapping_free_init(vm_offset_t mbl, int perm, boolean_t locked); /* Sets start and end of a block of mappings */
148 extern void mapping_adjust(void); /* Adjust free mapping count */
149 extern void mapping_free_prime(void); /* Primes the mapping block release list */
150 extern void mapping_prealloc(unsigned int); /* Preallocate mappings for large use */
151 extern void mapping_relpre(void); /* Releases preallocate request */
152 extern void mapping_init(void); /* Do initial stuff */
153 extern void mapping_flush(void);
154 extern mapping *mapping_alloc(void); /* Obtain a mapping */
155 extern void mapping_free(struct mapping *mp); /* Release a mapping */
156 extern boolean_t mapping_tst_ref(struct phys_entry *pp); /* Tests the reference bit of a physical page */
157 extern boolean_t mapping_tst_mod(struct phys_entry *pp); /* Tests the change bit of a physical page */
158 extern void mapping_set_ref(struct phys_entry *pp); /* Sets the reference bit of a physical page */
159 extern void mapping_clr_ref(struct phys_entry *pp); /* Clears the reference bit of a physical page */
160 extern void mapping_set_mod(struct phys_entry *pp); /* Sets the change bit of a physical page */
161 extern void mapping_clr_mod(struct phys_entry *pp); /* Clears the change bit of a physical page */
162 extern void mapping_invall(struct phys_entry *pp); /* Clear all PTEs pointing to a physical page */
163 extern void mapping_protect_phys(struct phys_entry *pp, vm_prot_t prot, boolean_t locked); /* Change protection of all mappings to page */
164 extern void mapping_protect(pmap_t pmap, vm_offset_t vaddr, vm_prot_t prot); /* Change protection of a single mapping to page */
165 extern mapping *mapping_make(pmap_t pmap, struct phys_entry *pp, vm_offset_t va, vm_offset_t pa, vm_prot_t prot, int attr, boolean_t locked); /* Make an address mapping */
166 extern void mapping_purge(struct phys_entry *pp); /* Remove all mappings for this physent */
167 extern void mapping_purge_pmap(struct phys_entry *pp, pmap_t pmap); /* Remove physent mappings for this pmap */
168 extern vm_offset_t mapping_p2v(pmap_t pmap, struct phys_entry *pp); /* Finds first virtual mapping of a physical page in a space */
169 extern void mapping_phys_attr(struct phys_entry *pp, vm_prot_t prot, unsigned int wimg); /* Sets the default physical page attributes */
170 extern void mapping_block_map_opt(pmap_t pmap, vm_offset_t va, vm_offset_t pa, vm_offset_t bnd, vm_size_t size, vm_prot_t prot, int attr); /* Map a block optimally */
171 extern int mapalc(struct mappingblok *mb); /* Finds and allcates a mapping entry */
172 extern void ignore_zero_fault(boolean_t type); /* Sets up to ignore or honor any fault on page 0 access for the current thread */
173
174
175 extern mapping *hw_lock_phys_vir(space_t space, vm_offset_t va); /* Finds and locks a physical entry by vaddr */
176 extern mapping *hw_cpv(struct mapping *mapping); /* Converts a physical mapping control block address to virtual */
177 extern mapping *hw_cvp(struct mapping *mapping); /* Converts a virtual mapping control block address to physical */
178 extern void hw_rem_map(struct mapping *mapping); /* Remove a mapping from the system */
179 extern void hw_add_map(struct mapping *mp, space_t space, vm_offset_t va); /* Add a mapping to the PTEG hash list */
180 extern void hw_select_mappings(struct mappingflush *mappingflush); /* Select user mappings in a PTEG */
181 extern blokmap *hw_rem_blk(pmap_t pmap, vm_offset_t sva, vm_offset_t eva); /* Remove a block that falls within a range */
182 extern vm_offset_t hw_cvp_blk(pmap_t pmap, vm_offset_t va); /* Convert mapped block virtual to physical */
183 extern blokmap *hw_add_blk(pmap_t pmap, struct blokmap *bmr); /* Add a block to the pmap */
184 extern void hw_prot(struct phys_entry *pp, vm_prot_t prot); /* Change the protection of a physical page */
185 extern void hw_prot_virt(struct mapping *mp, vm_prot_t prot); /* Change the protection of a virtual page */
186 extern void hw_attr_virt(struct mapping *mp, unsigned int wimg); /* Change the attributes of a virtual page */
187 extern void hw_phys_attr(struct phys_entry *pp, vm_prot_t prot, unsigned int wimg); /* Sets the default physical page attributes */
188 extern unsigned int hw_test_rc(struct mapping *mp, boolean_t reset); /* Test and optionally reset the RC bit of specific mapping */
189
190 extern boolean_t hw_tst_mod(struct phys_entry *pp); /* Tests change bit */
191 extern void hw_set_mod(struct phys_entry *pp); /* Set change bit */
192 extern void hw_clr_mod(struct phys_entry *pp); /* Clear change bit */
193
194 extern boolean_t hw_tst_ref(struct phys_entry *pp); /* Tests reference bit */
195 extern void hw_set_ref(struct phys_entry *pp); /* Set reference bit */
196 extern void hw_clr_ref(struct phys_entry *pp); /* Clear reference bit */
197
198 extern void hw_inv_all(struct phys_entry *pp); /* Invalidate all PTEs associated with page */
199 extern void hw_set_user_space(pmap_t pmap); /* Indicate we need a space switch */
200 extern void hw_set_user_space_dis(pmap_t pmap); /* Indicate we need a space switch (already disabled) */
201 kern_return_t copyp2v(vm_offset_t source, vm_offset_t sink, unsigned int size); /* Copy a physical page to a virtual address */
202 extern void *LRA(space_t space, void *vaddr); /* Translate virtual to real using only HW tables */
203 extern void dumpaddr(space_t space, vm_offset_t va);
204 extern void dumpmapping(struct mapping *mp); /* Print contents of a mapping */
205 extern void dumppca(struct mapping *mp); /* Print contents of a PCA */
206 extern void dumpphys(struct phys_entry *pp); /* Prints stuff starting at phys */
207
208 extern unsigned int mappingdeb0; /* (TEST/DEBUG) */
209 extern unsigned int incrVSID; /* VSID increment value */
210
211 #endif /* _PPC_MAPPINGS_H_ */
212