]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/AhciPei: Fix device cannot be found in non-S3 path
authorHao A Wu <hao.a.wu@intel.com>
Thu, 30 May 2019 01:17:22 +0000 (09:17 +0800)
committerHao A Wu <hao.a.wu@intel.com>
Fri, 31 May 2019 07:56:41 +0000 (15:56 +0800)
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1862

Current implementation of function AhciModeInitialization() has an
incorrect assumption that the value in the CAP (offset 00h) register will
always be greater than the highest bit set for the value in the PI (offset
0Ch) register.

This will lead to an issue that hard disk devices may not be found in the
non-S3 boot path for some AHCI controller capabilities.

More specifically, variable 'PortInitializeBitMap' will have the value
from 'Private->PortBitMap', which will be 0xFFFFFFFF in non-S3 boot path.
When the CAP register is of value 0x1 and PI register with value 0x4
(meaning port 2 is available), the current logic will only enumerate port
0. And the device attached behind port 2 will not be enumerated.

To address this issue, variable 'PortInitializeBitMap' will now take the
bitwise and result between 'Private->PortBitMap' and the value read from
the PI register.

Please note that there will be no function impact for S3 path, since in
this case, the bits being set in 'Private->PortBitMap' will be a subset
of the bits being set in the PI register. Their bitwise and operation will
still be the value of 'Private->PortBitMap'.

Cc: Maggie Chu <maggie.chu@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Signed-off-by: Hao A Wu <hao.a.wu@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
MdeModulePkg/Bus/Ata/AhciPei/AhciMode.c

index 7287f8290e9edf9625dca50afb405fc43d84433e..8c491bd138656e2d62463cfd84337f405a0204cc 100644 (file)
@@ -1713,7 +1713,7 @@ AhciModeInitialization (
   MaxPortNumber = MIN (MaxPortNumber, (UINT8)(UINTN)(HighBitSet32(PortImplementBitMap) + 1));\r
   MaxPortNumber = MIN (MaxPortNumber, AhciGetNumberOfPortsFromMap (Private->PortBitMap));\r
 \r
-  PortInitializeBitMap = Private->PortBitMap;\r
+  PortInitializeBitMap = Private->PortBitMap & PortImplementBitMap;\r
   AhciRegisters        = &Private->AhciRegisters;\r
   DeviceIndex          = 0;\r
   //\r
@@ -1721,6 +1721,13 @@ AhciModeInitialization (
   //\r
   for (PortIndex = 1; PortIndex <= MaxPortNumber; PortIndex ++) {\r
     Status = AhciGetPortFromMap (PortInitializeBitMap, PortIndex, &Port);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // No more available port, just break out of the loop.\r
+      //\r
+      break;\r
+    }\r
+\r
     if ((PortImplementBitMap & (BIT0 << Port)) != 0) {\r
       //\r
       // Initialize FIS Base Address Register and Command List Base Address\r