]>
Commit | Line | Data |
---|---|---|
2ef2b01e A |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2008-2009, Apple Inc. All rights reserved.\r | |
4 | \r | |
5 | All rights reserved. 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 | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "CpuDxe.h"\r | |
16 | \r | |
8a4d81e6 A |
17 | BOOLEAN mInterruptState = FALSE;\r |
18 | \r | |
f659880b A |
19 | \r |
20 | /**\r | |
21 | This function flushes the range of addresses from Start to Start+Length \r | |
22 | from the processor's data cache. If Start is not aligned to a cache line \r | |
23 | boundary, then the bytes before Start to the preceding cache line boundary \r | |
24 | are also flushed. If Start+Length is not aligned to a cache line boundary, \r | |
25 | then the bytes past Start+Length to the end of the next cache line boundary \r | |
26 | are also flushed. The FlushType of EfiCpuFlushTypeWriteBackInvalidate must be \r | |
27 | supported. If the data cache is fully coherent with all DMA operations, then \r | |
28 | this function can just return EFI_SUCCESS. If the processor does not support \r | |
29 | flushing a range of the data cache, then the entire data cache can be flushed.\r | |
30 | \r | |
31 | @param This The EFI_CPU_ARCH_PROTOCOL instance.\r | |
32 | @param Start The beginning physical address to flush from the processor's data\r | |
33 | cache.\r | |
34 | @param Length The number of bytes to flush from the processor's data cache. This\r | |
35 | function may flush more bytes than Length specifies depending upon\r | |
36 | the granularity of the flush operation that the processor supports.\r | |
37 | @param FlushType Specifies the type of flush operation to perform.\r | |
38 | \r | |
39 | @retval EFI_SUCCESS The address range from Start to Start+Length was flushed from\r | |
40 | the processor's data cache.\r | |
41 | @retval EFI_UNSUPPORTEDT The processor does not support the cache flush type specified\r | |
42 | by FlushType.\r | |
43 | @retval EFI_DEVICE_ERROR The address range from Start to Start+Length could not be flushed\r | |
44 | from the processor's data cache.\r | |
45 | \r | |
46 | **/\r | |
2ef2b01e A |
47 | EFI_STATUS\r |
48 | EFIAPI\r | |
49 | CpuFlushCpuDataCache (\r | |
50 | IN EFI_CPU_ARCH_PROTOCOL *This,\r | |
51 | IN EFI_PHYSICAL_ADDRESS Start,\r | |
52 | IN UINT64 Length,\r | |
53 | IN EFI_CPU_FLUSH_TYPE FlushType\r | |
54 | )\r | |
55 | {\r | |
f659880b A |
56 | DEBUG ((EFI_D_ERROR, "CpuFlushCpuDataCache (%lx, %lx, %x)\n", Start, Length, FlushType));\r |
57 | \r | |
2ef2b01e A |
58 | switch (FlushType) {\r |
59 | case EfiCpuFlushTypeWriteBack:\r | |
8a4d81e6 | 60 | WriteBackDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);\r |
2ef2b01e A |
61 | break;\r |
62 | case EfiCpuFlushTypeInvalidate:\r | |
8a4d81e6 | 63 | InvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);\r |
2ef2b01e A |
64 | break;\r |
65 | case EfiCpuFlushTypeWriteBackInvalidate:\r | |
8a4d81e6 | 66 | WriteBackInvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);\r |
2ef2b01e A |
67 | break;\r |
68 | default:\r | |
69 | return EFI_INVALID_PARAMETER;\r | |
70 | }\r | |
71 | \r | |
72 | return EFI_SUCCESS;\r | |
73 | }\r | |
74 | \r | |
f659880b A |
75 | \r |
76 | /**\r | |
77 | This function enables interrupt processing by the processor. \r | |
78 | \r | |
79 | @param This The EFI_CPU_ARCH_PROTOCOL instance.\r | |
80 | \r | |
81 | @retval EFI_SUCCESS Interrupts are enabled on the processor.\r | |
82 | @retval EFI_DEVICE_ERROR Interrupts could not be enabled on the processor.\r | |
83 | \r | |
84 | **/\r | |
2ef2b01e A |
85 | EFI_STATUS\r |
86 | EFIAPI\r | |
87 | CpuEnableInterrupt (\r | |
88 | IN EFI_CPU_ARCH_PROTOCOL *This\r | |
89 | )\r | |
90 | {\r | |
d213712d | 91 | ArmEnableInterrupts ();\r |
8a4d81e6 A |
92 | \r |
93 | mInterruptState = TRUE;\r | |
2ef2b01e A |
94 | return EFI_SUCCESS;\r |
95 | }\r | |
96 | \r | |
97 | \r | |
f659880b A |
98 | /**\r |
99 | This function disables interrupt processing by the processor.\r | |
100 | \r | |
101 | @param This The EFI_CPU_ARCH_PROTOCOL instance.\r | |
102 | \r | |
103 | @retval EFI_SUCCESS Interrupts are disabled on the processor.\r | |
104 | @retval EFI_DEVICE_ERROR Interrupts could not be disabled on the processor.\r | |
105 | \r | |
106 | **/\r | |
2ef2b01e A |
107 | EFI_STATUS\r |
108 | EFIAPI\r | |
109 | CpuDisableInterrupt (\r | |
110 | IN EFI_CPU_ARCH_PROTOCOL *This\r | |
111 | )\r | |
112 | {\r | |
d213712d | 113 | ArmDisableInterrupts ();\r |
8a4d81e6 A |
114 | \r |
115 | mInterruptState = FALSE;\r | |
2ef2b01e A |
116 | return EFI_SUCCESS;\r |
117 | }\r | |
118 | \r | |
f659880b A |
119 | \r |
120 | /**\r | |
121 | This function retrieves the processor's current interrupt state a returns it in \r | |
122 | State. If interrupts are currently enabled, then TRUE is returned. If interrupts \r | |
123 | are currently disabled, then FALSE is returned.\r | |
124 | \r | |
125 | @param This The EFI_CPU_ARCH_PROTOCOL instance.\r | |
126 | @param State A pointer to the processor's current interrupt state. Set to TRUE if\r | |
127 | interrupts are enabled and FALSE if interrupts are disabled.\r | |
128 | \r | |
129 | @retval EFI_SUCCESS The processor's current interrupt state was returned in State.\r | |
130 | @retval EFI_INVALID_PARAMETER State is NULL.\r | |
131 | \r | |
132 | **/\r | |
2ef2b01e A |
133 | EFI_STATUS\r |
134 | EFIAPI\r | |
135 | CpuGetInterruptState (\r | |
136 | IN EFI_CPU_ARCH_PROTOCOL *This,\r | |
137 | OUT BOOLEAN *State\r | |
138 | )\r | |
139 | {\r | |
140 | if (State == NULL) {\r | |
141 | return EFI_INVALID_PARAMETER;\r | |
142 | }\r | |
143 | \r | |
8a4d81e6 | 144 | *State = mInterruptState;\r |
2ef2b01e A |
145 | return EFI_SUCCESS;\r |
146 | }\r | |
147 | \r | |
f659880b A |
148 | \r |
149 | /**\r | |
150 | This function generates an INIT on the processor. If this function succeeds, then the\r | |
151 | processor will be reset, and control will not be returned to the caller. If InitType is \r | |
152 | not supported by this processor, or the processor cannot programmatically generate an \r | |
153 | INIT without help from external hardware, then EFI_UNSUPPORTED is returned. If an error \r | |
154 | occurs attempting to generate an INIT, then EFI_DEVICE_ERROR is returned.\r | |
155 | \r | |
156 | @param This The EFI_CPU_ARCH_PROTOCOL instance.\r | |
157 | @param InitType The type of processor INIT to perform.\r | |
158 | \r | |
159 | @retval EFI_SUCCESS The processor INIT was performed. This return code should never be seen.\r | |
160 | @retval EFI_UNSUPPORTED The processor INIT operation specified by InitType is not supported\r | |
161 | by this processor.\r | |
162 | @retval EFI_DEVICE_ERROR The processor INIT failed.\r | |
163 | \r | |
164 | **/\r | |
2ef2b01e A |
165 | EFI_STATUS\r |
166 | EFIAPI\r | |
167 | CpuInit (\r | |
168 | IN EFI_CPU_ARCH_PROTOCOL *This,\r | |
169 | IN EFI_CPU_INIT_TYPE InitType\r | |
170 | )\r | |
171 | {\r | |
172 | return EFI_UNSUPPORTED;\r | |
173 | }\r | |
174 | \r | |
175 | EFI_STATUS\r | |
176 | EFIAPI\r | |
177 | CpuRegisterInterruptHandler (\r | |
178 | IN EFI_CPU_ARCH_PROTOCOL *This,\r | |
179 | IN EFI_EXCEPTION_TYPE InterruptType,\r | |
180 | IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r | |
181 | )\r | |
182 | {\r | |
8a4d81e6 | 183 | return RegisterInterruptHandler (InterruptType, InterruptHandler);\r |
2ef2b01e A |
184 | }\r |
185 | \r | |
186 | EFI_STATUS\r | |
187 | EFIAPI\r | |
188 | CpuGetTimerValue (\r | |
189 | IN EFI_CPU_ARCH_PROTOCOL *This,\r | |
190 | IN UINT32 TimerIndex,\r | |
191 | OUT UINT64 *TimerValue,\r | |
192 | OUT UINT64 *TimerPeriod OPTIONAL\r | |
193 | )\r | |
194 | {\r | |
195 | return EFI_UNSUPPORTED;\r | |
196 | }\r | |
197 | \r | |
2ef2b01e A |
198 | \r |
199 | //\r | |
200 | // Globals used to initialize the protocol\r | |
201 | //\r | |
202 | EFI_HANDLE mCpuHandle = NULL;\r | |
203 | EFI_CPU_ARCH_PROTOCOL mCpu = {\r | |
204 | CpuFlushCpuDataCache,\r | |
205 | CpuEnableInterrupt,\r | |
206 | CpuDisableInterrupt,\r | |
207 | CpuGetInterruptState,\r | |
208 | CpuInit,\r | |
209 | CpuRegisterInterruptHandler,\r | |
210 | CpuGetTimerValue,\r | |
211 | CpuSetMemoryAttributes,\r | |
212 | 0, // NumberOfTimers\r | |
213 | 4, // DmaBufferAlignment\r | |
214 | };\r | |
215 | \r | |
216 | EFI_STATUS\r | |
217 | CpuDxeInitialize (\r | |
218 | IN EFI_HANDLE ImageHandle,\r | |
219 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
220 | )\r | |
f659880b A |
221 | {\r |
222 | EFI_STATUS Status;\r | |
223 | \r | |
8a4d81e6 | 224 | InitializeExceptions (&mCpu); \r |
f659880b A |
225 | \r |
226 | \r | |
227 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
228 | &mCpuHandle, \r | |
229 | &gEfiCpuArchProtocolGuid, &mCpu, \r | |
230 | &gVirtualUncachedPagesProtocolGuid, &gVirtualUncachedPages,\r | |
231 | NULL\r | |
232 | );\r | |
233 | \r | |
234 | //\r | |
235 | // Make sure GCD and MMU settings match. This API calls gDS->SetMemorySpaceAttributes ()\r | |
236 | // and that calls EFI_CPU_ARCH_PROTOCOL.SetMemoryAttributes, so this code needs to go\r | |
237 | // after the protocol is installed\r | |
238 | //\r | |
239 | SyncCacheConfig (&mCpu);\r | |
240 | \r | |
241 | return Status;\r | |
2ef2b01e A |
242 | }\r |
243 | \r |