ahci: add port count vs. ports implemented check

Check if controllers port count matches number of ports found in the
port implemented register. In case counts don't match print a diagnostic
message for debugging purposes.

issue #4081
This commit is contained in:
Sebastian Sumpf 2024-02-06 19:23:29 +01:00 committed by Christian Helmuth
parent 4a1a162c09
commit f86cd6899c
2 changed files with 17 additions and 3 deletions

View File

@ -166,6 +166,10 @@ struct Ahci::Hba : private Platform::Device::Mmio<0x28>
return read<Hba::Pi>() & (1u << port); return read<Hba::Pi>() & (1u << port);
} }
/* for diagnostics */
unsigned pi_value() const { return read<Hba::Pi>(); }
unsigned cap_np_value() const { return read<Cap::Np>(); }
template <typename FN> template <typename FN>
void handle_irq(FN const & fn) void handle_irq(FN const & fn)
{ {

View File

@ -72,9 +72,11 @@ class Ahci::Driver : Noncopyable
bool _enable_atapi; bool _enable_atapi;
void _scan_ports(Region_map &rm) unsigned _scan_ports(Region_map &rm)
{ {
log("number of ports: ", _hba.port_count()); log("port scan:");
unsigned port_count = 0;
for (unsigned index = 0; index < MAX_PORTS; index++) { for (unsigned index = 0; index < MAX_PORTS; index++) {
@ -106,7 +108,11 @@ class Ahci::Driver : Noncopyable
log("\t\t#", index, ":", port.atapi() ? " off (ATAPI)" log("\t\t#", index, ":", port.atapi() ? " off (ATAPI)"
: " off (unknown device signature)"); : " off (unknown device signature)");
} }
port_count++;
} }
return port_count;
} }
public: public:
@ -115,7 +121,11 @@ class Ahci::Driver : Noncopyable
: _env(env), _dispatch(dispatch), _enable_atapi(support_atapi) : _env(env), _dispatch(dispatch), _enable_atapi(support_atapi)
{ {
/* search for devices */ /* search for devices */
_scan_ports(env.rm()); unsigned port_count = _scan_ports(env.rm());
if (port_count != _hba.port_count())
log("controller port count differs from detected ports (CAP.NP=",
Hex(_hba.cap_np_value()), ",PI=", Hex(_hba.pi_value()), ")");
} }
/** /**