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