Adding support for a single stack, GCC check in will follow
[mirror_edk2.git] / ArmPkg / Drivers / CpuDxe / CpuDxe.c
1 /** @file
2
3 Copyright (c) 2008-2009, Apple Inc. All rights reserved.
4
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "CpuDxe.h"
16
17 BOOLEAN gExceptionContext = FALSE;
18 BOOLEAN mInterruptState = FALSE;
19
20 EFI_STATUS
21 EFIAPI
22 CpuFlushCpuDataCache (
23 IN EFI_CPU_ARCH_PROTOCOL *This,
24 IN EFI_PHYSICAL_ADDRESS Start,
25 IN UINT64 Length,
26 IN EFI_CPU_FLUSH_TYPE FlushType
27 )
28 {
29 switch (FlushType) {
30 case EfiCpuFlushTypeWriteBack:
31 WriteBackDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);
32 break;
33 case EfiCpuFlushTypeInvalidate:
34 InvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);
35 break;
36 case EfiCpuFlushTypeWriteBackInvalidate:
37 WriteBackInvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);
38 break;
39 default:
40 return EFI_INVALID_PARAMETER;
41 }
42
43 return EFI_SUCCESS;
44 }
45
46 EFI_STATUS
47 EFIAPI
48 CpuEnableInterrupt (
49 IN EFI_CPU_ARCH_PROTOCOL *This
50 )
51 {
52 if (!gExceptionContext) {
53 ArmEnableInterrupts ();
54 }
55
56 mInterruptState = TRUE;
57 return EFI_SUCCESS;
58 }
59
60
61 EFI_STATUS
62 EFIAPI
63 CpuDisableInterrupt (
64 IN EFI_CPU_ARCH_PROTOCOL *This
65 )
66 {
67 if (!gExceptionContext) {
68 ArmDisableInterrupts ();
69 }
70
71 mInterruptState = FALSE;
72 return EFI_SUCCESS;
73 }
74
75 EFI_STATUS
76 EFIAPI
77 CpuGetInterruptState (
78 IN EFI_CPU_ARCH_PROTOCOL *This,
79 OUT BOOLEAN *State
80 )
81 {
82 if (State == NULL) {
83 return EFI_INVALID_PARAMETER;
84 }
85
86 *State = mInterruptState;
87 return EFI_SUCCESS;
88 }
89
90 EFI_STATUS
91 EFIAPI
92 CpuInit (
93 IN EFI_CPU_ARCH_PROTOCOL *This,
94 IN EFI_CPU_INIT_TYPE InitType
95 )
96 {
97 return EFI_UNSUPPORTED;
98 }
99
100 EFI_STATUS
101 EFIAPI
102 CpuRegisterInterruptHandler (
103 IN EFI_CPU_ARCH_PROTOCOL *This,
104 IN EFI_EXCEPTION_TYPE InterruptType,
105 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
106 )
107 {
108 return RegisterInterruptHandler (InterruptType, InterruptHandler);
109 }
110
111 EFI_STATUS
112 EFIAPI
113 CpuGetTimerValue (
114 IN EFI_CPU_ARCH_PROTOCOL *This,
115 IN UINT32 TimerIndex,
116 OUT UINT64 *TimerValue,
117 OUT UINT64 *TimerPeriod OPTIONAL
118 )
119 {
120 return EFI_UNSUPPORTED;
121 }
122
123 EFI_STATUS
124 EFIAPI
125 CpuSetMemoryAttributes (
126 IN EFI_CPU_ARCH_PROTOCOL *This,
127 IN EFI_PHYSICAL_ADDRESS BaseAddress,
128 IN UINT64 Length,
129 IN UINT64 Attributes
130 )
131 {
132 return EFI_UNSUPPORTED;
133 }
134
135 //
136 // Globals used to initialize the protocol
137 //
138 EFI_HANDLE mCpuHandle = NULL;
139 EFI_CPU_ARCH_PROTOCOL mCpu = {
140 CpuFlushCpuDataCache,
141 CpuEnableInterrupt,
142 CpuDisableInterrupt,
143 CpuGetInterruptState,
144 CpuInit,
145 CpuRegisterInterruptHandler,
146 CpuGetTimerValue,
147 CpuSetMemoryAttributes,
148 0, // NumberOfTimers
149 4, // DmaBufferAlignment
150 };
151
152 EFI_STATUS
153 CpuDxeInitialize (
154 IN EFI_HANDLE ImageHandle,
155 IN EFI_SYSTEM_TABLE *SystemTable
156 )
157 {
158 InitializeExceptions (&mCpu);
159 return gBS->InstallMultipleProtocolInterfaces (&mCpuHandle, &gEfiCpuArchProtocolGuid, &mCpu, NULL);
160 }
161