| 1 | /*
|
|---|
| 2 | * Copyright (c) 2005 - 2006 Jakub Jermar
|
|---|
| 3 | * Copyright (c) 2006 Jakub Vana
|
|---|
| 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 |
|
|---|
| 30 | /** @addtogroup ia64mm
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef KERN_ia64_PAGE_H_
|
|---|
| 37 | #define KERN_ia64_PAGE_H_
|
|---|
| 38 |
|
|---|
| 39 | #include <arch/mm/frame.h>
|
|---|
| 40 |
|
|---|
| 41 | #define PAGE_SIZE FRAME_SIZE
|
|---|
| 42 | #define PAGE_WIDTH FRAME_WIDTH
|
|---|
| 43 |
|
|---|
| 44 | /** Bit width of the TLB-locked portion of kernel address space. */
|
|---|
| 45 | #define KERNEL_PAGE_WIDTH 28 /* 256M */
|
|---|
| 46 |
|
|---|
| 47 | #define PPN_SHIFT 12
|
|---|
| 48 |
|
|---|
| 49 | #define VRN_SHIFT 61
|
|---|
| 50 | #define VRN_MASK (7ULL << VRN_SHIFT)
|
|---|
| 51 | #define VA2VRN(va) ((va) >> VRN_SHIFT)
|
|---|
| 52 |
|
|---|
| 53 | #ifdef __ASM__
|
|---|
| 54 | #define VRN_KERNEL 7
|
|---|
| 55 | #else
|
|---|
| 56 | #define VRN_KERNEL 7ULL
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | #define REGION_REGISTERS 8
|
|---|
| 60 |
|
|---|
| 61 | #define KA2PA(x) ((uintptr_t) ((x) - (VRN_KERNEL << VRN_SHIFT)))
|
|---|
| 62 | #define PA2KA(x) ((uintptr_t) ((x) + (VRN_KERNEL << VRN_SHIFT)))
|
|---|
| 63 |
|
|---|
| 64 | #define VHPT_WIDTH 20 /* 1M */
|
|---|
| 65 | #define VHPT_SIZE (1 << VHPT_WIDTH)
|
|---|
| 66 |
|
|---|
| 67 | #define PTA_BASE_SHIFT 15
|
|---|
| 68 |
|
|---|
| 69 | /** Memory Attributes. */
|
|---|
| 70 | #define MA_WRITEBACK 0x00
|
|---|
| 71 | #define MA_UNCACHEABLE 0x04
|
|---|
| 72 |
|
|---|
| 73 | /** Privilege Levels. Only the most and the least privileged ones are ever used. */
|
|---|
| 74 | #define PL_KERNEL 0x00
|
|---|
| 75 | #define PL_USER 0x03
|
|---|
| 76 |
|
|---|
| 77 | /* Access Rigths. Only certain combinations are used by the kernel. */
|
|---|
| 78 | #define AR_READ 0x00
|
|---|
| 79 | #define AR_EXECUTE 0x01
|
|---|
| 80 | #define AR_WRITE 0x02
|
|---|
| 81 |
|
|---|
| 82 | #ifndef __ASM__
|
|---|
| 83 |
|
|---|
| 84 | #include <arch/mm/as.h>
|
|---|
| 85 | #include <arch/mm/frame.h>
|
|---|
| 86 | #include <arch/interrupt.h>
|
|---|
| 87 | #include <arch/barrier.h>
|
|---|
| 88 | #include <arch/mm/asid.h>
|
|---|
| 89 | #include <typedefs.h>
|
|---|
| 90 | #include <debug.h>
|
|---|
| 91 |
|
|---|
| 92 | struct vhpt_tag_info {
|
|---|
| 93 | unsigned long long tag : 63;
|
|---|
| 94 | unsigned int ti : 1;
|
|---|
| 95 | } __attribute__ ((packed));
|
|---|
| 96 |
|
|---|
| 97 | union vhpt_tag {
|
|---|
| 98 | struct vhpt_tag_info tag_info;
|
|---|
| 99 | unsigned tag_word;
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | struct vhpt_entry_present {
|
|---|
| 103 | /* Word 0 */
|
|---|
| 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;
|
|---|
| 111 | unsigned long long ppn : 38;
|
|---|
| 112 | unsigned int : 2;
|
|---|
| 113 | unsigned int ed : 1;
|
|---|
| 114 | unsigned int ig1 : 11;
|
|---|
| 115 |
|
|---|
| 116 | /* Word 1 */
|
|---|
| 117 | unsigned int : 2;
|
|---|
| 118 | unsigned int ps : 6;
|
|---|
| 119 | unsigned int key : 24;
|
|---|
| 120 | unsigned int : 32;
|
|---|
| 121 |
|
|---|
| 122 | /* Word 2 */
|
|---|
| 123 | union vhpt_tag tag;
|
|---|
| 124 |
|
|---|
| 125 | /* Word 3 */
|
|---|
| 126 | uint64_t ig3 : 64;
|
|---|
| 127 | } __attribute__ ((packed));
|
|---|
| 128 |
|
|---|
| 129 | struct vhpt_entry_not_present {
|
|---|
| 130 | /* Word 0 */
|
|---|
| 131 | unsigned int p : 1;
|
|---|
| 132 | unsigned long long ig0 : 52;
|
|---|
| 133 | unsigned int ig1 : 11;
|
|---|
| 134 |
|
|---|
| 135 | /* Word 1 */
|
|---|
| 136 | unsigned int : 2;
|
|---|
| 137 | unsigned int ps : 6;
|
|---|
| 138 | unsigned long long ig2 : 56;
|
|---|
| 139 |
|
|---|
| 140 | /* Word 2 */
|
|---|
| 141 | union vhpt_tag tag;
|
|---|
| 142 |
|
|---|
| 143 | /* Word 3 */
|
|---|
| 144 | uint64_t ig3 : 64;
|
|---|
| 145 | } __attribute__ ((packed));
|
|---|
| 146 |
|
|---|
| 147 | typedef union {
|
|---|
| 148 | struct vhpt_entry_present present;
|
|---|
| 149 | struct vhpt_entry_not_present not_present;
|
|---|
| 150 | uint64_t word[4];
|
|---|
| 151 | } vhpt_entry_t;
|
|---|
| 152 |
|
|---|
| 153 | struct region_register_map {
|
|---|
| 154 | unsigned int ve : 1;
|
|---|
| 155 | unsigned int : 1;
|
|---|
| 156 | unsigned int ps : 6;
|
|---|
| 157 | unsigned int rid : 24;
|
|---|
| 158 | unsigned int : 32;
|
|---|
| 159 | } __attribute__ ((packed));
|
|---|
| 160 |
|
|---|
| 161 | typedef union {
|
|---|
| 162 | struct region_register_map map;
|
|---|
| 163 | unsigned long long word;
|
|---|
| 164 | } region_register_t;
|
|---|
| 165 |
|
|---|
| 166 | struct pta_register_map {
|
|---|
| 167 | unsigned int ve : 1;
|
|---|
| 168 | unsigned int : 1;
|
|---|
| 169 | unsigned int size : 6;
|
|---|
| 170 | unsigned int vf : 1;
|
|---|
| 171 | unsigned int : 6;
|
|---|
| 172 | unsigned long long base : 49;
|
|---|
| 173 | } __attribute__ ((packed));
|
|---|
| 174 |
|
|---|
| 175 | typedef union pta_register {
|
|---|
| 176 | struct pta_register_map map;
|
|---|
| 177 | uint64_t word;
|
|---|
| 178 | } pta_register_t;
|
|---|
| 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 | */
|
|---|
| 189 | NO_TRACE static inline uint64_t thash(uint64_t va)
|
|---|
| 190 | {
|
|---|
| 191 | uint64_t ret;
|
|---|
| 192 |
|
|---|
| 193 | asm volatile (
|
|---|
| 194 | "thash %[ret] = %[va]\n"
|
|---|
| 195 | : [ret] "=r" (ret)
|
|---|
| 196 | : [va] "r" (va)
|
|---|
| 197 | );
|
|---|
| 198 |
|
|---|
| 199 | return ret;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 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 | */
|
|---|
| 211 | NO_TRACE static inline uint64_t ttag(uint64_t va)
|
|---|
| 212 | {
|
|---|
| 213 | uint64_t ret;
|
|---|
| 214 |
|
|---|
| 215 | asm volatile (
|
|---|
| 216 | "ttag %[ret] = %[va]\n"
|
|---|
| 217 | : [ret] "=r" (ret)
|
|---|
| 218 | : [va] "r" (va)
|
|---|
| 219 | );
|
|---|
| 220 |
|
|---|
| 221 | return ret;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | /** Read Region Register.
|
|---|
| 225 | *
|
|---|
| 226 | * @param i Region register index.
|
|---|
| 227 | *
|
|---|
| 228 | * @return Current contents of rr[i].
|
|---|
| 229 | */
|
|---|
| 230 | NO_TRACE static inline uint64_t rr_read(size_t i)
|
|---|
| 231 | {
|
|---|
| 232 | uint64_t ret;
|
|---|
| 233 |
|
|---|
| 234 | ASSERT(i < REGION_REGISTERS);
|
|---|
| 235 |
|
|---|
| 236 | asm volatile (
|
|---|
| 237 | "mov %[ret] = rr[%[index]]\n"
|
|---|
| 238 | : [ret] "=r" (ret)
|
|---|
| 239 | : [index] "r" (i << VRN_SHIFT)
|
|---|
| 240 | );
|
|---|
| 241 |
|
|---|
| 242 | return ret;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | /** Write Region Register.
|
|---|
| 246 | *
|
|---|
| 247 | * @param i Region register index.
|
|---|
| 248 | * @param v Value to be written to rr[i].
|
|---|
| 249 | */
|
|---|
| 250 | NO_TRACE static inline void rr_write(size_t i, uint64_t v)
|
|---|
| 251 | {
|
|---|
| 252 | ASSERT(i < REGION_REGISTERS);
|
|---|
| 253 |
|
|---|
| 254 | asm volatile (
|
|---|
| 255 | "mov rr[%[index]] = %[value]\n"
|
|---|
| 256 | :: [index] "r" (i << VRN_SHIFT),
|
|---|
| 257 | [value] "r" (v)
|
|---|
| 258 | );
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | /** Read Page Table Register.
|
|---|
| 262 | *
|
|---|
| 263 | * @return Current value stored in PTA.
|
|---|
| 264 | */
|
|---|
| 265 | NO_TRACE static inline uint64_t pta_read(void)
|
|---|
| 266 | {
|
|---|
| 267 | uint64_t ret;
|
|---|
| 268 |
|
|---|
| 269 | asm volatile (
|
|---|
| 270 | "mov %[ret] = cr.pta\n"
|
|---|
| 271 | : [ret] "=r" (ret)
|
|---|
| 272 | );
|
|---|
| 273 |
|
|---|
| 274 | return ret;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | /** Write Page Table Register.
|
|---|
| 278 | *
|
|---|
| 279 | * @param v New value to be stored in PTA.
|
|---|
| 280 | */
|
|---|
| 281 | NO_TRACE static inline void pta_write(uint64_t v)
|
|---|
| 282 | {
|
|---|
| 283 | asm volatile (
|
|---|
| 284 | "mov cr.pta = %[value]\n"
|
|---|
| 285 | :: [value] "r" (v)
|
|---|
| 286 | );
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | extern void page_arch_init(void);
|
|---|
| 290 |
|
|---|
| 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);
|
|---|
| 294 |
|
|---|
| 295 | #endif /* __ASM__ */
|
|---|
| 296 |
|
|---|
| 297 | #endif
|
|---|
| 298 |
|
|---|
| 299 | /** @}
|
|---|
| 300 | */
|
|---|