Back to home page

LXR

 
 

    


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

0001 #ifndef RTEMS_VIRTEX5_MMU_H
0002 #define RTEMS_VIRTEX5_MMU_H
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsPowerPCVirtex5MMU
0007  *
0008  * @brief Routines to manipulate the PPC 440 MMU.
0009  */
0010 /*
0011  * Authorship
0012  * ----------
0013  * This software was created by
0014  *     Till Straumann <strauman@slac.stanford.edu>, 2005-2007,
0015  *       Stanford Linear Accelerator Center, Stanford University.
0016  * and was transcribed for the PPC 440 by
0017  *     R. Claus <claus@slac.stanford.edu>, 2012,
0018  *       Stanford Linear Accelerator Center, Stanford University,
0019  *
0020  * Acknowledgement of sponsorship
0021  * ------------------------------
0022  * This software was produced by
0023  *     the Stanford Linear Accelerator Center, Stanford University,
0024  *     under Contract DE-AC03-76SFO0515 with the Department of Energy.
0025  *
0026  * Government disclaimer of liability
0027  * ----------------------------------
0028  * Neither the United States nor the United States Department of Energy,
0029  * nor any of their employees, makes any warranty, express or implied, or
0030  * assumes any legal liability or responsibility for the accuracy,
0031  * completeness, or usefulness of any data, apparatus, product, or process
0032  * disclosed, or represents that its use would not infringe privately owned
0033  * rights.
0034  *
0035  * Stanford disclaimer of liability
0036  * --------------------------------
0037  * Stanford University makes no representations or warranties, express or
0038  * implied, nor assumes any liability for the use of this software.
0039  *
0040  * Stanford disclaimer of copyright
0041  * --------------------------------
0042  * Stanford University, owner of the copyright, hereby disclaims its
0043  * copyright and all other rights in this software.  Hence, anyone may
0044  * freely use it for any purpose without restriction.
0045  *
0046  * Maintenance of notices
0047  * ----------------------
0048  * In the interest of clarity regarding the origin and status of this
0049  * SLAC software, this and all the preceding Stanford University notices
0050  * are to remain affixed to any copy or derivative of this software made
0051  * or distributed by the recipient and are to be affixed to any copy of
0052  * software made or distributed by the recipient that contains a copy or
0053  * derivative of this software.
0054  *
0055  * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03
0056  */
0057 
0058 #include <rtems.h>
0059 #include <inttypes.h>
0060 #include <stdio.h>
0061 
0062 #ifdef __cplusplus
0063 extern "C" {
0064 #endif
0065 
0066 /**
0067  * @defgroup Virtex5MMU Virtex 5 - MMU Support
0068  *
0069  * @ingroup RTEMSBSPsPowerPCVirtex5
0070  *
0071  * @brief MMU support.
0072  *
0073  * @{
0074  */
0075 
0076 /* Some routines require or return an index 'key'.
0077  */
0078 typedef int bsp_tlb_idx_t;
0079 
0080 /* Cache the relevant TLB entries so that we can make sure the user cannot
0081  * create conflicting (overlapping) entries. Keep them public for informational
0082  * purposes.
0083  */
0084 typedef struct {
0085   struct {
0086     uint32_t pad:24;
0087     uint32_t tid:8;             /** Translation ID */
0088   }        id;
0089   struct {
0090     uint32_t epn:22;            /** Effective page number */
0091     uint32_t v:1;               /** Valid */
0092     uint32_t ts:1;              /** Translation Address Space */
0093     uint32_t size:4;            /** Page size */
0094     uint32_t tpar:4;            /** Tag parity */
0095   }        w0;
0096   struct {
0097     uint32_t rpn:22;            /** The real (translated) page number. */
0098     uint32_t par1:2;            /** For matching the TLB array parity */
0099     uint32_t pad:4;
0100     uint32_t erpn:4;            /** Extended Real Page Number */
0101   }        w1;
0102   struct {
0103     uint32_t par2:2;            /** Parity for TLB word 2 */
0104     uint32_t pad1:14;
0105     uint32_t att:4;             /** User-defined attributes */
0106     uint32_t wimge:5;           /** Write-Through/Caching Inhibited/Memory Coherent/Guarded/Endian */
0107     uint32_t pad2:1;
0108     uint32_t perm:6;            /** User-State Executable/Writeable/Readable Supervisor-State Executable/Writeable/Readable */
0109   }        w2;
0110 } bsp_tlb_entry_t;
0111 
0112 #define NTLBS  64
0113 
0114 extern bsp_tlb_entry_t* bsp_mmu_cache;
0115 
0116 // These constants will have to be shifted right by 20 bits before
0117 // being inserted the high word of the TLB.
0118 
0119 #define MMU_M_SIZE_1K               (0x00000000U)
0120 #define MMU_M_SIZE_4K               (0x08000000U)
0121 #define MMU_M_SIZE_16K              (0x10000000U)
0122 #define MMU_M_SIZE_64K              (0x18000000U)
0123 #define MMU_M_SIZE_256K             (0x20000000U)
0124 #define MMU_M_SIZE_1M               (0x28000000U)
0125 #define MMU_M_SIZE_16M              (0x38000000U)
0126 #define MMU_M_SIZE_256M             (0x48000000U)
0127 #define MMU_M_SIZE_MIN              (MMU_M_SIZE_1K)
0128 #define MMU_M_SIZE_MAX              (MMU_M_SIZE_256M)
0129 #define MMU_M_SIZE                  (0x78000000U)
0130 #define MMU_V_SIZE                  (27)
0131 
0132 // These constants have the same bit positions they'll occupy
0133 // in low word of the TLB.
0134 
0135 #define MMU_M_ATTR_USER0            (0x00010000U)
0136 #define MMU_M_ATTR_USER1            (0x00008000U)
0137 #define MMU_M_ATTR_USER2            (0x00004000U)
0138 #define MMU_M_ATTR_USER3            (0x00002000U)
0139 #define MMU_M_ATTR                  (0x0001e000U)
0140 #define MMU_V_ATTR                  (13)
0141 
0142 #define MMU_M_PROP_WRITE_THROUGH    (0x00001000U)
0143 #define MMU_M_PROP_UNCACHED         (0x00000800U)
0144 #define MMU_M_PROP_MEM_COHERENT     (0x00000400U)
0145 #define MMU_M_PROP_GUARDED          (0x00000200U)
0146 #define MMU_M_PROP_LITTLE_ENDIAN    (0x00000100U)
0147 #define MMU_M_PROP                  (0x00000f00U)
0148 #define MMU_V_PROP                  (8)
0149 
0150 #define MMU_M_PERM_USER_EXEC        (0x00000020U)
0151 #define MMU_M_PERM_USER_WRITE       (0x00000010U)
0152 #define MMU_M_PERM_USER_READ        (0x00000008U)
0153 #define MMU_M_PERM_SUPER_EXEC       (0x00000004U)
0154 #define MMU_M_PERM_SUPER_WRITE      (0x00000002U)
0155 #define MMU_M_PERM_SUPER_READ       (0x00000001U)
0156 #define MMU_M_PERM                  (0x0000003fU)
0157 #define MMU_V_PERM                  (0)
0158 
0159 
0160 /*
0161  * Dump (cleartext) content info from cached TLB entries
0162  * to a file (stdout if f==NULL).
0163  */
0164 void
0165 bsp_mmu_dump_cache(FILE *f);
0166 
0167 /* Read a TLB entry from the hardware and store the settings in the
0168  * bsp_mmu_cache[] structure.
0169  *
0170  * The routine can perform this operation quietly or
0171  * print information to a file.
0172  *
0173  *   'key': TLB entry index.
0174  * 'quiet': perform operation silently (no info printed) if nonzero.
0175  *     'f': open FILE where to print information. May be NULL, in
0176  *          which case 'stdout' is used.
0177  *
0178  * RETURNS:
0179  *       0: success; TLB entry is VALID
0180  *      +1: success but TLB entry is INVALID
0181  *     < 0: error (-1: invalid argument)
0182  *                (-2: driver not initialized)
0183  */
0184 int
0185 bsp_mmu_update(bsp_tlb_idx_t key, bool quiet, FILE *f);
0186 
0187 /* Initialize cache.  Should be done only once although this is not enforced.
0188  *
0189  * RETURNS: zero on success, nonzero on error; in this case the driver will
0190  *          refuse to change TLB entries (other than disabling them).
0191  */
0192 int
0193 bsp_mmu_initialize(void);
0194 
0195 /* Find first free TLB entry by examining all entries' valid bit.  The first
0196  * entry without the valid bit set is returned.
0197  *
0198  * RETURNS: A free TLB entry number.  -1 if no entry can be found.
0199  */
0200 bsp_tlb_idx_t
0201 bsp_mmu_find_first_free(void);
0202 
0203 /* Write a TLB entry (can also be used to disable an entry).
0204  *
0205  * The routine checks against the cached data in bsp_mmu_cache[]
0206  * to prevent the user from generating overlapping entries.
0207  *
0208  *   'idx': TLB entry # to manipulate
0209  *    'ea': Effective address (must be page aligned)
0210  *    'pa': Physical  address (must be page aligned)
0211  *    'sz': Page size selector; page size is 1024 * 2^(2*sz) bytes.
0212  *          'sz' may also be one of the following:
0213  *          - page size in bytes ( >= 1024 ); the selector
0214  *            value is then computed by this routine.
0215  *            However, 'sz' must be a valid page size
0216  *            or -1 will be returned.
0217  *          - a value < 0 to invalidate/disable the
0218  *            TLB entry.
0219  *  'flgs': Page's User-defined flags, permissions and WIMGE page attributes
0220  *   'tid': Translation ID
0221  *    'ts': Translation Space
0222  *  'erpn': Extended Real Page Number
0223  *
0224  * RETURNS: 0 on success, nonzero on error:
0225  *
0226  *         >0: requested mapping would overlap with
0227  *             existing mapping in another entry. Return
0228  *             value gives conflicting entry + 1; i.e.,
0229  *             if a value of 4 is returned then the request
0230  *             conflicts with existing mapping in entry 3.
0231  *         -1: invalid argument
0232  *         -3: driver not initialized (or initialization failed).
0233  *         <0: other error
0234  */
0235 bsp_tlb_idx_t
0236 bsp_mmu_write(bsp_tlb_idx_t idx, uint32_t ea, uint32_t pa, int sz,
0237               uint32_t flgs, uint32_t tid, uint32_t ts, uint32_t erpn);
0238 
0239 /* Check if a ea/tid/ts/sz mapping overlaps with an existing entry.
0240  *
0241  *    'ea': The Effective Address to match against
0242  *    'sz': The 'logarithmic' size selector; the page size
0243  *          is 1024*2^(2*sz).
0244  *   'tid': Translation ID
0245  *    'ts': Translation Space
0246  *
0247  * RETURNS:
0248  *     >= 0: index of TLB entry that already provides a mapping
0249  *           which overlaps within the ea range.
0250  *       -1: SUCCESS (no conflicting entry found)
0251  *     <=-2: ERROR (invalid input)
0252  */
0253 bsp_tlb_idx_t
0254 bsp_mmu_match(uint32_t ea, int sz, uint32_t tid, uint32_t ts);
0255 
0256 /* Find TLB index that maps 'ea/tid/ts' combination
0257  *
0258  *    'ea': Effective address to match against
0259  *   'tid': Translation ID
0260  *    'ts': Translation Space
0261  *
0262  * RETURNS: index 'key'; i.e., the index number.
0263  *
0264  *          On error (no mapping) -1 is returned.
0265  */
0266 bsp_tlb_idx_t
0267 bsp_mmu_find(uint32_t ea, uint32_t tid, uint32_t ts);
0268 
0269 /* Mark TLB entry as invalid ('disabled').
0270  *
0271  * 'key': TLB entry index.
0272  *
0273  * RETURNS: zero on success, nonzero on error (TLB unchanged).
0274  *
0275  * NOTE:  If a TLB entry is disabled the associated
0276  *        entry in bsp_tlb_cache[] is also marked as disabled.
0277  */
0278 int
0279 bsp_mmu_invalidate(bsp_tlb_idx_t key);
0280 
0281 /** @} */
0282 
0283 #ifdef __cplusplus
0284 };
0285 #endif
0286 
0287 #endif