]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.h
MdeModulePkg/NvmExpressDxe: Memory leak fix in async code flow
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / NvmExpressDxe / NvmExpress.h
CommitLineData
eb290d02
FT
1/** @file\r
2 NvmExpressDxe driver is used to manage non-volatile memory subsystem which follows\r
3 NVM Express specification.\r
4\r
e79bed78 5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
5db1ac89 6 Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>\r
eb290d02
FT
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#ifndef _EFI_NVM_EXPRESS_H_\r
18#define _EFI_NVM_EXPRESS_H_\r
19\r
20#include <Uefi.h>\r
21\r
22#include <IndustryStandard/Pci.h>\r
e79bed78 23#include <IndustryStandard/Nvme.h>\r
eb290d02
FT
24\r
25#include <Protocol/ComponentName.h>\r
26#include <Protocol/ComponentName2.h>\r
27#include <Protocol/DriverBinding.h>\r
28#include <Protocol/LoadedImage.h>\r
29#include <Protocol/DevicePath.h>\r
30#include <Protocol/PciIo.h>\r
d6c55989 31#include <Protocol/NvmExpressPassthru.h>\r
eb290d02 32#include <Protocol/BlockIo.h>\r
758ea946 33#include <Protocol/BlockIo2.h>\r
eb290d02
FT
34#include <Protocol/DiskInfo.h>\r
35#include <Protocol/DriverSupportedEfiVersion.h>\r
754b489b 36#include <Protocol/StorageSecurityCommand.h>\r
eb290d02
FT
37\r
38#include <Library/BaseLib.h>\r
39#include <Library/BaseMemoryLib.h>\r
40#include <Library/DebugLib.h>\r
41#include <Library/PrintLib.h>\r
42#include <Library/UefiLib.h>\r
43#include <Library/DevicePathLib.h>\r
44#include <Library/MemoryAllocationLib.h>\r
45#include <Library/UefiBootServicesTableLib.h>\r
46#include <Library/UefiDriverEntryPoint.h>\r
47\r
48typedef struct _NVME_CONTROLLER_PRIVATE_DATA NVME_CONTROLLER_PRIVATE_DATA;\r
49typedef struct _NVME_DEVICE_PRIVATE_DATA NVME_DEVICE_PRIVATE_DATA;\r
50\r
eb290d02
FT
51#include "NvmExpressBlockIo.h"\r
52#include "NvmExpressDiskInfo.h"\r
53#include "NvmExpressHci.h"\r
54\r
55extern EFI_DRIVER_BINDING_PROTOCOL gNvmExpressDriverBinding;\r
56extern EFI_COMPONENT_NAME_PROTOCOL gNvmExpressComponentName;\r
57extern EFI_COMPONENT_NAME2_PROTOCOL gNvmExpressComponentName2;\r
58extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gNvmExpressDriverSupportedEfiVersion;\r
59\r
60#define PCI_CLASS_MASS_STORAGE_NVM 0x08 // mass storage sub-class non-volatile memory.\r
61#define PCI_IF_NVMHCI 0x02 // mass storage programming interface NVMHCI.\r
62\r
7b8883c6
FT
63#define NVME_ASQ_SIZE 1 // Number of admin submission queue entries, which is 0-based\r
64#define NVME_ACQ_SIZE 1 // Number of admin completion queue entries, which is 0-based\r
eb290d02 65\r
7b8883c6
FT
66#define NVME_CSQ_SIZE 1 // Number of I/O submission queue entries, which is 0-based\r
67#define NVME_CCQ_SIZE 1 // Number of I/O completion queue entries, which is 0-based\r
eb290d02 68\r
758ea946
HW
69//\r
70// Number of asynchronous I/O submission queue entries, which is 0-based.\r
71// The asynchronous I/O submission queue size is 4kB in total.\r
72//\r
73#define NVME_ASYNC_CSQ_SIZE 63\r
74//\r
75// Number of asynchronous I/O completion queue entries, which is 0-based.\r
76// The asynchronous I/O completion queue size is 4kB in total.\r
77//\r
78#define NVME_ASYNC_CCQ_SIZE 255\r
79\r
80#define NVME_MAX_QUEUES 3 // Number of queues supported by the driver\r
eb290d02
FT
81\r
82#define NVME_CONTROLLER_ID 0\r
83\r
84//\r
85// Time out value for Nvme transaction execution\r
86//\r
87#define NVME_GENERIC_TIMEOUT EFI_TIMER_PERIOD_SECONDS (5)\r
88\r
758ea946
HW
89//\r
90// Nvme async transfer timer interval, set by experience.\r
91//\r
92#define NVME_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS (1)\r
93\r
eb290d02
FT
94//\r
95// Unique signature for private data structure.\r
96//\r
97#define NVME_CONTROLLER_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('N','V','M','E')\r
98\r
99//\r
100// Nvme private data structure.\r
101//\r
102struct _NVME_CONTROLLER_PRIVATE_DATA {\r
d6c55989 103 UINT32 Signature;\r
eb290d02 104\r
d6c55989
FT
105 EFI_HANDLE ControllerHandle;\r
106 EFI_HANDLE ImageHandle;\r
107 EFI_HANDLE DriverBindingHandle;\r
eb290d02 108\r
d6c55989
FT
109 EFI_PCI_IO_PROTOCOL *PciIo;\r
110 UINT64 PciAttributes;\r
eb290d02 111\r
d6c55989 112 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
eb290d02 113\r
d6c55989
FT
114 EFI_NVM_EXPRESS_PASS_THRU_MODE PassThruMode;\r
115 EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL Passthru;\r
eb290d02
FT
116\r
117 //\r
118 // pointer to identify controller data\r
119 //\r
d6c55989 120 NVME_ADMIN_CONTROLLER_DATA *ControllerData;\r
eb290d02
FT
121\r
122 //\r
758ea946 123 // 6 x 4kB aligned buffers will be carved out of this buffer.\r
eb290d02 124 // 1st 4kB boundary is the start of the admin submission queue.\r
5db1ac89
FT
125 // 2nd 4kB boundary is the start of the admin completion queue.\r
126 // 3rd 4kB boundary is the start of I/O submission queue #1.\r
127 // 4th 4kB boundary is the start of I/O completion queue #1.\r
758ea946
HW
128 // 5th 4kB boundary is the start of I/O submission queue #2.\r
129 // 6th 4kB boundary is the start of I/O completion queue #2.\r
eb290d02 130 //\r
d6c55989
FT
131 UINT8 *Buffer;\r
132 UINT8 *BufferPciAddr;\r
eb290d02
FT
133\r
134 //\r
135 // Pointers to 4kB aligned submission & completion queues.\r
136 //\r
d6c55989
FT
137 NVME_SQ *SqBuffer[NVME_MAX_QUEUES];\r
138 NVME_CQ *CqBuffer[NVME_MAX_QUEUES];\r
139 NVME_SQ *SqBufferPciAddr[NVME_MAX_QUEUES];\r
140 NVME_CQ *CqBufferPciAddr[NVME_MAX_QUEUES];\r
eb290d02
FT
141\r
142 //\r
143 // Submission and completion queue indices.\r
144 //\r
d6c55989
FT
145 NVME_SQTDBL SqTdbl[NVME_MAX_QUEUES];\r
146 NVME_CQHDBL CqHdbl[NVME_MAX_QUEUES];\r
758ea946 147 UINT16 AsyncSqHead;\r
eb290d02 148\r
d6c55989
FT
149 UINT8 Pt[NVME_MAX_QUEUES];\r
150 UINT16 Cid[NVME_MAX_QUEUES];\r
eb290d02
FT
151\r
152 //\r
153 // Nvme controller capabilities\r
154 //\r
d6c55989 155 NVME_CAP Cap;\r
eb290d02 156\r
d6c55989 157 VOID *Mapping;\r
758ea946
HW
158\r
159 //\r
160 // For Non-blocking operations.\r
161 //\r
162 EFI_EVENT TimerEvent;\r
163 LIST_ENTRY AsyncPassThruQueue;\r
164 LIST_ENTRY UnsubmittedSubtasks;\r
eb290d02
FT
165};\r
166\r
167#define NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU(a) \\r
168 CR (a, \\r
169 NVME_CONTROLLER_PRIVATE_DATA, \\r
170 Passthru, \\r
171 NVME_CONTROLLER_PRIVATE_DATA_SIGNATURE \\r
172 )\r
173\r
174//\r
175// Unique signature for private data structure.\r
176//\r
177#define NVME_DEVICE_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('X','S','S','D')\r
178\r
179//\r
180// Nvme device private data structure\r
181//\r
182struct _NVME_DEVICE_PRIVATE_DATA {\r
754b489b 183 UINT32 Signature;\r
eb290d02 184\r
754b489b
TF
185 EFI_HANDLE DeviceHandle;\r
186 EFI_HANDLE ControllerHandle;\r
187 EFI_HANDLE DriverBindingHandle;\r
eb290d02 188\r
754b489b 189 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
eb290d02 190\r
754b489b 191 EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r
eb290d02 192\r
754b489b
TF
193 UINT32 NamespaceId;\r
194 UINT64 NamespaceUuid;\r
eb290d02 195\r
754b489b
TF
196 EFI_BLOCK_IO_MEDIA Media;\r
197 EFI_BLOCK_IO_PROTOCOL BlockIo;\r
758ea946 198 EFI_BLOCK_IO2_PROTOCOL BlockIo2;\r
754b489b
TF
199 EFI_DISK_INFO_PROTOCOL DiskInfo;\r
200 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL StorageSecurity;\r
eb290d02 201\r
758ea946
HW
202 LIST_ENTRY AsyncQueue;\r
203\r
754b489b 204 EFI_LBA NumBlocks;\r
eb290d02 205\r
754b489b
TF
206 CHAR16 ModelName[80];\r
207 NVME_ADMIN_NAMESPACE_DATA NamespaceData;\r
eb290d02 208\r
754b489b 209 NVME_CONTROLLER_PRIVATE_DATA *Controller;\r
eb290d02
FT
210\r
211};\r
212\r
213//\r
214// Statments to retrieve the private data from produced protocols.\r
215//\r
216#define NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO(a) \\r
217 CR (a, \\r
218 NVME_DEVICE_PRIVATE_DATA, \\r
219 BlockIo, \\r
220 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \\r
221 )\r
222\r
758ea946
HW
223#define NVME_DEVICE_PRIVATE_DATA_FROM_BLOCK_IO2(a) \\r
224 CR (a, \\r
225 NVME_DEVICE_PRIVATE_DATA, \\r
226 BlockIo2, \\r
227 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \\r
228 )\r
229\r
eb290d02
FT
230#define NVME_DEVICE_PRIVATE_DATA_FROM_DISK_INFO(a) \\r
231 CR (a, \\r
232 NVME_DEVICE_PRIVATE_DATA, \\r
233 DiskInfo, \\r
234 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \\r
235 )\r
236\r
754b489b
TF
237#define NVME_DEVICE_PRIVATE_DATA_FROM_STORAGE_SECURITY(a)\\r
238 CR (a, \\r
239 NVME_DEVICE_PRIVATE_DATA, \\r
240 StorageSecurity, \\r
241 NVME_DEVICE_PRIVATE_DATA_SIGNATURE \\r
242 )\r
243\r
758ea946
HW
244//\r
245// Nvme block I/O 2 request.\r
246//\r
247#define NVME_BLKIO2_REQUEST_SIGNATURE SIGNATURE_32 ('N', 'B', '2', 'R')\r
248\r
249typedef struct {\r
250 UINT32 Signature;\r
251 LIST_ENTRY Link;\r
252\r
253 EFI_BLOCK_IO2_TOKEN *Token;\r
254 UINTN UnsubmittedSubtaskNum;\r
255 BOOLEAN LastSubtaskSubmitted;\r
256 //\r
257 // The queue for Nvme read/write sub-tasks of a BlockIo2 request.\r
258 //\r
259 LIST_ENTRY SubtasksQueue;\r
260} NVME_BLKIO2_REQUEST;\r
261\r
262#define NVME_BLKIO2_REQUEST_FROM_LINK(a) \\r
263 CR (a, NVME_BLKIO2_REQUEST, Link, NVME_BLKIO2_REQUEST_SIGNATURE)\r
264\r
265#define NVME_BLKIO2_SUBTASK_SIGNATURE SIGNATURE_32 ('N', 'B', '2', 'S')\r
266\r
267typedef struct {\r
268 UINT32 Signature;\r
269 LIST_ENTRY Link;\r
270\r
271 BOOLEAN IsLast;\r
272 UINT32 NamespaceId;\r
273 EFI_EVENT Event;\r
274 EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *CommandPacket;\r
275 //\r
276 // The BlockIo2 request this subtask belongs to\r
277 //\r
278 NVME_BLKIO2_REQUEST *BlockIo2Request;\r
279} NVME_BLKIO2_SUBTASK;\r
280\r
281#define NVME_BLKIO2_SUBTASK_FROM_LINK(a) \\r
282 CR (a, NVME_BLKIO2_SUBTASK, Link, NVME_BLKIO2_SUBTASK_SIGNATURE)\r
283\r
284//\r
285// Nvme asynchronous passthru request.\r
286//\r
287#define NVME_PASS_THRU_ASYNC_REQ_SIG SIGNATURE_32 ('N', 'P', 'A', 'R')\r
288\r
289typedef struct {\r
290 UINT32 Signature;\r
291 LIST_ENTRY Link;\r
292\r
293 EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet;\r
294 UINT16 CommandId;\r
f2333c70
SP
295 VOID *MapPrpList;\r
296 UINTN PrpListNo;\r
297 VOID *PrpListHost;\r
298 VOID *MapData;\r
299 VOID *MapMeta;\r
758ea946
HW
300 EFI_EVENT CallerEvent;\r
301} NVME_PASS_THRU_ASYNC_REQ;\r
302\r
303#define NVME_PASS_THRU_ASYNC_REQ_FROM_THIS(a) \\r
304 CR (a, \\r
305 NVME_PASS_THRU_ASYNC_REQ, \\r
306 Link, \\r
307 NVME_PASS_THRU_ASYNC_REQ_SIG \\r
308 )\r
309\r
eb290d02
FT
310/**\r
311 Retrieves a Unicode string that is the user readable name of the driver.\r
312\r
313 This function retrieves the user readable name of a driver in the form of a\r
314 Unicode string. If the driver specified by This has a user readable name in\r
315 the language specified by Language, then a pointer to the driver name is\r
316 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
317 by This does not support the language specified by Language,\r
318 then EFI_UNSUPPORTED is returned.\r
319\r
320 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
321 EFI_COMPONENT_NAME_PROTOCOL instance.\r
322\r
323 @param Language[in] A pointer to a Null-terminated ASCII string\r
324 array indicating the language. This is the\r
325 language of the driver name that the caller is\r
326 requesting, and it must match one of the\r
327 languages specified in SupportedLanguages. The\r
328 number of languages supported by a driver is up\r
329 to the driver writer. Language is specified\r
330 in RFC 4646 or ISO 639-2 language code format.\r
331\r
332 @param DriverName[out] A pointer to the Unicode string to return.\r
333 This Unicode string is the name of the\r
334 driver specified by This in the language\r
335 specified by Language.\r
336\r
337 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
338 This and the language specified by Language was\r
339 returned in DriverName.\r
340\r
341 @retval EFI_INVALID_PARAMETER Language is NULL.\r
342\r
343 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
344\r
345 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
346 the language specified by Language.\r
347\r
348**/\r
349EFI_STATUS\r
350EFIAPI\r
351NvmExpressComponentNameGetDriverName (\r
352 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
353 IN CHAR8 *Language,\r
354 OUT CHAR16 **DriverName\r
355 );\r
356\r
357/**\r
358 Retrieves a Unicode string that is the user readable name of the controller\r
359 that is being managed by a driver.\r
360\r
361 This function retrieves the user readable name of the controller specified by\r
362 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
363 driver specified by This has a user readable name in the language specified by\r
364 Language, then a pointer to the controller name is returned in ControllerName,\r
365 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
366 managing the controller specified by ControllerHandle and ChildHandle,\r
367 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
368 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
369\r
370 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
371 EFI_COMPONENT_NAME_PROTOCOL instance.\r
372\r
373 @param ControllerHandle[in] The handle of a controller that the driver\r
374 specified by This is managing. This handle\r
375 specifies the controller whose name is to be\r
376 returned.\r
377\r
378 @param ChildHandle[in] The handle of the child controller to retrieve\r
379 the name of. This is an optional parameter that\r
380 may be NULL. It will be NULL for device\r
381 drivers. It will also be NULL for a bus drivers\r
382 that wish to retrieve the name of the bus\r
383 controller. It will not be NULL for a bus\r
384 driver that wishes to retrieve the name of a\r
385 child controller.\r
386\r
387 @param Language[in] A pointer to a Null-terminated ASCII string\r
388 array indicating the language. This is the\r
389 language of the driver name that the caller is\r
390 requesting, and it must match one of the\r
391 languages specified in SupportedLanguages. The\r
392 number of languages supported by a driver is up\r
393 to the driver writer. Language is specified in\r
394 RFC 4646 or ISO 639-2 language code format.\r
395\r
396 @param ControllerName[out] A pointer to the Unicode string to return.\r
397 This Unicode string is the name of the\r
398 controller specified by ControllerHandle and\r
399 ChildHandle in the language specified by\r
400 Language from the point of view of the driver\r
401 specified by This.\r
402\r
403 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
404 the language specified by Language for the\r
405 driver specified by This was returned in\r
406 DriverName.\r
407\r
408 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
409\r
410 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
411 EFI_HANDLE.\r
412\r
413 @retval EFI_INVALID_PARAMETER Language is NULL.\r
414\r
415 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
416\r
417 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
418 managing the controller specified by\r
419 ControllerHandle and ChildHandle.\r
420\r
421 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
422 the language specified by Language.\r
423\r
424**/\r
425EFI_STATUS\r
426EFIAPI\r
427NvmExpressComponentNameGetControllerName (\r
428 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
429 IN EFI_HANDLE ControllerHandle,\r
430 IN EFI_HANDLE ChildHandle OPTIONAL,\r
431 IN CHAR8 *Language,\r
432 OUT CHAR16 **ControllerName\r
433 );\r
434\r
435/**\r
436 Tests to see if this driver supports a given controller. If a child device is provided,\r
437 it further tests to see if this driver supports creating a handle for the specified child device.\r
438\r
439 This function checks to see if the driver specified by This supports the device specified by\r
440 ControllerHandle. Drivers will typically use the device path attached to\r
441 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
442 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
443 may be called many times during platform initialization. In order to reduce boot times, the tests\r
444 performed by this function must be very small, and take as little time as possible to execute. This\r
445 function must not change the state of any hardware devices, and this function must be aware that the\r
446 device specified by ControllerHandle may already be managed by the same driver or a\r
447 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
448 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
449 Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
450 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
451 to guarantee the state of ControllerHandle is not modified by this function.\r
452\r
453 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
454 @param[in] ControllerHandle The handle of the controller to test. This handle\r
455 must support a protocol interface that supplies\r
456 an I/O abstraction to the driver.\r
457 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
458 parameter is ignored by device drivers, and is optional for bus\r
459 drivers. For bus drivers, if this parameter is not NULL, then\r
460 the bus driver must determine if the bus controller specified\r
461 by ControllerHandle and the child controller specified\r
462 by RemainingDevicePath are both supported by this\r
463 bus driver.\r
464\r
465 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
466 RemainingDevicePath is supported by the driver specified by This.\r
467 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
468 RemainingDevicePath is already being managed by the driver\r
469 specified by This.\r
470 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
471 RemainingDevicePath is already being managed by a different\r
472 driver or an application that requires exclusive access.\r
473 Currently not implemented.\r
474 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
475 RemainingDevicePath is not supported by the driver specified by This.\r
476**/\r
477EFI_STATUS\r
478EFIAPI\r
479NvmExpressDriverBindingSupported (\r
480 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
481 IN EFI_HANDLE Controller,\r
482 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
483 );\r
484\r
485/**\r
486 Starts a device controller or a bus controller.\r
487\r
488 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
489 As a result, much of the error checking on the parameters to Start() has been moved into this\r
490 common boot service. It is legal to call Start() from other locations,\r
491 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
492 1. ControllerHandle must be a valid EFI_HANDLE.\r
493 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
494 EFI_DEVICE_PATH_PROTOCOL.\r
495 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
496 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
497\r
498 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
499 @param[in] ControllerHandle The handle of the controller to start. This handle\r
500 must support a protocol interface that supplies\r
501 an I/O abstraction to the driver.\r
502 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
503 parameter is ignored by device drivers, and is optional for bus\r
504 drivers. For a bus driver, if this parameter is NULL, then handles\r
505 for all the children of Controller are created by this driver.\r
506 If this parameter is not NULL and the first Device Path Node is\r
507 not the End of Device Path Node, then only the handle for the\r
508 child device specified by the first Device Path Node of\r
509 RemainingDevicePath is created by this driver.\r
510 If the first Device Path Node of RemainingDevicePath is\r
511 the End of Device Path Node, no child handle is created by this\r
512 driver.\r
513\r
514 @retval EFI_SUCCESS The device was started.\r
515 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
516 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
517 @retval Others The driver failded to start the device.\r
518\r
519**/\r
520EFI_STATUS\r
521EFIAPI\r
522NvmExpressDriverBindingStart (\r
523 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
524 IN EFI_HANDLE Controller,\r
525 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
526 );\r
527\r
528/**\r
529 Stops a device controller or a bus controller.\r
530\r
531 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
532 As a result, much of the error checking on the parameters to Stop() has been moved\r
533 into this common boot service. It is legal to call Stop() from other locations,\r
534 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
535 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
536 same driver's Start() function.\r
537 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
538 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
539 Start() function, and the Start() function must have called OpenProtocol() on\r
540 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
541\r
542 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
543 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
544 support a bus specific I/O protocol for the driver\r
545 to use to stop the device.\r
546 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
547 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
548 if NumberOfChildren is 0.\r
549\r
550 @retval EFI_SUCCESS The device was stopped.\r
551 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
552\r
553**/\r
554EFI_STATUS\r
555EFIAPI\r
556NvmExpressDriverBindingStop (\r
557 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
558 IN EFI_HANDLE Controller,\r
559 IN UINTN NumberOfChildren,\r
560 IN EFI_HANDLE *ChildHandleBuffer\r
561 );\r
562\r
563/**\r
564 Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports\r
565 both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the nonblocking\r
566 I/O functionality is optional.\r
567\r
d6c55989 568 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.\r
eb290d02
FT
569 @param[in] NamespaceId Is a 32 bit Namespace ID to which the Express HCI command packet will be sent.\r
570 A value of 0 denotes the NVM Express controller, a value of all 0FFh in the namespace\r
571 ID specifies that the command packet should be sent to all valid namespaces.\r
eb290d02
FT
572 @param[in,out] Packet A pointer to the NVM Express HCI Command Packet to send to the NVMe namespace specified\r
573 by NamespaceId.\r
574 @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking I/O is performed.\r
575 If Event is NULL, then blocking I/O is performed. If Event is not NULL and non blocking I/O\r
576 is supported, then nonblocking I/O is performed, and Event will be signaled when the NVM\r
577 Express Command Packet completes.\r
578\r
579 @retval EFI_SUCCESS The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred\r
580 to, or from DataBuffer.\r
581 @retval EFI_BAD_BUFFER_SIZE The NVM Express Command Packet was not executed. The number of bytes that could be transferred\r
582 is returned in TransferLength.\r
583 @retval EFI_NOT_READY The NVM Express Command Packet could not be sent because the controller is not ready. The caller\r
584 may retry again later.\r
585 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the NVM Express Command Packet.\r
d6c55989 586 @retval EFI_INVALID_PARAMETER Namespace, or the contents of EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM\r
eb290d02
FT
587 Express Command Packet was not sent, so no additional status information is available.\r
588 @retval EFI_UNSUPPORTED The command described by the NVM Express Command Packet is not supported by the host adapter.\r
589 The NVM Express Command Packet was not sent, so no additional status information is available.\r
590 @retval EFI_TIMEOUT A timeout occurred while waiting for the NVM Express Command Packet to execute.\r
591\r
592**/\r
593EFI_STATUS\r
594EFIAPI\r
595NvmExpressPassThru (\r
d6c55989 596 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,\r
eb290d02 597 IN UINT32 NamespaceId,\r
d6c55989 598 IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet,\r
eb290d02
FT
599 IN EFI_EVENT Event OPTIONAL\r
600 );\r
601\r
602/**\r
d6c55989
FT
603 Used to retrieve the next namespace ID for this NVM Express controller.\r
604\r
605 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNextNamespace() function retrieves the next valid\r
606 namespace ID on this NVM Express controller.\r
eb290d02 607\r
d6c55989
FT
608 If on input the value pointed to by NamespaceId is 0xFFFFFFFF, then the first valid namespace\r
609 ID defined on the NVM Express controller is returned in the location pointed to by NamespaceId\r
610 and a status of EFI_SUCCESS is returned.\r
eb290d02 611\r
d6c55989
FT
612 If on input the value pointed to by NamespaceId is an invalid namespace ID other than 0xFFFFFFFF,\r
613 then EFI_INVALID_PARAMETER is returned.\r
eb290d02 614\r
d6c55989
FT
615 If on input the value pointed to by NamespaceId is a valid namespace ID, then the next valid\r
616 namespace ID on the NVM Express controller is returned in the location pointed to by NamespaceId,\r
617 and EFI_SUCCESS is returned.\r
eb290d02 618\r
d6c55989
FT
619 If the value pointed to by NamespaceId is the namespace ID of the last namespace on the NVM\r
620 Express controller, then EFI_NOT_FOUND is returned.\r
eb290d02 621\r
d6c55989 622 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.\r
eb290d02
FT
623 @param[in,out] NamespaceId On input, a pointer to a legal NamespaceId for an NVM Express\r
624 namespace present on the NVM Express controller. On output, a\r
625 pointer to the next NamespaceId of an NVM Express namespace on\r
626 an NVM Express controller. An input value of 0xFFFFFFFF retrieves\r
627 the first NamespaceId for an NVM Express namespace present on an\r
628 NVM Express controller.\r
eb290d02 629\r
d6c55989 630 @retval EFI_SUCCESS The Namespace ID of the next Namespace was returned.\r
eb290d02 631 @retval EFI_NOT_FOUND There are no more namespaces defined on this controller.\r
d6c55989 632 @retval EFI_INVALID_PARAMETER NamespaceId is an invalid value other than 0xFFFFFFFF.\r
eb290d02
FT
633\r
634**/\r
635EFI_STATUS\r
636EFIAPI\r
637NvmExpressGetNextNamespace (\r
d6c55989
FT
638 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,\r
639 IN OUT UINT32 *NamespaceId\r
eb290d02
FT
640 );\r
641\r
642/**\r
d6c55989
FT
643 Used to translate a device path node to a namespace ID.\r
644\r
645 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNamespace() function determines the namespace ID associated with the\r
646 namespace described by DevicePath.\r
647\r
648 If DevicePath is a device path node type that the NVM Express Pass Thru driver supports, then the NVM Express\r
649 Pass Thru driver will attempt to translate the contents DevicePath into a namespace ID.\r
eb290d02 650\r
d6c55989 651 If this translation is successful, then that namespace ID is returned in NamespaceId, and EFI_SUCCESS is returned\r
eb290d02 652\r
d6c55989 653 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.\r
eb290d02
FT
654 @param[in] DevicePath A pointer to the device path node that describes an NVM Express namespace on\r
655 the NVM Express controller.\r
656 @param[out] NamespaceId The NVM Express namespace ID contained in the device path node.\r
eb290d02 657\r
d6c55989
FT
658 @retval EFI_SUCCESS DevicePath was successfully translated to NamespaceId.\r
659 @retval EFI_INVALID_PARAMETER If DevicePath or NamespaceId are NULL, then EFI_INVALID_PARAMETER is returned.\r
eb290d02
FT
660 @retval EFI_UNSUPPORTED If DevicePath is not a device path node type that the NVM Express Pass Thru driver\r
661 supports, then EFI_UNSUPPORTED is returned.\r
d6c55989
FT
662 @retval EFI_NOT_FOUND If DevicePath is a device path node type that the NVM Express Pass Thru driver\r
663 supports, but there is not a valid translation from DevicePath to a namespace ID,\r
664 then EFI_NOT_FOUND is returned.\r
eb290d02
FT
665**/\r
666EFI_STATUS\r
667EFIAPI\r
668NvmExpressGetNamespace (\r
d6c55989 669 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,\r
eb290d02 670 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
d6c55989 671 OUT UINT32 *NamespaceId\r
eb290d02
FT
672 );\r
673\r
674/**\r
675 Used to allocate and build a device path node for an NVM Express namespace on an NVM Express controller.\r
676\r
d6c55989 677 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.BuildDevicePath() function allocates and builds a single device\r
eb290d02
FT
678 path node for the NVM Express namespace specified by NamespaceId.\r
679\r
d6c55989 680 If the NamespaceId is not valid, then EFI_NOT_FOUND is returned.\r
eb290d02
FT
681\r
682 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.\r
683\r
684 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.\r
685\r
686 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of DevicePath are\r
687 initialized to describe the NVM Express namespace specified by NamespaceId, and EFI_SUCCESS is returned.\r
688\r
d6c55989 689 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.\r
eb290d02
FT
690 @param[in] NamespaceId The NVM Express namespace ID for which a device path node is to be\r
691 allocated and built. Caller must set the NamespaceId to zero if the\r
692 device path node will contain a valid UUID.\r
eb290d02
FT
693 @param[in,out] DevicePath A pointer to a single device path node that describes the NVM Express\r
694 namespace specified by NamespaceId. This function is responsible for\r
695 allocating the buffer DevicePath with the boot service AllocatePool().\r
696 It is the caller's responsibility to free DevicePath when the caller\r
697 is finished with DevicePath.\r
698 @retval EFI_SUCCESS The device path node that describes the NVM Express namespace specified\r
699 by NamespaceId was allocated and returned in DevicePath.\r
d6c55989 700 @retval EFI_NOT_FOUND The NamespaceId is not valid.\r
eb290d02
FT
701 @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
702 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the DevicePath node.\r
703\r
704**/\r
705EFI_STATUS\r
706EFIAPI\r
707NvmExpressBuildDevicePath (\r
d6c55989 708 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This,\r
eb290d02 709 IN UINT32 NamespaceId,\r
eb290d02
FT
710 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r
711 );\r
712\r
758ea946
HW
713/**\r
714 Dump the execution status from a given completion queue entry.\r
715\r
716 @param[in] Cq A pointer to the NVME_CQ item.\r
717\r
718**/\r
719VOID\r
720NvmeDumpStatus (\r
721 IN NVME_CQ *Cq\r
722 );\r
723\r
eb290d02 724#endif\r