--- /dev/null
+/**@file\r
+ Common header file shared by all source files.\r
+\r
+ This file includes package header files, library classes and protocol, PPI & GUID definitions.\r
+\r
+ Copyright (c) 2006 - 2007, Intel Corporation\r
+ All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#ifndef __COMMON_HEADER_H_\r
+#define __COMMON_HEADER_H_\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiDxe.h>\r
+#include <WinNtDxe.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Common/DataHubRecords.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo.h>\r
+#include <Protocol/WinNtIo.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/FrameworkHiiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#endif\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\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 common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include "CpuDriver.h"\r
+\r
+#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpu (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ );\r
+\r
+VOID\r
+EFIAPI\r
+WinNtIoProtocolNotifyFunction (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ );\r
+\r
+typedef union {\r
+ EFI_CPU_DATA_RECORD *DataRecord;\r
+ UINT8 *Raw;\r
+} EFI_CPU_DATA_RECORD_BUFFER;\r
+\r
+EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader = {\r
+ EFI_PROCESSOR_SUBCLASS_VERSION, // Version\r
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER), // Header Size\r
+ 0, // Instance, Initialize later\r
+ EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance\r
+ 0 // RecordType, Initialize later\r
+};\r
+\r
+//\r
+// Service routines for the driver\r
+//\r
+STATIC\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
+STATIC\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
+STATIC\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
+STATIC\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
+STATIC\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
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\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
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;\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
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\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
+ //\r
+ // No timer supported\r
+ //\r
+ return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\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
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;\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
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+ return EFI_UNSUPPORTED;\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
+// TODO: SystemTable - add argument and description to function comment\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_EVENT Event;\r
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+ VOID *Registration;\r
+\r
+ Private = AllocatePool (sizeof (CPU_ARCH_PROTOCOL_PRIVATE));\r
+ ASSERT (Private != NULL);\r
+\r
+ Private->Signature = CPU_ARCH_PROT_PRIVATE_SIGNATURE;\r
+ Private->Cpu.FlushDataCache = WinNtFlushCpuDataCache;\r
+ Private->Cpu.EnableInterrupt = WinNtEnableInterrupt;\r
+ Private->Cpu.DisableInterrupt = WinNtDisableInterrupt;\r
+ Private->Cpu.GetInterruptState = WinNtGetInterruptState;\r
+ Private->Cpu.Init = WinNtInit;\r
+ Private->Cpu.RegisterInterruptHandler = WinNtRegisterInterruptHandler;\r
+ Private->Cpu.GetTimerValue = WinNtGetTimerValue;\r
+ Private->Cpu.SetMemoryAttributes = WinNtSetMemoryAttributes;\r
+\r
+ Private->Cpu.NumberOfTimers = 0;\r
+ Private->Cpu.DmaBufferAlignment = 4;\r
+\r
+ Private->InterruptState = TRUE;\r
+\r
+ Private->CpuIo.Mem.Read = CpuMemoryServiceRead;\r
+ Private->CpuIo.Mem.Write = CpuMemoryServiceWrite;\r
+ Private->CpuIo.Io.Read = CpuIoServiceRead;\r
+ Private->CpuIo.Io.Write = CpuIoServiceWrite;\r
+\r
+\r
+ Private->Handle = NULL;\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &Private->Handle,\r
+ &gEfiCpuArchProtocolGuid, &Private->Cpu,\r
+ &gEfiCpuIoProtocolGuid, &Private->CpuIo,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ //\r
+ // Install notify function to store processor data to HII database and data hub.\r
+ //\r
+ Status = gBS->CreateEvent (\r
+ EVT_NOTIFY_SIGNAL,\r
+ TPL_CALLBACK,\r
+ WinNtIoProtocolNotifyFunction,\r
+ ImageHandle,\r
+ &Event\r
+ );\r
+ ASSERT (!EFI_ERROR (Status));\r
+\r
+ Status = gBS->RegisterProtocolNotify (\r
+ &gEfiWinNtIoProtocolGuid,\r
+ Event,\r
+ &Registration\r
+ );\r
+ ASSERT (!EFI_ERROR (Status));\r
+\r
+ //\r
+ // Should be at EFI_D_INFO, but lets us now things are running\r
+ //\r
+ DEBUG ((EFI_D_ERROR, "CPU Architectural Protocol Loaded\n"));\r
+\r
+\r
+\r
+ return Status;\r
+}\r
+\r
+UINTN\r
+Atoi (\r
+ CHAR16 *String\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Convert a unicode string to a UINTN\r
+\r
+Arguments:\r
+ String - Unicode string.\r
+\r
+Returns:\r
+ UINTN of the number represented by String.\r
+\r
+--*/\r
+{\r
+ UINTN Number;\r
+ CHAR16 *Str;\r
+\r
+ //\r
+ // skip preceeding white space\r
+ //\r
+ Str = String;\r
+ while ((*Str) && (*Str == ' ' || *Str == '"')) {\r
+ Str++;\r
+ }\r
+ //\r
+ // Convert ot a Number\r
+ //\r
+ Number = 0;\r
+ while (*Str != '\0') {\r
+ if ((*Str >= '0') && (*Str <= '9')) {\r
+ Number = (Number * 10) +*Str - '0';\r
+ } else {\r
+ break;\r
+ }\r
+\r
+ Str++;\r
+ }\r
+\r
+ return Number;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+WinNtIoProtocolNotifyFunction (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ This function will log processor version and frequency data to data hub.\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
+ EFI_CPU_DATA_RECORD_BUFFER RecordBuffer;\r
+ EFI_DATA_RECORD_HEADER *Record;\r
+ EFI_SUBCLASS_TYPE1_HEADER *DataHeader;\r
+ UINT32 HeaderSize;\r
+ UINT32 TotalSize;\r
+ UINTN HandleCount;\r
+ UINTN HandleIndex;\r
+ UINT64 MonotonicCount;\r
+ BOOLEAN RecordFound;\r
+ EFI_HANDLE *HandleBuffer;\r
+ EFI_WIN_NT_IO_PROTOCOL *WinNtIo;\r
+ EFI_DATA_HUB_PROTOCOL *DataHub;\r
+ EFI_HII_PROTOCOL *Hii;\r
+ EFI_HII_HANDLE StringHandle;\r
+ EFI_HII_PACKAGES *PackageList;\r
+ STRING_REF Token;\r
+\r
+ DataHub = NULL;\r
+ Token = 0;\r
+ MonotonicCount = 0;\r
+ RecordFound = FALSE;\r
+\r
+ //\r
+ // Retrieve the list of all handles from the handle database\r
+ //\r
+ Status = gBS->LocateHandleBuffer (\r
+ AllHandles,\r
+ &gEfiWinNtIoProtocolGuid,\r
+ NULL,\r
+ &HandleCount,\r
+ &HandleBuffer\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ return ;\r
+ }\r
+ //\r
+ // Locate HII protocol\r
+ //\r
+ Status = gBS->LocateProtocol (&gEfiHiiProtocolGuid, NULL, &Hii);\r
+ if (EFI_ERROR (Status)) {\r
+ return ;\r
+ }\r
+ //\r
+ // Locate DataHub protocol.\r
+ //\r
+ Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &DataHub);\r
+ if (EFI_ERROR (Status)) {\r
+ return ;\r
+ }\r
+ //\r
+ // Initialize data record header\r
+ //\r
+ mCpuDataRecordHeader.Instance = 1;\r
+ HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
+\r
+ RecordBuffer.Raw = AllocatePool (HeaderSize + EFI_CPU_DATA_MAXIMUM_LENGTH);\r
+ if (RecordBuffer.Raw == NULL) {\r
+ return ;\r
+ }\r
+\r
+ CopyMem (RecordBuffer.Raw, &mCpuDataRecordHeader, HeaderSize);\r
+\r
+ //\r
+ // Search the Handle array to find the CPU model and speed information\r
+ //\r
+ for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {\r
+ Status = gBS->OpenProtocol (\r
+ HandleBuffer[HandleIndex],\r
+ &gEfiWinNtIoProtocolGuid,\r
+ &WinNtIo,\r
+ Context,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ continue;\r
+ }\r
+\r
+ if ((WinNtIo->WinNtThunk->Signature == EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) &&\r
+ CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtCPUModelGuid)\r
+ ) {\r
+ //\r
+ // Check if this record has been stored in data hub\r
+ //\r
+ do {\r
+ Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);\r
+ if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {\r
+ DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *) (Record + 1);\r
+ if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&\r
+ (DataHeader->RecordType == ProcessorVersionRecordType)\r
+ ) {\r
+ RecordFound = TRUE;\r
+ }\r
+ }\r
+ } while (MonotonicCount != 0);\r
+\r
+ if (RecordFound) {\r
+ RecordFound = FALSE;\r
+ continue;\r
+ }\r
+ //\r
+ // Initialize strings to HII database\r
+ //\r
+ PackageList = PreparePackages (1, &gEfiProcessorProducerGuid, CpuStrings);\r
+\r
+ Status = Hii->NewPack (Hii, PackageList, &StringHandle);\r
+ ASSERT (!EFI_ERROR (Status));\r
+\r
+ FreePool (PackageList);\r
+\r
+ //\r
+ // Store processor version data record to data hub\r
+ //\r
+ Status = Hii->NewString (Hii, NULL, StringHandle, &Token, WinNtIo->EnvString);\r
+ ASSERT (!EFI_ERROR (Status));\r
+\r
+ RecordBuffer.DataRecord->DataRecordHeader.RecordType = ProcessorVersionRecordType;\r
+ RecordBuffer.DataRecord->VariableRecord.ProcessorVersion = Token;\r
+ TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_VERSION_DATA);\r
+\r
+ Status = DataHub->LogData (\r
+ DataHub,\r
+ &gEfiProcessorSubClassGuid,\r
+ &gEfiProcessorProducerGuid,\r
+ EFI_DATA_RECORD_CLASS_DATA,\r
+ RecordBuffer.Raw,\r
+ TotalSize\r
+ );\r
+ }\r
+\r
+ if ((WinNtIo->WinNtThunk->Signature == EFI_WIN_NT_THUNK_PROTOCOL_SIGNATURE) &&\r
+ CompareGuid (WinNtIo->TypeGuid, &gEfiWinNtCPUSpeedGuid)\r
+ ) {\r
+ //\r
+ // Check if this record has been stored in data hub\r
+ //\r
+ do {\r
+ Status = DataHub->GetNextRecord (DataHub, &MonotonicCount, NULL, &Record);\r
+ if (Record->DataRecordClass == EFI_DATA_RECORD_CLASS_DATA) {\r
+ DataHeader = (EFI_SUBCLASS_TYPE1_HEADER *) (Record + 1);\r
+ if (CompareGuid (&Record->DataRecordGuid, &gEfiProcessorSubClassGuid) &&\r
+ (DataHeader->RecordType == ProcessorCoreFrequencyRecordType)\r
+ ) {\r
+ RecordFound = TRUE;\r
+ }\r
+ }\r
+ } while (MonotonicCount != 0);\r
+\r
+ if (RecordFound) {\r
+ RecordFound = FALSE;\r
+ continue;\r
+ }\r
+ //\r
+ // Store CPU frequency data record to data hub\r
+ //\r
+ RecordBuffer.DataRecord->DataRecordHeader.RecordType = ProcessorCoreFrequencyRecordType;\r
+ RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Value = (UINT16) Atoi (WinNtIo->EnvString);\r
+ RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Exponent = 6;\r
+ TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA);\r
+\r
+ Status = DataHub->LogData (\r
+ DataHub,\r
+ &gEfiProcessorSubClassGuid,\r
+ &gEfiProcessorProducerGuid,\r
+ EFI_DATA_RECORD_CLASS_DATA,\r
+ RecordBuffer.Raw,\r
+ TotalSize\r
+ );\r
+\r
+ FreePool (RecordBuffer.Raw);\r
+ }\r
+\r
+ gBS->CloseProtocol (\r
+ HandleBuffer[HandleIndex],\r
+ &gEfiWinNtIoProtocolGuid,\r
+ Context,\r
+ NULL\r
+ );\r
+ }\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+\r
+ Cpu.dxs\r
+\r
+Abstract:\r
+\r
+ Dependency expression source file.\r
+ \r
+--*/ \r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include <DxeDepex.h>\r
+\r
+DEPENDENCY_START\r
+ EFI_DATA_HUB_PROTOCOL_GUID AND\r
+ EFI_HII_PROTOCOL_GUID\r
+DEPENDENCY_END\r
--- /dev/null
+#/** @file\r
+# Component description file for Cpu module.\r
+#\r
+# This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = Cpu\r
+ FILE_GUID = ee993080-5197-4d4e-b63c-f1f7413e33ce\r
+ MODULE_TYPE = DXE_DRIVER\r
+ VERSION_STRING = 1.0\r
+ EDK_RELEASE_VERSION = 0x00020000\r
+ EFI_SPECIFICATION_VERSION = 0x00020000\r
+\r
+ ENTRY_POINT = InitializeCpu\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32\r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+ Cpu.dxs\r
+ CpuIo.c\r
+ Cpu.c\r
+ CpuDriver.h\r
+ Strings.uni\r
+ CommonHeader.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+# this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+ UefiBootServicesTableLib\r
+ MemoryAllocationLib\r
+ BaseMemoryLib\r
+ UefiDriverEntryPoint\r
+ FrameworkHiiLib\r
+ DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Guid C Name Section - list of Guids that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Guids]\r
+ gEfiWinNtCPUSpeedGuid # SOMETIMES_CONSUMED\r
+ gEfiWinNtCPUModelGuid # SOMETIMES_CONSUMED\r
+ gEfiProcessorSubClassGuid # SOMETIMES_CONSUMED\r
+ gEfiProcessorProducerGuid # SOMETIMES_CONSUMED\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+# that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+ gEfiWinNtIoProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
+ gEfiDataHubProtocolGuid # PROTOCOL SOMETIMES_CONSUMED\r
+ gEfiHiiProtocolGuid # PROTOCOL SOMETIMES_CONSUMED\r
+ gEfiWinNtIoProtocolGuid # PROTOCOL ALWAYS_CONSUMED\r
+ gEfiCpuIoProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
+ gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED\r
+\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+ <MsaHeader>\r
+ <ModuleName>Cpu</ModuleName>\r
+ <ModuleType>DXE_DRIVER</ModuleType>\r
+ <GuidValue>ee993080-5197-4d4e-b63c-f1f7413e33ce</GuidValue>\r
+ <Version>1.0</Version>\r
+ <Abstract>Component description file for Cpu module.</Abstract>\r
+ <Description>This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.</Description>\r
+ <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+ <License>All rights reserved. This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
+ </MsaHeader>\r
+ <ModuleDefinitions>\r
+ <SupportedArchitectures>IA32</SupportedArchitectures>\r
+ <BinaryModule>false</BinaryModule>\r
+ <OutputFileBasename>Cpu</OutputFileBasename>\r
+ </ModuleDefinitions>\r
+ <LibraryClassDefinitions>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>DebugLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>HiiLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>UefiDriverEntryPoint</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>BaseMemoryLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>MemoryAllocationLib</Keyword>\r
+ </LibraryClass>\r
+ <LibraryClass Usage="ALWAYS_CONSUMED">\r
+ <Keyword>UefiBootServicesTableLib</Keyword>\r
+ </LibraryClass>\r
+ </LibraryClassDefinitions>\r
+ <SourceFiles>\r
+ <Filename>Strings.uni</Filename>\r
+ <Filename>CpuDriver.h</Filename>\r
+ <Filename>Cpu.c</Filename>\r
+ <Filename>CpuIo.c</Filename>\r
+ <Filename>Cpu.dxs</Filename>\r
+ </SourceFiles>\r
+ <PackageDependencies>\r
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+ <Package PackageGuid="0fb2aa2d-10d5-40a5-a9dc-060c12a4a3f3"/>\r
+ </PackageDependencies>\r
+ <Protocols>\r
+ <Protocol Usage="ALWAYS_PRODUCED">\r
+ <ProtocolCName>gEfiCpuArchProtocolGuid</ProtocolCName>\r
+ </Protocol>\r
+ <Protocol Usage="ALWAYS_PRODUCED">\r
+ <ProtocolCName>gEfiCpuIoProtocolGuid</ProtocolCName>\r
+ </Protocol>\r
+ <Protocol Usage="ALWAYS_CONSUMED">\r
+ <ProtocolCName>gEfiWinNtIoProtocolGuid</ProtocolCName>\r
+ </Protocol>\r
+ <Protocol Usage="SOMETIMES_CONSUMED">\r
+ <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+ </Protocol>\r
+ <Protocol Usage="SOMETIMES_CONSUMED">\r
+ <ProtocolCName>gEfiDataHubProtocolGuid</ProtocolCName>\r
+ </Protocol>\r
+ <ProtocolNotify Usage="SOMETIMES_CONSUMED">\r
+ <ProtocolNotifyCName>gEfiWinNtIoProtocolGuid</ProtocolNotifyCName>\r
+ </ProtocolNotify>\r
+ </Protocols>\r
+ <DataHubs>\r
+ <DataHubRecord Usage="SOMETIMES_PRODUCED">\r
+ <DataHubCName>ProcessorVersion</DataHubCName>\r
+ </DataHubRecord>\r
+ <DataHubRecord Usage="SOMETIMES_PRODUCED">\r
+ <DataHubCName>ProcessorCoreFrequency</DataHubCName>\r
+ </DataHubRecord>\r
+ </DataHubs>\r
+ <Guids>\r
+ <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+ <GuidCName>gEfiProcessorProducerGuid</GuidCName>\r
+ </GuidCNames>\r
+ <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+ <GuidCName>gEfiProcessorSubClassGuid</GuidCName>\r
+ </GuidCNames>\r
+ <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+ <GuidCName>gEfiWinNtCPUModelGuid</GuidCName>\r
+ </GuidCNames>\r
+ <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+ <GuidCName>gEfiWinNtCPUSpeedGuid</GuidCName>\r
+ </GuidCNames>\r
+ </Guids>\r
+ <Externs>\r
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+ <Extern>\r
+ <ModuleEntryPoint>InitializeCpu</ModuleEntryPoint>\r
+ </Extern>\r
+ </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+\r
+ CpuDriver.h\r
+\r
+Abstract:\r
+\r
+ NT Emulation Architectural Protocol Driver as defined in Tiano.\r
+\r
+--*/\r
+\r
+#ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+\r
+\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+extern UINT8 CpuStrings[];\r
+\r
+//\r
+// Internal Data Structures\r
+//\r
+#define CPU_ARCH_PROT_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('c', 'a', 'p', 'd')\r
+\r
+typedef struct {\r
+ UINTN Signature;\r
+ EFI_HANDLE Handle;\r
+\r
+ EFI_CPU_ARCH_PROTOCOL Cpu;\r
+ EFI_CPU_IO_PROTOCOL CpuIo;\r
+\r
+ //\r
+ // Local Data for CPU interface goes here\r
+ //\r
+ CRITICAL_SECTION NtCriticalSection;\r
+ BOOLEAN InterruptState;\r
+\r
+} CPU_ARCH_PROTOCOL_PRIVATE;\r
+\r
+#define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \\r
+ CR (a, \\r
+ CPU_ARCH_PROTOCOL_PRIVATE, \\r
+ Cpu, \\r
+ CPU_ARCH_PROT_PRIVATE_SIGNATURE \\r
+ )\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN OUT VOID *Buffer\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN OUT VOID *Buffer\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ IN OUT VOID *UserBuffer\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ IN OUT VOID *UserBuffer\r
+ );\r
+\r
+\r
+#endif\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+\r
+ CpuIo.c\r
+\r
+Abstract:\r
+\r
+ This is the code that publishes the CPU I/O Protocol.\r
+ The intent herein is to have a single I/O service that can load\r
+ as early as possible, extend into runtime, and be layered upon by \r
+ the implementations of architectural protocols and the PCI Root\r
+ Bridge I/O Protocol.\r
+\r
+--*/\r
+\r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
+#include <CpuDriver.h>\r
+\r
+#define IA32_MAX_IO_ADDRESS 0xFFFF\r
+#define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF\r
+\r
+EFI_CPU_IO_PROTOCOL mCpuIoProtocol;\r
+\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN VOID *Buffer,\r
+ IN UINT64 Limit\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN OUT VOID *Buffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+ Pointer to an instance of the CPU I/O Protocol\r
+ Width of the Memory Access\r
+ Address of the Memory access\r
+ Count of the number of accesses to perform\r
+ Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+ Status\r
+\r
+ EFI_SUCCESS - The data was read from or written to the EFI \r
+ System.\r
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
+ EFI_INVALID_PARAMETER - Buffer is NULL.\r
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
+ EFI_UNSUPPORTED - The address range specified by Address, Width, \r
+ and Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (!Buffer) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Do nothing for Nt32 version\r
+ //\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN OUT VOID *Buffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+ Pointer to an instance of the CPU I/O Protocol\r
+ Width of the Memory Access\r
+ Address of the Memory access\r
+ Count of the number of accesses to perform\r
+ Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+ Status\r
+\r
+ EFI_SUCCESS - The data was read from or written to the EFI System.\r
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
+ EFI_INVALID_PARAMETER - Buffer is NULL.\r
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
+ EFI_UNSUPPORTED - The address range specified by Address, Width, and \r
+ Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (!Buffer) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Do nothing for Nt32 version\r
+ //\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ IN OUT VOID *UserBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ This is the service that implements the I/O read\r
+\r
+Arguments:\r
+\r
+ Pointer to an instance of the CPU I/O Protocol\r
+ Width of the Memory Access\r
+ Address of the I/O access\r
+ Count of the number of accesses to perform\r
+ Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+ Status\r
+ EFI_SUCCESS - The data was read from or written to the EFI System.\r
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
+ EFI_INVALID_PARAMETER - Buffer is NULL.\r
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
+ EFI_UNSUPPORTED - The address range specified by Address, Width, and \r
+ Count is not valid for this EFI System.\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: UserAddress - add argument and description to function comment\r
+// TODO: UserBuffer - add argument and description to function comment\r
+{\r
+ UINTN Address;\r
+ EFI_STATUS Status;\r
+\r
+ if (!UserBuffer) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Address = (UINTN) UserAddress;\r
+\r
+ if (Width >= EfiCpuIoWidthMaximum) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Do nothing for Nt32 version\r
+ //\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+ IN EFI_CPU_IO_PROTOCOL *This,\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 UserAddress,\r
+ IN UINTN Count,\r
+ IN OUT VOID *UserBuffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ \r
+ This is the service that implements the I/O Write\r
+\r
+Arguments:\r
+\r
+ Pointer to an instance of the CPU I/O Protocol\r
+ Width of the Memory Access\r
+ Address of the I/O access\r
+ Count of the number of accesses to perform\r
+ Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+ Status\r
+\r
+ Status\r
+ EFI_SUCCESS - The data was read from or written to the EFI System.\r
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.\r
+ EFI_INVALID_PARAMETER - Buffer is NULL.\r
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.\r
+ EFI_UNSUPPORTED - The address range specified by Address, Width, and \r
+ Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO: This - add argument and description to function comment\r
+// TODO: UserAddress - add argument and description to function comment\r
+// TODO: UserBuffer - add argument and description to function comment\r
+{\r
+ UINTN Address;\r
+ EFI_STATUS Status;\r
+\r
+ if (!UserBuffer) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Address = (UINTN) UserAddress;\r
+\r
+ if (Width >= EfiCpuIoWidthMaximum) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Do nothing for Nt32 version\r
+ //\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,\r
+ IN UINT64 Address,\r
+ IN UINTN Count,\r
+ IN VOID *Buffer,\r
+ IN UINT64 Limit\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Width - TODO: add argument description\r
+ Address - TODO: add argument description\r
+ Count - TODO: add argument description\r
+ Buffer - TODO: add argument description\r
+ Limit - TODO: add argument description\r
+\r
+Returns:\r
+\r
+ EFI_UNSUPPORTED - TODO: Add description for return value\r
+ EFI_UNSUPPORTED - TODO: Add description for return value\r
+ EFI_UNSUPPORTED - TODO: Add description for return value\r
+ EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+ UINTN AlignMask;\r
+\r
+ if (Address > Limit) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // For FiFo type, the target address won't increase during the access, so treat count as 1\r
+ //\r
+ if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+ Count = 1;\r
+ }\r
+\r
+ Width = Width & 0x03;\r
+ if (Address - 1 + (1 << Width) * Count > Limit) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ AlignMask = (1 << Width) - 1;\r
+ if ((UINTN) Buffer & AlignMask) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+\r