summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-10-14 19:51:03 -0400
committerIan Moffett <ian@osmora.org>2025-10-14 19:51:03 -0400
commit86e794c18be111aed29d20fdd95fdbcbd6cf7320 (patch)
tree65a52e9abf9c1dec99c7ce275bf97404699f2686 /src/sys
parentd0c0c78f65fa06a5bec571bbdc415ad3fed151c4 (diff)
kern: ahci: Correct buffer order during ahci r/w
Move to the buffer given to us if there it is a read, move from the buffer given to us if it is a write Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/io/ic/ahci.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/sys/io/ic/ahci.c b/src/sys/io/ic/ahci.c
index 682c983..e6137e8 100644
--- a/src/sys/io/ic/ahci.c
+++ b/src/sys/io/ic/ahci.c
@@ -281,6 +281,7 @@ ahci_rw(struct ahci_hba *hba, struct ahci_port *port, struct bufargs *bufd)
struct ahci_cmdtab *cmdtbl;
struct ahci_fis_h2d *fis;
paddr_t buf, cmdbase;
+ void *va;
int cmdslot, status;
size_t npgs;
@@ -304,6 +305,11 @@ ahci_rw(struct ahci_hba *hba, struct ahci_port *port, struct bufargs *bufd)
return -ENOMEM;
}
+ if (bufd->write) {
+ va = PHYS_TO_VIRT(buf);
+ memcpy(va, bufd->buf, bufd->nblocks * 512);
+ }
+
/* Get the command list entry for this slot */
cmdslot = ahci_alloc_cmdslot(hba, port);
cmdbase = port->cmdlist;
@@ -342,12 +348,17 @@ ahci_rw(struct ahci_hba *hba, struct ahci_port *port, struct bufargs *bufd)
return status;
}
- /* Now copy it to the real buffer */
- memcpy(
- bufd->buf,
- PHYS_TO_VIRT(buf),
- bufd->nblocks * 512
- );
+ /*
+ * Now copy it to the real buffer if
+ * reading
+ */
+ if (!bufd->write) {
+ memcpy(
+ bufd->buf,
+ PHYS_TO_VIRT(buf),
+ bufd->nblocks * 512
+ );
+ }
vm_free_frame(buf, npgs);
return 0;