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