3 Copyright (c) 2006, 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
,
62 CpuMemoryServiceWrite
,
71 EFI_CPU_DATA_RECORD
*DataRecord
;
73 } EFI_CPU_DATA_RECORD_BUFFER
;
75 EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader
= {
76 EFI_PROCESSOR_SUBCLASS_VERSION
, // Version
77 sizeof (EFI_SUBCLASS_TYPE1_HEADER
), // Header Size
78 0, // Instance, Initialize later
79 EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
, // SubInstance
80 0 // RecordType, Initialize later
84 // Service routines for the driver
88 UnixFlushCpuDataCache (
89 IN EFI_CPU_ARCH_PROTOCOL
*This
,
90 IN EFI_PHYSICAL_ADDRESS Start
,
92 IN EFI_CPU_FLUSH_TYPE FlushType
98 This routine would provide support for flushing the CPU data cache.
99 In the case of UNIX emulation environment, this flushing is not necessary and
100 is thus not implemented.
104 Pointer to CPU Architectural Protocol interface
105 Start adddress in memory to flush
106 Length of memory to flush
115 // TODO: This - add argument and description to function comment
116 // TODO: FlushType - add argument and description to function comment
117 // TODO: EFI_UNSUPPORTED - add return value to function comment
119 if (FlushType
== EfiCpuFlushTypeWriteBackInvalidate
) {
121 // Only WB flush is supported. We actually need do nothing on UNIX emulator
122 // environment. Classify this to follow EFI spec
127 // Other flush types are not supported by UNIX emulator
129 return EFI_UNSUPPORTED
;
134 UnixEnableInterrupt (
135 IN EFI_CPU_ARCH_PROTOCOL
*This
141 This routine provides support for emulation of the interrupt enable of the
142 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
143 Architectural Protocol observes in order to defer behaviour while in its
144 emulated interrupt, or timer tick.
148 Pointer to CPU Architectural Protocol interface
156 // TODO: This - add argument and description to function comment
158 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
160 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
161 Private
->InterruptState
= TRUE
;
167 UnixDisableInterrupt (
168 IN EFI_CPU_ARCH_PROTOCOL
*This
174 This routine provides support for emulation of the interrupt disable of the
175 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
176 Architectural Protocol observes in order to defer behaviour while in its
177 emulated interrupt, or timer tick.
181 Pointer to CPU Architectural Protocol interface
189 // TODO: This - add argument and description to function comment
191 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
193 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
194 Private
->InterruptState
= FALSE
;
200 UnixGetInterruptState (
201 IN EFI_CPU_ARCH_PROTOCOL
*This
,
208 This routine provides support for emulation of the interrupt disable of the
209 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
210 Architectural Protocol observes in order to defer behaviour while in its
211 emulated interrupt, or timer tick.
215 Pointer to CPU Architectural Protocol interface
223 // TODO: This - add argument and description to function comment
224 // TODO: State - add argument and description to function comment
225 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
227 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
230 return EFI_INVALID_PARAMETER
;
233 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
234 *State
= Private
->InterruptState
;
241 IN EFI_CPU_ARCH_PROTOCOL
*This
,
242 IN EFI_CPU_INIT_TYPE InitType
248 This routine would support generation of a CPU INIT. At
249 present, this code does not provide emulation.
253 Pointer to CPU Architectural Protocol interface
259 EFI_UNSUPPORTED - not yet implemented
262 // TODO: This - add argument and description to function comment
263 // TODO: InitType - add argument and description to function comment
265 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
267 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
268 return EFI_UNSUPPORTED
;
273 UnixRegisterInterruptHandler (
274 IN EFI_CPU_ARCH_PROTOCOL
*This
,
275 IN EFI_EXCEPTION_TYPE InterruptType
,
276 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
282 This routine would support registration of an interrupt handler. At
283 present, this code does not provide emulation.
287 Pointer to CPU Architectural Protocol interface
288 Pointer to interrupt handlers
294 EFI_UNSUPPORTED - not yet implemented
297 // TODO: This - add argument and description to function comment
298 // TODO: InterruptType - add argument and description to function comment
299 // TODO: InterruptHandler - add argument and description to function comment
301 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
304 // Do parameter checking for EFI spec conformance
306 if (InterruptType
< 0 || InterruptType
> 0xff) {
307 return EFI_UNSUPPORTED
;
310 // Do nothing for Nt32 emulation
312 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
313 return EFI_UNSUPPORTED
;
319 IN EFI_CPU_ARCH_PROTOCOL
*This
,
320 IN UINT32 TimerIndex
,
321 OUT UINT64
*TimerValue
,
322 OUT UINT64
*TimerPeriod OPTIONAL
328 This routine would support querying of an on-CPU timer. At present,
329 this code does not provide timer emulation.
333 This - Pointer to CPU Architectural Protocol interface
334 TimerIndex - Index of given CPU timer
335 TimerValue - Output of the timer
336 TimerPeriod - Output of the timer period
340 EFI_UNSUPPORTED - not yet implemented
341 EFI_INVALID_PARAMETER - TimeValue is NULL
345 if (TimerValue
== NULL
) {
346 return EFI_INVALID_PARAMETER
;
350 // No timer supported
352 return EFI_UNSUPPORTED
;
357 UnixSetMemoryAttributes (
358 IN EFI_CPU_ARCH_PROTOCOL
*This
,
359 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
367 This routine would support querying of an on-CPU timer. At present,
368 this code does not provide timer emulation.
372 Pointer to CPU Architectural Protocol interface
373 Start address of memory region
374 The size in bytes of the memory region
375 The bit mask of attributes to set for the memory region
380 EFI_UNSUPPORTED - not yet implemented
383 // TODO: This - add argument and description to function comment
384 // TODO: BaseAddress - add argument and description to function comment
385 // TODO: Length - add argument and description to function comment
386 // TODO: Attributes - add argument and description to function comment
387 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
389 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
392 // Check for invalid parameter for Spec conformance
395 return EFI_INVALID_PARAMETER
;
399 // Do nothing for Nt32 emulation
401 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
402 return EFI_UNSUPPORTED
;
412 This function will log processor version and frequency data to data hub.
415 Event - Event whose notification function is being invoked.
416 Context - Pointer to the notification function's context.
424 EFI_CPU_DATA_RECORD_BUFFER RecordBuffer
;
427 EFI_DATA_HUB_PROTOCOL
*DataHub
;
428 EFI_HII_HANDLE HiiHandle
;
431 // Locate DataHub protocol.
433 Status
= gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, &DataHub
);
434 if (EFI_ERROR (Status
)) {
439 // Initialize data record header
441 mCpuDataRecordHeader
.Instance
= 1;
442 HeaderSize
= sizeof (EFI_SUBCLASS_TYPE1_HEADER
);
444 RecordBuffer
.Raw
= AllocatePool (HeaderSize
+ EFI_CPU_DATA_MAXIMUM_LENGTH
);
445 if (RecordBuffer
.Raw
== NULL
) {
450 // Initialize strings to HII database
452 HiiHandle
= HiiAddPackages (
458 ASSERT (HiiHandle
!= NULL
);
460 CopyMem (RecordBuffer
.Raw
, &mCpuDataRecordHeader
, HeaderSize
);
463 RecordBuffer
.DataRecord
->DataRecordHeader
.RecordType
= ProcessorVersionRecordType
;
464 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorVersion
= STRING_TOKEN (STR_INTEL_GENUINE_PROCESSOR
);
465 TotalSize
= HeaderSize
+ sizeof (EFI_PROCESSOR_VERSION_DATA
);
467 Status
= DataHub
->LogData (
469 &gEfiProcessorSubClassGuid
,
471 EFI_DATA_RECORD_CLASS_DATA
,
477 // Store CPU frequency data record to data hub - It's an emulator so make up a value
479 RecordBuffer
.DataRecord
->DataRecordHeader
.RecordType
= ProcessorCoreFrequencyRecordType
;
480 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorCoreFrequency
.Value
= 1234;
481 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorCoreFrequency
.Exponent
= 6;
482 TotalSize
= HeaderSize
+ sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA
);
484 Status
= DataHub
->LogData (
486 &gEfiProcessorSubClassGuid
,
488 EFI_DATA_RECORD_CLASS_DATA
,
493 FreePool (RecordBuffer
.Raw
);
499 IN EFI_HANDLE ImageHandle
,
500 IN EFI_SYSTEM_TABLE
*SystemTable
506 Initialize the state information for the CPU Architectural Protocol
510 ImageHandle of the loaded driver
511 Pointer to the System Table
517 EFI_SUCCESS - protocol instance can be published
518 EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure
519 EFI_DEVICE_ERROR - cannot create the thread
522 // TODO: SystemTable - add argument and description to function comment
528 Status
= gBS
->InstallMultipleProtocolInterfaces (
529 &mCpuTemplate
.Handle
,
530 &gEfiCpuArchProtocolGuid
, &mCpuTemplate
.Cpu
,
531 &gEfiCpuIoProtocolGuid
, &mCpuTemplate
.CpuIo
,
534 ASSERT_EFI_ERROR (Status
);
536 DEBUG ((EFI_D_ERROR
, "CPU Architectural Protocol Loaded\n"));