1 /******************************************************************************
3 * Copyright (C) 2012 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
36 * This file provides APIs for enabling/disabling MMU and setting the memory
37 * attributes for sections, in the MMU translation table.
40 * MODIFICATION HISTORY:
42 * Ver Who Date Changes
43 * ----- ---- -------- ---------------------------------------------------
44 * 1.00a sdm 01/12/12 Initial version
45 * 3.05a asa 03/10/12 Modified the Xil_EnableMMU to invalidate the caches
46 * before enabling back.
47 * 3.05a asa 04/15/12 Modified the Xil_SetTlbAttributes routine so that
48 * translation table and branch predictor arrays are
49 * invalidated, D-cache flushed before the attribute
50 * change is applied. This is done so that the user
51 * need not call Xil_DisableMMU before calling
52 * Xil_SetTlbAttributes.
53 * 3.10a srt 04/18/13 Implemented ARM Erratas. Please refer to file
54 * 'xil_errata.h' for errata description
55 * 3.11a asa 09/23/13 Modified Xil_SetTlbAttributes to flush the complete
56 * D cache after the translation table update. Removed the
57 * redundant TLB invalidation in the same API at the beginning.
64 ******************************************************************************/
66 /***************************** Include Files *********************************/
68 #include "xil_cache.h"
69 #include "xpseudo_asm.h"
70 #include "xil_types.h"
72 #include "xil_errata.h"
74 /***************** Macros (Inline Functions) Definitions *********************/
76 /**************************** Type Definitions *******************************/
78 /************************** Constant Definitions *****************************/
80 /************************** Variable Definitions *****************************/
84 /************************** Function Prototypes ******************************/
86 /*****************************************************************************
88 * Set the memory attributes for a section, in the translation table. Each
89 * section covers 1MB of memory.
91 * @param addr is the address for which attributes are to be set.
92 * @param attrib specifies the attributes for that memory region.
96 * @note The MMU and D-cache need not be disabled before changing an
97 * translation table attribute.
99 ******************************************************************************/
100 void Xil_SetTlbAttributes(u32 addr, u32 attrib)
105 section = addr / 0x100000;
106 ptr = &MMUTable + section;
107 *ptr = (addr & 0xFFF00000) | attrib;
111 mtcp(XREG_CP15_INVAL_UTLB_UNLOCKED, 0);
112 /* Invalidate all branch predictors */
113 mtcp(XREG_CP15_INVAL_BRANCH_ARRAY, 0);
115 dsb(); /* ensure completion of the BP and TLB invalidation */
116 isb(); /* synchronize context on this processor */
119 /*****************************************************************************
121 * Invalidate the caches, enable MMU and D Caches for Cortex A9 processor.
126 ******************************************************************************/
127 void Xil_EnableMMU(void)
130 Xil_DCacheInvalidate();
131 Xil_ICacheInvalidate();
134 Reg = mfcp(XREG_CP15_SYS_CONTROL);
136 { volatile register unsigned int Cp15Reg __asm(XREG_CP15_SYS_CONTROL);
140 mtcp(XREG_CP15_SYS_CONTROL, Reg);
146 /*****************************************************************************
148 * Disable MMU for Cortex A9 processors. This function invalidates the TLBs,
149 * Branch Predictor Array and flushed the D Caches before disabling
150 * the MMU and D cache.
156 ******************************************************************************/
157 void Xil_DisableMMU(void)
161 mtcp(XREG_CP15_INVAL_UTLB_UNLOCKED, 0);
162 mtcp(XREG_CP15_INVAL_BRANCH_ARRAY, 0);
166 Reg = mfcp(XREG_CP15_SYS_CONTROL);
168 { volatile register unsigned int Cp15Reg __asm(XREG_CP15_SYS_CONTROL);
172 #ifdef CONFIG_ARM_ERRATA_794073
173 /* Disable Branch Prediction */
176 mtcp(XREG_CP15_SYS_CONTROL, Reg);