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