3 Copyright (c) 2006 - 2009, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Unix Emulation Architectural Protocol Driver as defined in Tiano.
19 This CPU module abstracts the interrupt subsystem of a platform and
20 the CPU-specific setjump/long pair. Other services are not implemented
24 #include <FrameworkDxe.h>
25 #include <Protocol/Cpu.h>
26 #include <Protocol/DataHub.h>
27 #include <Guid/DataHubRecords.h>
28 #include <Protocol/CpuIo.h>
29 #include <Protocol/FrameworkHii.h>
31 #include <Library/BaseLib.h>
32 #include <Library/DebugLib.h>
33 #include <Library/HiiLib.h>
34 #include <Library/UefiLib.h>
35 #include <Library/UefiDriverEntryPoint.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/UefiBootServicesTableLib.h>
39 #include "CpuDriver.h"
41 #include <Protocol/UnixIo.h>
43 #define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100
45 CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate
= {
46 CPU_ARCH_PROT_PRIVATE_SIGNATURE
,
49 UnixFlushCpuDataCache
,
52 UnixGetInterruptState
,
54 UnixRegisterInterruptHandler
,
56 UnixSetMemoryAttributes
,
74 EFI_CPU_DATA_RECORD
*DataRecord
;
76 } EFI_CPU_DATA_RECORD_BUFFER
;
78 EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader
= {
79 EFI_PROCESSOR_SUBCLASS_VERSION
, // Version
80 sizeof (EFI_SUBCLASS_TYPE1_HEADER
), // Header Size
81 0, // Instance, Initialize later
82 EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
, // SubInstance
83 0 // RecordType, Initialize later
87 // Service routines for the driver
91 UnixFlushCpuDataCache (
92 IN EFI_CPU_ARCH_PROTOCOL
*This
,
93 IN EFI_PHYSICAL_ADDRESS Start
,
95 IN EFI_CPU_FLUSH_TYPE FlushType
101 This routine would provide support for flushing the CPU data cache.
102 In the case of UNIX emulation environment, this flushing is not necessary and
103 is thus not implemented.
107 Pointer to CPU Architectural Protocol interface
108 Start adddress in memory to flush
109 Length of memory to flush
118 // TODO: This - add argument and description to function comment
119 // TODO: FlushType - add argument and description to function comment
120 // TODO: EFI_UNSUPPORTED - add return value to function comment
122 if (FlushType
== EfiCpuFlushTypeWriteBackInvalidate
) {
124 // Only WB flush is supported. We actually need do nothing on UNIX emulator
125 // environment. Classify this to follow EFI spec
130 // Other flush types are not supported by UNIX emulator
132 return EFI_UNSUPPORTED
;
137 UnixEnableInterrupt (
138 IN EFI_CPU_ARCH_PROTOCOL
*This
144 This routine provides support for emulation of the interrupt enable of the
145 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
146 Architectural Protocol observes in order to defer behaviour while in its
147 emulated interrupt, or timer tick.
151 Pointer to CPU Architectural Protocol interface
159 // TODO: This - add argument and description to function comment
161 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
163 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
164 Private
->InterruptState
= TRUE
;
170 UnixDisableInterrupt (
171 IN EFI_CPU_ARCH_PROTOCOL
*This
177 This routine provides support for emulation of the interrupt disable of the
178 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
179 Architectural Protocol observes in order to defer behaviour while in its
180 emulated interrupt, or timer tick.
184 Pointer to CPU Architectural Protocol interface
192 // TODO: This - add argument and description to function comment
194 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
196 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
197 Private
->InterruptState
= FALSE
;
203 UnixGetInterruptState (
204 IN EFI_CPU_ARCH_PROTOCOL
*This
,
211 This routine provides support for emulation of the interrupt disable of the
212 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
213 Architectural Protocol observes in order to defer behaviour while in its
214 emulated interrupt, or timer tick.
218 Pointer to CPU Architectural Protocol interface
226 // TODO: This - add argument and description to function comment
227 // TODO: State - add argument and description to function comment
228 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
230 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
233 return EFI_INVALID_PARAMETER
;
236 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
237 *State
= Private
->InterruptState
;
244 IN EFI_CPU_ARCH_PROTOCOL
*This
,
245 IN EFI_CPU_INIT_TYPE InitType
251 This routine would support generation of a CPU INIT. At
252 present, this code does not provide emulation.
256 Pointer to CPU Architectural Protocol interface
262 EFI_UNSUPPORTED - not yet implemented
265 // TODO: This - add argument and description to function comment
266 // TODO: InitType - add argument and description to function comment
268 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
270 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
271 return EFI_UNSUPPORTED
;
276 UnixRegisterInterruptHandler (
277 IN EFI_CPU_ARCH_PROTOCOL
*This
,
278 IN EFI_EXCEPTION_TYPE InterruptType
,
279 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
285 This routine would support registration of an interrupt handler. At
286 present, this code does not provide emulation.
290 Pointer to CPU Architectural Protocol interface
291 Pointer to interrupt handlers
297 EFI_UNSUPPORTED - not yet implemented
300 // TODO: This - add argument and description to function comment
301 // TODO: InterruptType - add argument and description to function comment
302 // TODO: InterruptHandler - add argument and description to function comment
304 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
307 // Do parameter checking for EFI spec conformance
309 if (InterruptType
< 0 || InterruptType
> 0xff) {
310 return EFI_UNSUPPORTED
;
313 // Do nothing for Nt32 emulation
315 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
316 return EFI_UNSUPPORTED
;
322 IN EFI_CPU_ARCH_PROTOCOL
*This
,
323 IN UINT32 TimerIndex
,
324 OUT UINT64
*TimerValue
,
325 OUT UINT64
*TimerPeriod OPTIONAL
331 This routine would support querying of an on-CPU timer. At present,
332 this code does not provide timer emulation.
336 This - Pointer to CPU Architectural Protocol interface
337 TimerIndex - Index of given CPU timer
338 TimerValue - Output of the timer
339 TimerPeriod - Output of the timer period
343 EFI_UNSUPPORTED - not yet implemented
344 EFI_INVALID_PARAMETER - TimeValue is NULL
348 if (TimerValue
== NULL
) {
349 return EFI_INVALID_PARAMETER
;
353 // No timer supported
355 return EFI_UNSUPPORTED
;
360 UnixSetMemoryAttributes (
361 IN EFI_CPU_ARCH_PROTOCOL
*This
,
362 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
370 This routine would support querying of an on-CPU timer. At present,
371 this code does not provide timer emulation.
375 Pointer to CPU Architectural Protocol interface
376 Start address of memory region
377 The size in bytes of the memory region
378 The bit mask of attributes to set for the memory region
383 EFI_UNSUPPORTED - not yet implemented
386 // TODO: This - add argument and description to function comment
387 // TODO: BaseAddress - add argument and description to function comment
388 // TODO: Length - add argument and description to function comment
389 // TODO: Attributes - add argument and description to function comment
390 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
392 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
395 // Check for invalid parameter for Spec conformance
398 return EFI_INVALID_PARAMETER
;
402 // Do nothing for Nt32 emulation
404 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
405 return EFI_UNSUPPORTED
;
415 This function will log processor version and frequency data to data hub.
418 Event - Event whose notification function is being invoked.
419 Context - Pointer to the notification function's context.
427 EFI_CPU_DATA_RECORD_BUFFER RecordBuffer
;
430 EFI_DATA_HUB_PROTOCOL
*DataHub
;
431 EFI_HII_HANDLE HiiHandle
;
434 // Locate DataHub protocol.
436 Status
= gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, (VOID
**)&DataHub
);
437 if (EFI_ERROR (Status
)) {
442 // Initialize data record header
444 mCpuDataRecordHeader
.Instance
= 1;
445 HeaderSize
= sizeof (EFI_SUBCLASS_TYPE1_HEADER
);
447 RecordBuffer
.Raw
= AllocatePool (HeaderSize
+ EFI_CPU_DATA_MAXIMUM_LENGTH
);
448 if (RecordBuffer
.Raw
== NULL
) {
453 // Initialize strings to HII database
455 HiiHandle
= HiiAddPackages (
461 ASSERT (HiiHandle
!= NULL
);
463 CopyMem (RecordBuffer
.Raw
, &mCpuDataRecordHeader
, HeaderSize
);
466 RecordBuffer
.DataRecord
->DataRecordHeader
.RecordType
= ProcessorVersionRecordType
;
467 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorVersion
= STRING_TOKEN (STR_INTEL_GENUINE_PROCESSOR
);
468 TotalSize
= HeaderSize
+ sizeof (EFI_PROCESSOR_VERSION_DATA
);
470 Status
= DataHub
->LogData (
472 &gEfiProcessorSubClassGuid
,
474 EFI_DATA_RECORD_CLASS_DATA
,
480 // Store CPU frequency data record to data hub - It's an emulator so make up a value
482 RecordBuffer
.DataRecord
->DataRecordHeader
.RecordType
= ProcessorCoreFrequencyRecordType
;
483 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorCoreFrequency
.Value
= 1234;
484 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorCoreFrequency
.Exponent
= 6;
485 TotalSize
= HeaderSize
+ sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA
);
487 Status
= DataHub
->LogData (
489 &gEfiProcessorSubClassGuid
,
491 EFI_DATA_RECORD_CLASS_DATA
,
496 FreePool (RecordBuffer
.Raw
);
502 IN EFI_HANDLE ImageHandle
,
503 IN EFI_SYSTEM_TABLE
*SystemTable
509 Initialize the state information for the CPU Architectural Protocol
513 ImageHandle of the loaded driver
514 Pointer to the System Table
520 EFI_SUCCESS - protocol instance can be published
521 EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure
522 EFI_DEVICE_ERROR - cannot create the thread
525 // TODO: SystemTable - add argument and description to function comment
531 Status
= gBS
->InstallMultipleProtocolInterfaces (
532 &mCpuTemplate
.Handle
,
533 &gEfiCpuArchProtocolGuid
, &mCpuTemplate
.Cpu
,
534 &gEfiCpuIoProtocolGuid
, &mCpuTemplate
.CpuIo
,
537 ASSERT_EFI_ERROR (Status
);
539 DEBUG ((EFI_D_ERROR
, "CPU Architectural Protocol Loaded\n"));