Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:53

0001 #ifndef RTEMS_E500_MMU_DRIVER_H
0002 #define RTEMS_E500_MMU_DRIVER_H
0003 
0004 /*
0005  * Routines to manipulate e500 TLBs; TLB0 (fixed 4k page size)
0006  * is not very useful so we mostly focus on TLB1 (variable page size)
0007  */
0008 
0009 /*
0010  * Authorship
0011  * ----------
0012  * This software was created by
0013  *     Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
0014  *     Stanford Linear Accelerator Center, Stanford University.
0015  *
0016  * Acknowledgement of sponsorship
0017  * ------------------------------
0018  * This software was produced by
0019  *     the Stanford Linear Accelerator Center, Stanford University,
0020  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0021  *
0022  * Government disclaimer of liability
0023  * ----------------------------------
0024  * Neither the United States nor the United States Department of Energy,
0025  * nor any of their employees, makes any warranty, express or implied, or
0026  * assumes any legal liability or responsibility for the accuracy,
0027  * completeness, or usefulness of any data, apparatus, product, or process
0028  * disclosed, or represents that its use would not infringe privately owned
0029  * rights.
0030  *
0031  * Stanford disclaimer of liability
0032  * --------------------------------
0033  * Stanford University makes no representations or warranties, express or
0034  * implied, nor assumes any liability for the use of this software.
0035  *
0036  * Stanford disclaimer of copyright
0037  * --------------------------------
0038  * Stanford University, owner of the copyright, hereby disclaims its
0039  * copyright and all other rights in this software.  Hence, anyone may
0040  * freely use it for any purpose without restriction.
0041  *
0042  * Maintenance of notices
0043  * ----------------------
0044  * In the interest of clarity regarding the origin and status of this
0045  * SLAC software, this and all the preceding Stanford University notices
0046  * are to remain affixed to any copy or derivative of this software made
0047  * or distributed by the recipient and are to be affixed to any copy of
0048  * software made or distributed by the recipient that contains a copy or
0049  * derivative of this software.
0050  *
0051  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0052  */
0053 
0054 #include <rtems.h>
0055 #include <inttypes.h>
0056 #include <stdio.h>
0057 
0058 #ifdef __cplusplus
0059 extern "C" {
0060 #endif
0061 
0062 /* Some routines require or return a index 'key'. This
0063  * is simply the TLB entry # ORed with E500_SELTLB_0
0064  * or E500_SELTLB_1 specifying an entry in TLB0 or TLB1,
0065  * respectively.
0066  */
0067 typedef int rtems_e500_tlb_idx;
0068 #define E500_SELTLB_0   0x0000
0069 #define E500_SELTLB_1   0x1000
0070 
0071 /* Cache the relevant TLB1 entries so that we can
0072  * make sure the user cannot create conflicting
0073  * (overlapping) entries.
0074  * Keep them public for informational purposes.
0075  */
0076 typedef struct {
0077     struct {
0078         uint32_t va_epn: 20;
0079         uint32_t va_tid: 12;
0080     }         va;
0081     uint32_t rpn;
0082     struct {
0083         uint32_t     sz:  4;
0084         uint32_t     ts:  1;
0085         uint32_t      v:  1;
0086         uint32_t   perm: 10;
0087         uint32_t  wimge:  7;
0088     }        att;
0089 } E500_tlb_va_cache_t;
0090 
0091 extern E500_tlb_va_cache_t rtems_e500_tlb_va_cache[16];
0092 
0093 /*
0094  * Dump (cleartext) content info from cached TLB entries
0095  * to a file (stdout if f==NULL).
0096  */
0097 void
0098 rtems_e500_dmptlbc(FILE *f);
0099 
0100 /*
0101  * Read a TLB entry from the hardware; if it is a TLB1 entry
0102  * then the current settings are stored in the
0103  * rtems_e500_tlb_va_cache[] structure.
0104  *
0105  * The routine can perform this operation quietly or
0106  * print information to a file.
0107  *
0108  *   'key': TLB entry index ORed with selector bit
0109  *          (E500_SELTLB_0 for TLB0, E500_SELTLB_1 for TLB1).
0110  * 'quiet': perform operation silently (no info printed)
0111  *          if nonzero.
0112  *     'f': open FILE where to print information. May be
0113  *          NULL in which case 'stdout' is used.
0114  *
0115  * RETURNS:
0116  *       0: success; TLB entry is VALID
0117  *      +1: success but TLB entry is INVALID
0118  *     < 0: error (-1: invalid argument)
0119  */
0120 int
0121 rtems_e500_prtlb(rtems_e500_tlb_idx key, int quiet, FILE *f);
0122 
0123 /* Initialize cache; verify that TLB0 is unused;
0124  *
0125  * RETURNS: zero on success, nonzero on error (TLB0
0126  *          seems to be in use); in this case the
0127  *          driver will refuse to change TLB1 entries
0128  *          (other than disabling them).
0129  */
0130 int
0131 rtems_e500_initlb(void);
0132 
0133 /*
0134  * Write TLB1 entry (can also be used to disable an entry).
0135  *
0136  * The routine checks against the cached data in
0137  * rtems_e500_tlb_va[] to prevent the user from generating
0138  * overlapping entries.
0139  *
0140  *   'idx': TLB 1 entry # to manipulate
0141  *    'ea': Effective address (must be page aligned)
0142  *    'pa': Physical  address (must be page aligned)
0143  *    'sz': Page size selector; page size is
0144  *          1024 * 2^(2*sz) bytes.
0145  *          'sz' may also be one of the following:
0146  *          - page size in bytes ( >= 1024 ); the selector
0147  *            value is then computed by this routine.
0148  *            However, 'sz' must be a valid page size
0149  *            or -1 will be returned.
0150  *          - a value < 0 to invalidate/disable the
0151  *            TLB entry.
0152  *  'attr': Page attributes; ORed combination of WIMGE,
0153  *          PERMissions, TID and TS. Use ATTR_xxx macros
0154  *
0155  * RETURNS: 0 on success, nonzero on error:
0156  *
0157  *         >0: requested mapping would overlap with
0158  *             existing mapping in other entry. Return
0159  *             value gives conflicting entry + 1; i.e.,
0160  *             if a value of 4 is returned then the request
0161  *             conflicts with existing mapping in entry 3.
0162  *         -1: invalid argument
0163  *         -3: driver not initialized (or initialization
0164  *             failed because TLB0 is in use).
0165  *         <0: other error
0166  *
0167  */
0168 #define E500_TLB_ATTR_WIMGE(x)      ((x)&0x7f)              /* includes user bits */
0169 #define E500_TLB_ATTR_WIMGE_GET(x)  ((x)&0x7f)
0170 #define E500_TLB_ATTR_TS            (1<<7)
0171 #define E500_TLB_ATTR_PERM(x)       (((x)&0x3ff)<<8)
0172 #define E500_TLB_ATTR_PERM_GET(x)   (((x)>>8)&0x3ff)
0173 #define E500_TLB_ATTR_TID(x)        (((x)&0xfff)<<20)
0174 #define E500_TLB_ATTR_TID_GET(x)    (((x)>>20)&0xfff)
0175 
0176 int
0177 rtems_e500_wrtlb(int idx, uint32_t ea, uint32_t pa, int sz, uint32_t attr);
0178 
0179 /*
0180  * Check if a ts/tid/ea/sz mapping overlaps
0181  * with an existing entry.
0182  *
0183  * ASSUMPTION: all TLB0 (fixed 4k pages) are invalid and always unused.
0184  *
0185  * NOTE: 'sz' is the 'logarithmic' size selector; the page size
0186  *       is 1024*2^(2*sz).
0187  *
0188  * RETURNS:
0189  *     >= 0: index of TLB1 entry that already provides a mapping
0190  *           which overlaps within the ea range.
0191  *       -1: SUCCESS (no conflicting entry found)
0192  *     <=-2: ERROR (invalid input)
0193  */
0194 int
0195 rtems_e500_matchtlb(uint32_t ea, uint32_t tid, int ts, int sz);
0196 
0197 /* Find TLB index that maps 'ea/as' combination
0198  *
0199  * RETURNS: index 'key'; i.e., the index number plus
0200  *          a bit (E500_SELTLB_1) which indicates whether
0201  *          the mapping was found in TLB0 (4k fixed page
0202  *          size) or in TLB1 (variable page size).
0203  *
0204  *          On error (no mapping) -1 is returned.
0205  */
0206 rtems_e500_tlb_idx
0207 rtems_e500_ftlb(uint32_t ea, int as);
0208 
0209 /* Mark TLB entry as invalid ('disabled'). Unlike
0210  * rtems_e500_wrtlb() with a negative size argument
0211  * this routine also can disable TLB0 entries.
0212  *
0213  * 'key': TLB entry index ORed with selector bit
0214  *        (E500_SELTLB_0 for TLB0, E500_SELTLB_1 for TLB1).
0215  *
0216  * RETURNS: zero on success, nonzero on error (TLB
0217  *          unchanged).
0218  *
0219  * NOTE:  If a TLB1 entry is disabled the associated
0220  *        entry in rtems_e500_va_cache[] is also
0221  *        marked as disabled.
0222  */
0223 int
0224 rtems_e500_clrtlb(rtems_e500_tlb_idx key);
0225 
0226 #ifdef __cplusplus
0227 };
0228 #endif
0229 
0230 #endif