UINT32 Data32;\r
UINTN TotalCount;\r
UINT64 Supports;\r
+ UINT8 MaxPortNumber;\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
- // 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
- 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