Updating ArmLib.h to add functions needed to turn on paging in CpuDxe. Also added...
[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 mInterruptState = FALSE;
18
19 EFI_STATUS
20 EFIAPI
21 CpuFlushCpuDataCache (
22 IN EFI_CPU_ARCH_PROTOCOL *This,
23 IN EFI_PHYSICAL_ADDRESS Start,
24 IN UINT64 Length,
25 IN EFI_CPU_FLUSH_TYPE FlushType
26 )
27 {
28 switch (FlushType) {
29 case EfiCpuFlushTypeWriteBack:
30 WriteBackDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);
31 break;
32 case EfiCpuFlushTypeInvalidate:
33 InvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);
34 break;
35 case EfiCpuFlushTypeWriteBackInvalidate:
36 WriteBackInvalidateDataCacheRange ((VOID *)(UINTN)Start, (UINTN)Length);
37 break;
38 default:
39 return EFI_INVALID_PARAMETER;
40 }
41
42 return EFI_SUCCESS;
43 }
44
45 EFI_STATUS
46 EFIAPI
47 CpuEnableInterrupt (
48 IN EFI_CPU_ARCH_PROTOCOL *This
49 )
50 {
51 ArmEnableInterrupts ();
52
53 mInterruptState = TRUE;
54 return EFI_SUCCESS;
55 }
56
57
58 EFI_STATUS
59 EFIAPI
60 CpuDisableInterrupt (
61 IN EFI_CPU_ARCH_PROTOCOL *This
62 )
63 {
64 ArmDisableInterrupts ();
65
66 mInterruptState = FALSE;
67 return EFI_SUCCESS;
68 }
69
70 EFI_STATUS
71 EFIAPI
72 CpuGetInterruptState (
73 IN EFI_CPU_ARCH_PROTOCOL *This,
74 OUT BOOLEAN *State
75 )
76 {
77 if (State == NULL) {
78 return EFI_INVALID_PARAMETER;
79 }
80
81 *State = mInterruptState;
82 return EFI_SUCCESS;
83 }
84
85 EFI_STATUS
86 EFIAPI
87 CpuInit (
88 IN EFI_CPU_ARCH_PROTOCOL *This,
89 IN EFI_CPU_INIT_TYPE InitType
90 )
91 {
92 return EFI_UNSUPPORTED;
93 }
94
95 EFI_STATUS
96 EFIAPI
97 CpuRegisterInterruptHandler (
98 IN EFI_CPU_ARCH_PROTOCOL *This,
99 IN EFI_EXCEPTION_TYPE InterruptType,
100 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
101 )
102 {
103 return RegisterInterruptHandler (InterruptType, InterruptHandler);
104 }
105
106 EFI_STATUS
107 EFIAPI
108 CpuGetTimerValue (
109 IN EFI_CPU_ARCH_PROTOCOL *This,
110 IN UINT32 TimerIndex,
111 OUT UINT64 *TimerValue,
112 OUT UINT64 *TimerPeriod OPTIONAL
113 )
114 {
115 return EFI_UNSUPPORTED;
116 }
117
118 EFI_STATUS
119 EFIAPI
120 CpuSetMemoryAttributes (
121 IN EFI_CPU_ARCH_PROTOCOL *This,
122 IN EFI_PHYSICAL_ADDRESS BaseAddress,
123 IN UINT64 Length,
124 IN UINT64 Attributes
125 )
126 {
127 return EFI_UNSUPPORTED;
128 }
129
130 //
131 // Globals used to initialize the protocol
132 //
133 EFI_HANDLE mCpuHandle = NULL;
134 EFI_CPU_ARCH_PROTOCOL mCpu = {
135 CpuFlushCpuDataCache,
136 CpuEnableInterrupt,
137 CpuDisableInterrupt,
138 CpuGetInterruptState,
139 CpuInit,
140 CpuRegisterInterruptHandler,
141 CpuGetTimerValue,
142 CpuSetMemoryAttributes,
143 0, // NumberOfTimers
144 4, // DmaBufferAlignment
145 };
146
147 EFI_STATUS
148 CpuDxeInitialize (
149 IN EFI_HANDLE ImageHandle,
150 IN EFI_SYSTEM_TABLE *SystemTable
151 )
152 {
153 InitializeExceptions (&mCpu);
154 return gBS->InstallMultipleProtocolInterfaces (&mCpuHandle, &gEfiCpuArchProtocolGuid, &mCpu, NULL);
155 }
156