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