source: mainline/kernel/arch/mips32/include/mm/tlb.h@ d704d7f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d704d7f was d704d7f, checked in by Jakub Jermar <jakub@…>, 13 years ago

MIPS R4000 and 4Kc have different widths of the TLB index.

  • 6 bits for R4000
  • 4 bits for 4Kc
  • Property mode set to 100644
File size: 4.6 KB
Line 
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 mips32mm
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_mips32_TLB_H_
36#define KERN_mips32_TLB_H_
37
38#include <typedefs.h>
39#include <arch/mm/asid.h>
40#include <arch/exception.h>
41#include <trace.h>
42
43#if defined(PROCESSOR_R4000)
44#define TLB_ENTRY_COUNT 48
45#define TLB_INDEX_BITS 6
46#elif defined(PROCESSOR_4Kc)
47#define TLB_ENTRY_COUNT 16
48#define TLB_INDEX_BITS 4
49#else
50#error Please define TLB_ENTRY_COUNT for the target processor.
51#endif
52
53#define TLB_WIRED 1
54#define TLB_KSTACK_WIRED_INDEX 0
55
56#define TLB_PAGE_MASK_4K (0x000 << 13)
57#define TLB_PAGE_MASK_16K (0x003 << 13)
58#define TLB_PAGE_MASK_64K (0x00f << 13)
59#define TLB_PAGE_MASK_256K (0x03f << 13)
60#define TLB_PAGE_MASK_1M (0x0ff << 13)
61#define TLB_PAGE_MASK_4M (0x3ff << 13)
62#define TLB_PAGE_MASK_16M (0xfff << 13)
63
64#define PAGE_UNCACHED 2
65#define PAGE_CACHEABLE_EXC_WRITE 5
66
67typedef union {
68 struct {
69#ifdef __BE__
70 unsigned : 2; /* zero */
71 unsigned pfn : 24; /* frame number */
72 unsigned c : 3; /* cache coherency attribute */
73 unsigned d : 1; /* dirty/write-protect bit */
74 unsigned v : 1; /* valid bit */
75 unsigned g : 1; /* global bit */
76#else
77 unsigned g : 1; /* global bit */
78 unsigned v : 1; /* valid bit */
79 unsigned d : 1; /* dirty/write-protect bit */
80 unsigned c : 3; /* cache coherency attribute */
81 unsigned pfn : 24; /* frame number */
82 unsigned : 2; /* zero */
83#endif
84 } __attribute__ ((packed));
85 uint32_t value;
86} entry_lo_t;
87
88typedef union {
89 struct {
90#ifdef __BE__
91 unsigned vpn2 : 19;
92 unsigned : 5;
93 unsigned asid : 8;
94#else
95 unsigned asid : 8;
96 unsigned : 5;
97 unsigned vpn2 : 19;
98#endif
99 } __attribute__ ((packed));
100 uint32_t value;
101} entry_hi_t;
102
103typedef union {
104 struct {
105#ifdef __BE__
106 unsigned : 7;
107 unsigned mask : 12;
108 unsigned : 13;
109#else
110 unsigned : 13;
111 unsigned mask : 12;
112 unsigned : 7;
113#endif
114 } __attribute__ ((packed));
115 uint32_t value;
116} page_mask_t;
117
118typedef union {
119 struct {
120#ifdef __BE__
121 unsigned p : 1;
122 unsigned : 32 - TLB_INDEX_BITS - 1;
123 unsigned index : TLB_INDEX_BITS;
124#else
125 unsigned index : TLB_INDEX_BITS;
126 unsigned : 32 - TLB_INDEX_BITS - 1;
127 unsigned p : 1;
128#endif
129 } __attribute__ ((packed));
130 uint32_t value;
131} tlb_index_t;
132
133/** Probe TLB for Matching Entry
134 *
135 * Probe TLB for Matching Entry.
136 */
137NO_TRACE static inline void tlbp(void)
138{
139 asm volatile ("tlbp\n\t");
140}
141
142
143/** Read Indexed TLB Entry
144 *
145 * Read Indexed TLB Entry.
146 */
147NO_TRACE static inline void tlbr(void)
148{
149 asm volatile ("tlbr\n\t");
150}
151
152/** Write Indexed TLB Entry
153 *
154 * Write Indexed TLB Entry.
155 */
156NO_TRACE static inline void tlbwi(void)
157{
158 asm volatile ("tlbwi\n\t");
159}
160
161/** Write Random TLB Entry
162 *
163 * Write Random TLB Entry.
164 */
165NO_TRACE static inline void tlbwr(void)
166{
167 asm volatile ("tlbwr\n\t");
168}
169
170#define tlb_invalidate(asid) tlb_invalidate_asid(asid)
171
172extern void tlb_invalid(istate_t *istate);
173extern void tlb_refill(istate_t *istate);
174extern void tlb_modified(istate_t *istate);
175extern void tlb_prepare_entry_lo(entry_lo_t *lo, bool g, bool v, bool d, bool cacheable, uintptr_t pfn);
176extern void tlb_prepare_entry_hi(entry_hi_t *hi, asid_t asid, uintptr_t addr);
177
178#endif
179
180/** @}
181 */
Note: See TracBrowser for help on using the repository browser.