MdeModulePkg NvmExpressDxe: Add check on the attributes of NVME controller

According to UEFI spec, an EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL with neither
EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL nor
EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL set in the Attributes field
is an illegal configuration.

This commit adds this check in the PassThru API to follow the spec.

Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
index 6b29260..c7ead21 100644
--- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
+++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
@@ -375,6 +375,7 @@
   UINT64                         *Prp;

   VOID                           *PrpListHost;

   UINTN                          PrpListNo;

+  UINT32                         Attributes;

   UINT32                         IoAlign;

   UINT32                         Data;

   NVME_PASS_THRU_ASYNC_REQ       *AsyncRequest;

@@ -396,9 +397,20 @@
   }

 

   //

+  // 'Attributes' with neither EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL nor

+  // EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL set is an illegal

+  // configuration.

+  //

+  Attributes  = This->Mode->Attributes;

+  if ((Attributes & (EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_PHYSICAL |

+    EFI_NVM_EXPRESS_PASS_THRU_ATTRIBUTES_LOGICAL)) == 0) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  //

   // Buffer alignment check for TransferBuffer & MetadataBuffer.

   //

-  IoAlign = This->Mode->IoAlign;

+  IoAlign     = This->Mode->IoAlign;

   if (IoAlign > 0 && (((UINTN) Packet->TransferBuffer & (IoAlign - 1)) != 0)) {

     return EFI_INVALID_PARAMETER;

   }