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