RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mmu.h
Go to the documentation of this file.
1#ifndef RTEMS_VIRTEX4_MMU_H
2#define RTEMS_VIRTEX4_MMU_H
10/*
11 * Authorship
12 * ----------
13 * This software was created by
14 * Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
15 * Stanford Linear Accelerator Center, Stanford University.
16 * and was transcribed for the PPC 405 by
17 * R. Claus <claus@slac.stanford.edu>, 2012,
18 * Stanford Linear Accelerator Center, Stanford University,
19 *
20 * Acknowledgement of sponsorship
21 * ------------------------------
22 * This software was produced by
23 * the Stanford Linear Accelerator Center, Stanford University,
24 * under Contract DE-AC03-76SFO0515 with the Department of Energy.
25 *
26 * Government disclaimer of liability
27 * ----------------------------------
28 * Neither the United States nor the United States Department of Energy,
29 * nor any of their employees, makes any warranty, express or implied, or
30 * assumes any legal liability or responsibility for the accuracy,
31 * completeness, or usefulness of any data, apparatus, product, or process
32 * disclosed, or represents that its use would not infringe privately owned
33 * rights.
34 *
35 * Stanford disclaimer of liability
36 * --------------------------------
37 * Stanford University makes no representations or warranties, express or
38 * implied, nor assumes any liability for the use of this software.
39 *
40 * Stanford disclaimer of copyright
41 * --------------------------------
42 * Stanford University, owner of the copyright, hereby disclaims its
43 * copyright and all other rights in this software. Hence, anyone may
44 * freely use it for any purpose without restriction.
45 *
46 * Maintenance of notices
47 * ----------------------
48 * In the interest of clarity regarding the origin and status of this
49 * SLAC software, this and all the preceding Stanford University notices
50 * are to remain affixed to any copy or derivative of this software made
51 * or distributed by the recipient and are to be affixed to any copy of
52 * software made or distributed by the recipient that contains a copy or
53 * derivative of this software.
54 *
55 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
56 */
57
58#include <rtems.h>
59#include <inttypes.h>
60#include <stdio.h>
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
76/* Some routines require or return a index 'key'.
77 */
78typedef int bsp_tlb_idx_t;
79
80/* Cache the relevant TLB entries so that we can make sure the user cannot
81 * create conflicting (overlapping) entries. Keep them public for informational
82 * purposes.
83 */
84typedef struct {
85 struct {
86 uint32_t pad:24;
87 uint32_t tid:8;
88 } id;
89 struct {
90 uint32_t epn:22;
91 uint32_t size:3;
92 uint32_t v:1;
93 uint32_t att:2;
94 uint32_t pad:4;
95 } hi;
96 struct {
97 uint32_t rpn:22;
98 uint32_t perm:6;
99 uint32_t wimg:4;
100 } lo;
102
103#define NTLBS 64
104
105extern bsp_tlb_entry_t* bsp_mmu_cache;
106
107
108// These constants will have to be shifted right by 20 bits before
109// being inserted the high word of the TLB.
110
111#define MMU_M_SIZE_1K (0x00000000U)
112#define MMU_M_SIZE_4K (0x08000000U)
113#define MMU_M_SIZE_16K (0x10000000U)
114#define MMU_M_SIZE_64K (0x18000000U)
115#define MMU_M_SIZE_256K (0x20000000U)
116#define MMU_M_SIZE_1M (0x28000000U)
117#define MMU_M_SIZE_4M (0x30000000U)
118#define MMU_M_SIZE_16M (0x38000000U)
119#define MMU_M_SIZE_MIN (MMU_M_SIZE_1K)
120#define MMU_M_SIZE_MAX (MMU_M_SIZE_16M)
121#define MMU_M_SIZE (0x38000000U)
122#define MMU_V_SIZE (27)
123
124#define MMU_M_ATTR_LITTLE_ENDIAN (0x02000000U)
125#define MMU_M_ATTR_USER0 (0x01000000U)
126#define MMU_M_ATTR (0x03000000U)
127#define MMU_V_ATTR (24)
128
129// These constants have the same bit positions they'll occupy
130// in low word of the TLB.
131
132#define MMU_M_PERM_EXEC (0x00000200U)
133#define MMU_M_PERM_DATA_WRITE (0x00000100U)
134#define MMU_M_PERM_ZONE_SELECT (0x000000f0U)
135#define MMU_M_PERM (0x000003f0U)
136#define MMU_V_PERM (4)
137
138#define MMU_M_PROP_WRITE_THROUGH (0x00000008U)
139#define MMU_M_PROP_UNCACHED (0x00000004U)
140#define MMU_M_PROP_MEM_COHERENT (0x00000002U)
141#define MMU_M_PROP_GUARDED (0x00000001U)
142#define MMU_M_PROP (0x0000000fU)
143#define MMU_V_PROP (0)
144
145
146/*
147 * Dump (cleartext) content info from cached TLB entries
148 * to a file (stdout if f==NULL).
149 */
150void
151bsp_mmu_dump_cache(FILE *f);
152
153/* Read a TLB entry from the hardware and store the settings in the
154 * bsp_mmu_cache[] structure.
155 *
156 * The routine can perform this operation quietly or
157 * print information to a file.
158 *
159 * 'key': TLB entry index.
160 * 'quiet': perform operation silently (no info printed) if nonzero.
161 * 'f': open FILE where to print information. May be NULL, in
162 * which case 'stdout' is used.
163 *
164 * RETURNS:
165 * 0: success; TLB entry is VALID
166 * +1: success but TLB entry is INVALID
167 * < 0: error (-1: invalid argument)
168 * (-2: driver not initialized)
169 */
170int
171bsp_mmu_update(bsp_tlb_idx_t key, bool quiet, FILE *f);
172
173/* Initialize cache. Should be done only once although this is not enforced.
174 *
175 * RETURNS: zero on success, nonzero on error; in this case the driver will
176 * refuse to change TLB entries (other than disabling them).
177 */
178int
179bsp_mmu_initialize(void);
180
181/* Find first free TLB entry by examining all entries' valid bit. The first
182 * entry without the valid bit set is returned.
183 *
184 * RETURNS: A free TLB entry number. -1 if no entry can be found.
185 */
186bsp_tlb_idx_t
187bsp_mmu_find_first_free(void);
188
189/* Write a TLB entry (can also be used to disable an entry).
190 *
191 * The routine checks against the cached data in bsp_mmu_cache[]
192 * to prevent the user from generating overlapping entries.
193 *
194 * 'idx': TLB entry # to manipulate
195 * 'ea': Effective address (must be page aligned)
196 * 'pa': Physical address (must be page aligned)
197 * 'sz': Page size selector; page size is 1024 * 2^(2*sz) bytes.
198 * 'sz' may also be one of the following:
199 * - page size in bytes ( >= 1024 ); the selector
200 * value is then computed by this routine.
201 * However, 'sz' must be a valid page size
202 * or -1 will be returned.
203 * - a value < 0 to invalidate/disable the
204 * TLB entry.
205 * 'flgs': Page's little-endian & user-defined flags, permissions and attributes
206 * 'tid': Translation ID
207 *
208 * RETURNS: 0 on success, nonzero on error:
209 *
210 * >0: requested mapping would overlap with
211 * existing mapping in another entry. Return
212 * value gives conflicting entry + 1; i.e.,
213 * if a value of 4 is returned then the request
214 * conflicts with existing mapping in entry 3.
215 * -1: invalid argument
216 * -3: driver not initialized (or initialization failed).
217 * <0: other error
218 */
219bsp_tlb_idx_t
220bsp_mmu_write(bsp_tlb_idx_t idx, uint32_t ea, uint32_t pa, uint sz,
221 uint32_t flgs, uint32_t tid);
222
223/* Check if a ea/tid/sz mapping overlaps with an existing entry.
224 *
225 * 'ea': The Effective Address to match against
226 * 'sz': The 'logarithmic' size selector; the page size
227 * is 1024*2^(2*sz).
228 * 'tid': The TID to match against
229 *
230 * RETURNS:
231 * >= 0: index of TLB entry that already provides a mapping
232 * which overlaps within the ea range.
233 * -1: SUCCESS (no conflicting entry found)
234 * <=-2: ERROR (invalid input)
235 */
236bsp_tlb_idx_t
237bsp_mmu_match(uint32_t ea, int sz, uint32_t tid);
238
239/* Find TLB index that maps 'ea/tid' combination
240 *
241 * 'ea': Effective address to match against
242 * 'tid': The TID to match against
243 *
244 * RETURNS: index 'key'; i.e., the index number.
245 *
246 * On error (no mapping) -1 is returned.
247 */
248bsp_tlb_idx_t
249bsp_mmu_find(uint32_t ea, uint32_t tid);
250
251/* Mark TLB entry as invalid ('disabled').
252 *
253 * 'key': TLB entry index.
254 *
255 * RETURNS: zero on success, nonzero on error (TLB unchanged).
256 *
257 * NOTE: If a TLB entry is disabled the associated
258 * entry in bsp_mmu_cache[] is also marked as disabled.
259 */
260int
261bsp_mmu_invalidate(bsp_tlb_idx_t key);
262
265#ifdef __cplusplus
266};
267#endif
268
269#endif
Provide printf() PRIxxx Constante Beyond Standards.
Definition: mmu.h:84
uint32_t size
Definition: mmu.h:91
uint32_t wimg
Definition: mmu.h:99
uint32_t perm
Definition: mmu.h:98
uint32_t att
Definition: mmu.h:93
uint32_t pad
Definition: mmu.h:86
uint32_t v
Definition: mmu.h:92