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