From 86e794c18be111aed29d20fdd95fdbcbd6cf7320 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 14 Oct 2025 19:51:03 -0400 Subject: 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 --- src/sys/io/ic/ahci.c | 23 +++++++++++++++++------ 1 file 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; -- cgit v1.2.3