00001 /* 00002 * Copyright (C) 2003-2004 Jakub Jermar 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * - Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * - Redistributions in binary form must reproduce the above copyright 00012 * notice, this list of conditions and the following disclaimer in the 00013 * documentation and/or other materials provided with the distribution. 00014 * - The name of the author may not be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00018 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00019 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00020 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00035 #ifndef __mips32_TLB_H__ 00036 #define __mips32_TLB_H__ 00037 00038 #include <arch/exception.h> 00039 #include <typedefs.h> 00040 00041 #ifdef TLBCNT 00042 # define TLB_ENTRY_COUNT TLBCNT 00043 #else 00044 # define TLB_ENTRY_COUNT 48 00045 #endif 00046 00047 #define TLB_WIRED 1 00048 #define TLB_KSTACK_WIRED_INDEX 0 00049 00050 #define TLB_PAGE_MASK_16K (0x3<<13) 00051 00052 #define PAGE_UNCACHED 2 00053 #define PAGE_CACHEABLE_EXC_WRITE 5 00054 00055 typedef union entry_lo entry_lo_t; 00056 typedef union entry_hi entry_hi_t; 00057 typedef union page_mask page_mask_t; 00058 typedef union index tlb_index_t; 00059 00060 union entry_lo { 00061 struct { 00062 #ifdef BIG_ENDIAN 00063 unsigned : 2; /* zero */ 00064 unsigned pfn : 24; /* frame number */ 00065 unsigned c : 3; /* cache coherency attribute */ 00066 unsigned d : 1; /* dirty/write-protect bit */ 00067 unsigned v : 1; /* valid bit */ 00068 unsigned g : 1; /* global bit */ 00069 #else 00070 unsigned g : 1; /* global bit */ 00071 unsigned v : 1; /* valid bit */ 00072 unsigned d : 1; /* dirty/write-protect bit */ 00073 unsigned c : 3; /* cache coherency attribute */ 00074 unsigned pfn : 24; /* frame number */ 00075 unsigned : 2; /* zero */ 00076 #endif 00077 } __attribute__ ((packed)); 00078 __u32 value; 00079 }; 00080 00082 struct pte { 00083 unsigned g : 1; 00084 unsigned p : 1; 00085 unsigned d : 1; 00086 unsigned cacheable : 1; 00087 unsigned : 1; 00088 unsigned soft_valid : 1; 00089 unsigned pfn : 24; 00090 unsigned w : 1; 00091 unsigned a : 1; 00092 }; 00093 00094 union entry_hi { 00095 struct { 00096 #ifdef BIG_ENDIAN 00097 unsigned vpn2 : 19; 00098 unsigned : 5; 00099 unsigned asid : 8; 00100 #else 00101 unsigned asid : 8; 00102 unsigned : 5; 00103 unsigned vpn2 : 19; 00104 #endif 00105 } __attribute__ ((packed)); 00106 __u32 value; 00107 }; 00108 00109 union page_mask { 00110 struct { 00111 #ifdef BIG_ENDIAN 00112 unsigned : 7; 00113 unsigned mask : 12; 00114 unsigned : 13; 00115 #else 00116 unsigned : 13; 00117 unsigned mask : 12; 00118 unsigned : 7; 00119 #endif 00120 } __attribute__ ((packed)); 00121 __u32 value; 00122 }; 00123 00124 union index { 00125 struct { 00126 #ifdef BIG_ENDIAN 00127 unsigned p : 1; 00128 unsigned : 27; 00129 unsigned index : 4; 00130 #else 00131 unsigned index : 4; 00132 unsigned : 27; 00133 unsigned p : 1; 00134 #endif 00135 } __attribute__ ((packed)); 00136 __u32 value; 00137 }; 00138 00143 static inline void tlbp(void) 00144 { 00145 __asm__ volatile ("tlbp\n\t"); 00146 } 00147 00148 00153 static inline void tlbr(void) 00154 { 00155 __asm__ volatile ("tlbr\n\t"); 00156 } 00157 00162 static inline void tlbwi(void) 00163 { 00164 __asm__ volatile ("tlbwi\n\t"); 00165 } 00166 00171 static inline void tlbwr(void) 00172 { 00173 __asm__ volatile ("tlbwr\n\t"); 00174 } 00175 00176 #define tlb_invalidate(asid) tlb_invalidate_asid(asid) 00177 00178 extern void tlb_invalid(istate_t *istate); 00179 extern void tlb_refill(istate_t *istate); 00180 extern void tlb_modified(istate_t *istate); 00181 00182 #endif 00183