summaryrefslogtreecommitdiff
path: root/src/sys/io
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-21 14:12:27 -0400
committerIan Moffett <ian@osmora.org>2025-09-21 14:12:27 -0400
commit561ad1494cad32243fa256af8acb755466ef12a7 (patch)
tree3eaac3a5d0fcaf0080760cada788cbcb9955dff9 /src/sys/io
parent384ec033b8fbf26db2b390218541e9bd2a2e4cf6 (diff)
kern: ahci: Scan for implemented ports with PI reg
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys/io')
-rw-r--r--src/sys/io/ic/ahci.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/sys/io/ic/ahci.c b/src/sys/io/ic/ahci.c
index 825306d..9f96a00 100644
--- a/src/sys/io/ic/ahci.c
+++ b/src/sys/io/ic/ahci.c
@@ -144,6 +144,27 @@ ahci_hba_reset(struct ahci_hba *hba)
}
/*
+ * Initialize the ports of an HBA
+ */
+static int
+ahci_init_ports(struct ahci_hba *hba)
+{
+ volatile struct hba_memspace *io = hba->io;
+ uint32_t pi, nbits;
+
+ pi = hba->pi;
+ for (int i = 0; i < hba->nport; ++i) {
+ if (!ISSET(pi, BIT(i))) {
+ continue;
+ }
+
+ dtrace("port %d implemented\n", i);
+ }
+
+ return 0;
+}
+
+/*
* Put the HBA as well as its devices in an initialized
* state so that they may be used for operation.
*/
@@ -151,9 +172,14 @@ static int
ahci_hba_init(struct ahci_hba *hba)
{
volatile struct hba_memspace *io = hba->io;
- uint32_t ghc;
+ uint32_t ghc, cap;
int error;
+ /* Yoink from firmware before reset */
+ cap = mmio_read32(&io->cap);
+ hba->pi = mmio_read32(&io->pi);
+ hba->nport = AHCI_CAP_NP(cap) + 1;
+
/*
* We cannot be so certain what state the BIOS or whatever
* firmware left the host controller in, therefore the HBA
@@ -173,7 +199,7 @@ ahci_hba_init(struct ahci_hba *hba)
ghc = mmio_read32(&io->ghc);
ghc |= AHCI_GHC_AE;
mmio_write32(&io->ghc, ghc);
- return 0;
+ return ahci_init_ports(hba);
}
/*