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