]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / RamDiskDxe / RamDiskDriver.c
CommitLineData
20752cb8
HW
1/** @file\r
2 The driver entry point for RamDiskDxe driver.\r
3\r
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
20752cb8
HW
6\r
7**/\r
8\r
9#include "RamDiskImpl.h"\r
10\r
11//\r
12// Handle for the EFI_RAM_DISK_PROTOCOL instance\r
13//\r
14EFI_HANDLE mRamDiskHandle = NULL;\r
15\r
16//\r
17// The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver\r
18// handle\r
19//\r
20EFI_RAM_DISK_PROTOCOL mRamDiskProtocol = {\r
21 RamDiskRegister,\r
22 RamDiskUnregister\r
23};\r
24\r
25//\r
26// RamDiskDxe driver maintains a list of registered RAM disks.\r
27//\r
28LIST_ENTRY RegisteredRamDisks;\r
20752cb8 29\r
07a3fecd
HW
30//\r
31// Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.\r
32//\r
33EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL;\r
34EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol = NULL;\r
35\r
36\r
37/**\r
38 Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.\r
39 If both protocols are produced, publish all the reserved memory type RAM\r
40 disks to the NVDIMM Firmware Interface Table (NFIT).\r
41\r
42 @param[in] Event Event whose notification function is being invoked.\r
43 @param[in] Context The pointer to the notification function's context,\r
44 which is implementation-dependent.\r
45\r
46**/\r
47VOID\r
48EFIAPI\r
49RamDiskAcpiCheck (\r
50 IN EFI_EVENT Event,\r
51 IN VOID *Context\r
52 )\r
53{\r
54 EFI_STATUS Status;\r
55 LIST_ENTRY *Entry;\r
56 RAM_DISK_PRIVATE_DATA *PrivateData;\r
57\r
58 gBS->CloseEvent (Event);\r
59\r
60 //\r
61 // Locate the EFI_ACPI_TABLE_PROTOCOL.\r
62 //\r
63 Status = gBS->LocateProtocol (\r
64 &gEfiAcpiTableProtocolGuid,\r
65 NULL,\r
66 (VOID **)&mAcpiTableProtocol\r
67 );\r
68 if (EFI_ERROR (Status)) {\r
69 DEBUG ((\r
70 EFI_D_INFO,\r
76874be3 71 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "\r
07a3fecd
HW
72 "unable to publish RAM disks to NFIT.\n"\r
73 ));\r
74 return;\r
75 }\r
76\r
77 //\r
78 // Locate the EFI_ACPI_SDT_PROTOCOL.\r
79 //\r
80 Status = gBS->LocateProtocol (\r
81 &gEfiAcpiSdtProtocolGuid,\r
82 NULL,\r
83 (VOID **)&mAcpiSdtProtocol\r
84 );\r
85 if (EFI_ERROR (Status)) {\r
86 DEBUG ((\r
87 EFI_D_INFO,\r
76874be3 88 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "\r
07a3fecd
HW
89 "unable to publish RAM disks to NFIT.\n"\r
90 ));\r
91 mAcpiTableProtocol = NULL;\r
92 return;\r
93 }\r
94\r
95 EFI_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {\r
96 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r
97 RamDiskPublishNfit (PrivateData);\r
98 }\r
99}\r
100\r
20752cb8
HW
101\r
102/**\r
103 The entry point for RamDiskDxe driver.\r
104\r
105 @param[in] ImageHandle The image handle of the driver.\r
106 @param[in] SystemTable The system table.\r
107\r
108 @retval EFI_ALREADY_STARTED The driver already exists in system.\r
109 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of\r
110 resources.\r
111 @retval EFI_SUCCES All the related protocols are installed on\r
112 the driver.\r
113\r
114**/\r
115EFI_STATUS\r
116EFIAPI\r
117RamDiskDxeEntryPoint (\r
118 IN EFI_HANDLE ImageHandle,\r
119 IN EFI_SYSTEM_TABLE *SystemTable\r
120 )\r
121{\r
122 EFI_STATUS Status;\r
123 RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;\r
124 VOID *DummyInterface;\r
07a3fecd 125 EFI_EVENT Event;\r
20752cb8
HW
126\r
127 //\r
128 // If already started, return.\r
129 //\r
130 Status = gBS->LocateProtocol (\r
131 &gEfiRamDiskProtocolGuid,\r
132 NULL,\r
133 &DummyInterface\r
134 );\r
135 if (!EFI_ERROR (Status)) {\r
136 DEBUG ((EFI_D_INFO, "Driver already started!\n"));\r
137 return EFI_ALREADY_STARTED;\r
138 }\r
139\r
140 //\r
141 // Create a private data structure.\r
142 //\r
143 ConfigPrivate = AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA), &mRamDiskConfigPrivateDataTemplate);\r
144 if (ConfigPrivate == NULL) {\r
145 return EFI_OUT_OF_RESOURCES;\r
146 }\r
147\r
148 //\r
149 // Install RAM disk configuration form\r
150 //\r
151 Status = InstallRamDiskConfigForm (ConfigPrivate);\r
152 if (EFI_ERROR (Status)) {\r
153 goto ErrorExit;\r
154 }\r
155\r
156 //\r
157 // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a\r
158 // new handle\r
159 //\r
160 Status = gBS->InstallMultipleProtocolInterfaces (\r
161 &mRamDiskHandle,\r
162 &gEfiRamDiskProtocolGuid,\r
163 &mRamDiskProtocol,\r
164 &gEfiCallerIdGuid,\r
165 ConfigPrivate,\r
166 NULL\r
167 );\r
168 if (EFI_ERROR (Status)) {\r
169 goto ErrorExit;\r
170 }\r
171\r
172 //\r
173 // Initialize the list of registered RAM disks maintained by the driver\r
174 //\r
175 InitializeListHead (&RegisteredRamDisks);\r
176\r
07a3fecd
HW
177 Status = EfiCreateEventReadyToBootEx (\r
178 TPL_CALLBACK,\r
179 RamDiskAcpiCheck,\r
180 NULL,\r
181 &Event\r
182 );\r
183 ASSERT_EFI_ERROR (Status);\r
184\r
20752cb8
HW
185 return EFI_SUCCESS;\r
186\r
187ErrorExit:\r
188 if (ConfigPrivate != NULL) {\r
189 UninstallRamDiskConfigForm (ConfigPrivate);\r
190 }\r
191\r
192 return Status;\r
193}\r
194\r
195\r
196/**\r
197 Unload the RamDiskDxe driver and its configuration form.\r
198\r
199 @param[in] ImageHandle The driver's image handle.\r
200\r
201 @retval EFI_SUCCESS The RamDiskDxe driver and its configuration\r
202 form is unloaded.\r
203 @retval Others Failed to unload the form.\r
204\r
205**/\r
206EFI_STATUS\r
207EFIAPI\r
208RamDiskDxeUnload (\r
209 IN EFI_HANDLE ImageHandle\r
210 )\r
211{\r
212 EFI_STATUS Status;\r
213 RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;\r
214\r
215 Status = gBS->HandleProtocol (\r
216 mRamDiskHandle,\r
217 &gEfiCallerIdGuid,\r
218 (VOID **) &ConfigPrivate\r
219 );\r
220 if (EFI_ERROR (Status)) {\r
221 return Status;\r
222 }\r
223\r
224 ASSERT (ConfigPrivate->Signature == RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE);\r
225\r
226 //\r
227 // Unregister all registered RAM disks\r
228 //\r
229 UnregisterAllRamDisks ();\r
230\r
231 gBS->UninstallMultipleProtocolInterfaces (\r
232 mRamDiskHandle,\r
233 &gEfiRamDiskProtocolGuid,\r
234 &mRamDiskProtocol,\r
235 &gEfiCallerIdGuid,\r
236 ConfigPrivate,\r
237 NULL\r
238 );\r
239\r
240 UninstallRamDiskConfigForm (ConfigPrivate);\r
241\r
242 return EFI_SUCCESS;\r
243}\r