diff options
| author | Ian Moffett <ian@osmora.org> | 2025-11-23 13:37:23 -0500 |
|---|---|---|
| committer | Ian Moffett <ian@osmora.org> | 2025-11-23 13:37:23 -0500 |
| commit | b66e8e0c9999565c78d6d207f904c8d3ec1148e4 (patch) | |
| tree | d2bf632b9e4660a78637f09c4cc5110d67b79d47 /sys/lib | |
| parent | d9e933046e49221836cae35769c5d53ac721e715 (diff) | |
kern: lib: Add pointerbox physmem allocationdev
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/lib')
| -rw-r--r-- | sys/lib/ptrbox.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sys/lib/ptrbox.c b/sys/lib/ptrbox.c index d2e9171..b2777dc 100644 --- a/sys/lib/ptrbox.c +++ b/sys/lib/ptrbox.c @@ -29,11 +29,44 @@ #include <sys/types.h> #include <sys/cdefs.h> +#include <sys/param.h> #include <sys/errno.h> #include <vm/kalloc.h> +#include <vm/phys.h> +#include <vm/vm.h> #include <lib/ptrbox.h> static void * +ptrbox_physalloc(struct ptrbox *pbox, size_t len) +{ + struct ptrbox_aldes *aldes; + uintptr_t paddr; + + len = ALIGN_UP(len, PAGESIZE); + paddr = vm_phys_alloc(len / PAGESIZE); + if (paddr == 0) { + return NULL; + } + + /* Allocate a descriptor */ + aldes = kalloc(sizeof(*aldes)); + if (aldes == NULL) { + vm_phys_free(paddr, len / PAGESIZE); + return NULL; + } + + /* Initialize our descriptor */ + aldes->type = PTRBOX_PHYSMEM; + aldes->phys = paddr; + aldes->length = len; + + /* Push it to the pointer box */ + TAILQ_INSERT_TAIL(&pbox->allist, aldes, link); + ++pbox->alcnt; + return PHYS_TO_VIRT(paddr); +} + +static void * ptrbox_heapalloc(struct ptrbox *pbox, size_t len) { struct ptrbox_aldes *aldes; @@ -76,6 +109,8 @@ ptrbox_alloc(struct ptrbox *pbox, size_t len, ptrbox_altype_t type) switch (type) { case PTRBOX_HEAP: return ptrbox_heapalloc(pbox, len); + case PTRBOX_PHYSMEM: + return ptrbox_physalloc(pbox, len); default: return NULL; } @@ -106,6 +141,12 @@ ptrbox_free(struct ptrbox *pbox) case PTRBOX_HEAP: kfree(desc->base); break; + case PTRBOX_PHYSMEM: + vm_phys_free( + desc->phys, + desc->length / PAGESIZE + ); + break; } kfree(desc); |
