]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/Drivers/PL310L2Cache/PL310L2Cache.c
ARM Packages: Removed trailing spaces
[mirror_edk2.git] / ArmPlatformPkg / Drivers / PL310L2Cache / PL310L2Cache.c
CommitLineData
633724f4 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
633724f4 4*\r
3402aac7
RC
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
633724f4 12*\r
13**/\r
14\r
15#include <Library/IoLib.h>\r
16#include <Library/DebugLib.h>\r
17#include <Library/ArmLib.h>\r
18#include <Drivers/PL310L2Cache.h>\r
19#include <Library/PcdLib.h>\r
20\r
21#define L2x0WriteReg(reg,val) MmioWrite32(PcdGet32(PcdL2x0ControllerBase) + reg, val)\r
22#define L2x0ReadReg(reg) MmioRead32(PcdGet32(PcdL2x0ControllerBase) + reg)\r
23\r
24// Initialize PL320 L2 Cache Controller\r
25VOID\r
26L2x0CacheInit (\r
27 IN UINTN L2x0Base,\r
28 IN UINT32 L2x0TagLatencies,\r
29 IN UINT32 L2x0DataLatencies,\r
30 IN UINT32 L2x0AuxValue,\r
31 IN UINT32 L2x0AuxMask,\r
32 IN BOOLEAN CacheEnabled\r
33 )\r
34{\r
35 UINT32 Data;\r
36 UINT32 Revision;\r
37 UINT32 Aux;\r
38 UINT32 PfCtl;\r
39 UINT32 PwrCtl;\r
40\r
41 // Check if L2x0 is present and is an ARM implementation\r
42 Data = L2x0ReadReg(L2X0_CACHEID);\r
43 if ((Data >> 24) != L2X0_CACHEID_IMPLEMENTER_ARM) {\r
44 ASSERT(0);\r
45 return;\r
46 }\r
47\r
48 // Check if L2x0 is PL310\r
49 if (((Data >> 6) & 0xF) != L2X0_CACHEID_PARTNUM_PL310) {\r
50 ASSERT(0);\r
51 return;\r
52 }\r
53\r
54 // RTL release\r
55 Revision = Data & 0x3F;\r
56\r
57 // Check if L2x0 is already enabled then we disable it\r
58 Data = L2x0ReadReg(L2X0_CTRL);\r
59 if (Data & L2X0_CTRL_ENABLED) {\r
60 L2x0WriteReg(L2X0_CTRL, L2X0_CTRL_DISABLED);\r
61 }\r
62\r
63 //\r
64 // Set up global configurations\r
65 //\r
66\r
67 // Auxiliary register: Non-secure interrupt access Control + Event monitor bus enable + SBO\r
68 Aux = L2X0_AUXCTRL_NSAC | L2X0_AUXCTRL_EM | L2X0_AUXCTRL_SBO;\r
69 // Use AWCACHE attributes for WA\r
70 Aux |= L2x0_AUXCTRL_AW_AWCACHE;\r
71 // Use default Size\r
72 Data = L2x0ReadReg(L2X0_AUXCTRL);\r
73 Aux |= Data & L2X0_AUXCTRL_WAYSIZE_MASK;\r
74 // Use default associativity\r
75 Aux |= Data & L2X0_AUXCTRL_ASSOCIATIVITY;\r
76 // Enabled I & D Prefetch\r
77 Aux |= L2x0_AUXCTRL_IPREFETCH | L2x0_AUXCTRL_DPREFETCH;\r
78\r
79 if (Revision >= 5) {\r
80 // Prefetch Offset Register\r
81 PfCtl = L2x0ReadReg(L2X0_PFCTRL);\r
82 // - Prefetch increment set to 0\r
83 // - Prefetch dropping off\r
84 // - Double linefills off\r
85 L2x0WriteReg(L2X0_PFCTRL, PfCtl);\r
86\r
87 // Power Control Register - L2X0_PWRCTRL\r
88 PwrCtl = L2x0ReadReg(L2X0_PWRCTRL);\r
89 // - Standby when idle off\r
90 // - Dynamic clock gating off\r
91 // - Nc,NC-shared dropping off\r
92 L2x0WriteReg(L2X0_PWRCTRL, PwrCtl);\r
93 }\r
94\r
95 if (Revision >= 2) {\r
96 L2x0WriteReg(L230_TAG_LATENCY, L2x0TagLatencies);\r
97 L2x0WriteReg(L230_DATA_LATENCY, L2x0DataLatencies);\r
98 } else {\r
99 // PL310 old style latency is not supported yet\r
100 ASSERT(0);\r
101 }\r
102\r
103 // Set the platform specific values\r
104 Aux = (Aux & L2x0AuxMask) | L2x0AuxValue;\r
105\r
106 // Write Auxiliary value\r
107 L2x0WriteReg(L2X0_AUXCTRL, Aux);\r
108\r
109 //\r
110 // Invalidate all entries in cache\r
111 //\r
112 L2x0WriteReg(L2X0_INVWAY, 0xffff);\r
113 // Poll cache maintenance register until invalidate operation is complete\r
114 while(L2x0ReadReg(L2X0_INVWAY) & 0xffff);\r
115\r
116 // Write to the Lockdown D and Lockdown I Register 9 if required\r
117 // - Not required\r
118\r
119 // Clear any residual raw interrupts\r
120 L2x0WriteReg(L2X0_INTCLEAR, 0x1FF);\r
121\r
122 // Enable the cache\r
123 if (CacheEnabled) {\r
124 L2x0WriteReg(L2X0_CTRL, L2X0_CTRL_ENABLED);\r
125 }\r
126}\r