]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/UdfDxe/Udf.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / UdfDxe / Udf.c
1 /** @file
2 UDF/ECMA-167 file system driver.
3
4 Copyright (C) 2014-2017 Paulo Alcantara <pcacjr@zytor.com>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7 **/
8
9 #include "Udf.h"
10
11 //
12 // UDF filesystem driver's Global Variables.
13 //
14 EFI_DRIVER_BINDING_PROTOCOL gUdfDriverBinding = {
15 UdfDriverBindingSupported,
16 UdfDriverBindingStart,
17 UdfDriverBindingStop,
18 0x10,
19 NULL,
20 NULL
21 };
22
23 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL gUdfSimpleFsTemplate = {
24 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,
25 UdfOpenVolume
26 };
27
28 /**
29 Test to see if this driver supports ControllerHandle. Any ControllerHandle
30 than contains a BlockIo and DiskIo protocol or a BlockIo2 protocol can be
31 supported.
32
33 @param[in] This Protocol instance pointer.
34 @param[in] ControllerHandle Handle of device to test.
35 @param[in] RemainingDevicePath Optional parameter use to pick a specific
36 child device to start.
37
38 @retval EFI_SUCCESS This driver supports this device.
39 @retval EFI_ALREADY_STARTED This driver is already running on this device.
40 @retval other This driver does not support this device.
41
42 **/
43 EFI_STATUS
44 EFIAPI
45 UdfDriverBindingSupported (
46 IN EFI_DRIVER_BINDING_PROTOCOL *This,
47 IN EFI_HANDLE ControllerHandle,
48 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
49 )
50 {
51 EFI_STATUS Status;
52 EFI_DISK_IO_PROTOCOL *DiskIo;
53
54 //
55 // Open DiskIo protocol on ControllerHandle
56 //
57 Status = gBS->OpenProtocol (
58 ControllerHandle,
59 &gEfiDiskIoProtocolGuid,
60 (VOID **)&DiskIo,
61 This->DriverBindingHandle,
62 ControllerHandle,
63 EFI_OPEN_PROTOCOL_BY_DRIVER
64 );
65 if (EFI_ERROR (Status)) {
66 return Status;
67 }
68
69 //
70 // Close DiskIo protocol on ControllerHandle
71 //
72 gBS->CloseProtocol (
73 ControllerHandle,
74 &gEfiDiskIoProtocolGuid,
75 This->DriverBindingHandle,
76 ControllerHandle
77 );
78
79 //
80 // Test whether ControllerHandle supports BlockIo protocol
81 //
82 Status = gBS->OpenProtocol (
83 ControllerHandle,
84 &gEfiBlockIoProtocolGuid,
85 NULL,
86 This->DriverBindingHandle,
87 ControllerHandle,
88 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
89 );
90
91 return Status;
92 }
93
94 /**
95 Start this driver on ControllerHandle by opening a Block IO or a Block IO2
96 or both, and Disk IO protocol, reading Device Path, and creating a child
97 handle with a Disk IO and device path protocol.
98
99 @param[in] This Protocol instance pointer.
100 @param[in] ControllerHandle Handle of device to bind driver to
101 @param[in] RemainingDevicePath Optional parameter use to pick a specific
102 child device to start.
103
104 @retval EFI_SUCCESS This driver is added to ControllerHandle.
105 @retval EFI_ALREADY_STARTED This driver is already running on
106 ControllerHandle.
107 @retval other This driver does not support this device.
108
109 **/
110 EFI_STATUS
111 EFIAPI
112 UdfDriverBindingStart (
113 IN EFI_DRIVER_BINDING_PROTOCOL *This,
114 IN EFI_HANDLE ControllerHandle,
115 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
116 )
117 {
118 EFI_TPL OldTpl;
119 EFI_STATUS Status;
120 EFI_BLOCK_IO_PROTOCOL *BlockIo;
121 EFI_DISK_IO_PROTOCOL *DiskIo;
122 PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData;
123
124 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
125
126 //
127 // Open BlockIo protocol on ControllerHandle
128 //
129 Status = gBS->OpenProtocol (
130 ControllerHandle,
131 &gEfiBlockIoProtocolGuid,
132 (VOID **)&BlockIo,
133 This->DriverBindingHandle,
134 ControllerHandle,
135 EFI_OPEN_PROTOCOL_GET_PROTOCOL
136 );
137 ASSERT_EFI_ERROR (Status);
138
139 //
140 // Open DiskIo protocol on ControllerHandle
141 //
142 Status = gBS->OpenProtocol (
143 ControllerHandle,
144 &gEfiDiskIoProtocolGuid,
145 (VOID **)&DiskIo,
146 This->DriverBindingHandle,
147 ControllerHandle,
148 EFI_OPEN_PROTOCOL_BY_DRIVER
149 );
150 ASSERT_EFI_ERROR (Status);
151
152 //
153 // Check if ControllerHandle supports an UDF file system
154 //
155 Status = SupportUdfFileSystem (This, ControllerHandle);
156 if (EFI_ERROR (Status)) {
157 goto Exit;
158 }
159
160 //
161 // Initialize private file system structure
162 //
163 PrivFsData =
164 (PRIVATE_UDF_SIMPLE_FS_DATA *)
165 AllocateZeroPool (sizeof (PRIVATE_UDF_SIMPLE_FS_DATA));
166 if (PrivFsData == NULL) {
167 Status = EFI_OUT_OF_RESOURCES;
168 goto Exit;
169 }
170
171 //
172 // Create new child handle
173 //
174 PrivFsData->Signature = PRIVATE_UDF_SIMPLE_FS_DATA_SIGNATURE;
175 PrivFsData->BlockIo = BlockIo;
176 PrivFsData->DiskIo = DiskIo;
177 PrivFsData->Handle = ControllerHandle;
178
179 //
180 // Set up SimpleFs protocol
181 //
182 CopyMem (
183 (VOID *)&PrivFsData->SimpleFs,
184 (VOID *)&gUdfSimpleFsTemplate,
185 sizeof (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL)
186 );
187
188 //
189 // Install child handle
190 //
191 Status = gBS->InstallMultipleProtocolInterfaces (
192 &PrivFsData->Handle,
193 &gEfiSimpleFileSystemProtocolGuid,
194 &PrivFsData->SimpleFs,
195 NULL
196 );
197
198 Exit:
199 if (EFI_ERROR (Status)) {
200 //
201 // Close DiskIo protocol on ControllerHandle
202 //
203 gBS->CloseProtocol (
204 ControllerHandle,
205 &gEfiDiskIoProtocolGuid,
206 This->DriverBindingHandle,
207 ControllerHandle
208 );
209 //
210 // Close BlockIo protocol on ControllerHandle
211 //
212 gBS->CloseProtocol (
213 ControllerHandle,
214 &gEfiBlockIoProtocolGuid,
215 This->DriverBindingHandle,
216 ControllerHandle
217 );
218 }
219
220 gBS->RestoreTPL (OldTpl);
221
222 return Status;
223 }
224
225 /**
226 Stop this driver on ControllerHandle. Support stopping any child handles
227 created by this driver.
228
229 @param This Protocol instance pointer.
230 @param ControllerHandle Handle of device to stop driver on
231 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
232 children is zero stop the entire bus driver.
233 @param ChildHandleBuffer List of Child Handles to Stop.
234
235 @retval EFI_SUCCESS This driver is removed ControllerHandle
236 @retval other This driver was not removed from this device
237
238 **/
239 EFI_STATUS
240 EFIAPI
241 UdfDriverBindingStop (
242 IN EFI_DRIVER_BINDING_PROTOCOL *This,
243 IN EFI_HANDLE ControllerHandle,
244 IN UINTN NumberOfChildren,
245 IN EFI_HANDLE *ChildHandleBuffer
246 )
247 {
248 PRIVATE_UDF_SIMPLE_FS_DATA *PrivFsData;
249 EFI_STATUS Status;
250 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFs;
251
252 //
253 // Open SimpleFs protocol on ControllerHandle
254 //
255 Status = gBS->OpenProtocol (
256 ControllerHandle,
257 &gEfiSimpleFileSystemProtocolGuid,
258 (VOID **)&SimpleFs,
259 This->DriverBindingHandle,
260 ControllerHandle,
261 EFI_OPEN_PROTOCOL_GET_PROTOCOL
262 );
263 if (!EFI_ERROR (Status)) {
264 PrivFsData = PRIVATE_UDF_SIMPLE_FS_DATA_FROM_THIS (SimpleFs);
265
266 //
267 // Uninstall child handle
268 //
269 Status = gBS->UninstallMultipleProtocolInterfaces (
270 PrivFsData->Handle,
271 &gEfiSimpleFileSystemProtocolGuid,
272 &PrivFsData->SimpleFs,
273 NULL
274 );
275
276 FreePool ((VOID *)PrivFsData);
277 }
278
279 if (!EFI_ERROR (Status)) {
280 //
281 // Close DiskIo protocol on ControllerHandle
282 //
283 gBS->CloseProtocol (
284 ControllerHandle,
285 &gEfiDiskIoProtocolGuid,
286 This->DriverBindingHandle,
287 ControllerHandle
288 );
289 //
290 // Close BlockIo protocol on ControllerHandle
291 //
292 gBS->CloseProtocol (
293 ControllerHandle,
294 &gEfiBlockIoProtocolGuid,
295 This->DriverBindingHandle,
296 ControllerHandle
297 );
298 }
299
300 return Status;
301 }
302
303 /**
304 The user Entry Point for UDF file system driver. The user code starts with
305 this function.
306
307 @param[in] ImageHandle The firmware allocated handle for the EFI image.
308 @param[in] SystemTable A pointer to the EFI System Table.
309
310 @retval EFI_SUCCESS The entry point is executed successfully.
311 @retval other Some error occurs when executing this entry point.
312
313 **/
314 EFI_STATUS
315 EFIAPI
316 InitializeUdf (
317 IN EFI_HANDLE ImageHandle,
318 IN EFI_SYSTEM_TABLE *SystemTable
319 )
320 {
321 EFI_STATUS Status;
322
323 Status = EfiLibInstallDriverBindingComponentName2 (
324 ImageHandle,
325 SystemTable,
326 &gUdfDriverBinding,
327 ImageHandle,
328 &gUdfComponentName,
329 &gUdfComponentName2
330 );
331 ASSERT_EFI_ERROR (Status);
332
333 return Status;
334 }