- // 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