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