Current code calculates ChannelCount based on CAP(NP) value.
It only works when the ports implemented number are <= CAP(NP),
for example, platform has CAP(NP) = 5 (means 6 ports) and ports
implemented are 0, 1, 2, 3, 4 and 5.
But we have some platform that has CAP(NP) = 1 (means 2 ports) and
ports implemented are 1 and 2, and has no port 0 implemented, then
current code does not work.
This patch updates the code to calculate ChannelCount based on PI value.
Cc: Amy Chan <amy.chan@intel.com>
Cc: Hong-chihX Hsueh <hong-chihx.hsueh@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
Tested-by: Hong-chihX Hsueh <hong-chihx.hsueh@intel.com>
UINT32 Data32;\r
UINTN TotalCount;\r
UINT64 Supports;\r
UINT32 Data32;\r
UINTN TotalCount;\r
UINT64 Supports;\r
\r
DEBUG ((EFI_D_INFO, "SataControllerStart start\n"));\r
\r
\r
DEBUG ((EFI_D_INFO, "SataControllerStart start\n"));\r
\r
Private->DeviceCount = IDE_MAX_DEVICES;\r
} else if (IS_PCI_SATADPA (&PciData)) {\r
//\r
Private->DeviceCount = IDE_MAX_DEVICES;\r
} else if (IS_PCI_SATADPA (&PciData)) {\r
//\r
- // Read Host Capability Register(CAP) to get Number of Ports(NPS) and Supports Port Multiplier(SPM)\r
- // NPS is 0's based value indicating the maximum number of ports supported by the HBA silicon.\r
- // A maximum of 32 ports can be supported. A value of '0h', indicating one port, is the minimum requirement.\r
+ // Read Ports Implemented(PI) to calculate max port number (0 based).\r
+ //\r
+ Data32 = AhciReadReg (PciIo, R_AHCI_PI);\r
+ DEBUG ((DEBUG_INFO, "Ports Implemented(PI) = 0x%x\n", Data32));\r
+ if (Data32 == 0) {\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
+ }\r
+ MaxPortNumber = 31;\r
+ while (MaxPortNumber > 0) {\r
+ if (Data32 & (1 << MaxPortNumber)) {\r
+ break;\r
+ }\r
+ MaxPortNumber--;\r
+ }\r
+ //\r
+ // Make the ChannelCount equal to the max port number (0 based) plus 1.\r
+ //\r
+ Private->IdeInit.ChannelCount = MaxPortNumber + 1;\r
+\r
+ //\r
+ // Read HBA Capabilities(CAP) to get Supports Port Multiplier(SPM).\r
//\r
Data32 = AhciReadReg (PciIo, R_AHCI_CAP);\r
//\r
Data32 = AhciReadReg (PciIo, R_AHCI_CAP);\r
- Private->IdeInit.ChannelCount = (UINT8) ((Data32 & B_AHCI_CAP_NPS) + 1);\r
+ DEBUG ((DEBUG_INFO, "HBA Capabilities(CAP) = 0x%x\n", Data32));\r
Private->DeviceCount = AHCI_MAX_DEVICES;\r
if ((Data32 & B_AHCI_CAP_SPM) == B_AHCI_CAP_SPM) {\r
Private->DeviceCount = AHCI_MULTI_MAX_DEVICES;\r
Private->DeviceCount = AHCI_MAX_DEVICES;\r
if ((Data32 & B_AHCI_CAP_SPM) == B_AHCI_CAP_SPM) {\r
Private->DeviceCount = AHCI_MULTI_MAX_DEVICES;\r
#define R_AHCI_CAP 0x0\r
#define B_AHCI_CAP_NPS (BIT4 | BIT3 | BIT2 | BIT1 | BIT0) // Number of Ports\r
#define B_AHCI_CAP_SPM BIT17 // Supports Port Multiplier\r
#define R_AHCI_CAP 0x0\r
#define B_AHCI_CAP_NPS (BIT4 | BIT3 | BIT2 | BIT1 | BIT0) // Number of Ports\r
#define B_AHCI_CAP_SPM BIT17 // Supports Port Multiplier\r
\r
///\r
/// AHCI each channel can have up to 1 device\r
\r
///\r
/// AHCI each channel can have up to 1 device\r