summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/Disk/RamDiskDxe
diff options
context:
space:
mode:
authorkx <kx@radix.pro>2024-06-04 06:43:08 +0300
committerkx <kx@radix.pro>2024-06-04 06:43:08 +0300
commit7e2ccccace24636f29ddc210b94606abd4c7e42b (patch)
tree545d43ea12671048956cafeb12303e84d601e571 /MdeModulePkg/Universal/Disk/RamDiskDxe
parent27b044605cd5f6b33a3d231576003850b3fe305b (diff)
downloadedk2-trunk.tar.xz
Renormalized end-of-lines from master@27b044605cd5f6b33a3d231576003850b3fe305btrunk
Diffstat (limited to 'MdeModulePkg/Universal/Disk/RamDiskDxe')
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDisk.asl76
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c960
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c484
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf168
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.uni28
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c212
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHii.vfr188
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHiiStrings.uni82
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c1514
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h1204
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskNVData.h88
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c1730
12 files changed, 3367 insertions, 3367 deletions
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDisk.asl b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDisk.asl
index 9615aaa66b..2213204b08 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDisk.asl
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDisk.asl
@@ -1,38 +1,38 @@
-/** @file
- The definition block in ACPI table for NVDIMM root device.
-
-Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-DefinitionBlock (
- "RamDisk.aml",
- "SSDT",
- 2,
- "INTEL ",
- "RamDisk ",
- 0x1000
- )
-{
- Scope (\_SB)
- {
- Device (NVDR)
- {
- //
- // Define _HID, "ACPI0012" NVDIMM Root Device
- //
- Name (_HID, "ACPI0012")
-
- //
- // Readable name of this device
- //
- Name (_STR, Unicode ("NVDIMM Root Device"))
-
- Method (_STA, 0)
- {
- Return (0x0f)
- }
- }
- }
-}
+/** @file
+ The definition block in ACPI table for NVDIMM root device.
+
+Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+DefinitionBlock (
+ "RamDisk.aml",
+ "SSDT",
+ 2,
+ "INTEL ",
+ "RamDisk ",
+ 0x1000
+ )
+{
+ Scope (\_SB)
+ {
+ Device (NVDR)
+ {
+ //
+ // Define _HID, "ACPI0012" NVDIMM Root Device
+ //
+ Name (_HID, "ACPI0012")
+
+ //
+ // Readable name of this device
+ //
+ Name (_STR, Unicode ("NVDIMM Root Device"))
+
+ Method (_STA, 0)
+ {
+ Return (0x0f)
+ }
+ }
+ }
+}
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c
index 4fbbb1f3b4..054d7ca9d1 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskBlockIo.c
@@ -1,480 +1,480 @@
-/** @file
- Produce EFI_BLOCK_IO_PROTOCOL on a RAM disk device.
-
- Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "RamDiskImpl.h"
-
-//
-// The EFI_BLOCK_IO_PROTOCOL instances that is installed onto the handle
-// for newly registered RAM disks
-//
-EFI_BLOCK_IO_PROTOCOL mRamDiskBlockIoTemplate = {
- EFI_BLOCK_IO_PROTOCOL_REVISION,
- (EFI_BLOCK_IO_MEDIA *)0,
- RamDiskBlkIoReset,
- RamDiskBlkIoReadBlocks,
- RamDiskBlkIoWriteBlocks,
- RamDiskBlkIoFlushBlocks
-};
-
-//
-// The EFI_BLOCK_IO_PROTOCOL2 instances that is installed onto the handle
-// for newly registered RAM disks
-//
-EFI_BLOCK_IO2_PROTOCOL mRamDiskBlockIo2Template = {
- (EFI_BLOCK_IO_MEDIA *)0,
- RamDiskBlkIo2Reset,
- RamDiskBlkIo2ReadBlocksEx,
- RamDiskBlkIo2WriteBlocksEx,
- RamDiskBlkIo2FlushBlocksEx
-};
-
-/**
- Initialize the BlockIO & BlockIO2 protocol of a RAM disk device.
-
- @param[in] PrivateData Points to RAM disk private data.
-
-**/
-VOID
-RamDiskInitBlockIo (
- IN RAM_DISK_PRIVATE_DATA *PrivateData
- )
-{
- EFI_BLOCK_IO_PROTOCOL *BlockIo;
- EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
- EFI_BLOCK_IO_MEDIA *Media;
- UINT32 Remainder;
-
- BlockIo = &PrivateData->BlockIo;
- BlockIo2 = &PrivateData->BlockIo2;
- Media = &PrivateData->Media;
-
- CopyMem (BlockIo, &mRamDiskBlockIoTemplate, sizeof (EFI_BLOCK_IO_PROTOCOL));
- CopyMem (BlockIo2, &mRamDiskBlockIo2Template, sizeof (EFI_BLOCK_IO2_PROTOCOL));
-
- BlockIo->Media = Media;
- BlockIo2->Media = Media;
- Media->RemovableMedia = FALSE;
- Media->MediaPresent = TRUE;
- Media->LogicalPartition = FALSE;
- Media->ReadOnly = FALSE;
- Media->WriteCaching = FALSE;
-
- for (Media->BlockSize = RAM_DISK_DEFAULT_BLOCK_SIZE;
- Media->BlockSize >= 1;
- Media->BlockSize = Media->BlockSize >> 1)
- {
- Media->LastBlock = DivU64x32Remainder (PrivateData->Size, Media->BlockSize, &Remainder) - 1;
- if (Remainder == 0) {
- break;
- }
- }
-
- ASSERT (Media->BlockSize != 0);
-
- return;
-}
-
-/**
- Reset the Block Device.
-
- @param This Indicates a pointer to the calling context.
- @param ExtendedVerification Driver may perform diagnostics on reset.
-
- @retval EFI_SUCCESS The device was reset.
- @retval EFI_DEVICE_ERROR The device is not functioning properly and could
- not be reset.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoReset (
- IN EFI_BLOCK_IO_PROTOCOL *This,
- IN BOOLEAN ExtendedVerification
- )
-{
- return EFI_SUCCESS;
-}
-
-/**
- Read BufferSize bytes from Lba into Buffer.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId Id of the media, changes every time the media is
- replaced.
- @param[in] Lba The starting Logical Block Address to read from.
- @param[in] BufferSize Size of Buffer, must be a multiple of device block
- size.
- @param[out] Buffer A pointer to the destination buffer for the data.
- The caller is responsible for either having
- implicit or explicit ownership of the buffer.
-
- @retval EFI_SUCCESS The data was read correctly from the device.
- @retval EFI_DEVICE_ERROR The device reported an error while performing
- the read.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
- device.
- @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
- size of the device.
- @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
- valid, or the buffer is not on proper alignment.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoReadBlocks (
- IN EFI_BLOCK_IO_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- )
-{
- RAM_DISK_PRIVATE_DATA *PrivateData;
- UINTN NumberOfBlocks;
-
- PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This);
-
- if (MediaId != PrivateData->Media.MediaId) {
- return EFI_MEDIA_CHANGED;
- }
-
- if (Buffer == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (BufferSize == 0) {
- return EFI_SUCCESS;
- }
-
- if ((BufferSize % PrivateData->Media.BlockSize) != 0) {
- return EFI_BAD_BUFFER_SIZE;
- }
-
- if (Lba > PrivateData->Media.LastBlock) {
- return EFI_INVALID_PARAMETER;
- }
-
- NumberOfBlocks = BufferSize / PrivateData->Media.BlockSize;
- if ((Lba + NumberOfBlocks - 1) > PrivateData->Media.LastBlock) {
- return EFI_INVALID_PARAMETER;
- }
-
- CopyMem (
- Buffer,
- (VOID *)(UINTN)(PrivateData->StartingAddr + MultU64x32 (Lba, PrivateData->Media.BlockSize)),
- BufferSize
- );
-
- return EFI_SUCCESS;
-}
-
-/**
- Write BufferSize bytes from Lba into Buffer.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId The media ID that the write request is for.
- @param[in] Lba The starting logical block address to be written.
- The caller is responsible for writing to only
- legitimate locations.
- @param[in] BufferSize Size of Buffer, must be a multiple of device block
- size.
- @param[in] Buffer A pointer to the source buffer for the data.
-
- @retval EFI_SUCCESS The data was written correctly to the device.
- @retval EFI_WRITE_PROTECTED The device can not be written to.
- @retval EFI_DEVICE_ERROR The device reported an error while performing
- the write.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
- device.
- @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
- size of the device.
- @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
- valid, or the buffer is not on proper alignment.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoWriteBlocks (
- IN EFI_BLOCK_IO_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN UINTN BufferSize,
- IN VOID *Buffer
- )
-{
- RAM_DISK_PRIVATE_DATA *PrivateData;
- UINTN NumberOfBlocks;
-
- PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This);
-
- if (MediaId != PrivateData->Media.MediaId) {
- return EFI_MEDIA_CHANGED;
- }
-
- if (TRUE == PrivateData->Media.ReadOnly) {
- return EFI_WRITE_PROTECTED;
- }
-
- if (Buffer == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (BufferSize == 0) {
- return EFI_SUCCESS;
- }
-
- if ((BufferSize % PrivateData->Media.BlockSize) != 0) {
- return EFI_BAD_BUFFER_SIZE;
- }
-
- if (Lba > PrivateData->Media.LastBlock) {
- return EFI_INVALID_PARAMETER;
- }
-
- NumberOfBlocks = BufferSize / PrivateData->Media.BlockSize;
- if ((Lba + NumberOfBlocks - 1) > PrivateData->Media.LastBlock) {
- return EFI_INVALID_PARAMETER;
- }
-
- CopyMem (
- (VOID *)(UINTN)(PrivateData->StartingAddr + MultU64x32 (Lba, PrivateData->Media.BlockSize)),
- Buffer,
- BufferSize
- );
-
- return EFI_SUCCESS;
-}
-
-/**
- Flush the Block Device.
-
- @param[in] This Indicates a pointer to the calling context.
-
- @retval EFI_SUCCESS All outstanding data was written to the device.
- @retval EFI_DEVICE_ERROR The device reported an error while writting
- back the data
- @retval EFI_NO_MEDIA There is no media in the device.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoFlushBlocks (
- IN EFI_BLOCK_IO_PROTOCOL *This
- )
-{
- return EFI_SUCCESS;
-}
-
-/**
- Resets the block device hardware.
-
- @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
- @param[in] ExtendedVerification The flag about if extend verificate.
-
- @retval EFI_SUCCESS The device was reset.
- @retval EFI_DEVICE_ERROR The block device is not functioning correctly
- and could not be reset.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2Reset (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN BOOLEAN ExtendedVerification
- )
-{
- return EFI_SUCCESS;
-}
-
-/**
- Reads the requested number of blocks from the device.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId The media ID that the read request is for.
- @param[in] Lba The starting logical block address to read
- from on the device.
- @param[in, out] Token A pointer to the token associated with the
- transaction.
- @param[in] BufferSize The size of the Buffer in bytes. This must be
- a multiple of the intrinsic block size of the
- device.
- @param[out] Buffer A pointer to the destination buffer for the
- data. The caller is responsible for either
- having implicit or explicit ownership of the
- buffer.
-
- @retval EFI_SUCCESS The read request was queued if Token->Event
- is not NULL. The data was read correctly from
- the device if the Token->Event is NULL.
- @retval EFI_DEVICE_ERROR The device reported an error while attempting
- to perform the read operation.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
- @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
- the intrinsic block size of the device.
- @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
- valid, or the buffer is not on proper
- alignment.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2ReadBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- )
-{
- RAM_DISK_PRIVATE_DATA *PrivateData;
- EFI_STATUS Status;
-
- PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);
-
- Status = RamDiskBlkIoReadBlocks (
- &PrivateData->BlockIo,
- MediaId,
- Lba,
- BufferSize,
- Buffer
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // If caller's event is given, signal it after the memory read completes.
- //
- if ((Token != NULL) && (Token->Event != NULL)) {
- Token->TransactionStatus = EFI_SUCCESS;
- gBS->SignalEvent (Token->Event);
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Writes a specified number of blocks to the device.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId The media ID that the write request is for.
- @param[in] Lba The starting logical block address to be
- written. The caller is responsible for
- writing to only legitimate locations.
- @param[in, out] Token A pointer to the token associated with the
- transaction.
- @param[in] BufferSize The size in bytes of Buffer. This must be a
- multiple of the intrinsic block size of the
- device.
- @param[in] Buffer A pointer to the source buffer for the data.
-
- @retval EFI_SUCCESS The write request was queued if Event is not
- NULL. The data was written correctly to the
- device if the Event is NULL.
- @retval EFI_WRITE_PROTECTED The device cannot be written to.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
- @retval EFI_DEVICE_ERROR The device reported an error while attempting
- to perform the write operation.
- @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
- the intrinsic block size of the device.
- @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
- valid, or the buffer is not on proper
- alignment.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2WriteBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token,
- IN UINTN BufferSize,
- IN VOID *Buffer
- )
-{
- RAM_DISK_PRIVATE_DATA *PrivateData;
- EFI_STATUS Status;
-
- PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);
-
- Status = RamDiskBlkIoWriteBlocks (
- &PrivateData->BlockIo,
- MediaId,
- Lba,
- BufferSize,
- Buffer
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // If caller's event is given, signal it after the memory write completes.
- //
- if ((Token != NULL) && (Token->Event != NULL)) {
- Token->TransactionStatus = EFI_SUCCESS;
- gBS->SignalEvent (Token->Event);
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Flushes all modified data to a physical block device.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in, out] Token A pointer to the token associated with the
- transaction.
-
- @retval EFI_SUCCESS The flush request was queued if Event is not
- NULL. All outstanding data was written
- correctly to the device if the Event is NULL.
- @retval EFI_DEVICE_ERROR The device reported an error while attempting
- to write data.
- @retval EFI_WRITE_PROTECTED The device cannot be written to.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2FlushBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token
- )
-{
- RAM_DISK_PRIVATE_DATA *PrivateData;
-
- PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);
-
- if (TRUE == PrivateData->Media.ReadOnly) {
- return EFI_WRITE_PROTECTED;
- }
-
- //
- // If caller's event is given, signal it directly.
- //
- if ((Token != NULL) && (Token->Event != NULL)) {
- Token->TransactionStatus = EFI_SUCCESS;
- gBS->SignalEvent (Token->Event);
- }
-
- return EFI_SUCCESS;
-}
+/** @file
+ Produce EFI_BLOCK_IO_PROTOCOL on a RAM disk device.
+
+ Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "RamDiskImpl.h"
+
+//
+// The EFI_BLOCK_IO_PROTOCOL instances that is installed onto the handle
+// for newly registered RAM disks
+//
+EFI_BLOCK_IO_PROTOCOL mRamDiskBlockIoTemplate = {
+ EFI_BLOCK_IO_PROTOCOL_REVISION,
+ (EFI_BLOCK_IO_MEDIA *)0,
+ RamDiskBlkIoReset,
+ RamDiskBlkIoReadBlocks,
+ RamDiskBlkIoWriteBlocks,
+ RamDiskBlkIoFlushBlocks
+};
+
+//
+// The EFI_BLOCK_IO_PROTOCOL2 instances that is installed onto the handle
+// for newly registered RAM disks
+//
+EFI_BLOCK_IO2_PROTOCOL mRamDiskBlockIo2Template = {
+ (EFI_BLOCK_IO_MEDIA *)0,
+ RamDiskBlkIo2Reset,
+ RamDiskBlkIo2ReadBlocksEx,
+ RamDiskBlkIo2WriteBlocksEx,
+ RamDiskBlkIo2FlushBlocksEx
+};
+
+/**
+ Initialize the BlockIO & BlockIO2 protocol of a RAM disk device.
+
+ @param[in] PrivateData Points to RAM disk private data.
+
+**/
+VOID
+RamDiskInitBlockIo (
+ IN RAM_DISK_PRIVATE_DATA *PrivateData
+ )
+{
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
+ EFI_BLOCK_IO_MEDIA *Media;
+ UINT32 Remainder;
+
+ BlockIo = &PrivateData->BlockIo;
+ BlockIo2 = &PrivateData->BlockIo2;
+ Media = &PrivateData->Media;
+
+ CopyMem (BlockIo, &mRamDiskBlockIoTemplate, sizeof (EFI_BLOCK_IO_PROTOCOL));
+ CopyMem (BlockIo2, &mRamDiskBlockIo2Template, sizeof (EFI_BLOCK_IO2_PROTOCOL));
+
+ BlockIo->Media = Media;
+ BlockIo2->Media = Media;
+ Media->RemovableMedia = FALSE;
+ Media->MediaPresent = TRUE;
+ Media->LogicalPartition = FALSE;
+ Media->ReadOnly = FALSE;
+ Media->WriteCaching = FALSE;
+
+ for (Media->BlockSize = RAM_DISK_DEFAULT_BLOCK_SIZE;
+ Media->BlockSize >= 1;
+ Media->BlockSize = Media->BlockSize >> 1)
+ {
+ Media->LastBlock = DivU64x32Remainder (PrivateData->Size, Media->BlockSize, &Remainder) - 1;
+ if (Remainder == 0) {
+ break;
+ }
+ }
+
+ ASSERT (Media->BlockSize != 0);
+
+ return;
+}
+
+/**
+ Reset the Block Device.
+
+ @param This Indicates a pointer to the calling context.
+ @param ExtendedVerification Driver may perform diagnostics on reset.
+
+ @retval EFI_SUCCESS The device was reset.
+ @retval EFI_DEVICE_ERROR The device is not functioning properly and could
+ not be reset.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoReset (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ )
+{
+ return EFI_SUCCESS;
+}
+
+/**
+ Read BufferSize bytes from Lba into Buffer.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId Id of the media, changes every time the media is
+ replaced.
+ @param[in] Lba The starting Logical Block Address to read from.
+ @param[in] BufferSize Size of Buffer, must be a multiple of device block
+ size.
+ @param[out] Buffer A pointer to the destination buffer for the data.
+ The caller is responsible for either having
+ implicit or explicit ownership of the buffer.
+
+ @retval EFI_SUCCESS The data was read correctly from the device.
+ @retval EFI_DEVICE_ERROR The device reported an error while performing
+ the read.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
+ device.
+ @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
+ size of the device.
+ @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
+ valid, or the buffer is not on proper alignment.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoReadBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ UINTN NumberOfBlocks;
+
+ PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This);
+
+ if (MediaId != PrivateData->Media.MediaId) {
+ return EFI_MEDIA_CHANGED;
+ }
+
+ if (Buffer == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (BufferSize == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if ((BufferSize % PrivateData->Media.BlockSize) != 0) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ if (Lba > PrivateData->Media.LastBlock) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ NumberOfBlocks = BufferSize / PrivateData->Media.BlockSize;
+ if ((Lba + NumberOfBlocks - 1) > PrivateData->Media.LastBlock) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CopyMem (
+ Buffer,
+ (VOID *)(UINTN)(PrivateData->StartingAddr + MultU64x32 (Lba, PrivateData->Media.BlockSize)),
+ BufferSize
+ );
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Write BufferSize bytes from Lba into Buffer.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId The media ID that the write request is for.
+ @param[in] Lba The starting logical block address to be written.
+ The caller is responsible for writing to only
+ legitimate locations.
+ @param[in] BufferSize Size of Buffer, must be a multiple of device block
+ size.
+ @param[in] Buffer A pointer to the source buffer for the data.
+
+ @retval EFI_SUCCESS The data was written correctly to the device.
+ @retval EFI_WRITE_PROTECTED The device can not be written to.
+ @retval EFI_DEVICE_ERROR The device reported an error while performing
+ the write.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
+ device.
+ @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
+ size of the device.
+ @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
+ valid, or the buffer is not on proper alignment.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoWriteBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+{
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ UINTN NumberOfBlocks;
+
+ PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO (This);
+
+ if (MediaId != PrivateData->Media.MediaId) {
+ return EFI_MEDIA_CHANGED;
+ }
+
+ if (TRUE == PrivateData->Media.ReadOnly) {
+ return EFI_WRITE_PROTECTED;
+ }
+
+ if (Buffer == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (BufferSize == 0) {
+ return EFI_SUCCESS;
+ }
+
+ if ((BufferSize % PrivateData->Media.BlockSize) != 0) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ if (Lba > PrivateData->Media.LastBlock) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ NumberOfBlocks = BufferSize / PrivateData->Media.BlockSize;
+ if ((Lba + NumberOfBlocks - 1) > PrivateData->Media.LastBlock) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CopyMem (
+ (VOID *)(UINTN)(PrivateData->StartingAddr + MultU64x32 (Lba, PrivateData->Media.BlockSize)),
+ Buffer,
+ BufferSize
+ );
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Flush the Block Device.
+
+ @param[in] This Indicates a pointer to the calling context.
+
+ @retval EFI_SUCCESS All outstanding data was written to the device.
+ @retval EFI_DEVICE_ERROR The device reported an error while writting
+ back the data
+ @retval EFI_NO_MEDIA There is no media in the device.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoFlushBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This
+ )
+{
+ return EFI_SUCCESS;
+}
+
+/**
+ Resets the block device hardware.
+
+ @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
+ @param[in] ExtendedVerification The flag about if extend verificate.
+
+ @retval EFI_SUCCESS The device was reset.
+ @retval EFI_DEVICE_ERROR The block device is not functioning correctly
+ and could not be reset.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2Reset (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ )
+{
+ return EFI_SUCCESS;
+}
+
+/**
+ Reads the requested number of blocks from the device.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId The media ID that the read request is for.
+ @param[in] Lba The starting logical block address to read
+ from on the device.
+ @param[in, out] Token A pointer to the token associated with the
+ transaction.
+ @param[in] BufferSize The size of the Buffer in bytes. This must be
+ a multiple of the intrinsic block size of the
+ device.
+ @param[out] Buffer A pointer to the destination buffer for the
+ data. The caller is responsible for either
+ having implicit or explicit ownership of the
+ buffer.
+
+ @retval EFI_SUCCESS The read request was queued if Token->Event
+ is not NULL. The data was read correctly from
+ the device if the Token->Event is NULL.
+ @retval EFI_DEVICE_ERROR The device reported an error while attempting
+ to perform the read operation.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
+ @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
+ the intrinsic block size of the device.
+ @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
+ valid, or the buffer is not on proper
+ alignment.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2ReadBlocksEx (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+{
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ EFI_STATUS Status;
+
+ PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);
+
+ Status = RamDiskBlkIoReadBlocks (
+ &PrivateData->BlockIo,
+ MediaId,
+ Lba,
+ BufferSize,
+ Buffer
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // If caller's event is given, signal it after the memory read completes.
+ //
+ if ((Token != NULL) && (Token->Event != NULL)) {
+ Token->TransactionStatus = EFI_SUCCESS;
+ gBS->SignalEvent (Token->Event);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Writes a specified number of blocks to the device.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId The media ID that the write request is for.
+ @param[in] Lba The starting logical block address to be
+ written. The caller is responsible for
+ writing to only legitimate locations.
+ @param[in, out] Token A pointer to the token associated with the
+ transaction.
+ @param[in] BufferSize The size in bytes of Buffer. This must be a
+ multiple of the intrinsic block size of the
+ device.
+ @param[in] Buffer A pointer to the source buffer for the data.
+
+ @retval EFI_SUCCESS The write request was queued if Event is not
+ NULL. The data was written correctly to the
+ device if the Event is NULL.
+ @retval EFI_WRITE_PROTECTED The device cannot be written to.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
+ @retval EFI_DEVICE_ERROR The device reported an error while attempting
+ to perform the write operation.
+ @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
+ the intrinsic block size of the device.
+ @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
+ valid, or the buffer is not on proper
+ alignment.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2WriteBlocksEx (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+{
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ EFI_STATUS Status;
+
+ PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);
+
+ Status = RamDiskBlkIoWriteBlocks (
+ &PrivateData->BlockIo,
+ MediaId,
+ Lba,
+ BufferSize,
+ Buffer
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // If caller's event is given, signal it after the memory write completes.
+ //
+ if ((Token != NULL) && (Token->Event != NULL)) {
+ Token->TransactionStatus = EFI_SUCCESS;
+ gBS->SignalEvent (Token->Event);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Flushes all modified data to a physical block device.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in, out] Token A pointer to the token associated with the
+ transaction.
+
+ @retval EFI_SUCCESS The flush request was queued if Event is not
+ NULL. All outstanding data was written
+ correctly to the device if the Event is NULL.
+ @retval EFI_DEVICE_ERROR The device reported an error while attempting
+ to write data.
+ @retval EFI_WRITE_PROTECTED The device cannot be written to.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2FlushBlocksEx (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token
+ )
+{
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+
+ PrivateData = RAM_DISK_PRIVATE_FROM_BLKIO2 (This);
+
+ if (TRUE == PrivateData->Media.ReadOnly) {
+ return EFI_WRITE_PROTECTED;
+ }
+
+ //
+ // If caller's event is given, signal it directly.
+ //
+ if ((Token != NULL) && (Token->Event != NULL)) {
+ Token->TransactionStatus = EFI_SUCCESS;
+ gBS->SignalEvent (Token->Event);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
index 82184c1c69..212d9e860d 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
@@ -1,242 +1,242 @@
-/** @file
- The driver entry point for RamDiskDxe driver.
-
- Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
- Copyright (c) Microsoft Corporation.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "RamDiskImpl.h"
-
-//
-// Handle for the EFI_RAM_DISK_PROTOCOL instance
-//
-EFI_HANDLE mRamDiskHandle = NULL;
-
-//
-// The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver
-// handle
-//
-EFI_RAM_DISK_PROTOCOL mRamDiskProtocol = {
- RamDiskRegister,
- RamDiskUnregister
-};
-
-//
-// RamDiskDxe driver maintains a list of registered RAM disks.
-//
-LIST_ENTRY RegisteredRamDisks;
-
-//
-// Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
-//
-EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL;
-EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol = NULL;
-
-/**
- Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.
- If both protocols are produced, publish all the reserved memory type RAM
- disks to the NVDIMM Firmware Interface Table (NFIT).
-
- @param[in] Event Event whose notification function is being invoked.
- @param[in] Context The pointer to the notification function's context,
- which is implementation-dependent.
-
-**/
-VOID
-EFIAPI
-RamDiskAcpiCheck (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-{
- EFI_STATUS Status;
- LIST_ENTRY *Entry;
- RAM_DISK_PRIVATE_DATA *PrivateData;
-
- gBS->CloseEvent (Event);
-
- //
- // Locate the EFI_ACPI_TABLE_PROTOCOL.
- //
- Status = gBS->LocateProtocol (
- &gEfiAcpiTableProtocolGuid,
- NULL,
- (VOID **)&mAcpiTableProtocol
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((
- DEBUG_INFO,
- "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "
- "unable to publish RAM disks to NFIT.\n"
- ));
- return;
- }
-
- //
- // Locate the EFI_ACPI_SDT_PROTOCOL.
- //
- Status = gBS->LocateProtocol (
- &gEfiAcpiSdtProtocolGuid,
- NULL,
- (VOID **)&mAcpiSdtProtocol
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((
- DEBUG_INFO,
- "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "
- "unable to publish RAM disks to NFIT.\n"
- ));
- mAcpiTableProtocol = NULL;
- return;
- }
-
- BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
- PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
- RamDiskPublishNfit (PrivateData);
- }
-}
-
-/**
- The entry point for RamDiskDxe driver.
-
- @param[in] ImageHandle The image handle of the driver.
- @param[in] SystemTable The system table.
-
- @retval EFI_ALREADY_STARTED The driver already exists in system.
- @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of
- resources.
- @retval EFI_SUCCES All the related protocols are installed on
- the driver.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskDxeEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
- RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
- VOID *DummyInterface;
- EFI_EVENT Event;
-
- //
- // If already started, return.
- //
- Status = gBS->LocateProtocol (
- &gEfiRamDiskProtocolGuid,
- NULL,
- &DummyInterface
- );
- if (!EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "Driver already started!\n"));
- return EFI_ALREADY_STARTED;
- }
-
- //
- // Create a private data structure.
- //
- ConfigPrivate = AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA), &mRamDiskConfigPrivateDataTemplate);
- if (ConfigPrivate == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- //
- // Install RAM disk configuration form
- //
- Status = InstallRamDiskConfigForm (ConfigPrivate);
- if (EFI_ERROR (Status)) {
- goto ErrorExit;
- }
-
- //
- // Initialize the list of registered RAM disks maintained by the driver
- // before installing the protocol
- //
- InitializeListHead (&RegisteredRamDisks);
-
- //
- // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
- // new handle
- //
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mRamDiskHandle,
- &gEfiRamDiskProtocolGuid,
- &mRamDiskProtocol,
- &gEfiCallerIdGuid,
- ConfigPrivate,
- NULL
- );
- if (EFI_ERROR (Status)) {
- goto ErrorExit;
- }
-
- Status = EfiCreateEventReadyToBootEx (
- TPL_CALLBACK,
- RamDiskAcpiCheck,
- NULL,
- &Event
- );
- ASSERT_EFI_ERROR (Status);
-
- return EFI_SUCCESS;
-
-ErrorExit:
- if (ConfigPrivate != NULL) {
- UninstallRamDiskConfigForm (ConfigPrivate);
- }
-
- return Status;
-}
-
-/**
- Unload the RamDiskDxe driver and its configuration form.
-
- @param[in] ImageHandle The driver's image handle.
-
- @retval EFI_SUCCESS The RamDiskDxe driver and its configuration
- form is unloaded.
- @retval Others Failed to unload the form.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskDxeUnload (
- IN EFI_HANDLE ImageHandle
- )
-{
- EFI_STATUS Status;
- RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
-
- Status = gBS->HandleProtocol (
- mRamDiskHandle,
- &gEfiCallerIdGuid,
- (VOID **)&ConfigPrivate
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- ASSERT (ConfigPrivate->Signature == RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE);
-
- //
- // Unregister all registered RAM disks
- //
- UnregisterAllRamDisks ();
-
- gBS->UninstallMultipleProtocolInterfaces (
- mRamDiskHandle,
- &gEfiRamDiskProtocolGuid,
- &mRamDiskProtocol,
- &gEfiCallerIdGuid,
- ConfigPrivate,
- NULL
- );
-
- UninstallRamDiskConfigForm (ConfigPrivate);
-
- return EFI_SUCCESS;
-}
+/** @file
+ The driver entry point for RamDiskDxe driver.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "RamDiskImpl.h"
+
+//
+// Handle for the EFI_RAM_DISK_PROTOCOL instance
+//
+EFI_HANDLE mRamDiskHandle = NULL;
+
+//
+// The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver
+// handle
+//
+EFI_RAM_DISK_PROTOCOL mRamDiskProtocol = {
+ RamDiskRegister,
+ RamDiskUnregister
+};
+
+//
+// RamDiskDxe driver maintains a list of registered RAM disks.
+//
+LIST_ENTRY RegisteredRamDisks;
+
+//
+// Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
+//
+EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL;
+EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol = NULL;
+
+/**
+ Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.
+ If both protocols are produced, publish all the reserved memory type RAM
+ disks to the NVDIMM Firmware Interface Table (NFIT).
+
+ @param[in] Event Event whose notification function is being invoked.
+ @param[in] Context The pointer to the notification function's context,
+ which is implementation-dependent.
+
+**/
+VOID
+EFIAPI
+RamDiskAcpiCheck (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ EFI_STATUS Status;
+ LIST_ENTRY *Entry;
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+
+ gBS->CloseEvent (Event);
+
+ //
+ // Locate the EFI_ACPI_TABLE_PROTOCOL.
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiAcpiTableProtocolGuid,
+ NULL,
+ (VOID **)&mAcpiTableProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_INFO,
+ "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "
+ "unable to publish RAM disks to NFIT.\n"
+ ));
+ return;
+ }
+
+ //
+ // Locate the EFI_ACPI_SDT_PROTOCOL.
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiAcpiSdtProtocolGuid,
+ NULL,
+ (VOID **)&mAcpiSdtProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((
+ DEBUG_INFO,
+ "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "
+ "unable to publish RAM disks to NFIT.\n"
+ ));
+ mAcpiTableProtocol = NULL;
+ return;
+ }
+
+ BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
+ PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
+ RamDiskPublishNfit (PrivateData);
+ }
+}
+
+/**
+ The entry point for RamDiskDxe driver.
+
+ @param[in] ImageHandle The image handle of the driver.
+ @param[in] SystemTable The system table.
+
+ @retval EFI_ALREADY_STARTED The driver already exists in system.
+ @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of
+ resources.
+ @retval EFI_SUCCES All the related protocols are installed on
+ the driver.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskDxeEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
+ VOID *DummyInterface;
+ EFI_EVENT Event;
+
+ //
+ // If already started, return.
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiRamDiskProtocolGuid,
+ NULL,
+ &DummyInterface
+ );
+ if (!EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "Driver already started!\n"));
+ return EFI_ALREADY_STARTED;
+ }
+
+ //
+ // Create a private data structure.
+ //
+ ConfigPrivate = AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA), &mRamDiskConfigPrivateDataTemplate);
+ if (ConfigPrivate == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Install RAM disk configuration form
+ //
+ Status = InstallRamDiskConfigForm (ConfigPrivate);
+ if (EFI_ERROR (Status)) {
+ goto ErrorExit;
+ }
+
+ //
+ // Initialize the list of registered RAM disks maintained by the driver
+ // before installing the protocol
+ //
+ InitializeListHead (&RegisteredRamDisks);
+
+ //
+ // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
+ // new handle
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &mRamDiskHandle,
+ &gEfiRamDiskProtocolGuid,
+ &mRamDiskProtocol,
+ &gEfiCallerIdGuid,
+ ConfigPrivate,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ goto ErrorExit;
+ }
+
+ Status = EfiCreateEventReadyToBootEx (
+ TPL_CALLBACK,
+ RamDiskAcpiCheck,
+ NULL,
+ &Event
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_SUCCESS;
+
+ErrorExit:
+ if (ConfigPrivate != NULL) {
+ UninstallRamDiskConfigForm (ConfigPrivate);
+ }
+
+ return Status;
+}
+
+/**
+ Unload the RamDiskDxe driver and its configuration form.
+
+ @param[in] ImageHandle The driver's image handle.
+
+ @retval EFI_SUCCESS The RamDiskDxe driver and its configuration
+ form is unloaded.
+ @retval Others Failed to unload the form.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskDxeUnload (
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ EFI_STATUS Status;
+ RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
+
+ Status = gBS->HandleProtocol (
+ mRamDiskHandle,
+ &gEfiCallerIdGuid,
+ (VOID **)&ConfigPrivate
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ ASSERT (ConfigPrivate->Signature == RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE);
+
+ //
+ // Unregister all registered RAM disks
+ //
+ UnregisterAllRamDisks ();
+
+ gBS->UninstallMultipleProtocolInterfaces (
+ mRamDiskHandle,
+ &gEfiRamDiskProtocolGuid,
+ &mRamDiskProtocol,
+ &gEfiCallerIdGuid,
+ ConfigPrivate,
+ NULL
+ );
+
+ UninstallRamDiskConfigForm (ConfigPrivate);
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
index bc2e642cf9..5e71b6c877 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
@@ -1,84 +1,84 @@
-## @file
-# Produces EFI_RAM_DISK_PROTOCOL and provides the capability to
-# create/remove RAM disks in a setup browser.
-#
-# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = RamDiskDxe
- MODULE_UNI_FILE = RamDiskDxe.uni
- FILE_GUID = 28A03FF4-12B3-4305-A417-BB1A4F94081E
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = RamDiskDxeEntryPoint
- UNLOAD_IMAGE = RamDiskDxeUnload
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
-#
-
-[Sources]
- RamDiskDriver.c
- RamDiskImpl.c
- RamDiskBlockIo.c
- RamDiskProtocol.c
- RamDiskFileExplorer.c
- RamDiskImpl.h
- RamDiskHii.vfr
- RamDiskHiiStrings.uni
- RamDiskNVData.h
- RamDisk.asl
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
-
-[LibraryClasses]
- BaseLib
- BaseMemoryLib
- DebugLib
- UefiLib
- UefiDriverEntryPoint
- UefiBootServicesTableLib
- UefiHiiServicesLib
- MemoryAllocationLib
- HiiLib
- FileExplorerLib
- DevicePathLib
- PrintLib
- PcdLib
- DxeServicesLib
-
-[Guids]
- gEfiIfrTianoGuid ## PRODUCES ## GUID # HII opcode
- ## PRODUCES ## HII
- ## CONSUMES ## HII
- gRamDiskFormSetGuid
- gEfiVirtualDiskGuid ## SOMETIMES_CONSUMES ## GUID
- gEfiFileInfoGuid ## SOMETIMES_CONSUMES ## GUID # Indicate the information type
-
-[Protocols]
- gEfiRamDiskProtocolGuid ## PRODUCES
- gEfiHiiConfigAccessProtocolGuid ## PRODUCES
- gEfiDevicePathProtocolGuid ## PRODUCES
- gEfiBlockIoProtocolGuid ## PRODUCES
- gEfiBlockIo2ProtocolGuid ## PRODUCES
- gEfiAcpiTableProtocolGuid ## SOMETIMES_CONSUMES
- gEfiAcpiSdtProtocolGuid ## SOMETIMES_CONSUMES
-
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## SOMETIMES_CONSUMES
-
-[Depex]
- gEfiHiiConfigRoutingProtocolGuid AND
- gEfiHiiDatabaseProtocolGuid
+## @file
+# Produces EFI_RAM_DISK_PROTOCOL and provides the capability to
+# create/remove RAM disks in a setup browser.
+#
+# Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = RamDiskDxe
+ MODULE_UNI_FILE = RamDiskDxe.uni
+ FILE_GUID = 28A03FF4-12B3-4305-A417-BB1A4F94081E
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = RamDiskDxeEntryPoint
+ UNLOAD_IMAGE = RamDiskDxeUnload
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ RamDiskDriver.c
+ RamDiskImpl.c
+ RamDiskBlockIo.c
+ RamDiskProtocol.c
+ RamDiskFileExplorer.c
+ RamDiskImpl.h
+ RamDiskHii.vfr
+ RamDiskHiiStrings.uni
+ RamDiskNVData.h
+ RamDisk.asl
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ UefiLib
+ UefiDriverEntryPoint
+ UefiBootServicesTableLib
+ UefiHiiServicesLib
+ MemoryAllocationLib
+ HiiLib
+ FileExplorerLib
+ DevicePathLib
+ PrintLib
+ PcdLib
+ DxeServicesLib
+
+[Guids]
+ gEfiIfrTianoGuid ## PRODUCES ## GUID # HII opcode
+ ## PRODUCES ## HII
+ ## CONSUMES ## HII
+ gRamDiskFormSetGuid
+ gEfiVirtualDiskGuid ## SOMETIMES_CONSUMES ## GUID
+ gEfiFileInfoGuid ## SOMETIMES_CONSUMES ## GUID # Indicate the information type
+
+[Protocols]
+ gEfiRamDiskProtocolGuid ## PRODUCES
+ gEfiHiiConfigAccessProtocolGuid ## PRODUCES
+ gEfiDevicePathProtocolGuid ## PRODUCES
+ gEfiBlockIoProtocolGuid ## PRODUCES
+ gEfiBlockIo2ProtocolGuid ## PRODUCES
+ gEfiAcpiTableProtocolGuid ## SOMETIMES_CONSUMES
+ gEfiAcpiSdtProtocolGuid ## SOMETIMES_CONSUMES
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## SOMETIMES_CONSUMES
+
+[Depex]
+ gEfiHiiConfigRoutingProtocolGuid AND
+ gEfiHiiDatabaseProtocolGuid
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.uni b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.uni
index edf35ea183..117e406c3a 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.uni
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.uni
@@ -1,14 +1,14 @@
-// /** @file
-// Produces EFI_RAM_DISK_PROTOCOL and provides the capability to
-// create/remove RAM disks in a setup browser.
-//
-// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#string STR_MODULE_ABSTRACT #language en-US "Produces EFI_RAM_DISK_PROTOCOL and provides the capability to create/remove RAM disks in a setup browser."
-
-#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI_RAM_DISK_PROTOCOL and provides the capability to create/remove RAM disks in a setup browser."
-
+// /** @file
+// Produces EFI_RAM_DISK_PROTOCOL and provides the capability to
+// create/remove RAM disks in a setup browser.
+//
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Produces EFI_RAM_DISK_PROTOCOL and provides the capability to create/remove RAM disks in a setup browser."
+
+#string STR_MODULE_DESCRIPTION #language en-US "This module produces EFI_RAM_DISK_PROTOCOL and provides the capability to create/remove RAM disks in a setup browser."
+
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c
index 0285ff5d0e..9a8b80a74f 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c
@@ -1,106 +1,106 @@
-/** @file
- Internal file explorer helper functions for RamDiskDxe driver.
-
- Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "RamDiskImpl.h"
-
-/**
- Helper function called as part of the code needed to allocate the proper
- sized buffer for various EFI interfaces.
-
- @param[in, out] Status Current status.
- @param[in, out] Buffer Current allocated buffer, or NULL.
- @param[in] BufferSize Current buffer size needed.
-
- @retval TRUE If the buffer was reallocated and the caller should
- try the API again.
- @retval FALSE The caller should not call this function again.
-
-**/
-BOOLEAN
-GrowBuffer (
- IN OUT EFI_STATUS *Status,
- IN OUT VOID **Buffer,
- IN UINTN BufferSize
- )
-{
- BOOLEAN TryAgain;
-
- //
- // If this is an initial request, buffer will be null with a new buffer size
- //
- if ((*Buffer == NULL) && (BufferSize != 0)) {
- *Status = EFI_BUFFER_TOO_SMALL;
- }
-
- //
- // If the status code is "buffer too small", resize the buffer
- //
- TryAgain = FALSE;
- if (*Status == EFI_BUFFER_TOO_SMALL) {
- if (*Buffer != NULL) {
- FreePool (*Buffer);
- }
-
- *Buffer = AllocateZeroPool (BufferSize);
-
- if (*Buffer != NULL) {
- TryAgain = TRUE;
- } else {
- *Status = EFI_OUT_OF_RESOURCES;
- }
- }
-
- //
- // If there's an error, free the buffer
- //
- if (!TryAgain && EFI_ERROR (*Status) && (*Buffer != NULL)) {
- FreePool (*Buffer);
- *Buffer = NULL;
- }
-
- return TryAgain;
-}
-
-/**
- This function gets the file information from an open file descriptor,
- and stores it in a buffer allocated from pool.
-
- @param[in] FHand File Handle.
-
- @return A pointer to a buffer with file information or NULL is returned.
-
-**/
-EFI_FILE_INFO *
-FileInfo (
- IN EFI_FILE_HANDLE FHand
- )
-{
- EFI_STATUS Status;
- EFI_FILE_INFO *Buffer;
- UINTN BufferSize;
-
- //
- // Initialize for GrowBuffer loop
- //
- Buffer = NULL;
- BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
-
- //
- // Call the real function
- //
- while (GrowBuffer (&Status, (VOID **)&Buffer, BufferSize)) {
- Status = FHand->GetInfo (
- FHand,
- &gEfiFileInfoGuid,
- &BufferSize,
- Buffer
- );
- }
-
- return Buffer;
-}
+/** @file
+ Internal file explorer helper functions for RamDiskDxe driver.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "RamDiskImpl.h"
+
+/**
+ Helper function called as part of the code needed to allocate the proper
+ sized buffer for various EFI interfaces.
+
+ @param[in, out] Status Current status.
+ @param[in, out] Buffer Current allocated buffer, or NULL.
+ @param[in] BufferSize Current buffer size needed.
+
+ @retval TRUE If the buffer was reallocated and the caller should
+ try the API again.
+ @retval FALSE The caller should not call this function again.
+
+**/
+BOOLEAN
+GrowBuffer (
+ IN OUT EFI_STATUS *Status,
+ IN OUT VOID **Buffer,
+ IN UINTN BufferSize
+ )
+{
+ BOOLEAN TryAgain;
+
+ //
+ // If this is an initial request, buffer will be null with a new buffer size
+ //
+ if ((*Buffer == NULL) && (BufferSize != 0)) {
+ *Status = EFI_BUFFER_TOO_SMALL;
+ }
+
+ //
+ // If the status code is "buffer too small", resize the buffer
+ //
+ TryAgain = FALSE;
+ if (*Status == EFI_BUFFER_TOO_SMALL) {
+ if (*Buffer != NULL) {
+ FreePool (*Buffer);
+ }
+
+ *Buffer = AllocateZeroPool (BufferSize);
+
+ if (*Buffer != NULL) {
+ TryAgain = TRUE;
+ } else {
+ *Status = EFI_OUT_OF_RESOURCES;
+ }
+ }
+
+ //
+ // If there's an error, free the buffer
+ //
+ if (!TryAgain && EFI_ERROR (*Status) && (*Buffer != NULL)) {
+ FreePool (*Buffer);
+ *Buffer = NULL;
+ }
+
+ return TryAgain;
+}
+
+/**
+ This function gets the file information from an open file descriptor,
+ and stores it in a buffer allocated from pool.
+
+ @param[in] FHand File Handle.
+
+ @return A pointer to a buffer with file information or NULL is returned.
+
+**/
+EFI_FILE_INFO *
+FileInfo (
+ IN EFI_FILE_HANDLE FHand
+ )
+{
+ EFI_STATUS Status;
+ EFI_FILE_INFO *Buffer;
+ UINTN BufferSize;
+
+ //
+ // Initialize for GrowBuffer loop
+ //
+ Buffer = NULL;
+ BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
+
+ //
+ // Call the real function
+ //
+ while (GrowBuffer (&Status, (VOID **)&Buffer, BufferSize)) {
+ Status = FHand->GetInfo (
+ FHand,
+ &gEfiFileInfoGuid,
+ &BufferSize,
+ Buffer
+ );
+ }
+
+ return Buffer;
+}
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHii.vfr b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHii.vfr
index 3964d2f5b0..a6bee27581 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHii.vfr
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHii.vfr
@@ -1,94 +1,94 @@
-///** @file
-// VFR file used by the RamDiskDxe driver.
-//
-// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
-// (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-//**/
-
-#include "RamDiskNVData.h"
-
-formset
- guid = RAM_DISK_FORM_SET_GUID,
- title = STRING_TOKEN(STR_FORM_SET_TITLE),
- help = STRING_TOKEN(STR_FORM_SET_TITLE_HELP),
- classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID,
-
- //
- // Form #1 "Main Form - Add/Remove/Show RAM Disks"
- //
- form formid = MAIN_FORM_ID,
- title = STRING_TOKEN(STR_MAIN_FORM_TITLE);
-
- oneof
- questionid = CREATE_RAW_MEMORY_TYPE_QUESTION_ID,
- prompt = STRING_TOKEN(STR_MEMORY_TYPE_PROMPT),
- help = STRING_TOKEN(STR_MEMORY_TYPE_HELP),
- flags = NUMERIC_SIZE_1 | INTERACTIVE,
- option text = STRING_TOKEN(STR_RAM_DISK_BOOT_SERVICE_DATA_MEMORY), value = RAM_DISK_BOOT_SERVICE_DATA_MEMORY, flags = DEFAULT;
- option text = STRING_TOKEN(STR_RAM_DISK_RESERVED_MEMORY), value = RAM_DISK_RESERVED_MEMORY, flags = 0;
- endoneof;
-
- subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
-
- goto CREATE_RAW_RAM_DISK_FORM_ID,
- prompt = STRING_TOKEN(STR_GOTO_ADD_RAW_FORM),
- help = STRING_TOKEN(STR_GOTO_ADD_RAW_FORM_HELP);
-
- goto MAIN_FORM_ID,
- prompt = STRING_TOKEN(STR_GOTO_ADD_FROM_FILE_FORM),
- help = STRING_TOKEN(STR_GOTO_ADD_FROM_FILE_FORM_HELP),
- flags = INTERACTIVE,
- key = MAIN_GOTO_FILE_EXPLORER_ID;
-
- subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
- subtitle text = STRING_TOKEN(STR_RAM_DISK_LIST_TEXT);
-
- label MAIN_LABEL_LIST_START;
- label MAIN_LABEL_LIST_END;
-
- subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
-
- text
- help = STRING_TOKEN(STR_REMOVE_SEL_HELP),
- text = STRING_TOKEN(STR_REMOVE_SEL_TEXT),
- flags = INTERACTIVE,
- key = MAIN_REMOVE_RD_QUESTION_ID;
-
- endform;
-
- //
- // Form #2 "Add New Raw RAM Disk"
- //
- form formid = CREATE_RAW_RAM_DISK_FORM_ID,
- title = STRING_TOKEN(STR_ADD_RAW_FORM_TITLE);
-
- subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
-
- numeric
- questionid = CREATE_RAW_SIZE_QUESTION_ID,
- prompt = STRING_TOKEN(STR_SIZE_PROMPT),
- help = STRING_TOKEN(STR_SIZE_HELP),
- flags = NUMERIC_SIZE_8 | DISPLAY_UINT_HEX | INTERACTIVE,
- minimum = 1,
- maximum = 0xFFFFFFFFFFFFFFFF,
- endnumeric;
-
- subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
-
- text
- help = STRING_TOKEN(STR_CREATE_AND_EXIT_HELP),
- text = STRING_TOKEN(STR_CREATE_AND_EXIT_PROMPT),
- flags = INTERACTIVE,
- key = CREATE_RAW_SUBMIT_QUESTION_ID;
-
- text
- help = STRING_TOKEN(STR_DISCARD_AND_EXIT_HELP),
- text = STRING_TOKEN(STR_DISCARD_AND_EXIT_PROMPT),
- flags = INTERACTIVE,
- key = CREATE_RAW_DISCARD_QUESTION_ID;
-
- endform;
-
-endformset;
+///** @file
+// VFR file used by the RamDiskDxe driver.
+//
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+// (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+//**/
+
+#include "RamDiskNVData.h"
+
+formset
+ guid = RAM_DISK_FORM_SET_GUID,
+ title = STRING_TOKEN(STR_FORM_SET_TITLE),
+ help = STRING_TOKEN(STR_FORM_SET_TITLE_HELP),
+ classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID,
+
+ //
+ // Form #1 "Main Form - Add/Remove/Show RAM Disks"
+ //
+ form formid = MAIN_FORM_ID,
+ title = STRING_TOKEN(STR_MAIN_FORM_TITLE);
+
+ oneof
+ questionid = CREATE_RAW_MEMORY_TYPE_QUESTION_ID,
+ prompt = STRING_TOKEN(STR_MEMORY_TYPE_PROMPT),
+ help = STRING_TOKEN(STR_MEMORY_TYPE_HELP),
+ flags = NUMERIC_SIZE_1 | INTERACTIVE,
+ option text = STRING_TOKEN(STR_RAM_DISK_BOOT_SERVICE_DATA_MEMORY), value = RAM_DISK_BOOT_SERVICE_DATA_MEMORY, flags = DEFAULT;
+ option text = STRING_TOKEN(STR_RAM_DISK_RESERVED_MEMORY), value = RAM_DISK_RESERVED_MEMORY, flags = 0;
+ endoneof;
+
+ subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
+
+ goto CREATE_RAW_RAM_DISK_FORM_ID,
+ prompt = STRING_TOKEN(STR_GOTO_ADD_RAW_FORM),
+ help = STRING_TOKEN(STR_GOTO_ADD_RAW_FORM_HELP);
+
+ goto MAIN_FORM_ID,
+ prompt = STRING_TOKEN(STR_GOTO_ADD_FROM_FILE_FORM),
+ help = STRING_TOKEN(STR_GOTO_ADD_FROM_FILE_FORM_HELP),
+ flags = INTERACTIVE,
+ key = MAIN_GOTO_FILE_EXPLORER_ID;
+
+ subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
+ subtitle text = STRING_TOKEN(STR_RAM_DISK_LIST_TEXT);
+
+ label MAIN_LABEL_LIST_START;
+ label MAIN_LABEL_LIST_END;
+
+ subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
+
+ text
+ help = STRING_TOKEN(STR_REMOVE_SEL_HELP),
+ text = STRING_TOKEN(STR_REMOVE_SEL_TEXT),
+ flags = INTERACTIVE,
+ key = MAIN_REMOVE_RD_QUESTION_ID;
+
+ endform;
+
+ //
+ // Form #2 "Add New Raw RAM Disk"
+ //
+ form formid = CREATE_RAW_RAM_DISK_FORM_ID,
+ title = STRING_TOKEN(STR_ADD_RAW_FORM_TITLE);
+
+ subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
+
+ numeric
+ questionid = CREATE_RAW_SIZE_QUESTION_ID,
+ prompt = STRING_TOKEN(STR_SIZE_PROMPT),
+ help = STRING_TOKEN(STR_SIZE_HELP),
+ flags = NUMERIC_SIZE_8 | DISPLAY_UINT_HEX | INTERACTIVE,
+ minimum = 1,
+ maximum = 0xFFFFFFFFFFFFFFFF,
+ endnumeric;
+
+ subtitle text = STRING_TOKEN(STR_RAM_DISK_NULL_STRING);
+
+ text
+ help = STRING_TOKEN(STR_CREATE_AND_EXIT_HELP),
+ text = STRING_TOKEN(STR_CREATE_AND_EXIT_PROMPT),
+ flags = INTERACTIVE,
+ key = CREATE_RAW_SUBMIT_QUESTION_ID;
+
+ text
+ help = STRING_TOKEN(STR_DISCARD_AND_EXIT_HELP),
+ text = STRING_TOKEN(STR_DISCARD_AND_EXIT_PROMPT),
+ flags = INTERACTIVE,
+ key = CREATE_RAW_DISCARD_QUESTION_ID;
+
+ endform;
+
+endformset;
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHiiStrings.uni b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHiiStrings.uni
index 5ee1172c48..818b5e4dbb 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHiiStrings.uni
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskHiiStrings.uni
@@ -1,41 +1,41 @@
-// /** @file
-// String definitions for RamDiskDxe driver form.
-//
-// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
-// (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#langdef en-US "English"
-
-#string STR_FORM_SET_TITLE #language en-US "RAM Disk Configuration"
-#string STR_FORM_SET_TITLE_HELP #language en-US "Press <Enter> to add/remove RAM disks."
-
-#string STR_MAIN_FORM_TITLE #language en-US "RAM Disk HII Main Screen"
-#string STR_RAM_DISK_NULL_STRING #language en-US ""
-
-#string STR_RAM_DISK_LIST_TEXT #language en-US "Created RAM disk list:"
-#string STR_RAM_DISK_LIST_HELP #language en-US "Select for remove"
-#string STR_GOTO_ADD_RAW_FORM #language en-US "Create raw"
-#string STR_GOTO_ADD_RAW_FORM_HELP #language en-US "Create a raw RAM disk."
-#string STR_GOTO_ADD_FROM_FILE_FORM #language en-US "Create from file"
-#string STR_GOTO_ADD_FROM_FILE_FORM_HELP #language en-US "Create a RAM disk from a given file."
-#string STR_REMOVE_SEL_HELP #language en-US "Remove selected RAM disk(s)"
-#string STR_REMOVE_SEL_TEXT #language en-US "Remove selected RAM disk(s)."
-
-#string STR_ADD_RAW_FORM_TITLE #language en-US "Add A Raw RAM Disk"
-#string STR_ADD_RAW_FORM_SUBTITLE_TEXT #language en-US " "
-
-#string STR_SIZE_PROMPT #language en-US "Size (Hex):"
-#string STR_SIZE_HELP #language en-US "The valid RAM disk size should be multiples of the RAM disk block size."
-
-#string STR_MEMORY_TYPE_PROMPT #language en-US "Disk Memory Type:"
-#string STR_MEMORY_TYPE_HELP #language en-US "Specifies type of memory to use from available memory pool in system to create a disk."
-#string STR_RAM_DISK_BOOT_SERVICE_DATA_MEMORY #language en-US "Boot Service Data"
-#string STR_RAM_DISK_RESERVED_MEMORY #language en-US "Reserved"
-
-#string STR_CREATE_AND_EXIT_HELP #language en-US "Create a new RAM disk with the given starting and ending address."
-#string STR_CREATE_AND_EXIT_PROMPT #language en-US "Create & Exit"
-#string STR_DISCARD_AND_EXIT_HELP #language en-US "Discard and exit."
-#string STR_DISCARD_AND_EXIT_PROMPT #language en-US "Discard & Exit"
+// /** @file
+// String definitions for RamDiskDxe driver form.
+//
+// Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+// (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#langdef en-US "English"
+
+#string STR_FORM_SET_TITLE #language en-US "RAM Disk Configuration"
+#string STR_FORM_SET_TITLE_HELP #language en-US "Press <Enter> to add/remove RAM disks."
+
+#string STR_MAIN_FORM_TITLE #language en-US "RAM Disk HII Main Screen"
+#string STR_RAM_DISK_NULL_STRING #language en-US ""
+
+#string STR_RAM_DISK_LIST_TEXT #language en-US "Created RAM disk list:"
+#string STR_RAM_DISK_LIST_HELP #language en-US "Select for remove"
+#string STR_GOTO_ADD_RAW_FORM #language en-US "Create raw"
+#string STR_GOTO_ADD_RAW_FORM_HELP #language en-US "Create a raw RAM disk."
+#string STR_GOTO_ADD_FROM_FILE_FORM #language en-US "Create from file"
+#string STR_GOTO_ADD_FROM_FILE_FORM_HELP #language en-US "Create a RAM disk from a given file."
+#string STR_REMOVE_SEL_HELP #language en-US "Remove selected RAM disk(s)"
+#string STR_REMOVE_SEL_TEXT #language en-US "Remove selected RAM disk(s)."
+
+#string STR_ADD_RAW_FORM_TITLE #language en-US "Add A Raw RAM Disk"
+#string STR_ADD_RAW_FORM_SUBTITLE_TEXT #language en-US " "
+
+#string STR_SIZE_PROMPT #language en-US "Size (Hex):"
+#string STR_SIZE_HELP #language en-US "The valid RAM disk size should be multiples of the RAM disk block size."
+
+#string STR_MEMORY_TYPE_PROMPT #language en-US "Disk Memory Type:"
+#string STR_MEMORY_TYPE_HELP #language en-US "Specifies type of memory to use from available memory pool in system to create a disk."
+#string STR_RAM_DISK_BOOT_SERVICE_DATA_MEMORY #language en-US "Boot Service Data"
+#string STR_RAM_DISK_RESERVED_MEMORY #language en-US "Reserved"
+
+#string STR_CREATE_AND_EXIT_HELP #language en-US "Create a new RAM disk with the given starting and ending address."
+#string STR_CREATE_AND_EXIT_PROMPT #language en-US "Create & Exit"
+#string STR_DISCARD_AND_EXIT_HELP #language en-US "Discard and exit."
+#string STR_DISCARD_AND_EXIT_PROMPT #language en-US "Discard & Exit"
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c
index 60cf3c8c4a..eda70e7a27 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c
@@ -1,757 +1,757 @@
-/** @file
- HII Config Access protocol implementation of RamDiskDxe driver.
-
- Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
- (C) Copyright 2016-2018 Hewlett Packard Enterprise Development LP<BR>
- Copyright (c) Microsoft Corporation.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "RamDiskImpl.h"
-
-CHAR16 mRamDiskStorageName[] = L"RAM_DISK_CONFIGURATION";
-
-RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate = {
- RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE,
- {
- EFI_PAGE_SIZE,
- RAM_DISK_BOOT_SERVICE_DATA_MEMORY
- },
- {
- RamDiskExtractConfig,
- RamDiskRouteConfig,
- RamDiskCallback
- }
-};
-
-HII_VENDOR_DEVICE_PATH mRamDiskHiiVendorDevicePath = {
- {
- {
- HARDWARE_DEVICE_PATH,
- HW_VENDOR_DP,
- {
- (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
- (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
- }
- },
- RAM_DISK_FORM_SET_GUID
- },
- {
- END_DEVICE_PATH_TYPE,
- END_ENTIRE_DEVICE_PATH_SUBTYPE,
- {
- (UINT8)(END_DEVICE_PATH_LENGTH),
- (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
- }
- }
-};
-
-/**
- This function publish the RAM disk configuration Form.
-
- @param[in, out] ConfigPrivateData
- Points to RAM disk configuration private data.
-
- @retval EFI_SUCCESS HII Form is installed successfully.
- @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
- @retval Others Other errors as indicated.
-
-**/
-EFI_STATUS
-InstallRamDiskConfigForm (
- IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
- )
-{
- EFI_STATUS Status;
- EFI_HII_HANDLE HiiHandle;
- EFI_HANDLE DriverHandle;
- EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
-
- DriverHandle = NULL;
- ConfigAccess = &ConfigPrivateData->ConfigAccess;
- Status = gBS->InstallMultipleProtocolInterfaces (
- &DriverHandle,
- &gEfiDevicePathProtocolGuid,
- &mRamDiskHiiVendorDevicePath,
- &gEfiHiiConfigAccessProtocolGuid,
- ConfigAccess,
- NULL
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- ConfigPrivateData->DriverHandle = DriverHandle;
-
- //
- // Publish the HII package list
- //
- HiiHandle = HiiAddPackages (
- &gRamDiskFormSetGuid,
- DriverHandle,
- RamDiskDxeStrings,
- RamDiskHiiBin,
- NULL
- );
- if (HiiHandle == NULL) {
- gBS->UninstallMultipleProtocolInterfaces (
- DriverHandle,
- &gEfiDevicePathProtocolGuid,
- &mRamDiskHiiVendorDevicePath,
- &gEfiHiiConfigAccessProtocolGuid,
- ConfigAccess,
- NULL
- );
- return EFI_OUT_OF_RESOURCES;
- }
-
- ConfigPrivateData->HiiHandle = HiiHandle;
-
- return EFI_SUCCESS;
-}
-
-/**
- This function removes RAM disk configuration Form.
-
- @param[in, out] ConfigPrivateData
- Points to RAM disk configuration private data.
-
-**/
-VOID
-UninstallRamDiskConfigForm (
- IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
- )
-{
- //
- // Uninstall HII package list
- //
- if (ConfigPrivateData->HiiHandle != NULL) {
- HiiRemovePackages (ConfigPrivateData->HiiHandle);
- ConfigPrivateData->HiiHandle = NULL;
- }
-
- //
- // Uninstall HII Config Access Protocol
- //
- if (ConfigPrivateData->DriverHandle != NULL) {
- gBS->UninstallMultipleProtocolInterfaces (
- ConfigPrivateData->DriverHandle,
- &gEfiDevicePathProtocolGuid,
- &mRamDiskHiiVendorDevicePath,
- &gEfiHiiConfigAccessProtocolGuid,
- &ConfigPrivateData->ConfigAccess,
- NULL
- );
- ConfigPrivateData->DriverHandle = NULL;
- }
-
- FreePool (ConfigPrivateData);
-}
-
-/**
- Unregister all registered RAM disks.
-
-**/
-VOID
-UnregisterAllRamDisks (
- VOID
- )
-{
- LIST_ENTRY *Entry;
- LIST_ENTRY *NextEntry;
- RAM_DISK_PRIVATE_DATA *PrivateData;
-
- if (!IsListEmpty (&RegisteredRamDisks)) {
- BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {
- PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
-
- gBS->UninstallMultipleProtocolInterfaces (
- PrivateData->Handle,
- &gEfiBlockIoProtocolGuid,
- &PrivateData->BlockIo,
- &gEfiBlockIo2ProtocolGuid,
- &PrivateData->BlockIo2,
- &gEfiDevicePathProtocolGuid,
- (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath,
- NULL
- );
-
- RemoveEntryList (&PrivateData->ThisInstance);
-
- if (RamDiskCreateHii == PrivateData->CreateMethod) {
- //
- // If a RAM disk is created within HII, then the RamDiskDxe driver
- // driver is responsible for freeing the allocated memory for the
- // RAM disk.
- //
- FreePool ((VOID *)(UINTN)PrivateData->StartingAddr);
- }
-
- FreePool (PrivateData->DevicePath);
- FreePool (PrivateData);
- }
- }
-}
-
-/**
- This function allows a caller to extract the current configuration for one
- or more named elements from the target driver.
-
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
- @param[in] Request A null-terminated Unicode string in
- <ConfigRequest> format.
- @param[out] Progress On return, points to a character in the Request
- string. Points to the string's null terminator if
- request was successful. Points to the most recent
- '&' before the first failing name/value pair (or
- the beginning of the string if the failure is in
- the first name/value pair) if the request was not
- successful.
- @param[out] Results A null-terminated Unicode string in
- <ConfigAltResp> format which has all values filled
- in for the names in the Request string. String to
- be allocated by the called function.
-
- @retval EFI_SUCCESS The Results is filled with the requested
- values.
- @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
- @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in
- this driver.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskExtractConfig (
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
- IN CONST EFI_STRING Request,
- OUT EFI_STRING *Progress,
- OUT EFI_STRING *Results
- )
-{
- if ((Progress == NULL) || (Results == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- *Progress = Request;
- return EFI_NOT_FOUND;
-}
-
-/**
- This function processes the results of changes in configuration.
-
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
- @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
- format.
- @param[out] Progress A pointer to a string filled in with the offset of
- the most recent '&' before the first failing
- name/value pair (or the beginning of the string if
- the failure is in the first name/value pair) or
- the terminating NULL if all was successful.
-
- @retval EFI_SUCCESS The Results is processed successfully.
- @retval EFI_INVALID_PARAMETER Configuration is NULL.
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in
- this driver.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskRouteConfig (
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
- IN CONST EFI_STRING Configuration,
- OUT EFI_STRING *Progress
- )
-{
- if ((Configuration == NULL) || (Progress == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- *Progress = Configuration;
-
- return EFI_NOT_FOUND;
-}
-
-/**
- Allocate memory and register the RAM disk created within RamDiskDxe
- driver HII.
-
- @param[in] Size If creating raw, size of the RAM disk to create.
- If creating from file, zero.
- @param[in] FileHandle If creating raw, NULL. If creating from file, the
- file handle.
- @param[in] MemoryType Type of memory to be used to create RAM Disk.
-
- @retval EFI_SUCCESS RAM disk is created and registered.
- @retval EFI_OUT_OF_RESOURCES Not enough storage is available to match the
- size required.
-
-**/
-EFI_STATUS
-HiiCreateRamDisk (
- IN UINT64 Size,
- IN EFI_FILE_HANDLE FileHandle,
- IN UINT8 MemoryType
- )
-{
- EFI_STATUS Status;
- UINTN BufferSize;
- UINT64 *StartingAddr;
- EFI_INPUT_KEY Key;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- RAM_DISK_PRIVATE_DATA *PrivateData;
- EFI_FILE_INFO *FileInformation;
-
- FileInformation = NULL;
- StartingAddr = NULL;
-
- if (FileHandle != NULL) {
- //
- // Create from file.
- //
- FileInformation = FileInfo (FileHandle);
- if (NULL == FileInformation) {
- do {
- CreatePopUp (
- EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
- &Key,
- L"",
- L"Not enough memory to get the file information!",
- L"Press ENTER to continue ...",
- L"",
- NULL
- );
- } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
-
- return EFI_OUT_OF_RESOURCES;
- }
-
- //
- // Update the size of RAM disk according to the file size.
- //
- Size = FileInformation->FileSize;
- }
-
- if (Size > (UINTN)-1) {
- do {
- CreatePopUp (
- EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
- &Key,
- L"",
- L"The given RAM disk size is too large!",
- L"Press ENTER to continue ...",
- L"",
- NULL
- );
- } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
-
- return EFI_OUT_OF_RESOURCES;
- }
-
- if (MemoryType == RAM_DISK_BOOT_SERVICE_DATA_MEMORY) {
- Status = gBS->AllocatePool (
- EfiBootServicesData,
- (UINTN)Size,
- (VOID **)&StartingAddr
- );
- } else if (MemoryType == RAM_DISK_RESERVED_MEMORY) {
- Status = gBS->AllocatePool (
- EfiReservedMemoryType,
- (UINTN)Size,
- (VOID **)&StartingAddr
- );
- } else {
- Status = EFI_INVALID_PARAMETER;
- }
-
- if ((StartingAddr == NULL) || EFI_ERROR (Status)) {
- do {
- CreatePopUp (
- EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
- &Key,
- L"",
- L"Not enough memory to create the RAM disk!",
- L"Press ENTER to continue ...",
- L"",
- NULL
- );
- } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
-
- return EFI_OUT_OF_RESOURCES;
- }
-
- if (FileHandle != NULL) {
- //
- // Copy the file content to the RAM disk.
- //
- BufferSize = (UINTN)Size;
- FileHandle->Read (
- FileHandle,
- &BufferSize,
- (VOID *)(UINTN)StartingAddr
- );
- if (BufferSize != FileInformation->FileSize) {
- do {
- CreatePopUp (
- EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
- &Key,
- L"",
- L"File content read error!",
- L"Press ENTER to continue ...",
- L"",
- NULL
- );
- } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
-
- return EFI_DEVICE_ERROR;
- }
- }
-
- //
- // Register the newly created RAM disk.
- //
- Status = RamDiskRegister (
- ((UINT64)(UINTN)StartingAddr),
- Size,
- &gEfiVirtualDiskGuid,
- NULL,
- &DevicePath
- );
- if (EFI_ERROR (Status)) {
- do {
- CreatePopUp (
- EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
- &Key,
- L"",
- L"Fail to register the newly created RAM disk!",
- L"Press ENTER to continue ...",
- L"",
- NULL
- );
- } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
-
- return Status;
- }
-
- //
- // If RAM disk is created within HII, memory should be freed when the
- // RAM disk is unregisterd.
- //
- PrivateData = RAM_DISK_PRIVATE_FROM_THIS (RegisteredRamDisks.BackLink);
- PrivateData->CreateMethod = RamDiskCreateHii;
-
- return EFI_SUCCESS;
-}
-
-/**
- This function updates the registered RAM disks list on the main form.
-
- @param[in, out] ConfigPrivate
- Private data for configurating hii data for RAM
- disks.
-
-**/
-VOID
-UpdateMainForm (
- IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate
- )
-{
- VOID *StartOpCodeHandle;
- VOID *EndOpCodeHandle;
- EFI_IFR_GUID_LABEL *StartLabel;
- EFI_IFR_GUID_LABEL *EndLabel;
- LIST_ENTRY *Entry;
- UINTN Index;
- RAM_DISK_PRIVATE_DATA *PrivateData;
- CHAR16 *String;
- CHAR16 RamDiskStr[128];
- EFI_STRING_ID StringId;
-
- //
- // Init OpCode Handle
- //
- StartOpCodeHandle = HiiAllocateOpCodeHandle ();
- ASSERT (StartOpCodeHandle != NULL);
-
- EndOpCodeHandle = HiiAllocateOpCodeHandle ();
- ASSERT (EndOpCodeHandle != NULL);
-
- //
- // Create Hii Extend Label OpCode as the start opcode
- //
- StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
- StartOpCodeHandle,
- &gEfiIfrTianoGuid,
- NULL,
- sizeof (EFI_IFR_GUID_LABEL)
- );
- StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
- StartLabel->Number = MAIN_LABEL_LIST_START;
-
- //
- // Create Hii Extend Label OpCode as the end opcode
- //
- EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
- EndOpCodeHandle,
- &gEfiIfrTianoGuid,
- NULL,
- sizeof (EFI_IFR_GUID_LABEL)
- );
- EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
- EndLabel->Number = MAIN_LABEL_LIST_END;
-
- Index = 0;
- BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
- PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
- PrivateData->CheckBoxId = (EFI_QUESTION_ID)
- (MAIN_CHECKBOX_QUESTION_ID_START + Index);
- //
- // CheckBox is unchecked by default.
- //
- PrivateData->CheckBoxChecked = FALSE;
- String = RamDiskStr;
-
- UnicodeSPrint (
- String,
- sizeof (RamDiskStr),
- L" RAM Disk %d: [0x%lx, 0x%lx]\n",
- Index,
- PrivateData->StartingAddr,
- PrivateData->StartingAddr + PrivateData->Size - 1
- );
-
- StringId = HiiSetString (ConfigPrivate->HiiHandle, 0, RamDiskStr, NULL);
- ASSERT (StringId != 0);
-
- HiiCreateCheckBoxOpCode (
- StartOpCodeHandle,
- PrivateData->CheckBoxId,
- 0,
- 0,
- StringId,
- STRING_TOKEN (STR_RAM_DISK_LIST_HELP),
- EFI_IFR_FLAG_CALLBACK,
- 0,
- NULL
- );
-
- Index++;
- }
-
- HiiUpdateForm (
- ConfigPrivate->HiiHandle,
- &gRamDiskFormSetGuid,
- MAIN_FORM_ID,
- StartOpCodeHandle,
- EndOpCodeHandle
- );
-
- HiiFreeOpCodeHandle (StartOpCodeHandle);
- HiiFreeOpCodeHandle (EndOpCodeHandle);
-}
-
-/**
- This function processes the results of changes in configuration.
-
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
- @param[in] Action Specifies the type of action taken by the browser.
- @param[in] QuestionId A unique value which is sent to the original
- exporting driver so that it can identify the type
- of data to expect.
- @param[in] Type The type of value for the question.
- @param[in] Value A pointer to the data being sent to the original
- exporting driver.
- @param[out] ActionRequest On return, points to the action requested by the
- callback function.
-
- @retval EFI_SUCCESS The callback successfully handled the action.
- @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
- variable and its data.
- @retval EFI_DEVICE_ERROR The variable could not be saved.
- @retval EFI_UNSUPPORTED The specified Action is not supported by the
- callback.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskCallback (
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
- IN EFI_BROWSER_ACTION Action,
- IN EFI_QUESTION_ID QuestionId,
- IN UINT8 Type,
- IN EFI_IFR_TYPE_VALUE *Value,
- OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
- )
-{
- EFI_STATUS Status;
- RAM_DISK_PRIVATE_DATA *PrivateData;
- RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
- EFI_DEVICE_PATH_PROTOCOL *FileDevPath;
- EFI_FILE_HANDLE FileHandle;
- LIST_ENTRY *Entry;
- LIST_ENTRY *NextEntry;
-
- if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- ConfigPrivate = RAM_DISK_CONFIG_PRIVATE_FROM_THIS (This);
-
- if (Action == EFI_BROWSER_ACTION_RETRIEVE) {
- Status = EFI_UNSUPPORTED;
- if (QuestionId == CREATE_RAW_SIZE_QUESTION_ID) {
- Value->u64 = EFI_PAGE_SIZE;
- ConfigPrivate->ConfigStore.Size = EFI_PAGE_SIZE;
- Status = EFI_SUCCESS;
- } else if (QuestionId == CREATE_RAW_MEMORY_TYPE_QUESTION_ID) {
- Value->u8 = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;
- ConfigPrivate->ConfigStore.MemType = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;
- Status = EFI_SUCCESS;
- }
-
- return Status;
- }
-
- if ((Action != EFI_BROWSER_ACTION_CHANGED) &&
- (Action != EFI_BROWSER_ACTION_CHANGING) &&
- (Action != EFI_BROWSER_ACTION_FORM_OPEN))
- {
- return EFI_UNSUPPORTED;
- }
-
- //
- // Update the RAM disk list show at the main form first.
- //
- if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
- Status = EFI_UNSUPPORTED;
- if (QuestionId == MAIN_GOTO_FILE_EXPLORER_ID) {
- UpdateMainForm (ConfigPrivate);
- Status = EFI_SUCCESS;
- }
-
- return Status;
- }
-
- Status = EFI_SUCCESS;
-
- if (Action == EFI_BROWSER_ACTION_CHANGING) {
- switch (QuestionId) {
- case MAIN_GOTO_FILE_EXPLORER_ID:
- Status = ChooseFile (NULL, NULL, NULL, &FileDevPath);
- if (EFI_ERROR (Status)) {
- break;
- }
-
- if (FileDevPath != NULL) {
- //
- // Open the file.
- //
- Status = EfiOpenFileByDevicePath (
- &FileDevPath,
- &FileHandle,
- EFI_FILE_MODE_READ,
- 0
- );
- if (EFI_ERROR (Status)) {
- break;
- }
-
- //
- // Create from file, RAM disk size is zero. It will be updated
- // according to the file size.
- //
- Status = HiiCreateRamDisk (
- 0,
- FileHandle,
- ConfigPrivate->ConfigStore.MemType
- );
- if (EFI_ERROR (Status)) {
- break;
- }
-
- //
- // Refresh the registered RAM disks list.
- //
- UpdateMainForm (ConfigPrivate);
- }
-
- break;
-
- default:
- break;
- }
- } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
- switch (QuestionId) {
- case MAIN_REMOVE_RD_QUESTION_ID:
- //
- // Remove the selected RAM disks
- //
- BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {
- PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
- if (PrivateData->CheckBoxChecked) {
- RamDiskUnregister (
- (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath
- );
- }
- }
-
- UpdateMainForm (ConfigPrivate);
-
- *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
- break;
-
- case CREATE_RAW_SIZE_QUESTION_ID:
- ConfigPrivate->ConfigStore.Size = Value->u64;
- break;
-
- case CREATE_RAW_MEMORY_TYPE_QUESTION_ID:
- ConfigPrivate->ConfigStore.MemType = Value->u8;
- break;
-
- case CREATE_RAW_SUBMIT_QUESTION_ID:
- //
- // Create raw, FileHandle is NULL.
- //
- Status = HiiCreateRamDisk (
- ConfigPrivate->ConfigStore.Size,
- NULL,
- ConfigPrivate->ConfigStore.MemType
- );
- if (EFI_ERROR (Status)) {
- break;
- }
-
- //
- // Refresh the registered RAM disks list.
- //
- UpdateMainForm (ConfigPrivate);
-
- *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
- break;
-
- case CREATE_RAW_DISCARD_QUESTION_ID:
- *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
- break;
-
- default:
- //
- // QuestionIds for checkboxes
- //
- if ((QuestionId >= MAIN_CHECKBOX_QUESTION_ID_START) &&
- (QuestionId < CREATE_RAW_RAM_DISK_FORM_ID))
- {
- BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
- PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
- if (PrivateData->CheckBoxId == QuestionId) {
- PrivateData->CheckBoxChecked = (BOOLEAN)(Value->u8 != 0);
- }
- }
- }
-
- break;
- }
- }
-
- return EFI_SUCCESS;
-}
+/** @file
+ HII Config Access protocol implementation of RamDiskDxe driver.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2016-2018 Hewlett Packard Enterprise Development LP<BR>
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "RamDiskImpl.h"
+
+CHAR16 mRamDiskStorageName[] = L"RAM_DISK_CONFIGURATION";
+
+RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate = {
+ RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE,
+ {
+ EFI_PAGE_SIZE,
+ RAM_DISK_BOOT_SERVICE_DATA_MEMORY
+ },
+ {
+ RamDiskExtractConfig,
+ RamDiskRouteConfig,
+ RamDiskCallback
+ }
+};
+
+HII_VENDOR_DEVICE_PATH mRamDiskHiiVendorDevicePath = {
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ {
+ (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
+ (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
+ }
+ },
+ RAM_DISK_FORM_SET_GUID
+ },
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ (UINT8)(END_DEVICE_PATH_LENGTH),
+ (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
+ }
+ }
+};
+
+/**
+ This function publish the RAM disk configuration Form.
+
+ @param[in, out] ConfigPrivateData
+ Points to RAM disk configuration private data.
+
+ @retval EFI_SUCCESS HII Form is installed successfully.
+ @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
+ @retval Others Other errors as indicated.
+
+**/
+EFI_STATUS
+InstallRamDiskConfigForm (
+ IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
+ )
+{
+ EFI_STATUS Status;
+ EFI_HII_HANDLE HiiHandle;
+ EFI_HANDLE DriverHandle;
+ EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
+
+ DriverHandle = NULL;
+ ConfigAccess = &ConfigPrivateData->ConfigAccess;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &DriverHandle,
+ &gEfiDevicePathProtocolGuid,
+ &mRamDiskHiiVendorDevicePath,
+ &gEfiHiiConfigAccessProtocolGuid,
+ ConfigAccess,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ ConfigPrivateData->DriverHandle = DriverHandle;
+
+ //
+ // Publish the HII package list
+ //
+ HiiHandle = HiiAddPackages (
+ &gRamDiskFormSetGuid,
+ DriverHandle,
+ RamDiskDxeStrings,
+ RamDiskHiiBin,
+ NULL
+ );
+ if (HiiHandle == NULL) {
+ gBS->UninstallMultipleProtocolInterfaces (
+ DriverHandle,
+ &gEfiDevicePathProtocolGuid,
+ &mRamDiskHiiVendorDevicePath,
+ &gEfiHiiConfigAccessProtocolGuid,
+ ConfigAccess,
+ NULL
+ );
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ ConfigPrivateData->HiiHandle = HiiHandle;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function removes RAM disk configuration Form.
+
+ @param[in, out] ConfigPrivateData
+ Points to RAM disk configuration private data.
+
+**/
+VOID
+UninstallRamDiskConfigForm (
+ IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
+ )
+{
+ //
+ // Uninstall HII package list
+ //
+ if (ConfigPrivateData->HiiHandle != NULL) {
+ HiiRemovePackages (ConfigPrivateData->HiiHandle);
+ ConfigPrivateData->HiiHandle = NULL;
+ }
+
+ //
+ // Uninstall HII Config Access Protocol
+ //
+ if (ConfigPrivateData->DriverHandle != NULL) {
+ gBS->UninstallMultipleProtocolInterfaces (
+ ConfigPrivateData->DriverHandle,
+ &gEfiDevicePathProtocolGuid,
+ &mRamDiskHiiVendorDevicePath,
+ &gEfiHiiConfigAccessProtocolGuid,
+ &ConfigPrivateData->ConfigAccess,
+ NULL
+ );
+ ConfigPrivateData->DriverHandle = NULL;
+ }
+
+ FreePool (ConfigPrivateData);
+}
+
+/**
+ Unregister all registered RAM disks.
+
+**/
+VOID
+UnregisterAllRamDisks (
+ VOID
+ )
+{
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *NextEntry;
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+
+ if (!IsListEmpty (&RegisteredRamDisks)) {
+ BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {
+ PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
+
+ gBS->UninstallMultipleProtocolInterfaces (
+ PrivateData->Handle,
+ &gEfiBlockIoProtocolGuid,
+ &PrivateData->BlockIo,
+ &gEfiBlockIo2ProtocolGuid,
+ &PrivateData->BlockIo2,
+ &gEfiDevicePathProtocolGuid,
+ (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath,
+ NULL
+ );
+
+ RemoveEntryList (&PrivateData->ThisInstance);
+
+ if (RamDiskCreateHii == PrivateData->CreateMethod) {
+ //
+ // If a RAM disk is created within HII, then the RamDiskDxe driver
+ // driver is responsible for freeing the allocated memory for the
+ // RAM disk.
+ //
+ FreePool ((VOID *)(UINTN)PrivateData->StartingAddr);
+ }
+
+ FreePool (PrivateData->DevicePath);
+ FreePool (PrivateData);
+ }
+ }
+}
+
+/**
+ This function allows a caller to extract the current configuration for one
+ or more named elements from the target driver.
+
+ @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
+ @param[in] Request A null-terminated Unicode string in
+ <ConfigRequest> format.
+ @param[out] Progress On return, points to a character in the Request
+ string. Points to the string's null terminator if
+ request was successful. Points to the most recent
+ '&' before the first failing name/value pair (or
+ the beginning of the string if the failure is in
+ the first name/value pair) if the request was not
+ successful.
+ @param[out] Results A null-terminated Unicode string in
+ <ConfigAltResp> format which has all values filled
+ in for the names in the Request string. String to
+ be allocated by the called function.
+
+ @retval EFI_SUCCESS The Results is filled with the requested
+ values.
+ @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
+ @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in
+ this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskExtractConfig (
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
+ IN CONST EFI_STRING Request,
+ OUT EFI_STRING *Progress,
+ OUT EFI_STRING *Results
+ )
+{
+ if ((Progress == NULL) || (Results == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Progress = Request;
+ return EFI_NOT_FOUND;
+}
+
+/**
+ This function processes the results of changes in configuration.
+
+ @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
+ @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
+ format.
+ @param[out] Progress A pointer to a string filled in with the offset of
+ the most recent '&' before the first failing
+ name/value pair (or the beginning of the string if
+ the failure is in the first name/value pair) or
+ the terminating NULL if all was successful.
+
+ @retval EFI_SUCCESS The Results is processed successfully.
+ @retval EFI_INVALID_PARAMETER Configuration is NULL.
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in
+ this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskRouteConfig (
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
+ IN CONST EFI_STRING Configuration,
+ OUT EFI_STRING *Progress
+ )
+{
+ if ((Configuration == NULL) || (Progress == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Progress = Configuration;
+
+ return EFI_NOT_FOUND;
+}
+
+/**
+ Allocate memory and register the RAM disk created within RamDiskDxe
+ driver HII.
+
+ @param[in] Size If creating raw, size of the RAM disk to create.
+ If creating from file, zero.
+ @param[in] FileHandle If creating raw, NULL. If creating from file, the
+ file handle.
+ @param[in] MemoryType Type of memory to be used to create RAM Disk.
+
+ @retval EFI_SUCCESS RAM disk is created and registered.
+ @retval EFI_OUT_OF_RESOURCES Not enough storage is available to match the
+ size required.
+
+**/
+EFI_STATUS
+HiiCreateRamDisk (
+ IN UINT64 Size,
+ IN EFI_FILE_HANDLE FileHandle,
+ IN UINT8 MemoryType
+ )
+{
+ EFI_STATUS Status;
+ UINTN BufferSize;
+ UINT64 *StartingAddr;
+ EFI_INPUT_KEY Key;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ EFI_FILE_INFO *FileInformation;
+
+ FileInformation = NULL;
+ StartingAddr = NULL;
+
+ if (FileHandle != NULL) {
+ //
+ // Create from file.
+ //
+ FileInformation = FileInfo (FileHandle);
+ if (NULL == FileInformation) {
+ do {
+ CreatePopUp (
+ EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+ &Key,
+ L"",
+ L"Not enough memory to get the file information!",
+ L"Press ENTER to continue ...",
+ L"",
+ NULL
+ );
+ } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
+
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Update the size of RAM disk according to the file size.
+ //
+ Size = FileInformation->FileSize;
+ }
+
+ if (Size > (UINTN)-1) {
+ do {
+ CreatePopUp (
+ EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+ &Key,
+ L"",
+ L"The given RAM disk size is too large!",
+ L"Press ENTER to continue ...",
+ L"",
+ NULL
+ );
+ } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
+
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ if (MemoryType == RAM_DISK_BOOT_SERVICE_DATA_MEMORY) {
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ (UINTN)Size,
+ (VOID **)&StartingAddr
+ );
+ } else if (MemoryType == RAM_DISK_RESERVED_MEMORY) {
+ Status = gBS->AllocatePool (
+ EfiReservedMemoryType,
+ (UINTN)Size,
+ (VOID **)&StartingAddr
+ );
+ } else {
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ if ((StartingAddr == NULL) || EFI_ERROR (Status)) {
+ do {
+ CreatePopUp (
+ EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+ &Key,
+ L"",
+ L"Not enough memory to create the RAM disk!",
+ L"Press ENTER to continue ...",
+ L"",
+ NULL
+ );
+ } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
+
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ if (FileHandle != NULL) {
+ //
+ // Copy the file content to the RAM disk.
+ //
+ BufferSize = (UINTN)Size;
+ FileHandle->Read (
+ FileHandle,
+ &BufferSize,
+ (VOID *)(UINTN)StartingAddr
+ );
+ if (BufferSize != FileInformation->FileSize) {
+ do {
+ CreatePopUp (
+ EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+ &Key,
+ L"",
+ L"File content read error!",
+ L"Press ENTER to continue ...",
+ L"",
+ NULL
+ );
+ } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
+
+ return EFI_DEVICE_ERROR;
+ }
+ }
+
+ //
+ // Register the newly created RAM disk.
+ //
+ Status = RamDiskRegister (
+ ((UINT64)(UINTN)StartingAddr),
+ Size,
+ &gEfiVirtualDiskGuid,
+ NULL,
+ &DevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ do {
+ CreatePopUp (
+ EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
+ &Key,
+ L"",
+ L"Fail to register the newly created RAM disk!",
+ L"Press ENTER to continue ...",
+ L"",
+ NULL
+ );
+ } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
+
+ return Status;
+ }
+
+ //
+ // If RAM disk is created within HII, memory should be freed when the
+ // RAM disk is unregisterd.
+ //
+ PrivateData = RAM_DISK_PRIVATE_FROM_THIS (RegisteredRamDisks.BackLink);
+ PrivateData->CreateMethod = RamDiskCreateHii;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function updates the registered RAM disks list on the main form.
+
+ @param[in, out] ConfigPrivate
+ Private data for configurating hii data for RAM
+ disks.
+
+**/
+VOID
+UpdateMainForm (
+ IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate
+ )
+{
+ VOID *StartOpCodeHandle;
+ VOID *EndOpCodeHandle;
+ EFI_IFR_GUID_LABEL *StartLabel;
+ EFI_IFR_GUID_LABEL *EndLabel;
+ LIST_ENTRY *Entry;
+ UINTN Index;
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ CHAR16 *String;
+ CHAR16 RamDiskStr[128];
+ EFI_STRING_ID StringId;
+
+ //
+ // Init OpCode Handle
+ //
+ StartOpCodeHandle = HiiAllocateOpCodeHandle ();
+ ASSERT (StartOpCodeHandle != NULL);
+
+ EndOpCodeHandle = HiiAllocateOpCodeHandle ();
+ ASSERT (EndOpCodeHandle != NULL);
+
+ //
+ // Create Hii Extend Label OpCode as the start opcode
+ //
+ StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
+ StartOpCodeHandle,
+ &gEfiIfrTianoGuid,
+ NULL,
+ sizeof (EFI_IFR_GUID_LABEL)
+ );
+ StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
+ StartLabel->Number = MAIN_LABEL_LIST_START;
+
+ //
+ // Create Hii Extend Label OpCode as the end opcode
+ //
+ EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (
+ EndOpCodeHandle,
+ &gEfiIfrTianoGuid,
+ NULL,
+ sizeof (EFI_IFR_GUID_LABEL)
+ );
+ EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;
+ EndLabel->Number = MAIN_LABEL_LIST_END;
+
+ Index = 0;
+ BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
+ PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
+ PrivateData->CheckBoxId = (EFI_QUESTION_ID)
+ (MAIN_CHECKBOX_QUESTION_ID_START + Index);
+ //
+ // CheckBox is unchecked by default.
+ //
+ PrivateData->CheckBoxChecked = FALSE;
+ String = RamDiskStr;
+
+ UnicodeSPrint (
+ String,
+ sizeof (RamDiskStr),
+ L" RAM Disk %d: [0x%lx, 0x%lx]\n",
+ Index,
+ PrivateData->StartingAddr,
+ PrivateData->StartingAddr + PrivateData->Size - 1
+ );
+
+ StringId = HiiSetString (ConfigPrivate->HiiHandle, 0, RamDiskStr, NULL);
+ ASSERT (StringId != 0);
+
+ HiiCreateCheckBoxOpCode (
+ StartOpCodeHandle,
+ PrivateData->CheckBoxId,
+ 0,
+ 0,
+ StringId,
+ STRING_TOKEN (STR_RAM_DISK_LIST_HELP),
+ EFI_IFR_FLAG_CALLBACK,
+ 0,
+ NULL
+ );
+
+ Index++;
+ }
+
+ HiiUpdateForm (
+ ConfigPrivate->HiiHandle,
+ &gRamDiskFormSetGuid,
+ MAIN_FORM_ID,
+ StartOpCodeHandle,
+ EndOpCodeHandle
+ );
+
+ HiiFreeOpCodeHandle (StartOpCodeHandle);
+ HiiFreeOpCodeHandle (EndOpCodeHandle);
+}
+
+/**
+ This function processes the results of changes in configuration.
+
+ @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
+ @param[in] Action Specifies the type of action taken by the browser.
+ @param[in] QuestionId A unique value which is sent to the original
+ exporting driver so that it can identify the type
+ of data to expect.
+ @param[in] Type The type of value for the question.
+ @param[in] Value A pointer to the data being sent to the original
+ exporting driver.
+ @param[out] ActionRequest On return, points to the action requested by the
+ callback function.
+
+ @retval EFI_SUCCESS The callback successfully handled the action.
+ @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
+ variable and its data.
+ @retval EFI_DEVICE_ERROR The variable could not be saved.
+ @retval EFI_UNSUPPORTED The specified Action is not supported by the
+ callback.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskCallback (
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
+ IN EFI_BROWSER_ACTION Action,
+ IN EFI_QUESTION_ID QuestionId,
+ IN UINT8 Type,
+ IN EFI_IFR_TYPE_VALUE *Value,
+ OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
+ )
+{
+ EFI_STATUS Status;
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
+ EFI_DEVICE_PATH_PROTOCOL *FileDevPath;
+ EFI_FILE_HANDLE FileHandle;
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *NextEntry;
+
+ if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ ConfigPrivate = RAM_DISK_CONFIG_PRIVATE_FROM_THIS (This);
+
+ if (Action == EFI_BROWSER_ACTION_RETRIEVE) {
+ Status = EFI_UNSUPPORTED;
+ if (QuestionId == CREATE_RAW_SIZE_QUESTION_ID) {
+ Value->u64 = EFI_PAGE_SIZE;
+ ConfigPrivate->ConfigStore.Size = EFI_PAGE_SIZE;
+ Status = EFI_SUCCESS;
+ } else if (QuestionId == CREATE_RAW_MEMORY_TYPE_QUESTION_ID) {
+ Value->u8 = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;
+ ConfigPrivate->ConfigStore.MemType = RAM_DISK_BOOT_SERVICE_DATA_MEMORY;
+ Status = EFI_SUCCESS;
+ }
+
+ return Status;
+ }
+
+ if ((Action != EFI_BROWSER_ACTION_CHANGED) &&
+ (Action != EFI_BROWSER_ACTION_CHANGING) &&
+ (Action != EFI_BROWSER_ACTION_FORM_OPEN))
+ {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Update the RAM disk list show at the main form first.
+ //
+ if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
+ Status = EFI_UNSUPPORTED;
+ if (QuestionId == MAIN_GOTO_FILE_EXPLORER_ID) {
+ UpdateMainForm (ConfigPrivate);
+ Status = EFI_SUCCESS;
+ }
+
+ return Status;
+ }
+
+ Status = EFI_SUCCESS;
+
+ if (Action == EFI_BROWSER_ACTION_CHANGING) {
+ switch (QuestionId) {
+ case MAIN_GOTO_FILE_EXPLORER_ID:
+ Status = ChooseFile (NULL, NULL, NULL, &FileDevPath);
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ if (FileDevPath != NULL) {
+ //
+ // Open the file.
+ //
+ Status = EfiOpenFileByDevicePath (
+ &FileDevPath,
+ &FileHandle,
+ EFI_FILE_MODE_READ,
+ 0
+ );
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ //
+ // Create from file, RAM disk size is zero. It will be updated
+ // according to the file size.
+ //
+ Status = HiiCreateRamDisk (
+ 0,
+ FileHandle,
+ ConfigPrivate->ConfigStore.MemType
+ );
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ //
+ // Refresh the registered RAM disks list.
+ //
+ UpdateMainForm (ConfigPrivate);
+ }
+
+ break;
+
+ default:
+ break;
+ }
+ } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
+ switch (QuestionId) {
+ case MAIN_REMOVE_RD_QUESTION_ID:
+ //
+ // Remove the selected RAM disks
+ //
+ BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {
+ PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
+ if (PrivateData->CheckBoxChecked) {
+ RamDiskUnregister (
+ (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath
+ );
+ }
+ }
+
+ UpdateMainForm (ConfigPrivate);
+
+ *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
+ break;
+
+ case CREATE_RAW_SIZE_QUESTION_ID:
+ ConfigPrivate->ConfigStore.Size = Value->u64;
+ break;
+
+ case CREATE_RAW_MEMORY_TYPE_QUESTION_ID:
+ ConfigPrivate->ConfigStore.MemType = Value->u8;
+ break;
+
+ case CREATE_RAW_SUBMIT_QUESTION_ID:
+ //
+ // Create raw, FileHandle is NULL.
+ //
+ Status = HiiCreateRamDisk (
+ ConfigPrivate->ConfigStore.Size,
+ NULL,
+ ConfigPrivate->ConfigStore.MemType
+ );
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ //
+ // Refresh the registered RAM disks list.
+ //
+ UpdateMainForm (ConfigPrivate);
+
+ *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
+ break;
+
+ case CREATE_RAW_DISCARD_QUESTION_ID:
+ *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT;
+ break;
+
+ default:
+ //
+ // QuestionIds for checkboxes
+ //
+ if ((QuestionId >= MAIN_CHECKBOX_QUESTION_ID_START) &&
+ (QuestionId < CREATE_RAW_RAM_DISK_FORM_ID))
+ {
+ BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
+ PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
+ if (PrivateData->CheckBoxId == QuestionId) {
+ PrivateData->CheckBoxChecked = (BOOLEAN)(Value->u8 != 0);
+ }
+ }
+ }
+
+ break;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h
index e194951805..183f452882 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h
@@ -1,602 +1,602 @@
-/** @file
- The header file of RamDiskDxe driver.
-
- Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
- Copyright (c) Microsoft Corporation.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _RAM_DISK_IMPL_H_
-#define _RAM_DISK_IMPL_H_
-
-#include <Uefi.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/DebugLib.h>
-#include <Library/UefiLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiHiiServicesLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/HiiLib.h>
-#include <Library/FileExplorerLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/PrintLib.h>
-#include <Library/PcdLib.h>
-#include <Library/DxeServicesLib.h>
-#include <Protocol/RamDisk.h>
-#include <Protocol/BlockIo.h>
-#include <Protocol/BlockIo2.h>
-#include <Protocol/HiiConfigAccess.h>
-#include <Protocol/SimpleFileSystem.h>
-#include <Protocol/AcpiTable.h>
-#include <Protocol/AcpiSystemDescriptionTable.h>
-#include <Guid/MdeModuleHii.h>
-#include <Guid/RamDiskHii.h>
-#include <Guid/FileInfo.h>
-#include <IndustryStandard/Acpi61.h>
-
-#include "RamDiskNVData.h"
-
-///
-/// RAM disk general definitions and declarations
-///
-
-//
-// Default block size for RAM disk
-//
-#define RAM_DISK_DEFAULT_BLOCK_SIZE 512
-
-//
-// RamDiskDxe driver maintains a list of registered RAM disks.
-//
-extern LIST_ENTRY RegisteredRamDisks;
-
-//
-// Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
-//
-extern EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol;
-extern EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol;
-
-//
-// RAM Disk create method.
-//
-typedef enum _RAM_DISK_CREATE_METHOD {
- RamDiskCreateOthers = 0,
- RamDiskCreateHii
-} RAM_DISK_CREATE_METHOD;
-
-//
-// RamDiskDxe driver maintains a list of registered RAM disks.
-// The struct contains the list entry and the information of each RAM
-// disk
-//
-typedef struct {
- UINTN Signature;
-
- EFI_HANDLE Handle;
-
- EFI_BLOCK_IO_PROTOCOL BlockIo;
- EFI_BLOCK_IO2_PROTOCOL BlockIo2;
- EFI_BLOCK_IO_MEDIA Media;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
-
- UINT64 StartingAddr;
- UINT64 Size;
- EFI_GUID TypeGuid;
- UINT16 InstanceNumber;
- RAM_DISK_CREATE_METHOD CreateMethod;
- BOOLEAN InNfit;
- EFI_QUESTION_ID CheckBoxId;
- BOOLEAN CheckBoxChecked;
-
- LIST_ENTRY ThisInstance;
-} RAM_DISK_PRIVATE_DATA;
-
-#define RAM_DISK_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'D', 'S', 'K')
-#define RAM_DISK_PRIVATE_FROM_BLKIO(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo, RAM_DISK_PRIVATE_DATA_SIGNATURE)
-#define RAM_DISK_PRIVATE_FROM_BLKIO2(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo2, RAM_DISK_PRIVATE_DATA_SIGNATURE)
-#define RAM_DISK_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_PRIVATE_DATA, ThisInstance, RAM_DISK_PRIVATE_DATA_SIGNATURE)
-
-///
-/// RAM disk HII-related definitions and declarations
-///
-
-//
-// Tool generated IFR binary data and String package data
-//
-extern UINT8 RamDiskHiiBin[];
-extern UINT8 RamDiskDxeStrings[];
-
-typedef struct {
- VENDOR_DEVICE_PATH VendorDevicePath;
- EFI_DEVICE_PATH_PROTOCOL End;
-} HII_VENDOR_DEVICE_PATH;
-
-typedef struct {
- UINTN Signature;
-
- RAM_DISK_CONFIGURATION ConfigStore;
-
- EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
- EFI_HANDLE DriverHandle;
- EFI_HII_HANDLE HiiHandle;
-} RAM_DISK_CONFIG_PRIVATE_DATA;
-
-extern RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate;
-
-#define RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'C', 'F', 'G')
-#define RAM_DISK_CONFIG_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_CONFIG_PRIVATE_DATA, ConfigAccess, RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE)
-
-/**
- Register a RAM disk with specified address, size and type.
-
- @param[in] RamDiskBase The base address of registered RAM disk.
- @param[in] RamDiskSize The size of registered RAM disk.
- @param[in] RamDiskType The type of registered RAM disk. The GUID can be
- any of the values defined in section 9.3.6.9, or a
- vendor defined GUID.
- @param[in] ParentDevicePath
- Pointer to the parent device path. If there is no
- parent device path then ParentDevicePath is NULL.
- @param[out] DevicePath On return, points to a pointer to the device path
- of the RAM disk device.
- If ParentDevicePath is not NULL, the returned
- DevicePath is created by appending a RAM disk node
- to the parent device path. If ParentDevicePath is
- NULL, the returned DevicePath is a RAM disk device
- path without appending. This function is
- responsible for allocating the buffer DevicePath
- with the boot service AllocatePool().
-
- @retval EFI_SUCCESS The RAM disk is registered successfully.
- @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
- RamDiskSize is 0.
- @retval EFI_ALREADY_STARTED A Device Path Protocol instance to be created
- is already present in the handle database.
- @retval EFI_OUT_OF_RESOURCES The RAM disk register operation fails due to
- resource limitation.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskRegister (
- IN UINT64 RamDiskBase,
- IN UINT64 RamDiskSize,
- IN EFI_GUID *RamDiskType,
- IN EFI_DEVICE_PATH *ParentDevicePath OPTIONAL,
- OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
- );
-
-/**
- Unregister a RAM disk specified by DevicePath.
-
- @param[in] DevicePath A pointer to the device path that describes a RAM
- Disk device.
-
- @retval EFI_SUCCESS The RAM disk is unregistered successfully.
- @retval EFI_INVALID_PARAMETER DevicePath is NULL.
- @retval EFI_UNSUPPORTED The device specified by DevicePath is not a
- valid ramdisk device path and not supported
- by the driver.
- @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
- exist.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskUnregister (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- );
-
-/**
- Initialize the BlockIO protocol of a RAM disk device.
-
- @param[in] PrivateData Points to RAM disk private data.
-
-**/
-VOID
-RamDiskInitBlockIo (
- IN RAM_DISK_PRIVATE_DATA *PrivateData
- );
-
-/**
- Reset the Block Device.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] ExtendedVerification
- Driver may perform diagnostics on reset.
-
- @retval EFI_SUCCESS The device was reset.
- @retval EFI_DEVICE_ERROR The device is not functioning properly and
- could not be reset.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoReset (
- IN EFI_BLOCK_IO_PROTOCOL *This,
- IN BOOLEAN ExtendedVerification
- );
-
-/**
- Read BufferSize bytes from Lba into Buffer.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId Id of the media, changes every time the media is
- replaced.
- @param[in] Lba The starting Logical Block Address to read from.
- @param[in] BufferSize Size of Buffer, must be a multiple of device block
- size.
- @param[out] Buffer A pointer to the destination buffer for the data.
- The caller is responsible for either having
- implicit or explicit ownership of the buffer.
-
- @retval EFI_SUCCESS The data was read correctly from the device.
- @retval EFI_DEVICE_ERROR The device reported an error while performing
- the read.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
- device.
- @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
- size of the device.
- @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
- valid, or the buffer is not on proper alignment.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoReadBlocks (
- IN EFI_BLOCK_IO_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- );
-
-/**
- Write BufferSize bytes from Lba into Buffer.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId The media ID that the write request is for.
- @param[in] Lba The starting logical block address to be written.
- The caller is responsible for writing to only
- legitimate locations.
- @param[in] BufferSize Size of Buffer, must be a multiple of device block
- size.
- @param[in] Buffer A pointer to the source buffer for the data.
-
- @retval EFI_SUCCESS The data was written correctly to the device.
- @retval EFI_WRITE_PROTECTED The device can not be written to.
- @retval EFI_DEVICE_ERROR The device reported an error while performing
- the write.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
- device.
- @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
- size of the device.
- @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
- valid, or the buffer is not on proper alignment.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoWriteBlocks (
- IN EFI_BLOCK_IO_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN UINTN BufferSize,
- IN VOID *Buffer
- );
-
-/**
- Flush the Block Device.
-
- @param[in] This Indicates a pointer to the calling context.
-
- @retval EFI_SUCCESS All outstanding data was written to the device.
- @retval EFI_DEVICE_ERROR The device reported an error while writting
- back the data
- @retval EFI_NO_MEDIA There is no media in the device.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIoFlushBlocks (
- IN EFI_BLOCK_IO_PROTOCOL *This
- );
-
-/**
- Resets the block device hardware.
-
- @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
- @param[in] ExtendedVerification The flag about if extend verificate.
-
- @retval EFI_SUCCESS The device was reset.
- @retval EFI_DEVICE_ERROR The block device is not functioning correctly
- and could not be reset.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2Reset (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN BOOLEAN ExtendedVerification
- );
-
-/**
- Reads the requested number of blocks from the device.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId The media ID that the read request is for.
- @param[in] Lba The starting logical block address to read
- from on the device.
- @param[in, out] Token A pointer to the token associated with the
- transaction.
- @param[in] BufferSize The size of the Buffer in bytes. This must be
- a multiple of the intrinsic block size of the
- device.
- @param[out] Buffer A pointer to the destination buffer for the
- data. The caller is responsible for either
- having implicit or explicit ownership of the
- buffer.
-
- @retval EFI_SUCCESS The read request was queued if Token->Event
- is not NULL. The data was read correctly from
- the device if the Token->Event is NULL.
- @retval EFI_DEVICE_ERROR The device reported an error while attempting
- to perform the read operation.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
- @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
- the intrinsic block size of the device.
- @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
- valid, or the buffer is not on proper
- alignment.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2ReadBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token,
- IN UINTN BufferSize,
- OUT VOID *Buffer
- );
-
-/**
- Writes a specified number of blocks to the device.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in] MediaId The media ID that the write request is for.
- @param[in] Lba The starting logical block address to be
- written. The caller is responsible for
- writing to only legitimate locations.
- @param[in, out] Token A pointer to the token associated with the
- transaction.
- @param[in] BufferSize The size in bytes of Buffer. This must be a
- multiple of the intrinsic block size of the
- device.
- @param[in] Buffer A pointer to the source buffer for the data.
-
- @retval EFI_SUCCESS The write request was queued if Event is not
- NULL. The data was written correctly to the
- device if the Event is NULL.
- @retval EFI_WRITE_PROTECTED The device cannot be written to.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
- @retval EFI_DEVICE_ERROR The device reported an error while attempting
- to perform the write operation.
- @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
- the intrinsic block size of the device.
- @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
- valid, or the buffer is not on proper
- alignment.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2WriteBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token,
- IN UINTN BufferSize,
- IN VOID *Buffer
- );
-
-/**
- Flushes all modified data to a physical block device.
-
- @param[in] This Indicates a pointer to the calling context.
- @param[in, out] Token A pointer to the token associated with the
- transaction.
-
- @retval EFI_SUCCESS The flush request was queued if Event is not
- NULL. All outstanding data was written
- correctly to the device if the Event is NULL.
- @retval EFI_DEVICE_ERROR The device reported an error while attempting
- to write data.
- @retval EFI_WRITE_PROTECTED The device cannot be written to.
- @retval EFI_NO_MEDIA There is no media in the device.
- @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskBlkIo2FlushBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token
- );
-
-/**
- This function publish the RAM disk configuration Form.
-
- @param[in, out] ConfigPrivateData
- Points to RAM disk configuration private data.
-
- @retval EFI_SUCCESS HII Form is installed successfully.
- @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
- @retval Others Other errors as indicated.
-
-**/
-EFI_STATUS
-InstallRamDiskConfigForm (
- IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
- );
-
-/**
- This function removes RAM disk configuration Form.
-
- @param[in, out] ConfigPrivateData
- Points to RAM disk configuration private data.
-
-**/
-VOID
-UninstallRamDiskConfigForm (
- IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
- );
-
-/**
- Unregister all registered RAM disks.
-
-**/
-VOID
-UnregisterAllRamDisks (
- VOID
- );
-
-/**
- This function allows a caller to extract the current configuration for one
- or more named elements from the target driver.
-
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
- @param[in] Request A null-terminated Unicode string in
- <ConfigRequest> format.
- @param[out] Progress On return, points to a character in the Request
- string. Points to the string's null terminator if
- request was successful. Points to the most recent
- '&' before the first failing name/value pair (or
- the beginning of the string if the failure is in
- the first name/value pair) if the request was not
- successful.
- @param[out] Results A null-terminated Unicode string in
- <ConfigAltResp> format which has all values filled
- in for the names in the Request string. String to
- be allocated by the called function.
-
- @retval EFI_SUCCESS The Results is filled with the requested
- values.
- @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
- @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in
- this driver.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskExtractConfig (
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
- IN CONST EFI_STRING Request,
- OUT EFI_STRING *Progress,
- OUT EFI_STRING *Results
- );
-
-/**
- This function processes the results of changes in configuration.
-
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
- @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
- format.
- @param[out] Progress A pointer to a string filled in with the offset of
- the most recent '&' before the first failing
- name/value pair (or the beginning of the string if
- the failure is in the first name/value pair) or
- the terminating NULL if all was successful.
-
- @retval EFI_SUCCESS The Results is processed successfully.
- @retval EFI_INVALID_PARAMETER Configuration is NULL.
- @retval EFI_NOT_FOUND Routing data doesn't match any storage in
- this driver.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskRouteConfig (
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
- IN CONST EFI_STRING Configuration,
- OUT EFI_STRING *Progress
- );
-
-/**
- This function processes the results of changes in configuration.
-
- @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
- @param[in] Action Specifies the type of action taken by the browser.
- @param[in] QuestionId A unique value which is sent to the original
- exporting driver so that it can identify the type
- of data to expect.
- @param[in] Type The type of value for the question.
- @param[in] Value A pointer to the data being sent to the original
- exporting driver.
- @param[out] ActionRequest On return, points to the action requested by the
- callback function.
-
- @retval EFI_SUCCESS The callback successfully handled the action.
- @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
- variable and its data.
- @retval EFI_DEVICE_ERROR The variable could not be saved.
- @retval EFI_UNSUPPORTED The specified Action is not supported by the
- callback.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskCallback (
- IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
- IN EFI_BROWSER_ACTION Action,
- IN EFI_QUESTION_ID QuestionId,
- IN UINT8 Type,
- IN EFI_IFR_TYPE_VALUE *Value,
- OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
- );
-
-/**
- This function gets the file information from an open file descriptor,
- and stores it in a buffer allocated from pool.
-
- @param[in] FHand File Handle.
-
- @return A pointer to a buffer with file information or NULL is returned.
-
-**/
-EFI_FILE_INFO *
-FileInfo (
- IN EFI_FILE_HANDLE FHand
- );
-
-/**
- Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
- table.
-
- @param[in] PrivateData Points to RAM disk private data.
-
- @retval EFI_SUCCESS The RAM disk NFIT has been published.
- @retval others The RAM disk NFIT has not been published.
-
-**/
-EFI_STATUS
-RamDiskPublishNfit (
- IN RAM_DISK_PRIVATE_DATA *PrivateData
- );
-
-#endif
+/** @file
+ The header file of RamDiskDxe driver.
+
+ Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _RAM_DISK_IMPL_H_
+#define _RAM_DISK_IMPL_H_
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiHiiServicesLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/HiiLib.h>
+#include <Library/FileExplorerLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/PrintLib.h>
+#include <Library/PcdLib.h>
+#include <Library/DxeServicesLib.h>
+#include <Protocol/RamDisk.h>
+#include <Protocol/BlockIo.h>
+#include <Protocol/BlockIo2.h>
+#include <Protocol/HiiConfigAccess.h>
+#include <Protocol/SimpleFileSystem.h>
+#include <Protocol/AcpiTable.h>
+#include <Protocol/AcpiSystemDescriptionTable.h>
+#include <Guid/MdeModuleHii.h>
+#include <Guid/RamDiskHii.h>
+#include <Guid/FileInfo.h>
+#include <IndustryStandard/Acpi61.h>
+
+#include "RamDiskNVData.h"
+
+///
+/// RAM disk general definitions and declarations
+///
+
+//
+// Default block size for RAM disk
+//
+#define RAM_DISK_DEFAULT_BLOCK_SIZE 512
+
+//
+// RamDiskDxe driver maintains a list of registered RAM disks.
+//
+extern LIST_ENTRY RegisteredRamDisks;
+
+//
+// Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
+//
+extern EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol;
+extern EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol;
+
+//
+// RAM Disk create method.
+//
+typedef enum _RAM_DISK_CREATE_METHOD {
+ RamDiskCreateOthers = 0,
+ RamDiskCreateHii
+} RAM_DISK_CREATE_METHOD;
+
+//
+// RamDiskDxe driver maintains a list of registered RAM disks.
+// The struct contains the list entry and the information of each RAM
+// disk
+//
+typedef struct {
+ UINTN Signature;
+
+ EFI_HANDLE Handle;
+
+ EFI_BLOCK_IO_PROTOCOL BlockIo;
+ EFI_BLOCK_IO2_PROTOCOL BlockIo2;
+ EFI_BLOCK_IO_MEDIA Media;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ UINT64 StartingAddr;
+ UINT64 Size;
+ EFI_GUID TypeGuid;
+ UINT16 InstanceNumber;
+ RAM_DISK_CREATE_METHOD CreateMethod;
+ BOOLEAN InNfit;
+ EFI_QUESTION_ID CheckBoxId;
+ BOOLEAN CheckBoxChecked;
+
+ LIST_ENTRY ThisInstance;
+} RAM_DISK_PRIVATE_DATA;
+
+#define RAM_DISK_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'D', 'S', 'K')
+#define RAM_DISK_PRIVATE_FROM_BLKIO(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo, RAM_DISK_PRIVATE_DATA_SIGNATURE)
+#define RAM_DISK_PRIVATE_FROM_BLKIO2(a) CR (a, RAM_DISK_PRIVATE_DATA, BlockIo2, RAM_DISK_PRIVATE_DATA_SIGNATURE)
+#define RAM_DISK_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_PRIVATE_DATA, ThisInstance, RAM_DISK_PRIVATE_DATA_SIGNATURE)
+
+///
+/// RAM disk HII-related definitions and declarations
+///
+
+//
+// Tool generated IFR binary data and String package data
+//
+extern UINT8 RamDiskHiiBin[];
+extern UINT8 RamDiskDxeStrings[];
+
+typedef struct {
+ VENDOR_DEVICE_PATH VendorDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} HII_VENDOR_DEVICE_PATH;
+
+typedef struct {
+ UINTN Signature;
+
+ RAM_DISK_CONFIGURATION ConfigStore;
+
+ EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
+ EFI_HANDLE DriverHandle;
+ EFI_HII_HANDLE HiiHandle;
+} RAM_DISK_CONFIG_PRIVATE_DATA;
+
+extern RAM_DISK_CONFIG_PRIVATE_DATA mRamDiskConfigPrivateDataTemplate;
+
+#define RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'C', 'F', 'G')
+#define RAM_DISK_CONFIG_PRIVATE_FROM_THIS(a) CR (a, RAM_DISK_CONFIG_PRIVATE_DATA, ConfigAccess, RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE)
+
+/**
+ Register a RAM disk with specified address, size and type.
+
+ @param[in] RamDiskBase The base address of registered RAM disk.
+ @param[in] RamDiskSize The size of registered RAM disk.
+ @param[in] RamDiskType The type of registered RAM disk. The GUID can be
+ any of the values defined in section 9.3.6.9, or a
+ vendor defined GUID.
+ @param[in] ParentDevicePath
+ Pointer to the parent device path. If there is no
+ parent device path then ParentDevicePath is NULL.
+ @param[out] DevicePath On return, points to a pointer to the device path
+ of the RAM disk device.
+ If ParentDevicePath is not NULL, the returned
+ DevicePath is created by appending a RAM disk node
+ to the parent device path. If ParentDevicePath is
+ NULL, the returned DevicePath is a RAM disk device
+ path without appending. This function is
+ responsible for allocating the buffer DevicePath
+ with the boot service AllocatePool().
+
+ @retval EFI_SUCCESS The RAM disk is registered successfully.
+ @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
+ RamDiskSize is 0.
+ @retval EFI_ALREADY_STARTED A Device Path Protocol instance to be created
+ is already present in the handle database.
+ @retval EFI_OUT_OF_RESOURCES The RAM disk register operation fails due to
+ resource limitation.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskRegister (
+ IN UINT64 RamDiskBase,
+ IN UINT64 RamDiskSize,
+ IN EFI_GUID *RamDiskType,
+ IN EFI_DEVICE_PATH *ParentDevicePath OPTIONAL,
+ OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
+ );
+
+/**
+ Unregister a RAM disk specified by DevicePath.
+
+ @param[in] DevicePath A pointer to the device path that describes a RAM
+ Disk device.
+
+ @retval EFI_SUCCESS The RAM disk is unregistered successfully.
+ @retval EFI_INVALID_PARAMETER DevicePath is NULL.
+ @retval EFI_UNSUPPORTED The device specified by DevicePath is not a
+ valid ramdisk device path and not supported
+ by the driver.
+ @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
+ exist.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskUnregister (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ );
+
+/**
+ Initialize the BlockIO protocol of a RAM disk device.
+
+ @param[in] PrivateData Points to RAM disk private data.
+
+**/
+VOID
+RamDiskInitBlockIo (
+ IN RAM_DISK_PRIVATE_DATA *PrivateData
+ );
+
+/**
+ Reset the Block Device.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] ExtendedVerification
+ Driver may perform diagnostics on reset.
+
+ @retval EFI_SUCCESS The device was reset.
+ @retval EFI_DEVICE_ERROR The device is not functioning properly and
+ could not be reset.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoReset (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ );
+
+/**
+ Read BufferSize bytes from Lba into Buffer.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId Id of the media, changes every time the media is
+ replaced.
+ @param[in] Lba The starting Logical Block Address to read from.
+ @param[in] BufferSize Size of Buffer, must be a multiple of device block
+ size.
+ @param[out] Buffer A pointer to the destination buffer for the data.
+ The caller is responsible for either having
+ implicit or explicit ownership of the buffer.
+
+ @retval EFI_SUCCESS The data was read correctly from the device.
+ @retval EFI_DEVICE_ERROR The device reported an error while performing
+ the read.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId does not matched the current
+ device.
+ @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
+ size of the device.
+ @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
+ valid, or the buffer is not on proper alignment.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoReadBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ );
+
+/**
+ Write BufferSize bytes from Lba into Buffer.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId The media ID that the write request is for.
+ @param[in] Lba The starting logical block address to be written.
+ The caller is responsible for writing to only
+ legitimate locations.
+ @param[in] BufferSize Size of Buffer, must be a multiple of device block
+ size.
+ @param[in] Buffer A pointer to the source buffer for the data.
+
+ @retval EFI_SUCCESS The data was written correctly to the device.
+ @retval EFI_WRITE_PROTECTED The device can not be written to.
+ @retval EFI_DEVICE_ERROR The device reported an error while performing
+ the write.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current
+ device.
+ @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block
+ size of the device.
+ @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
+ valid, or the buffer is not on proper alignment.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoWriteBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ );
+
+/**
+ Flush the Block Device.
+
+ @param[in] This Indicates a pointer to the calling context.
+
+ @retval EFI_SUCCESS All outstanding data was written to the device.
+ @retval EFI_DEVICE_ERROR The device reported an error while writting
+ back the data
+ @retval EFI_NO_MEDIA There is no media in the device.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIoFlushBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This
+ );
+
+/**
+ Resets the block device hardware.
+
+ @param[in] This The pointer of EFI_BLOCK_IO2_PROTOCOL.
+ @param[in] ExtendedVerification The flag about if extend verificate.
+
+ @retval EFI_SUCCESS The device was reset.
+ @retval EFI_DEVICE_ERROR The block device is not functioning correctly
+ and could not be reset.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2Reset (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ );
+
+/**
+ Reads the requested number of blocks from the device.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId The media ID that the read request is for.
+ @param[in] Lba The starting logical block address to read
+ from on the device.
+ @param[in, out] Token A pointer to the token associated with the
+ transaction.
+ @param[in] BufferSize The size of the Buffer in bytes. This must be
+ a multiple of the intrinsic block size of the
+ device.
+ @param[out] Buffer A pointer to the destination buffer for the
+ data. The caller is responsible for either
+ having implicit or explicit ownership of the
+ buffer.
+
+ @retval EFI_SUCCESS The read request was queued if Token->Event
+ is not NULL. The data was read correctly from
+ the device if the Token->Event is NULL.
+ @retval EFI_DEVICE_ERROR The device reported an error while attempting
+ to perform the read operation.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
+ @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
+ the intrinsic block size of the device.
+ @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
+ valid, or the buffer is not on proper
+ alignment.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2ReadBlocksEx (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ );
+
+/**
+ Writes a specified number of blocks to the device.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in] MediaId The media ID that the write request is for.
+ @param[in] Lba The starting logical block address to be
+ written. The caller is responsible for
+ writing to only legitimate locations.
+ @param[in, out] Token A pointer to the token associated with the
+ transaction.
+ @param[in] BufferSize The size in bytes of Buffer. This must be a
+ multiple of the intrinsic block size of the
+ device.
+ @param[in] Buffer A pointer to the source buffer for the data.
+
+ @retval EFI_SUCCESS The write request was queued if Event is not
+ NULL. The data was written correctly to the
+ device if the Event is NULL.
+ @retval EFI_WRITE_PROTECTED The device cannot be written to.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
+ @retval EFI_DEVICE_ERROR The device reported an error while attempting
+ to perform the write operation.
+ @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
+ the intrinsic block size of the device.
+ @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not
+ valid, or the buffer is not on proper
+ alignment.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2WriteBlocksEx (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ );
+
+/**
+ Flushes all modified data to a physical block device.
+
+ @param[in] This Indicates a pointer to the calling context.
+ @param[in, out] Token A pointer to the token associated with the
+ transaction.
+
+ @retval EFI_SUCCESS The flush request was queued if Event is not
+ NULL. All outstanding data was written
+ correctly to the device if the Event is NULL.
+ @retval EFI_DEVICE_ERROR The device reported an error while attempting
+ to write data.
+ @retval EFI_WRITE_PROTECTED The device cannot be written to.
+ @retval EFI_NO_MEDIA There is no media in the device.
+ @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
+ @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
+ lack of resources.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskBlkIo2FlushBlocksEx (
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token
+ );
+
+/**
+ This function publish the RAM disk configuration Form.
+
+ @param[in, out] ConfigPrivateData
+ Points to RAM disk configuration private data.
+
+ @retval EFI_SUCCESS HII Form is installed successfully.
+ @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
+ @retval Others Other errors as indicated.
+
+**/
+EFI_STATUS
+InstallRamDiskConfigForm (
+ IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
+ );
+
+/**
+ This function removes RAM disk configuration Form.
+
+ @param[in, out] ConfigPrivateData
+ Points to RAM disk configuration private data.
+
+**/
+VOID
+UninstallRamDiskConfigForm (
+ IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData
+ );
+
+/**
+ Unregister all registered RAM disks.
+
+**/
+VOID
+UnregisterAllRamDisks (
+ VOID
+ );
+
+/**
+ This function allows a caller to extract the current configuration for one
+ or more named elements from the target driver.
+
+ @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
+ @param[in] Request A null-terminated Unicode string in
+ <ConfigRequest> format.
+ @param[out] Progress On return, points to a character in the Request
+ string. Points to the string's null terminator if
+ request was successful. Points to the most recent
+ '&' before the first failing name/value pair (or
+ the beginning of the string if the failure is in
+ the first name/value pair) if the request was not
+ successful.
+ @param[out] Results A null-terminated Unicode string in
+ <ConfigAltResp> format which has all values filled
+ in for the names in the Request string. String to
+ be allocated by the called function.
+
+ @retval EFI_SUCCESS The Results is filled with the requested
+ values.
+ @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
+ @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in
+ this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskExtractConfig (
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
+ IN CONST EFI_STRING Request,
+ OUT EFI_STRING *Progress,
+ OUT EFI_STRING *Results
+ );
+
+/**
+ This function processes the results of changes in configuration.
+
+ @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
+ @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
+ format.
+ @param[out] Progress A pointer to a string filled in with the offset of
+ the most recent '&' before the first failing
+ name/value pair (or the beginning of the string if
+ the failure is in the first name/value pair) or
+ the terminating NULL if all was successful.
+
+ @retval EFI_SUCCESS The Results is processed successfully.
+ @retval EFI_INVALID_PARAMETER Configuration is NULL.
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in
+ this driver.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskRouteConfig (
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
+ IN CONST EFI_STRING Configuration,
+ OUT EFI_STRING *Progress
+ );
+
+/**
+ This function processes the results of changes in configuration.
+
+ @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
+ @param[in] Action Specifies the type of action taken by the browser.
+ @param[in] QuestionId A unique value which is sent to the original
+ exporting driver so that it can identify the type
+ of data to expect.
+ @param[in] Type The type of value for the question.
+ @param[in] Value A pointer to the data being sent to the original
+ exporting driver.
+ @param[out] ActionRequest On return, points to the action requested by the
+ callback function.
+
+ @retval EFI_SUCCESS The callback successfully handled the action.
+ @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
+ variable and its data.
+ @retval EFI_DEVICE_ERROR The variable could not be saved.
+ @retval EFI_UNSUPPORTED The specified Action is not supported by the
+ callback.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskCallback (
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
+ IN EFI_BROWSER_ACTION Action,
+ IN EFI_QUESTION_ID QuestionId,
+ IN UINT8 Type,
+ IN EFI_IFR_TYPE_VALUE *Value,
+ OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
+ );
+
+/**
+ This function gets the file information from an open file descriptor,
+ and stores it in a buffer allocated from pool.
+
+ @param[in] FHand File Handle.
+
+ @return A pointer to a buffer with file information or NULL is returned.
+
+**/
+EFI_FILE_INFO *
+FileInfo (
+ IN EFI_FILE_HANDLE FHand
+ );
+
+/**
+ Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
+ table.
+
+ @param[in] PrivateData Points to RAM disk private data.
+
+ @retval EFI_SUCCESS The RAM disk NFIT has been published.
+ @retval others The RAM disk NFIT has not been published.
+
+**/
+EFI_STATUS
+RamDiskPublishNfit (
+ IN RAM_DISK_PRIVATE_DATA *PrivateData
+ );
+
+#endif
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskNVData.h b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskNVData.h
index 71935f0152..ca1721a4bc 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskNVData.h
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskNVData.h
@@ -1,44 +1,44 @@
-/** @file
- Header file for NV data structure definition.
-
- Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
- (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _RAM_DISK_NVDATA_H_
-#define _RAM_DISK_NVDATA_H_
-
-#include <Guid/HiiPlatformSetupFormset.h>
-#include <Guid/RamDiskHii.h>
-
-#define MAIN_FORM_ID 0x1000
-#define MAIN_GOTO_FILE_EXPLORER_ID 0x1001
-#define MAIN_REMOVE_RD_QUESTION_ID 0x1002
-#define MAIN_LABEL_LIST_START 0x1003
-#define MAIN_LABEL_LIST_END 0x1004
-#define MAIN_CHECKBOX_QUESTION_ID_START 0x1100
-
-#define CREATE_RAW_RAM_DISK_FORM_ID 0x2000
-#define CREATE_RAW_SIZE_QUESTION_ID 0x2001
-#define CREATE_RAW_SUBMIT_QUESTION_ID 0x2002
-#define CREATE_RAW_DISCARD_QUESTION_ID 0x2003
-#define CREATE_RAW_MEMORY_TYPE_QUESTION_ID 0x2004
-
-#define RAM_DISK_BOOT_SERVICE_DATA_MEMORY 0x00
-#define RAM_DISK_RESERVED_MEMORY 0x01
-#define RAM_DISK_MEMORY_TYPE_MAX 0x02
-
-typedef struct {
- //
- // The size of the RAM disk to be created.
- //
- UINT64 Size;
- //
- // Selected RAM Disk Memory Type
- //
- UINT8 MemType;
-} RAM_DISK_CONFIGURATION;
-
-#endif
+/** @file
+ Header file for NV data structure definition.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _RAM_DISK_NVDATA_H_
+#define _RAM_DISK_NVDATA_H_
+
+#include <Guid/HiiPlatformSetupFormset.h>
+#include <Guid/RamDiskHii.h>
+
+#define MAIN_FORM_ID 0x1000
+#define MAIN_GOTO_FILE_EXPLORER_ID 0x1001
+#define MAIN_REMOVE_RD_QUESTION_ID 0x1002
+#define MAIN_LABEL_LIST_START 0x1003
+#define MAIN_LABEL_LIST_END 0x1004
+#define MAIN_CHECKBOX_QUESTION_ID_START 0x1100
+
+#define CREATE_RAW_RAM_DISK_FORM_ID 0x2000
+#define CREATE_RAW_SIZE_QUESTION_ID 0x2001
+#define CREATE_RAW_SUBMIT_QUESTION_ID 0x2002
+#define CREATE_RAW_DISCARD_QUESTION_ID 0x2003
+#define CREATE_RAW_MEMORY_TYPE_QUESTION_ID 0x2004
+
+#define RAM_DISK_BOOT_SERVICE_DATA_MEMORY 0x00
+#define RAM_DISK_RESERVED_MEMORY 0x01
+#define RAM_DISK_MEMORY_TYPE_MAX 0x02
+
+typedef struct {
+ //
+ // The size of the RAM disk to be created.
+ //
+ UINT64 Size;
+ //
+ // Selected RAM Disk Memory Type
+ //
+ UINT8 MemType;
+} RAM_DISK_CONFIGURATION;
+
+#endif
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c
index 780cf0a016..af8e189e19 100644
--- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c
@@ -1,865 +1,865 @@
-/** @file
- The realization of EFI_RAM_DISK_PROTOCOL.
-
- Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
- (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
- Copyright (c) Microsoft Corporation.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "RamDiskImpl.h"
-
-RAM_DISK_PRIVATE_DATA mRamDiskPrivateDataTemplate = {
- RAM_DISK_PRIVATE_DATA_SIGNATURE,
- NULL
-};
-
-MEDIA_RAM_DISK_DEVICE_PATH mRamDiskDeviceNodeTemplate = {
- {
- MEDIA_DEVICE_PATH,
- MEDIA_RAM_DISK_DP,
- {
- (UINT8)(sizeof (MEDIA_RAM_DISK_DEVICE_PATH)),
- (UINT8)((sizeof (MEDIA_RAM_DISK_DEVICE_PATH)) >> 8)
- }
- }
-};
-
-BOOLEAN mRamDiskSsdtTableKeyValid = FALSE;
-UINTN mRamDiskSsdtTableKey;
-
-/**
- Initialize the RAM disk device node.
-
- @param[in] PrivateData Points to RAM disk private data.
- @param[in, out] RamDiskDevNode Points to the RAM disk device node.
-
-**/
-VOID
-RamDiskInitDeviceNode (
- IN RAM_DISK_PRIVATE_DATA *PrivateData,
- IN OUT MEDIA_RAM_DISK_DEVICE_PATH *RamDiskDevNode
- )
-{
- WriteUnaligned64 (
- (UINT64 *)&(RamDiskDevNode->StartingAddr[0]),
- (UINT64)PrivateData->StartingAddr
- );
- WriteUnaligned64 (
- (UINT64 *)&(RamDiskDevNode->EndingAddr[0]),
- (UINT64)PrivateData->StartingAddr + PrivateData->Size - 1
- );
- CopyGuid (&RamDiskDevNode->TypeGuid, &PrivateData->TypeGuid);
- RamDiskDevNode->Instance = PrivateData->InstanceNumber;
-}
-
-/**
- Initialize and publish NVDIMM root device SSDT in ACPI table.
-
- @retval EFI_SUCCESS The NVDIMM root device SSDT is published.
- @retval Others The NVDIMM root device SSDT is not published.
-
-**/
-EFI_STATUS
-RamDiskPublishSsdt (
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_ACPI_DESCRIPTION_HEADER *Table;
- UINTN SectionInstance;
- UINTN TableSize;
-
- Status = EFI_SUCCESS;
- SectionInstance = 0;
-
- //
- // Scan all the EFI raw section instances in FV to find the NVDIMM root
- // device SSDT.
- //
- while (TRUE) {
- Status = GetSectionFromFv (
- &gEfiCallerIdGuid,
- EFI_SECTION_RAW,
- SectionInstance,
- (VOID **)&Table,
- &TableSize
- );
- if (EFI_ERROR (Status)) {
- break;
- }
-
- if (Table->OemTableId == SIGNATURE_64 ('R', 'a', 'm', 'D', 'i', 's', 'k', ' ')) {
- Status = mAcpiTableProtocol->InstallAcpiTable (
- mAcpiTableProtocol,
- Table,
- TableSize,
- &mRamDiskSsdtTableKey
- );
- ASSERT_EFI_ERROR (Status);
-
- if (!EFI_ERROR (Status)) {
- mRamDiskSsdtTableKeyValid = TRUE;
- }
-
- FreePool (Table);
- return Status;
- } else {
- FreePool (Table);
- SectionInstance++;
- }
- }
-
- return Status;
-}
-
-/**
- Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
- table.
-
- @param[in] PrivateData Points to RAM disk private data.
-
- @retval EFI_SUCCESS The RAM disk NFIT has been published.
- @retval others The RAM disk NFIT has not been published.
-
-**/
-EFI_STATUS
-RamDiskPublishNfit (
- IN RAM_DISK_PRIVATE_DATA *PrivateData
- )
-{
- EFI_STATUS Status;
- EFI_MEMORY_DESCRIPTOR *MemoryMap;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
- EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
- UINTN TableIndex;
- VOID *TableHeader;
- EFI_ACPI_TABLE_VERSION TableVersion;
- UINTN TableKey;
- EFI_ACPI_DESCRIPTION_HEADER *NfitHeader;
- EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
- *SpaRange;
- VOID *Nfit;
- UINT32 NfitLen;
- UINTN MemoryMapSize;
- UINTN MapKey;
- UINTN DescriptorSize;
- UINT32 DescriptorVersion;
- UINT64 CurrentData;
- UINT8 Checksum;
- BOOLEAN MemoryFound;
-
- //
- // Get the EFI memory map.
- //
- MemoryMapSize = 0;
- MemoryMap = NULL;
- MemoryFound = FALSE;
-
- Status = gBS->GetMemoryMap (
- &MemoryMapSize,
- MemoryMap,
- &MapKey,
- &DescriptorSize,
- &DescriptorVersion
- );
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);
- do {
- MemoryMap = (EFI_MEMORY_DESCRIPTOR *)AllocatePool (MemoryMapSize);
- ASSERT (MemoryMap != NULL);
- Status = gBS->GetMemoryMap (
- &MemoryMapSize,
- MemoryMap,
- &MapKey,
- &DescriptorSize,
- &DescriptorVersion
- );
- if (EFI_ERROR (Status)) {
- FreePool (MemoryMap);
- }
- } while (Status == EFI_BUFFER_TOO_SMALL);
-
- ASSERT_EFI_ERROR (Status);
-
- MemoryMapEntry = MemoryMap;
- MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
- while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
- if ((MemoryMapEntry->Type == EfiReservedMemoryType) &&
- (MemoryMapEntry->PhysicalStart <= PrivateData->StartingAddr) &&
- (MemoryMapEntry->PhysicalStart +
- MultU64x32 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SIZE)
- >= PrivateData->StartingAddr + PrivateData->Size))
- {
- MemoryFound = TRUE;
- DEBUG ((
- DEBUG_INFO,
- "RamDiskPublishNfit: RAM disk with reserved memory type, will publish to NFIT.\n"
- ));
- break;
- }
-
- MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
- }
-
- FreePool (MemoryMap);
-
- if (!MemoryFound) {
- return EFI_NOT_FOUND;
- }
-
- //
- // Determine whether there is a NFIT already in the ACPI table.
- //
- Status = EFI_SUCCESS;
- TableIndex = 0;
- TableKey = 0;
- TableHeader = NULL;
-
- while (!EFI_ERROR (Status)) {
- Status = mAcpiSdtProtocol->GetAcpiTable (
- TableIndex,
- (EFI_ACPI_SDT_HEADER **)&TableHeader,
- &TableVersion,
- &TableKey
- );
- if (!EFI_ERROR (Status)) {
- TableIndex++;
-
- if (((EFI_ACPI_SDT_HEADER *)TableHeader)->Signature ==
- EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE)
- {
- break;
- }
- }
- }
-
- if (!EFI_ERROR (Status)) {
- //
- // A NFIT is already in the ACPI table.
- //
- DEBUG ((
- DEBUG_INFO,
- "RamDiskPublishNfit: A NFIT is already exist in the ACPI Table.\n"
- ));
-
- NfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)TableHeader;
- NfitLen = NfitHeader->Length + sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
- Nfit = AllocateZeroPool (NfitLen);
- if (Nfit == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- CopyMem (Nfit, TableHeader, NfitHeader->Length);
-
- //
- // Update the NFIT head pointer.
- //
- NfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)Nfit;
-
- //
- // Uninstall the origin NFIT from the ACPI table.
- //
- Status = mAcpiTableProtocol->UninstallAcpiTable (
- mAcpiTableProtocol,
- TableKey
- );
- ASSERT_EFI_ERROR (Status);
-
- if (EFI_ERROR (Status)) {
- FreePool (Nfit);
- return Status;
- }
-
- //
- // Append the System Physical Address (SPA) Range Structure at the end
- // of the origin NFIT.
- //
- SpaRange = (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *)
- ((UINT8 *)Nfit + NfitHeader->Length);
-
- //
- // Update the length field of the NFIT
- //
- NfitHeader->Length = NfitLen;
-
- //
- // The checksum will be updated after the new contents are appended.
- //
- NfitHeader->Checksum = 0;
- } else {
- //
- // Assumption is made that if no NFIT is in the ACPI table, there is no
- // NVDIMM root device in the \SB scope.
- // Therefore, a NVDIMM root device will be reported via Secondary System
- // Description Table (SSDT).
- //
- Status = RamDiskPublishSsdt ();
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // No NFIT is in the ACPI table, we will create one here.
- //
- DEBUG ((
- DEBUG_INFO,
- "RamDiskPublishNfit: No NFIT is in the ACPI Table, will create one.\n"
- ));
-
- NfitLen = sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE) +
- sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
- Nfit = AllocateZeroPool (NfitLen);
- if (Nfit == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- SpaRange = (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *)
- ((UINT8 *)Nfit + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
-
- NfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)Nfit;
- NfitHeader->Signature = EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE;
- NfitHeader->Length = NfitLen;
- NfitHeader->Revision = EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_REVISION;
- NfitHeader->Checksum = 0;
- NfitHeader->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
- NfitHeader->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
- NfitHeader->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
- CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
- CopyMem (NfitHeader->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (NfitHeader->OemId));
- CopyMem (&NfitHeader->OemTableId, &CurrentData, sizeof (UINT64));
- }
-
- //
- // Fill in the content of the SPA Range Structure.
- //
- SpaRange->Type = EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE;
- SpaRange->Length = sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
- SpaRange->SystemPhysicalAddressRangeBase = PrivateData->StartingAddr;
- SpaRange->SystemPhysicalAddressRangeLength = PrivateData->Size;
- CopyGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid);
-
- Checksum = CalculateCheckSum8 ((UINT8 *)Nfit, NfitHeader->Length);
- NfitHeader->Checksum = Checksum;
-
- //
- // Publish the NFIT to the ACPI table.
- // Note, since the NFIT might be modified by other driver, therefore, we
- // do not track the returning TableKey from the InstallAcpiTable().
- //
- Status = mAcpiTableProtocol->InstallAcpiTable (
- mAcpiTableProtocol,
- Nfit,
- NfitHeader->Length,
- &TableKey
- );
- ASSERT_EFI_ERROR (Status);
-
- FreePool (Nfit);
-
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- PrivateData->InNfit = TRUE;
-
- return EFI_SUCCESS;
-}
-
-/**
- Unpublish the RAM disk NVDIMM Firmware Interface Table (NFIT) from the
- ACPI table.
-
- @param[in] PrivateData Points to RAM disk private data.
-
- @retval EFI_SUCCESS The RAM disk NFIT has been unpublished.
- @retval others The RAM disk NFIT has not been unpublished.
-
-**/
-EFI_STATUS
-RamDiskUnpublishNfit (
- IN RAM_DISK_PRIVATE_DATA *PrivateData
- )
-{
- EFI_STATUS Status;
- UINTN TableIndex;
- VOID *TableHeader;
- EFI_ACPI_TABLE_VERSION TableVersion;
- UINTN TableKey;
- EFI_ACPI_DESCRIPTION_HEADER *NewNfitHeader;
- EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
- *SpaRange;
- VOID *NewNfit;
- VOID *NewNfitPtr;
- EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *NfitStructHeader;
- UINT32 NewNfitLen;
- UINT32 RemainLen;
- UINT8 Checksum;
-
- //
- // Find the NFIT in the ACPI table.
- //
- Status = EFI_SUCCESS;
- TableIndex = 0;
- TableKey = 0;
- TableHeader = NULL;
-
- while (!EFI_ERROR (Status)) {
- Status = mAcpiSdtProtocol->GetAcpiTable (
- TableIndex,
- (EFI_ACPI_SDT_HEADER **)&TableHeader,
- &TableVersion,
- &TableKey
- );
- if (!EFI_ERROR (Status)) {
- TableIndex++;
-
- if (((EFI_ACPI_SDT_HEADER *)TableHeader)->Signature ==
- EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE)
- {
- break;
- }
- }
- }
-
- if (EFI_ERROR (Status)) {
- //
- // No NFIT is found in the ACPI table.
- //
- return EFI_NOT_FOUND;
- }
-
- NewNfitLen = ((EFI_ACPI_DESCRIPTION_HEADER *)TableHeader)->Length -
- sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
-
- //
- // After removing this RAM disk from the NFIT, if no other structure is in
- // the NFIT, we just remove the NFIT and the SSDT which is used to report
- // the NVDIMM root device.
- //
- if (NewNfitLen == sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE)) {
- //
- // Remove the NFIT.
- //
- Status = mAcpiTableProtocol->UninstallAcpiTable (
- mAcpiTableProtocol,
- TableKey
- );
- ASSERT_EFI_ERROR (Status);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Remove the SSDT which is used by RamDiskDxe driver to report the NVDIMM
- // root device.
- // We do not care the return status since this SSDT might already be
- // uninstalled by other drivers to update the information of the NVDIMM
- // root device.
- //
- if (mRamDiskSsdtTableKeyValid) {
- mRamDiskSsdtTableKeyValid = FALSE;
-
- mAcpiTableProtocol->UninstallAcpiTable (
- mAcpiTableProtocol,
- mRamDiskSsdtTableKey
- );
- }
-
- return EFI_SUCCESS;
- }
-
- NewNfit = AllocateZeroPool (NewNfitLen);
- if (NewNfit == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- //
- // Get a copy of the old NFIT header content.
- //
- CopyMem (NewNfit, TableHeader, sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
- NewNfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)NewNfit;
- NewNfitHeader->Length = NewNfitLen;
- NewNfitHeader->Checksum = 0;
-
- //
- // Copy the content of required NFIT structures.
- //
- NewNfitPtr = (UINT8 *)NewNfit + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE);
- RemainLen = NewNfitLen - sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE);
- NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
- ((UINT8 *)TableHeader + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
- while (RemainLen > 0) {
- if ((NfitStructHeader->Type == EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE) &&
- (NfitStructHeader->Length == sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE)))
- {
- SpaRange = (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *)NfitStructHeader;
-
- if ((SpaRange->SystemPhysicalAddressRangeBase == PrivateData->StartingAddr) &&
- (SpaRange->SystemPhysicalAddressRangeLength == PrivateData->Size) &&
- (CompareGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid)))
- {
- //
- // Skip the SPA Range Structure for the RAM disk to be unpublished
- // from NFIT.
- //
- NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
- ((UINT8 *)NfitStructHeader + NfitStructHeader->Length);
- continue;
- }
- }
-
- //
- // Copy the content of origin NFIT.
- //
- CopyMem (NewNfitPtr, NfitStructHeader, NfitStructHeader->Length);
- NewNfitPtr = (UINT8 *)NewNfitPtr + NfitStructHeader->Length;
-
- //
- // Move to the header of next NFIT structure.
- //
- RemainLen -= NfitStructHeader->Length;
- NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
- ((UINT8 *)NfitStructHeader + NfitStructHeader->Length);
- }
-
- Checksum = CalculateCheckSum8 ((UINT8 *)NewNfit, NewNfitHeader->Length);
- NewNfitHeader->Checksum = Checksum;
-
- Status = mAcpiTableProtocol->UninstallAcpiTable (
- mAcpiTableProtocol,
- TableKey
- );
- ASSERT_EFI_ERROR (Status);
-
- if (EFI_ERROR (Status)) {
- FreePool (NewNfit);
- return Status;
- }
-
- //
- // Publish the NFIT to the ACPI table.
- // Note, since the NFIT might be modified by other driver, therefore, we
- // do not track the returning TableKey from the InstallAcpiTable().
- //
- Status = mAcpiTableProtocol->InstallAcpiTable (
- mAcpiTableProtocol,
- NewNfit,
- NewNfitLen,
- &TableKey
- );
- ASSERT_EFI_ERROR (Status);
-
- FreePool (NewNfit);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Register a RAM disk with specified address, size and type.
-
- @param[in] RamDiskBase The base address of registered RAM disk.
- @param[in] RamDiskSize The size of registered RAM disk.
- @param[in] RamDiskType The type of registered RAM disk. The GUID can be
- any of the values defined in section 9.3.6.9, or a
- vendor defined GUID.
- @param[in] ParentDevicePath
- Pointer to the parent device path. If there is no
- parent device path then ParentDevicePath is NULL.
- @param[out] DevicePath On return, points to a pointer to the device path
- of the RAM disk device.
- If ParentDevicePath is not NULL, the returned
- DevicePath is created by appending a RAM disk node
- to the parent device path. If ParentDevicePath is
- NULL, the returned DevicePath is a RAM disk device
- path without appending. This function is
- responsible for allocating the buffer DevicePath
- with the boot service AllocatePool().
-
- @retval EFI_SUCCESS The RAM disk is registered successfully.
- @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
- RamDiskSize is 0.
- @retval EFI_ALREADY_STARTED A Device Path Protocol instance to be created
- is already present in the handle database.
- @retval EFI_OUT_OF_RESOURCES The RAM disk register operation fails due to
- resource limitation.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskRegister (
- IN UINT64 RamDiskBase,
- IN UINT64 RamDiskSize,
- IN EFI_GUID *RamDiskType,
- IN EFI_DEVICE_PATH *ParentDevicePath OPTIONAL,
- OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
- )
-{
- EFI_STATUS Status;
- RAM_DISK_PRIVATE_DATA *PrivateData;
- RAM_DISK_PRIVATE_DATA *RegisteredPrivateData;
- MEDIA_RAM_DISK_DEVICE_PATH *RamDiskDevNode;
- UINTN DevicePathSize;
- LIST_ENTRY *Entry;
-
- if ((0 == RamDiskSize) || (NULL == RamDiskType) || (NULL == DevicePath)) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Add check to prevent data read across the memory boundary
- //
- if ((RamDiskSize > MAX_UINTN) ||
- (RamDiskBase > MAX_UINTN - RamDiskSize + 1))
- {
- return EFI_INVALID_PARAMETER;
- }
-
- RamDiskDevNode = NULL;
-
- //
- // Create a new RAM disk instance and initialize its private data
- //
- PrivateData = AllocateCopyPool (
- sizeof (RAM_DISK_PRIVATE_DATA),
- &mRamDiskPrivateDataTemplate
- );
- if (NULL == PrivateData) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- PrivateData->StartingAddr = RamDiskBase;
- PrivateData->Size = RamDiskSize;
- CopyGuid (&PrivateData->TypeGuid, RamDiskType);
- InitializeListHead (&PrivateData->ThisInstance);
-
- //
- // Generate device path information for the registered RAM disk
- //
- RamDiskDevNode = AllocateCopyPool (
- sizeof (MEDIA_RAM_DISK_DEVICE_PATH),
- &mRamDiskDeviceNodeTemplate
- );
- if (NULL == RamDiskDevNode) {
- Status = EFI_OUT_OF_RESOURCES;
- goto ErrorExit;
- }
-
- RamDiskInitDeviceNode (PrivateData, RamDiskDevNode);
-
- *DevicePath = AppendDevicePathNode (
- ParentDevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *)RamDiskDevNode
- );
- if (NULL == *DevicePath) {
- Status = EFI_OUT_OF_RESOURCES;
- goto ErrorExit;
- }
-
- PrivateData->DevicePath = *DevicePath;
-
- //
- // Check whether the created device path is already present in the handle
- // database
- //
- if (!IsListEmpty (&RegisteredRamDisks)) {
- DevicePathSize = GetDevicePathSize (PrivateData->DevicePath);
-
- BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
- RegisteredPrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
- if (DevicePathSize == GetDevicePathSize (RegisteredPrivateData->DevicePath)) {
- //
- // Compare device path
- //
- if ((CompareMem (
- PrivateData->DevicePath,
- RegisteredPrivateData->DevicePath,
- DevicePathSize
- )) == 0)
- {
- *DevicePath = NULL;
- Status = EFI_ALREADY_STARTED;
- goto ErrorExit;
- }
- }
- }
- }
-
- //
- // Fill Block IO protocol informations for the RAM disk
- //
- RamDiskInitBlockIo (PrivateData);
-
- //
- // Install EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO(2)_PROTOCOL on a new
- // handle
- //
- Status = gBS->InstallMultipleProtocolInterfaces (
- &PrivateData->Handle,
- &gEfiBlockIoProtocolGuid,
- &PrivateData->BlockIo,
- &gEfiBlockIo2ProtocolGuid,
- &PrivateData->BlockIo2,
- &gEfiDevicePathProtocolGuid,
- PrivateData->DevicePath,
- NULL
- );
- if (EFI_ERROR (Status)) {
- goto ErrorExit;
- }
-
- //
- // Insert the newly created one to the registered RAM disk list
- //
- InsertTailList (&RegisteredRamDisks, &PrivateData->ThisInstance);
-
- gBS->ConnectController (PrivateData->Handle, NULL, NULL, TRUE);
-
- FreePool (RamDiskDevNode);
-
- if ((mAcpiTableProtocol != NULL) && (mAcpiSdtProtocol != NULL)) {
- RamDiskPublishNfit (PrivateData);
- }
-
- return EFI_SUCCESS;
-
-ErrorExit:
- if (RamDiskDevNode != NULL) {
- FreePool (RamDiskDevNode);
- }
-
- if (PrivateData != NULL) {
- if (PrivateData->DevicePath) {
- FreePool (PrivateData->DevicePath);
- }
-
- FreePool (PrivateData);
- }
-
- return Status;
-}
-
-/**
- Unregister a RAM disk specified by DevicePath.
-
- @param[in] DevicePath A pointer to the device path that describes a RAM
- Disk device.
-
- @retval EFI_SUCCESS The RAM disk is unregistered successfully.
- @retval EFI_INVALID_PARAMETER DevicePath is NULL.
- @retval EFI_UNSUPPORTED The device specified by DevicePath is not a
- valid ramdisk device path and not supported
- by the driver.
- @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
- exist.
-
-**/
-EFI_STATUS
-EFIAPI
-RamDiskUnregister (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
- )
-{
- LIST_ENTRY *Entry;
- LIST_ENTRY *NextEntry;
- BOOLEAN Found;
- UINT64 StartingAddr;
- UINT64 EndingAddr;
- EFI_DEVICE_PATH_PROTOCOL *Header;
- MEDIA_RAM_DISK_DEVICE_PATH *RamDiskDevNode;
- RAM_DISK_PRIVATE_DATA *PrivateData;
-
- if (NULL == DevicePath) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Locate the RAM disk device node.
- //
- RamDiskDevNode = NULL;
- Header = DevicePath;
- do {
- //
- // Test if the current device node is a RAM disk.
- //
- if ((MEDIA_DEVICE_PATH == Header->Type) &&
- (MEDIA_RAM_DISK_DP == Header->SubType))
- {
- RamDiskDevNode = (MEDIA_RAM_DISK_DEVICE_PATH *)Header;
-
- break;
- }
-
- Header = NextDevicePathNode (Header);
- } while ((Header->Type != END_DEVICE_PATH_TYPE));
-
- if (NULL == RamDiskDevNode) {
- return EFI_UNSUPPORTED;
- }
-
- Found = FALSE;
- StartingAddr = ReadUnaligned64 ((UINT64 *)&(RamDiskDevNode->StartingAddr[0]));
- EndingAddr = ReadUnaligned64 ((UINT64 *)&(RamDiskDevNode->EndingAddr[0]));
-
- if (!IsListEmpty (&RegisteredRamDisks)) {
- BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {
- PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
-
- //
- // Unregister the RAM disk given by its starting address, ending address
- // and type guid.
- //
- if ((StartingAddr == PrivateData->StartingAddr) &&
- (EndingAddr == PrivateData->StartingAddr + PrivateData->Size - 1) &&
- (CompareGuid (&RamDiskDevNode->TypeGuid, &PrivateData->TypeGuid)))
- {
- //
- // Remove the content for this RAM disk in NFIT.
- //
- if (PrivateData->InNfit) {
- RamDiskUnpublishNfit (PrivateData);
- }
-
- //
- // Uninstall the EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO(2)_PROTOCOL
- //
- gBS->UninstallMultipleProtocolInterfaces (
- PrivateData->Handle,
- &gEfiBlockIoProtocolGuid,
- &PrivateData->BlockIo,
- &gEfiBlockIo2ProtocolGuid,
- &PrivateData->BlockIo2,
- &gEfiDevicePathProtocolGuid,
- (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath,
- NULL
- );
-
- RemoveEntryList (&PrivateData->ThisInstance);
-
- if (RamDiskCreateHii == PrivateData->CreateMethod) {
- //
- // If a RAM disk is created within HII, then the RamDiskDxe driver
- // driver is responsible for freeing the allocated memory for the
- // RAM disk.
- //
- FreePool ((VOID *)(UINTN)PrivateData->StartingAddr);
- }
-
- FreePool (PrivateData->DevicePath);
- FreePool (PrivateData);
- Found = TRUE;
-
- break;
- }
- }
- }
-
- if (TRUE == Found) {
- return EFI_SUCCESS;
- } else {
- return EFI_NOT_FOUND;
- }
-}
+/** @file
+ The realization of EFI_RAM_DISK_PROTOCOL.
+
+ Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+ Copyright (c) Microsoft Corporation.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "RamDiskImpl.h"
+
+RAM_DISK_PRIVATE_DATA mRamDiskPrivateDataTemplate = {
+ RAM_DISK_PRIVATE_DATA_SIGNATURE,
+ NULL
+};
+
+MEDIA_RAM_DISK_DEVICE_PATH mRamDiskDeviceNodeTemplate = {
+ {
+ MEDIA_DEVICE_PATH,
+ MEDIA_RAM_DISK_DP,
+ {
+ (UINT8)(sizeof (MEDIA_RAM_DISK_DEVICE_PATH)),
+ (UINT8)((sizeof (MEDIA_RAM_DISK_DEVICE_PATH)) >> 8)
+ }
+ }
+};
+
+BOOLEAN mRamDiskSsdtTableKeyValid = FALSE;
+UINTN mRamDiskSsdtTableKey;
+
+/**
+ Initialize the RAM disk device node.
+
+ @param[in] PrivateData Points to RAM disk private data.
+ @param[in, out] RamDiskDevNode Points to the RAM disk device node.
+
+**/
+VOID
+RamDiskInitDeviceNode (
+ IN RAM_DISK_PRIVATE_DATA *PrivateData,
+ IN OUT MEDIA_RAM_DISK_DEVICE_PATH *RamDiskDevNode
+ )
+{
+ WriteUnaligned64 (
+ (UINT64 *)&(RamDiskDevNode->StartingAddr[0]),
+ (UINT64)PrivateData->StartingAddr
+ );
+ WriteUnaligned64 (
+ (UINT64 *)&(RamDiskDevNode->EndingAddr[0]),
+ (UINT64)PrivateData->StartingAddr + PrivateData->Size - 1
+ );
+ CopyGuid (&RamDiskDevNode->TypeGuid, &PrivateData->TypeGuid);
+ RamDiskDevNode->Instance = PrivateData->InstanceNumber;
+}
+
+/**
+ Initialize and publish NVDIMM root device SSDT in ACPI table.
+
+ @retval EFI_SUCCESS The NVDIMM root device SSDT is published.
+ @retval Others The NVDIMM root device SSDT is not published.
+
+**/
+EFI_STATUS
+RamDiskPublishSsdt (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_ACPI_DESCRIPTION_HEADER *Table;
+ UINTN SectionInstance;
+ UINTN TableSize;
+
+ Status = EFI_SUCCESS;
+ SectionInstance = 0;
+
+ //
+ // Scan all the EFI raw section instances in FV to find the NVDIMM root
+ // device SSDT.
+ //
+ while (TRUE) {
+ Status = GetSectionFromFv (
+ &gEfiCallerIdGuid,
+ EFI_SECTION_RAW,
+ SectionInstance,
+ (VOID **)&Table,
+ &TableSize
+ );
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ if (Table->OemTableId == SIGNATURE_64 ('R', 'a', 'm', 'D', 'i', 's', 'k', ' ')) {
+ Status = mAcpiTableProtocol->InstallAcpiTable (
+ mAcpiTableProtocol,
+ Table,
+ TableSize,
+ &mRamDiskSsdtTableKey
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ if (!EFI_ERROR (Status)) {
+ mRamDiskSsdtTableKeyValid = TRUE;
+ }
+
+ FreePool (Table);
+ return Status;
+ } else {
+ FreePool (Table);
+ SectionInstance++;
+ }
+ }
+
+ return Status;
+}
+
+/**
+ Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI
+ table.
+
+ @param[in] PrivateData Points to RAM disk private data.
+
+ @retval EFI_SUCCESS The RAM disk NFIT has been published.
+ @retval others The RAM disk NFIT has not been published.
+
+**/
+EFI_STATUS
+RamDiskPublishNfit (
+ IN RAM_DISK_PRIVATE_DATA *PrivateData
+ )
+{
+ EFI_STATUS Status;
+ EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEntry;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapEnd;
+ UINTN TableIndex;
+ VOID *TableHeader;
+ EFI_ACPI_TABLE_VERSION TableVersion;
+ UINTN TableKey;
+ EFI_ACPI_DESCRIPTION_HEADER *NfitHeader;
+ EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
+ *SpaRange;
+ VOID *Nfit;
+ UINT32 NfitLen;
+ UINTN MemoryMapSize;
+ UINTN MapKey;
+ UINTN DescriptorSize;
+ UINT32 DescriptorVersion;
+ UINT64 CurrentData;
+ UINT8 Checksum;
+ BOOLEAN MemoryFound;
+
+ //
+ // Get the EFI memory map.
+ //
+ MemoryMapSize = 0;
+ MemoryMap = NULL;
+ MemoryFound = FALSE;
+
+ Status = gBS->GetMemoryMap (
+ &MemoryMapSize,
+ MemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
+ ASSERT (Status == EFI_BUFFER_TOO_SMALL);
+ do {
+ MemoryMap = (EFI_MEMORY_DESCRIPTOR *)AllocatePool (MemoryMapSize);
+ ASSERT (MemoryMap != NULL);
+ Status = gBS->GetMemoryMap (
+ &MemoryMapSize,
+ MemoryMap,
+ &MapKey,
+ &DescriptorSize,
+ &DescriptorVersion
+ );
+ if (EFI_ERROR (Status)) {
+ FreePool (MemoryMap);
+ }
+ } while (Status == EFI_BUFFER_TOO_SMALL);
+
+ ASSERT_EFI_ERROR (Status);
+
+ MemoryMapEntry = MemoryMap;
+ MemoryMapEnd = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)MemoryMap + MemoryMapSize);
+ while ((UINTN)MemoryMapEntry < (UINTN)MemoryMapEnd) {
+ if ((MemoryMapEntry->Type == EfiReservedMemoryType) &&
+ (MemoryMapEntry->PhysicalStart <= PrivateData->StartingAddr) &&
+ (MemoryMapEntry->PhysicalStart +
+ MultU64x32 (MemoryMapEntry->NumberOfPages, EFI_PAGE_SIZE)
+ >= PrivateData->StartingAddr + PrivateData->Size))
+ {
+ MemoryFound = TRUE;
+ DEBUG ((
+ DEBUG_INFO,
+ "RamDiskPublishNfit: RAM disk with reserved memory type, will publish to NFIT.\n"
+ ));
+ break;
+ }
+
+ MemoryMapEntry = NEXT_MEMORY_DESCRIPTOR (MemoryMapEntry, DescriptorSize);
+ }
+
+ FreePool (MemoryMap);
+
+ if (!MemoryFound) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Determine whether there is a NFIT already in the ACPI table.
+ //
+ Status = EFI_SUCCESS;
+ TableIndex = 0;
+ TableKey = 0;
+ TableHeader = NULL;
+
+ while (!EFI_ERROR (Status)) {
+ Status = mAcpiSdtProtocol->GetAcpiTable (
+ TableIndex,
+ (EFI_ACPI_SDT_HEADER **)&TableHeader,
+ &TableVersion,
+ &TableKey
+ );
+ if (!EFI_ERROR (Status)) {
+ TableIndex++;
+
+ if (((EFI_ACPI_SDT_HEADER *)TableHeader)->Signature ==
+ EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE)
+ {
+ break;
+ }
+ }
+ }
+
+ if (!EFI_ERROR (Status)) {
+ //
+ // A NFIT is already in the ACPI table.
+ //
+ DEBUG ((
+ DEBUG_INFO,
+ "RamDiskPublishNfit: A NFIT is already exist in the ACPI Table.\n"
+ ));
+
+ NfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)TableHeader;
+ NfitLen = NfitHeader->Length + sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
+ Nfit = AllocateZeroPool (NfitLen);
+ if (Nfit == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CopyMem (Nfit, TableHeader, NfitHeader->Length);
+
+ //
+ // Update the NFIT head pointer.
+ //
+ NfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)Nfit;
+
+ //
+ // Uninstall the origin NFIT from the ACPI table.
+ //
+ Status = mAcpiTableProtocol->UninstallAcpiTable (
+ mAcpiTableProtocol,
+ TableKey
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ if (EFI_ERROR (Status)) {
+ FreePool (Nfit);
+ return Status;
+ }
+
+ //
+ // Append the System Physical Address (SPA) Range Structure at the end
+ // of the origin NFIT.
+ //
+ SpaRange = (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *)
+ ((UINT8 *)Nfit + NfitHeader->Length);
+
+ //
+ // Update the length field of the NFIT
+ //
+ NfitHeader->Length = NfitLen;
+
+ //
+ // The checksum will be updated after the new contents are appended.
+ //
+ NfitHeader->Checksum = 0;
+ } else {
+ //
+ // Assumption is made that if no NFIT is in the ACPI table, there is no
+ // NVDIMM root device in the \SB scope.
+ // Therefore, a NVDIMM root device will be reported via Secondary System
+ // Description Table (SSDT).
+ //
+ Status = RamDiskPublishSsdt ();
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // No NFIT is in the ACPI table, we will create one here.
+ //
+ DEBUG ((
+ DEBUG_INFO,
+ "RamDiskPublishNfit: No NFIT is in the ACPI Table, will create one.\n"
+ ));
+
+ NfitLen = sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE) +
+ sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
+ Nfit = AllocateZeroPool (NfitLen);
+ if (Nfit == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ SpaRange = (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *)
+ ((UINT8 *)Nfit + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
+
+ NfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)Nfit;
+ NfitHeader->Signature = EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE;
+ NfitHeader->Length = NfitLen;
+ NfitHeader->Revision = EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_REVISION;
+ NfitHeader->Checksum = 0;
+ NfitHeader->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
+ NfitHeader->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
+ NfitHeader->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
+ CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
+ CopyMem (NfitHeader->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (NfitHeader->OemId));
+ CopyMem (&NfitHeader->OemTableId, &CurrentData, sizeof (UINT64));
+ }
+
+ //
+ // Fill in the content of the SPA Range Structure.
+ //
+ SpaRange->Type = EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE;
+ SpaRange->Length = sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
+ SpaRange->SystemPhysicalAddressRangeBase = PrivateData->StartingAddr;
+ SpaRange->SystemPhysicalAddressRangeLength = PrivateData->Size;
+ CopyGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid);
+
+ Checksum = CalculateCheckSum8 ((UINT8 *)Nfit, NfitHeader->Length);
+ NfitHeader->Checksum = Checksum;
+
+ //
+ // Publish the NFIT to the ACPI table.
+ // Note, since the NFIT might be modified by other driver, therefore, we
+ // do not track the returning TableKey from the InstallAcpiTable().
+ //
+ Status = mAcpiTableProtocol->InstallAcpiTable (
+ mAcpiTableProtocol,
+ Nfit,
+ NfitHeader->Length,
+ &TableKey
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ FreePool (Nfit);
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ PrivateData->InNfit = TRUE;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Unpublish the RAM disk NVDIMM Firmware Interface Table (NFIT) from the
+ ACPI table.
+
+ @param[in] PrivateData Points to RAM disk private data.
+
+ @retval EFI_SUCCESS The RAM disk NFIT has been unpublished.
+ @retval others The RAM disk NFIT has not been unpublished.
+
+**/
+EFI_STATUS
+RamDiskUnpublishNfit (
+ IN RAM_DISK_PRIVATE_DATA *PrivateData
+ )
+{
+ EFI_STATUS Status;
+ UINTN TableIndex;
+ VOID *TableHeader;
+ EFI_ACPI_TABLE_VERSION TableVersion;
+ UINTN TableKey;
+ EFI_ACPI_DESCRIPTION_HEADER *NewNfitHeader;
+ EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE
+ *SpaRange;
+ VOID *NewNfit;
+ VOID *NewNfitPtr;
+ EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *NfitStructHeader;
+ UINT32 NewNfitLen;
+ UINT32 RemainLen;
+ UINT8 Checksum;
+
+ //
+ // Find the NFIT in the ACPI table.
+ //
+ Status = EFI_SUCCESS;
+ TableIndex = 0;
+ TableKey = 0;
+ TableHeader = NULL;
+
+ while (!EFI_ERROR (Status)) {
+ Status = mAcpiSdtProtocol->GetAcpiTable (
+ TableIndex,
+ (EFI_ACPI_SDT_HEADER **)&TableHeader,
+ &TableVersion,
+ &TableKey
+ );
+ if (!EFI_ERROR (Status)) {
+ TableIndex++;
+
+ if (((EFI_ACPI_SDT_HEADER *)TableHeader)->Signature ==
+ EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE_STRUCTURE_SIGNATURE)
+ {
+ break;
+ }
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ //
+ // No NFIT is found in the ACPI table.
+ //
+ return EFI_NOT_FOUND;
+ }
+
+ NewNfitLen = ((EFI_ACPI_DESCRIPTION_HEADER *)TableHeader)->Length -
+ sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE);
+
+ //
+ // After removing this RAM disk from the NFIT, if no other structure is in
+ // the NFIT, we just remove the NFIT and the SSDT which is used to report
+ // the NVDIMM root device.
+ //
+ if (NewNfitLen == sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE)) {
+ //
+ // Remove the NFIT.
+ //
+ Status = mAcpiTableProtocol->UninstallAcpiTable (
+ mAcpiTableProtocol,
+ TableKey
+ );
+ ASSERT_EFI_ERROR (Status);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Remove the SSDT which is used by RamDiskDxe driver to report the NVDIMM
+ // root device.
+ // We do not care the return status since this SSDT might already be
+ // uninstalled by other drivers to update the information of the NVDIMM
+ // root device.
+ //
+ if (mRamDiskSsdtTableKeyValid) {
+ mRamDiskSsdtTableKeyValid = FALSE;
+
+ mAcpiTableProtocol->UninstallAcpiTable (
+ mAcpiTableProtocol,
+ mRamDiskSsdtTableKey
+ );
+ }
+
+ return EFI_SUCCESS;
+ }
+
+ NewNfit = AllocateZeroPool (NewNfitLen);
+ if (NewNfit == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // Get a copy of the old NFIT header content.
+ //
+ CopyMem (NewNfit, TableHeader, sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
+ NewNfitHeader = (EFI_ACPI_DESCRIPTION_HEADER *)NewNfit;
+ NewNfitHeader->Length = NewNfitLen;
+ NewNfitHeader->Checksum = 0;
+
+ //
+ // Copy the content of required NFIT structures.
+ //
+ NewNfitPtr = (UINT8 *)NewNfit + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE);
+ RemainLen = NewNfitLen - sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE);
+ NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
+ ((UINT8 *)TableHeader + sizeof (EFI_ACPI_6_1_NVDIMM_FIRMWARE_INTERFACE_TABLE));
+ while (RemainLen > 0) {
+ if ((NfitStructHeader->Type == EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE_TYPE) &&
+ (NfitStructHeader->Length == sizeof (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE)))
+ {
+ SpaRange = (EFI_ACPI_6_1_NFIT_SYSTEM_PHYSICAL_ADDRESS_RANGE_STRUCTURE *)NfitStructHeader;
+
+ if ((SpaRange->SystemPhysicalAddressRangeBase == PrivateData->StartingAddr) &&
+ (SpaRange->SystemPhysicalAddressRangeLength == PrivateData->Size) &&
+ (CompareGuid (&SpaRange->AddressRangeTypeGUID, &PrivateData->TypeGuid)))
+ {
+ //
+ // Skip the SPA Range Structure for the RAM disk to be unpublished
+ // from NFIT.
+ //
+ NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
+ ((UINT8 *)NfitStructHeader + NfitStructHeader->Length);
+ continue;
+ }
+ }
+
+ //
+ // Copy the content of origin NFIT.
+ //
+ CopyMem (NewNfitPtr, NfitStructHeader, NfitStructHeader->Length);
+ NewNfitPtr = (UINT8 *)NewNfitPtr + NfitStructHeader->Length;
+
+ //
+ // Move to the header of next NFIT structure.
+ //
+ RemainLen -= NfitStructHeader->Length;
+ NfitStructHeader = (EFI_ACPI_6_1_NFIT_STRUCTURE_HEADER *)
+ ((UINT8 *)NfitStructHeader + NfitStructHeader->Length);
+ }
+
+ Checksum = CalculateCheckSum8 ((UINT8 *)NewNfit, NewNfitHeader->Length);
+ NewNfitHeader->Checksum = Checksum;
+
+ Status = mAcpiTableProtocol->UninstallAcpiTable (
+ mAcpiTableProtocol,
+ TableKey
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ if (EFI_ERROR (Status)) {
+ FreePool (NewNfit);
+ return Status;
+ }
+
+ //
+ // Publish the NFIT to the ACPI table.
+ // Note, since the NFIT might be modified by other driver, therefore, we
+ // do not track the returning TableKey from the InstallAcpiTable().
+ //
+ Status = mAcpiTableProtocol->InstallAcpiTable (
+ mAcpiTableProtocol,
+ NewNfit,
+ NewNfitLen,
+ &TableKey
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ FreePool (NewNfit);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Register a RAM disk with specified address, size and type.
+
+ @param[in] RamDiskBase The base address of registered RAM disk.
+ @param[in] RamDiskSize The size of registered RAM disk.
+ @param[in] RamDiskType The type of registered RAM disk. The GUID can be
+ any of the values defined in section 9.3.6.9, or a
+ vendor defined GUID.
+ @param[in] ParentDevicePath
+ Pointer to the parent device path. If there is no
+ parent device path then ParentDevicePath is NULL.
+ @param[out] DevicePath On return, points to a pointer to the device path
+ of the RAM disk device.
+ If ParentDevicePath is not NULL, the returned
+ DevicePath is created by appending a RAM disk node
+ to the parent device path. If ParentDevicePath is
+ NULL, the returned DevicePath is a RAM disk device
+ path without appending. This function is
+ responsible for allocating the buffer DevicePath
+ with the boot service AllocatePool().
+
+ @retval EFI_SUCCESS The RAM disk is registered successfully.
+ @retval EFI_INVALID_PARAMETER DevicePath or RamDiskType is NULL.
+ RamDiskSize is 0.
+ @retval EFI_ALREADY_STARTED A Device Path Protocol instance to be created
+ is already present in the handle database.
+ @retval EFI_OUT_OF_RESOURCES The RAM disk register operation fails due to
+ resource limitation.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskRegister (
+ IN UINT64 RamDiskBase,
+ IN UINT64 RamDiskSize,
+ IN EFI_GUID *RamDiskType,
+ IN EFI_DEVICE_PATH *ParentDevicePath OPTIONAL,
+ OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
+ )
+{
+ EFI_STATUS Status;
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+ RAM_DISK_PRIVATE_DATA *RegisteredPrivateData;
+ MEDIA_RAM_DISK_DEVICE_PATH *RamDiskDevNode;
+ UINTN DevicePathSize;
+ LIST_ENTRY *Entry;
+
+ if ((0 == RamDiskSize) || (NULL == RamDiskType) || (NULL == DevicePath)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Add check to prevent data read across the memory boundary
+ //
+ if ((RamDiskSize > MAX_UINTN) ||
+ (RamDiskBase > MAX_UINTN - RamDiskSize + 1))
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ RamDiskDevNode = NULL;
+
+ //
+ // Create a new RAM disk instance and initialize its private data
+ //
+ PrivateData = AllocateCopyPool (
+ sizeof (RAM_DISK_PRIVATE_DATA),
+ &mRamDiskPrivateDataTemplate
+ );
+ if (NULL == PrivateData) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ PrivateData->StartingAddr = RamDiskBase;
+ PrivateData->Size = RamDiskSize;
+ CopyGuid (&PrivateData->TypeGuid, RamDiskType);
+ InitializeListHead (&PrivateData->ThisInstance);
+
+ //
+ // Generate device path information for the registered RAM disk
+ //
+ RamDiskDevNode = AllocateCopyPool (
+ sizeof (MEDIA_RAM_DISK_DEVICE_PATH),
+ &mRamDiskDeviceNodeTemplate
+ );
+ if (NULL == RamDiskDevNode) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ErrorExit;
+ }
+
+ RamDiskInitDeviceNode (PrivateData, RamDiskDevNode);
+
+ *DevicePath = AppendDevicePathNode (
+ ParentDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)RamDiskDevNode
+ );
+ if (NULL == *DevicePath) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ErrorExit;
+ }
+
+ PrivateData->DevicePath = *DevicePath;
+
+ //
+ // Check whether the created device path is already present in the handle
+ // database
+ //
+ if (!IsListEmpty (&RegisteredRamDisks)) {
+ DevicePathSize = GetDevicePathSize (PrivateData->DevicePath);
+
+ BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
+ RegisteredPrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
+ if (DevicePathSize == GetDevicePathSize (RegisteredPrivateData->DevicePath)) {
+ //
+ // Compare device path
+ //
+ if ((CompareMem (
+ PrivateData->DevicePath,
+ RegisteredPrivateData->DevicePath,
+ DevicePathSize
+ )) == 0)
+ {
+ *DevicePath = NULL;
+ Status = EFI_ALREADY_STARTED;
+ goto ErrorExit;
+ }
+ }
+ }
+ }
+
+ //
+ // Fill Block IO protocol informations for the RAM disk
+ //
+ RamDiskInitBlockIo (PrivateData);
+
+ //
+ // Install EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO(2)_PROTOCOL on a new
+ // handle
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &PrivateData->Handle,
+ &gEfiBlockIoProtocolGuid,
+ &PrivateData->BlockIo,
+ &gEfiBlockIo2ProtocolGuid,
+ &PrivateData->BlockIo2,
+ &gEfiDevicePathProtocolGuid,
+ PrivateData->DevicePath,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ goto ErrorExit;
+ }
+
+ //
+ // Insert the newly created one to the registered RAM disk list
+ //
+ InsertTailList (&RegisteredRamDisks, &PrivateData->ThisInstance);
+
+ gBS->ConnectController (PrivateData->Handle, NULL, NULL, TRUE);
+
+ FreePool (RamDiskDevNode);
+
+ if ((mAcpiTableProtocol != NULL) && (mAcpiSdtProtocol != NULL)) {
+ RamDiskPublishNfit (PrivateData);
+ }
+
+ return EFI_SUCCESS;
+
+ErrorExit:
+ if (RamDiskDevNode != NULL) {
+ FreePool (RamDiskDevNode);
+ }
+
+ if (PrivateData != NULL) {
+ if (PrivateData->DevicePath) {
+ FreePool (PrivateData->DevicePath);
+ }
+
+ FreePool (PrivateData);
+ }
+
+ return Status;
+}
+
+/**
+ Unregister a RAM disk specified by DevicePath.
+
+ @param[in] DevicePath A pointer to the device path that describes a RAM
+ Disk device.
+
+ @retval EFI_SUCCESS The RAM disk is unregistered successfully.
+ @retval EFI_INVALID_PARAMETER DevicePath is NULL.
+ @retval EFI_UNSUPPORTED The device specified by DevicePath is not a
+ valid ramdisk device path and not supported
+ by the driver.
+ @retval EFI_NOT_FOUND The RAM disk pointed by DevicePath doesn't
+ exist.
+
+**/
+EFI_STATUS
+EFIAPI
+RamDiskUnregister (
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ )
+{
+ LIST_ENTRY *Entry;
+ LIST_ENTRY *NextEntry;
+ BOOLEAN Found;
+ UINT64 StartingAddr;
+ UINT64 EndingAddr;
+ EFI_DEVICE_PATH_PROTOCOL *Header;
+ MEDIA_RAM_DISK_DEVICE_PATH *RamDiskDevNode;
+ RAM_DISK_PRIVATE_DATA *PrivateData;
+
+ if (NULL == DevicePath) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Locate the RAM disk device node.
+ //
+ RamDiskDevNode = NULL;
+ Header = DevicePath;
+ do {
+ //
+ // Test if the current device node is a RAM disk.
+ //
+ if ((MEDIA_DEVICE_PATH == Header->Type) &&
+ (MEDIA_RAM_DISK_DP == Header->SubType))
+ {
+ RamDiskDevNode = (MEDIA_RAM_DISK_DEVICE_PATH *)Header;
+
+ break;
+ }
+
+ Header = NextDevicePathNode (Header);
+ } while ((Header->Type != END_DEVICE_PATH_TYPE));
+
+ if (NULL == RamDiskDevNode) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Found = FALSE;
+ StartingAddr = ReadUnaligned64 ((UINT64 *)&(RamDiskDevNode->StartingAddr[0]));
+ EndingAddr = ReadUnaligned64 ((UINT64 *)&(RamDiskDevNode->EndingAddr[0]));
+
+ if (!IsListEmpty (&RegisteredRamDisks)) {
+ BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &RegisteredRamDisks) {
+ PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
+
+ //
+ // Unregister the RAM disk given by its starting address, ending address
+ // and type guid.
+ //
+ if ((StartingAddr == PrivateData->StartingAddr) &&
+ (EndingAddr == PrivateData->StartingAddr + PrivateData->Size - 1) &&
+ (CompareGuid (&RamDiskDevNode->TypeGuid, &PrivateData->TypeGuid)))
+ {
+ //
+ // Remove the content for this RAM disk in NFIT.
+ //
+ if (PrivateData->InNfit) {
+ RamDiskUnpublishNfit (PrivateData);
+ }
+
+ //
+ // Uninstall the EFI_DEVICE_PATH_PROTOCOL & EFI_BLOCK_IO(2)_PROTOCOL
+ //
+ gBS->UninstallMultipleProtocolInterfaces (
+ PrivateData->Handle,
+ &gEfiBlockIoProtocolGuid,
+ &PrivateData->BlockIo,
+ &gEfiBlockIo2ProtocolGuid,
+ &PrivateData->BlockIo2,
+ &gEfiDevicePathProtocolGuid,
+ (EFI_DEVICE_PATH_PROTOCOL *)PrivateData->DevicePath,
+ NULL
+ );
+
+ RemoveEntryList (&PrivateData->ThisInstance);
+
+ if (RamDiskCreateHii == PrivateData->CreateMethod) {
+ //
+ // If a RAM disk is created within HII, then the RamDiskDxe driver
+ // driver is responsible for freeing the allocated memory for the
+ // RAM disk.
+ //
+ FreePool ((VOID *)(UINTN)PrivateData->StartingAddr);
+ }
+
+ FreePool (PrivateData->DevicePath);
+ FreePool (PrivateData);
+ Found = TRUE;
+
+ break;
+ }
+ }
+ }
+
+ if (TRUE == Found) {
+ return EFI_SUCCESS;
+ } else {
+ return EFI_NOT_FOUND;
+ }
+}