X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=FatPkg%2FFatPei%2FFatLiteApi.c;h=b71eaaab2a60051632a6429c8d6a15f8ba07a71a;hp=bf8158d94f01ea3f165664bdf8b42cd18e41b8e2;hb=e38f26a2f7f62b69fec2d84e83bcc4b45ddefdc1;hpb=2f4dfa84ac56d84935e086e91f292134b8074984
diff --git a/FatPkg/FatPei/FatLiteApi.c b/FatPkg/FatPei/FatLiteApi.c
index bf8158d94f..b71eaaab2a 100644
--- a/FatPkg/FatPei/FatLiteApi.c
+++ b/FatPkg/FatPei/FatLiteApi.c
@@ -1,7 +1,7 @@
/** @file
FAT recovery PEIM entry point, Ppi Functions and FAT Api functions.
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, 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
@@ -21,12 +21,12 @@ PEI_FAT_PRIVATE_DATA *mPrivateData = NULL;
BlockIo installation nofication function. Find out all the current BlockIO
PPIs in the system and add them into private data. Assume there is
- @param PeiServices General purpose services available to every
- PEIM.
- @param NotifyDescriptor The typedef structure of the notification
- descriptor. Not used in this function.
- @param Ppi The typedef structure of the PPI descriptor.
- Not used in this function.
+ @param PeiServices General purpose services available to every
+ PEIM.
+ @param NotifyDescriptor The typedef structure of the notification
+ descriptor. Not used in this function.
+ @param Ppi The typedef structure of the PPI descriptor.
+ Not used in this function.
@retval EFI_SUCCESS The function completed successfully.
@@ -43,29 +43,34 @@ BlockIoNotifyEntry (
/**
Discover all the block I/O devices to find the FAT volume.
- @param PrivateData Global memory map for accessing global
- variables.
+ @param PrivateData Global memory map for accessing global
+ variables.
+ @param BlockIo2 Boolean to show whether using BlockIo2 or BlockIo
@retval EFI_SUCCESS The function completed successfully.
**/
EFI_STATUS
UpdateBlocksAndVolumes (
- IN OUT PEI_FAT_PRIVATE_DATA *PrivateData
+ IN OUT PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN BOOLEAN BlockIo2
)
{
- EFI_STATUS Status;
- EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
- UINTN BlockIoPpiInstance;
- EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
- UINTN NumberBlockDevices;
- UINTN Index;
- EFI_PEI_BLOCK_IO_MEDIA Media;
- PEI_FAT_VOLUME Volume;
- EFI_PEI_SERVICES **PeiServices;
+ EFI_STATUS Status;
+ EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
+ UINTN BlockIoPpiInstance;
+ EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
+ EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi;
+ UINTN NumberBlockDevices;
+ UINTN Index;
+ EFI_PEI_BLOCK_IO_MEDIA Media;
+ EFI_PEI_BLOCK_IO2_MEDIA Media2;
+ PEI_FAT_VOLUME Volume;
+ EFI_PEI_SERVICES **PeiServices;
PeiServices = (EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
-
+ BlockIo2Ppi = NULL;
+ BlockIoPpi = NULL;
//
// Clean up caches
//
@@ -80,12 +85,21 @@ UpdateBlocksAndVolumes (
// Assuming all device Block Io Peims are dispatched already
//
for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_FAT_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
- Status = PeiServicesLocatePpi (
- &gEfiPeiVirtualBlockIoPpiGuid,
- BlockIoPpiInstance,
- &TempPpiDescriptor,
- (VOID **) &BlockIoPpi
- );
+ if (BlockIo2) {
+ Status = PeiServicesLocatePpi (
+ &gEfiPeiVirtualBlockIo2PpiGuid,
+ BlockIoPpiInstance,
+ &TempPpiDescriptor,
+ (VOID **) &BlockIo2Ppi
+ );
+ } else {
+ Status = PeiServicesLocatePpi (
+ &gEfiPeiVirtualBlockIoPpiGuid,
+ BlockIoPpiInstance,
+ &TempPpiDescriptor,
+ (VOID **) &BlockIoPpi
+ );
+ }
if (EFI_ERROR (Status)) {
//
// Done with all Block Io Ppis
@@ -93,40 +107,63 @@ UpdateBlocksAndVolumes (
break;
}
- Status = BlockIoPpi->GetNumberOfBlockDevices (
- PeiServices,
- BlockIoPpi,
- &NumberBlockDevices
- );
+ if (BlockIo2) {
+ Status = BlockIo2Ppi->GetNumberOfBlockDevices (
+ PeiServices,
+ BlockIo2Ppi,
+ &NumberBlockDevices
+ );
+ } else {
+ Status = BlockIoPpi->GetNumberOfBlockDevices (
+ PeiServices,
+ BlockIoPpi,
+ &NumberBlockDevices
+ );
+ }
if (EFI_ERROR (Status)) {
continue;
}
for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) {
- Status = BlockIoPpi->GetBlockDeviceMediaInfo (
- PeiServices,
- BlockIoPpi,
- Index,
- &Media
- );
- if (EFI_ERROR (Status) || !Media.MediaPresent) {
- continue;
+ if (BlockIo2) {
+ Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
+ PeiServices,
+ BlockIo2Ppi,
+ Index,
+ &Media2
+ );
+ if (EFI_ERROR (Status) || !Media2.MediaPresent) {
+ continue;
+ }
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = Media2.BlockSize;
+ } else {
+ Status = BlockIoPpi->GetBlockDeviceMediaInfo (
+ PeiServices,
+ BlockIoPpi,
+ Index,
+ &Media
+ );
+ if (EFI_ERROR (Status) || !Media.MediaPresent) {
+ continue;
+ }
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32) Media.BlockSize;
}
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32) Media.BlockSize;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
//
// Not used here
//
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8) Index;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
-
PrivateData->BlockDeviceCount++;
}
}
@@ -166,12 +203,12 @@ UpdateBlocksAndVolumes (
BlockIo installation notification function. Find out all the current BlockIO
PPIs in the system and add them into private data. Assume there is
- @param PeiServices General purpose services available to every
- PEIM.
- @param NotifyDescriptor The typedef structure of the notification
- descriptor. Not used in this function.
- @param Ppi The typedef structure of the PPI descriptor.
- Not used in this function.
+ @param PeiServices General purpose services available to every
+ PEIM.
+ @param NotifyDescriptor The typedef structure of the notification
+ descriptor. Not used in this function.
+ @param Ppi The typedef structure of the PPI descriptor.
+ Not used in this function.
@retval EFI_SUCCESS The function completed successfully.
@@ -184,8 +221,11 @@ BlockIoNotifyEntry (
IN VOID *Ppi
)
{
- UpdateBlocksAndVolumes (mPrivateData);
-
+ if (CompareGuid (NotifyDescriptor->Guid, &gEfiPeiVirtualBlockIo2PpiGuid)) {
+ UpdateBlocksAndVolumes (mPrivateData, TRUE);
+ } else {
+ UpdateBlocksAndVolumes (mPrivateData, FALSE);
+ }
return EFI_SUCCESS;
}
@@ -194,13 +234,13 @@ BlockIoNotifyEntry (
Installs the Device Recovery Module PPI, Initialize BlockIo Ppi
installation notification
- @param FileHandle Handle of the file being invoked. Type
- EFI_PEI_FILE_HANDLE is defined in
- FfsFindNextFile().
- @param PeiServices Describes the list of possible PEI Services.
+ @param FileHandle Handle of the file being invoked. Type
+ EFI_PEI_FILE_HANDLE is defined in
+ FfsFindNextFile().
+ @param PeiServices Describes the list of possible PEI Services.
- @retval EFI_SUCCESS The entry point was executed successfully.
- @retval EFI_OUT_OF_RESOURCES There is no enough memory to complete the
+ @retval EFI_SUCCESS The entry point was executed successfully.
+ @retval EFI_OUT_OF_RESOURCES There is no enough memory to complete the
operations.
**/
@@ -247,7 +287,7 @@ FatPeimEntry (
PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
- PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
+ PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
Status = PeiServicesInstallPpi (&PrivateData->PpiDescriptor);
if (EFI_ERROR (Status)) {
@@ -258,7 +298,8 @@ FatPeimEntry (
//
PrivateData->BlockDeviceCount = 0;
- UpdateBlocksAndVolumes (PrivateData);
+ UpdateBlocksAndVolumes (PrivateData, TRUE);
+ UpdateBlocksAndVolumes (PrivateData, FALSE);
//
// PrivateData is allocated now, set it to the module variable
@@ -268,14 +309,20 @@ FatPeimEntry (
//
// Installs Block Io Ppi notification function
//
- PrivateData->NotifyDescriptor.Flags =
+ PrivateData->NotifyDescriptor[0].Flags =
+ (
+ EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
+ );
+ PrivateData->NotifyDescriptor[0].Guid = &gEfiPeiVirtualBlockIoPpiGuid;
+ PrivateData->NotifyDescriptor[0].Notify = BlockIoNotifyEntry;
+ PrivateData->NotifyDescriptor[1].Flags =
(
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
- PrivateData->NotifyDescriptor.Guid = &gEfiPeiVirtualBlockIoPpiGuid;
- PrivateData->NotifyDescriptor.Notify = BlockIoNotifyEntry;
- return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor);
+ PrivateData->NotifyDescriptor[1].Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
+ PrivateData->NotifyDescriptor[1].Notify = BlockIoNotifyEntry;
+ return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
}
@@ -283,18 +330,18 @@ FatPeimEntry (
Returns the number of DXE capsules residing on the device.
This function searches for DXE capsules from the associated device and returns
- the number and maximum size in bytes of the capsules discovered. Entry 1 is
- assumed to be the highest load priority and entry N is assumed to be the lowest
+ the number and maximum size in bytes of the capsules discovered. Entry 1 is
+ assumed to be the highest load priority and entry N is assumed to be the lowest
priority.
- @param[in] PeiServices General-purpose services that are available
+ @param[in] PeiServices General-purpose services that are available
to every PEIM
@param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
instance.
- @param[out] NumberRecoveryCapsules Pointer to a caller-allocated UINTN. On
- output, *NumberRecoveryCapsules contains
- the number of recovery capsule images
- available for retrieval from this PEIM
+ @param[out] NumberRecoveryCapsules Pointer to a caller-allocated UINTN. On
+ output, *NumberRecoveryCapsules contains
+ the number of recovery capsule images
+ available for retrieval from this PEIM
instance.
@retval EFI_SUCCESS One or more capsules were discovered.
@@ -323,7 +370,7 @@ GetNumberRecoveryCapsules (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, PEI_FAT_RECOVERY_CAPSULE_WITHOUT_NT_EMULATOR, &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
@@ -347,18 +394,18 @@ GetNumberRecoveryCapsules (
This function gets the size and type of the capsule specified by CapsuleInstance.
@param[in] PeiServices General-purpose services that are available to every PEIM
- @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
+ @param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
instance.
- @param[in] CapsuleInstance Specifies for which capsule instance to retrieve
- the information. This parameter must be between
- one and the value returned by GetNumberRecoveryCapsules()
+ @param[in] CapsuleInstance Specifies for which capsule instance to retrieve
+ the information. This parameter must be between
+ one and the value returned by GetNumberRecoveryCapsules()
in NumberRecoveryCapsules.
- @param[out] Size A pointer to a caller-allocated UINTN in which
- the size of the requested recovery module is
+ @param[out] Size A pointer to a caller-allocated UINTN in which
+ the size of the requested recovery module is
returned.
- @param[out] CapsuleType A pointer to a caller-allocated EFI_GUID in which
- the type of the requested recovery capsule is
- returned. The semantic meaning of the value
+ @param[out] CapsuleType A pointer to a caller-allocated EFI_GUID in which
+ the type of the requested recovery capsule is
+ returned. The semantic meaning of the value
returned is defined by the implementation.
@retval EFI_SUCCESS One or more capsules were discovered.
@@ -405,7 +452,7 @@ GetRecoveryCapsuleInfo (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, PEI_FAT_RECOVERY_CAPSULE_WITHOUT_NT_EMULATOR, &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
@@ -428,22 +475,42 @@ GetRecoveryCapsuleInfo (
// Fill in the Capsule Type GUID according to the block device type
//
if (BlockDeviceNo < PrivateData->BlockDeviceCount) {
- switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
- case LegacyFloppy:
- CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
- break;
-
- case IdeCDROM:
- case IdeLS120:
- CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
- break;
-
- case UsbMassStorage:
- CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
- break;
-
- default:
- break;
+ if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo2 != NULL) {
+ switch (PrivateData->BlockDevice[BlockDeviceNo].InterfaceType) {
+ case MSG_ATAPI_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
+ break;
+
+ case MSG_USB_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
+ break;
+
+ case MSG_NVME_NAMESPACE_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatNvmeDiskGuid);
+ break;
+
+ default:
+ break;
+ }
+ }
+ if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
+ switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
+ case LegacyFloppy:
+ CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
+ break;
+
+ case IdeCDROM:
+ case IdeLS120:
+ CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
+ break;
+
+ case UsbMassStorage:
+ CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
+ break;
+
+ default:
+ break;
+ }
}
}
@@ -463,12 +530,12 @@ GetRecoveryCapsuleInfo (
This function, by whatever mechanism, retrieves a DXE capsule from some device
and loads it into memory. Note that the published interface is device neutral.
- @param[in] PeiServices General-purpose services that are available
+ @param[in] PeiServices General-purpose services that are available
to every PEIM
@param[in] This Indicates the EFI_PEI_DEVICE_RECOVERY_MODULE_PPI
instance.
@param[in] CapsuleInstance Specifies which capsule instance to retrieve.
- @param[out] Buffer Specifies a caller-allocated buffer in which
+ @param[out] Buffer Specifies a caller-allocated buffer in which
the requested recovery capsule will be returned.
@retval EFI_SUCCESS The capsule was loaded correctly.
@@ -513,7 +580,7 @@ LoadRecoveryCapsule (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, PEI_FAT_RECOVERY_CAPSULE_WITHOUT_NT_EMULATOR, &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
@@ -541,16 +608,16 @@ LoadRecoveryCapsule (
This function finds the the recovery file named FileName on a specified FAT volume and returns
its FileHandle pointer.
- @param PrivateData Global memory map for accessing global
- variables.
- @param VolumeIndex The index of the volume.
- @param FileName The recovery file name to find.
- @param Handle The output file handle.
+ @param PrivateData Global memory map for accessing global
+ variables.
+ @param VolumeIndex The index of the volume.
+ @param FileName The recovery file name to find.
+ @param Handle The output file handle.
- @retval EFI_DEVICE_ERROR Some error occured when operating the FAT
- volume.
- @retval EFI_NOT_FOUND The recovery file was not found.
- @retval EFI_SUCCESS The recovery file was successfully found on the
+ @retval EFI_DEVICE_ERROR Some error occured when operating the FAT
+ volume.
+ @retval EFI_NOT_FOUND The recovery file was not found.
+ @retval EFI_SUCCESS The recovery file was successfully found on the
FAT volume.
**/
@@ -577,6 +644,7 @@ FindRecoveryFile (
//
// Construct root directory file
//
+ ZeroMem (&Parent, sizeof (PEI_FAT_FILE));
Parent.IsFixedRootDir = (BOOLEAN) ((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
Parent.Attributes = FAT_ATTR_DIRECTORY;
Parent.CurrentPos = 0;
@@ -593,6 +661,9 @@ FindRecoveryFile (
//
Status = FatReadNextDirectoryEntry (PrivateData, &Parent, File);
while (Status == EFI_SUCCESS) {
+ //
+ // Compare whether the file name is recovery file name.
+ //
if (EngStriColl (PrivateData, FileName, File->FileName)) {
break;
}
@@ -604,6 +675,13 @@ FindRecoveryFile (
return EFI_NOT_FOUND;
}
+ //
+ // Get the recovery file, set its file position to 0.
+ //
+ if (File->StartingCluster != 0) {
+ Status = FatSetFilePos (PrivateData, File, 0);
+ }
+
*Handle = File;
return EFI_SUCCESS;