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