3 Copyright (c) 2006 - 2007, 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 NT 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
26 #include "CpuDriver.h"
29 CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate
= {
30 CPU_ARCH_PROT_PRIVATE_SIGNATURE
,
33 WinNtFlushCpuDataCache
,
35 WinNtDisableInterrupt
,
36 WinNtGetInterruptState
,
38 WinNtRegisterInterruptHandler
,
40 WinNtSetMemoryAttributes
,
46 CpuMemoryServiceWrite
,
54 #define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100
59 EFI_CPU_DATA_RECORD
*DataRecord
;
61 } EFI_CPU_DATA_RECORD_BUFFER
;
63 EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader
= {
64 EFI_PROCESSOR_SUBCLASS_VERSION
, // Version
65 sizeof (EFI_SUBCLASS_TYPE1_HEADER
), // Header Size
66 0, // Instance, Initialize later
67 EFI_SUBCLASS_INSTANCE_NON_APPLICABLE
, // SubInstance
68 0 // RecordType, Initialize later
72 // Service routines for the driver
76 WinNtFlushCpuDataCache (
77 IN EFI_CPU_ARCH_PROTOCOL
*This
,
78 IN EFI_PHYSICAL_ADDRESS Start
,
80 IN EFI_CPU_FLUSH_TYPE FlushType
86 This routine would provide support for flushing the CPU data cache.
87 In the case of NT emulation environment, this flushing is not necessary and
88 is thus not implemented.
92 Pointer to CPU Architectural Protocol interface
93 Start adddress in memory to flush
94 Length of memory to flush
103 // TODO: This - add argument and description to function comment
104 // TODO: FlushType - add argument and description to function comment
105 // TODO: EFI_UNSUPPORTED - add return value to function comment
107 if (FlushType
== EfiCpuFlushTypeWriteBackInvalidate
) {
109 // Only WB flush is supported. We actually need do nothing on NT emulator
110 // environment. Classify this to follow EFI spec
115 // Other flush types are not supported by NT emulator
117 return EFI_UNSUPPORTED
;
123 WinNtEnableInterrupt (
124 IN EFI_CPU_ARCH_PROTOCOL
*This
130 This routine provides support for emulation of the interrupt enable of the
131 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
132 Architectural Protocol observes in order to defer behaviour while in its
133 emulated interrupt, or timer tick.
137 Pointer to CPU Architectural Protocol interface
145 // TODO: This - add argument and description to function comment
147 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
149 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
150 Private
->InterruptState
= TRUE
;
157 WinNtDisableInterrupt (
158 IN EFI_CPU_ARCH_PROTOCOL
*This
164 This routine provides support for emulation of the interrupt disable of the
165 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
166 Architectural Protocol observes in order to defer behaviour while in its
167 emulated interrupt, or timer tick.
171 Pointer to CPU Architectural Protocol interface
179 // TODO: This - add argument and description to function comment
181 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
183 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
184 Private
->InterruptState
= FALSE
;
191 WinNtGetInterruptState (
192 IN EFI_CPU_ARCH_PROTOCOL
*This
,
199 This routine provides support for emulation of the interrupt disable of the
200 the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
201 Architectural Protocol observes in order to defer behaviour while in its
202 emulated interrupt, or timer tick.
206 Pointer to CPU Architectural Protocol interface
214 // TODO: This - add argument and description to function comment
215 // TODO: State - add argument and description to function comment
216 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
218 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
221 return EFI_INVALID_PARAMETER
;
224 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
225 *State
= Private
->InterruptState
;
233 IN EFI_CPU_ARCH_PROTOCOL
*This
,
234 IN EFI_CPU_INIT_TYPE InitType
240 This routine would support generation of a CPU INIT. At
241 present, this code does not provide emulation.
245 Pointer to CPU Architectural Protocol interface
251 EFI_UNSUPPORTED - not yet implemented
254 // TODO: This - add argument and description to function comment
255 // TODO: InitType - add argument and description to function comment
257 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
259 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
260 return EFI_UNSUPPORTED
;
266 WinNtRegisterInterruptHandler (
267 IN EFI_CPU_ARCH_PROTOCOL
*This
,
268 IN EFI_EXCEPTION_TYPE InterruptType
,
269 IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
275 This routine would support registration of an interrupt handler. At
276 present, this code does not provide emulation.
280 Pointer to CPU Architectural Protocol interface
281 Pointer to interrupt handlers
287 EFI_UNSUPPORTED - not yet implemented
290 // TODO: This - add argument and description to function comment
291 // TODO: InterruptType - add argument and description to function comment
292 // TODO: InterruptHandler - add argument and description to function comment
294 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
297 // Do parameter checking for EFI spec conformance
299 if (InterruptType
< 0 || InterruptType
> 0xff) {
300 return EFI_UNSUPPORTED
;
303 // Do nothing for Nt32 emulation
305 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
306 return EFI_UNSUPPORTED
;
313 IN EFI_CPU_ARCH_PROTOCOL
*This
,
314 IN UINT32 TimerIndex
,
315 OUT UINT64
*TimerValue
,
316 OUT UINT64
*TimerPeriod OPTIONAL
322 This routine would support querying of an on-CPU timer. At present,
323 this code does not provide timer emulation.
327 This - Pointer to CPU Architectural Protocol interface
328 TimerIndex - Index of given CPU timer
329 TimerValue - Output of the timer
330 TimerPeriod - Output of the timer period
334 EFI_UNSUPPORTED - not yet implemented
335 EFI_INVALID_PARAMETER - TimeValue is NULL
339 if (TimerValue
== NULL
) {
340 return EFI_INVALID_PARAMETER
;
344 // No timer supported
346 return EFI_UNSUPPORTED
;
352 WinNtSetMemoryAttributes (
353 IN EFI_CPU_ARCH_PROTOCOL
*This
,
354 IN EFI_PHYSICAL_ADDRESS BaseAddress
,
362 This routine would support querying of an on-CPU timer. At present,
363 this code does not provide timer emulation.
367 Pointer to CPU Architectural Protocol interface
368 Start address of memory region
369 The size in bytes of the memory region
370 The bit mask of attributes to set for the memory region
375 EFI_UNSUPPORTED - not yet implemented
378 // TODO: This - add argument and description to function comment
379 // TODO: BaseAddress - add argument and description to function comment
380 // TODO: Length - add argument and description to function comment
381 // TODO: Attributes - add argument and description to function comment
382 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
384 CPU_ARCH_PROTOCOL_PRIVATE
*Private
;
387 // Check for invalid parameter for Spec conformance
390 return EFI_INVALID_PARAMETER
;
394 // Do nothing for Nt32 emulation
396 Private
= CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This
);
397 return EFI_UNSUPPORTED
;
408 This function will log processor version and frequency data to data hub.
411 Event - Event whose notification function is being invoked.
412 Context - Pointer to the notification function's context.
420 EFI_CPU_DATA_RECORD_BUFFER RecordBuffer
;
423 EFI_DATA_HUB_PROTOCOL
*DataHub
;
424 EFI_HII_HANDLE HiiHandle
;
427 // Locate DataHub protocol.
429 Status
= gBS
->LocateProtocol (&gEfiDataHubProtocolGuid
, NULL
, &DataHub
);
430 if (EFI_ERROR (Status
)) {
435 // Initialize data record header
437 mCpuDataRecordHeader
.Instance
= 1;
438 HeaderSize
= sizeof (EFI_SUBCLASS_TYPE1_HEADER
);
440 RecordBuffer
.Raw
= AllocatePool (HeaderSize
+ EFI_CPU_DATA_MAXIMUM_LENGTH
);
441 if (RecordBuffer
.Raw
== NULL
) {
446 // Initialize strings to HII database
448 HiiLibAddPackages (1, &gEfiProcessorProducerGuid
, NULL
, &HiiHandle
, CpuStrings
);
451 CopyMem (RecordBuffer
.Raw
, &mCpuDataRecordHeader
, HeaderSize
);
454 RecordBuffer
.DataRecord
->DataRecordHeader
.RecordType
= ProcessorVersionRecordType
;
455 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorVersion
= STRING_TOKEN (STR_PROCESSOR_VERSION
);
456 TotalSize
= HeaderSize
+ sizeof (EFI_PROCESSOR_VERSION_DATA
);
458 Status
= DataHub
->LogData (
460 &gEfiProcessorSubClassGuid
,
461 &gEfiProcessorProducerGuid
,
462 EFI_DATA_RECORD_CLASS_DATA
,
468 // Store CPU frequency data record to data hub - It's an emulator so make up a value
470 RecordBuffer
.DataRecord
->DataRecordHeader
.RecordType
= ProcessorCoreFrequencyRecordType
;
471 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorCoreFrequency
.Value
= 1234;
472 RecordBuffer
.DataRecord
->VariableRecord
.ProcessorCoreFrequency
.Exponent
= 6;
473 TotalSize
= HeaderSize
+ sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA
);
475 Status
= DataHub
->LogData (
477 &gEfiProcessorSubClassGuid
,
478 &gEfiProcessorProducerGuid
,
479 EFI_DATA_RECORD_CLASS_DATA
,
484 FreePool (RecordBuffer
.Raw
);
492 IN EFI_HANDLE ImageHandle
,
493 IN EFI_SYSTEM_TABLE
*SystemTable
499 Initialize the state information for the CPU Architectural Protocol
503 ImageHandle of the loaded driver
504 Pointer to the System Table
510 EFI_SUCCESS - protocol instance can be published
511 EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure
512 EFI_DEVICE_ERROR - cannot create the thread
520 Status
= gBS
->InstallMultipleProtocolInterfaces (
521 &mCpuTemplate
.Handle
,
522 &gEfiCpuArchProtocolGuid
, &mCpuTemplate
.Cpu
,
523 &gEfiCpuIoProtocolGuid
, &mCpuTemplate
.CpuIo
,
526 ASSERT_EFI_ERROR (Status
);