From 5dfd2c3d6f4ed51867c8a11ea01bf32c7fb41e46 Mon Sep 17 00:00:00 2001 From: Matheus Date: Wed, 18 Sep 2024 21:43:11 -0300 Subject: [PATCH] block: directly do DMA into page cache --- kernel-src/io/block/block.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/kernel-src/io/block/block.c b/kernel-src/io/block/block.c index 41408ff9..5fc6958c 100644 --- a/kernel-src/io/block/block.c +++ b/kernel-src/io/block/block.c @@ -79,6 +79,7 @@ static int rwblock(int minor, void *buffer, size_t size, uintmax_t offset, int f if (desc == NULL) return ENODEV; + __assert((size % desc->blocksize) == 0); uintmax_t bytetop = desc->blockcapacity * desc->blocksize; // offset past end @@ -99,28 +100,21 @@ static int rwblock(int minor, void *buffer, size_t size, uintmax_t offset, int f size_t lbaoffset, lbacount, startoffset; bytestolba(desc, offset, size, &lbaoffset, &lbacount, &startoffset); - void *lbabuffer = vmm_map(NULL, lbacount * desc->blocksize, VMM_FLAGS_ALLOCATE, MAP_FLAGS, NULL); - if (lbabuffer == NULL) - return ENOMEM; - - int error = DISK_READ(desc, lbabuffer, lbaoffset + desc->lbaoffset, lbacount); - if (error) - goto cleanup; - + int error = 0; if (write) { - memcpy((void *)((uintptr_t)lbabuffer + startoffset), buffer, size); - error = DISK_WRITE(desc, lbabuffer, lbaoffset + desc->lbaoffset, lbacount); + error = DISK_WRITE(desc, buffer, lbaoffset + desc->lbaoffset, lbacount); + if (error) + goto cleanup; + } else { + error = DISK_READ(desc, buffer, lbaoffset + desc->lbaoffset, lbacount); if (error) goto cleanup; } - if (!write) - memcpy(buffer, (void *)((uintptr_t)lbabuffer + startoffset), size); *done = size; cleanup: - vmm_unmap(lbabuffer, lbacount * desc->blocksize, 0); return error; }