--- /dev/null
+/*++\r
+\r
+Copyright (c) 2005 - 2008, 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
+ Fvb.c \r
+\r
+Abstract:\r
+\r
+ Firmware Volume Block Protocol Runtime Abstraction\r
+\r
+ mFvbEntry is an array of Handle Fvb pairs. The Fvb Lib Instance matches the \r
+ index in the mFvbEntry array. This should be the same sequence as the FVB's\r
+ were described in the HOB. We have to remember the handle so we can tell if \r
+ the protocol has been reinstalled and it needs updateing.\r
+\r
+ If you are using any of these lib functions.you must first call FvbInitialize ().\r
+\r
+Key:\r
+ FVB - Firmware Volume Block\r
+\r
+--*/\r
+\r
+#include "Tiano.h"\r
+#include "EfiRuntimeLib.h"\r
+#include EFI_PROTOCOL_DEFINITION (FirmwareVolumeBlock)\r
+#include EFI_PROTOCOL_DEFINITION (FvbExtension)\r
+\r
+//\r
+// Lib will ASSERT if more FVB devices than this are added to the system.\r
+//\r
+UINTN mFvbCount;\r
+VOID *mFvbRegistration;\r
+VOID *mFvbExtRegistration;\r
+//static EFI_EVENT mEfiFvbVirtualNotifyEvent;\r
+BOOLEAN gEfiFvbInitialized = FALSE;\r
+EFI_EVENT mFvbEvent;\r
+\r
+BOOLEAN\r
+IsMemoryRuntime (\r
+ IN VOID *Address\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Check whether an address is runtime memory or not.\r
+\r
+Arguments:\r
+\r
+ Address - The Address being checked.\r
+ \r
+Returns: \r
+ TRUE - The address is runtime memory.\r
+ FALSE - The address is not runtime memory.\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINT8 TmpMemoryMap[1];\r
+ UINTN MapKey;\r
+ UINTN DescriptorSize;\r
+ UINT32 DescriptorVersion;\r
+ UINTN MemoryMapSize;\r
+ EFI_MEMORY_DESCRIPTOR *MemoryMap;\r
+ EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;\r
+ BOOLEAN IsRuntime;\r
+ UINTN Index;\r
+\r
+ IsRuntime = FALSE;\r
+\r
+ //\r
+ // Get System MemoryMapSize\r
+ //\r
+ MemoryMapSize = 1;\r
+ Status = gBS->GetMemoryMap (\r
+ &MemoryMapSize,\r
+ (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap,\r
+ &MapKey,\r
+ &DescriptorSize,\r
+ &DescriptorVersion\r
+ );\r
+ ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
+ //\r
+ // Enlarge space here, because we will allocate pool now.\r
+ //\r
+ MemoryMapSize += EFI_PAGE_SIZE;\r
+ Status = gBS->AllocatePool (\r
+ EfiBootServicesData,\r
+ MemoryMapSize,\r
+ (VOID**)&MemoryMap\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ //\r
+ // Get System MemoryMap\r
+ //\r
+ Status = gBS->GetMemoryMap (\r
+ &MemoryMapSize,\r
+ MemoryMap,\r
+ &MapKey,\r
+ &DescriptorSize,\r
+ &DescriptorVersion\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ MemoryMapPtr = MemoryMap;\r
+ //\r
+ // Search the request Address\r
+ //\r
+ for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {\r
+ if (((EFI_PHYSICAL_ADDRESS)(UINTN)Address >= MemoryMap->PhysicalStart) &&\r
+ ((EFI_PHYSICAL_ADDRESS)(UINTN)Address < MemoryMap->PhysicalStart\r
+ + LShiftU64 (MemoryMap->NumberOfPages, EFI_PAGE_SHIFT))) {\r
+ //\r
+ // Found it\r
+ //\r
+ if (MemoryMap->Attribute & EFI_MEMORY_RUNTIME) {\r
+ IsRuntime = TRUE;\r
+ }\r
+ break;\r
+ }\r
+ //\r
+ // Get next item\r
+ //\r
+ MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize);\r
+ }\r
+\r
+ //\r
+ // Done\r
+ //\r
+ gBS->FreePool (MemoryMapPtr);\r
+\r
+ return IsRuntime;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+FvbNotificationFunction (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r
+ reinstalled.\r
+\r
+Arguments:\r
+\r
+ Event - The Event that is being processed\r
+ \r
+ Context - Event Context\r
+\r
+Returns: \r
+ None\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN BufferSize;\r
+ EFI_HANDLE Handle;\r
+ UINTN Index;\r
+ UINTN UpdateIndex;\r
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r
+ EFI_FVB_EXTENSION_PROTOCOL *FvbExtension;\r
+\r
+ while (TRUE) {\r
+ BufferSize = sizeof (Handle);\r
+ Status = gBS->LocateHandle (\r
+ ByRegisterNotify,\r
+ &gEfiFirmwareVolumeBlockProtocolGuid,\r
+ mFvbRegistration,\r
+ &BufferSize,\r
+ &Handle\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ //\r
+ // Exit Path of While Loop....\r
+ //\r
+ break;\r
+ }\r
+\r
+ UpdateIndex = MAX_FVB_COUNT;\r
+ for (Index = 0; Index < mFvbCount; Index++) {\r
+ if (mFvbEntry[Index].Handle == Handle) {\r
+ //\r
+ // If the handle is already in the table just update the protocol\r
+ //\r
+ UpdateIndex = Index;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (UpdateIndex == MAX_FVB_COUNT) {\r
+ //\r
+ // Use the next free slot for a new entry\r
+ //\r
+ UpdateIndex = mFvbCount;\r
+ }\r
+ //\r
+ // The array does not have enough entries\r
+ //\r
+ ASSERT (UpdateIndex < MAX_FVB_COUNT);\r
+\r
+ //\r
+ // Get the interface pointer and if it's ours, skip it.\r
+ // We check Runtime here, because it has no reason to register\r
+ // a boot time FVB protocol.\r
+ //\r
+ Status = gBS->HandleProtocol (Handle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **) &Fvb);\r
+ ASSERT_EFI_ERROR (Status);\r
+ if (IsMemoryRuntime (Fvb)) {\r
+ //\r
+ // Increase mFvbCount if we need to add a new entry\r
+ //\r
+ if (UpdateIndex == mFvbCount) {\r
+ mFvbCount++;\r
+ }\r
+ mFvbEntry[UpdateIndex].Handle = Handle;\r
+ mFvbEntry[UpdateIndex].Fvb = Fvb;\r
+ mFvbEntry[UpdateIndex].FvbExtension = NULL;\r
+\r
+ Status = gBS->HandleProtocol (Handle, &gEfiFvbExtensionProtocolGuid, (VOID **) &FvbExtension);\r
+ if ((Status == EFI_SUCCESS) && IsMemoryRuntime (FvbExtension)) {\r
+ mFvbEntry[UpdateIndex].FvbExtension = FvbExtension;\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbInitialize (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Initialize globals and register Fvb Protocol notification function.\r
+\r
+Arguments:\r
+ None \r
+\r
+Returns: \r
+ EFI_SUCCESS - Fvb is successfully initialized\r
+ others - Fail to initialize\r
+\r
+--*/\r
+{\r
+ UINTN Status;\r
+ mFvbCount = 0;\r
+\r
+ Status = gBS->AllocatePool (\r
+ EfiRuntimeServicesData,\r
+ (UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT,\r
+ (VOID *) &mFvbEntry\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ EfiZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r
+\r
+ mFvbEvent = RtEfiLibCreateProtocolNotifyEvent (\r
+ &gEfiFirmwareVolumeBlockProtocolGuid,\r
+ EFI_TPL_CALLBACK,\r
+ FvbNotificationFunction,\r
+ NULL,\r
+ &mFvbRegistration\r
+ );\r
+\r
+ //\r
+ // Register SetVirtualAddressMap () notify function\r
+ //\r
+ // Status = gBS->CreateEvent (\r
+ // EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
+ // EFI_TPL_NOTIFY,\r
+ // EfiRuntimeLibFvbVirtualNotifyEvent,\r
+ // NULL,\r
+ // &mEfiFvbVirtualNotifyEvent\r
+ // );\r
+ // ASSERT_EFI_ERROR (Status);\r
+ //\r
+ gEfiFvbInitialized = TRUE;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbShutdown (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Release resources allocated in EfiFvbInitialize.\r
+\r
+Arguments:\r
+ None \r
+\r
+Returns: \r
+ EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+ gBS->FreePool ((VOID *) mFvbEntry);\r
+\r
+ gBS->CloseEvent (mFvbEvent);\r
+\r
+ gEfiFvbInitialized = FALSE;\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// The following functions wrap Fvb protocol in the Runtime Lib functions.\r
+// The Instance translates into Fvb instance. The Fvb order defined by HOBs and\r
+// thus the sequence of FVB protocol addition define Instance.\r
+//\r
+// EfiFvbInitialize () must be called before any of the following functions\r
+// must be called.\r
+//\r
+\r
+EFI_STATUS\r
+EfiFvbReadBlock (\r
+ IN UINTN Instance,\r
+ IN EFI_LBA Lba,\r
+ IN UINTN Offset,\r
+ IN OUT UINTN *NumBytes,\r
+ IN UINT8 *Buffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Reads specified number of bytes into a buffer from the specified block\r
+\r
+Arguments:\r
+ Instance - The FV instance to be read from\r
+ Lba - The logical block address to be read from\r
+ Offset - Offset into the block at which to begin reading\r
+ NumBytes - Pointer that on input contains the total size of\r
+ the buffer. On output, it contains the total number\r
+ of bytes read\r
+ Buffer - Pointer to a caller allocated buffer that will be\r
+ used to hold the data read\r
+\r
+Returns: \r
+\r
+ Status code\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+\r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return mFvbEntry[Instance].Fvb->Read (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbWriteBlock (\r
+ IN UINTN Instance,\r
+ IN EFI_LBA Lba,\r
+ IN UINTN Offset,\r
+ IN OUT UINTN *NumBytes,\r
+ IN UINT8 *Buffer\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Writes specified number of bytes from the input buffer to the block\r
+\r
+Arguments:\r
+ Instance - The FV instance to be written to\r
+ Lba - The starting logical block index to write to\r
+ Offset - Offset into the block at which to begin writing\r
+ NumBytes - Pointer that on input contains the total size of\r
+ the buffer. On output, it contains the total number\r
+ of bytes actually written\r
+ Buffer - Pointer to a caller allocated buffer that contains\r
+ the source for the write\r
+\r
+Returns: \r
+\r
+ Status code\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+\r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbEraseBlock (\r
+ IN UINTN Instance,\r
+ IN EFI_LBA Lba\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Erases and initializes a firmware volume block\r
+\r
+Arguments:\r
+ Instance - The FV instance to be erased\r
+ Lba - The logical block index to be erased\r
+ \r
+Returns: \r
+\r
+ Status code\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+\r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, -1);\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbGetVolumeAttributes (\r
+ IN UINTN Instance,\r
+ OUT EFI_FVB_ATTRIBUTES *Attributes\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Retrieves attributes, insures positive polarity of attribute bits, returns\r
+ resulting attributes in output parameter\r
+\r
+Arguments:\r
+ Instance - The FV instance whose attributes is going to be \r
+ returned\r
+ Attributes - Output buffer which contains attributes\r
+\r
+Returns: \r
+ Status code\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+\r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return mFvbEntry[Instance].Fvb->GetVolumeAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbSetVolumeAttributes (\r
+ IN UINTN Instance,\r
+ IN EFI_FVB_ATTRIBUTES Attributes\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Modifies the current settings of the firmware volume according to the \r
+ input parameter.\r
+\r
+Arguments:\r
+ Instance - The FV instance whose attributes is going to be \r
+ modified\r
+ Attributes - It is a pointer to EFI_FVB_ATTRIBUTES \r
+ containing the desired firmware volume settings.\r
+\r
+Returns: \r
+ Status code\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+\r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return mFvbEntry[Instance].Fvb->SetVolumeAttributes (mFvbEntry[Instance].Fvb, &Attributes);\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbGetPhysicalAddress (\r
+ IN UINTN Instance,\r
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Retrieves the physical address of a memory mapped FV\r
+\r
+Arguments:\r
+ Instance - The FV instance whose base address is going to be\r
+ returned\r
+ BaseAddress - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS \r
+ that on successful return, contains the base address\r
+ of the firmware volume. \r
+\r
+Returns: \r
+\r
+ Status code\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+\r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbGetBlockSize (\r
+ IN UINTN Instance,\r
+ IN EFI_LBA Lba,\r
+ OUT UINTN *BlockSize,\r
+ OUT UINTN *NumOfBlocks\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Retrieve the size of a logical block\r
+\r
+Arguments:\r
+ Instance - The FV instance whose block size is going to be\r
+ returned\r
+ Lba - Indicates which block to return the size for.\r
+ BlockSize - A pointer to a caller allocated UINTN in which\r
+ the size of the block is returned\r
+ NumOfBlocks - a pointer to a caller allocated UINTN in which the\r
+ number of consecutive blocks starting with Lba is\r
+ returned. All blocks in this range have a size of\r
+ BlockSize\r
+\r
+Returns: \r
+ EFI_SUCCESS - The firmware volume was read successfully and \r
+ contents are in Buffer\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+\r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);\r
+}\r
+\r
+EFI_STATUS\r
+EfiFvbEraseCustomBlockRange (\r
+ IN UINTN Instance,\r
+ IN EFI_LBA StartLba,\r
+ IN UINTN OffsetStartLba,\r
+ IN EFI_LBA LastLba,\r
+ IN UINTN OffsetLastLba\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Erases and initializes a specified range of a firmware volume\r
+\r
+Arguments:\r
+ Instance - The FV instance to be erased\r
+ StartLba - The starting logical block index to be erased\r
+ OffsetStartLba - Offset into the starting block at which to \r
+ begin erasing\r
+ LastLba - The last logical block index to be erased\r
+ OffsetLastLba - Offset into the last block at which to end erasing\r
+\r
+Returns: \r
+\r
+ Status code\r
+ \r
+ EFI_INVALID_PARAMETER - invalid parameter\r
+ \r
+ EFI_UNSUPPORTED - not support\r
+ \r
+--*/\r
+{\r
+ if (Instance >= mFvbCount) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (!(mFvbEntry[Instance].FvbExtension)) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock (\r
+ mFvbEntry[Instance].FvbExtension,\r
+ StartLba,\r
+ OffsetStartLba,\r
+ LastLba,\r
+ OffsetLastLba\r
+ );\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2005, 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
+ IoLib.c\r
+\r
+Abstract:\r
+\r
+ Light weight lib to support Tiano drivers.\r
+\r
+--*/\r
+\r
+#include "Tiano.h"\r
+#include "EfiRuntimeLib.h"\r
+#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
+\r
+extern EFI_CPU_IO_PROTOCOL *gCpuIo;\r
+\r
+EFI_STATUS\r
+EfiIoRead (\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
+ Perform an IO read into Buffer.\r
+\r
+Arguments:\r
+ Width - Width of read transaction, and repeat operation to use\r
+ Address - IO address to read\r
+ Count - Number of times to read the IO address.\r
+ Buffer - Buffer to read data into. size is Width * Count\r
+\r
+Returns: \r
+ BugBug: Check with Mike to see if I can find this #define some ware else\r
+\r
+--*/\r
+{\r
+ return gCpuIo->Io.Read (gCpuIo, Width, Address, Count, Buffer);\r
+}\r
+\r
+EFI_STATUS\r
+EfiIoWrite (\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
+ Perform an IO write into Buffer.\r
+\r
+Arguments:\r
+ Width - Width of write transaction, and repeat operation to use\r
+ Address - IO address to write\r
+ Count - Number of times to write the IO address.\r
+ Buffer - Buffer to write data from. size is Width * Count\r
+\r
+Returns: \r
+ BugBug: Check with Mike to see if I can find this #define some ware else\r
+\r
+--*/\r
+{\r
+ return gCpuIo->Io.Write (gCpuIo, Width, Address, Count, Buffer);\r
+}\r
+\r
+EFI_STATUS\r
+EfiMemRead (\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
+ Perform a Memory mapped IO read into Buffer.\r
+\r
+Arguments:\r
+ Width - Width of each read transaction.\r
+ Address - Memory mapped IO address to read\r
+ Count - Number of Width quanta to read\r
+ Buffer - Buffer to read data into. size is Width * Count\r
+\r
+Returns: \r
+ BugBug: Check with Mike to see if I can find this #define some ware else\r
+\r
+--*/\r
+{\r
+ return gCpuIo->Mem.Read (gCpuIo, Width, Address, Count, Buffer);\r
+}\r
+\r
+EFI_STATUS\r
+EfiMemWrite (\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
+ Perform a memory mapped IO write into Buffer.\r
+\r
+Arguments:\r
+ Width - Width of write transaction, and repeat operation to use\r
+ Address - IO address to write\r
+ Count - Number of times to write the IO address.\r
+ Buffer - Buffer to write data from. size is Width * Count\r
+\r
+Returns: \r
+ BugBug: Check with Mike to see if I can find this #define some ware else\r
+\r
+--*/\r
+{\r
+ return gCpuIo->Mem.Write (gCpuIo, Width, Address, Count, Buffer);\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2005, 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
+ Lock.c\r
+\r
+Abstract:\r
+\r
+ Support for locking lib services.\r
+\r
+--*/\r
+\r
+#include "Tiano.h"\r
+#include "EfiDriverLib.h"\r
+\r
+extern\r
+BOOLEAN\r
+EfiAtRuntime (\r
+ VOID\r
+ );\r
+\r
+VOID\r
+EfiInitializeLock (\r
+ IN OUT EFI_LOCK *Lock,\r
+ IN EFI_TPL Priority\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Initialize a basic mutual exclusion lock. Each lock\r
+ provides mutual exclusion access at it's task priority\r
+ level. Since there is no-premption (at any TPL) or\r
+ multiprocessor support, acquiring the lock only consists\r
+ of raising to the locks TPL.\r
+\r
+ Note on a check build ASSERT()s are used to ensure proper\r
+ lock usage.\r
+ \r
+Arguments:\r
+\r
+ Lock - The EFI_LOCK structure to initialize\r
+\r
+ Priority - The task priority level of the lock\r
+\r
+ \r
+Returns:\r
+\r
+ An initialized Efi Lock structure.\r
+\r
+--*/\r
+{\r
+ Lock->Tpl = Priority;\r
+ Lock->OwnerTpl = 0;\r
+ Lock->Lock = 0;\r
+}\r
+\r
+EFI_STATUS\r
+EfiAcquireLockOrFail (\r
+ IN EFI_LOCK *Lock\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Initialize a basic mutual exclusion lock. Each lock\r
+ provides mutual exclusion access at it's task priority\r
+ level. Since there is no-premption (at any TPL) or\r
+ multiprocessor support, acquiring the lock only consists\r
+ of raising to the locks TPL.\r
+ \r
+Arguments:\r
+\r
+ Lock - The EFI_LOCK structure to initialize\r
+ \r
+Returns:\r
+\r
+ EFI_SUCCESS - Lock Owned.\r
+ EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.\r
+\r
+--*/\r
+{\r
+ if (Lock->Lock != 0) {\r
+ //\r
+ // Lock is already owned, so bail out\r
+ //\r
+ return EFI_ACCESS_DENIED;\r
+ }\r
+\r
+ if (!EfiAtRuntime ()) {\r
+ //\r
+ // The check is just debug code for core inplementation. It must\r
+ // always be true in a driver\r
+ //\r
+ Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r
+ }\r
+\r
+ Lock->Lock += 1;\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+VOID\r
+EfiAcquireLock (\r
+ IN EFI_LOCK *Lock\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Raising to the task priority level of the mutual exclusion\r
+ lock, and then acquires ownership of the lock.\r
+ \r
+Arguments:\r
+\r
+ Lock - The lock to acquire\r
+ \r
+Returns:\r
+\r
+ Lock owned\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = EfiAcquireLockOrFail (Lock);\r
+\r
+ //\r
+ // Lock was already locked.\r
+ //\r
+ ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+VOID\r
+EfiReleaseLock (\r
+ IN EFI_LOCK *Lock\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Releases ownership of the mutual exclusion lock, and\r
+ restores the previous task priority level.\r
+ \r
+Arguments:\r
+\r
+ Lock - The lock to release\r
+ \r
+Returns:\r
+\r
+ Lock unowned\r
+\r
+--*/\r
+{\r
+ EFI_TPL Tpl;\r
+\r
+ Tpl = Lock->OwnerTpl;\r
+\r
+ ASSERT (Lock->Lock == 1);\r
+ Lock->Lock -= 1;\r
+\r
+ if (!EfiAtRuntime ()) {\r
+ //\r
+ // The check is just debug code for core inplementation. It must\r
+ // always be true in a driver\r
+ //\r
+ gBS->RestoreTPL (Tpl);\r
+ }\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2005 - 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
+ PlatformIoLib.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "Tiano.h"\r
+#include "EfiRuntimeLib.h"\r
+#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
+\r
+#define PCI_CONFIG_INDEX_PORT 0xcf8\r
+#define PCI_CONFIG_DATA_PORT 0xcfc\r
+#define REFRESH_CYCLE_TOGGLE_BIT 0x10\r
+\r
+UINT32\r
+GetPciAddress (\r
+ UINT8 Segment,\r
+ UINT8 Bus,\r
+ UINT8 DevFunc,\r
+ UINT8 Register\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Constructs PCI Address 32 bits\r
+ \r
+Arguments:\r
+ Segment - PCI Segment ACPI _SEG\r
+ Bus - PCI Bus\r
+ DevFunc - PCI Device(7:3) and Func(2:0)\r
+ Register - PCI config space register\r
+\r
+Returns:\r
+ PciAddress to be written to Config Port\r
+\r
+--*/\r
+{\r
+ UINT32 Data;\r
+\r
+ Data = 0;\r
+\r
+ Data = (((UINT32) Segment) << 24);\r
+ Data |= (((UINT32) Bus) << 16);\r
+ Data |= (((UINT32) DevFunc) << 8);\r
+ Data |= (UINT32) Register;\r
+\r
+ return Data;\r
+\r
+}\r
+\r
+UINT8\r
+PciRead8 (\r
+ UINT8 Segment,\r
+ UINT8 Bus,\r
+ UINT8 DevFunc,\r
+ UINT8 Register\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform an one byte PCI config cycle read\r
+ \r
+Arguments:\r
+ Segment - PCI Segment ACPI _SEG\r
+ Bus - PCI Bus\r
+ DevFunc - PCI Device(7:3) and Func(2:0)\r
+ Register - PCI config space register\r
+\r
+Returns:\r
+ Data read from PCI config space\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 PciAddress;\r
+ UINT32 PciAddress1;\r
+ UINT8 Data;\r
+\r
+ PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
+ //\r
+ // Set bit 31 for PCI config access\r
+ //\r
+ PciAddress1 = PciAddress;\r
+ PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
+\r
+ Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return 0;\r
+ }\r
+\r
+ EfiIoRead (EfiCpuIoWidthUint8, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
+\r
+ return Data;\r
+}\r
+\r
+UINT16\r
+PciRead16 (\r
+ UINT8 Segment,\r
+ UINT8 Bus,\r
+ UINT8 DevFunc,\r
+ UINT8 Register\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform an two byte PCI config cycle read\r
+ \r
+Arguments:\r
+ Segment - PCI Segment ACPI _SEG\r
+ Bus - PCI Bus\r
+ DevFunc - PCI Device(7:3) and Func(2:0)\r
+ Register - PCI config space register\r
+\r
+Returns:\r
+ Data read from PCI config space\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 PciAddress;\r
+ UINT32 PciAddress1;\r
+ UINT16 Data;\r
+\r
+ PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
+ //\r
+ // Set bit 31 for PCI config access\r
+ //\r
+ PciAddress1 = PciAddress;\r
+ PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
+\r
+ Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return 0;\r
+ }\r
+\r
+ EfiIoRead (EfiCpuIoWidthUint16, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
+\r
+ return Data;\r
+}\r
+\r
+UINT32\r
+PciRead32 (\r
+ UINT8 Segment,\r
+ UINT8 Bus,\r
+ UINT8 DevFunc,\r
+ UINT8 Register\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform an four byte PCI config cycle read\r
+ \r
+Arguments:\r
+ Segment - PCI Segment ACPI _SEG\r
+ Bus - PCI Bus\r
+ DevFunc - PCI Device(7:3) and Func(2:0)\r
+ Register - PCI config space register\r
+\r
+Returns:\r
+ Data read from PCI config space\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 PciAddress;\r
+ UINT32 PciAddress1;\r
+ UINT32 Data;\r
+\r
+ PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
+ //\r
+ // Set bit 31 for PCI config access\r
+ //\r
+ PciAddress1 = PciAddress;\r
+ PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
+\r
+ Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return 0;\r
+ }\r
+\r
+ EfiIoRead (EfiCpuIoWidthUint32, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
+\r
+ return Data;\r
+}\r
+\r
+VOID\r
+PciWrite8 (\r
+ UINT8 Segment,\r
+ UINT8 Bus,\r
+ UINT8 DevFunc,\r
+ UINT8 Register,\r
+ UINT8 Data\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform an one byte PCI config cycle write\r
+ \r
+Arguments:\r
+ Segment - PCI Segment ACPI _SEG\r
+ Bus - PCI Bus\r
+ DevFunc - PCI Device(7:3) and Func(2:0)\r
+ Register - PCI config space register\r
+ Data - Data to write\r
+\r
+Returns:\r
+ NONE\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 PciAddress;\r
+ UINT32 PciAddress1;\r
+\r
+ PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
+ //\r
+ // Set bit 31 for PCI config access\r
+ //\r
+ PciAddress1 = PciAddress;\r
+ PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
+\r
+ Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return ;\r
+ }\r
+\r
+ EfiIoWrite (EfiCpuIoWidthUint8, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
+}\r
+\r
+VOID\r
+PciWrite16 (\r
+ UINT8 Segment,\r
+ UINT8 Bus,\r
+ UINT8 DevFunc,\r
+ UINT8 Register,\r
+ UINT16 Data\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform an two byte PCI config cycle write\r
+ \r
+Arguments:\r
+ Segment - PCI Segment ACPI _SEG\r
+ Bus - PCI Bus\r
+ DevFunc - PCI Device(7:3) and Func(2:0)\r
+ Register - PCI config space register\r
+ Data - Data to write\r
+\r
+Returns:\r
+ NONE\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 PciAddress;\r
+ UINT32 PciAddress1;\r
+\r
+ PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
+ //\r
+ // Set bit 31 for PCI config access\r
+ //\r
+ PciAddress1 = PciAddress;\r
+ PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
+\r
+ Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return ;\r
+ }\r
+\r
+ EfiIoWrite (EfiCpuIoWidthUint16, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
+}\r
+\r
+VOID\r
+PciWrite32 (\r
+ UINT8 Segment,\r
+ UINT8 Bus,\r
+ UINT8 DevFunc,\r
+ UINT8 Register,\r
+ UINT32 Data\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform an four byte PCI config cycle write\r
+ \r
+Arguments:\r
+ Segment - PCI Segment ACPI _SEG\r
+ Bus - PCI Bus\r
+ DevFunc - PCI Device(7:3) and Func(2:0)\r
+ Register - PCI config space register\r
+ Data - Data to write\r
+\r
+Returns:\r
+ NONE\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ UINT32 PciAddress;\r
+ UINT32 PciAddress1;\r
+\r
+ PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
+ //\r
+ // Set bit 31 for PCI config access\r
+ //\r
+ PciAddress1 = PciAddress;\r
+ PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
+\r
+ Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ return ;\r
+ }\r
+\r
+ EfiIoWrite (EfiCpuIoWidthUint32, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
+}\r
+//\r
+// Delay Primative\r
+//\r
+VOID\r
+EfiStall (\r
+ IN UINTN Microseconds\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Delay for at least the request number of microseconds\r
+ \r
+Arguments:\r
+ Microseconds - Number of microseconds to delay.\r
+\r
+Returns:\r
+ NONE\r
+\r
+--*/\r
+{\r
+ UINT8 Data;\r
+ UINT8 InitialState;\r
+ UINTN CycleIterations;\r
+\r
+ CycleIterations = 0;\r
+ Data = 0;\r
+ InitialState = 0;\r
+\r
+ if (EfiAtRuntime ()) {\r
+ //\r
+ // The time-source is 30 us granular, so calibrate the timing loop\r
+ // based on this baseline\r
+ // Error is possible 30us.\r
+ //\r
+ CycleIterations = (Microseconds - 1) / 30 + 1;\r
+\r
+ //\r
+ // Use the DMA Refresh timer in port 0x61. Cheap but effective.\r
+ // The only issue is that the granularity is 30us, and we want to\r
+ // guarantee "at least" one full transition to avoid races.\r
+ //\r
+ //\r
+ // _____________/----------\__________/--------\r
+ //\r
+ // |<--15us-->|<--15us-->|\r
+ //\r
+ // --------------------------------------------------> Time (us)\r
+ //\r
+ while (CycleIterations--) {\r
+ EfiIoRead (EfiCpuIoWidthUint8, 0x61, 1, &Data);\r
+ Data &= REFRESH_CYCLE_TOGGLE_BIT;\r
+ InitialState = Data;\r
+\r
+ //\r
+ // Capture first transition (strictly less than one period)\r
+ //\r
+ while (InitialState == Data) {\r
+ EfiIoRead (EfiCpuIoWidthUint8, 0x61, 1, &Data);\r
+ Data &= REFRESH_CYCLE_TOGGLE_BIT;\r
+ }\r
+\r
+ InitialState = Data;\r
+ //\r
+ // Capture next transition (guarantee at least one full pulse)\r
+ //\r
+ while (InitialState == Data) {\r
+ EfiIoRead (EfiCpuIoWidthUint8, 0x61, 1, &Data);\r
+ Data &= REFRESH_CYCLE_TOGGLE_BIT;\r
+ }\r
+ }\r
+ } else {\r
+ gBS->Stall (Microseconds);\r
+ }\r
+}\r
--- /dev/null
+/*++\r
+\r
+Copyright (c) 2005 - 2008, 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
+ RuntimeLib.c\r
+\r
+Abstract:\r
+\r
+ Light weight lib to support Tiano drivers.\r
+\r
+--*/\r
+\r
+#include "Tiano.h"\r
+#include "EfiRuntimeLib.h"\r
+#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
+#include EFI_PROTOCOL_DEFINITION (FirmwareVolumeBlock)\r
+#include EFI_GUID_DEFINITION (StatusCodeCallerId)\r
+#include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)\r
+\r
+//\r
+// Driver Lib Module Globals\r
+//\r
+static EFI_RUNTIME_SERVICES *mRT;\r
+static EFI_EVENT mRuntimeNotifyEvent = NULL;\r
+static EFI_EVENT mEfiVirtualNotifyEvent = NULL;\r
+static BOOLEAN mRuntimeLibInitialized = FALSE;\r
+static BOOLEAN mEfiGoneVirtual = FALSE;\r
+\r
+//\r
+// Runtime Global, but you should use the Lib functions\r
+//\r
+EFI_CPU_IO_PROTOCOL *gCpuIo;\r
+BOOLEAN mEfiAtRuntime = FALSE;\r
+FVB_ENTRY *mFvbEntry;\r
+\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+static EFI_STATUS_CODE_PROTOCOL *gStatusCode = NULL;\r
+#endif\r
+\r
+EFI_STATUS\r
+EfiConvertPointer (\r
+ IN UINTN DebugDisposition,\r
+ IN OUT VOID *Address\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Determines the new virtual address that is to be used on subsequent memory accesses.\r
+\r
+Arguments:\r
+\r
+ DebugDisposition - Supplies type information for the pointer being converted.\r
+ Address - A pointer to a pointer that is to be fixed to be the value needed\r
+ for the new virtual address mappings being applied.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->ConvertPointer (DebugDisposition, Address);\r
+}\r
+\r
+EFI_STATUS\r
+EfiConvertInternalPointer (\r
+ IN OUT VOID *Address\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Call EfiConvertPointer() to convert internal pointer.\r
+\r
+Arguments:\r
+\r
+ Address - A pointer to a pointer that is to be fixed to be the value needed\r
+ for the new virtual address mappings being applied.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return EfiConvertPointer (EFI_INTERNAL_POINTER, Address);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+EfiRuntimeLibFvbVirtualNotifyEvent (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Convert all pointers in mFvbEntry after ExitBootServices.\r
+\r
+Arguments:\r
+\r
+ Event - The Event that is being processed\r
+ \r
+ Context - Event Context\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+{\r
+ UINTN Index;\r
+ if (mFvbEntry != NULL) {\r
+ for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r
+ if (NULL != mFvbEntry[Index].Fvb) {\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetVolumeAttributes);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->SetVolumeAttributes);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Read);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Write);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb);\r
+ }\r
+\r
+ if (NULL != mFvbEntry[Index].FvbExtension) {\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension);\r
+ }\r
+ }\r
+\r
+ EfiConvertInternalPointer ((VOID **) &mFvbEntry);\r
+ }\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+RuntimeDriverExitBootServices (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Set AtRuntime flag as TRUE after ExitBootServices\r
+\r
+Arguments:\r
+\r
+ Event - The Event that is being processed\r
+ \r
+ Context - Event Context\r
+\r
+Returns: \r
+\r
+ None\r
+\r
+--*/\r
+{\r
+ mEfiAtRuntime = TRUE;\r
+}\r
+\r
+extern BOOLEAN gEfiFvbInitialized;\r
+\r
+VOID\r
+EFIAPI\r
+EfiRuntimeLibVirtualNotifyEvent (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Fixup internal data so that EFI can be call in virtual mode.\r
+ Call the passed in Child Notify event and convert any pointers in \r
+ lib to virtual mode.\r
+\r
+Arguments:\r
+\r
+ Event - The Event that is being processed\r
+ \r
+ Context - Event Context\r
+\r
+Returns: \r
+\r
+ None\r
+\r
+--*/\r
+{\r
+ EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
+\r
+ if (Context != NULL) {\r
+ ChildNotifyEventHandler = (EFI_EVENT_NOTIFY) (UINTN) Context;\r
+ ChildNotifyEventHandler (Event, NULL);\r
+ }\r
+\r
+ if (gEfiFvbInitialized) {\r
+ EfiRuntimeLibFvbVirtualNotifyEvent (Event, Context);\r
+ }\r
+ //\r
+ // Update global for Runtime Services Table and IO\r
+ //\r
+ EfiConvertInternalPointer ((VOID **) &gCpuIo);\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+ if (gStatusCode != NULL) {\r
+ EfiConvertInternalPointer ((VOID **) &gStatusCode->ReportStatusCode);\r
+ EfiConvertInternalPointer ((VOID **) &gStatusCode);\r
+ }\r
+#endif\r
+ EfiConvertInternalPointer ((VOID **) &mRT);\r
+\r
+ //\r
+ // Clear out BootService globals\r
+ //\r
+ gBS = NULL;\r
+ gST = NULL;\r
+ mEfiGoneVirtual = TRUE;\r
+}\r
+\r
+EFI_STATUS\r
+EfiInitializeRuntimeDriverLib (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable,\r
+ IN EFI_EVENT_NOTIFY GoVirtualChildEvent\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Intialize runtime Driver Lib if it has not yet been initialized. \r
+\r
+Arguments:\r
+\r
+ ImageHandle - The firmware allocated handle for the EFI image.\r
+ \r
+ SystemTable - A pointer to the EFI System Table.\r
+\r
+ GoVirtualChildEvent - Caller can register a virtual notification event.\r
+\r
+Returns: \r
+\r
+ EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (mRuntimeLibInitialized) {\r
+ return EFI_ALREADY_STARTED;\r
+ }\r
+\r
+ mRuntimeLibInitialized = TRUE;\r
+\r
+ gST = SystemTable;\r
+ ASSERT (gST != NULL);\r
+\r
+ gBS = SystemTable->BootServices;\r
+ ASSERT (gBS != NULL);\r
+ mRT = SystemTable->RuntimeServices;\r
+ ASSERT (mRT != NULL);\r
+\r
+ Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+ Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
+ if (EFI_ERROR (Status)) {\r
+ gStatusCode = NULL;\r
+ }\r
+#endif\r
+\r
+ Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (VOID **) &gCpuIo);\r
+ if (EFI_ERROR (Status)) {\r
+ gCpuIo = NULL;\r
+ }\r
+\r
+ //\r
+ // Register our ExitBootServices () notify function\r
+ //\r
+ Status = gBS->CreateEvent (\r
+ EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
+ EFI_TPL_NOTIFY,\r
+ RuntimeDriverExitBootServices,\r
+ NULL,\r
+ &mRuntimeNotifyEvent\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ //\r
+ // Register SetVirtualAddressMap () notify function\r
+ //\r
+ Status = gBS->CreateEvent (\r
+ EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
+ EFI_TPL_NOTIFY,\r
+ EfiRuntimeLibVirtualNotifyEvent,\r
+ (VOID *) (UINTN) GoVirtualChildEvent,\r
+ &mEfiVirtualNotifyEvent\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EfiShutdownRuntimeDriverLib (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This routine will free some resources which have been allocated in\r
+ EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
+ it must call this routine to free the allocated resource before the exiting.\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns: \r
+\r
+ EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
+ EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (!mRuntimeLibInitialized) {\r
+ //\r
+ // You must call EfiInitializeRuntimeDriverLib() first\r
+ //\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ mRuntimeLibInitialized = FALSE;\r
+\r
+ //\r
+ // Close our ExitBootServices () notify function\r
+ //\r
+ if (mRuntimeNotifyEvent != NULL) {\r
+ Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
+ //\r
+ // Close SetVirtualAddressMap () notify function\r
+ //\r
+ if (mEfiVirtualNotifyEvent != NULL) {\r
+ Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EfiInitializeSmmDriverLib (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Intialize runtime Driver Lib if it has not yet been initialized. \r
+\r
+Arguments:\r
+\r
+ ImageHandle - The firmware allocated handle for the EFI image.\r
+ \r
+ SystemTable - A pointer to the EFI System Table.\r
+\r
+Returns: \r
+\r
+ EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ if (mRuntimeLibInitialized) {\r
+ return EFI_ALREADY_STARTED;\r
+ }\r
+\r
+ mRuntimeLibInitialized = TRUE;\r
+\r
+ gST = SystemTable;\r
+ ASSERT (gST != NULL);\r
+\r
+ gBS = SystemTable->BootServices;\r
+ ASSERT (gBS != NULL);\r
+ mRT = SystemTable->RuntimeServices;\r
+ ASSERT (mRT != NULL);\r
+\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+ Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
+ if (EFI_ERROR (Status)) {\r
+ gStatusCode = NULL;\r
+ }\r
+#endif\r
+\r
+ Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (VOID **) &gCpuIo);\r
+ if (EFI_ERROR (Status)) {\r
+ gCpuIo = NULL;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+EfiAtRuntime (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Return TRUE if ExitBootServices () has been called\r
+\r
+Arguments:\r
+ NONE\r
+\r
+Returns: \r
+ TRUE - If ExitBootServices () has been called\r
+\r
+--*/\r
+{\r
+ return mEfiAtRuntime;\r
+}\r
+\r
+BOOLEAN\r
+EfiGoneVirtual (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Return TRUE if SetVirtualAddressMap () has been called\r
+\r
+Arguments:\r
+ NONE\r
+\r
+Returns: \r
+ TRUE - If SetVirtualAddressMap () has been called\r
+\r
+--*/\r
+{\r
+ return mEfiGoneVirtual;\r
+}\r
+//\r
+// The following functions hide the mRT local global from the call to\r
+// runtime service in the EFI system table.\r
+//\r
+EFI_STATUS\r
+EfiGetTime (\r
+ OUT EFI_TIME *Time,\r
+ OUT EFI_TIME_CAPABILITIES *Capabilities\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Returns the current time and date information, and the time-keeping \r
+ capabilities of the hardware platform.\r
+\r
+Arguments:\r
+\r
+ Time - A pointer to storage to receive a snapshot of the current time.\r
+ Capabilities - An optional pointer to a buffer to receive the real time clock device's\r
+ capabilities.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->GetTime (Time, Capabilities);\r
+}\r
+\r
+EFI_STATUS\r
+EfiSetTime (\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Sets the current local time and date information.\r
+\r
+Arguments:\r
+\r
+ Time - A pointer to the current time.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->SetTime (Time);\r
+}\r
+\r
+EFI_STATUS\r
+EfiGetWakeupTime (\r
+ OUT BOOLEAN *Enabled,\r
+ OUT BOOLEAN *Pending,\r
+ OUT EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Returns the current wakeup alarm clock setting.\r
+\r
+Arguments:\r
+\r
+ Enabled - Indicates if the alarm is currently enabled or disabled.\r
+ Pending - Indicates if the alarm signal is pending and requires acknowledgement.\r
+ Time - The current alarm setting.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->GetWakeupTime (Enabled, Pending, Time);\r
+}\r
+\r
+EFI_STATUS\r
+EfiSetWakeupTime (\r
+ IN BOOLEAN Enable,\r
+ IN EFI_TIME *Time\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Sets the system wakeup alarm clock time.\r
+\r
+Arguments:\r
+\r
+ Enable - Enable or disable the wakeup alarm.\r
+ Time - If Enable is TRUE, the time to set the wakeup alarm for.\r
+ If Enable is FALSE, then this parameter is optional, and may be NULL.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->SetWakeupTime (Enable, Time);\r
+}\r
+\r
+EFI_STATUS\r
+EfiGetVariable (\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID * VendorGuid,\r
+ OUT UINT32 *Attributes OPTIONAL,\r
+ IN OUT UINTN *DataSize,\r
+ OUT VOID *Data\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Returns the value of a variable.\r
+\r
+Arguments:\r
+\r
+ VariableName - A Null-terminated Unicode string that is the name of the\r
+ vendor's variable.\r
+ VendorGuid - A unique identifier for the vendor.\r
+ Attributes - If not NULL, a pointer to the memory location to return the\r
+ attributes bitmask for the variable.\r
+ DataSize - On input, the size in bytes of the return Data buffer.\r
+ On output the size of data returned in Data.\r
+ Data - The buffer to return the contents of the variable.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
+}\r
+\r
+EFI_STATUS\r
+EfiGetNextVariableName (\r
+ IN OUT UINTN *VariableNameSize,\r
+ IN OUT CHAR16 *VariableName,\r
+ IN OUT EFI_GUID *VendorGuid\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Enumerates the current variable names.\r
+\r
+Arguments:\r
+\r
+ VariableNameSize - The size of the VariableName buffer.\r
+ VariableName - On input, supplies the last VariableName that was returned\r
+ by GetNextVariableName(). \r
+ On output, returns the Nullterminated Unicode string of the\r
+ current variable.\r
+ VendorGuid - On input, supplies the last VendorGuid that was returned by\r
+ GetNextVariableName(). \r
+ On output, returns the VendorGuid of the current variable.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);\r
+}\r
+\r
+EFI_STATUS\r
+EfiSetVariable (\r
+ IN CHAR16 *VariableName,\r
+ IN EFI_GUID *VendorGuid,\r
+ IN UINT32 Attributes,\r
+ IN UINTN DataSize,\r
+ IN VOID *Data\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Sets the value of a variable.\r
+\r
+Arguments:\r
+\r
+ VariableName - A Null-terminated Unicode string that is the name of the\r
+ vendor's variable.\r
+ VendorGuid - A unique identifier for the vendor.\r
+ Attributes - Attributes bitmask to set for the variable.\r
+ DataSize - The size in bytes of the Data buffer.\r
+ Data - The contents for the variable.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
+}\r
+\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+\r
+EFI_STATUS\r
+EfiQueryVariableInfo (\r
+ IN UINT32 Attributes,\r
+ OUT UINT64 *MaximumVariableStorageSize,\r
+ OUT UINT64 *RemainingVariableStorageSize,\r
+ OUT UINT64 *MaximumVariableSize\r
+ )\r
+\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ This code returns information about the EFI variables.\r
+\r
+Arguments:\r
+\r
+ Attributes Attributes bitmask to specify the type of variables \r
+ on which to return information.\r
+ MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
+ for the EFI variables associated with the attributes specified.\r
+ RemainingVariableStorageSize Pointer to the remaining size of the storage space available \r
+ for the EFI variables associated with the attributes specified.\r
+ MaximumVariableSize Pointer to the maximum size of the individual EFI variables\r
+ associated with the attributes specified.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->QueryVariableInfo (Attributes, MaximumVariableStorageSize, RemainingVariableStorageSize, MaximumVariableSize);\r
+}\r
+\r
+#endif\r
+\r
+\r
+EFI_STATUS\r
+EfiGetNextHighMonotonicCount (\r
+ OUT UINT32 *HighCount\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Returns the next high 32 bits of the platform's monotonic counter.\r
+\r
+Arguments:\r
+\r
+ HighCount - Pointer to returned value.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ return mRT->GetNextHighMonotonicCount (HighCount);\r
+}\r
+\r
+VOID\r
+EfiResetSystem (\r
+ IN EFI_RESET_TYPE ResetType,\r
+ IN EFI_STATUS ResetStatus,\r
+ IN UINTN DataSize,\r
+ IN CHAR16 *ResetData\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Resets the entire platform.\r
+\r
+Arguments:\r
+\r
+ ResetType - The type of reset to perform.\r
+ ResetStatus - The status code for the reset.\r
+ DataSize - The size, in bytes, of ResetData.\r
+ ResetData - A data buffer that includes a Null-terminated Unicode string, optionally\r
+ followed by additional binary data.\r
+\r
+Returns:\r
+\r
+ None\r
+\r
+--*/\r
+{\r
+ mRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);\r
+}\r
+\r
+EFI_STATUS\r
+EfiReportStatusCode (\r
+ IN EFI_STATUS_CODE_TYPE CodeType,\r
+ IN EFI_STATUS_CODE_VALUE Value,\r
+ IN UINT32 Instance,\r
+ IN EFI_GUID * CallerId,\r
+ IN EFI_STATUS_CODE_DATA * Data OPTIONAL\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Status Code reporter\r
+\r
+Arguments:\r
+\r
+ CodeType - Type of Status Code.\r
+ \r
+ Value - Value to output for Status Code.\r
+ \r
+ Instance - Instance Number of this status code.\r
+ \r
+ CallerId - ID of the caller of this status code.\r
+ \r
+ Data - Optional data associated with this status code.\r
+\r
+Returns:\r
+\r
+ Status code\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000) \r
+ if (gStatusCode == NULL) {\r
+ if (EfiAtRuntime ()) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
+ if (EFI_ERROR (Status) || gStatusCode == NULL) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+ Status = gStatusCode->ReportStatusCode (CodeType, Value, Instance, CallerId, Data);\r
+#else\r
+ if (mRT == NULL) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ //\r
+ // Check whether EFI_RUNTIME_SERVICES has Tiano Extension\r
+ //\r
+ Status = EFI_UNSUPPORTED;\r
+ if (mRT->Hdr.Revision == EFI_SPECIFICATION_VERSION &&\r
+ mRT->Hdr.HeaderSize == sizeof (EFI_RUNTIME_SERVICES) &&\r
+ mRT->ReportStatusCode != NULL) {\r
+ Status = mRT->ReportStatusCode (CodeType, Value, Instance, CallerId, Data);\r
+ }\r
+#endif\r
+ return Status;\r
+}\r
--- /dev/null
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2008, Intel Corporation
+# All rights reserved. This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+#
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+# Module Name:
+#
+# RuntimeLibAsm.S
+#
+# Abstract:
+#
+#
+#------------------------------------------------------------------------------
+#include <EfiBind.h>
+
+.text
+
+.global ASM_PFX(EfiCpuFlushCache)
+#------------------------------------------------------------------------------
+#EFI_STATUS
+#EfiCpuFlushCache (
+# IN EFI_PHYSICAL_ADDRESS Start,
+# IN UINT64 Length
+# );
+#------------------------------------------------------------------------------
+
+ASM_PFX(EfiCpuFlushCache):
+ wbinvd
+ mov $0, %rax
+ ret
+
--- /dev/null
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (c) 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
+; RuntimeLibAsm.asm\r
+;\r
+; Abstract:\r
+;\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+.code\r
+\r
+;------------------------------------------------------------------------------\r
+;EFI_STATUS\r
+;EfiCpuFlushCache (\r
+; IN EFI_PHYSICAL_ADDRESS Start,\r
+; IN UINT64 Length\r
+; );\r
+;------------------------------------------------------------------------------\r
+\r
+EfiCpuFlushCache PROC PUBLIC\r
+ wbinvd\r
+ mov rax, 0\r
+ ret\r
+EfiCpuFlushCache ENDP\r
+\r
+END
\ No newline at end of file
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2005 - 2008, 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
- Fvb.c \r
-\r
-Abstract:\r
-\r
- Firmware Volume Block Protocol Runtime Abstraction\r
-\r
- mFvbEntry is an array of Handle Fvb pairs. The Fvb Lib Instance matches the \r
- index in the mFvbEntry array. This should be the same sequence as the FVB's\r
- were described in the HOB. We have to remember the handle so we can tell if \r
- the protocol has been reinstalled and it needs updateing.\r
-\r
- If you are using any of these lib functions.you must first call FvbInitialize ().\r
-\r
-Key:\r
- FVB - Firmware Volume Block\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiRuntimeLib.h"\r
-#include EFI_PROTOCOL_DEFINITION (FirmwareVolumeBlock)\r
-#include EFI_PROTOCOL_DEFINITION (FvbExtension)\r
-\r
-//\r
-// Lib will ASSERT if more FVB devices than this are added to the system.\r
-//\r
-UINTN mFvbCount;\r
-VOID *mFvbRegistration;\r
-VOID *mFvbExtRegistration;\r
-//static EFI_EVENT mEfiFvbVirtualNotifyEvent;\r
-BOOLEAN gEfiFvbInitialized = FALSE;\r
-EFI_EVENT mFvbEvent;\r
-\r
-BOOLEAN\r
-IsMemoryRuntime (\r
- IN VOID *Address\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Check whether an address is runtime memory or not.\r
-\r
-Arguments:\r
-\r
- Address - The Address being checked.\r
- \r
-Returns: \r
- TRUE - The address is runtime memory.\r
- FALSE - The address is not runtime memory.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT8 TmpMemoryMap[1];\r
- UINTN MapKey;\r
- UINTN DescriptorSize;\r
- UINT32 DescriptorVersion;\r
- UINTN MemoryMapSize;\r
- EFI_MEMORY_DESCRIPTOR *MemoryMap;\r
- EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;\r
- BOOLEAN IsRuntime;\r
- UINTN Index;\r
-\r
- IsRuntime = FALSE;\r
-\r
- //\r
- // Get System MemoryMapSize\r
- //\r
- MemoryMapSize = 1;\r
- Status = gBS->GetMemoryMap (\r
- &MemoryMapSize,\r
- (EFI_MEMORY_DESCRIPTOR *)TmpMemoryMap,\r
- &MapKey,\r
- &DescriptorSize,\r
- &DescriptorVersion\r
- );\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
- //\r
- // Enlarge space here, because we will allocate pool now.\r
- //\r
- MemoryMapSize += EFI_PAGE_SIZE;\r
- Status = gBS->AllocatePool (\r
- EfiBootServicesData,\r
- MemoryMapSize,\r
- (VOID**)&MemoryMap\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // Get System MemoryMap\r
- //\r
- Status = gBS->GetMemoryMap (\r
- &MemoryMapSize,\r
- MemoryMap,\r
- &MapKey,\r
- &DescriptorSize,\r
- &DescriptorVersion\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- MemoryMapPtr = MemoryMap;\r
- //\r
- // Search the request Address\r
- //\r
- for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {\r
- if (((EFI_PHYSICAL_ADDRESS)(UINTN)Address >= MemoryMap->PhysicalStart) &&\r
- ((EFI_PHYSICAL_ADDRESS)(UINTN)Address < MemoryMap->PhysicalStart\r
- + LShiftU64 (MemoryMap->NumberOfPages, EFI_PAGE_SHIFT))) {\r
- //\r
- // Found it\r
- //\r
- if (MemoryMap->Attribute & EFI_MEMORY_RUNTIME) {\r
- IsRuntime = TRUE;\r
- }\r
- break;\r
- }\r
- //\r
- // Get next item\r
- //\r
- MemoryMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemoryMap + DescriptorSize);\r
- }\r
-\r
- //\r
- // Done\r
- //\r
- gBS->FreePool (MemoryMapPtr);\r
-\r
- return IsRuntime;\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-FvbNotificationFunction (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Update mFvbEntry. Add new entry, or update existing entry if Fvb protocol is\r
- reinstalled.\r
-\r
-Arguments:\r
-\r
- Event - The Event that is being processed\r
- \r
- Context - Event Context\r
-\r
-Returns: \r
- None\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINTN BufferSize;\r
- EFI_HANDLE Handle;\r
- UINTN Index;\r
- UINTN UpdateIndex;\r
- EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb;\r
- EFI_FVB_EXTENSION_PROTOCOL *FvbExtension;\r
-\r
- while (TRUE) {\r
- BufferSize = sizeof (Handle);\r
- Status = gBS->LocateHandle (\r
- ByRegisterNotify,\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- mFvbRegistration,\r
- &BufferSize,\r
- &Handle\r
- );\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // Exit Path of While Loop....\r
- //\r
- break;\r
- }\r
-\r
- UpdateIndex = MAX_FVB_COUNT;\r
- for (Index = 0; Index < mFvbCount; Index++) {\r
- if (mFvbEntry[Index].Handle == Handle) {\r
- //\r
- // If the handle is already in the table just update the protocol\r
- //\r
- UpdateIndex = Index;\r
- break;\r
- }\r
- }\r
-\r
- if (UpdateIndex == MAX_FVB_COUNT) {\r
- //\r
- // Use the next free slot for a new entry\r
- //\r
- UpdateIndex = mFvbCount;\r
- }\r
- //\r
- // The array does not have enough entries\r
- //\r
- ASSERT (UpdateIndex < MAX_FVB_COUNT);\r
-\r
- //\r
- // Get the interface pointer and if it's ours, skip it.\r
- // We check Runtime here, because it has no reason to register\r
- // a boot time FVB protocol.\r
- //\r
- Status = gBS->HandleProtocol (Handle, &gEfiFirmwareVolumeBlockProtocolGuid, (VOID **) &Fvb);\r
- ASSERT_EFI_ERROR (Status);\r
- if (IsMemoryRuntime (Fvb)) {\r
- //\r
- // Increase mFvbCount if we need to add a new entry\r
- //\r
- if (UpdateIndex == mFvbCount) {\r
- mFvbCount++;\r
- }\r
- mFvbEntry[UpdateIndex].Handle = Handle;\r
- mFvbEntry[UpdateIndex].Fvb = Fvb;\r
- mFvbEntry[UpdateIndex].FvbExtension = NULL;\r
-\r
- Status = gBS->HandleProtocol (Handle, &gEfiFvbExtensionProtocolGuid, (VOID **) &FvbExtension);\r
- if ((Status == EFI_SUCCESS) && IsMemoryRuntime (FvbExtension)) {\r
- mFvbEntry[UpdateIndex].FvbExtension = FvbExtension;\r
- }\r
- }\r
- }\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbInitialize (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Initialize globals and register Fvb Protocol notification function.\r
-\r
-Arguments:\r
- None \r
-\r
-Returns: \r
- EFI_SUCCESS - Fvb is successfully initialized\r
- others - Fail to initialize\r
-\r
---*/\r
-{\r
- UINTN Status;\r
- mFvbCount = 0;\r
-\r
- Status = gBS->AllocatePool (\r
- EfiRuntimeServicesData,\r
- (UINTN) sizeof (FVB_ENTRY) * MAX_FVB_COUNT,\r
- (VOID *) &mFvbEntry\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
-\r
- EfiZeroMem (mFvbEntry, sizeof (FVB_ENTRY) * MAX_FVB_COUNT);\r
-\r
- mFvbEvent = RtEfiLibCreateProtocolNotifyEvent (\r
- &gEfiFirmwareVolumeBlockProtocolGuid,\r
- EFI_TPL_CALLBACK,\r
- FvbNotificationFunction,\r
- NULL,\r
- &mFvbRegistration\r
- );\r
-\r
- //\r
- // Register SetVirtualAddressMap () notify function\r
- //\r
- // Status = gBS->CreateEvent (\r
- // EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
- // EFI_TPL_NOTIFY,\r
- // EfiRuntimeLibFvbVirtualNotifyEvent,\r
- // NULL,\r
- // &mEfiFvbVirtualNotifyEvent\r
- // );\r
- // ASSERT_EFI_ERROR (Status);\r
- //\r
- gEfiFvbInitialized = TRUE;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbShutdown (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Release resources allocated in EfiFvbInitialize.\r
-\r
-Arguments:\r
- None \r
-\r
-Returns: \r
- EFI_SUCCESS\r
-\r
---*/\r
-{\r
- gBS->FreePool ((VOID *) mFvbEntry);\r
-\r
- gBS->CloseEvent (mFvbEvent);\r
-\r
- gEfiFvbInitialized = FALSE;\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-//\r
-// The following functions wrap Fvb protocol in the Runtime Lib functions.\r
-// The Instance translates into Fvb instance. The Fvb order defined by HOBs and\r
-// thus the sequence of FVB protocol addition define Instance.\r
-//\r
-// EfiFvbInitialize () must be called before any of the following functions\r
-// must be called.\r
-//\r
-\r
-EFI_STATUS\r
-EfiFvbReadBlock (\r
- IN UINTN Instance,\r
- IN EFI_LBA Lba,\r
- IN UINTN Offset,\r
- IN OUT UINTN *NumBytes,\r
- IN UINT8 *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Reads specified number of bytes into a buffer from the specified block\r
-\r
-Arguments:\r
- Instance - The FV instance to be read from\r
- Lba - The logical block address to be read from\r
- Offset - Offset into the block at which to begin reading\r
- NumBytes - Pointer that on input contains the total size of\r
- the buffer. On output, it contains the total number\r
- of bytes read\r
- Buffer - Pointer to a caller allocated buffer that will be\r
- used to hold the data read\r
-\r
-Returns: \r
-\r
- Status code\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
-\r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return mFvbEntry[Instance].Fvb->Read (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbWriteBlock (\r
- IN UINTN Instance,\r
- IN EFI_LBA Lba,\r
- IN UINTN Offset,\r
- IN OUT UINTN *NumBytes,\r
- IN UINT8 *Buffer\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Writes specified number of bytes from the input buffer to the block\r
-\r
-Arguments:\r
- Instance - The FV instance to be written to\r
- Lba - The starting logical block index to write to\r
- Offset - Offset into the block at which to begin writing\r
- NumBytes - Pointer that on input contains the total size of\r
- the buffer. On output, it contains the total number\r
- of bytes actually written\r
- Buffer - Pointer to a caller allocated buffer that contains\r
- the source for the write\r
-\r
-Returns: \r
-\r
- Status code\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
-\r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return mFvbEntry[Instance].Fvb->Write (mFvbEntry[Instance].Fvb, Lba, Offset, NumBytes, Buffer);\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbEraseBlock (\r
- IN UINTN Instance,\r
- IN EFI_LBA Lba\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Erases and initializes a firmware volume block\r
-\r
-Arguments:\r
- Instance - The FV instance to be erased\r
- Lba - The logical block index to be erased\r
- \r
-Returns: \r
-\r
- Status code\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
-\r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return mFvbEntry[Instance].Fvb->EraseBlocks (mFvbEntry[Instance].Fvb, Lba, -1);\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbGetVolumeAttributes (\r
- IN UINTN Instance,\r
- OUT EFI_FVB_ATTRIBUTES *Attributes\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Retrieves attributes, insures positive polarity of attribute bits, returns\r
- resulting attributes in output parameter\r
-\r
-Arguments:\r
- Instance - The FV instance whose attributes is going to be \r
- returned\r
- Attributes - Output buffer which contains attributes\r
-\r
-Returns: \r
- Status code\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
-\r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return mFvbEntry[Instance].Fvb->GetVolumeAttributes (mFvbEntry[Instance].Fvb, Attributes);\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbSetVolumeAttributes (\r
- IN UINTN Instance,\r
- IN EFI_FVB_ATTRIBUTES Attributes\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Modifies the current settings of the firmware volume according to the \r
- input parameter.\r
-\r
-Arguments:\r
- Instance - The FV instance whose attributes is going to be \r
- modified\r
- Attributes - It is a pointer to EFI_FVB_ATTRIBUTES \r
- containing the desired firmware volume settings.\r
-\r
-Returns: \r
- Status code\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
-\r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return mFvbEntry[Instance].Fvb->SetVolumeAttributes (mFvbEntry[Instance].Fvb, &Attributes);\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbGetPhysicalAddress (\r
- IN UINTN Instance,\r
- OUT EFI_PHYSICAL_ADDRESS *BaseAddress\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Retrieves the physical address of a memory mapped FV\r
-\r
-Arguments:\r
- Instance - The FV instance whose base address is going to be\r
- returned\r
- BaseAddress - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS \r
- that on successful return, contains the base address\r
- of the firmware volume. \r
-\r
-Returns: \r
-\r
- Status code\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
-\r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return mFvbEntry[Instance].Fvb->GetPhysicalAddress (mFvbEntry[Instance].Fvb, BaseAddress);\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbGetBlockSize (\r
- IN UINTN Instance,\r
- IN EFI_LBA Lba,\r
- OUT UINTN *BlockSize,\r
- OUT UINTN *NumOfBlocks\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Retrieve the size of a logical block\r
-\r
-Arguments:\r
- Instance - The FV instance whose block size is going to be\r
- returned\r
- Lba - Indicates which block to return the size for.\r
- BlockSize - A pointer to a caller allocated UINTN in which\r
- the size of the block is returned\r
- NumOfBlocks - a pointer to a caller allocated UINTN in which the\r
- number of consecutive blocks starting with Lba is\r
- returned. All blocks in this range have a size of\r
- BlockSize\r
-\r
-Returns: \r
- EFI_SUCCESS - The firmware volume was read successfully and \r
- contents are in Buffer\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
-\r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- return mFvbEntry[Instance].Fvb->GetBlockSize (mFvbEntry[Instance].Fvb, Lba, BlockSize, NumOfBlocks);\r
-}\r
-\r
-EFI_STATUS\r
-EfiFvbEraseCustomBlockRange (\r
- IN UINTN Instance,\r
- IN EFI_LBA StartLba,\r
- IN UINTN OffsetStartLba,\r
- IN EFI_LBA LastLba,\r
- IN UINTN OffsetLastLba\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Erases and initializes a specified range of a firmware volume\r
-\r
-Arguments:\r
- Instance - The FV instance to be erased\r
- StartLba - The starting logical block index to be erased\r
- OffsetStartLba - Offset into the starting block at which to \r
- begin erasing\r
- LastLba - The last logical block index to be erased\r
- OffsetLastLba - Offset into the last block at which to end erasing\r
-\r
-Returns: \r
-\r
- Status code\r
- \r
- EFI_INVALID_PARAMETER - invalid parameter\r
- \r
- EFI_UNSUPPORTED - not support\r
- \r
---*/\r
-{\r
- if (Instance >= mFvbCount) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (!(mFvbEntry[Instance].FvbExtension)) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- if (!(mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock)) {\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- return mFvbEntry[Instance].FvbExtension->EraseFvbCustomBlock (\r
- mFvbEntry[Instance].FvbExtension,\r
- StartLba,\r
- OffsetStartLba,\r
- LastLba,\r
- OffsetLastLba\r
- );\r
-}\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2005, 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
- IoLib.c\r
-\r
-Abstract:\r
-\r
- Light weight lib to support Tiano drivers.\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiRuntimeLib.h"\r
-#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
-\r
-extern EFI_CPU_IO_PROTOCOL *gCpuIo;\r
-\r
-EFI_STATUS\r
-EfiIoRead (\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
- Perform an IO read into Buffer.\r
-\r
-Arguments:\r
- Width - Width of read transaction, and repeat operation to use\r
- Address - IO address to read\r
- Count - Number of times to read the IO address.\r
- Buffer - Buffer to read data into. size is Width * Count\r
-\r
-Returns: \r
- BugBug: Check with Mike to see if I can find this #define some ware else\r
-\r
---*/\r
-{\r
- return gCpuIo->Io.Read (gCpuIo, Width, Address, Count, Buffer);\r
-}\r
-\r
-EFI_STATUS\r
-EfiIoWrite (\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
- Perform an IO write into Buffer.\r
-\r
-Arguments:\r
- Width - Width of write transaction, and repeat operation to use\r
- Address - IO address to write\r
- Count - Number of times to write the IO address.\r
- Buffer - Buffer to write data from. size is Width * Count\r
-\r
-Returns: \r
- BugBug: Check with Mike to see if I can find this #define some ware else\r
-\r
---*/\r
-{\r
- return gCpuIo->Io.Write (gCpuIo, Width, Address, Count, Buffer);\r
-}\r
-\r
-EFI_STATUS\r
-EfiMemRead (\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
- Perform a Memory mapped IO read into Buffer.\r
-\r
-Arguments:\r
- Width - Width of each read transaction.\r
- Address - Memory mapped IO address to read\r
- Count - Number of Width quanta to read\r
- Buffer - Buffer to read data into. size is Width * Count\r
-\r
-Returns: \r
- BugBug: Check with Mike to see if I can find this #define some ware else\r
-\r
---*/\r
-{\r
- return gCpuIo->Mem.Read (gCpuIo, Width, Address, Count, Buffer);\r
-}\r
-\r
-EFI_STATUS\r
-EfiMemWrite (\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
- Perform a memory mapped IO write into Buffer.\r
-\r
-Arguments:\r
- Width - Width of write transaction, and repeat operation to use\r
- Address - IO address to write\r
- Count - Number of times to write the IO address.\r
- Buffer - Buffer to write data from. size is Width * Count\r
-\r
-Returns: \r
- BugBug: Check with Mike to see if I can find this #define some ware else\r
-\r
---*/\r
-{\r
- return gCpuIo->Mem.Write (gCpuIo, Width, Address, Count, Buffer);\r
-}\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2005, 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
- Lock.c\r
-\r
-Abstract:\r
-\r
- Support for locking lib services.\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiDriverLib.h"\r
-\r
-extern\r
-BOOLEAN\r
-EfiAtRuntime (\r
- VOID\r
- );\r
-\r
-VOID\r
-EfiInitializeLock (\r
- IN OUT EFI_LOCK *Lock,\r
- IN EFI_TPL Priority\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Initialize a basic mutual exclusion lock. Each lock\r
- provides mutual exclusion access at it's task priority\r
- level. Since there is no-premption (at any TPL) or\r
- multiprocessor support, acquiring the lock only consists\r
- of raising to the locks TPL.\r
-\r
- Note on a check build ASSERT()s are used to ensure proper\r
- lock usage.\r
- \r
-Arguments:\r
-\r
- Lock - The EFI_LOCK structure to initialize\r
-\r
- Priority - The task priority level of the lock\r
-\r
- \r
-Returns:\r
-\r
- An initialized Efi Lock structure.\r
-\r
---*/\r
-{\r
- Lock->Tpl = Priority;\r
- Lock->OwnerTpl = 0;\r
- Lock->Lock = 0;\r
-}\r
-\r
-EFI_STATUS\r
-EfiAcquireLockOrFail (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Initialize a basic mutual exclusion lock. Each lock\r
- provides mutual exclusion access at it's task priority\r
- level. Since there is no-premption (at any TPL) or\r
- multiprocessor support, acquiring the lock only consists\r
- of raising to the locks TPL.\r
- \r
-Arguments:\r
-\r
- Lock - The EFI_LOCK structure to initialize\r
- \r
-Returns:\r
-\r
- EFI_SUCCESS - Lock Owned.\r
- EFI_ACCESS_DENIED - Reentrant Lock Acquisition, Lock not Owned.\r
-\r
---*/\r
-{\r
- if (Lock->Lock != 0) {\r
- //\r
- // Lock is already owned, so bail out\r
- //\r
- return EFI_ACCESS_DENIED;\r
- }\r
-\r
- if (!EfiAtRuntime ()) {\r
- //\r
- // The check is just debug code for core inplementation. It must\r
- // always be true in a driver\r
- //\r
- Lock->OwnerTpl = gBS->RaiseTPL (Lock->Tpl);\r
- }\r
-\r
- Lock->Lock += 1;\r
- return EFI_SUCCESS;\r
-}\r
-\r
-VOID\r
-EfiAcquireLock (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Raising to the task priority level of the mutual exclusion\r
- lock, and then acquires ownership of the lock.\r
- \r
-Arguments:\r
-\r
- Lock - The lock to acquire\r
- \r
-Returns:\r
-\r
- Lock owned\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- Status = EfiAcquireLockOrFail (Lock);\r
-\r
- //\r
- // Lock was already locked.\r
- //\r
- ASSERT_EFI_ERROR (Status);\r
-}\r
-\r
-VOID\r
-EfiReleaseLock (\r
- IN EFI_LOCK *Lock\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Releases ownership of the mutual exclusion lock, and\r
- restores the previous task priority level.\r
- \r
-Arguments:\r
-\r
- Lock - The lock to release\r
- \r
-Returns:\r
-\r
- Lock unowned\r
-\r
---*/\r
-{\r
- EFI_TPL Tpl;\r
-\r
- Tpl = Lock->OwnerTpl;\r
-\r
- ASSERT (Lock->Lock == 1);\r
- Lock->Lock -= 1;\r
-\r
- if (!EfiAtRuntime ()) {\r
- //\r
- // The check is just debug code for core inplementation. It must\r
- // always be true in a driver\r
- //\r
- gBS->RestoreTPL (Tpl);\r
- }\r
-}\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2005 - 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
- PlatformIoLib.c\r
-\r
-Abstract:\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiRuntimeLib.h"\r
-#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
-\r
-#define PCI_CONFIG_INDEX_PORT 0xcf8\r
-#define PCI_CONFIG_DATA_PORT 0xcfc\r
-#define REFRESH_CYCLE_TOGGLE_BIT 0x10\r
-\r
-UINT32\r
-GetPciAddress (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Constructs PCI Address 32 bits\r
- \r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
-\r
-Returns:\r
- PciAddress to be written to Config Port\r
-\r
---*/\r
-{\r
- UINT32 Data;\r
-\r
- Data = 0;\r
-\r
- Data = (((UINT32) Segment) << 24);\r
- Data |= (((UINT32) Bus) << 16);\r
- Data |= (((UINT32) DevFunc) << 8);\r
- Data |= (UINT32) Register;\r
-\r
- return Data;\r
-\r
-}\r
-\r
-UINT8\r
-PciRead8 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an one byte PCI config cycle read\r
- \r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
-\r
-Returns:\r
- Data read from PCI config space\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT32 PciAddress;\r
- UINT32 PciAddress1;\r
- UINT8 Data;\r
-\r
- PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
- //\r
- // Set bit 31 for PCI config access\r
- //\r
- PciAddress1 = PciAddress;\r
- PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
-\r
- Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return 0;\r
- }\r
-\r
- EfiIoRead (EfiCpuIoWidthUint8, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
-\r
- return Data;\r
-}\r
-\r
-UINT16\r
-PciRead16 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an two byte PCI config cycle read\r
- \r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
-\r
-Returns:\r
- Data read from PCI config space\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT32 PciAddress;\r
- UINT32 PciAddress1;\r
- UINT16 Data;\r
-\r
- PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
- //\r
- // Set bit 31 for PCI config access\r
- //\r
- PciAddress1 = PciAddress;\r
- PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
-\r
- Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return 0;\r
- }\r
-\r
- EfiIoRead (EfiCpuIoWidthUint16, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
-\r
- return Data;\r
-}\r
-\r
-UINT32\r
-PciRead32 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an four byte PCI config cycle read\r
- \r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
-\r
-Returns:\r
- Data read from PCI config space\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT32 PciAddress;\r
- UINT32 PciAddress1;\r
- UINT32 Data;\r
-\r
- PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
- //\r
- // Set bit 31 for PCI config access\r
- //\r
- PciAddress1 = PciAddress;\r
- PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
-\r
- Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return 0;\r
- }\r
-\r
- EfiIoRead (EfiCpuIoWidthUint32, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
-\r
- return Data;\r
-}\r
-\r
-VOID\r
-PciWrite8 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register,\r
- UINT8 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an one byte PCI config cycle write\r
- \r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
- Data - Data to write\r
-\r
-Returns:\r
- NONE\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT32 PciAddress;\r
- UINT32 PciAddress1;\r
-\r
- PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
- //\r
- // Set bit 31 for PCI config access\r
- //\r
- PciAddress1 = PciAddress;\r
- PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
-\r
- Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return ;\r
- }\r
-\r
- EfiIoWrite (EfiCpuIoWidthUint8, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
-}\r
-\r
-VOID\r
-PciWrite16 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register,\r
- UINT16 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an two byte PCI config cycle write\r
- \r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
- Data - Data to write\r
-\r
-Returns:\r
- NONE\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT32 PciAddress;\r
- UINT32 PciAddress1;\r
-\r
- PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
- //\r
- // Set bit 31 for PCI config access\r
- //\r
- PciAddress1 = PciAddress;\r
- PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
-\r
- Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return ;\r
- }\r
-\r
- EfiIoWrite (EfiCpuIoWidthUint16, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
-}\r
-\r
-VOID\r
-PciWrite32 (\r
- UINT8 Segment,\r
- UINT8 Bus,\r
- UINT8 DevFunc,\r
- UINT8 Register,\r
- UINT32 Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Perform an four byte PCI config cycle write\r
- \r
-Arguments:\r
- Segment - PCI Segment ACPI _SEG\r
- Bus - PCI Bus\r
- DevFunc - PCI Device(7:3) and Func(2:0)\r
- Register - PCI config space register\r
- Data - Data to write\r
-\r
-Returns:\r
- NONE\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- UINT32 PciAddress;\r
- UINT32 PciAddress1;\r
-\r
- PciAddress = GetPciAddress (Segment, Bus, DevFunc, Register);\r
- //\r
- // Set bit 31 for PCI config access\r
- //\r
- PciAddress1 = PciAddress;\r
- PciAddress = ((PciAddress & 0xFFFFFFFC) | (0x80000000));\r
-\r
- Status = EfiIoWrite (EfiCpuIoWidthUint32, PCI_CONFIG_INDEX_PORT, 1, &PciAddress);\r
-\r
- if (EFI_ERROR (Status)) {\r
- return ;\r
- }\r
-\r
- EfiIoWrite (EfiCpuIoWidthUint32, (PCI_CONFIG_DATA_PORT + (PciAddress1 & 0x3)), 1, &Data);\r
-}\r
-//\r
-// Delay Primative\r
-//\r
-VOID\r
-EfiStall (\r
- IN UINTN Microseconds\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Delay for at least the request number of microseconds\r
- \r
-Arguments:\r
- Microseconds - Number of microseconds to delay.\r
-\r
-Returns:\r
- NONE\r
-\r
---*/\r
-{\r
- UINT8 Data;\r
- UINT8 InitialState;\r
- UINTN CycleIterations;\r
-\r
- CycleIterations = 0;\r
- Data = 0;\r
- InitialState = 0;\r
-\r
- if (EfiAtRuntime ()) {\r
- //\r
- // The time-source is 30 us granular, so calibrate the timing loop\r
- // based on this baseline\r
- // Error is possible 30us.\r
- //\r
- CycleIterations = (Microseconds - 1) / 30 + 1;\r
-\r
- //\r
- // Use the DMA Refresh timer in port 0x61. Cheap but effective.\r
- // The only issue is that the granularity is 30us, and we want to\r
- // guarantee "at least" one full transition to avoid races.\r
- //\r
- //\r
- // _____________/----------\__________/--------\r
- //\r
- // |<--15us-->|<--15us-->|\r
- //\r
- // --------------------------------------------------> Time (us)\r
- //\r
- while (CycleIterations--) {\r
- EfiIoRead (EfiCpuIoWidthUint8, 0x61, 1, &Data);\r
- Data &= REFRESH_CYCLE_TOGGLE_BIT;\r
- InitialState = Data;\r
-\r
- //\r
- // Capture first transition (strictly less than one period)\r
- //\r
- while (InitialState == Data) {\r
- EfiIoRead (EfiCpuIoWidthUint8, 0x61, 1, &Data);\r
- Data &= REFRESH_CYCLE_TOGGLE_BIT;\r
- }\r
-\r
- InitialState = Data;\r
- //\r
- // Capture next transition (guarantee at least one full pulse)\r
- //\r
- while (InitialState == Data) {\r
- EfiIoRead (EfiCpuIoWidthUint8, 0x61, 1, &Data);\r
- Data &= REFRESH_CYCLE_TOGGLE_BIT;\r
- }\r
- }\r
- } else {\r
- gBS->Stall (Microseconds);\r
- }\r
-}\r
+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2005 - 2008, 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
- RuntimeLib.c\r
-\r
-Abstract:\r
-\r
- Light weight lib to support Tiano drivers.\r
-\r
---*/\r
-\r
-#include "Tiano.h"\r
-#include "EfiRuntimeLib.h"\r
-#include EFI_PROTOCOL_DEFINITION (CpuIo)\r
-#include EFI_PROTOCOL_DEFINITION (FirmwareVolumeBlock)\r
-#include EFI_GUID_DEFINITION (StatusCodeCallerId)\r
-#include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)\r
-\r
-//\r
-// Driver Lib Module Globals\r
-//\r
-static EFI_RUNTIME_SERVICES *mRT;\r
-static EFI_EVENT mRuntimeNotifyEvent = NULL;\r
-static EFI_EVENT mEfiVirtualNotifyEvent = NULL;\r
-static BOOLEAN mRuntimeLibInitialized = FALSE;\r
-static BOOLEAN mEfiGoneVirtual = FALSE;\r
-\r
-//\r
-// Runtime Global, but you should use the Lib functions\r
-//\r
-EFI_CPU_IO_PROTOCOL *gCpuIo;\r
-BOOLEAN mEfiAtRuntime = FALSE;\r
-FVB_ENTRY *mFvbEntry;\r
-\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-static EFI_STATUS_CODE_PROTOCOL *gStatusCode = NULL;\r
-#endif\r
-\r
-EFI_STATUS\r
-EfiConvertPointer (\r
- IN UINTN DebugDisposition,\r
- IN OUT VOID *Address\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Determines the new virtual address that is to be used on subsequent memory accesses.\r
-\r
-Arguments:\r
-\r
- DebugDisposition - Supplies type information for the pointer being converted.\r
- Address - A pointer to a pointer that is to be fixed to be the value needed\r
- for the new virtual address mappings being applied.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->ConvertPointer (DebugDisposition, Address);\r
-}\r
-\r
-EFI_STATUS\r
-EfiConvertInternalPointer (\r
- IN OUT VOID *Address\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Call EfiConvertPointer() to convert internal pointer.\r
-\r
-Arguments:\r
-\r
- Address - A pointer to a pointer that is to be fixed to be the value needed\r
- for the new virtual address mappings being applied.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return EfiConvertPointer (EFI_INTERNAL_POINTER, Address);\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-EfiRuntimeLibFvbVirtualNotifyEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Convert all pointers in mFvbEntry after ExitBootServices.\r
-\r
-Arguments:\r
-\r
- Event - The Event that is being processed\r
- \r
- Context - Event Context\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- UINTN Index;\r
- if (mFvbEntry != NULL) {\r
- for (Index = 0; Index < MAX_FVB_COUNT; Index++) {\r
- if (NULL != mFvbEntry[Index].Fvb) {\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetBlockSize);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetPhysicalAddress);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->GetVolumeAttributes);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->SetVolumeAttributes);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Read);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->Write);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb->EraseBlocks);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].Fvb);\r
- }\r
-\r
- if (NULL != mFvbEntry[Index].FvbExtension) {\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension->EraseFvbCustomBlock);\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry[Index].FvbExtension);\r
- }\r
- }\r
-\r
- EfiConvertInternalPointer ((VOID **) &mFvbEntry);\r
- }\r
-}\r
-\r
-VOID\r
-EFIAPI\r
-RuntimeDriverExitBootServices (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Set AtRuntime flag as TRUE after ExitBootServices\r
-\r
-Arguments:\r
-\r
- Event - The Event that is being processed\r
- \r
- Context - Event Context\r
-\r
-Returns: \r
-\r
- None\r
-\r
---*/\r
-{\r
- mEfiAtRuntime = TRUE;\r
-}\r
-\r
-extern BOOLEAN gEfiFvbInitialized;\r
-\r
-VOID\r
-EFIAPI\r
-EfiRuntimeLibVirtualNotifyEvent (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Fixup internal data so that EFI can be call in virtual mode.\r
- Call the passed in Child Notify event and convert any pointers in \r
- lib to virtual mode.\r
-\r
-Arguments:\r
-\r
- Event - The Event that is being processed\r
- \r
- Context - Event Context\r
-\r
-Returns: \r
-\r
- None\r
-\r
---*/\r
-{\r
- EFI_EVENT_NOTIFY ChildNotifyEventHandler;\r
-\r
- if (Context != NULL) {\r
- ChildNotifyEventHandler = (EFI_EVENT_NOTIFY) (UINTN) Context;\r
- ChildNotifyEventHandler (Event, NULL);\r
- }\r
-\r
- if (gEfiFvbInitialized) {\r
- EfiRuntimeLibFvbVirtualNotifyEvent (Event, Context);\r
- }\r
- //\r
- // Update global for Runtime Services Table and IO\r
- //\r
- EfiConvertInternalPointer ((VOID **) &gCpuIo);\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
- if (gStatusCode != NULL) {\r
- EfiConvertInternalPointer ((VOID **) &gStatusCode->ReportStatusCode);\r
- EfiConvertInternalPointer ((VOID **) &gStatusCode);\r
- }\r
-#endif\r
- EfiConvertInternalPointer ((VOID **) &mRT);\r
-\r
- //\r
- // Clear out BootService globals\r
- //\r
- gBS = NULL;\r
- gST = NULL;\r
- mEfiGoneVirtual = TRUE;\r
-}\r
-\r
-EFI_STATUS\r
-EfiInitializeRuntimeDriverLib (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable,\r
- IN EFI_EVENT_NOTIFY GoVirtualChildEvent\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Intialize runtime Driver Lib if it has not yet been initialized. \r
-\r
-Arguments:\r
-\r
- ImageHandle - The firmware allocated handle for the EFI image.\r
- \r
- SystemTable - A pointer to the EFI System Table.\r
-\r
- GoVirtualChildEvent - Caller can register a virtual notification event.\r
-\r
-Returns: \r
-\r
- EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- if (mRuntimeLibInitialized) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
-\r
- mRuntimeLibInitialized = TRUE;\r
-\r
- gST = SystemTable;\r
- ASSERT (gST != NULL);\r
-\r
- gBS = SystemTable->BootServices;\r
- ASSERT (gBS != NULL);\r
- mRT = SystemTable->RuntimeServices;\r
- ASSERT (mRT != NULL);\r
-\r
- Status = EfiLibGetSystemConfigurationTable (&gEfiDxeServicesTableGuid, (VOID **) &gDS);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
- Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
- if (EFI_ERROR (Status)) {\r
- gStatusCode = NULL;\r
- }\r
-#endif\r
-\r
- Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (VOID **) &gCpuIo);\r
- if (EFI_ERROR (Status)) {\r
- gCpuIo = NULL;\r
- }\r
-\r
- //\r
- // Register our ExitBootServices () notify function\r
- //\r
- Status = gBS->CreateEvent (\r
- EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
- EFI_TPL_NOTIFY,\r
- RuntimeDriverExitBootServices,\r
- NULL,\r
- &mRuntimeNotifyEvent\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- //\r
- // Register SetVirtualAddressMap () notify function\r
- //\r
- Status = gBS->CreateEvent (\r
- EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,\r
- EFI_TPL_NOTIFY,\r
- EfiRuntimeLibVirtualNotifyEvent,\r
- (VOID *) (UINTN) GoVirtualChildEvent,\r
- &mEfiVirtualNotifyEvent\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EfiShutdownRuntimeDriverLib (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This routine will free some resources which have been allocated in\r
- EfiInitializeRuntimeDriverLib(). If a runtime driver exits with an error, \r
- it must call this routine to free the allocated resource before the exiting.\r
-\r
-Arguments:\r
-\r
- None\r
-\r
-Returns: \r
-\r
- EFI_SUCCESS - Shotdown the Runtime Driver Lib successfully\r
- EFI_UNSUPPORTED - Runtime Driver lib was not initialized at all\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- if (!mRuntimeLibInitialized) {\r
- //\r
- // You must call EfiInitializeRuntimeDriverLib() first\r
- //\r
- return EFI_UNSUPPORTED;\r
- }\r
-\r
- mRuntimeLibInitialized = FALSE;\r
-\r
- //\r
- // Close our ExitBootServices () notify function\r
- //\r
- if (mRuntimeNotifyEvent != NULL) {\r
- Status = gBS->CloseEvent (mRuntimeNotifyEvent);\r
- ASSERT_EFI_ERROR (Status);\r
- }\r
-\r
- //\r
- // Close SetVirtualAddressMap () notify function\r
- //\r
- if (mEfiVirtualNotifyEvent != NULL) {\r
- Status = gBS->CloseEvent (mEfiVirtualNotifyEvent);\r
- ASSERT_EFI_ERROR (Status);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-EfiInitializeSmmDriverLib (\r
- IN EFI_HANDLE ImageHandle,\r
- IN EFI_SYSTEM_TABLE *SystemTable\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Intialize runtime Driver Lib if it has not yet been initialized. \r
-\r
-Arguments:\r
-\r
- ImageHandle - The firmware allocated handle for the EFI image.\r
- \r
- SystemTable - A pointer to the EFI System Table.\r
-\r
-Returns: \r
-\r
- EFI_STATUS always returns EFI_SUCCESS except EFI_ALREADY_STARTED if already started.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
- if (mRuntimeLibInitialized) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
-\r
- mRuntimeLibInitialized = TRUE;\r
-\r
- gST = SystemTable;\r
- ASSERT (gST != NULL);\r
-\r
- gBS = SystemTable->BootServices;\r
- ASSERT (gBS != NULL);\r
- mRT = SystemTable->RuntimeServices;\r
- ASSERT (mRT != NULL);\r
-\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
- Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
- if (EFI_ERROR (Status)) {\r
- gStatusCode = NULL;\r
- }\r
-#endif\r
-\r
- Status = gBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, (VOID **) &gCpuIo);\r
- if (EFI_ERROR (Status)) {\r
- gCpuIo = NULL;\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-BOOLEAN\r
-EfiAtRuntime (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Return TRUE if ExitBootServices () has been called\r
-\r
-Arguments:\r
- NONE\r
-\r
-Returns: \r
- TRUE - If ExitBootServices () has been called\r
-\r
---*/\r
-{\r
- return mEfiAtRuntime;\r
-}\r
-\r
-BOOLEAN\r
-EfiGoneVirtual (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Return TRUE if SetVirtualAddressMap () has been called\r
-\r
-Arguments:\r
- NONE\r
-\r
-Returns: \r
- TRUE - If SetVirtualAddressMap () has been called\r
-\r
---*/\r
-{\r
- return mEfiGoneVirtual;\r
-}\r
-//\r
-// The following functions hide the mRT local global from the call to\r
-// runtime service in the EFI system table.\r
-//\r
-EFI_STATUS\r
-EfiGetTime (\r
- OUT EFI_TIME *Time,\r
- OUT EFI_TIME_CAPABILITIES *Capabilities\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the current time and date information, and the time-keeping \r
- capabilities of the hardware platform.\r
-\r
-Arguments:\r
-\r
- Time - A pointer to storage to receive a snapshot of the current time.\r
- Capabilities - An optional pointer to a buffer to receive the real time clock device's\r
- capabilities.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->GetTime (Time, Capabilities);\r
-}\r
-\r
-EFI_STATUS\r
-EfiSetTime (\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Sets the current local time and date information.\r
-\r
-Arguments:\r
-\r
- Time - A pointer to the current time.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->SetTime (Time);\r
-}\r
-\r
-EFI_STATUS\r
-EfiGetWakeupTime (\r
- OUT BOOLEAN *Enabled,\r
- OUT BOOLEAN *Pending,\r
- OUT EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the current wakeup alarm clock setting.\r
-\r
-Arguments:\r
-\r
- Enabled - Indicates if the alarm is currently enabled or disabled.\r
- Pending - Indicates if the alarm signal is pending and requires acknowledgement.\r
- Time - The current alarm setting.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->GetWakeupTime (Enabled, Pending, Time);\r
-}\r
-\r
-EFI_STATUS\r
-EfiSetWakeupTime (\r
- IN BOOLEAN Enable,\r
- IN EFI_TIME *Time\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Sets the system wakeup alarm clock time.\r
-\r
-Arguments:\r
-\r
- Enable - Enable or disable the wakeup alarm.\r
- Time - If Enable is TRUE, the time to set the wakeup alarm for.\r
- If Enable is FALSE, then this parameter is optional, and may be NULL.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->SetWakeupTime (Enable, Time);\r
-}\r
-\r
-EFI_STATUS\r
-EfiGetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID * VendorGuid,\r
- OUT UINT32 *Attributes OPTIONAL,\r
- IN OUT UINTN *DataSize,\r
- OUT VOID *Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the value of a variable.\r
-\r
-Arguments:\r
-\r
- VariableName - A Null-terminated Unicode string that is the name of the\r
- vendor's variable.\r
- VendorGuid - A unique identifier for the vendor.\r
- Attributes - If not NULL, a pointer to the memory location to return the\r
- attributes bitmask for the variable.\r
- DataSize - On input, the size in bytes of the return Data buffer.\r
- On output the size of data returned in Data.\r
- Data - The buffer to return the contents of the variable.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->GetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
-}\r
-\r
-EFI_STATUS\r
-EfiGetNextVariableName (\r
- IN OUT UINTN *VariableNameSize,\r
- IN OUT CHAR16 *VariableName,\r
- IN OUT EFI_GUID *VendorGuid\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Enumerates the current variable names.\r
-\r
-Arguments:\r
-\r
- VariableNameSize - The size of the VariableName buffer.\r
- VariableName - On input, supplies the last VariableName that was returned\r
- by GetNextVariableName(). \r
- On output, returns the Nullterminated Unicode string of the\r
- current variable.\r
- VendorGuid - On input, supplies the last VendorGuid that was returned by\r
- GetNextVariableName(). \r
- On output, returns the VendorGuid of the current variable.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->GetNextVariableName (VariableNameSize, VariableName, VendorGuid);\r
-}\r
-\r
-EFI_STATUS\r
-EfiSetVariable (\r
- IN CHAR16 *VariableName,\r
- IN EFI_GUID *VendorGuid,\r
- IN UINT32 Attributes,\r
- IN UINTN DataSize,\r
- IN VOID *Data\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Sets the value of a variable.\r
-\r
-Arguments:\r
-\r
- VariableName - A Null-terminated Unicode string that is the name of the\r
- vendor's variable.\r
- VendorGuid - A unique identifier for the vendor.\r
- Attributes - Attributes bitmask to set for the variable.\r
- DataSize - The size in bytes of the Data buffer.\r
- Data - The contents for the variable.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->SetVariable (VariableName, VendorGuid, Attributes, DataSize, Data);\r
-}\r
-\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
-\r
-EFI_STATUS\r
-EfiQueryVariableInfo (\r
- IN UINT32 Attributes,\r
- OUT UINT64 *MaximumVariableStorageSize,\r
- OUT UINT64 *RemainingVariableStorageSize,\r
- OUT UINT64 *MaximumVariableSize\r
- )\r
-\r
-/*++\r
-\r
-Routine Description:\r
-\r
- This code returns information about the EFI variables.\r
-\r
-Arguments:\r
-\r
- Attributes Attributes bitmask to specify the type of variables \r
- on which to return information.\r
- MaximumVariableStorageSize Pointer to the maximum size of the storage space available\r
- for the EFI variables associated with the attributes specified.\r
- RemainingVariableStorageSize Pointer to the remaining size of the storage space available \r
- for the EFI variables associated with the attributes specified.\r
- MaximumVariableSize Pointer to the maximum size of the individual EFI variables\r
- associated with the attributes specified.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->QueryVariableInfo (Attributes, MaximumVariableStorageSize, RemainingVariableStorageSize, MaximumVariableSize);\r
-}\r
-\r
-#endif\r
-\r
-\r
-EFI_STATUS\r
-EfiGetNextHighMonotonicCount (\r
- OUT UINT32 *HighCount\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Returns the next high 32 bits of the platform's monotonic counter.\r
-\r
-Arguments:\r
-\r
- HighCount - Pointer to returned value.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- return mRT->GetNextHighMonotonicCount (HighCount);\r
-}\r
-\r
-VOID\r
-EfiResetSystem (\r
- IN EFI_RESET_TYPE ResetType,\r
- IN EFI_STATUS ResetStatus,\r
- IN UINTN DataSize,\r
- IN CHAR16 *ResetData\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Resets the entire platform.\r
-\r
-Arguments:\r
-\r
- ResetType - The type of reset to perform.\r
- ResetStatus - The status code for the reset.\r
- DataSize - The size, in bytes, of ResetData.\r
- ResetData - A data buffer that includes a Null-terminated Unicode string, optionally\r
- followed by additional binary data.\r
-\r
-Returns:\r
-\r
- None\r
-\r
---*/\r
-{\r
- mRT->ResetSystem (ResetType, ResetStatus, DataSize, ResetData);\r
-}\r
-\r
-EFI_STATUS\r
-EfiReportStatusCode (\r
- IN EFI_STATUS_CODE_TYPE CodeType,\r
- IN EFI_STATUS_CODE_VALUE Value,\r
- IN UINT32 Instance,\r
- IN EFI_GUID * CallerId,\r
- IN EFI_STATUS_CODE_DATA * Data OPTIONAL\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Status Code reporter\r
-\r
-Arguments:\r
-\r
- CodeType - Type of Status Code.\r
- \r
- Value - Value to output for Status Code.\r
- \r
- Instance - Instance Number of this status code.\r
- \r
- CallerId - ID of the caller of this status code.\r
- \r
- Data - Optional data associated with this status code.\r
-\r
-Returns:\r
-\r
- Status code\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
-\r
-#if (EFI_SPECIFICATION_VERSION >= 0x00020000) \r
- if (gStatusCode == NULL) {\r
- if (EfiAtRuntime ()) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);\r
- if (EFI_ERROR (Status) || gStatusCode == NULL) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- }\r
- Status = gStatusCode->ReportStatusCode (CodeType, Value, Instance, CallerId, Data);\r
-#else\r
- if (mRT == NULL) {\r
- return EFI_UNSUPPORTED;\r
- }\r
- //\r
- // Check whether EFI_RUNTIME_SERVICES has Tiano Extension\r
- //\r
- Status = EFI_UNSUPPORTED;\r
- if (mRT->Hdr.Revision == EFI_SPECIFICATION_VERSION &&\r
- mRT->Hdr.HeaderSize == sizeof (EFI_RUNTIME_SERVICES) &&\r
- mRT->ReportStatusCode != NULL) {\r
- Status = mRT->ReportStatusCode (CodeType, Value, Instance, CallerId, Data);\r
- }\r
-#endif\r
- return Status;\r
-}\r
+++ /dev/null
-#------------------------------------------------------------------------------
-#
-# Copyright (c) 2008, Intel Corporation
-# All rights reserved. This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-# Module Name:
-#
-# RuntimeLibAsm.S
-#
-# Abstract:
-#
-#
-#------------------------------------------------------------------------------
-#include <EfiBind.h>
-
-.text
-
-.global ASM_PFX(EfiCpuFlushCache)
-#------------------------------------------------------------------------------
-#EFI_STATUS
-#EfiCpuFlushCache (
-# IN EFI_PHYSICAL_ADDRESS Start,
-# IN UINT64 Length
-# );
-#------------------------------------------------------------------------------
-
-ASM_PFX(EfiCpuFlushCache):
- wbinvd
- mov $0, %rax
- ret
-
+++ /dev/null
-;------------------------------------------------------------------------------\r
-;\r
-; Copyright (c) 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
-; RuntimeLibAsm.asm\r
-;\r
-; Abstract:\r
-;\r
-;\r
-;------------------------------------------------------------------------------\r
-\r
-.code\r
-\r
-;------------------------------------------------------------------------------\r
-;EFI_STATUS\r
-;EfiCpuFlushCache (\r
-; IN EFI_PHYSICAL_ADDRESS Start,\r
-; IN UINT64 Length\r
-; );\r
-;------------------------------------------------------------------------------\r
-\r
-EfiCpuFlushCache PROC PUBLIC\r
- wbinvd\r
- mov rax, 0\r
- ret\r
-EfiCpuFlushCache ENDP\r
-\r
-END
\ No newline at end of file