+++ /dev/null
-/**@file\r
-\r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-Module Name:\r
-\r
- Cpu.c\r
-\r
-Abstract:\r
-\r
- NT Emulation Architectural Protocol Driver as defined in Tiano.\r
- This CPU module abstracts the interrupt subsystem of a platform and\r
- the CPU-specific setjump/long pair. Other services are not implemented\r
- in this driver.\r
-\r
-**/\r
-\r
-\r
-#include "CpuDriver.h"\r
-\r
-UINT64 mTimerPeriod;\r
-\r
-CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {\r
- CPU_ARCH_PROT_PRIVATE_SIGNATURE,\r
- NULL,\r
- {\r
- WinNtFlushCpuDataCache,\r
- WinNtEnableInterrupt,\r
- WinNtDisableInterrupt,\r
- WinNtGetInterruptState,\r
- WinNtInit,\r
- WinNtRegisterInterruptHandler,\r
- WinNtGetTimerValue,\r
- WinNtSetMemoryAttributes,\r
- 1,\r
- 4\r
- },\r
- {\r
- CpuMemoryServiceRead,\r
- CpuMemoryServiceWrite,\r
- CpuIoServiceRead,\r
- CpuIoServiceWrite\r
- },\r
- 0,\r
- TRUE\r
-};\r
-\r
-#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
-\r
-\r
-\r
-//\r
-// Service routines for the driver\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtFlushCpuDataCache (\r
- IN EFI_CPU_ARCH_PROTOCOL *This,\r
- IN EFI_PHYSICAL_ADDRESS Start,\r
- IN UINT64 Length,\r
- IN EFI_CPU_FLUSH_TYPE FlushType\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine would provide support for flushing the CPU data cache.\r
- In the case of NT emulation environment, this flushing is not necessary and\r
- is thus not implemented.\r
-\r
-Arguments:\r
-\r
- Pointer to CPU Architectural Protocol interface\r
- Start adddress in memory to flush\r
- Length of memory to flush\r
- Flush type\r
-\r
-Returns:\r
-\r
- Status\r
- EFI_SUCCESS\r
-\r
---*/\r
-// TODO: This - add argument and description to function comment\r
-// TODO: FlushType - add argument and description to function comment\r
-// TODO: EFI_UNSUPPORTED - add return value to function comment\r
-{\r
- if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
- //\r
- // Only WB flush is supported. We actually need do nothing on NT emulator\r
- // environment. Classify this to follow EFI spec\r
- //\r
- return EFI_SUCCESS;\r
- }\r
- //\r
- // Other flush types are not supported by NT emulator\r
- //\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtEnableInterrupt (\r
- IN EFI_CPU_ARCH_PROTOCOL *This\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine provides support for emulation of the interrupt enable of the\r
- the system. For our purposes, CPU enable is just a BOOLEAN that the Timer\r
- Architectural Protocol observes in order to defer behaviour while in its\r
- emulated interrupt, or timer tick.\r
-\r
-Arguments:\r
-\r
- Pointer to CPU Architectural Protocol interface\r
-\r
-Returns:\r
-\r
- Status\r
- EFI_SUCCESS\r
-\r
---*/\r
-// TODO: This - add argument and description to function comment\r
-{\r
- CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
-\r
- Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
- Private->InterruptState = TRUE;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtDisableInterrupt (\r
- IN EFI_CPU_ARCH_PROTOCOL *This\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine provides support for emulation of the interrupt disable of the\r
- the system. For our purposes, CPU enable is just a BOOLEAN that the Timer\r
- Architectural Protocol observes in order to defer behaviour while in its\r
- emulated interrupt, or timer tick.\r
-\r
-Arguments:\r
-\r
- Pointer to CPU Architectural Protocol interface\r
-\r
-Returns:\r
-\r
- Status\r
- EFI_SUCCESS\r
-\r
---*/\r
-// TODO: This - add argument and description to function comment\r
-{\r
- CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
-\r
- Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
- Private->InterruptState = FALSE;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtGetInterruptState (\r
- IN EFI_CPU_ARCH_PROTOCOL *This,\r
- OUT BOOLEAN *State\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine provides support for emulation of the interrupt disable of the\r
- the system. For our purposes, CPU enable is just a BOOLEAN that the Timer\r
- Architectural Protocol observes in order to defer behaviour while in its\r
- emulated interrupt, or timer tick.\r
-\r
-Arguments:\r
-\r
- Pointer to CPU Architectural Protocol interface\r
-\r
-Returns:\r
-\r
- Status\r
- EFI_SUCCESS\r
-\r
---*/\r
-// TODO: This - add argument and description to function comment\r
-// TODO: State - add argument and description to function comment\r
-// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-{\r
- CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
-\r
- if (State == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
- *State = Private->InterruptState;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtInit (\r
- IN EFI_CPU_ARCH_PROTOCOL *This,\r
- IN EFI_CPU_INIT_TYPE InitType\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine would support generation of a CPU INIT. At\r
- present, this code does not provide emulation.\r
-\r
-Arguments:\r
-\r
- Pointer to CPU Architectural Protocol interface\r
- INIT Type\r
-\r
-Returns:\r
-\r
- Status\r
- EFI_UNSUPPORTED - not yet implemented\r
-\r
---*/\r
-// TODO: This - add argument and description to function comment\r
-// TODO: InitType - add argument and description to function comment\r
-{\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtRegisterInterruptHandler (\r
- IN EFI_CPU_ARCH_PROTOCOL *This,\r
- IN EFI_EXCEPTION_TYPE InterruptType,\r
- IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine would support registration of an interrupt handler. At\r
- present, this code does not provide emulation.\r
-\r
-Arguments:\r
-\r
- Pointer to CPU Architectural Protocol interface\r
- Pointer to interrupt handlers\r
- Interrupt type\r
-\r
-Returns:\r
-\r
- Status\r
- EFI_UNSUPPORTED - not yet implemented\r
-\r
---*/\r
-// TODO: This - add argument and description to function comment\r
-// TODO: InterruptType - add argument and description to function comment\r
-// TODO: InterruptHandler - add argument and description to function comment\r
-{\r
-\r
- //\r
- // Do parameter checking for EFI spec conformance\r
- //\r
- if (InterruptType < 0 || InterruptType > 0xff) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- //\r
- // Do nothing for Nt32 emulation\r
- //\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtGetTimerValue (\r
- IN EFI_CPU_ARCH_PROTOCOL *This,\r
- IN UINT32 TimerIndex,\r
- OUT UINT64 *TimerValue,\r
- OUT UINT64 *TimerPeriod OPTIONAL\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine would support querying of an on-CPU timer. At present,\r
- this code does not provide timer emulation.\r
-\r
-Arguments:\r
-\r
- This - Pointer to CPU Architectural Protocol interface\r
- TimerIndex - Index of given CPU timer\r
- TimerValue - Output of the timer\r
- TimerPeriod - Output of the timer period\r
-\r
-Returns:\r
-\r
- EFI_UNSUPPORTED - not yet implemented\r
- EFI_INVALID_PARAMETER - TimeValue is NULL\r
-\r
---*/\r
-{\r
- if (TimerValue == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- if (TimerIndex != 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
- \r
- gWinNt->QueryPerformanceCounter ((LARGE_INTEGER *)TimerValue);\r
- \r
- if (TimerPeriod != NULL) {\r
- *TimerPeriod = mTimerPeriod;\r
- }\r
- \r
- return EFI_SUCCESS;\r
-}\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-WinNtSetMemoryAttributes (\r
- IN EFI_CPU_ARCH_PROTOCOL *This,\r
- IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
- IN UINT64 Length,\r
- IN UINT64 Attributes\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine would support querying of an on-CPU timer. At present,\r
- this code does not provide timer emulation.\r
-\r
-Arguments:\r
-\r
- Pointer to CPU Architectural Protocol interface\r
- Start address of memory region\r
- The size in bytes of the memory region\r
- The bit mask of attributes to set for the memory region\r
-\r
-Returns:\r
-\r
- Status\r
- EFI_UNSUPPORTED - not yet implemented\r
-\r
---*/\r
-// TODO: This - add argument and description to function comment\r
-// TODO: BaseAddress - add argument and description to function comment\r
-// TODO: Length - add argument and description to function comment\r
-// TODO: Attributes - add argument and description to function comment\r
-// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
-{\r
- //\r
- // Check for invalid parameter for Spec conformance\r
- //\r
- if (Length == 0) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // Do nothing for Nt32 emulation\r
- //\r
- return EFI_UNSUPPORTED;\r
-}\r
-\r
-\r
-\r
-/**\r
- Logs SMBIOS record.\r
-\r
- @param Smbios Pointer to SMBIOS protocol instance.\r
- @param Buffer Pointer to the data buffer.\r
-\r
-**/\r
-VOID\r
-LogSmbiosData (\r
- IN EFI_SMBIOS_PROTOCOL *Smbios,\r
- IN UINT8 *Buffer\r
- )\r
-{\r
- EFI_STATUS Status;\r
- EFI_SMBIOS_HANDLE SmbiosHandle;\r
- \r
- SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
- Status = Smbios->Add (\r
- Smbios,\r
- NULL,\r
- &SmbiosHandle,\r
- (EFI_SMBIOS_TABLE_HEADER*)Buffer\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-}\r
-\r
-\r
-VOID\r
-CpuUpdateSmbios (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This function will log processor version and frequency data to Smbios.\r
-\r
-Arguments:\r
- Event - Event whose notification function is being invoked.\r
- Context - Pointer to the notification function's context.\r
-\r
-Returns:\r
- None.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT32 TotalSize;\r
- EFI_SMBIOS_PROTOCOL *Smbios;\r
- EFI_HII_HANDLE HiiHandle;\r
- STRING_REF Token;\r
- UINTN CpuVerStrLen;\r
- EFI_STRING CpuVerStr;\r
- SMBIOS_TABLE_TYPE4 *SmbiosRecord;\r
- CHAR8 *OptionalStrStart;\r
-\r
- //\r
- // Locate Smbios protocol.\r
- //\r
- Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);\r
- \r
- if (EFI_ERROR (Status)) {\r
- return;\r
- }\r
-\r
- //\r
- // Initialize strings to HII database\r
- //\r
- HiiHandle = HiiAddPackages (\r
- &gEfiCallerIdGuid,\r
- NULL,\r
- CpuStrings,\r
- NULL\r
- );\r
- ASSERT (HiiHandle != NULL);\r
-\r
- Token = STRING_TOKEN (STR_PROCESSOR_VERSION);\r
- CpuVerStr = HiiGetPackageString(&gEfiCallerIdGuid, Token, NULL);\r
- CpuVerStrLen = StrLen(CpuVerStr);\r
- ASSERT (CpuVerStrLen <= SMBIOS_STRING_MAX_LENGTH);\r
-\r
-\r
- TotalSize = (UINT32)(sizeof(SMBIOS_TABLE_TYPE4) + CpuVerStrLen + 1 + 1);\r
- SmbiosRecord = AllocatePool(TotalSize);\r
- ZeroMem(SmbiosRecord, TotalSize);\r
-\r
- SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;\r
- SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);\r
- //\r
- // Make handle chosen by smbios protocol.add automatically.\r
- //\r
- SmbiosRecord->Hdr.Handle = 0; \r
- //\r
- // Processor version is the 1st string.\r
- //\r
- SmbiosRecord->ProcessorVersion = 1;\r
- //\r
- // Store CPU frequency data record to data hub - It's an emulator so make up a value\r
- //\r
- SmbiosRecord->CurrentSpeed = 1234;\r
-\r
- OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
- UnicodeStrToAsciiStr(CpuVerStr, OptionalStrStart);\r
-\r
- //\r
- // Now we have got the full smbios record, call smbios protocol to add this record.\r
- //\r
- LogSmbiosData(Smbios, (UINT8 *) SmbiosRecord);\r
- FreePool (SmbiosRecord);\r
-\r
-}\r
-\r
-\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeCpu (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Initialize the state information for the CPU Architectural Protocol\r
-\r
-Arguments:\r
-\r
- ImageHandle of the loaded driver\r
- Pointer to the System Table\r
-\r
-Returns:\r
-\r
- Status\r
-\r
- EFI_SUCCESS - protocol instance can be published\r
- EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure\r
- EFI_DEVICE_ERROR - cannot create the thread\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT64 Frequency;\r
-\r
- //\r
- // Retrieve the frequency of the performance counter in Hz.\r
- // \r
- gWinNt->QueryPerformanceFrequency ((LARGE_INTEGER *)&Frequency);\r
- \r
- //\r
- // Convert frequency in Hz to a clock period in femtoseconds.\r
- //\r
- mTimerPeriod = DivU64x64Remainder (1000000000000000, Frequency, NULL);\r
- \r
- CpuUpdateSmbios ();\r
-\r
- Status = gBS->InstallMultipleProtocolInterfaces (\r
- &mCpuTemplate.Handle,\r
- &gEfiCpuArchProtocolGuid, &mCpuTemplate.Cpu,\r
- &gEfiCpuIo2ProtocolGuid, &mCpuTemplate.CpuIo,\r
- NULL\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return Status;\r
-}\r