![]() |
|
|||
File indexing completed on 2025-05-11 08:23:53
0001 #ifndef _LIBCPU_PTE121_H 0002 #define _LIBCPU_PTE121_H 0003 0004 /* 0005 * Authorship 0006 * ---------- 0007 * This software was created by 0008 * Till Straumann <strauman@slac.stanford.edu>, 4/2002, 2003, 2004, 0009 * Stanford Linear Accelerator Center, Stanford University. 0010 * 0011 * Acknowledgement of sponsorship 0012 * ------------------------------ 0013 * This software was produced by 0014 * the Stanford Linear Accelerator Center, Stanford University, 0015 * under Contract DE-AC03-76SFO0515 with the Department of Energy. 0016 * 0017 * Government disclaimer of liability 0018 * ---------------------------------- 0019 * Neither the United States nor the United States Department of Energy, 0020 * nor any of their employees, makes any warranty, express or implied, or 0021 * assumes any legal liability or responsibility for the accuracy, 0022 * completeness, or usefulness of any data, apparatus, product, or process 0023 * disclosed, or represents that its use would not infringe privately owned 0024 * rights. 0025 * 0026 * Stanford disclaimer of liability 0027 * -------------------------------- 0028 * Stanford University makes no representations or warranties, express or 0029 * implied, nor assumes any liability for the use of this software. 0030 * 0031 * Stanford disclaimer of copyright 0032 * -------------------------------- 0033 * Stanford University, owner of the copyright, hereby disclaims its 0034 * copyright and all other rights in this software. Hence, anyone may 0035 * freely use it for any purpose without restriction. 0036 * 0037 * Maintenance of notices 0038 * ---------------------- 0039 * In the interest of clarity regarding the origin and status of this 0040 * SLAC software, this and all the preceding Stanford University notices 0041 * are to remain affixed to any copy or derivative of this software made 0042 * or distributed by the recipient and are to be affixed to any copy of 0043 * software made or distributed by the recipient that contains a copy or 0044 * derivative of this software. 0045 * 0046 * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 0047 */ 0048 0049 /* Rudimentary page/hash table support for Powerpc 0050 * 0051 * A simple, static (i.e. no 'per-process' virtual 0052 * address space etc.) page table providing 0053 * one-to-one effective <-> virtual <-> physical 0054 * address mapping. 0055 * 0056 * PURPOSE: 0057 * 1) allow write-protection of text/read-only data areas 0058 * 2) provide more effective-address space in case 0059 * the BATs are not enough 0060 * 3) allow 'alias' mappings. Such aliases can only use 0061 * the upper bits of the VSID since VSID & 0xf and the 0062 * PI are always mapped 1:1 to the RPN. 0063 * LIMITATIONS: 0064 * - no PTE replacement (makes no sense in a real-time 0065 * environment, anyway) -> the page table just MUST 0066 * be big enough!. 0067 * - only one page table supported. 0068 * - no locking implemented. If multiple threads modify 0069 * the page table, it is the user's responsibility to 0070 * implement exclusive access. 0071 */ 0072 0073 0074 /* I don't include mmu.h here because it says it's derived from linux 0075 * and I want to avoid licensing problems 0076 */ 0077 0078 /* Abstract handle for a page table */ 0079 typedef struct Triv121PgTblRec_ *Triv121PgTbl; 0080 0081 /* A PTE entry */ 0082 typedef struct PTERec_ { 0083 volatile unsigned long v:1, vsid:24, h:1, api: 6; 0084 volatile unsigned long rpn:20, pad: 3, r:1, c:1, wimg:4, marked:1, pp:2; 0085 } PTERec, *APte; 0086 0087 /* Initialize a trivial page table 0088 * using 2^ldSize bytes of memory starting at 0089 * 'base'. 0090 * 0091 * RETURNS: a handle to the internal data structure 0092 * used to manage the page table. NULL on 0093 * error. 0094 * 0095 * NOTES: - 'base' must be aligned to the size 0096 * - minimal ldSize is 16 (== 64k) 0097 * - this routine maps the page table itself 0098 * with read-only access. While this prevents 0099 * the CPU from overwriting the page table, 0100 * it can still be corrupted by PCI bus masters 0101 * (like DMA engines, [VME] bridges etc.) and 0102 * even by this CPU if either the MMU is off 0103 * or if there is a DBAT mapping granting write 0104 * access... 0105 */ 0106 Triv121PgTbl 0107 triv121PgTblInit(unsigned long base, unsigned ldSize); 0108 0109 /* get the log2 of the minimal page table size needed 0110 * for mapping 'size' bytes. 0111 * 0112 * EXAMPLE: create a page table which maps the entire 0113 * physical memory. The page table itself shall 0114 * be allocated at the top of the available 0115 * memory (assuming 'memsize' is a power of two): 0116 * 0117 * ldSize = triv121PgTblLdMinSize(memsize); 0118 * memsize -= (1<<ldSize); / * reduce memory available to RTEMS * / 0119 * pgTbl = triv121PgTblInit(memsize,ldSize); 0120 * 0121 */ 0122 unsigned long 0123 triv121PgTblLdMinSize(unsigned long size); 0124 0125 /* Map an address range 1:1 in pgTbl with the given protection; 0126 * 0127 * RETURNS: -1 (TRIV121_MAP_SUCCESS) on success; the page index 0128 * for which no PTE could be allocated, on failure. 0129 * 0130 * NOTES: - This routine returns MINUS ONE ON SUCCESS 0131 * - (parts) of a mapping which overlap with 0132 * already existing PTEs are silently ignored. 0133 * 0134 * Therefore, you can e.g. first create 0135 * a couple of write protected maps and 0136 * finally map the entire memory r/w. This 0137 * will leave the write protected maps 0138 * intact. 0139 */ 0140 long 0141 triv121PgTblMap( 0142 Triv121PgTbl pgTbl, /* handle, returned by Init or Get */ 0143 0144 long vsid, /* vsid for this mapping (contains topmost 4 bits of EA); 0145 * 0146 * NOTE: it is allowed to pass a VSID < 0 to tell this 0147 * routine it should use a VSID corresponding to a 0148 * 1:1:1 effective - virtual - physical mapping 0149 */ 0150 0151 unsigned long start, /* segment offset (lowermost 28 bits of EA) of address range 0152 * 0153 * NOTE: if VSID < 0 (TRIV121_121_VSID), 'start' is inter- 0154 * preted as an effective address (EA), i.e. all 32 0155 * bits are used - the most significant four going into 0156 * to the VSID... 0157 */ 0158 0159 unsigned long numPages, /* number of pages to map */ 0160 0161 unsigned wimgAttr, /* 'wimg' attributes 0162 * (Write thru, cache Inhibit, coherent Memory, 0163 * Guarded memory) 0164 */ 0165 0166 unsigned protection /* 'pp' access protection: Super User 0167 * 0168 * 0 r/w none 0169 * 1 r/w ro 0170 * 2 r/w r/w 0171 * 3 ro ro 0172 */ 0173 ); 0174 0175 #define TRIV121_ATTR_W 8 0176 #define TRIV121_ATTR_I 4 0177 #define TRIV121_ATTR_M 2 0178 #define TRIV121_ATTR_G 1 0179 0180 /* for I/O pages (e.g. PCI, VME addresses) use cache inhibited 0181 * and guarded pages. RTM about the 'eieio' instruction! 0182 */ 0183 #define TRIV121_ATTR_IO_PAGE (TRIV121_ATTR_I|TRIV121_ATTR_G) 0184 0185 #define TRIV121_PP_RO_PAGE (1) /* read-only for key = 1, unlocked by key=0 */ 0186 #define TRIV121_PP_RW_PAGE (2) /* read-write for key = 1/0 */ 0187 0188 #define TRIV121_121_VSID (-1) /* use 1:1 effective<->virtual address mapping */ 0189 #define TRIV121_SEG_VSID (-2) /* lookup VSID in the segment register */ 0190 0191 #define TRIV121_MAP_SUCCESS (-1) /* triv121PgTblMap() returns this on SUCCESS */ 0192 0193 /* get a handle to the one and only page table 0194 * (must have been initialized/allocated) 0195 * 0196 * RETURNS: NULL if the page table has not been initialized/allocated. 0197 */ 0198 Triv121PgTbl 0199 triv121PgTblGet(void); 0200 0201 /* 0202 * compute the SDR1 register value for the page table 0203 */ 0204 0205 unsigned long 0206 triv121PgTblSDR1(Triv121PgTbl pgTbl); 0207 0208 /* 0209 * Activate the page table: 0210 * - set up the segment registers for a 1:1 effective <-> virtual address mapping, 0211 * give user and supervisor keys. 0212 * - set up the SDR1 register 0213 * - flush all tlbs 0214 * - 'lock' pgTbl, i.e. prevent all further modifications. 0215 * 0216 * NOTE: This routine does not change any BATs. Since these 0217 * have priority over the page table, the user 0218 * may have to switch overlapping BATs OFF in order 0219 * for the page table mappings to take effect. 0220 */ 0221 void triv121PgTblActivate(Triv121PgTbl pgTbl); 0222 0223 /* Find the PTE for a EA and print its contents to stdout 0224 * RETURNS: pte for EA or NULL if no entry was found. 0225 */ 0226 APte triv121DumpEa(unsigned long ea); 0227 0228 /* Find and return a PTE for a vsid/pi combination 0229 * RETURNS: pte or NULL if no entry was found 0230 */ 0231 APte triv121FindPte(unsigned long vsid, unsigned long pi); 0232 0233 /* 0234 * Unmap an effective address 0235 * 0236 * RETURNS: pte that mapped the ea or NULL if no 0237 * mapping existed. 0238 */ 0239 APte triv121UnmapEa(unsigned long ea); 0240 0241 /* 0242 * Change the WIMG and PP attributes of the page containing 'ea' 0243 * 0244 * NOTES: The 'wimg' and 'pp' may be <0 to indicate that no 0245 * change is desired. 0246 * 0247 * RETURNS: Pointer to modified PTE or NULL if 'ea' is not mapped. 0248 */ 0249 APte triv121ChangeEaAttributes(unsigned long ea, int wimg, int pp); 0250 0251 /* Make the whole page table writable 0252 * NOTES: If the page table has not been initialized yet, 0253 * this routine has no effect (i.e., after 0254 * initialization the page table will still be read-only). 0255 */ 0256 void triv121MakePgTblRW(void); 0257 0258 /* Make the whole page table read-only 0259 */ 0260 void triv121MakePgTblRO(void); 0261 0262 /* Dump a pte to stdout */ 0263 long triv121DumpPte(APte pte); 0264 0265 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |