]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Partition.h
1 /** @file
2 Partition driver that produces logical BlockIo devices from a physical
3 BlockIo device. The logical BlockIo devices are based on the format
4 of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy
5 MBR, and GPT partition schemes are supported.
6
7 Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.
8 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10
11 **/
12
13 #ifndef _PARTITION_H_
14 #define _PARTITION_H_
15
16 #include <Uefi.h>
17 #include <Protocol/BlockIo.h>
18 #include <Protocol/BlockIo2.h>
19 #include <Guid/Gpt.h>
20 #include <Protocol/ComponentName.h>
21 #include <Protocol/DevicePath.h>
22 #include <Protocol/DriverBinding.h>
23 #include <Protocol/DiskIo.h>
24 #include <Protocol/DiskIo2.h>
25 #include <Protocol/PartitionInfo.h>
26 #include <Library/DebugLib.h>
27 #include <Library/UefiDriverEntryPoint.h>
28 #include <Library/BaseLib.h>
29 #include <Library/UefiLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/MemoryAllocationLib.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/DevicePathLib.h>
34
35 #include <IndustryStandard/Mbr.h>
36 #include <IndustryStandard/ElTorito.h>
37 #include <IndustryStandard/Udf.h>
38
39 //
40 // Partition private data
41 //
42 #define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')
43 typedef struct {
44 UINT64 Signature;
45
46 EFI_HANDLE Handle;
47 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
48 EFI_BLOCK_IO_PROTOCOL BlockIo;
49 EFI_BLOCK_IO2_PROTOCOL BlockIo2;
50 EFI_BLOCK_IO_MEDIA Media;
51 EFI_BLOCK_IO_MEDIA Media2;// For BlockIO2
52 EFI_PARTITION_INFO_PROTOCOL PartitionInfo;
53
54 EFI_DISK_IO_PROTOCOL *DiskIo;
55 EFI_DISK_IO2_PROTOCOL *DiskIo2;
56 EFI_BLOCK_IO_PROTOCOL *ParentBlockIo;
57 EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2;
58 UINT64 Start;
59 UINT64 End;
60 UINT32 BlockSize;
61 BOOLEAN InStop;
62
63 EFI_GUID TypeGuid;
64 } PARTITION_PRIVATE_DATA;
65
66 typedef struct {
67 EFI_DISK_IO2_TOKEN DiskIo2Token;
68 EFI_BLOCK_IO2_TOKEN *BlockIo2Token;
69 } PARTITION_ACCESS_TASK;
70
71 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)
72 #define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE)
73
74 //
75 // Global Variables
76 //
77 extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding;
78 extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName;
79 extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2;
80
81 //
82 // Extract INT32 from char array
83 //
84 #define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
85 (((UINT8 *) a)[1] << 8) | \
86 (((UINT8 *) a)[2] << 16) | \
87 (((UINT8 *) a)[3] << 24) )
88
89 //
90 // Extract UINT32 from char array
91 //
92 #define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
93 (((UINT8 *) a)[1] << 8) | \
94 (((UINT8 *) a)[2] << 16) | \
95 (((UINT8 *) a)[3] << 24) )
96
97 //
98 // GPT Partition Entry Status
99 //
100 typedef struct {
101 BOOLEAN OutOfRange;
102 BOOLEAN Overlap;
103 BOOLEAN OsSpecific;
104 } EFI_PARTITION_ENTRY_STATUS;
105
106 //
107 // Function Prototypes
108 //
109
110 /**
111 Test to see if this driver supports ControllerHandle. Any ControllerHandle
112 than contains a BlockIo and DiskIo protocol can be supported.
113
114 @param This Protocol instance pointer.
115 @param ControllerHandle Handle of device to test
116 @param RemainingDevicePath Optional parameter use to pick a specific child
117 device to start.
118
119 @retval EFI_SUCCESS This driver supports this device
120 @retval EFI_ALREADY_STARTED This driver is already running on this device
121 @retval other This driver does not support this device
122
123 **/
124 EFI_STATUS
125 EFIAPI
126 PartitionDriverBindingSupported (
127 IN EFI_DRIVER_BINDING_PROTOCOL *This,
128 IN EFI_HANDLE ControllerHandle,
129 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
130 );
131
132 /**
133 Start this driver on ControllerHandle by opening a Block IO and Disk IO
134 protocol, reading Device Path, and creating a child handle with a
135 Disk IO and device path protocol.
136
137 @param This Protocol instance pointer.
138 @param ControllerHandle Handle of device to bind driver to
139 @param RemainingDevicePath Optional parameter use to pick a specific child
140 device to start.
141
142 @retval EFI_SUCCESS This driver is added to ControllerHandle
143 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
144 @retval other This driver does not support this device
145
146 **/
147 EFI_STATUS
148 EFIAPI
149 PartitionDriverBindingStart (
150 IN EFI_DRIVER_BINDING_PROTOCOL *This,
151 IN EFI_HANDLE ControllerHandle,
152 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
153 );
154
155 /**
156 Stop this driver on ControllerHandle. Support stopping any child handles
157 created by this driver.
158
159 @param This Protocol instance pointer.
160 @param ControllerHandle Handle of device to stop driver on
161 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
162 children is zero stop the entire bus driver.
163 @param ChildHandleBuffer List of Child Handles to Stop.
164
165 @retval EFI_SUCCESS This driver is removed ControllerHandle
166 @retval other This driver was not removed from this device
167
168 **/
169 EFI_STATUS
170 EFIAPI
171 PartitionDriverBindingStop (
172 IN EFI_DRIVER_BINDING_PROTOCOL *This,
173 IN EFI_HANDLE ControllerHandle,
174 IN UINTN NumberOfChildren,
175 IN EFI_HANDLE *ChildHandleBuffer
176 );
177
178 //
179 // EFI Component Name Functions
180 //
181
182 /**
183 Retrieves a Unicode string that is the user readable name of the driver.
184
185 This function retrieves the user readable name of a driver in the form of a
186 Unicode string. If the driver specified by This has a user readable name in
187 the language specified by Language, then a pointer to the driver name is
188 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
189 by This does not support the language specified by Language,
190 then EFI_UNSUPPORTED is returned.
191
192 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
193 EFI_COMPONENT_NAME_PROTOCOL instance.
194
195 @param Language[in] A pointer to a Null-terminated ASCII string
196 array indicating the language. This is the
197 language of the driver name that the caller is
198 requesting, and it must match one of the
199 languages specified in SupportedLanguages. The
200 number of languages supported by a driver is up
201 to the driver writer. Language is specified
202 in RFC 4646 or ISO 639-2 language code format.
203
204 @param DriverName[out] A pointer to the Unicode string to return.
205 This Unicode string is the name of the
206 driver specified by This in the language
207 specified by Language.
208
209 @retval EFI_SUCCESS The Unicode string for the Driver specified by
210 This and the language specified by Language was
211 returned in DriverName.
212
213 @retval EFI_INVALID_PARAMETER Language is NULL.
214
215 @retval EFI_INVALID_PARAMETER DriverName is NULL.
216
217 @retval EFI_UNSUPPORTED The driver specified by This does not support
218 the language specified by Language.
219
220 **/
221 EFI_STATUS
222 EFIAPI
223 PartitionComponentNameGetDriverName (
224 IN EFI_COMPONENT_NAME_PROTOCOL *This,
225 IN CHAR8 *Language,
226 OUT CHAR16 **DriverName
227 );
228
229 /**
230 Retrieves a Unicode string that is the user readable name of the controller
231 that is being managed by a driver.
232
233 This function retrieves the user readable name of the controller specified by
234 ControllerHandle and ChildHandle in the form of a Unicode string. If the
235 driver specified by This has a user readable name in the language specified by
236 Language, then a pointer to the controller name is returned in ControllerName,
237 and EFI_SUCCESS is returned. If the driver specified by This is not currently
238 managing the controller specified by ControllerHandle and ChildHandle,
239 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
240 support the language specified by Language, then EFI_UNSUPPORTED is returned.
241
242 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
243 EFI_COMPONENT_NAME_PROTOCOL instance.
244
245 @param ControllerHandle[in] The handle of a controller that the driver
246 specified by This is managing. This handle
247 specifies the controller whose name is to be
248 returned.
249
250 @param ChildHandle[in] The handle of the child controller to retrieve
251 the name of. This is an optional parameter that
252 may be NULL. It will be NULL for device
253 drivers. It will also be NULL for a bus drivers
254 that wish to retrieve the name of the bus
255 controller. It will not be NULL for a bus
256 driver that wishes to retrieve the name of a
257 child controller.
258
259 @param Language[in] A pointer to a Null-terminated ASCII string
260 array indicating the language. This is the
261 language of the driver name that the caller is
262 requesting, and it must match one of the
263 languages specified in SupportedLanguages. The
264 number of languages supported by a driver is up
265 to the driver writer. Language is specified in
266 RFC 4646 or ISO 639-2 language code format.
267
268 @param ControllerName[out] A pointer to the Unicode string to return.
269 This Unicode string is the name of the
270 controller specified by ControllerHandle and
271 ChildHandle in the language specified by
272 Language from the point of view of the driver
273 specified by This.
274
275 @retval EFI_SUCCESS The Unicode string for the user readable name in
276 the language specified by Language for the
277 driver specified by This was returned in
278 DriverName.
279
280 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
281
282 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
283 EFI_HANDLE.
284
285 @retval EFI_INVALID_PARAMETER Language is NULL.
286
287 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
288
289 @retval EFI_UNSUPPORTED The driver specified by This is not currently
290 managing the controller specified by
291 ControllerHandle and ChildHandle.
292
293 @retval EFI_UNSUPPORTED The driver specified by This does not support
294 the language specified by Language.
295
296 **/
297 EFI_STATUS
298 EFIAPI
299 PartitionComponentNameGetControllerName (
300 IN EFI_COMPONENT_NAME_PROTOCOL *This,
301 IN EFI_HANDLE ControllerHandle,
302 IN EFI_HANDLE ChildHandle OPTIONAL,
303 IN CHAR8 *Language,
304 OUT CHAR16 **ControllerName
305 );
306
307 /**
308 Create a child handle for a logical block device that represents the
309 bytes Start to End of the Parent Block IO device.
310
311 @param[in] This Protocol instance pointer.
312 @param[in] ParentHandle Parent Handle for new child.
313 @param[in] ParentDiskIo Parent DiskIo interface.
314 @param[in] ParentDiskIo2 Parent DiskIo2 interface.
315 @param[in] ParentBlockIo Parent BlockIo interface.
316 @param[in] ParentBlockIo2 Parent BlockIo2 interface.
317 @param[in] ParentDevicePath Parent Device Path.
318 @param[in] DevicePathNode Child Device Path node.
319 @param[in] PartitionInfo Child Partition Information interface.
320 @param[in] Start Start Block.
321 @param[in] End End Block.
322 @param[in] BlockSize Child block size.
323 @param[in] TypeGuid Parition Type Guid.
324
325 @retval EFI_SUCCESS A child handle was added.
326 @retval other A child handle was not added.
327
328 **/
329 EFI_STATUS
330 PartitionInstallChildHandle (
331 IN EFI_DRIVER_BINDING_PROTOCOL *This,
332 IN EFI_HANDLE ParentHandle,
333 IN EFI_DISK_IO_PROTOCOL *ParentDiskIo,
334 IN EFI_DISK_IO2_PROTOCOL *ParentDiskIo2,
335 IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo,
336 IN EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2,
337 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
338 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
339 IN EFI_PARTITION_INFO_PROTOCOL *PartitionInfo,
340 IN EFI_LBA Start,
341 IN EFI_LBA End,
342 IN UINT32 BlockSize,
343 IN EFI_GUID *TypeGuid
344 );
345
346 /**
347 Test to see if there is any child on ControllerHandle.
348
349 @param[in] ControllerHandle Handle of device to test.
350
351 @retval TRUE There are children on the ControllerHandle.
352 @retval FALSE No child is on the ControllerHandle.
353
354 **/
355 BOOLEAN
356 HasChildren (
357 IN EFI_HANDLE ControllerHandle
358 );
359
360 /**
361 Install child handles if the Handle supports GPT partition structure.
362
363 @param[in] This Calling context.
364 @param[in] Handle Parent Handle.
365 @param[in] DiskIo Parent DiskIo interface.
366 @param[in] DiskIo2 Parent DiskIo2 interface.
367 @param[in] BlockIo Parent BlockIo interface.
368 @param[in] BlockIo2 Parent BlockIo2 interface.
369 @param[in] DevicePath Parent Device Path.
370
371 @retval EFI_SUCCESS Valid GPT disk.
372 @retval EFI_MEDIA_CHANGED Media changed Detected.
373 @retval EFI_INVALID_PARAMETER If both BlockIo and BlockIo2 are NULL;
374 @retval other Not a valid GPT disk.
375
376 **/
377 EFI_STATUS
378 PartitionInstallGptChildHandles (
379 IN EFI_DRIVER_BINDING_PROTOCOL *This,
380 IN EFI_HANDLE Handle,
381 IN EFI_DISK_IO_PROTOCOL *DiskIo,
382 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
383 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
384 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,
385 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
386 );
387
388 /**
389 Install child handles if the Handle supports El Torito format.
390
391 @param[in] This Calling context.
392 @param[in] Handle Parent Handle.
393 @param[in] DiskIo Parent DiskIo interface.
394 @param[in] DiskIo2 Parent DiskIo2 interface.
395 @param[in] BlockIo Parent BlockIo interface.
396 @param[in] BlockIo2 Parent BlockIo2 interface.
397 @param[in] DevicePath Parent Device Path
398
399
400 @retval EFI_SUCCESS Child handle(s) was added.
401 @retval EFI_MEDIA_CHANGED Media changed Detected.
402 @retval other no child handle was added.
403
404 **/
405 EFI_STATUS
406 PartitionInstallElToritoChildHandles (
407 IN EFI_DRIVER_BINDING_PROTOCOL *This,
408 IN EFI_HANDLE Handle,
409 IN EFI_DISK_IO_PROTOCOL *DiskIo,
410 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
411 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
412 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,
413 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
414 );
415
416 /**
417 Install child handles if the Handle supports MBR format.
418
419 @param[in] This Calling context.
420 @param[in] Handle Parent Handle.
421 @param[in] DiskIo Parent DiskIo interface.
422 @param[in] DiskIo2 Parent DiskIo2 interface.
423 @param[in] BlockIo Parent BlockIo interface.
424 @param[in] BlockIo2 Parent BlockIo2 interface.
425 @param[in] DevicePath Parent Device Path.
426
427 @retval EFI_SUCCESS A child handle was added.
428 @retval EFI_MEDIA_CHANGED Media change was detected.
429 @retval Others MBR partition was not found.
430
431 **/
432 EFI_STATUS
433 PartitionInstallMbrChildHandles (
434 IN EFI_DRIVER_BINDING_PROTOCOL *This,
435 IN EFI_HANDLE Handle,
436 IN EFI_DISK_IO_PROTOCOL *DiskIo,
437 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
438 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
439 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,
440 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
441 );
442
443 /**
444 Install child handles if the Handle supports UDF/ECMA-167 volume format.
445
446 @param[in] This Calling context.
447 @param[in] Handle Parent Handle.
448 @param[in] DiskIo Parent DiskIo interface.
449 @param[in] DiskIo2 Parent DiskIo2 interface.
450 @param[in] BlockIo Parent BlockIo interface.
451 @param[in] BlockIo2 Parent BlockIo2 interface.
452 @param[in] DevicePath Parent Device Path
453
454
455 @retval EFI_SUCCESS Child handle(s) was added.
456 @retval EFI_MEDIA_CHANGED Media changed Detected.
457 @retval other no child handle was added.
458
459 **/
460 EFI_STATUS
461 PartitionInstallUdfChildHandles (
462 IN EFI_DRIVER_BINDING_PROTOCOL *This,
463 IN EFI_HANDLE Handle,
464 IN EFI_DISK_IO_PROTOCOL *DiskIo,
465 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
466 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
467 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,
468 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
469 );
470
471 typedef
472 EFI_STATUS
473 (*PARTITION_DETECT_ROUTINE) (
474 IN EFI_DRIVER_BINDING_PROTOCOL *This,
475 IN EFI_HANDLE Handle,
476 IN EFI_DISK_IO_PROTOCOL *DiskIo,
477 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
478 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
479 IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,
480 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
481 );
482
483 #endif