summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
diff options
context:
space:
mode:
authorHao Wu <hao.a.wu@intel.com>2016-02-03 14:14:47 +0800
committerHao Wu <hao.a.wu@intel.com>2016-02-29 13:51:08 +0800
commit20752cb8e79b3effedd9a8d34f228f9d37f9eeff (patch)
tree1740151aa377fce476e83d9f32e072c973e2323c /MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
parent7b0a1ead7d2efa7f9eae4c2b254ff154d9c5f74f (diff)
downloadedk2-20752cb8e79b3effedd9a8d34f228f9d37f9eeff.tar.gz
edk2-20752cb8e79b3effedd9a8d34f228f9d37f9eeff.tar.bz2
edk2-20752cb8e79b3effedd9a8d34f228f9d37f9eeff.zip
MdeModulePkg: Add RamDiskDxe driver implementation
The RamDiskDxe driver will: 1. Produce the EFI RAM Disk Protocol 2. Install RAM disk device path and block I/O related protocols on the RAM disk device handle. 3. Install RAM disk configuration form to HII database Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu <hao.a.wu@intel.com> Reviewed-by: Samer El-Haj-Mahmoud <elhaj@hpe.com> Reviewed-by: Feng Tian <feng.tian@intel.com>
Diffstat (limited to 'MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c')
-rw-r--r--MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
new file mode 100644
index 0000000000..7d068b25c9
--- /dev/null
+++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
@@ -0,0 +1,170 @@
+/** @file
+ The driver entry point for RamDiskDxe driver.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#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;
+UINTN ListEntryNum;
+
+
+/**
+ 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;
+
+ //
+ // If already started, return.
+ //
+ Status = gBS->LocateProtocol (
+ &gEfiRamDiskProtocolGuid,
+ NULL,
+ &DummyInterface
+ );
+ if (!EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_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;
+ }
+
+ //
+ // 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;
+ }
+
+ //
+ // Initialize the list of registered RAM disks maintained by the driver
+ //
+ InitializeListHead (&RegisteredRamDisks);
+
+ 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;
+}