Rev 879 | Rev 902 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 879 | Rev 901 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Jakub Jermar |
2 | * Copyright (C) 2006 Jakub Jermar |
3 | * Copyright (C) 2006 Jakub Vana |
3 | * Copyright (C) 2006 Jakub Vana |
4 | * All rights reserved. |
4 | * All rights reserved. |
5 | * |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
8 | * are met: |
9 | * |
9 | * |
10 | * - Redistributions of source code must retain the above copyright |
10 | * - Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * - Redistributions in binary form must reproduce the above copyright |
12 | * - Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the |
13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. |
14 | * documentation and/or other materials provided with the distribution. |
15 | * - The name of the author may not be used to endorse or promote products |
15 | * - The name of the author may not be used to endorse or promote products |
16 | * derived from this software without specific prior written permission. |
16 | * derived from this software without specific prior written permission. |
17 | * |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #include <arch/mm/page.h> |
30 | #include <arch/mm/page.h> |
31 | #include <genarch/mm/page_ht.h> |
31 | #include <genarch/mm/page_ht.h> |
32 | #include <mm/asid.h> |
32 | #include <mm/asid.h> |
33 | #include <arch/mm/asid.h> |
33 | #include <arch/mm/asid.h> |
34 | #include <arch/types.h> |
34 | #include <arch/types.h> |
35 | #include <typedefs.h> |
35 | #include <typedefs.h> |
36 | #include <print.h> |
36 | #include <print.h> |
37 | #include <mm/page.h> |
37 | #include <mm/page.h> |
38 | #include <mm/frame.h> |
38 | #include <mm/frame.h> |
39 | #include <config.h> |
39 | #include <config.h> |
40 | #include <panic.h> |
40 | #include <panic.h> |
41 | #include <arch/asm.h> |
41 | #include <arch/asm.h> |
42 | #include <arch/barrier.h> |
42 | #include <arch/barrier.h> |
43 | #include <memstr.h> |
43 | #include <memstr.h> |
44 | 44 | ||
45 | static void set_environment(void); |
45 | static void set_environment(void); |
46 | 46 | ||
47 | /** Initialize ia64 virtual address translation subsystem. */ |
47 | /** Initialize ia64 virtual address translation subsystem. */ |
48 | void page_arch_init(void) |
48 | void page_arch_init(void) |
49 | { |
49 | { |
50 | page_mapping_operations = &ht_mapping_operations; |
50 | page_mapping_operations = &ht_mapping_operations; |
51 | pk_disable(); |
51 | pk_disable(); |
52 | set_environment(); |
52 | set_environment(); |
53 | } |
53 | } |
54 | 54 | ||
55 | /** Initialize VHPT and region registers. */ |
55 | /** Initialize VHPT and region registers. */ |
56 | void set_environment(void) |
56 | void set_environment(void) |
57 | { |
57 | { |
58 | - | ||
59 | region_register rr; |
58 | region_register rr; |
60 | pta_register pta; |
59 | pta_register pta; |
61 | int i; |
60 | int i; |
62 | 61 | ||
63 | /* |
62 | /* |
64 | * First set up kernel region register. |
63 | * First set up kernel region register. |
65 | * This action is redundand (see start.S) but I would to keep it to make sure that |
64 | * This is redundant (see start.S) but we keep it here just for sure. |
66 | *no unexpected changes will be made. |
- | |
67 | */ |
65 | */ |
68 | rr.word = rr_read(VRN_KERNEL); |
66 | rr.word = rr_read(VRN_KERNEL); |
69 | rr.map.ve = 0; /* disable VHPT walker */ |
67 | rr.map.ve = 0; /* disable VHPT walker */ |
70 | rr.map.ps = PAGE_WIDTH; |
68 | rr.map.ps = PAGE_WIDTH; |
71 | rr.map.rid = ASID2RID(ASID_KERNEL,VRN_KERNEL); |
69 | rr.map.rid = ASID2RID(ASID_KERNEL, VRN_KERNEL); |
72 | rr_write(VRN_KERNEL, rr.word); |
70 | rr_write(VRN_KERNEL, rr.word); |
73 | srlz_i(); |
71 | srlz_i(); |
74 | srlz_d(); |
72 | srlz_d(); |
75 | 73 | ||
76 | /* |
74 | /* |
77 | * And invalidate the rest of region register. |
75 | * And invalidate the rest of region register. |
78 | */ |
76 | */ |
79 | for(i = 0; i < REGION_REGISTERS; i++) { |
77 | for(i = 0; i < REGION_REGISTERS; i++) { |
80 | /* skip kernel rr */ |
78 | /* skip kernel rr */ |
81 | if (i == VRN_KERNEL) |
79 | if (i == VRN_KERNEL) |
82 | continue; |
80 | continue; |
83 | 81 | ||
84 | rr.word == rr_read(i); |
82 | rr.word == rr_read(i); |
85 | rr.map.ve = 0; /* disable VHPT walker */ |
83 | rr.map.ve = 0; /* disable VHPT walker */ |
86 | rr.map.rid = ASID2RID(ASID_INVALID,i); |
84 | rr.map.rid = RID_INVALID; |
87 | rr_write(i, rr.word); |
85 | rr_write(i, rr.word); |
88 | srlz_i(); |
86 | srlz_i(); |
89 | srlz_d(); |
87 | srlz_d(); |
90 | } |
88 | } |
91 | 89 | ||
92 | /* |
90 | /* |
93 | * Set up PTA register. |
91 | * Set up PTA register. |
94 | */ |
92 | */ |
95 | pta.word = pta_read(); |
93 | pta.word = pta_read(); |
96 | pta.map.ve = 0; /* disable VHPT walker */ |
94 | pta.map.ve = 0; /* disable VHPT walker */ |
97 | pta.map.vf = 1; /* large entry format */ |
95 | pta.map.vf = 1; /* large entry format */ |
98 | pta.map.size = VHPT_WIDTH; |
96 | pta.map.size = VHPT_WIDTH; |
99 | pta.map.base = VHPT_BASE >> PTA_BASE_SHIFT; |
97 | pta.map.base = VHPT_BASE >> PTA_BASE_SHIFT; |
100 | pta_write(pta.word); |
98 | pta_write(pta.word); |
101 | srlz_i(); |
99 | srlz_i(); |
102 | srlz_d(); |
100 | srlz_d(); |
103 | - | ||
104 | - | ||
105 | return ; |
- | |
106 | - | ||
107 | } |
101 | } |
108 | 102 | ||
109 | /** Calculate address of collision chain from VPN and ASID. |
103 | /** Calculate address of collision chain from VPN and ASID. |
110 | * |
104 | * |
111 | * Interrupts must be disabled. |
105 | * Interrupts must be disabled. |
112 | * |
106 | * |
113 | * @param page Address of virtual page including VRN bits. |
107 | * @param page Address of virtual page including VRN bits. |
114 | * @param asid Address space identifier. |
108 | * @param asid Address space identifier. |
115 | * |
109 | * |
116 | * @return VHPT entry address. |
110 | * @return VHPT entry address. |
117 | */ |
111 | */ |
118 | vhpt_entry_t *vhpt_hash(__address page, asid_t asid) |
112 | vhpt_entry_t *vhpt_hash(__address page, asid_t asid) |
119 | { |
113 | { |
120 | region_register rr_save, rr; |
114 | region_register rr_save, rr; |
121 | index_t vrn; |
115 | index_t vrn; |
122 | rid_t rid; |
116 | rid_t rid; |
123 | vhpt_entry_t *v; |
117 | vhpt_entry_t *v; |
124 | 118 | ||
125 | vrn = page >> VRN_SHIFT; |
119 | vrn = page >> VRN_SHIFT; |
126 | rid = ASID2RID(asid, vrn); |
120 | rid = ASID2RID(asid, vrn); |
127 | 121 | ||
128 | rr_save.word = rr_read(vrn); |
122 | rr_save.word = rr_read(vrn); |
129 | if (rr_save.map.rid == rid) { |
123 | if (rr_save.map.rid == rid) { |
130 | /* |
124 | /* |
131 | * The RID is already in place, compute thash and return. |
125 | * The RID is already in place, compute thash and return. |
132 | */ |
126 | */ |
133 | v = (vhpt_entry_t *) thash(page); |
127 | v = (vhpt_entry_t *) thash(page); |
134 | return v; |
128 | return v; |
135 | } |
129 | } |
136 | 130 | ||
137 | /* |
131 | /* |
138 | * The RID must be written to some region register. |
132 | * The RID must be written to some region register. |
139 | * To speed things up, register indexed by vrn is used. |
133 | * To speed things up, register indexed by vrn is used. |
140 | */ |
134 | */ |
141 | rr.word = rr_save.word; |
135 | rr.word = rr_save.word; |
142 | rr.map.rid = rid; |
136 | rr.map.rid = rid; |
143 | rr_write(vrn, rr.word); |
137 | rr_write(vrn, rr.word); |
144 | srlz_i(); |
138 | srlz_i(); |
145 | v = (vhpt_entry_t *) thash(page); |
139 | v = (vhpt_entry_t *) thash(page); |
146 | rr_write(vrn, rr_save.word); |
140 | rr_write(vrn, rr_save.word); |
147 | srlz_i(); |
141 | srlz_i(); |
148 | srlz_d(); |
142 | srlz_d(); |
149 | 143 | ||
150 | return v; |
144 | return v; |
151 | } |
145 | } |
152 | 146 | ||
153 | /** Compare ASID and VPN against PTE. |
147 | /** Compare ASID and VPN against PTE. |
154 | * |
148 | * |
155 | * Interrupts must be disabled. |
149 | * Interrupts must be disabled. |
156 | * |
150 | * |
157 | * @param page Address of virtual page including VRN bits. |
151 | * @param page Address of virtual page including VRN bits. |
158 | * @param asid Address space identifier. |
152 | * @param asid Address space identifier. |
159 | * |
153 | * |
160 | * @return True if page and asid match the page and asid of t, false otherwise. |
154 | * @return True if page and asid match the page and asid of t, false otherwise. |
161 | */ |
155 | */ |
162 | bool vhpt_compare(__address page, asid_t asid, vhpt_entry_t *v) |
156 | bool vhpt_compare(__address page, asid_t asid, vhpt_entry_t *v) |
163 | { |
157 | { |
164 | region_register rr_save, rr; |
158 | region_register rr_save, rr; |
165 | index_t vrn; |
159 | index_t vrn; |
166 | rid_t rid; |
160 | rid_t rid; |
167 | bool match; |
161 | bool match; |
168 | 162 | ||
169 | ASSERT(v); |
163 | ASSERT(v); |
170 | 164 | ||
171 | vrn = page >> VRN_SHIFT; |
165 | vrn = page >> VRN_SHIFT; |
172 | rid = ASID2RID(asid, vrn); |
166 | rid = ASID2RID(asid, vrn); |
173 | 167 | ||
174 | rr_save.word = rr_read(vrn); |
168 | rr_save.word = rr_read(vrn); |
175 | if (rr_save.map.rid == rid) { |
169 | if (rr_save.map.rid == rid) { |
176 | /* |
170 | /* |
177 | * The RID is already in place, compare ttag with t and return. |
171 | * The RID is already in place, compare ttag with t and return. |
178 | */ |
172 | */ |
179 | return ttag(page) == v->present.tag.tag_word; |
173 | return ttag(page) == v->present.tag.tag_word; |
180 | } |
174 | } |
181 | 175 | ||
182 | /* |
176 | /* |
183 | * The RID must be written to some region register. |
177 | * The RID must be written to some region register. |
184 | * To speed things up, register indexed by vrn is used. |
178 | * To speed things up, register indexed by vrn is used. |
185 | */ |
179 | */ |
186 | rr.word = rr_save.word; |
180 | rr.word = rr_save.word; |
187 | rr.map.rid = rid; |
181 | rr.map.rid = rid; |
188 | rr_write(vrn, rr.word); |
182 | rr_write(vrn, rr.word); |
189 | srlz_i(); |
183 | srlz_i(); |
190 | match = (ttag(page) == v->present.tag.tag_word); |
184 | match = (ttag(page) == v->present.tag.tag_word); |
191 | rr_write(vrn, rr_save.word); |
185 | rr_write(vrn, rr_save.word); |
192 | srlz_i(); |
186 | srlz_i(); |
193 | srlz_d(); |
187 | srlz_d(); |
194 | 188 | ||
195 | return match; |
189 | return match; |
196 | } |
190 | } |
197 | 191 | ||
198 | /** Set up one VHPT entry. |
192 | /** Set up one VHPT entry. |
199 | * |
193 | * |
200 | * @param t VHPT entry to be set up. |
194 | * @param t VHPT entry to be set up. |
201 | * @param page Virtual address of the page mapped by the entry. |
195 | * @param page Virtual address of the page mapped by the entry. |
202 | * @param asid Address space identifier of the address space to which page belongs. |
196 | * @param asid Address space identifier of the address space to which page belongs. |
203 | * @param frame Physical address of the frame to wich page is mapped. |
197 | * @param frame Physical address of the frame to wich page is mapped. |
204 | * @param flags Different flags for the mapping. |
198 | * @param flags Different flags for the mapping. |
205 | */ |
199 | */ |
206 | void vhpt_set_record(vhpt_entry_t *v, __address page, asid_t asid, __address frame, int flags) |
200 | void vhpt_set_record(vhpt_entry_t *v, __address page, asid_t asid, __address frame, int flags) |
207 | { |
201 | { |
208 | region_register rr_save, rr; |
202 | region_register rr_save, rr; |
209 | index_t vrn; |
203 | index_t vrn; |
210 | rid_t rid; |
204 | rid_t rid; |
211 | __u64 tag; |
205 | __u64 tag; |
212 | 206 | ||
213 | ASSERT(v); |
207 | ASSERT(v); |
214 | 208 | ||
215 | vrn = page >> VRN_SHIFT; |
209 | vrn = page >> VRN_SHIFT; |
216 | rid = ASID2RID(asid, vrn); |
210 | rid = ASID2RID(asid, vrn); |
217 | 211 | ||
218 | /* |
212 | /* |
219 | * Compute ttag. |
213 | * Compute ttag. |
220 | */ |
214 | */ |
221 | rr_save.word = rr_read(vrn); |
215 | rr_save.word = rr_read(vrn); |
222 | rr.word = rr_save.word; |
216 | rr.word = rr_save.word; |
223 | rr.map.rid = rid; |
217 | rr.map.rid = rid; |
224 | rr_write(vrn, rr.word); |
218 | rr_write(vrn, rr.word); |
225 | srlz_i(); |
219 | srlz_i(); |
226 | tag = ttag(page); |
220 | tag = ttag(page); |
227 | rr_write(vrn, rr_save.word); |
221 | rr_write(vrn, rr_save.word); |
228 | srlz_i(); |
222 | srlz_i(); |
229 | srlz_d(); |
223 | srlz_d(); |
230 | 224 | ||
231 | /* |
225 | /* |
232 | * Clear the entry. |
226 | * Clear the entry. |
233 | */ |
227 | */ |
234 | v->word[0] = 0; |
228 | v->word[0] = 0; |
235 | v->word[1] = 0; |
229 | v->word[1] = 0; |
236 | v->word[2] = 0; |
230 | v->word[2] = 0; |
237 | v->word[3] = 0; |
231 | v->word[3] = 0; |
238 | 232 | ||
239 | v->present.p = true; |
233 | v->present.p = true; |
240 | v->present.ma = (flags & PAGE_CACHEABLE) ? MA_WRITEBACK : MA_UNCACHEABLE; |
234 | v->present.ma = (flags & PAGE_CACHEABLE) ? MA_WRITEBACK : MA_UNCACHEABLE; |
241 | v->present.a = false; /* not accessed */ |
235 | v->present.a = false; /* not accessed */ |
242 | v->present.d = false; /* not dirty */ |
236 | v->present.d = false; /* not dirty */ |
243 | v->present.pl = (flags & PAGE_USER) ? PL_USER : PL_KERNEL; |
237 | v->present.pl = (flags & PAGE_USER) ? PL_USER : PL_KERNEL; |
244 | v->present.ar = (flags & PAGE_WRITE) ? AR_WRITE : AR_READ; |
238 | v->present.ar = (flags & PAGE_WRITE) ? AR_WRITE : AR_READ; |
245 | v->present.ar |= (flags & PAGE_EXEC) ? AR_EXECUTE : 0; |
239 | v->present.ar |= (flags & PAGE_EXEC) ? AR_EXECUTE : 0; |
246 | v->present.ppn = frame >> PPN_SHIFT; |
240 | v->present.ppn = frame >> PPN_SHIFT; |
247 | v->present.ed = false; /* exception not deffered */ |
241 | v->present.ed = false; /* exception not deffered */ |
248 | v->present.ps = PAGE_WIDTH; |
242 | v->present.ps = PAGE_WIDTH; |
249 | v->present.key = 0; |
243 | v->present.key = 0; |
250 | v->present.tag.tag_word = tag; |
244 | v->present.tag.tag_word = tag; |
251 | } |
245 | } |
252 | 246 |