mips3_pte.h revision 1.32 1 1.32 andvar /* $NetBSD: mips3_pte.h,v 1.32 2023/09/09 18:49:21 andvar Exp $ */
2 1.2 thorpej
3 1.1 jonathan /*
4 1.26 rmind * Copyright (c) 1988 University of Utah.
5 1.1 jonathan * Copyright (c) 1992, 1993
6 1.1 jonathan * The Regents of the University of California. All rights reserved.
7 1.16 agc *
8 1.16 agc * This code is derived from software contributed to Berkeley by
9 1.16 agc * the Systems Programming Group of the University of Utah Computer
10 1.16 agc * Science Department and Ralph Campbell.
11 1.16 agc *
12 1.16 agc * Redistribution and use in source and binary forms, with or without
13 1.16 agc * modification, are permitted provided that the following conditions
14 1.16 agc * are met:
15 1.16 agc * 1. Redistributions of source code must retain the above copyright
16 1.16 agc * notice, this list of conditions and the following disclaimer.
17 1.16 agc * 2. Redistributions in binary form must reproduce the above copyright
18 1.16 agc * notice, this list of conditions and the following disclaimer in the
19 1.16 agc * documentation and/or other materials provided with the distribution.
20 1.16 agc * 3. Neither the name of the University nor the names of its contributors
21 1.16 agc * may be used to endorse or promote products derived from this software
22 1.16 agc * without specific prior written permission.
23 1.16 agc *
24 1.16 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.16 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.16 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.16 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.16 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.16 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.16 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.16 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.16 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.16 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.16 agc * SUCH DAMAGE.
35 1.16 agc *
36 1.16 agc * from: Utah Hdr: pte.h 1.11 89/09/03
37 1.16 agc *
38 1.16 agc * from: @(#)pte.h 8.1 (Berkeley) 6/10/93
39 1.16 agc */
40 1.1 jonathan
41 1.27 matt #ifndef _MIPS_MIPS3_PTE_H_
42 1.30 simonb #define _MIPS_MIPS3_PTE_H_
43 1.29 matt
44 1.1 jonathan /*
45 1.1 jonathan * R4000 hardware page table entry
46 1.1 jonathan */
47 1.1 jonathan
48 1.3 jonathan #ifndef _LOCORE
49 1.29 matt #if 0
50 1.7 jonathan struct mips3_pte {
51 1.1 jonathan #if BYTE_ORDER == BIG_ENDIAN
52 1.1 jonathan unsigned int pg_prot:2, /* SW: access control */
53 1.1 jonathan pg_pfnum:24, /* HW: core page frame number or 0 */
54 1.1 jonathan pg_attr:3, /* HW: cache attribute */
55 1.9 nisimura pg_m:1, /* HW: dirty bit */
56 1.1 jonathan pg_v:1, /* HW: valid bit */
57 1.9 nisimura pg_g:1; /* HW: ignore asid bit */
58 1.1 jonathan #endif
59 1.1 jonathan #if BYTE_ORDER == LITTLE_ENDIAN
60 1.9 nisimura unsigned int pg_g:1, /* HW: ignore asid bit */
61 1.1 jonathan pg_v:1, /* HW: valid bit */
62 1.9 nisimura pg_m:1, /* HW: dirty bit */
63 1.9 nisimura pg_attr:3, /* HW: cache attribute */
64 1.1 jonathan pg_pfnum:24, /* HW: core page frame number or 0 */
65 1.1 jonathan pg_prot:2; /* SW: access control */
66 1.1 jonathan #endif
67 1.1 jonathan };
68 1.29 matt #endif
69 1.3 jonathan #endif /* _LOCORE */
70 1.1 jonathan
71 1.30 simonb #define MIPS3_PG_WIRED 0x80000000 /* SW */
72 1.30 simonb #define MIPS3_PG_RO 0x40000000 /* SW */
73 1.1 jonathan
74 1.29 matt #if PGSHIFT == 14
75 1.29 matt #define MIPS3_PG_SVPN (~0UL << 14) /* Software page no mask */
76 1.29 matt #define MIPS3_PG_HVPN (~0UL << 15) /* Hardware page no mask */
77 1.30 simonb #define MIPS3_PG_ODDPG (MIPS3_PG_SVPN ^ MIPS3_PG_HVPN)
78 1.29 matt #elif PGSHIFT == 13
79 1.29 matt #ifdef MIPS3_4100
80 1.32 andvar #error 8KB page size is not supported on the MIPS3_4100
81 1.24 matt #endif
82 1.29 matt #define MIPS3_PG_SVPN (~0UL << 13) /* Software page no mask */
83 1.29 matt #define MIPS3_PG_HVPN (~0UL << 13) /* Hardware page no mask */
84 1.30 simonb #define MIPS3_PG_NEXT (1 << (12 - MIPS3_DEFAULT_PG_SHIFT))
85 1.29 matt #elif PGSHIFT == 12
86 1.29 matt #define MIPS3_PG_SVPN (~0UL << 12) /* Software page no mask */
87 1.29 matt #define MIPS3_PG_HVPN (~0UL << 13) /* Hardware page no mask */
88 1.30 simonb #define MIPS3_PG_ODDPG (MIPS3_PG_SVPN ^ MIPS3_PG_HVPN)
89 1.29 matt #endif
90 1.29 matt /* Odd even pte entry */
91 1.7 jonathan #define MIPS3_PG_ASID 0x000000ff /* Address space ID */
92 1.7 jonathan #define MIPS3_PG_G 0x00000001 /* Global; ignore ASID if in lo0 & lo1 */
93 1.7 jonathan #define MIPS3_PG_V 0x00000002 /* Valid */
94 1.7 jonathan #define MIPS3_PG_NV 0x00000000
95 1.9 nisimura #define MIPS3_PG_D 0x00000004 /* Dirty */
96 1.7 jonathan #define MIPS3_PG_ATTR 0x0000003f
97 1.14 simonb
98 1.14 simonb #define MIPS3_CCA_TO_PG(cca) ((cca) << 3)
99 1.25 matt #define MIPS3_PG_TO_CCA(cca) (((cca) >> 3) & 7)
100 1.14 simonb
101 1.25 matt #define MIPS3_XPHYS_UNCACHED MIPS_PHYS_TO_XKPHYS(2, 0)
102 1.28 macallan #define MIPS3_XPHYS_ACC MIPS_PHYS_TO_XKPHYS(mips_options.mips3_cca_devmem, 0)
103 1.28 macallan
104 1.14 simonb #define MIPS3_PG_UNCACHED MIPS3_CCA_TO_PG(2)
105 1.28 macallan #define MIPS3_PG_WT MIPS3_CCA_TO_PG(5)
106 1.28 macallan #define MIPS3_PG_ACC MIPS3_CCA_TO_PG(mips_options.mips3_cca_devmem)
107 1.10 shin #ifdef HPCMIPS_L1CACHE_DISABLE /* MIPS3_L1CACHE_DISABLE */
108 1.25 matt #define MIPS3_DEFAULT_XKPHYS_CACHED MIPS3_DEFAULT_XKPHYS_UNCACHED
109 1.14 simonb #define MIPS3_PG_CACHED MIPS3_PG_UNCACHED /* XXX: brain damaged!!! */
110 1.10 shin #else /* HPCMIPS_L1CACHE_DISABLE */
111 1.25 matt #define MIPS3_DEFAULT_XKPHYS_CACHED MIPS_PHYS_TO_XKPHYS(3, 0)
112 1.27 matt #define MIPS3_PG_CACHED mips_options.mips3_pg_cached
113 1.14 simonb #define MIPS3_DEFAULT_PG_CACHED MIPS3_CCA_TO_PG(3)
114 1.10 shin #endif /* ! HPCMIPS_L1CACHE_DISABLE */
115 1.14 simonb #define MIPS3_PG_CACHEMODE MIPS3_CCA_TO_PG(7)
116 1.14 simonb
117 1.7 jonathan /* Write protected */
118 1.7 jonathan #define MIPS3_PG_ROPAGE (MIPS3_PG_V | MIPS3_PG_RO | MIPS3_PG_CACHED)
119 1.7 jonathan
120 1.7 jonathan /* Not wr-prot not clean */
121 1.9 nisimura #define MIPS3_PG_RWPAGE (MIPS3_PG_V | MIPS3_PG_D | MIPS3_PG_CACHED)
122 1.7 jonathan
123 1.22 macallan /* Not wr-prot not clean not cached */
124 1.22 macallan #define MIPS3_PG_RWNCPAGE (MIPS3_PG_V | MIPS3_PG_D | MIPS3_PG_UNCACHED)
125 1.22 macallan
126 1.28 macallan /* Not wr-prot not clean not cached, accel */
127 1.28 macallan #define MIPS3_PG_RWAPAGE (MIPS3_PG_V | MIPS3_PG_D | MIPS3_PG_ACC)
128 1.28 macallan
129 1.7 jonathan /* Not wr-prot but clean */
130 1.7 jonathan #define MIPS3_PG_CWPAGE (MIPS3_PG_V | MIPS3_PG_CACHED)
131 1.22 macallan
132 1.22 macallan /* Not wr-prot but clean not cached*/
133 1.22 macallan #define MIPS3_PG_CWNCPAGE (MIPS3_PG_V | MIPS3_PG_UNCACHED)
134 1.22 macallan
135 1.28 macallan /* Not wr-prot but clean not cached, accel*/
136 1.28 macallan #define MIPS3_PG_CWAPAGE (MIPS3_PG_V | MIPS3_PG_ACC)
137 1.28 macallan
138 1.14 simonb #define MIPS3_PG_IOPAGE(cca) \
139 1.14 simonb (MIPS3_PG_G | MIPS3_PG_V | MIPS3_PG_D | MIPS3_CCA_TO_PG(cca))
140 1.7 jonathan #define MIPS3_PG_FRAME 0x3fffffc0
141 1.20 tsutsui
142 1.30 simonb #define MIPS3_DEFAULT_PG_SHIFT 6
143 1.30 simonb #define MIPS3_4100_PG_SHIFT 4
144 1.20 tsutsui
145 1.20 tsutsui /* NEC Vr4100 CPUs have different PFN layout to support 1kbytes/page */
146 1.20 tsutsui #if defined(MIPS3_4100)
147 1.30 simonb #define MIPS3_PG_SHIFT mips_options.mips3_pg_shift
148 1.10 shin #else
149 1.30 simonb #define MIPS3_PG_SHIFT MIPS3_DEFAULT_PG_SHIFT
150 1.10 shin #endif
151 1.4 jonathan
152 1.4 jonathan /* pte accessor macros */
153 1.4 jonathan
154 1.30 simonb #define mips3_pfn_is_ext(x) ((x) & 0x3c000000)
155 1.30 simonb #define mips3_paddr_to_tlbpfn(x) \
156 1.13 soda (((paddr_t)(x) >> MIPS3_PG_SHIFT) & MIPS3_PG_FRAME)
157 1.30 simonb #define mips3_tlbpfn_to_paddr(x) \
158 1.13 soda ((paddr_t)((x) & MIPS3_PG_FRAME) << MIPS3_PG_SHIFT)
159 1.30 simonb #define mips3_vad_to_vpn(x) ((vaddr_t)(x) & MIPS3_PG_SVPN)
160 1.30 simonb #define mips3_vpn_to_vad(x) ((x) & MIPS3_PG_SVPN)
161 1.4 jonathan
162 1.30 simonb #define MIPS3_PTE_TO_PADDR(pte) (mips3_tlbpfn_to_paddr(pte))
163 1.30 simonb #define MIPS3_PAGE_IS_RDONLY(pte,va) \
164 1.27 matt (pmap_is_page_ro_p(pmap_kernel(), mips_trunc_page(va), (pte)))
165 1.5 jonathan
166 1.4 jonathan
167 1.7 jonathan #define MIPS3_PG_SIZE_4K 0x00000000
168 1.7 jonathan #define MIPS3_PG_SIZE_16K 0x00006000
169 1.7 jonathan #define MIPS3_PG_SIZE_64K 0x0001e000
170 1.7 jonathan #define MIPS3_PG_SIZE_256K 0x0007e000
171 1.7 jonathan #define MIPS3_PG_SIZE_1M 0x001fe000
172 1.7 jonathan #define MIPS3_PG_SIZE_4M 0x007fe000
173 1.7 jonathan #define MIPS3_PG_SIZE_16M 0x01ffe000
174 1.15 simonb #define MIPS3_PG_SIZE_64M 0x07ffe000
175 1.15 simonb #define MIPS3_PG_SIZE_256M 0x1fffe000
176 1.17 tsutsui
177 1.31 mrg #ifdef _KERNEL
178 1.18 tsutsui #define MIPS3_PG_SIZE_MASK_TO_SIZE(pg_mask) \
179 1.18 tsutsui ((((pg_mask) | 0x00001fff) + 1) / 2)
180 1.18 tsutsui
181 1.19 tsutsui #define MIPS3_PG_SIZE_TO_MASK(pg_size) \
182 1.29 matt ((((pg_size) << (((pg_size) & 0x2aaaa) == 0)) - 1) & ~0x00001fff)
183 1.29 matt
184 1.29 matt CTASSERT(MIPS3_PG_SIZE_TO_MASK(4096) == MIPS3_PG_SIZE_4K);
185 1.29 matt CTASSERT(MIPS3_PG_SIZE_TO_MASK(8192) == MIPS3_PG_SIZE_4K);
186 1.31 mrg #endif
187 1.19 tsutsui
188 1.17 tsutsui /* NEC Vr41xx uses different pagemask values. */
189 1.17 tsutsui #define MIPS4100_PG_SIZE_1K 0x00000000
190 1.17 tsutsui #define MIPS4100_PG_SIZE_4K 0x00001800
191 1.17 tsutsui #define MIPS4100_PG_SIZE_16K 0x00007800
192 1.17 tsutsui #define MIPS4100_PG_SIZE_64K 0x0001f800
193 1.17 tsutsui #define MIPS4100_PG_SIZE_256K 0x0007f800
194 1.18 tsutsui
195 1.18 tsutsui #define MIPS4100_PG_SIZE_MASK_TO_SIZE(pg_mask) \
196 1.18 tsutsui ((((pg_mask) | 0x000007ff) + 1) / 2)
197 1.19 tsutsui
198 1.19 tsutsui #define MIPS4100_PG_SIZE_TO_MASK(pg_size) \
199 1.19 tsutsui ((((pg_size) * 2) - 1) & ~0x000007ff)
200 1.19 tsutsui
201 1.27 matt #endif /* !_MIPS_MIPS3_PTE_H_ */
202