From f86cd6899cd3512e014b67789ad8b4e85430855c Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Tue, 6 Feb 2024 19:23:29 +0100 Subject: [PATCH] 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 --- repos/os/src/drivers/ahci/ahci.h | 4 ++++ repos/os/src/drivers/ahci/main.cc | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/repos/os/src/drivers/ahci/ahci.h b/repos/os/src/drivers/ahci/ahci.h index 83cf4d5155..e24e63e950 100644 --- a/repos/os/src/drivers/ahci/ahci.h +++ b/repos/os/src/drivers/ahci/ahci.h @@ -166,6 +166,10 @@ struct Ahci::Hba : private Platform::Device::Mmio<0x28> return read() & (1u << port); } + /* for diagnostics */ + unsigned pi_value() const { return read(); } + unsigned cap_np_value() const { return read(); } + template void handle_irq(FN const & fn) { diff --git a/repos/os/src/drivers/ahci/main.cc b/repos/os/src/drivers/ahci/main.cc index eb6d6f6749..b9bb1066ef 100644 --- a/repos/os/src/drivers/ahci/main.cc +++ b/repos/os/src/drivers/ahci/main.cc @@ -72,9 +72,11 @@ class Ahci::Driver : Noncopyable 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++) { @@ -106,7 +108,11 @@ class Ahci::Driver : Noncopyable log("\t\t#", index, ":", port.atapi() ? " off (ATAPI)" : " off (unknown device signature)"); } + + port_count++; } + + return port_count; } public: @@ -115,7 +121,11 @@ class Ahci::Driver : Noncopyable : _env(env), _dispatch(dispatch), _enable_atapi(support_atapi) { /* 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()), ")"); } /**