blob: 9442786713a5728be7d459f96e2c7c09f4737aab [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/*++ @file
2
3Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4Portions copyright (c) 2011, Apple Inc. All rights reserved.
5
6This program and the accompanying materials
7are licensed and made available under the terms and conditions of the BSD License
8which accompanies this distribution. The full text of the license may be found at
9http://opensource.org/licenses/bsd-license.php
10
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14**/
15
16#ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
17#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
18
19
20#include <PiDxe.h>
21#include <IndustryStandard/SmBios.h>
22
23#include <Protocol/Cpu.h>
24#include <Protocol/Smbios.h>
25#include <Protocol/MpService.h>
26#include <Protocol/EmuThread.h>
27#include <Protocol/CpuIo2.h>
28
29#include <Guid/IdleLoopEvent.h>
30
31#include <Library/BaseLib.h>
32#include <Library/DebugLib.h>
33#include <Library/UefiDriverEntryPoint.h>
34#include <Library/BaseMemoryLib.h>
35#include <Library/MemoryAllocationLib.h>
36#include <Library/UefiBootServicesTableLib.h>
37#include <Library/EmuThunkLib.h>
38#include <Library/UefiLib.h>
39#include <Library/PcdLib.h>
40
41
42
43//
44// Internal Data Structures
45//
46#define CPU_ARCH_PROT_PRIVATE_SIGNATURE SIGNATURE_32 ('c', 'a', 'p', 'd')
47
48typedef struct {
49 UINTN Signature;
50 EFI_HANDLE Handle;
51
52 EFI_CPU_ARCH_PROTOCOL Cpu;
53 EFI_CPU_IO2_PROTOCOL CpuIo;
54
55 //
56 // Local Data for CPU interface goes here
57 //
58 BOOLEAN InterruptState;
59
60} CPU_ARCH_PROTOCOL_PRIVATE;
61
62#define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
63 CR (a, \
64 CPU_ARCH_PROTOCOL_PRIVATE, \
65 Cpu, \
66 CPU_ARCH_PROT_PRIVATE_SIGNATURE \
67 )
68
69
70
71typedef enum {
72 CPU_STATE_IDLE,
73 CPU_STATE_BLOCKED,
74 CPU_STATE_READY,
75 CPU_STATE_BUSY,
76 CPU_STATE_FINISHED
77} PROCESSOR_STATE;
78
79
80//
81// Define Individual Processor Data block.
82//
83typedef struct {
84 EFI_PROCESSOR_INFORMATION Info;
85 EFI_AP_PROCEDURE Procedure;
86 VOID *Parameter;
87 VOID *StateLock;
88 VOID *ProcedureLock;
89 PROCESSOR_STATE State;
90 EFI_EVENT CheckThisAPEvent;
91} PROCESSOR_DATA_BLOCK;
92
93
94//
95// Define MP data block which consumes individual processor block.
96//
97typedef struct {
98 UINTN NumberOfProcessors;
99 UINTN NumberOfEnabledProcessors;
100 EFI_EVENT CheckAllAPsEvent;
101 EFI_EVENT WaitEvent;
102 UINTN FinishCount;
103 UINTN StartCount;
104 EFI_AP_PROCEDURE Procedure;
105 VOID *ProcedureArgument;
106 BOOLEAN SingleThread;
107 UINTN StartedNumber;
108 PROCESSOR_DATA_BLOCK *ProcessorData;
109 UINTN Timeout;
110 UINTN *FailedList;
111 UINTN FailedListIndex;
112 BOOLEAN TimeoutActive;
113} MP_SYSTEM_DATA;
114
115
116
117
118
119EFI_STATUS
120EFIAPI
121CpuMemoryServiceRead (
122 IN EFI_CPU_IO2_PROTOCOL *This,
123 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
124 IN UINT64 Address,
125 IN UINTN Count,
126 IN OUT VOID *Buffer
127 );
128
129EFI_STATUS
130EFIAPI
131CpuMemoryServiceWrite (
132 IN EFI_CPU_IO2_PROTOCOL *This,
133 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
134 IN UINT64 Address,
135 IN UINTN Count,
136 IN OUT VOID *Buffer
137 );
138
139EFI_STATUS
140EFIAPI
141CpuIoServiceRead (
142 IN EFI_CPU_IO2_PROTOCOL *This,
143 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
144 IN UINT64 UserAddress,
145 IN UINTN Count,
146 IN OUT VOID *UserBuffer
147 );
148
149EFI_STATUS
150EFIAPI
151CpuIoServiceWrite (
152 IN EFI_CPU_IO2_PROTOCOL *This,
153 IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
154 IN UINT64 UserAddress,
155 IN UINTN Count,
156 IN OUT VOID *UserBuffer
157 );
158
159EFI_STATUS
160EFIAPI
161InitializeCpu (
162 IN EFI_HANDLE ImageHandle,
163 IN EFI_SYSTEM_TABLE *SystemTable
164 );
165
166EFI_STATUS
167EFIAPI
168EmuFlushCpuDataCache (
169 IN EFI_CPU_ARCH_PROTOCOL *This,
170 IN EFI_PHYSICAL_ADDRESS Start,
171 IN UINT64 Length,
172 IN EFI_CPU_FLUSH_TYPE FlushType
173 );
174
175EFI_STATUS
176EFIAPI
177EmuEnableInterrupt (
178 IN EFI_CPU_ARCH_PROTOCOL *This
179 );
180
181EFI_STATUS
182EFIAPI
183EmuDisableInterrupt (
184 IN EFI_CPU_ARCH_PROTOCOL *This
185 );
186
187EFI_STATUS
188EFIAPI
189EmuGetInterruptState (
190 IN EFI_CPU_ARCH_PROTOCOL *This,
191 OUT BOOLEAN *State
192 );
193
194EFI_STATUS
195EFIAPI
196EmuInit (
197 IN EFI_CPU_ARCH_PROTOCOL *This,
198 IN EFI_CPU_INIT_TYPE InitType
199 );
200
201EFI_STATUS
202EFIAPI
203EmuRegisterInterruptHandler (
204 IN EFI_CPU_ARCH_PROTOCOL *This,
205 IN EFI_EXCEPTION_TYPE InterruptType,
206 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
207 );
208
209EFI_STATUS
210EFIAPI
211EmuGetTimerValue (
212 IN EFI_CPU_ARCH_PROTOCOL *This,
213 IN UINT32 TimerIndex,
214 OUT UINT64 *TimerValue,
215 OUT UINT64 *TimerPeriod OPTIONAL
216 );
217
218EFI_STATUS
219EFIAPI
220EmuSetMemoryAttributes (
221 IN EFI_CPU_ARCH_PROTOCOL *This,
222 IN EFI_PHYSICAL_ADDRESS BaseAddress,
223 IN UINT64 Length,
224 IN UINT64 Attributes
225 );
226
227EFI_STATUS
228CpuMpServicesInit (
229 OUT UINTN *MaxCores
230 );
231
232EFI_STATUS
233EFIAPI
234CpuMpServicesWhoAmI (
235 IN EFI_MP_SERVICES_PROTOCOL *This,
236 OUT UINTN *ProcessorNumber
237 );
238
239extern EFI_MP_SERVICES_PROTOCOL mMpServicesTemplate;
240
241
242#endif