2 The driver entry point for RamDiskDxe driver.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) Microsoft Corporation.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "RamDiskImpl.h"
13 // Handle for the EFI_RAM_DISK_PROTOCOL instance
15 EFI_HANDLE mRamDiskHandle
= NULL
;
18 // The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver
21 EFI_RAM_DISK_PROTOCOL mRamDiskProtocol
= {
27 // RamDiskDxe driver maintains a list of registered RAM disks.
29 LIST_ENTRY RegisteredRamDisks
;
32 // Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
34 EFI_ACPI_TABLE_PROTOCOL
*mAcpiTableProtocol
= NULL
;
35 EFI_ACPI_SDT_PROTOCOL
*mAcpiSdtProtocol
= NULL
;
38 Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.
39 If both protocols are produced, publish all the reserved memory type RAM
40 disks to the NVDIMM Firmware Interface Table (NFIT).
42 @param[in] Event Event whose notification function is being invoked.
43 @param[in] Context The pointer to the notification function's context,
44 which is implementation-dependent.
56 RAM_DISK_PRIVATE_DATA
*PrivateData
;
58 gBS
->CloseEvent (Event
);
61 // Locate the EFI_ACPI_TABLE_PROTOCOL.
63 Status
= gBS
->LocateProtocol (
64 &gEfiAcpiTableProtocolGuid
,
66 (VOID
**)&mAcpiTableProtocol
68 if (EFI_ERROR (Status
)) {
71 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "
72 "unable to publish RAM disks to NFIT.\n"
78 // Locate the EFI_ACPI_SDT_PROTOCOL.
80 Status
= gBS
->LocateProtocol (
81 &gEfiAcpiSdtProtocolGuid
,
83 (VOID
**)&mAcpiSdtProtocol
85 if (EFI_ERROR (Status
)) {
88 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "
89 "unable to publish RAM disks to NFIT.\n"
91 mAcpiTableProtocol
= NULL
;
95 BASE_LIST_FOR_EACH (Entry
, &RegisteredRamDisks
) {
96 PrivateData
= RAM_DISK_PRIVATE_FROM_THIS (Entry
);
97 RamDiskPublishNfit (PrivateData
);
102 The entry point for RamDiskDxe driver.
104 @param[in] ImageHandle The image handle of the driver.
105 @param[in] SystemTable The system table.
107 @retval EFI_ALREADY_STARTED The driver already exists in system.
108 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of
110 @retval EFI_SUCCES All the related protocols are installed on
116 RamDiskDxeEntryPoint (
117 IN EFI_HANDLE ImageHandle
,
118 IN EFI_SYSTEM_TABLE
*SystemTable
122 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
123 VOID
*DummyInterface
;
127 // If already started, return.
129 Status
= gBS
->LocateProtocol (
130 &gEfiRamDiskProtocolGuid
,
134 if (!EFI_ERROR (Status
)) {
135 DEBUG ((DEBUG_INFO
, "Driver already started!\n"));
136 return EFI_ALREADY_STARTED
;
140 // Create a private data structure.
142 ConfigPrivate
= AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA
), &mRamDiskConfigPrivateDataTemplate
);
143 if (ConfigPrivate
== NULL
) {
144 return EFI_OUT_OF_RESOURCES
;
148 // Install RAM disk configuration form
150 Status
= InstallRamDiskConfigForm (ConfigPrivate
);
151 if (EFI_ERROR (Status
)) {
156 // Initialize the list of registered RAM disks maintained by the driver
157 // before installing the protocol
159 InitializeListHead (&RegisteredRamDisks
);
162 // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
165 Status
= gBS
->InstallMultipleProtocolInterfaces (
167 &gEfiRamDiskProtocolGuid
,
173 if (EFI_ERROR (Status
)) {
177 Status
= EfiCreateEventReadyToBootEx (
183 ASSERT_EFI_ERROR (Status
);
188 if (ConfigPrivate
!= NULL
) {
189 UninstallRamDiskConfigForm (ConfigPrivate
);
196 Unload the RamDiskDxe driver and its configuration form.
198 @param[in] ImageHandle The driver's image handle.
200 @retval EFI_SUCCESS The RamDiskDxe driver and its configuration
202 @retval Others Failed to unload the form.
208 IN EFI_HANDLE ImageHandle
212 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
214 Status
= gBS
->HandleProtocol (
217 (VOID
**)&ConfigPrivate
219 if (EFI_ERROR (Status
)) {
223 ASSERT (ConfigPrivate
->Signature
== RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE
);
226 // Unregister all registered RAM disks
228 UnregisterAllRamDisks ();
230 gBS
->UninstallMultipleProtocolInterfaces (
232 &gEfiRamDiskProtocolGuid
,
239 UninstallRamDiskConfigForm (ConfigPrivate
);