]> git.proxmox.com Git - mirror_edk2.git/blob - InOsEmuPkg/CpuRuntimeDxe/CpuDriver.h
Add MP support. Based on PcdEmuApCount APs (Application Processors) are created in...
[mirror_edk2.git] / InOsEmuPkg / CpuRuntimeDxe / CpuDriver.h
1 /*++ @file
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2011, Apple Inc. All rights reserved.
5 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 #ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
16 #define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
17
18
19 #include <FrameworkDxe.h>
20 #include <IndustryStandard/SmBios.h>
21
22 #include <Protocol/Cpu.h>
23 #include <Protocol/Smbios.h>
24 #include <Protocol/FrameworkHii.h>
25 #include <Protocol/MpService.h>
26 #include <Protocol/EmuPthreadThunk.h>
27 #include <Protocol/CpuIo2.h>
28
29 #include <Guid/DataHubRecords.h>
30
31 #include <Library/BaseLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/HiiLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/MemoryAllocationLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/EmuThunkLib.h>
39 #include <Library/UefiLib.h>
40 #include <Library/PcdLib.h>
41
42
43 extern UINT8 CpuStrings[];
44
45 //
46 // Internal Data Structures
47 //
48 #define CPU_ARCH_PROT_PRIVATE_SIGNATURE SIGNATURE_32 ('c', 'a', 'p', 'd')
49
50 typedef struct {
51 UINTN Signature;
52 EFI_HANDLE Handle;
53
54 EFI_CPU_ARCH_PROTOCOL Cpu;
55 EFI_CPU_IO2_PROTOCOL CpuIo;
56
57 //
58 // Local Data for CPU interface goes here
59 //
60 BOOLEAN InterruptState;
61
62 } CPU_ARCH_PROTOCOL_PRIVATE;
63
64 #define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
65 CR (a, \
66 CPU_ARCH_PROTOCOL_PRIVATE, \
67 Cpu, \
68 CPU_ARCH_PROT_PRIVATE_SIGNATURE \
69 )
70
71
72
73 typedef enum {
74 CPU_STATE_IDLE,
75 CPU_STATE_BLOCKED,
76 CPU_STATE_READY,
77 CPU_STATE_BUSY,
78 CPU_STATE_FINISHED
79 } PROCESSOR_STATE;
80
81
82 //
83 // Define Individual Processor Data block.
84 //
85 typedef struct {
86 EFI_PROCESSOR_INFORMATION Info;
87 EFI_AP_PROCEDURE Procedure;
88 VOID *Parameter;
89 VOID *StateLock;
90 VOID *ProcedureLock;
91 PROCESSOR_STATE State;
92 EFI_EVENT CheckThisAPEvent;
93 } PROCESSOR_DATA_BLOCK;
94
95
96 //
97 // Define MP data block which consumes individual processor block.
98 //
99 typedef struct {
100 UINTN NumberOfProcessors;
101 UINTN NumberOfEnabledProcessors;
102 EFI_EVENT CheckAllAPsEvent;
103 EFI_EVENT WaitEvent;
104 UINTN FinishCount;
105 UINTN StartCount;
106 EFI_AP_PROCEDURE Procedure;
107 VOID *ProcedureArgument;
108 BOOLEAN SingleThread;
109 UINTN StartedNumber;
110 PROCESSOR_DATA_BLOCK *ProcessorData;
111 } MP_SYSTEM_DATA;
112
113
114
115
116
117 EFI_STATUS
118 EFIAPI
119 CpuMemoryServiceRead (
120 IN EFI_CPU_IO2_PROTOCOL *This,
121 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
122 IN UINT64 Address,
123 IN UINTN Count,
124 IN OUT VOID *Buffer
125 );
126
127 EFI_STATUS
128 EFIAPI
129 CpuMemoryServiceWrite (
130 IN EFI_CPU_IO2_PROTOCOL *This,
131 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
132 IN UINT64 Address,
133 IN UINTN Count,
134 IN OUT VOID *Buffer
135 );
136
137 EFI_STATUS
138 EFIAPI
139 CpuIoServiceRead (
140 IN EFI_CPU_IO2_PROTOCOL *This,
141 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
142 IN UINT64 UserAddress,
143 IN UINTN Count,
144 IN OUT VOID *UserBuffer
145 );
146
147 EFI_STATUS
148 EFIAPI
149 CpuIoServiceWrite (
150 IN EFI_CPU_IO2_PROTOCOL *This,
151 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
152 IN UINT64 UserAddress,
153 IN UINTN Count,
154 IN OUT VOID *UserBuffer
155 );
156
157 EFI_STATUS
158 EFIAPI
159 InitializeCpu (
160 IN EFI_HANDLE ImageHandle,
161 IN EFI_SYSTEM_TABLE *SystemTable
162 );
163
164 EFI_STATUS
165 EFIAPI
166 EmuFlushCpuDataCache (
167 IN EFI_CPU_ARCH_PROTOCOL *This,
168 IN EFI_PHYSICAL_ADDRESS Start,
169 IN UINT64 Length,
170 IN EFI_CPU_FLUSH_TYPE FlushType
171 );
172
173 EFI_STATUS
174 EFIAPI
175 EmuEnableInterrupt (
176 IN EFI_CPU_ARCH_PROTOCOL *This
177 );
178
179 EFI_STATUS
180 EFIAPI
181 EmuDisableInterrupt (
182 IN EFI_CPU_ARCH_PROTOCOL *This
183 );
184
185 EFI_STATUS
186 EFIAPI
187 EmuGetInterruptState (
188 IN EFI_CPU_ARCH_PROTOCOL *This,
189 OUT BOOLEAN *State
190 );
191
192 EFI_STATUS
193 EFIAPI
194 EmuInit (
195 IN EFI_CPU_ARCH_PROTOCOL *This,
196 IN EFI_CPU_INIT_TYPE InitType
197 );
198
199 EFI_STATUS
200 EFIAPI
201 EmuRegisterInterruptHandler (
202 IN EFI_CPU_ARCH_PROTOCOL *This,
203 IN EFI_EXCEPTION_TYPE InterruptType,
204 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
205 );
206
207 EFI_STATUS
208 EFIAPI
209 EmuGetTimerValue (
210 IN EFI_CPU_ARCH_PROTOCOL *This,
211 IN UINT32 TimerIndex,
212 OUT UINT64 *TimerValue,
213 OUT UINT64 *TimerPeriod OPTIONAL
214 );
215
216 EFI_STATUS
217 EFIAPI
218 EmuSetMemoryAttributes (
219 IN EFI_CPU_ARCH_PROTOCOL *This,
220 IN EFI_PHYSICAL_ADDRESS BaseAddress,
221 IN UINT64 Length,
222 IN UINT64 Attributes
223 );
224
225 EFI_STATUS
226 CpuMpServicesInit (
227 VOID
228 );
229
230 EFI_STATUS
231 EFIAPI
232 CpuMpServicesWhoAmI (
233 IN EFI_MP_SERVICES_PROTOCOL *This,
234 OUT UINTN *ProcessorNumber
235 );
236
237 extern EFI_MP_SERVICES_PROTOCOL mMpSercicesTemplate;
238
239
240 #endif