pmm: full rewrite

I've decided to do a rewrite on it due to some plans that would make refcounting physical pages nescessary among other things. now instead of a bitmap it uses a list of pages with each physical page having a page_t associated with it
This commit is contained in:
Matheus
2023-07-29 17:14:41 -03:00
parent 8ca2360991
commit 55fc1b7026
11 changed files with 267 additions and 179 deletions
+15 -12
View File
@@ -233,7 +233,7 @@ typedef struct {
int phase;
} queuedesc_t;
#define QUEUEPAIR_ENTRY_COUNT 256
#define QUEUEPAIR_ENTRY_COUNT (PAGE_SIZE / sizeof(subentry_t))
typedef struct {
queuedesc_t submission;
@@ -350,7 +350,7 @@ static int identify(nvmecontroller_t *controller, void *buffer, int what, int na
entrypair_t pair = {0};
PAIR_INIT(&pair, SUB_DW0_OPCODE_IDENTIFY, SUB_DW0_UNFUSED, SUB_DW0_PRP, 0);
pair.sub.datapointer[0] = (uint64_t)pmm_alloc(1, PMM_SECTION_DEFAULT);
pair.sub.datapointer[0] = (uint64_t)pmm_allocpage(PMM_SECTION_DEFAULT);
if (pair.sub.datapointer[0] == 0)
return ENOMEM;
@@ -519,30 +519,33 @@ static int iowrite(nvmenamespace_t *namespace, uint64_t prp[2], uint64_t lba, ui
static int rwblocks(nvmenamespace_t *namespace, void *buffer, uintmax_t lba, size_t count, bool write, bool pagealignedbuffer) {
// TODO this is pretty inefficient and will be replaced later
__assert(namespace->blocksize < PAGE_SIZE * 2);
void *phys = pmm_alloc(2, PMM_SECTION_DEFAULT);
if (phys == NULL)
return ENOMEM;
__assert(namespace->blocksize <= PAGE_SIZE);
uint64_t prp[2] = {(uint64_t)phys, (uint64_t)phys + PAGE_SIZE};
uint64_t prp[2] = {(uint64_t)pmm_allocpage(PMM_SECTION_DEFAULT), 0};
int err = 0;
if (prp[0] == 0)
goto cleanup;
for (int i = 0; i < count; ++i) {
void *bufferp = (void *)((uintptr_t)buffer + i * namespace->blocksize);
if (write)
memcpy(MAKE_HHDM(phys), bufferp, namespace->blocksize);
if (write) {
memcpy(MAKE_HHDM(prp[0]), bufferp, namespace->blocksize);
}
err = write ? iowrite(namespace, prp, lba + i, 1) : ioread(namespace, prp, lba + i, 1);
if (err)
goto cleanup;
if (!write)
memcpy(bufferp, MAKE_HHDM(phys), namespace->blocksize);
if (!write) {
memcpy(bufferp, MAKE_HHDM(prp[0]), namespace->blocksize);
}
}
cleanup:
pmm_free(phys, 2);
if (prp[0])
pmm_release((void *)prp[0]);
return err;
}
+3 -3
View File
@@ -129,14 +129,14 @@ static int mmap(int minor, void *addr, uintmax_t offset, int flags) {
return arch_mmu_map(_cpu()->vmmctx->pagetable, FROM_HHDM((void *)((uintptr_t)fbs[minor]->address + offset)), addr, vnodeflagstommuflags(flags)) ? 0 : ENOMEM;
} else {
size_t size = offset + PAGE_SIZE < end ? PAGE_SIZE : end - offset;
paddr = pmm_alloc(1, PMM_SECTION_DEFAULT);
paddr = pmm_allocpage(PMM_SECTION_DEFAULT);
if (paddr == NULL)
return ENOMEM;
memcpy(MAKE_HHDM(paddr), (void *)((uintptr_t)fbs[minor]->address + offset), size);
if (arch_mmu_map(_cpu()->vmmctx->pagetable, paddr, addr, vnodeflagstommuflags(flags)) == false) {
pmm_free(paddr, 1);
pmm_release(paddr);
return ENOMEM;
}
@@ -148,7 +148,7 @@ static int munmap(int minor, void *addr, uintmax_t offset, int flags) {
void *phys = arch_mmu_getphysical(_cpu()->vmmctx->pagetable, addr);
arch_mmu_unmap(_cpu()->vmmctx->pagetable, addr);
if ((flags & V_FFLAGS_SHARED) == 0) {
pmm_free(phys, 1);
pmm_release(phys);
}
return 0;