1 | /*
|
---|
2 | * Copyright (c) 2003-2004 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 |
|
---|
29 | /** @addtogroup mips32mm
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #ifndef KERN_mips32_TLB_H_
|
---|
36 | #define KERN_mips32_TLB_H_
|
---|
37 |
|
---|
38 | #include <typedefs.h>
|
---|
39 | #include <arch/mm/asid.h>
|
---|
40 | #include <arch/exception.h>
|
---|
41 | #include <trace.h>
|
---|
42 |
|
---|
43 | #if defined(PROCESSOR_R4000)
|
---|
44 | #define TLB_ENTRY_COUNT 48
|
---|
45 | #elif defined(PROCESSOR_4Kc)
|
---|
46 | #define TLB_ENTRY_COUNT 16
|
---|
47 | #else
|
---|
48 | #error Please define TLB_ENTRY_COUNT for the target processor.
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #define TLB_WIRED 1
|
---|
52 | #define TLB_KSTACK_WIRED_INDEX 0
|
---|
53 |
|
---|
54 | #define TLB_PAGE_MASK_4K (0x000 << 13)
|
---|
55 | #define TLB_PAGE_MASK_16K (0x003 << 13)
|
---|
56 | #define TLB_PAGE_MASK_64K (0x00f << 13)
|
---|
57 | #define TLB_PAGE_MASK_256K (0x03f << 13)
|
---|
58 | #define TLB_PAGE_MASK_1M (0x0ff << 13)
|
---|
59 | #define TLB_PAGE_MASK_4M (0x3ff << 13)
|
---|
60 | #define TLB_PAGE_MASK_16M (0xfff << 13)
|
---|
61 |
|
---|
62 | #define PAGE_UNCACHED 2
|
---|
63 | #define PAGE_CACHEABLE_EXC_WRITE 5
|
---|
64 |
|
---|
65 | typedef union {
|
---|
66 | struct {
|
---|
67 | #ifdef __BE__
|
---|
68 | unsigned : 2; /* zero */
|
---|
69 | unsigned pfn : 24; /* frame number */
|
---|
70 | unsigned c : 3; /* cache coherency attribute */
|
---|
71 | unsigned d : 1; /* dirty/write-protect bit */
|
---|
72 | unsigned v : 1; /* valid bit */
|
---|
73 | unsigned g : 1; /* global bit */
|
---|
74 | #else
|
---|
75 | unsigned g : 1; /* global bit */
|
---|
76 | unsigned v : 1; /* valid bit */
|
---|
77 | unsigned d : 1; /* dirty/write-protect bit */
|
---|
78 | unsigned c : 3; /* cache coherency attribute */
|
---|
79 | unsigned pfn : 24; /* frame number */
|
---|
80 | unsigned : 2; /* zero */
|
---|
81 | #endif
|
---|
82 | } __attribute__ ((packed));
|
---|
83 | uint32_t value;
|
---|
84 | } entry_lo_t;
|
---|
85 |
|
---|
86 | typedef union {
|
---|
87 | struct {
|
---|
88 | #ifdef __BE__
|
---|
89 | unsigned vpn2 : 19;
|
---|
90 | unsigned : 5;
|
---|
91 | unsigned asid : 8;
|
---|
92 | #else
|
---|
93 | unsigned asid : 8;
|
---|
94 | unsigned : 5;
|
---|
95 | unsigned vpn2 : 19;
|
---|
96 | #endif
|
---|
97 | } __attribute__ ((packed));
|
---|
98 | uint32_t value;
|
---|
99 | } entry_hi_t;
|
---|
100 |
|
---|
101 | typedef union {
|
---|
102 | struct {
|
---|
103 | #ifdef __BE__
|
---|
104 | unsigned : 7;
|
---|
105 | unsigned mask : 12;
|
---|
106 | unsigned : 13;
|
---|
107 | #else
|
---|
108 | unsigned : 13;
|
---|
109 | unsigned mask : 12;
|
---|
110 | unsigned : 7;
|
---|
111 | #endif
|
---|
112 | } __attribute__ ((packed));
|
---|
113 | uint32_t value;
|
---|
114 | } page_mask_t;
|
---|
115 |
|
---|
116 | typedef union {
|
---|
117 | struct {
|
---|
118 | #ifdef __BE__
|
---|
119 | unsigned p : 1;
|
---|
120 | unsigned : 27;
|
---|
121 | unsigned index : 4;
|
---|
122 | #else
|
---|
123 | unsigned index : 4;
|
---|
124 | unsigned : 27;
|
---|
125 | unsigned p : 1;
|
---|
126 | #endif
|
---|
127 | } __attribute__ ((packed));
|
---|
128 | uint32_t value;
|
---|
129 | } tlb_index_t;
|
---|
130 |
|
---|
131 | /** Probe TLB for Matching Entry
|
---|
132 | *
|
---|
133 | * Probe TLB for Matching Entry.
|
---|
134 | */
|
---|
135 | NO_TRACE static inline void tlbp(void)
|
---|
136 | {
|
---|
137 | asm volatile ("tlbp\n\t");
|
---|
138 | }
|
---|
139 |
|
---|
140 |
|
---|
141 | /** Read Indexed TLB Entry
|
---|
142 | *
|
---|
143 | * Read Indexed TLB Entry.
|
---|
144 | */
|
---|
145 | NO_TRACE static inline void tlbr(void)
|
---|
146 | {
|
---|
147 | asm volatile ("tlbr\n\t");
|
---|
148 | }
|
---|
149 |
|
---|
150 | /** Write Indexed TLB Entry
|
---|
151 | *
|
---|
152 | * Write Indexed TLB Entry.
|
---|
153 | */
|
---|
154 | NO_TRACE static inline void tlbwi(void)
|
---|
155 | {
|
---|
156 | asm volatile ("tlbwi\n\t");
|
---|
157 | }
|
---|
158 |
|
---|
159 | /** Write Random TLB Entry
|
---|
160 | *
|
---|
161 | * Write Random TLB Entry.
|
---|
162 | */
|
---|
163 | NO_TRACE static inline void tlbwr(void)
|
---|
164 | {
|
---|
165 | asm volatile ("tlbwr\n\t");
|
---|
166 | }
|
---|
167 |
|
---|
168 | #define tlb_invalidate(asid) tlb_invalidate_asid(asid)
|
---|
169 |
|
---|
170 | extern void tlb_invalid(istate_t *istate);
|
---|
171 | extern void tlb_refill(istate_t *istate);
|
---|
172 | extern void tlb_modified(istate_t *istate);
|
---|
173 | extern void tlb_prepare_entry_lo(entry_lo_t *lo, bool g, bool v, bool d, bool cacheable, uintptr_t pfn);
|
---|
174 | extern void tlb_prepare_entry_hi(entry_hi_t *hi, asid_t asid, uintptr_t addr);
|
---|
175 |
|
---|
176 | #endif
|
---|
177 |
|
---|
178 | /** @}
|
---|
179 | */
|
---|