]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v4_1/src/xil_mmu.c
Remove obsolete MPU demos.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v4_1 / src / xil_mmu.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2012 - 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 * @file xil_mmu.c
35 *
36 * This file provides APIs for enabling/disabling MMU and setting the memory
37 * attributes for sections, in the MMU translation table.
38 *
39 * <pre>
40 * MODIFICATION HISTORY:
41 *
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.
58 * </pre>
59 *
60 * @note
61 *
62 * None.
63 *
64 ******************************************************************************/
65
66 /***************************** Include Files *********************************/
67
68 #include "xil_cache.h"
69 #include "xpseudo_asm.h"
70 #include "xil_types.h"
71 #include "xil_mmu.h"
72 #include "xil_errata.h"
73
74 /***************** Macros (Inline Functions) Definitions *********************/
75
76 /**************************** Type Definitions *******************************/
77
78 /************************** Constant Definitions *****************************/
79
80 /************************** Variable Definitions *****************************/
81
82 extern u32 MMUTable;
83
84 /************************** Function Prototypes ******************************/
85
86 /*****************************************************************************
87 *
88 * Set the memory attributes for a section, in the translation table. Each
89 * section covers 1MB of memory.
90 *
91 * @param        addr is the address for which attributes are to be set.
92 * @param        attrib specifies the attributes for that memory region.
93 *
94 * @return       None.
95 *
96 * @note         The MMU and D-cache need not be disabled before changing an
97 *               translation table attribute.
98 *
99 ******************************************************************************/
100 void Xil_SetTlbAttributes(u32 addr, u32 attrib)
101 {
102         u32 *ptr;
103         u32 section;
104
105         section = addr / 0x100000;
106         ptr = &MMUTable + section;
107         *ptr = (addr & 0xFFF00000) | attrib;
108
109         Xil_DCacheFlush();
110
111         mtcp(XREG_CP15_INVAL_UTLB_UNLOCKED, 0);
112         /* Invalidate all branch predictors */
113         mtcp(XREG_CP15_INVAL_BRANCH_ARRAY, 0);
114
115         dsb(); /* ensure completion of the BP and TLB invalidation */
116     isb(); /* synchronize context on this processor */
117 }
118
119 /*****************************************************************************
120 *
121 * Invalidate the caches, enable MMU and D Caches for Cortex A9 processor.
122 *
123 * @param        None.
124 * @return       None.
125 *
126 ******************************************************************************/
127 void Xil_EnableMMU(void)
128 {
129         u32 Reg;
130         Xil_DCacheInvalidate();
131         Xil_ICacheInvalidate();
132
133 #ifdef __GNUC__
134         Reg = mfcp(XREG_CP15_SYS_CONTROL);
135 #else
136         { volatile register unsigned int Cp15Reg __asm(XREG_CP15_SYS_CONTROL);
137           Reg = Cp15Reg; }
138 #endif
139         Reg |= 0x05;
140         mtcp(XREG_CP15_SYS_CONTROL, Reg);
141
142         dsb();
143         isb();
144 }
145
146 /*****************************************************************************
147 *
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.
151 *
152 * @param        None.
153 *
154 * @return       None.
155 *
156 ******************************************************************************/
157 void Xil_DisableMMU(void)
158 {
159         u32 Reg;
160
161         mtcp(XREG_CP15_INVAL_UTLB_UNLOCKED, 0);
162         mtcp(XREG_CP15_INVAL_BRANCH_ARRAY, 0);
163         Xil_DCacheFlush();
164
165 #ifdef __GNUC__
166         Reg = mfcp(XREG_CP15_SYS_CONTROL);
167 #else
168         { volatile register unsigned int Cp15Reg __asm(XREG_CP15_SYS_CONTROL);
169           Reg = Cp15Reg; }
170 #endif
171         Reg &= ~0x05;
172 #ifdef CONFIG_ARM_ERRATA_794073
173         /* Disable Branch Prediction */
174         Reg &= ~0x800;
175 #endif
176         mtcp(XREG_CP15_SYS_CONTROL, Reg);
177 }