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