]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.h
Add DiskIo2 protocol definition to MdePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / DiskIoDxe / DiskIo.h
... / ...
CommitLineData
1/** @file\r
2 Master header file for DiskIo driver. It includes the module private defininitions.\r
3\r
4Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _DISK_IO_H_\r
16#define _DISK_IO_H_\r
17\r
18#include <Uefi.h>\r
19#include <Protocol/BlockIo.h>\r
20#include <Protocol/BlockIo2.h>\r
21#include <Protocol/DiskIo2.h>\r
22#include <Protocol/ComponentName.h>\r
23#include <Protocol/DriverBinding.h>\r
24#include <Protocol/DiskIo.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/UefiDriverEntryPoint.h>\r
27#include <Library/UefiLib.h>\r
28#include <Library/BaseLib.h>\r
29#include <Library/BaseMemoryLib.h>\r
30#include <Library/MemoryAllocationLib.h>\r
31#include <Library/UefiBootServicesTableLib.h>\r
32\r
33//\r
34// Pre-allocate an aligned buffer of 64 blocks so very large Disk I/O requests\r
35// will be broken up into 64 * BlockSize chunks to provide better performance\r
36// than allocating an aligned 1 block buffer.\r
37//\r
38#define DATA_BUFFER_BLOCK_NUM 64\r
39\r
40#define DISK_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('d', 's', 'k', 'I')\r
41typedef struct {\r
42 UINT32 Signature;\r
43\r
44 EFI_DISK_IO_PROTOCOL DiskIo;\r
45 EFI_DISK_IO2_PROTOCOL DiskIo2;\r
46 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
47 EFI_BLOCK_IO2_PROTOCOL *BlockIo2;\r
48\r
49 UINT8 *SharedWorkingBuffer;\r
50\r
51 EFI_LOCK TaskQueueLock;\r
52 LIST_ENTRY TaskQueue;\r
53} DISK_IO_PRIVATE_DATA;\r
54#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
55#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO2(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo2, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
56\r
57#define DISK_IO2_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'a', 't')\r
58typedef struct {\r
59 UINT32 Signature;\r
60 LIST_ENTRY Link; /// < link to other task\r
61 LIST_ENTRY Subtasks; /// < header of subtasks\r
62 EFI_DISK_IO2_TOKEN *Token;\r
63 DISK_IO_PRIVATE_DATA *Instance;\r
64} DISK_IO2_TASK;\r
65\r
66#define DISK_IO2_FLUSH_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'f', 't')\r
67typedef struct {\r
68 UINT32 Signature;\r
69 EFI_BLOCK_IO2_TOKEN BlockIo2Token;\r
70 EFI_DISK_IO2_TOKEN *Token;\r
71} DISK_IO2_FLUSH_TASK;\r
72\r
73#define DISK_IO_SUBTASK_SIGNATURE SIGNATURE_32 ('d', 'i', 's', 't')\r
74typedef struct {\r
75 //\r
76 // UnderRun: Offset != 0, Length < BlockSize\r
77 // OverRun: Offset == 0, Length < BlockSize\r
78 // Middle: Offset is block aligned, Length is multiple of block size\r
79 //\r
80 UINT32 Signature;\r
81 LIST_ENTRY Link;\r
82 BOOLEAN Write;\r
83 UINT64 Lba;\r
84 UINT32 Offset;\r
85 UINTN Length;\r
86 UINT8 *WorkingBuffer; /// < NULL indicates using "Buffer" directly\r
87 UINT8 *Buffer;\r
88 BOOLEAN Blocking;\r
89\r
90 //\r
91 // Following fields are for DiskIo2\r
92 //\r
93 DISK_IO2_TASK *Task;\r
94 EFI_BLOCK_IO2_TOKEN BlockIo2Token;\r
95} DISK_IO_SUBTASK;\r
96\r
97//\r
98// Global Variables\r
99//\r
100extern EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding;\r
101extern EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName;\r
102extern EFI_COMPONENT_NAME2_PROTOCOL gDiskIoComponentName2;\r
103\r
104//\r
105// Prototypes\r
106// Driver model protocol interface\r
107//\r
108/**\r
109 Test to see if this driver supports ControllerHandle. \r
110\r
111 @param This Protocol instance pointer.\r
112 @param ControllerHandle Handle of device to test\r
113 @param RemainingDevicePath Optional parameter use to pick a specific child\r
114 device to start.\r
115\r
116 @retval EFI_SUCCESS This driver supports this device\r
117 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
118 @retval other This driver does not support this device\r
119\r
120**/\r
121EFI_STATUS\r
122EFIAPI\r
123DiskIoDriverBindingSupported (\r
124 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
125 IN EFI_HANDLE ControllerHandle,\r
126 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
127 );\r
128\r
129/**\r
130 Start this driver on ControllerHandle by opening a Block IO protocol and\r
131 installing a Disk IO protocol on ControllerHandle.\r
132\r
133 @param This Protocol instance pointer.\r
134 @param ControllerHandle Handle of device to bind driver to\r
135 @param RemainingDevicePath Optional parameter use to pick a specific child\r
136 device to start.\r
137\r
138 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
139 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
140 @retval other This driver does not support this device\r
141\r
142**/\r
143EFI_STATUS\r
144EFIAPI\r
145DiskIoDriverBindingStart (\r
146 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
147 IN EFI_HANDLE ControllerHandle,\r
148 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
149 );\r
150\r
151/**\r
152 Stop this driver on ControllerHandle by removing Disk IO protocol and closing\r
153 the Block IO protocol on ControllerHandle.\r
154\r
155 @param This Protocol instance pointer.\r
156 @param ControllerHandle Handle of device to stop driver on\r
157 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
158 children is zero stop the entire bus driver.\r
159 @param ChildHandleBuffer List of Child Handles to Stop.\r
160\r
161 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
162 @retval other This driver was not removed from this device\r
163\r
164**/\r
165EFI_STATUS\r
166EFIAPI\r
167DiskIoDriverBindingStop (\r
168 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
169 IN EFI_HANDLE ControllerHandle,\r
170 IN UINTN NumberOfChildren,\r
171 IN EFI_HANDLE *ChildHandleBuffer\r
172 );\r
173\r
174//\r
175// Disk I/O Protocol Interface\r
176//\r
177/**\r
178 Read BufferSize bytes from Offset into Buffer.\r
179 Reads may support reads that are not aligned on\r
180 sector boundaries. There are three cases:\r
181 UnderRun - The first byte is not on a sector boundary or the read request is\r
182 less than a sector in length.\r
183 Aligned - A read of N contiguous sectors.\r
184 OverRun - The last byte is not on a sector boundary.\r
185\r
186 @param This Protocol instance pointer.\r
187 @param MediaId Id of the media, changes every time the media is replaced.\r
188 @param Offset The starting byte offset to read from\r
189 @param BufferSize Size of Buffer\r
190 @param Buffer Buffer containing read data\r
191\r
192 @retval EFI_SUCCESS The data was read correctly from the device.\r
193 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r
194 @retval EFI_NO_MEDIA There is no media in the device.\r
195 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
196 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not\r
197 valid for the device.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202DiskIoReadDisk (\r
203 IN EFI_DISK_IO_PROTOCOL *This,\r
204 IN UINT32 MediaId,\r
205 IN UINT64 Offset,\r
206 IN UINTN BufferSize,\r
207 OUT VOID *Buffer\r
208 );\r
209\r
210/**\r
211 Writes BufferSize bytes from Buffer into Offset.\r
212 Writes may require a read modify write to support writes that are not\r
213 aligned on sector boundaries. There are three cases:\r
214 UnderRun - The first byte is not on a sector boundary or the write request\r
215 is less than a sector in length. Read modify write is required.\r
216 Aligned - A write of N contiguous sectors.\r
217 OverRun - The last byte is not on a sector boundary. Read modified write\r
218 required.\r
219\r
220 @param This Protocol instance pointer.\r
221 @param MediaId Id of the media, changes every time the media is replaced.\r
222 @param Offset The starting byte offset to read from\r
223 @param BufferSize Size of Buffer\r
224 @param Buffer Buffer containing read data\r
225\r
226 @retval EFI_SUCCESS The data was written correctly to the device.\r
227 @retval EFI_WRITE_PROTECTED The device can not be written to.\r
228 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
229 @retval EFI_NO_MEDIA There is no media in the device.\r
230 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
231 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not\r
232 valid for the device.\r
233\r
234**/\r
235EFI_STATUS\r
236EFIAPI\r
237DiskIoWriteDisk (\r
238 IN EFI_DISK_IO_PROTOCOL *This,\r
239 IN UINT32 MediaId,\r
240 IN UINT64 Offset,\r
241 IN UINTN BufferSize,\r
242 IN VOID *Buffer\r
243 );\r
244\r
245\r
246/**\r
247 Terminate outstanding asynchronous requests to a device.\r
248\r
249 @param This Indicates a pointer to the calling context.\r
250\r
251 @retval EFI_SUCCESS All outstanding requests were successfully terminated.\r
252 @retval EFI_DEVICE_ERROR The device reported an error while performing the cancel\r
253 operation.\r
254**/\r
255EFI_STATUS\r
256EFIAPI\r
257DiskIo2Cancel (\r
258 IN EFI_DISK_IO2_PROTOCOL *This\r
259 );\r
260\r
261/**\r
262 Reads a specified number of bytes from a device.\r
263\r
264 @param This Indicates a pointer to the calling context.\r
265 @param MediaId ID of the medium to be read.\r
266 @param Offset The starting byte offset on the logical block I/O device to read from.\r
267 @param Token A pointer to the token associated with the transaction.\r
268 If this field is NULL, synchronous/blocking IO is performed.\r
269 @param BufferSize The size in bytes of Buffer. The number of bytes to read from the device.\r
270 @param Buffer A pointer to the destination buffer for the data.\r
271 The caller is responsible either having implicit or explicit ownership of the buffer.\r
272\r
273 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read correctly from the device.\r
274 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
275 Event will be signaled upon completion.\r
276 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
277 @retval EFI_NO_MEDIA There is no medium in the device.\r
278 @retval EFI_MEDIA_CHNAGED The MediaId is not for the current medium.\r
279 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not valid for the device.\r
280 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
281\r
282**/\r
283EFI_STATUS\r
284EFIAPI\r
285DiskIo2ReadDiskEx (\r
286 IN EFI_DISK_IO2_PROTOCOL *This,\r
287 IN UINT32 MediaId,\r
288 IN UINT64 Offset,\r
289 IN OUT EFI_DISK_IO2_TOKEN *Token,\r
290 IN UINTN BufferSize,\r
291 OUT VOID *Buffer\r
292 );\r
293\r
294/**\r
295 Writes a specified number of bytes to a device.\r
296\r
297 @param This Indicates a pointer to the calling context.\r
298 @param MediaId ID of the medium to be written.\r
299 @param Offset The starting byte offset on the logical block I/O device to write to.\r
300 @param Token A pointer to the token associated with the transaction.\r
301 If this field is NULL, synchronous/blocking IO is performed.\r
302 @param BufferSize The size in bytes of Buffer. The number of bytes to write to the device.\r
303 @param Buffer A pointer to the buffer containing the data to be written.\r
304\r
305 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was written correctly to the device.\r
306 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
307 Event will be signaled upon completion.\r
308 @retval EFI_WRITE_PROTECTED The device cannot be written to.\r
309 @retval EFI_DEVICE_ERROR The device reported an error while performing the write operation.\r
310 @retval EFI_NO_MEDIA There is no medium in the device.\r
311 @retval EFI_MEDIA_CHNAGED The MediaId is not for the current medium.\r
312 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not valid for the device.\r
313 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
314\r
315**/\r
316EFI_STATUS\r
317EFIAPI\r
318DiskIo2WriteDiskEx (\r
319 IN EFI_DISK_IO2_PROTOCOL *This,\r
320 IN UINT32 MediaId,\r
321 IN UINT64 Offset,\r
322 IN EFI_DISK_IO2_TOKEN *Token,\r
323 IN UINTN BufferSize,\r
324 IN VOID *Buffer\r
325 );\r
326\r
327/**\r
328 Flushes all modified data to the physical device.\r
329\r
330 @param This Indicates a pointer to the calling context.\r
331 @param Token A pointer to the token associated with the transaction.\r
332 If this field is NULL, synchronous/blocking IO is performed.\r
333\r
334 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was flushed successfully to the device.\r
335 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
336 Event will be signaled upon completion.\r
337 @retval EFI_WRITE_PROTECTED The device cannot be written to.\r
338 @retval EFI_DEVICE_ERROR The device reported an error while performing the write operation.\r
339 @retval EFI_NO_MEDIA There is no medium in the device.\r
340 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
341**/\r
342EFI_STATUS\r
343EFIAPI\r
344DiskIo2FlushDiskEx (\r
345 IN EFI_DISK_IO2_PROTOCOL *This,\r
346 IN OUT EFI_DISK_IO2_TOKEN *Token\r
347 );\r
348\r
349//\r
350// EFI Component Name Functions\r
351//\r
352/**\r
353 Retrieves a Unicode string that is the user readable name of the driver.\r
354\r
355 This function retrieves the user readable name of a driver in the form of a\r
356 Unicode string. If the driver specified by This has a user readable name in\r
357 the language specified by Language, then a pointer to the driver name is\r
358 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
359 by This does not support the language specified by Language,\r
360 then EFI_UNSUPPORTED is returned.\r
361\r
362 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
363 EFI_COMPONENT_NAME_PROTOCOL instance.\r
364\r
365 @param Language[in] A pointer to a Null-terminated ASCII string\r
366 array indicating the language. This is the\r
367 language of the driver name that the caller is\r
368 requesting, and it must match one of the\r
369 languages specified in SupportedLanguages. The\r
370 number of languages supported by a driver is up\r
371 to the driver writer. Language is specified\r
372 in RFC 4646 or ISO 639-2 language code format.\r
373\r
374 @param DriverName[out] A pointer to the Unicode string to return.\r
375 This Unicode string is the name of the\r
376 driver specified by This in the language\r
377 specified by Language.\r
378\r
379 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
380 This and the language specified by Language was\r
381 returned in DriverName.\r
382\r
383 @retval EFI_INVALID_PARAMETER Language is NULL.\r
384\r
385 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
386\r
387 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
388 the language specified by Language.\r
389\r
390**/\r
391EFI_STATUS\r
392EFIAPI\r
393DiskIoComponentNameGetDriverName (\r
394 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
395 IN CHAR8 *Language,\r
396 OUT CHAR16 **DriverName\r
397 );\r
398\r
399\r
400/**\r
401 Retrieves a Unicode string that is the user readable name of the controller\r
402 that is being managed by a driver.\r
403\r
404 This function retrieves the user readable name of the controller specified by\r
405 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
406 driver specified by This has a user readable name in the language specified by\r
407 Language, then a pointer to the controller name is returned in ControllerName,\r
408 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
409 managing the controller specified by ControllerHandle and ChildHandle,\r
410 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
411 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
412\r
413 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
414 EFI_COMPONENT_NAME_PROTOCOL instance.\r
415\r
416 @param ControllerHandle[in] The handle of a controller that the driver\r
417 specified by This is managing. This handle\r
418 specifies the controller whose name is to be\r
419 returned.\r
420\r
421 @param ChildHandle[in] The handle of the child controller to retrieve\r
422 the name of. This is an optional parameter that\r
423 may be NULL. It will be NULL for device\r
424 drivers. It will also be NULL for a bus drivers\r
425 that wish to retrieve the name of the bus\r
426 controller. It will not be NULL for a bus\r
427 driver that wishes to retrieve the name of a\r
428 child controller.\r
429\r
430 @param Language[in] A pointer to a Null-terminated ASCII string\r
431 array indicating the language. This is the\r
432 language of the driver name that the caller is\r
433 requesting, and it must match one of the\r
434 languages specified in SupportedLanguages. The\r
435 number of languages supported by a driver is up\r
436 to the driver writer. Language is specified in\r
437 RFC 4646 or ISO 639-2 language code format.\r
438\r
439 @param ControllerName[out] A pointer to the Unicode string to return.\r
440 This Unicode string is the name of the\r
441 controller specified by ControllerHandle and\r
442 ChildHandle in the language specified by\r
443 Language from the point of view of the driver\r
444 specified by This.\r
445\r
446 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
447 the language specified by Language for the\r
448 driver specified by This was returned in\r
449 DriverName.\r
450\r
451 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
452\r
453 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
454 EFI_HANDLE.\r
455\r
456 @retval EFI_INVALID_PARAMETER Language is NULL.\r
457\r
458 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
459\r
460 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
461 managing the controller specified by\r
462 ControllerHandle and ChildHandle.\r
463\r
464 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
465 the language specified by Language.\r
466\r
467**/\r
468EFI_STATUS\r
469EFIAPI\r
470DiskIoComponentNameGetControllerName (\r
471 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
472 IN EFI_HANDLE ControllerHandle,\r
473 IN EFI_HANDLE ChildHandle OPTIONAL,\r
474 IN CHAR8 *Language,\r
475 OUT CHAR16 **ControllerName\r
476 );\r
477\r
478\r
479#endif\r