Rev 1822 | Rev 1851 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
418 | jermar | 1 | /* |
2 | * Copyright (C) 2005 Jakub Jermar |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions |
||
7 | * are met: |
||
8 | * |
||
9 | * - Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * - Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * - The name of the author may not be used to endorse or promote products |
||
15 | * derived from this software without specific prior written permission. |
||
16 | * |
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
||
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
27 | */ |
||
28 | |||
1822 | jermar | 29 | /** @addtogroup sparc64mm |
1702 | cejka | 30 | * @{ |
31 | */ |
||
32 | /** @file |
||
33 | */ |
||
34 | |||
418 | jermar | 35 | #ifndef __sparc64_TLB_H__ |
36 | #define __sparc64_TLB_H__ |
||
37 | |||
530 | jermar | 38 | |
569 | jermar | 39 | #define ITLB_ENTRY_COUNT 64 |
40 | #define DTLB_ENTRY_COUNT 64 |
||
41 | |||
1823 | jermar | 42 | #define MEM_CONTEXT_KERNEL 0 |
43 | #define MEM_CONTEXT_TEMP 1 |
||
44 | |||
619 | jermar | 45 | /** Page sizes. */ |
46 | #define PAGESIZE_8K 0 |
||
47 | #define PAGESIZE_64K 1 |
||
48 | #define PAGESIZE_512K 2 |
||
49 | #define PAGESIZE_4M 3 |
||
531 | jermar | 50 | |
901 | jermar | 51 | /** Bit width of the TLB-locked portion of kernel address space. */ |
52 | #define KERNEL_PAGE_WIDTH 22 /* 4M */ |
||
53 | |||
1823 | jermar | 54 | /* TLB Demap Operation types. */ |
55 | #define TLB_DEMAP_PAGE 0 |
||
56 | #define TLB_DEMAP_CONTEXT 1 |
||
57 | |||
58 | #define TLB_DEMAP_TYPE_SHIFT 6 |
||
59 | |||
60 | /* TLB Demap Operation Context register encodings. */ |
||
61 | #define TLB_DEMAP_PRIMARY 0 |
||
62 | #define TLB_DEMAP_SECONDARY 1 |
||
63 | #define TLB_DEMAP_NUCLEUS 2 |
||
64 | |||
65 | #define TLB_DEMAP_CONTEXT_SHIFT 4 |
||
66 | |||
67 | /* TLB Tag Access shifts */ |
||
68 | #define TLB_TAG_ACCESS_CONTEXT_SHIFT 0 |
||
69 | #define TLB_TAG_ACCESS_VPN_SHIFT 13 |
||
70 | |||
71 | #ifndef __ASM__ |
||
72 | |||
73 | #include <arch/mm/tte.h> |
||
74 | #include <arch/mm/mmu.h> |
||
75 | #include <arch/mm/page.h> |
||
76 | #include <arch/asm.h> |
||
77 | #include <arch/barrier.h> |
||
78 | #include <arch/types.h> |
||
79 | #include <typedefs.h> |
||
80 | |||
873 | jermar | 81 | union tlb_context_reg { |
1780 | jermar | 82 | uint64_t v; |
873 | jermar | 83 | struct { |
84 | unsigned long : 51; |
||
85 | unsigned context : 13; /**< Context/ASID. */ |
||
86 | } __attribute__ ((packed)); |
||
87 | }; |
||
88 | typedef union tlb_context_reg tlb_context_reg_t; |
||
89 | |||
530 | jermar | 90 | /** I-/D-TLB Data In/Access Register type. */ |
91 | typedef tte_data_t tlb_data_t; |
||
92 | |||
569 | jermar | 93 | /** I-/D-TLB Data Access Address in Alternate Space. */ |
94 | union tlb_data_access_addr { |
||
1780 | jermar | 95 | uint64_t value; |
569 | jermar | 96 | struct { |
1780 | jermar | 97 | uint64_t : 55; |
569 | jermar | 98 | unsigned tlb_entry : 6; |
99 | unsigned : 3; |
||
100 | } __attribute__ ((packed)); |
||
101 | }; |
||
102 | typedef union tlb_data_access_addr tlb_data_access_addr_t; |
||
103 | typedef union tlb_data_access_addr tlb_tag_read_addr_t; |
||
418 | jermar | 104 | |
569 | jermar | 105 | /** I-/D-TLB Tag Read Register. */ |
106 | union tlb_tag_read_reg { |
||
1780 | jermar | 107 | uint64_t value; |
569 | jermar | 108 | struct { |
1780 | jermar | 109 | uint64_t vpn : 51; /**< Virtual Address bits 63:13. */ |
569 | jermar | 110 | unsigned context : 13; /**< Context identifier. */ |
111 | } __attribute__ ((packed)); |
||
112 | }; |
||
113 | typedef union tlb_tag_read_reg tlb_tag_read_reg_t; |
||
613 | jermar | 114 | typedef union tlb_tag_read_reg tlb_tag_access_reg_t; |
569 | jermar | 115 | |
617 | jermar | 116 | |
117 | /** TLB Demap Operation Address. */ |
||
118 | union tlb_demap_addr { |
||
1780 | jermar | 119 | uint64_t value; |
617 | jermar | 120 | struct { |
1780 | jermar | 121 | uint64_t vpn: 51; /**< Virtual Address bits 63:13. */ |
617 | jermar | 122 | unsigned : 6; /**< Ignored. */ |
123 | unsigned type : 1; /**< The type of demap operation. */ |
||
124 | unsigned context : 2; /**< Context register selection. */ |
||
125 | unsigned : 4; /**< Zero. */ |
||
126 | } __attribute__ ((packed)); |
||
127 | }; |
||
128 | typedef union tlb_demap_addr tlb_demap_addr_t; |
||
129 | |||
873 | jermar | 130 | /** TLB Synchronous Fault Status Register. */ |
131 | union tlb_sfsr_reg { |
||
1780 | jermar | 132 | uint64_t value; |
873 | jermar | 133 | struct { |
134 | unsigned long : 39; /**< Implementation dependent. */ |
||
135 | unsigned nf : 1; /**< Nonfaulting load. */ |
||
136 | unsigned asi : 8; /**< ASI. */ |
||
137 | unsigned tm : 1; /**< TLB miss. */ |
||
877 | jermar | 138 | unsigned : 1; |
139 | unsigned ft : 7; /**< Fault type. */ |
||
873 | jermar | 140 | unsigned e : 1; /**< Side-effect bit. */ |
141 | unsigned ct : 2; /**< Context Register selection. */ |
||
142 | unsigned pr : 1; /**< Privilege bit. */ |
||
143 | unsigned w : 1; /**< Write bit. */ |
||
144 | unsigned ow : 1; /**< Overwrite bit. */ |
||
877 | jermar | 145 | unsigned fv : 1; /**< Fault Valid bit. */ |
873 | jermar | 146 | } __attribute__ ((packed)); |
147 | }; |
||
148 | typedef union tlb_sfsr_reg tlb_sfsr_reg_t; |
||
149 | |||
150 | /** Read MMU Primary Context Register. |
||
151 | * |
||
152 | * @return Current value of Primary Context Register. |
||
153 | */ |
||
1780 | jermar | 154 | static inline uint64_t mmu_primary_context_read(void) |
873 | jermar | 155 | { |
156 | return asi_u64_read(ASI_DMMU, VA_PRIMARY_CONTEXT_REG); |
||
157 | } |
||
158 | |||
159 | /** Write MMU Primary Context Register. |
||
160 | * |
||
161 | * @param v New value of Primary Context Register. |
||
162 | */ |
||
1780 | jermar | 163 | static inline void mmu_primary_context_write(uint64_t v) |
873 | jermar | 164 | { |
165 | asi_u64_write(ASI_DMMU, VA_PRIMARY_CONTEXT_REG, v); |
||
166 | flush(); |
||
167 | } |
||
168 | |||
169 | /** Read MMU Secondary Context Register. |
||
170 | * |
||
171 | * @return Current value of Secondary Context Register. |
||
172 | */ |
||
1780 | jermar | 173 | static inline uint64_t mmu_secondary_context_read(void) |
873 | jermar | 174 | { |
175 | return asi_u64_read(ASI_DMMU, VA_SECONDARY_CONTEXT_REG); |
||
176 | } |
||
177 | |||
178 | /** Write MMU Primary Context Register. |
||
179 | * |
||
180 | * @param v New value of Primary Context Register. |
||
181 | */ |
||
1780 | jermar | 182 | static inline void mmu_secondary_context_write(uint64_t v) |
873 | jermar | 183 | { |
184 | asi_u64_write(ASI_DMMU, VA_PRIMARY_CONTEXT_REG, v); |
||
185 | flush(); |
||
186 | } |
||
187 | |||
569 | jermar | 188 | /** Read IMMU TLB Data Access Register. |
189 | * |
||
190 | * @param entry TLB Entry index. |
||
191 | * |
||
192 | * @return Current value of specified IMMU TLB Data Access Register. |
||
193 | */ |
||
1780 | jermar | 194 | static inline uint64_t itlb_data_access_read(index_t entry) |
569 | jermar | 195 | { |
196 | tlb_data_access_addr_t reg; |
||
197 | |||
198 | reg.value = 0; |
||
199 | reg.tlb_entry = entry; |
||
200 | return asi_u64_read(ASI_ITLB_DATA_ACCESS_REG, reg.value); |
||
201 | } |
||
202 | |||
617 | jermar | 203 | /** Write IMMU TLB Data Access Register. |
204 | * |
||
205 | * @param entry TLB Entry index. |
||
206 | * @param value Value to be written. |
||
207 | */ |
||
1780 | jermar | 208 | static inline void itlb_data_access_write(index_t entry, uint64_t value) |
617 | jermar | 209 | { |
210 | tlb_data_access_addr_t reg; |
||
211 | |||
212 | reg.value = 0; |
||
213 | reg.tlb_entry = entry; |
||
214 | asi_u64_write(ASI_ITLB_DATA_ACCESS_REG, reg.value, value); |
||
215 | flush(); |
||
216 | } |
||
217 | |||
569 | jermar | 218 | /** Read DMMU TLB Data Access Register. |
219 | * |
||
220 | * @param entry TLB Entry index. |
||
221 | * |
||
222 | * @return Current value of specified DMMU TLB Data Access Register. |
||
223 | */ |
||
1780 | jermar | 224 | static inline uint64_t dtlb_data_access_read(index_t entry) |
569 | jermar | 225 | { |
226 | tlb_data_access_addr_t reg; |
||
227 | |||
228 | reg.value = 0; |
||
229 | reg.tlb_entry = entry; |
||
230 | return asi_u64_read(ASI_DTLB_DATA_ACCESS_REG, reg.value); |
||
231 | } |
||
232 | |||
617 | jermar | 233 | /** Write DMMU TLB Data Access Register. |
234 | * |
||
235 | * @param entry TLB Entry index. |
||
236 | * @param value Value to be written. |
||
237 | */ |
||
1780 | jermar | 238 | static inline void dtlb_data_access_write(index_t entry, uint64_t value) |
617 | jermar | 239 | { |
240 | tlb_data_access_addr_t reg; |
||
241 | |||
242 | reg.value = 0; |
||
243 | reg.tlb_entry = entry; |
||
244 | asi_u64_write(ASI_DTLB_DATA_ACCESS_REG, reg.value, value); |
||
1822 | jermar | 245 | membar(); |
617 | jermar | 246 | } |
247 | |||
569 | jermar | 248 | /** Read IMMU TLB Tag Read Register. |
249 | * |
||
250 | * @param entry TLB Entry index. |
||
251 | * |
||
252 | * @return Current value of specified IMMU TLB Tag Read Register. |
||
253 | */ |
||
1780 | jermar | 254 | static inline uint64_t itlb_tag_read_read(index_t entry) |
569 | jermar | 255 | { |
256 | tlb_tag_read_addr_t tag; |
||
257 | |||
258 | tag.value = 0; |
||
259 | tag.tlb_entry = entry; |
||
260 | return asi_u64_read(ASI_ITLB_TAG_READ_REG, tag.value); |
||
261 | } |
||
262 | |||
263 | /** Read DMMU TLB Tag Read Register. |
||
264 | * |
||
265 | * @param entry TLB Entry index. |
||
266 | * |
||
267 | * @return Current value of specified DMMU TLB Tag Read Register. |
||
268 | */ |
||
1780 | jermar | 269 | static inline uint64_t dtlb_tag_read_read(index_t entry) |
569 | jermar | 270 | { |
271 | tlb_tag_read_addr_t tag; |
||
272 | |||
273 | tag.value = 0; |
||
274 | tag.tlb_entry = entry; |
||
275 | return asi_u64_read(ASI_DTLB_TAG_READ_REG, tag.value); |
||
276 | } |
||
277 | |||
613 | jermar | 278 | /** Write IMMU TLB Tag Access Register. |
279 | * |
||
280 | * @param v Value to be written. |
||
281 | */ |
||
1780 | jermar | 282 | static inline void itlb_tag_access_write(uint64_t v) |
613 | jermar | 283 | { |
284 | asi_u64_write(ASI_IMMU, VA_IMMU_TAG_ACCESS, v); |
||
285 | flush(); |
||
286 | } |
||
287 | |||
877 | jermar | 288 | /** Read IMMU TLB Tag Access Register. |
289 | * |
||
290 | * @return Current value of IMMU TLB Tag Access Register. |
||
291 | */ |
||
1780 | jermar | 292 | static inline uint64_t itlb_tag_access_read(void) |
877 | jermar | 293 | { |
294 | return asi_u64_read(ASI_IMMU, VA_IMMU_TAG_ACCESS); |
||
295 | } |
||
296 | |||
613 | jermar | 297 | /** Write DMMU TLB Tag Access Register. |
298 | * |
||
299 | * @param v Value to be written. |
||
300 | */ |
||
1780 | jermar | 301 | static inline void dtlb_tag_access_write(uint64_t v) |
613 | jermar | 302 | { |
303 | asi_u64_write(ASI_DMMU, VA_DMMU_TAG_ACCESS, v); |
||
1822 | jermar | 304 | membar(); |
613 | jermar | 305 | } |
306 | |||
877 | jermar | 307 | /** Read DMMU TLB Tag Access Register. |
308 | * |
||
309 | * @return Current value of DMMU TLB Tag Access Register. |
||
310 | */ |
||
1780 | jermar | 311 | static inline uint64_t dtlb_tag_access_read(void) |
877 | jermar | 312 | { |
313 | return asi_u64_read(ASI_DMMU, VA_DMMU_TAG_ACCESS); |
||
314 | } |
||
315 | |||
316 | |||
613 | jermar | 317 | /** Write IMMU TLB Data in Register. |
318 | * |
||
319 | * @param v Value to be written. |
||
320 | */ |
||
1780 | jermar | 321 | static inline void itlb_data_in_write(uint64_t v) |
613 | jermar | 322 | { |
323 | asi_u64_write(ASI_ITLB_DATA_IN_REG, 0, v); |
||
324 | flush(); |
||
325 | } |
||
326 | |||
327 | /** Write DMMU TLB Data in Register. |
||
328 | * |
||
329 | * @param v Value to be written. |
||
330 | */ |
||
1780 | jermar | 331 | static inline void dtlb_data_in_write(uint64_t v) |
613 | jermar | 332 | { |
333 | asi_u64_write(ASI_DTLB_DATA_IN_REG, 0, v); |
||
1822 | jermar | 334 | membar(); |
613 | jermar | 335 | } |
336 | |||
873 | jermar | 337 | /** Read ITLB Synchronous Fault Status Register. |
338 | * |
||
339 | * @return Current content of I-SFSR register. |
||
340 | */ |
||
1780 | jermar | 341 | static inline uint64_t itlb_sfsr_read(void) |
873 | jermar | 342 | { |
343 | return asi_u64_read(ASI_IMMU, VA_IMMU_SFSR); |
||
344 | } |
||
345 | |||
346 | /** Write ITLB Synchronous Fault Status Register. |
||
347 | * |
||
348 | * @param v New value of I-SFSR register. |
||
349 | */ |
||
1780 | jermar | 350 | static inline void itlb_sfsr_write(uint64_t v) |
873 | jermar | 351 | { |
352 | asi_u64_write(ASI_IMMU, VA_IMMU_SFSR, v); |
||
353 | flush(); |
||
354 | } |
||
355 | |||
356 | /** Read DTLB Synchronous Fault Status Register. |
||
357 | * |
||
358 | * @return Current content of D-SFSR register. |
||
359 | */ |
||
1780 | jermar | 360 | static inline uint64_t dtlb_sfsr_read(void) |
873 | jermar | 361 | { |
362 | return asi_u64_read(ASI_DMMU, VA_DMMU_SFSR); |
||
363 | } |
||
364 | |||
365 | /** Write DTLB Synchronous Fault Status Register. |
||
366 | * |
||
367 | * @param v New value of D-SFSR register. |
||
368 | */ |
||
1780 | jermar | 369 | static inline void dtlb_sfsr_write(uint64_t v) |
873 | jermar | 370 | { |
371 | asi_u64_write(ASI_DMMU, VA_DMMU_SFSR, v); |
||
1822 | jermar | 372 | membar(); |
873 | jermar | 373 | } |
374 | |||
375 | /** Read DTLB Synchronous Fault Address Register. |
||
376 | * |
||
377 | * @return Current content of D-SFAR register. |
||
378 | */ |
||
1780 | jermar | 379 | static inline uint64_t dtlb_sfar_read(void) |
873 | jermar | 380 | { |
381 | return asi_u64_read(ASI_DMMU, VA_DMMU_SFAR); |
||
382 | } |
||
383 | |||
617 | jermar | 384 | /** Perform IMMU TLB Demap Operation. |
385 | * |
||
386 | * @param type Selects between context and page demap. |
||
387 | * @param context_encoding Specifies which Context register has Context ID for demap. |
||
388 | * @param page Address which is on the page to be demapped. |
||
389 | */ |
||
1780 | jermar | 390 | static inline void itlb_demap(int type, int context_encoding, uintptr_t page) |
617 | jermar | 391 | { |
392 | tlb_demap_addr_t da; |
||
393 | page_address_t pg; |
||
394 | |||
395 | da.value = 0; |
||
396 | pg.address = page; |
||
397 | |||
398 | da.type = type; |
||
399 | da.context = context_encoding; |
||
400 | da.vpn = pg.vpn; |
||
401 | |||
1823 | jermar | 402 | asi_u64_write(ASI_IMMU_DEMAP, da.value, 0); /* da.value is the address within the ASI */ |
617 | jermar | 403 | flush(); |
404 | } |
||
405 | |||
406 | /** Perform DMMU TLB Demap Operation. |
||
407 | * |
||
408 | * @param type Selects between context and page demap. |
||
409 | * @param context_encoding Specifies which Context register has Context ID for demap. |
||
410 | * @param page Address which is on the page to be demapped. |
||
411 | */ |
||
1780 | jermar | 412 | static inline void dtlb_demap(int type, int context_encoding, uintptr_t page) |
617 | jermar | 413 | { |
414 | tlb_demap_addr_t da; |
||
415 | page_address_t pg; |
||
416 | |||
417 | da.value = 0; |
||
418 | pg.address = page; |
||
419 | |||
420 | da.type = type; |
||
421 | da.context = context_encoding; |
||
422 | da.vpn = pg.vpn; |
||
423 | |||
1823 | jermar | 424 | asi_u64_write(ASI_DMMU_DEMAP, da.value, 0); /* da.value is the address within the ASI */ |
1822 | jermar | 425 | membar(); |
617 | jermar | 426 | } |
427 | |||
863 | jermar | 428 | extern void fast_instruction_access_mmu_miss(void); |
429 | extern void fast_data_access_mmu_miss(void); |
||
430 | extern void fast_data_access_protection(void); |
||
431 | |||
1780 | jermar | 432 | extern void dtlb_insert_mapping(uintptr_t page, uintptr_t frame, int pagesize, bool locked, bool cacheable); |
897 | jermar | 433 | |
1823 | jermar | 434 | #endif /* !def __ASM__ */ |
435 | |||
418 | jermar | 436 | #endif |
1702 | cejka | 437 | |
1822 | jermar | 438 | /** @} |
1702 | cejka | 439 | */ |