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
;
39 Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.
40 If both protocols are produced, publish all the reserved memory type RAM
41 disks to the NVDIMM Firmware Interface Table (NFIT).
43 @param[in] Event Event whose notification function is being invoked.
44 @param[in] Context The pointer to the notification function's context,
45 which is implementation-dependent.
57 RAM_DISK_PRIVATE_DATA
*PrivateData
;
59 gBS
->CloseEvent (Event
);
62 // Locate the EFI_ACPI_TABLE_PROTOCOL.
64 Status
= gBS
->LocateProtocol (
65 &gEfiAcpiTableProtocolGuid
,
67 (VOID
**)&mAcpiTableProtocol
69 if (EFI_ERROR (Status
)) {
72 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "
73 "unable to publish RAM disks to NFIT.\n"
79 // Locate the EFI_ACPI_SDT_PROTOCOL.
81 Status
= gBS
->LocateProtocol (
82 &gEfiAcpiSdtProtocolGuid
,
84 (VOID
**)&mAcpiSdtProtocol
86 if (EFI_ERROR (Status
)) {
89 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "
90 "unable to publish RAM disks to NFIT.\n"
92 mAcpiTableProtocol
= NULL
;
96 BASE_LIST_FOR_EACH (Entry
, &RegisteredRamDisks
) {
97 PrivateData
= RAM_DISK_PRIVATE_FROM_THIS (Entry
);
98 RamDiskPublishNfit (PrivateData
);
104 The entry point for RamDiskDxe driver.
106 @param[in] ImageHandle The image handle of the driver.
107 @param[in] SystemTable The system table.
109 @retval EFI_ALREADY_STARTED The driver already exists in system.
110 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of
112 @retval EFI_SUCCES All the related protocols are installed on
118 RamDiskDxeEntryPoint (
119 IN EFI_HANDLE ImageHandle
,
120 IN EFI_SYSTEM_TABLE
*SystemTable
124 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
125 VOID
*DummyInterface
;
129 // If already started, return.
131 Status
= gBS
->LocateProtocol (
132 &gEfiRamDiskProtocolGuid
,
136 if (!EFI_ERROR (Status
)) {
137 DEBUG ((EFI_D_INFO
, "Driver already started!\n"));
138 return EFI_ALREADY_STARTED
;
142 // Create a private data structure.
144 ConfigPrivate
= AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA
), &mRamDiskConfigPrivateDataTemplate
);
145 if (ConfigPrivate
== NULL
) {
146 return EFI_OUT_OF_RESOURCES
;
150 // Install RAM disk configuration form
152 Status
= InstallRamDiskConfigForm (ConfigPrivate
);
153 if (EFI_ERROR (Status
)) {
158 // Initialize the list of registered RAM disks maintained by the driver
159 // before installing the protocol
161 InitializeListHead (&RegisteredRamDisks
);
164 // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
167 Status
= gBS
->InstallMultipleProtocolInterfaces (
169 &gEfiRamDiskProtocolGuid
,
175 if (EFI_ERROR (Status
)) {
179 Status
= EfiCreateEventReadyToBootEx (
185 ASSERT_EFI_ERROR (Status
);
190 if (ConfigPrivate
!= NULL
) {
191 UninstallRamDiskConfigForm (ConfigPrivate
);
199 Unload the RamDiskDxe driver and its configuration form.
201 @param[in] ImageHandle The driver's image handle.
203 @retval EFI_SUCCESS The RamDiskDxe driver and its configuration
205 @retval Others Failed to unload the form.
211 IN EFI_HANDLE ImageHandle
215 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
217 Status
= gBS
->HandleProtocol (
220 (VOID
**) &ConfigPrivate
222 if (EFI_ERROR (Status
)) {
226 ASSERT (ConfigPrivate
->Signature
== RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE
);
229 // Unregister all registered RAM disks
231 UnregisterAllRamDisks ();
233 gBS
->UninstallMultipleProtocolInterfaces (
235 &gEfiRamDiskProtocolGuid
,
242 UninstallRamDiskConfigForm (ConfigPrivate
);