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