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