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