1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
/* $NetBSD: pte_coldfire.h,v 1.2 2014/03/18 18:20:41 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas of 3am Software Foundry.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _M68K_PTE_COLDFIRE_H_
#define _M68K_PTE_COLDFIRE_H_
#ifdef __ASSEMBLY__
#error use assym.h instead
#endif
#ifndef __BSD_PT_ENTRY_T
#define __BSD_PT_ENTRY_T __uint32_t
typedef __BSD_PT_ENTRY_T pt_entry_t;
#endif
#define MMUTR_VA __BITS(31,10) // Virtual Address
#define MMUTR_ID __BITS(9,2) // ASID
#define MMUTR_SG __BIT(1) // Shared Global
#define MMUTR_V __BIT(0) // Valid
#define MMUDR_PA __BITS(31,10) // Physical Address
#define MMUDR_SZ __BITS(9,8) // Entry Size
#define MMUDR_SZ_1MB 0
#define MMUDR_SZ_4KB 1
#define MMUDR_SZ_8KB 2
#define MMUDR_SZ_16MB 3
#define MMUDR_CM __BITS(7,6) // Cache Mode
#define MMUDR_CM_WT 0 // Write-Through
#define MMUDR_CM_WB 1 // Write-Back (Copy-Back)
#define MMUDR_CM_NC 2 // Non-cacheable
#define MMUDR_CM_NCP 2 // Non-cacheable Precise
#define MMUDR_CM_NCI 3 // Non-cacheable Imprecise
#define MMUDR_SP __BIT(5) // Supervisor Protect
#define MMUDR_R __BIT(4) // Read Access
#define MMUDR_W __BIT(3) // Write Access
#define MMUDR_X __BIT(2) // Execute Access
#define MMUDR_LK __BIT(1) // Lock Entry
#define MMUDR_MBZ0 __BIT(0) // Must be zero
/*
* The PTE basically the contents of MMUDR[31:2] | MMUAR[0].
* We overload the meaning of MMUDR_LK for indicating wired.
* It will be cleared before writing to the TLB.
*/
#ifdef _KERNEL
static inline bool
pte_cached_p(pt_entry_t pt_entry)
{
return (pt_entry & MMUDR_CM_NC) != MMUDR_CM_NC;
}
static inline bool
pte_modified_p(pt_entry_t pt_entry)
{
return (pt_entry & MMUDR_W) == MMUDR_W;
}
static inline bool
pte_valid_p(pt_entry_t pt_entry)
{
return (pt_entry & MMUAR_V) == MMUAR_V;
}
static inline bool
pte_exec_p(pt_entry_t pt_entry)
{
return (pt_entry & MMUDR_X) == MMUDR_X;
}
static inline bool
pte_deferred_exec_p(pt_entry_t pt_entry)
{
return !pte_exec_p(pt_entry);
}
static inline bool
pte_wired_p(pt_entry_t pt_entry)
{
return (pt_entry & MMUDR_LK) == MMUDR_LK;
}
static inline pt_entry_t
pte_nv_entry(bool kernel)
{
return 0;
}
static inline paddr_t
pte_to_paddr(pt_entry_t pt_entry)
{
return (paddr_t)(pt_entry & MMUDR_PA);
}
static inline pt_entry_t
pte_ionocached_bits(void)
{
return MMUDR_CM_NCP;
}
static inline pt_entry_t
pte_iocached_bits(void)
{
return MMUDR_CM_NCP;
}
static inline pt_entry_t
pte_nocached_bits(void)
{
return MMUDR_CM_NCP;
}
static inline pt_entry_t
pte_cached_bits(void)
{
return MMUDR_CM_WB;
}
static inline pt_entry_t
pte_cached_change(pt_entry_t pt_entry, bool cached)
{
return (pt_entry & ~MMUDR_CM) | (cached ? MMUDR_CM_WB : MMUDR_CM_NCP);
}
static inline pt_entry_t
pte_wire_entry(pt_entry_t pt_entry)
{
return pt_entry | MMUDR_LK;
}
static inline pt_entry_t
pte_unwire_entry(pt_entry_t pt_entry)
{
return pt_entry & ~MMUDR_LK;
}
static inline pt_entry_t
pte_prot_nowrite(pt_entry_t pt_entry)
{
return pt_entry & ~MMUDR_W;
}
static inline pt_entry_t
pte_prot_downgrade(pt_entry_t pt_entry, vm_prot_t newprot)
{
pt_entry &= ~MMUDR_W;
if ((newprot & VM_PROT_EXECUTE) == 0)
pt_entry &= ~MMUDR_X;
return pt_entry;
}
static inline pt_entry_t
pte_prot_bits(struct vm_page_md *mdpg, vm_prot_t prot)
{
KASSERT(prot & VM_PROT_READ);
pt_entry_t pt_entry = MMUDR_R;
if (prot & VM_PROT_EXECUTE) {
/* Only allow exec for managed pages */
if (mdpg != NULL && VM_PAGEMD_EXECPAGE_P(mdpg))
pt_entry |= MMUDR_X;
}
if (prot & VM_PROT_WRITE) {
if (mdpg == NULL || VM_PAGEMD_MODIFIED_P(mdpg))
pt_entry |= MMUDR_W;
}
return pt_entry;
}
static inline pt_entry_t
pte_flag_bits(struct vm_page_md *mdpg, int flags)
{
if (__predict_false(flags & PMAP_NOCACHE)) {
if (__predict_true(mdpg != NULL)) {
return pte_nocached_bits();
} else {
return pte_ionocached_bits();
}
} else {
if (__predict_false(mdpg != NULL)) {
return pte_cached_bits();
} else {
return pte_iocached_bits();
}
}
}
static inline pt_entry_t
pte_make_enter(paddr_t pa, struct vm_page_md *mdpg, vm_prot_t prot,
int flags, bool kernel)
{
pt_entry_t pt_entry = (pt_entry_t) pa & MMUDR_PA;
pt_entry |= pte_flag_bits(mdpg, flags);
pt_entry |= pte_prot_bits(mdpg, prot);
return pt_entry;
}
static inline pt_entry_t
pte_make_kenter_pa(paddr_t pa, struct vm_page_md *mdpg, vm_prot_t prot,
int flags)
{
pt_entry_t pt_entry = (pt_entry_t) pa & MMUDR_PA;
pt_entry |= MMUDR_LK;
pt_entry |= pte_flag_bits(mdpg, flags);
pt_entry |= pte_prot_bits(NULL, prot); /* pretend unmanaged */
return pt_entry;
}
#endif /* _KERNEL_ */
#endif /* _M68K_PTE_COLDFIRE_H_ */
|