[30ef8ce] | 1 | /*
|
---|
[c2b95d3] | 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 |
|
---|
[7f1c620] | 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 |
|
---|
[30ef8ce] | 41 | #define PAGE_SIZE FRAME_SIZE
|
---|
[fd537a0] | 42 | #define PAGE_WIDTH FRAME_WIDTH
|
---|
[30ef8ce] | 43 |
|
---|
[d1f8a87] | 44 |
|
---|
| 45 | #ifdef KERNEL
|
---|
| 46 |
|
---|
[a0d74fd] | 47 | /** Bit width of the TLB-locked portion of kernel address space. */
|
---|
| 48 | #define KERNEL_PAGE_WIDTH 28 /* 256M */
|
---|
[30ef8ce] | 49 |
|
---|
[457d18a] | 50 | #define PPN_SHIFT 12
|
---|
[0c0410b] | 51 |
|
---|
[849386a] | 52 | #define VRN_SHIFT 61
|
---|
| 53 | #define VRN_MASK (7LL << VRN_SHIFT)
|
---|
[a0d74fd] | 54 | #define VA2VRN(va) ((va)>>VRN_SHIFT)
|
---|
[5ac2e61] | 55 |
|
---|
| 56 | #ifdef __ASM__
|
---|
| 57 | #define VRN_KERNEL 7
|
---|
| 58 | #else
|
---|
| 59 | #define VRN_KERNEL 7LL
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
[c2b95d3] | 62 | #define REGION_REGISTERS 8
|
---|
[fd537a0] | 63 |
|
---|
[7f1c620] | 64 | #define KA2PA(x) ((uintptr_t) (x-(VRN_KERNEL<<VRN_SHIFT)))
|
---|
| 65 | #define PA2KA(x) ((uintptr_t) (x+(VRN_KERNEL<<VRN_SHIFT)))
|
---|
[5ac2e61] | 66 |
|
---|
[c2b95d3] | 67 | #define VHPT_WIDTH 20 /* 1M */
|
---|
[c7ec94a4] | 68 | #define VHPT_SIZE (1 << VHPT_WIDTH)
|
---|
[fd537a0] | 69 |
|
---|
[df09142f] | 70 | #define PTA_BASE_SHIFT 15
|
---|
| 71 |
|
---|
[457d18a] | 72 | /** Memory Attributes. */
|
---|
| 73 | #define MA_WRITEBACK 0x0
|
---|
| 74 | #define MA_UNCACHEABLE 0x4
|
---|
| 75 |
|
---|
| 76 | /** Privilege Levels. Only the most and the least privileged ones are ever used. */
|
---|
| 77 | #define PL_KERNEL 0x0
|
---|
| 78 | #define PL_USER 0x3
|
---|
| 79 |
|
---|
| 80 | /* Access Rigths. Only certain combinations are used by the kernel. */
|
---|
| 81 | #define AR_READ 0x0
|
---|
| 82 | #define AR_EXECUTE 0x1
|
---|
| 83 | #define AR_WRITE 0x2
|
---|
| 84 |
|
---|
[5ac2e61] | 85 | #ifndef __ASM__
|
---|
[bc78c75] | 86 |
|
---|
[a0d74fd] | 87 | #include <arch/mm/frame.h>
|
---|
| 88 | #include <arch/barrier.h>
|
---|
| 89 | #include <genarch/mm/page_ht.h>
|
---|
| 90 | #include <arch/mm/asid.h>
|
---|
| 91 | #include <arch/types.h>
|
---|
| 92 | #include <typedefs.h>
|
---|
| 93 | #include <debug.h>
|
---|
| 94 |
|
---|
[c2b95d3] | 95 | struct vhpt_tag_info {
|
---|
| 96 | unsigned long long tag : 63;
|
---|
| 97 | unsigned ti : 1;
|
---|
| 98 | } __attribute__ ((packed));
|
---|
[8c0d692] | 99 |
|
---|
[c2b95d3] | 100 | union vhpt_tag {
|
---|
| 101 | struct vhpt_tag_info tag_info;
|
---|
| 102 | unsigned tag_word;
|
---|
[8c0d692] | 103 | };
|
---|
| 104 |
|
---|
[c2b95d3] | 105 | struct vhpt_entry_present {
|
---|
[8c0d692] | 106 | /* Word 0 */
|
---|
[c2b95d3] | 107 | unsigned p : 1;
|
---|
| 108 | unsigned : 1;
|
---|
| 109 | unsigned ma : 3;
|
---|
| 110 | unsigned a : 1;
|
---|
| 111 | unsigned d : 1;
|
---|
| 112 | unsigned pl : 2;
|
---|
| 113 | unsigned ar : 3;
|
---|
| 114 | unsigned long long ppn : 38;
|
---|
| 115 | unsigned : 2;
|
---|
| 116 | unsigned ed : 1;
|
---|
| 117 | unsigned ig1 : 11;
|
---|
[8c0d692] | 118 |
|
---|
| 119 | /* Word 1 */
|
---|
[c2b95d3] | 120 | unsigned : 2;
|
---|
| 121 | unsigned ps : 6;
|
---|
| 122 | unsigned key : 24;
|
---|
| 123 | unsigned : 32;
|
---|
[8c0d692] | 124 |
|
---|
| 125 | /* Word 2 */
|
---|
[c2b95d3] | 126 | union vhpt_tag tag;
|
---|
[8c0d692] | 127 |
|
---|
[c2b95d3] | 128 | /* Word 3 */
|
---|
[7f1c620] | 129 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 130 | } __attribute__ ((packed));
|
---|
[8c0d692] | 131 |
|
---|
[c2b95d3] | 132 | struct vhpt_entry_not_present {
|
---|
[8c0d692] | 133 | /* Word 0 */
|
---|
[c2b95d3] | 134 | unsigned p : 1;
|
---|
| 135 | unsigned long long ig0 : 52;
|
---|
| 136 | unsigned ig1 : 11;
|
---|
[8c0d692] | 137 |
|
---|
| 138 | /* Word 1 */
|
---|
[c2b95d3] | 139 | unsigned : 2;
|
---|
| 140 | unsigned ps : 6;
|
---|
| 141 | unsigned long long ig2 : 56;
|
---|
[8c0d692] | 142 |
|
---|
| 143 | /* Word 2 */
|
---|
[c2b95d3] | 144 | union vhpt_tag tag;
|
---|
| 145 |
|
---|
[8c0d692] | 146 | /* Word 3 */
|
---|
[7f1c620] | 147 | uint64_t ig3 : 64;
|
---|
[c2b95d3] | 148 | } __attribute__ ((packed));
|
---|
| 149 |
|
---|
| 150 | typedef union vhpt_entry {
|
---|
| 151 | struct vhpt_entry_present present;
|
---|
| 152 | struct vhpt_entry_not_present not_present;
|
---|
[7f1c620] | 153 | uint64_t word[4];
|
---|
[c7ec94a4] | 154 | } vhpt_entry_t;
|
---|
[c2b95d3] | 155 |
|
---|
| 156 | struct region_register_map {
|
---|
| 157 | unsigned ve : 1;
|
---|
| 158 | unsigned : 1;
|
---|
| 159 | unsigned ps : 6;
|
---|
| 160 | unsigned rid : 24;
|
---|
| 161 | unsigned : 32;
|
---|
| 162 | } __attribute__ ((packed));
|
---|
| 163 |
|
---|
| 164 | typedef union region_register {
|
---|
| 165 | struct region_register_map map;
|
---|
| 166 | unsigned long long word;
|
---|
| 167 | } region_register;
|
---|
| 168 |
|
---|
| 169 | struct pta_register_map {
|
---|
| 170 | unsigned ve : 1;
|
---|
| 171 | unsigned : 1;
|
---|
| 172 | unsigned size : 6;
|
---|
| 173 | unsigned vf : 1;
|
---|
| 174 | unsigned : 6;
|
---|
| 175 | unsigned long long base : 49;
|
---|
| 176 | } __attribute__ ((packed));
|
---|
| 177 |
|
---|
| 178 | typedef union pta_register {
|
---|
| 179 | struct pta_register_map map;
|
---|
[7f1c620] | 180 | uint64_t word;
|
---|
[c2b95d3] | 181 | } pta_register;
|
---|
| 182 |
|
---|
| 183 | /** Return Translation Hashed Entry Address.
|
---|
| 184 | *
|
---|
| 185 | * VRN bits are used to read RID (ASID) from one
|
---|
| 186 | * of the eight region registers registers.
|
---|
| 187 | *
|
---|
| 188 | * @param va Virtual address including VRN bits.
|
---|
| 189 | *
|
---|
| 190 | * @return Address of the head of VHPT collision chain.
|
---|
| 191 | */
|
---|
[7f1c620] | 192 | static inline uint64_t thash(uint64_t va)
|
---|
[8c0d692] | 193 | {
|
---|
[7f1c620] | 194 | uint64_t ret;
|
---|
[8c0d692] | 195 |
|
---|
[c2b95d3] | 196 | __asm__ volatile ("thash %0 = %1\n" : "=r" (ret) : "r" (va));
|
---|
[6d7ffa65] | 197 |
|
---|
[c2b95d3] | 198 | return ret;
|
---|
| 199 | }
|
---|
[fd537a0] | 200 |
|
---|
[c2b95d3] | 201 | /** Return Translation Hashed Entry Tag.
|
---|
| 202 | *
|
---|
| 203 | * VRN bits are used to read RID (ASID) from one
|
---|
| 204 | * of the eight region registers.
|
---|
| 205 | *
|
---|
| 206 | * @param va Virtual address including VRN bits.
|
---|
| 207 | *
|
---|
| 208 | * @return The unique tag for VPN and RID in the collision chain returned by thash().
|
---|
| 209 | */
|
---|
[7f1c620] | 210 | static inline uint64_t ttag(uint64_t va)
|
---|
[fd537a0] | 211 | {
|
---|
[7f1c620] | 212 | uint64_t ret;
|
---|
[fd537a0] | 213 |
|
---|
[c2b95d3] | 214 | __asm__ volatile ("ttag %0 = %1\n" : "=r" (ret) : "r" (va));
|
---|
[fd537a0] | 215 |
|
---|
[c2b95d3] | 216 | return ret;
|
---|
| 217 | }
|
---|
[fd537a0] | 218 |
|
---|
[c2b95d3] | 219 | /** Read Region Register.
|
---|
| 220 | *
|
---|
| 221 | * @param i Region register index.
|
---|
| 222 | *
|
---|
| 223 | * @return Current contents of rr[i].
|
---|
| 224 | */
|
---|
[7f1c620] | 225 | static inline uint64_t rr_read(index_t i)
|
---|
[fd537a0] | 226 | {
|
---|
[7f1c620] | 227 | uint64_t ret;
|
---|
[849386a] | 228 | ASSERT(i < REGION_REGISTERS);
|
---|
[a0d74fd] | 229 | __asm__ volatile ("mov %0 = rr[%1]\n" : "=r" (ret) : "r" (i << VRN_SHIFT));
|
---|
[c2b95d3] | 230 | return ret;
|
---|
| 231 | }
|
---|
[fd537a0] | 232 |
|
---|
[c2b95d3] | 233 | /** Write Region Register.
|
---|
| 234 | *
|
---|
| 235 | * @param i Region register index.
|
---|
| 236 | * @param v Value to be written to rr[i].
|
---|
| 237 | */
|
---|
[7f1c620] | 238 | static inline void rr_write(index_t i, uint64_t v)
|
---|
[fd537a0] | 239 | {
|
---|
[849386a] | 240 | ASSERT(i < REGION_REGISTERS);
|
---|
[bc78c75] | 241 | __asm__ volatile (
|
---|
[a0d74fd] | 242 | "mov rr[%0] = %1\n"
|
---|
| 243 | :
|
---|
| 244 | : "r" (i << VRN_SHIFT), "r" (v)
|
---|
| 245 | );
|
---|
[c2b95d3] | 246 | }
|
---|
| 247 |
|
---|
| 248 | /** Read Page Table Register.
|
---|
| 249 | *
|
---|
| 250 | * @return Current value stored in PTA.
|
---|
| 251 | */
|
---|
[7f1c620] | 252 | static inline uint64_t pta_read(void)
|
---|
[c2b95d3] | 253 | {
|
---|
[7f1c620] | 254 | uint64_t ret;
|
---|
[c2b95d3] | 255 |
|
---|
| 256 | __asm__ volatile ("mov %0 = cr.pta\n" : "=r" (ret));
|
---|
| 257 |
|
---|
| 258 | return ret;
|
---|
| 259 | }
|
---|
[fd537a0] | 260 |
|
---|
[c2b95d3] | 261 | /** Write Page Table Register.
|
---|
| 262 | *
|
---|
| 263 | * @param v New value to be stored in PTA.
|
---|
| 264 | */
|
---|
[7f1c620] | 265 | static inline void pta_write(uint64_t v)
|
---|
[c2b95d3] | 266 | {
|
---|
| 267 | __asm__ volatile ("mov cr.pta = %0\n" : : "r" (v));
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | extern void page_arch_init(void);
|
---|
[c7ec94a4] | 271 |
|
---|
[7f1c620] | 272 | extern vhpt_entry_t *vhpt_hash(uintptr_t page, asid_t asid);
|
---|
| 273 | extern bool vhpt_compare(uintptr_t page, asid_t asid, vhpt_entry_t *v);
|
---|
| 274 | extern void vhpt_set_record(vhpt_entry_t *v, uintptr_t page, asid_t asid, uintptr_t frame, int flags);
|
---|
[fd537a0] | 275 |
|
---|
[d1f8a87] | 276 | #endif /* __ASM__ */
|
---|
| 277 |
|
---|
| 278 | #endif /* KERNEL */
|
---|
[5ac2e61] | 279 |
|
---|
[30ef8ce] | 280 | #endif
|
---|
[b45c443] | 281 |
|
---|
[7f1c620] | 282 | /** @}
|
---|
[b45c443] | 283 | */
|
---|