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