[30ef8ce] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 - 2006 Jakub Jermar
|
---|
| 3 | * Copyright (c) 2006 Jakub Vana
|
---|
[30ef8ce] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 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
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 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
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 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
|
---|
| 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
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[5bda2f3e] | 30 | /** @addtogroup ia64mm
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[06e1e95] | 36 | #ifndef KERN_ia64_PAGE_H_
|
---|
| 37 | #define KERN_ia64_PAGE_H_
|
---|
[30ef8ce] | 38 |
|
---|
[d1f8a87] | 39 | #include <arch/mm/frame.h>
|
---|
| 40 |
|
---|
[5bda2f3e] | 41 | #define PAGE_SIZE FRAME_SIZE
|
---|
| 42 | #define PAGE_WIDTH FRAME_WIDTH
|
---|
[30ef8ce] | 43 |
|
---|
[a0d74fd] | 44 | /** Bit width of the TLB-locked portion of kernel address space. */
|
---|
[22f0561] | 45 | #define KERNEL_PAGE_WIDTH 28 /* 256M */
|
---|
[59e4864] | 46 |
|
---|
[5bda2f3e] | 47 | #define PPN_SHIFT 12
|
---|
[0c0410b] | 48 |
|
---|
[5bda2f3e] | 49 | #define VRN_SHIFT 61
|
---|
| 50 | #define VRN_MASK (7ULL << VRN_SHIFT)
|
---|
| 51 | #define VA2VRN(va) ((va) >> VRN_SHIFT)
|
---|
[5ac2e61] | 52 |
|
---|
| 53 | #ifdef __ASM__
|
---|
[5bda2f3e] | 54 | #define VRN_KERNEL 7
|
---|
[5ac2e61] | 55 | #else
|
---|
[5bda2f3e] | 56 | #define VRN_KERNEL 7ULL
|
---|
[5ac2e61] | 57 | #endif
|
---|
| 58 |
|
---|
[5bda2f3e] | 59 | #define REGION_REGISTERS 8
|
---|
[fd537a0] | 60 |
|
---|
[5bda2f3e] | 61 | #define KA2PA(x) ((uintptr_t) ((x) - (VRN_KERNEL << VRN_SHIFT)))
|
---|
| 62 | #define PA2KA(x) ((uintptr_t) ((x) + (VRN_KERNEL << VRN_SHIFT)))
|
---|
[5ac2e61] | 63 |
|
---|
[5bda2f3e] | 64 | #define VHPT_WIDTH 20 /* 1M */
|
---|
| 65 | #define VHPT_SIZE (1 << VHPT_WIDTH)
|
---|
[fd537a0] | 66 |
|
---|
[5bda2f3e] | 67 | #define PTA_BASE_SHIFT 15
|
---|
[df09142f] | 68 |
|
---|
[457d18a] | 69 | /** Memory Attributes. */
|
---|
[5bda2f3e] | 70 | #define MA_WRITEBACK 0x00
|
---|
| 71 | #define MA_UNCACHEABLE 0x04
|
---|
[457d18a] | 72 |
|
---|
| 73 | /** Privilege Levels. Only the most and the least privileged ones are ever used. */
|
---|
[5bda2f3e] | 74 | #define PL_KERNEL 0x00
|
---|
| 75 | #define PL_USER 0x03
|
---|
[457d18a] | 76 |
|
---|
| 77 | /* Access Rigths. Only certain combinations are used by the kernel. */
|
---|
[5bda2f3e] | 78 | #define AR_READ 0x00
|
---|
| 79 | #define AR_EXECUTE 0x01
|
---|
| 80 | #define AR_WRITE 0x02
|
---|
[457d18a] | 81 |
|
---|
[5ac2e61] | 82 | #ifndef __ASM__
|
---|
[bc78c75] | 83 |
|
---|
[b3f8fb7] | 84 | #include <arch/mm/as.h>
|
---|
[a0d74fd] | 85 | #include <arch/mm/frame.h>
|
---|
[b3f8fb7] | 86 | #include <arch/interrupt.h>
|
---|
[a0d74fd] | 87 | #include <arch/barrier.h>
|
---|
| 88 | #include <arch/mm/asid.h>
|
---|
[d99c1d2] | 89 | #include <typedefs.h>
|
---|
[a0d74fd] | 90 | #include <debug.h>
|
---|
| 91 |
|
---|
[c2b95d3] | 92 | struct vhpt_tag_info {
|
---|
| 93 | unsigned long long tag : 63;
|
---|
[5bda2f3e] | 94 | unsigned int ti : 1;
|
---|
[c2b95d3] | 95 | } __attribute__ ((packed));
|
---|
[8c0d692] | 96 |
|
---|
[c2b95d3] | 97 | union vhpt_tag {
|
---|
| 98 | struct vhpt_tag_info tag_info;
|
---|
| 99 | unsigned tag_word;
|
---|
[8c0d692] | 100 | };
|
---|
| 101 |
|
---|
[c2b95d3] | 102 | struct vhpt_entry_present {
|
---|
[8c0d692] | 103 | /* Word 0 */
|
---|
[5bda2f3e] | 104 | unsigned int p : 1;
|
---|
| 105 | unsigned int : 1;
|
---|
| 106 | unsigned int ma : 3;
|
---|
| 107 | unsigned int a : 1;
|
---|
| 108 | unsigned int d : 1;
|
---|
| 109 | unsigned int pl : 2;
|
---|
| 110 | unsigned int ar : 3;
|
---|
[c2b95d3] | 111 | unsigned long long ppn : 38;
|
---|
[5bda2f3e] | 112 | unsigned int : 2;
|
---|
| 113 | unsigned int ed : 1;
|
---|
| 114 | unsigned int ig1 : 11;
|
---|
[8c0d692] | 115 |
|
---|
| 116 | /* Word 1 */
|
---|
[5bda2f3e] | 117 | unsigned int : 2;
|
---|
| 118 | unsigned int ps : 6;
|
---|
| 119 | unsigned int key : 24;
|
---|
| 120 | unsigned int : 32;
|
---|
[8c0d692] | 121 |
|
---|
| 122 | /* Word 2 */
|
---|
[c2b95d3] | 123 | union vhpt_tag tag;
|
---|
[8c0d692] | 124 |
|
---|
[5bda2f3e] | 125 | /* Word 3 */
|
---|
[7f1c620] | 126 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 127 | } __attribute__ ((packed));
|
---|
[8c0d692] | 128 |
|
---|
[c2b95d3] | 129 | struct vhpt_entry_not_present {
|
---|
[8c0d692] | 130 | /* Word 0 */
|
---|
[5bda2f3e] | 131 | unsigned int p : 1;
|
---|
[c2b95d3] | 132 | unsigned long long ig0 : 52;
|
---|
[5bda2f3e] | 133 | unsigned int ig1 : 11;
|
---|
[8c0d692] | 134 |
|
---|
| 135 | /* Word 1 */
|
---|
[5bda2f3e] | 136 | unsigned int : 2;
|
---|
| 137 | unsigned int ps : 6;
|
---|
[c2b95d3] | 138 | unsigned long long ig2 : 56;
|
---|
[5bda2f3e] | 139 |
|
---|
[8c0d692] | 140 | /* Word 2 */
|
---|
[c2b95d3] | 141 | union vhpt_tag tag;
|
---|
| 142 |
|
---|
[5bda2f3e] | 143 | /* Word 3 */
|
---|
[7f1c620] | 144 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 145 | } __attribute__ ((packed));
|
---|
| 146 |
|
---|
[5bda2f3e] | 147 | typedef union {
|
---|
[c2b95d3] | 148 | struct vhpt_entry_present present;
|
---|
| 149 | struct vhpt_entry_not_present not_present;
|
---|
[7f1c620] | 150 | uint64_t word[4];
|
---|
[c7ec94a4] | 151 | } vhpt_entry_t;
|
---|
[c2b95d3] | 152 |
|
---|
| 153 | struct region_register_map {
|
---|
[5bda2f3e] | 154 | unsigned int ve : 1;
|
---|
| 155 | unsigned int : 1;
|
---|
| 156 | unsigned int ps : 6;
|
---|
| 157 | unsigned int rid : 24;
|
---|
| 158 | unsigned int : 32;
|
---|
[c2b95d3] | 159 | } __attribute__ ((packed));
|
---|
| 160 |
|
---|
[5bda2f3e] | 161 | typedef union {
|
---|
[c2b95d3] | 162 | struct region_register_map map;
|
---|
| 163 | unsigned long long word;
|
---|
[5bda2f3e] | 164 | } region_register_t;
|
---|
[c2b95d3] | 165 |
|
---|
| 166 | struct pta_register_map {
|
---|
[5bda2f3e] | 167 | unsigned int ve : 1;
|
---|
| 168 | unsigned int : 1;
|
---|
| 169 | unsigned int size : 6;
|
---|
| 170 | unsigned int vf : 1;
|
---|
| 171 | unsigned int : 6;
|
---|
[c2b95d3] | 172 | unsigned long long base : 49;
|
---|
| 173 | } __attribute__ ((packed));
|
---|
| 174 |
|
---|
| 175 | typedef union pta_register {
|
---|
| 176 | struct pta_register_map map;
|
---|
[7f1c620] | 177 | uint64_t word;
|
---|
[5bda2f3e] | 178 | } pta_register_t;
|
---|
[c2b95d3] | 179 |
|
---|
| 180 | /** Return Translation Hashed Entry Address.
|
---|
| 181 | *
|
---|
| 182 | * VRN bits are used to read RID (ASID) from one
|
---|
| 183 | * of the eight region registers registers.
|
---|
| 184 | *
|
---|
| 185 | * @param va Virtual address including VRN bits.
|
---|
| 186 | *
|
---|
| 187 | * @return Address of the head of VHPT collision chain.
|
---|
| 188 | */
|
---|
[7a0359b] | 189 | NO_TRACE static inline uint64_t thash(uint64_t va)
|
---|
[8c0d692] | 190 | {
|
---|
[7f1c620] | 191 | uint64_t ret;
|
---|
[5bda2f3e] | 192 |
|
---|
| 193 | asm volatile (
|
---|
| 194 | "thash %[ret] = %[va]\n"
|
---|
| 195 | : [ret] "=r" (ret)
|
---|
| 196 | : [va] "r" (va)
|
---|
| 197 | );
|
---|
| 198 |
|
---|
[c2b95d3] | 199 | return ret;
|
---|
| 200 | }
|
---|
[fd537a0] | 201 |
|
---|
[c2b95d3] | 202 | /** Return Translation Hashed Entry Tag.
|
---|
| 203 | *
|
---|
| 204 | * VRN bits are used to read RID (ASID) from one
|
---|
| 205 | * of the eight region registers.
|
---|
| 206 | *
|
---|
| 207 | * @param va Virtual address including VRN bits.
|
---|
| 208 | *
|
---|
| 209 | * @return The unique tag for VPN and RID in the collision chain returned by thash().
|
---|
| 210 | */
|
---|
[7a0359b] | 211 | NO_TRACE static inline uint64_t ttag(uint64_t va)
|
---|
[fd537a0] | 212 | {
|
---|
[7f1c620] | 213 | uint64_t ret;
|
---|
[5bda2f3e] | 214 |
|
---|
| 215 | asm volatile (
|
---|
| 216 | "ttag %[ret] = %[va]\n"
|
---|
| 217 | : [ret] "=r" (ret)
|
---|
| 218 | : [va] "r" (va)
|
---|
| 219 | );
|
---|
| 220 |
|
---|
[c2b95d3] | 221 | return ret;
|
---|
| 222 | }
|
---|
[fd537a0] | 223 |
|
---|
[c2b95d3] | 224 | /** Read Region Register.
|
---|
| 225 | *
|
---|
| 226 | * @param i Region register index.
|
---|
| 227 | *
|
---|
| 228 | * @return Current contents of rr[i].
|
---|
| 229 | */
|
---|
[7a0359b] | 230 | NO_TRACE static inline uint64_t rr_read(size_t i)
|
---|
[fd537a0] | 231 | {
|
---|
[7f1c620] | 232 | uint64_t ret;
|
---|
[5bda2f3e] | 233 |
|
---|
[849386a] | 234 | ASSERT(i < REGION_REGISTERS);
|
---|
[5bda2f3e] | 235 |
|
---|
| 236 | asm volatile (
|
---|
| 237 | "mov %[ret] = rr[%[index]]\n"
|
---|
| 238 | : [ret] "=r" (ret)
|
---|
| 239 | : [index] "r" (i << VRN_SHIFT)
|
---|
| 240 | );
|
---|
| 241 |
|
---|
[c2b95d3] | 242 | return ret;
|
---|
| 243 | }
|
---|
[fd537a0] | 244 |
|
---|
[c2b95d3] | 245 | /** Write Region Register.
|
---|
| 246 | *
|
---|
| 247 | * @param i Region register index.
|
---|
| 248 | * @param v Value to be written to rr[i].
|
---|
| 249 | */
|
---|
[7a0359b] | 250 | NO_TRACE static inline void rr_write(size_t i, uint64_t v)
|
---|
[fd537a0] | 251 | {
|
---|
[849386a] | 252 | ASSERT(i < REGION_REGISTERS);
|
---|
[5bda2f3e] | 253 |
|
---|
[e7b7be3f] | 254 | asm volatile (
|
---|
[5bda2f3e] | 255 | "mov rr[%[index]] = %[value]\n"
|
---|
| 256 | :: [index] "r" (i << VRN_SHIFT),
|
---|
| 257 | [value] "r" (v)
|
---|
[a0d74fd] | 258 | );
|
---|
[c2b95d3] | 259 | }
|
---|
[5bda2f3e] | 260 |
|
---|
[c2b95d3] | 261 | /** Read Page Table Register.
|
---|
| 262 | *
|
---|
| 263 | * @return Current value stored in PTA.
|
---|
| 264 | */
|
---|
[7a0359b] | 265 | NO_TRACE static inline uint64_t pta_read(void)
|
---|
[c2b95d3] | 266 | {
|
---|
[7f1c620] | 267 | uint64_t ret;
|
---|
[c2b95d3] | 268 |
|
---|
[5bda2f3e] | 269 | asm volatile (
|
---|
| 270 | "mov %[ret] = cr.pta\n"
|
---|
| 271 | : [ret] "=r" (ret)
|
---|
| 272 | );
|
---|
[c2b95d3] | 273 |
|
---|
| 274 | return ret;
|
---|
| 275 | }
|
---|
[fd537a0] | 276 |
|
---|
[c2b95d3] | 277 | /** Write Page Table Register.
|
---|
| 278 | *
|
---|
| 279 | * @param v New value to be stored in PTA.
|
---|
| 280 | */
|
---|
[7a0359b] | 281 | NO_TRACE static inline void pta_write(uint64_t v)
|
---|
[c2b95d3] | 282 | {
|
---|
[5bda2f3e] | 283 | asm volatile (
|
---|
| 284 | "mov cr.pta = %[value]\n"
|
---|
| 285 | :: [value] "r" (v)
|
---|
| 286 | );
|
---|
[c2b95d3] | 287 | }
|
---|
| 288 |
|
---|
| 289 | extern void page_arch_init(void);
|
---|
[c7ec94a4] | 290 |
|
---|
[7f1c620] | 291 | extern vhpt_entry_t *vhpt_hash(uintptr_t page, asid_t asid);
|
---|
| 292 | extern bool vhpt_compare(uintptr_t page, asid_t asid, vhpt_entry_t *v);
|
---|
| 293 | extern void vhpt_set_record(vhpt_entry_t *v, uintptr_t page, asid_t asid, uintptr_t frame, int flags);
|
---|
[fd537a0] | 294 |
|
---|
[d1f8a87] | 295 | #endif /* __ASM__ */
|
---|
| 296 |
|
---|
[30ef8ce] | 297 | #endif
|
---|
[b45c443] | 298 |
|
---|
[7f1c620] | 299 | /** @}
|
---|
[b45c443] | 300 | */
|
---|