summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-05-09 22:12:27 -0400
committerIan Moffett <ian@osmora.org>2025-05-09 22:12:27 -0400
commit1ec9b34e7abf37fd00fd04c3f2e1a75c41fe403f (patch)
tree3e876a8a38196252e34a9cbccb59b0e5cebfdbff
parent4c47d7b7656c64e35673a45c1bfe8a6a002174cc (diff)
kernel: ahci: Add sanity checks to port start/stop
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/dev/ic/ahci.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/sys/dev/ic/ahci.c b/sys/dev/ic/ahci.c
index 1eac07b..c0c6fec 100644
--- a/sys/dev/ic/ahci.c
+++ b/sys/dev/ic/ahci.c
@@ -127,10 +127,15 @@ ahci_hba_reset(struct ahci_hba *hba)
static int
hba_port_stop(struct hba_port *port)
{
+ const uint32_t RUN_MASK = (AHCI_PXCMD_FR | AHCI_PXCMD_CR);
uint32_t cmd, tmp;
- /* Stop the port */
+ /* Ensure the port is running */
cmd = mmio_read32(&port->cmd);
+ if (!ISSET(cmd, RUN_MASK)) {
+ return 0;
+ }
+
cmd &= ~(AHCI_PXCMD_ST | AHCI_PXCMD_FRE);
mmio_write32(&port->cmd, cmd);
@@ -153,10 +158,16 @@ hba_port_stop(struct hba_port *port)
static int
hba_port_start(struct hba_port *port)
{
+ const uint32_t RUN_MASK = (AHCI_PXCMD_FR | AHCI_PXCMD_CR);
uint32_t cmd, tmp;
- /* Bring up the port */
+ /* Ensure the port is not running */
cmd = mmio_read32(&port->cmd);
+ if (ISSET(cmd, RUN_MASK)) {
+ return 0;
+ }
+
+ /* Bring up the port */
cmd |= AHCI_PXCMD_ST | AHCI_PXCMD_FRE;
mmio_write32(&port->cmd, cmd);