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