2 NvmExpressDxe driver is used to manage non-volatile memory subsystem which follows
3 NVM Express specification.
5 (C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
6 Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "NvmExpress.h"
20 Dump the execution status from a given completion queue entry.
22 @param[in] Cq A pointer to the NVME_CQ item.
30 DEBUG ((EFI_D_VERBOSE
, "Dump NVMe Completion Entry Status from [0x%x]:\n", Cq
));
32 DEBUG ((EFI_D_VERBOSE
, " SQ Identifier : [0x%x], Phase Tag : [%d], Cmd Identifier : [0x%x]\n", Cq
->Sqid
, Cq
->Pt
, Cq
->Cid
));
34 DEBUG ((EFI_D_VERBOSE
, " NVMe Cmd Execution Result - "));
40 DEBUG ((EFI_D_VERBOSE
, "Successful Completion\n"));
43 DEBUG ((EFI_D_VERBOSE
, "Invalid Command Opcode\n"));
46 DEBUG ((EFI_D_VERBOSE
, "Invalid Field in Command\n"));
49 DEBUG ((EFI_D_VERBOSE
, "Command ID Conflict\n"));
52 DEBUG ((EFI_D_VERBOSE
, "Data Transfer Error\n"));
55 DEBUG ((EFI_D_VERBOSE
, "Commands Aborted due to Power Loss Notification\n"));
58 DEBUG ((EFI_D_VERBOSE
, "Internal Device Error\n"));
61 DEBUG ((EFI_D_VERBOSE
, "Command Abort Requested\n"));
64 DEBUG ((EFI_D_VERBOSE
, "Command Aborted due to SQ Deletion\n"));
67 DEBUG ((EFI_D_VERBOSE
, "Command Aborted due to Failed Fused Command\n"));
70 DEBUG ((EFI_D_VERBOSE
, "Command Aborted due to Missing Fused Command\n"));
73 DEBUG ((EFI_D_VERBOSE
, "Invalid Namespace or Format\n"));
76 DEBUG ((EFI_D_VERBOSE
, "Command Sequence Error\n"));
79 DEBUG ((EFI_D_VERBOSE
, "Invalid SGL Last Segment Descriptor\n"));
82 DEBUG ((EFI_D_VERBOSE
, "Invalid Number of SGL Descriptors\n"));
85 DEBUG ((EFI_D_VERBOSE
, "Data SGL Length Invalid\n"));
88 DEBUG ((EFI_D_VERBOSE
, "Metadata SGL Length Invalid\n"));
91 DEBUG ((EFI_D_VERBOSE
, "SGL Descriptor Type Invalid\n"));
94 DEBUG ((EFI_D_VERBOSE
, "LBA Out of Range\n"));
97 DEBUG ((EFI_D_VERBOSE
, "Capacity Exceeded\n"));
100 DEBUG ((EFI_D_VERBOSE
, "Namespace Not Ready\n"));
103 DEBUG ((EFI_D_VERBOSE
, "Reservation Conflict\n"));
111 DEBUG ((EFI_D_VERBOSE
, "Completion Queue Invalid\n"));
114 DEBUG ((EFI_D_VERBOSE
, "Invalid Queue Identifier\n"));
117 DEBUG ((EFI_D_VERBOSE
, "Maximum Queue Size Exceeded\n"));
120 DEBUG ((EFI_D_VERBOSE
, "Abort Command Limit Exceeded\n"));
123 DEBUG ((EFI_D_VERBOSE
, "Asynchronous Event Request Limit Exceeded\n"));
126 DEBUG ((EFI_D_VERBOSE
, "Invalid Firmware Slot\n"));
129 DEBUG ((EFI_D_VERBOSE
, "Invalid Firmware Image\n"));
132 DEBUG ((EFI_D_VERBOSE
, "Invalid Interrupt Vector\n"));
135 DEBUG ((EFI_D_VERBOSE
, "Invalid Log Page\n"));
138 DEBUG ((EFI_D_VERBOSE
, "Invalid Format\n"));
141 DEBUG ((EFI_D_VERBOSE
, "Firmware Application Requires Conventional Reset\n"));
144 DEBUG ((EFI_D_VERBOSE
, "Invalid Queue Deletion\n"));
147 DEBUG ((EFI_D_VERBOSE
, "Feature Identifier Not Saveable\n"));
150 DEBUG ((EFI_D_VERBOSE
, "Feature Not Changeable\n"));
153 DEBUG ((EFI_D_VERBOSE
, "Feature Not Namespace Specific\n"));
156 DEBUG ((EFI_D_VERBOSE
, "Firmware Application Requires NVM Subsystem Reset\n"));
159 DEBUG ((EFI_D_VERBOSE
, "Conflicting Attributes\n"));
162 DEBUG ((EFI_D_VERBOSE
, "Invalid Protection Information\n"));
165 DEBUG ((EFI_D_VERBOSE
, "Attempted Write to Read Only Range\n"));
173 DEBUG ((EFI_D_VERBOSE
, "Write Fault\n"));
176 DEBUG ((EFI_D_VERBOSE
, "Unrecovered Read Error\n"));
179 DEBUG ((EFI_D_VERBOSE
, "End-to-end Guard Check Error\n"));
182 DEBUG ((EFI_D_VERBOSE
, "End-to-end Application Tag Check Error\n"));
185 DEBUG ((EFI_D_VERBOSE
, "End-to-end Reference Tag Check Error\n"));
188 DEBUG ((EFI_D_VERBOSE
, "Compare Failure\n"));
191 DEBUG ((EFI_D_VERBOSE
, "Access Denied\n"));
202 Create PRP lists for data transfer which is larger than 2 memory pages.
203 Note here we calcuate the number of required PRP lists and allocate them at one time.
205 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
206 @param[in] PhysicalAddr The physical base address of data buffer.
207 @param[in] Pages The number of pages to be transfered.
208 @param[out] PrpListHost The host base address of PRP lists.
209 @param[in,out] PrpListNo The number of PRP List.
210 @param[out] Mapping The mapping value returned from PciIo.Map().
212 @retval The pointer to the first PRP List of the PRP lists.
217 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
218 IN EFI_PHYSICAL_ADDRESS PhysicalAddr
,
220 OUT VOID
**PrpListHost
,
221 IN OUT UINTN
*PrpListNo
,
230 EFI_PHYSICAL_ADDRESS PrpListPhyAddr
;
235 // The number of Prp Entry in a memory page.
237 PrpEntryNo
= EFI_PAGE_SIZE
/ sizeof (UINT64
);
240 // Calculate total PrpList number.
242 *PrpListNo
= (UINTN
)DivU64x64Remainder ((UINT64
)Pages
, (UINT64
)PrpEntryNo
- 1, &Remainder
);
243 if (*PrpListNo
== 0) {
245 } else if ((Remainder
!= 0) && (Remainder
!= 1)) {
247 } else if (Remainder
== 1) {
248 Remainder
= PrpEntryNo
;
249 } else if (Remainder
== 0) {
250 Remainder
= PrpEntryNo
- 1;
253 Status
= PciIo
->AllocateBuffer (
262 if (EFI_ERROR (Status
)) {
266 Bytes
= EFI_PAGES_TO_SIZE (*PrpListNo
);
267 Status
= PciIo
->Map (
269 EfiPciIoOperationBusMasterCommonBuffer
,
276 if (EFI_ERROR (Status
) || (Bytes
!= EFI_PAGES_TO_SIZE (*PrpListNo
))) {
277 DEBUG ((EFI_D_ERROR
, "NvmeCreatePrpList: create PrpList failure!\n"));
281 // Fill all PRP lists except of last one.
283 ZeroMem (*PrpListHost
, Bytes
);
284 for (PrpListIndex
= 0; PrpListIndex
< *PrpListNo
- 1; ++PrpListIndex
) {
285 PrpListBase
= *(UINT64
*)PrpListHost
+ PrpListIndex
* EFI_PAGE_SIZE
;
287 for (PrpEntryIndex
= 0; PrpEntryIndex
< PrpEntryNo
; ++PrpEntryIndex
) {
288 if (PrpEntryIndex
!= PrpEntryNo
- 1) {
290 // Fill all PRP entries except of last one.
292 *((UINT64
*)(UINTN
)PrpListBase
+ PrpEntryIndex
) = PhysicalAddr
;
293 PhysicalAddr
+= EFI_PAGE_SIZE
;
296 // Fill last PRP entries with next PRP List pointer.
298 *((UINT64
*)(UINTN
)PrpListBase
+ PrpEntryIndex
) = PrpListPhyAddr
+ (PrpListIndex
+ 1) * EFI_PAGE_SIZE
;
303 // Fill last PRP list.
305 PrpListBase
= *(UINT64
*)PrpListHost
+ PrpListIndex
* EFI_PAGE_SIZE
;
306 for (PrpEntryIndex
= 0; PrpEntryIndex
< Remainder
; ++PrpEntryIndex
) {
307 *((UINT64
*)(UINTN
)PrpListBase
+ PrpEntryIndex
) = PhysicalAddr
;
308 PhysicalAddr
+= EFI_PAGE_SIZE
;
311 return (VOID
*)(UINTN
)PrpListPhyAddr
;
314 PciIo
->FreeBuffer (PciIo
, *PrpListNo
, *PrpListHost
);
320 Sends an NVM Express Command Packet to an NVM Express controller or namespace. This function supports
321 both blocking I/O and non-blocking I/O. The blocking I/O functionality is required, and the non-blocking
322 I/O functionality is optional.
325 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
326 @param[in] NamespaceId A 32 bit namespace ID as defined in the NVMe specification to which the NVM Express Command
327 Packet will be sent. A value of 0 denotes the NVM Express controller, a value of all 0xFF's
328 (all bytes are 0xFF) in the namespace ID specifies that the command packet should be sent to
329 all valid namespaces.
330 @param[in,out] Packet A pointer to the NVM Express Command Packet.
331 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking I/O is performed.
332 If Event is NULL, then blocking I/O is performed. If Event is not NULL and non-blocking I/O
333 is supported, then non-blocking I/O is performed, and Event will be signaled when the NVM
334 Express Command Packet completes.
336 @retval EFI_SUCCESS The NVM Express Command Packet was sent by the host. TransferLength bytes were transferred
337 to, or from DataBuffer.
338 @retval EFI_BAD_BUFFER_SIZE The NVM Express Command Packet was not executed. The number of bytes that could be transferred
339 is returned in TransferLength.
340 @retval EFI_NOT_READY The NVM Express Command Packet could not be sent because the controller is not ready. The caller
341 may retry again later.
342 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the NVM Express Command Packet.
343 @retval EFI_INVALID_PARAMETER NamespaceId or the contents of EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET are invalid. The NVM
344 Express Command Packet was not sent, so no additional status information is available.
345 @retval EFI_UNSUPPORTED The command described by the NVM Express Command Packet is not supported by the NVM Express
346 controller. The NVM Express Command Packet was not sent so no additional status information
348 @retval EFI_TIMEOUT A timeout occurred while waiting for the NVM Express Command Packet to execute.
354 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL
*This
,
355 IN UINT32 NamespaceId
,
356 IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET
*Packet
,
357 IN EFI_EVENT Event OPTIONAL
360 NVME_CONTROLLER_PRIVATE_DATA
*Private
;
362 EFI_PCI_IO_PROTOCOL
*PciIo
;
368 EFI_EVENT TimerEvent
;
369 EFI_PCI_IO_PROTOCOL_OPERATION Flag
;
370 EFI_PHYSICAL_ADDRESS PhyAddr
;
381 // check the data fields in Packet parameter.
383 if ((This
== NULL
) || (Packet
== NULL
)) {
384 return EFI_INVALID_PARAMETER
;
387 if ((Packet
->NvmeCmd
== NULL
) || (Packet
->NvmeCompletion
== NULL
)) {
388 return EFI_INVALID_PARAMETER
;
391 if (Packet
->QueueType
!= NVME_ADMIN_QUEUE
&& Packet
->QueueType
!= NVME_IO_QUEUE
) {
392 return EFI_INVALID_PARAMETER
;
395 Private
= NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (This
);
396 PciIo
= Private
->PciIo
;
404 Status
= EFI_SUCCESS
;
406 QueueType
= Packet
->QueueType
;
407 Sq
= Private
->SqBuffer
[QueueType
] + Private
->SqTdbl
[QueueType
].Sqt
;
408 Cq
= Private
->CqBuffer
[QueueType
] + Private
->CqHdbl
[QueueType
].Cqh
;
410 if (Packet
->NvmeCmd
->Nsid
!= NamespaceId
) {
411 return EFI_INVALID_PARAMETER
;
414 ZeroMem (Sq
, sizeof (NVME_SQ
));
415 Sq
->Opc
= (UINT8
)Packet
->NvmeCmd
->Cdw0
.Opcode
;
416 Sq
->Fuse
= (UINT8
)Packet
->NvmeCmd
->Cdw0
.FusedOperation
;
417 Sq
->Cid
= Private
->Cid
[QueueType
]++;
418 Sq
->Nsid
= Packet
->NvmeCmd
->Nsid
;
421 // Currently we only support PRP for data transfer, SGL is NOT supported.
423 ASSERT (Sq
->Psdt
== 0);
425 DEBUG ((EFI_D_ERROR
, "NvmExpressPassThru: doesn't support SGL mechanism\n"));
426 return EFI_UNSUPPORTED
;
429 Sq
->Prp
[0] = (UINT64
)(UINTN
)Packet
->TransferBuffer
;
431 // If the NVMe cmd has data in or out, then mapping the user buffer to the PCI controller specific addresses.
432 // Note here we don't handle data buffer for CreateIOSubmitionQueue and CreateIOCompletionQueue cmds because
433 // these two cmds are special which requires their data buffer must support simultaneous access by both the
434 // processor and a PCI Bus Master. It's caller's responsbility to ensure this.
436 if (((Sq
->Opc
& (BIT0
| BIT1
)) != 0) && (Sq
->Opc
!= NVME_ADMIN_CRIOCQ_OPC
) && (Sq
->Opc
!= NVME_ADMIN_CRIOSQ_OPC
)) {
437 if ((Sq
->Opc
& BIT0
) != 0) {
438 Flag
= EfiPciIoOperationBusMasterRead
;
440 Flag
= EfiPciIoOperationBusMasterWrite
;
443 MapLength
= Packet
->TransferLength
;
444 Status
= PciIo
->Map (
447 Packet
->TransferBuffer
,
452 if (EFI_ERROR (Status
) || (Packet
->TransferLength
!= MapLength
)) {
453 return EFI_OUT_OF_RESOURCES
;
456 Sq
->Prp
[0] = PhyAddr
;
459 MapLength
= Packet
->MetadataLength
;
460 if(Packet
->MetadataBuffer
!= NULL
) {
461 MapLength
= Packet
->MetadataLength
;
462 Status
= PciIo
->Map (
465 Packet
->MetadataBuffer
,
470 if (EFI_ERROR (Status
) || (Packet
->MetadataLength
!= MapLength
)) {
476 return EFI_OUT_OF_RESOURCES
;
482 // If the buffer size spans more than two memory pages (page size as defined in CC.Mps),
483 // then build a PRP list in the second PRP submission queue entry.
485 Offset
= ((UINT16
)Sq
->Prp
[0]) & (EFI_PAGE_SIZE
- 1);
486 Bytes
= Packet
->TransferLength
;
488 if ((Offset
+ Bytes
) > (EFI_PAGE_SIZE
* 2)) {
490 // Create PrpList for remaining data buffer.
492 PhyAddr
= (Sq
->Prp
[0] + EFI_PAGE_SIZE
) & ~(EFI_PAGE_SIZE
- 1);
493 Prp
= NvmeCreatePrpList (PciIo
, PhyAddr
, EFI_SIZE_TO_PAGES(Offset
+ Bytes
) - 1, &PrpListHost
, &PrpListNo
, &MapPrpList
);
498 Sq
->Prp
[1] = (UINT64
)(UINTN
)Prp
;
499 } else if ((Offset
+ Bytes
) > EFI_PAGE_SIZE
) {
500 Sq
->Prp
[1] = (Sq
->Prp
[0] + EFI_PAGE_SIZE
) & ~(EFI_PAGE_SIZE
- 1);
503 if(Packet
->NvmeCmd
->Flags
& CDW2_VALID
) {
504 Sq
->Rsvd2
= (UINT64
)Packet
->NvmeCmd
->Cdw2
;
506 if(Packet
->NvmeCmd
->Flags
& CDW3_VALID
) {
507 Sq
->Rsvd2
|= LShiftU64 ((UINT64
)Packet
->NvmeCmd
->Cdw3
, 32);
509 if(Packet
->NvmeCmd
->Flags
& CDW10_VALID
) {
510 Sq
->Payload
.Raw
.Cdw10
= Packet
->NvmeCmd
->Cdw10
;
512 if(Packet
->NvmeCmd
->Flags
& CDW11_VALID
) {
513 Sq
->Payload
.Raw
.Cdw11
= Packet
->NvmeCmd
->Cdw11
;
515 if(Packet
->NvmeCmd
->Flags
& CDW12_VALID
) {
516 Sq
->Payload
.Raw
.Cdw12
= Packet
->NvmeCmd
->Cdw12
;
518 if(Packet
->NvmeCmd
->Flags
& CDW13_VALID
) {
519 Sq
->Payload
.Raw
.Cdw13
= Packet
->NvmeCmd
->Cdw13
;
521 if(Packet
->NvmeCmd
->Flags
& CDW14_VALID
) {
522 Sq
->Payload
.Raw
.Cdw14
= Packet
->NvmeCmd
->Cdw14
;
524 if(Packet
->NvmeCmd
->Flags
& CDW15_VALID
) {
525 Sq
->Payload
.Raw
.Cdw15
= Packet
->NvmeCmd
->Cdw15
;
529 // Ring the submission queue doorbell.
531 Private
->SqTdbl
[QueueType
].Sqt
^= 1;
532 Data
= ReadUnaligned32 ((UINT32
*)&Private
->SqTdbl
[QueueType
]);
537 NVME_SQTDBL_OFFSET(QueueType
, Private
->Cap
.Dstrd
),
542 Status
= gBS
->CreateEvent (
549 if (EFI_ERROR (Status
)) {
553 Status
= gBS
->SetTimer(TimerEvent
, TimerRelative
, Packet
->CommandTimeout
);
555 if (EFI_ERROR(Status
)) {
560 // Wait for completion queue to get filled in.
562 Status
= EFI_TIMEOUT
;
563 while (EFI_ERROR (gBS
->CheckEvent (TimerEvent
))) {
564 if (Cq
->Pt
!= Private
->Pt
[QueueType
]) {
565 Status
= EFI_SUCCESS
;
570 if ((Private
->CqHdbl
[QueueType
].Cqh
^= 1) == 0) {
571 Private
->Pt
[QueueType
] ^= 1;
575 // Copy the Respose Queue entry for this command to the callers response buffer
577 CopyMem(Packet
->NvmeCompletion
, Cq
, sizeof(EFI_NVM_EXPRESS_COMPLETION
));
580 // Dump every completion entry status for debugging.
586 Data
= ReadUnaligned32 ((UINT32
*)&Private
->CqHdbl
[QueueType
]);
591 NVME_CQHDBL_OFFSET(QueueType
, Private
->Cap
.Dstrd
),
597 if (MapData
!= NULL
) {
604 if (MapMeta
!= NULL
) {
611 if (MapPrpList
!= NULL
) {
619 PciIo
->FreeBuffer (PciIo
, PrpListNo
, PrpListHost
);
622 if (TimerEvent
!= NULL
) {
623 gBS
->CloseEvent (TimerEvent
);
629 Used to retrieve the next namespace ID for this NVM Express controller.
631 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNextNamespace() function retrieves the next valid
632 namespace ID on this NVM Express controller.
634 If on input the value pointed to by NamespaceId is 0xFFFFFFFF, then the first valid namespace
635 ID defined on the NVM Express controller is returned in the location pointed to by NamespaceId
636 and a status of EFI_SUCCESS is returned.
638 If on input the value pointed to by NamespaceId is an invalid namespace ID other than 0xFFFFFFFF,
639 then EFI_INVALID_PARAMETER is returned.
641 If on input the value pointed to by NamespaceId is a valid namespace ID, then the next valid
642 namespace ID on the NVM Express controller is returned in the location pointed to by NamespaceId,
643 and EFI_SUCCESS is returned.
645 If the value pointed to by NamespaceId is the namespace ID of the last namespace on the NVM
646 Express controller, then EFI_NOT_FOUND is returned.
648 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
649 @param[in,out] NamespaceId On input, a pointer to a legal NamespaceId for an NVM Express
650 namespace present on the NVM Express controller. On output, a
651 pointer to the next NamespaceId of an NVM Express namespace on
652 an NVM Express controller. An input value of 0xFFFFFFFF retrieves
653 the first NamespaceId for an NVM Express namespace present on an
654 NVM Express controller.
656 @retval EFI_SUCCESS The Namespace ID of the next Namespace was returned.
657 @retval EFI_NOT_FOUND There are no more namespaces defined on this controller.
658 @retval EFI_INVALID_PARAMETER NamespaceId is an invalid value other than 0xFFFFFFFF.
663 NvmExpressGetNextNamespace (
664 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL
*This
,
665 IN OUT UINT32
*NamespaceId
668 NVME_CONTROLLER_PRIVATE_DATA
*Private
;
669 NVME_ADMIN_NAMESPACE_DATA
*NamespaceData
;
670 UINT32 NextNamespaceId
;
673 if ((This
== NULL
) || (NamespaceId
== NULL
)) {
674 return EFI_INVALID_PARAMETER
;
677 NamespaceData
= NULL
;
678 Status
= EFI_NOT_FOUND
;
680 Private
= NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (This
);
682 // If the NamespaceId input value is 0xFFFFFFFF, then get the first valid namespace ID
684 if (*NamespaceId
== 0xFFFFFFFF) {
686 // Start with the first namespace ID
690 // Allocate buffer for Identify Namespace data.
692 NamespaceData
= (NVME_ADMIN_NAMESPACE_DATA
*)AllocateZeroPool (sizeof (NVME_ADMIN_NAMESPACE_DATA
));
694 if (NamespaceData
== NULL
) {
695 return EFI_NOT_FOUND
;
698 Status
= NvmeIdentifyNamespace (Private
, NextNamespaceId
, NamespaceData
);
699 if (EFI_ERROR(Status
)) {
703 *NamespaceId
= NextNamespaceId
;
705 if (*NamespaceId
>= Private
->ControllerData
->Nn
) {
706 return EFI_INVALID_PARAMETER
;
709 NextNamespaceId
= *NamespaceId
+ 1;
711 // Allocate buffer for Identify Namespace data.
713 NamespaceData
= (NVME_ADMIN_NAMESPACE_DATA
*)AllocateZeroPool (sizeof (NVME_ADMIN_NAMESPACE_DATA
));
714 if (NamespaceData
== NULL
) {
715 return EFI_NOT_FOUND
;
718 Status
= NvmeIdentifyNamespace (Private
, NextNamespaceId
, NamespaceData
);
719 if (EFI_ERROR(Status
)) {
723 *NamespaceId
= NextNamespaceId
;
727 if (NamespaceData
!= NULL
) {
728 FreePool(NamespaceData
);
735 Used to translate a device path node to a namespace ID.
737 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.GetNamespace() function determines the namespace ID associated with the
738 namespace described by DevicePath.
740 If DevicePath is a device path node type that the NVM Express Pass Thru driver supports, then the NVM Express
741 Pass Thru driver will attempt to translate the contents DevicePath into a namespace ID.
743 If this translation is successful, then that namespace ID is returned in NamespaceId, and EFI_SUCCESS is returned
745 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
746 @param[in] DevicePath A pointer to the device path node that describes an NVM Express namespace on
747 the NVM Express controller.
748 @param[out] NamespaceId The NVM Express namespace ID contained in the device path node.
750 @retval EFI_SUCCESS DevicePath was successfully translated to NamespaceId.
751 @retval EFI_INVALID_PARAMETER If DevicePath or NamespaceId are NULL, then EFI_INVALID_PARAMETER is returned.
752 @retval EFI_UNSUPPORTED If DevicePath is not a device path node type that the NVM Express Pass Thru driver
753 supports, then EFI_UNSUPPORTED is returned.
754 @retval EFI_NOT_FOUND If DevicePath is a device path node type that the NVM Express Pass Thru driver
755 supports, but there is not a valid translation from DevicePath to a namespace ID,
756 then EFI_NOT_FOUND is returned.
760 NvmExpressGetNamespace (
761 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL
*This
,
762 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
763 OUT UINT32
*NamespaceId
766 NVME_NAMESPACE_DEVICE_PATH
*Node
;
768 if ((This
== NULL
) || (DevicePath
== NULL
) || (NamespaceId
== NULL
)) {
769 return EFI_INVALID_PARAMETER
;
772 if (DevicePath
->Type
!= MESSAGING_DEVICE_PATH
) {
773 return EFI_UNSUPPORTED
;
776 Node
= (NVME_NAMESPACE_DEVICE_PATH
*)DevicePath
;
778 if (DevicePath
->SubType
== MSG_NVME_NAMESPACE_DP
) {
779 if (DevicePathNodeLength(DevicePath
) != sizeof(NVME_NAMESPACE_DEVICE_PATH
)) {
780 return EFI_NOT_FOUND
;
783 *NamespaceId
= Node
->NamespaceId
;
787 return EFI_UNSUPPORTED
;
792 Used to allocate and build a device path node for an NVM Express namespace on an NVM Express controller.
794 The EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL.BuildDevicePath() function allocates and builds a single device
795 path node for the NVM Express namespace specified by NamespaceId.
797 If the NamespaceId is not valid, then EFI_NOT_FOUND is returned.
799 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned.
801 If there are not enough resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
803 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of DevicePath are
804 initialized to describe the NVM Express namespace specified by NamespaceId, and EFI_SUCCESS is returned.
806 @param[in] This A pointer to the EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL instance.
807 @param[in] NamespaceId The NVM Express namespace ID for which a device path node is to be
808 allocated and built. Caller must set the NamespaceId to zero if the
809 device path node will contain a valid UUID.
810 @param[in,out] DevicePath A pointer to a single device path node that describes the NVM Express
811 namespace specified by NamespaceId. This function is responsible for
812 allocating the buffer DevicePath with the boot service AllocatePool().
813 It is the caller's responsibility to free DevicePath when the caller
814 is finished with DevicePath.
815 @retval EFI_SUCCESS The device path node that describes the NVM Express namespace specified
816 by NamespaceId was allocated and returned in DevicePath.
817 @retval EFI_NOT_FOUND The NamespaceId is not valid.
818 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
819 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate the DevicePath node.
824 NvmExpressBuildDevicePath (
825 IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL
*This
,
826 IN UINT32 NamespaceId
,
827 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
830 NVME_NAMESPACE_DEVICE_PATH
*Node
;
831 NVME_CONTROLLER_PRIVATE_DATA
*Private
;
833 NVME_ADMIN_NAMESPACE_DATA
*NamespaceData
;
836 // Validate parameters
838 if ((This
== NULL
) || (DevicePath
== NULL
)) {
839 return EFI_INVALID_PARAMETER
;
842 if (NamespaceId
== 0) {
843 return EFI_NOT_FOUND
;
846 Status
= EFI_SUCCESS
;
847 Private
= NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (This
);
849 Node
= (NVME_NAMESPACE_DEVICE_PATH
*)AllocateZeroPool (sizeof (NVME_NAMESPACE_DEVICE_PATH
));
851 return EFI_OUT_OF_RESOURCES
;
854 Node
->Header
.Type
= MESSAGING_DEVICE_PATH
;
855 Node
->Header
.SubType
= MSG_NVME_NAMESPACE_DP
;
856 SetDevicePathNodeLength (&Node
->Header
, sizeof (NVME_NAMESPACE_DEVICE_PATH
));
857 Node
->NamespaceId
= NamespaceId
;
860 // Allocate a buffer for Identify Namespace data.
862 NamespaceData
= NULL
;
863 NamespaceData
= AllocateZeroPool(sizeof (NVME_ADMIN_NAMESPACE_DATA
));
864 if(NamespaceData
== NULL
) {
865 Status
= EFI_OUT_OF_RESOURCES
;
870 // Get UUID from specified Identify Namespace data.
872 Status
= NvmeIdentifyNamespace (
875 (VOID
*)NamespaceData
878 if (EFI_ERROR(Status
)) {
882 Node
->NamespaceUuid
= NamespaceData
->Eui64
;
884 *DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*)Node
;
887 if(NamespaceData
!= NULL
) {
888 FreePool (NamespaceData
);
891 if (EFI_ERROR (Status
)) {