diff options
author | Ian Moffett <ian@osmora.org> | 2025-05-09 22:45:06 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-05-09 22:45:06 -0400 |
commit | 0973627785f3b2387bb5c4bb13c634b74348e1b1 (patch) | |
tree | e8e1e58a5ca6116e2250bfcbfcb42f2435a1f8e0 | |
parent | 2219a2ed8c831f85afb849100b571273f9055a0c (diff) |
kernel: ahci: Add command list helpers
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | sys/dev/ic/ahci.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c index 3142193..3078ec3 100644 --- a/sys/dev/ic/ahci.c +++ b/sys/dev/ic/ahci.c @@ -87,6 +87,42 @@ ahci_poll_reg(volatile uint32_t *reg, uint32_t bits, bool pollset) return 0; } +/* + * Allocate a command slot for a port on + * the HBA. + */ +static int +ahci_alloc_cmdslot(struct ahci_hba *hba, struct hba_port *port) +{ + uint32_t slotlist; + + slotlist = port->ci | port->sact; + slotlist = mmio_read32(&port->ci); + slotlist |= mmio_read32(&port->sact); + + for (int i = 0; i < hba->nslots; ++i) { + if (!ISSET(slotlist, i)) { + return i; + } + } + + return -EAGAIN; +} + +/* + * Get the command list base. + */ +static paddr_t +ahci_cmdbase(struct hba_port *port) +{ + paddr_t basel, baseh, base; + + basel = mmio_read32(&port->clb); + baseh = mmio_read32(&port->clbu); + base = COMBINE32(baseh, basel); + return base; +} + static int ahci_hba_reset(struct ahci_hba *hba) { |