]>
Commit | Line | Data |
---|---|---|
1c79356b A |
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 blkPermbit 0 | |
85 | unsigned int gas3; /* Reserved */ | |
86 | unsigned int gas4; /* Reserved */ | |
87 | } blokmap; | |
88 | ||
89 | #define ODDBLKMIN (8 * PAGE_SIZE) | |
90 | ||
91 | #define MAPPING_NULL ((struct mapping *) 0) | |
92 | ||
0b4e3aa0 A |
93 | #define mapDirect 0x08 |
94 | #define mapRWNA 0x00000000 | |
95 | #define mapRWRO 0x00000001 | |
96 | #define mapRWRW 0x00000002 | |
97 | #define mapRORO 0x00000003 | |
98 | ||
99 | ||
1c79356b A |
100 | typedef struct mappingctl { |
101 | unsigned int mapclock; /* Mapping allocation lock */ | |
102 | unsigned int mapcrecurse; /* Mapping allocation recursion control */ | |
103 | struct mappingblok *mapcnext; /* First mapping block with free entries */ | |
104 | struct mappingblok *mapclast; /* Last mapping block with free entries */ | |
105 | struct mappingblok *mapcrel; /* List of deferred block releases */ | |
106 | unsigned int mapcfree; /* Total free entries on list */ | |
107 | unsigned int mapcinuse; /* Total entries in use */ | |
108 | unsigned int mapcreln; /* Total blocks on pending release list */ | |
109 | int mapcholdoff; /* Hold off clearing release list */ | |
110 | unsigned int mapcfreec; /* Total calls to mapping free */ | |
111 | unsigned int mapcallocc; /* Total calls to mapping alloc */ | |
112 | unsigned int mapcmin; /* Minimum free mappings to keep */ | |
113 | unsigned int mapcmaxalloc; /* Maximum number of mappings allocated at one time */ | |
114 | unsigned int mapcgas[3]; /* Pad to 64 bytes */ | |
115 | } mappingctl; | |
116 | ||
117 | #define MAPPERBLOK 127 | |
118 | #define MAPALTHRSH (4*MAPPERBLOK) | |
119 | #define MAPFRTHRSH (2 * ((MAPALTHRSH + MAPPERBLOK - 1) / MAPPERBLOK)) | |
120 | typedef struct mappingblok { | |
121 | unsigned int mapblokfree[4]; /* Bit map of free mapping entrys */ | |
122 | unsigned int mapblokvrswap; /* Virtual address XORed with physical address */ | |
123 | unsigned int mapblokflags; /* Various flags */ | |
124 | #define mbPerm 0x80000000 /* Block is permanent */ | |
125 | struct mappingblok *nextblok; /* Pointer to the next mapping block */ | |
126 | } mappingblok; | |
127 | ||
128 | extern mappingctl mapCtl; /* Mapping allocation control */ | |
129 | ||
130 | extern void mapping_phys_init(struct phys_entry *pp, unsigned int pa, unsigned int wimg); /* Initializes hw specific storage attributes */ | |
131 | extern boolean_t mapping_remove(pmap_t pmap, vm_offset_t va); /* Remove a single mapping for this VADDR */ | |
132 | extern void mapping_free_init(vm_offset_t mbl, int perm, boolean_t locked); /* Sets start and end of a block of mappings */ | |
133 | extern void mapping_adjust(void); /* Adjust free mapping count */ | |
134 | extern void mapping_free_prime(void); /* Primes the mapping block release list */ | |
135 | extern void mapping_prealloc(unsigned int); /* Preallocate mappings for large use */ | |
136 | extern void mapping_relpre(void); /* Releases preallocate request */ | |
137 | extern void mapping_init(void); /* Do initial stuff */ | |
138 | extern mapping *mapping_alloc(void); /* Obtain a mapping */ | |
139 | extern void mapping_free(struct mapping *mp); /* Release a mapping */ | |
140 | extern boolean_t mapping_tst_ref(struct phys_entry *pp); /* Tests the reference bit of a physical page */ | |
141 | extern boolean_t mapping_tst_mod(struct phys_entry *pp); /* Tests the change bit of a physical page */ | |
142 | extern void mapping_set_ref(struct phys_entry *pp); /* Sets the reference bit of a physical page */ | |
143 | extern void mapping_clr_ref(struct phys_entry *pp); /* Clears the reference bit of a physical page */ | |
144 | extern void mapping_set_mod(struct phys_entry *pp); /* Sets the change bit of a physical page */ | |
145 | extern void mapping_clr_mod(struct phys_entry *pp); /* Clears the change bit of a physical page */ | |
146 | extern void mapping_invall(struct phys_entry *pp); /* Clear all PTEs pointing to a physical page */ | |
147 | extern void mapping_protect_phys(struct phys_entry *pp, vm_prot_t prot, boolean_t locked); /* Change protection of all mappings to page */ | |
148 | extern void mapping_protect(pmap_t pmap, vm_offset_t vaddr, vm_prot_t prot); /* Change protection of a single mapping to page */ | |
149 | 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 */ | |
150 | extern void mapping_purge(struct phys_entry *pp); /* Remove all mappings for this physent */ | |
0b4e3aa0 | 151 | extern void mapping_purge_pmap(struct phys_entry *pp, pmap_t pmap); /* Remove physent mappings for this pmap */ |
1c79356b A |
152 | extern vm_offset_t mapping_p2v(pmap_t pmap, struct phys_entry *pp); /* Finds first virtual mapping of a physical page in a space */ |
153 | extern void mapping_phys_attr(struct phys_entry *pp, vm_prot_t prot, unsigned int wimg); /* Sets the default physical page attributes */ | |
154 | 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 */ | |
155 | extern int mapalc(struct mappingblok *mb); /* Finds and allcates a mapping entry */ | |
156 | extern void ignore_zero_fault(boolean_t type); /* Sets up to ignore or honor any fault on page 0 access for the current thread */ | |
157 | ||
158 | ||
159 | extern mapping *hw_lock_phys_vir(space_t space, vm_offset_t va); /* Finds and locks a physical entry by vaddr */ | |
160 | extern mapping *hw_cpv(struct mapping *mapping); /* Converts a physical mapping control block address to virtual */ | |
161 | extern mapping *hw_cvp(struct mapping *mapping); /* Converts a virtual mapping control block address to physical */ | |
162 | extern void hw_rem_map(struct mapping *mapping); /* Remove a mapping from the system */ | |
163 | extern void hw_add_map(struct mapping *mp, space_t space, vm_offset_t va); /* Add a mapping to the PTEG hash list */ | |
164 | extern blokmap *hw_rem_blk(pmap_t pmap, vm_offset_t sva, vm_offset_t eva); /* Remove a block that falls within a range */ | |
165 | extern vm_offset_t hw_cvp_blk(pmap_t pmap, vm_offset_t va); /* Convert mapped block virtual to physical */ | |
166 | extern blokmap *hw_add_blk(pmap_t pmap, struct blokmap *bmr); /* Add a block to the pmap */ | |
167 | extern void hw_prot(struct phys_entry *pp, vm_prot_t prot); /* Change the protection of a physical page */ | |
168 | extern void hw_prot_virt(struct mapping *mp, vm_prot_t prot); /* Change the protection of a virtual page */ | |
169 | extern void hw_attr_virt(struct mapping *mp, unsigned int wimg); /* Change the attributes of a virtual page */ | |
170 | extern void hw_phys_attr(struct phys_entry *pp, vm_prot_t prot, unsigned int wimg); /* Sets the default physical page attributes */ | |
171 | extern unsigned int hw_test_rc(struct mapping *mp, boolean_t reset); /* Test and optionally reset the RC bit of specific mapping */ | |
172 | ||
173 | extern boolean_t hw_tst_mod(struct phys_entry *pp); /* Tests change bit */ | |
174 | extern void hw_set_mod(struct phys_entry *pp); /* Set change bit */ | |
175 | extern void hw_clr_mod(struct phys_entry *pp); /* Clear change bit */ | |
176 | ||
177 | extern boolean_t hw_tst_ref(struct phys_entry *pp); /* Tests reference bit */ | |
178 | extern void hw_set_ref(struct phys_entry *pp); /* Set reference bit */ | |
179 | extern void hw_clr_ref(struct phys_entry *pp); /* Clear reference bit */ | |
180 | ||
181 | extern void hw_inv_all(struct phys_entry *pp); /* Invalidate all PTEs associated with page */ | |
182 | extern void hw_set_user_space(pmap_t pmap); /* Indicate we need a space switch */ | |
183 | extern void hw_set_user_space_dis(pmap_t pmap); /* Indicate we need a space switch (already disabled) */ | |
184 | kern_return_t copyp2v(vm_offset_t source, vm_offset_t sink, unsigned int size); /* Copy a physical page to a virtual address */ | |
185 | extern void *LRA(space_t space, void *vaddr); /* Translate virtual to real using only HW tables */ | |
186 | extern void dumpaddr(space_t space, vm_offset_t va); | |
187 | extern void dumpmapping(struct mapping *mp); /* Print contents of a mapping */ | |
188 | extern void dumppca(struct mapping *mp); /* Print contents of a PCA */ | |
189 | extern void dumpphys(struct phys_entry *pp); /* Prints stuff starting at phys */ | |
190 | ||
191 | extern unsigned int mappingdeb0; /* (TEST/DEBUG) */ | |
192 | extern unsigned int incrVSID; /* VSID increment value */ | |
193 | ||
194 | #endif /* _PPC_MAPPINGS_H_ */ | |
195 |