From 8a5e4cf53d981e793fca90d9b51bd395265cf4db Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 26 Jan 2023 15:53:16 +0200 Subject: add req_page syscall --- include/apos/mem.h | 8 ++++++++ include/apos/syscalls.h | 3 +++ include/apos/types.h | 1 + include/apos/uapi.h | 26 ++++++++++++++++++++++++++ include/apos/vmem.h | 13 +++++++++++++ 5 files changed, 51 insertions(+) (limited to 'include') diff --git a/include/apos/mem.h b/include/apos/mem.h index 4db7a67..ea61aba 100644 --- a/include/apos/mem.h +++ b/include/apos/mem.h @@ -195,6 +195,14 @@ extern size_t __mm_page_shift; /** Gives access to global maximum order size. \global */ extern enum mm_order __mm_max_order; +/** + * Find nearest order to size. + * + * @param size Size to map to an order. + * @return Nearest order larger than \p size. + */ +enum mm_order nearest_order(size_t size); + /** * Initialize memory subsystem data. Populates __mm_* with data given. * diff --git a/include/apos/syscalls.h b/include/apos/syscalls.h index 611765d..40e6504 100644 --- a/include/apos/syscalls.h +++ b/include/apos/syscalls.h @@ -38,6 +38,9 @@ enum { /** Request memory from anywhere. */ SYS_REQ_MEM, + /** Request physical page from ram. */ + SYS_REQ_PAGE, + /** Request memory with physical address. */ SYS_REQ_PMEM, diff --git a/include/apos/types.h b/include/apos/types.h index 431d551..36e918e 100644 --- a/include/apos/types.h +++ b/include/apos/types.h @@ -445,6 +445,7 @@ typedef int_fast8_t stat_t; * is with pids */ typedef int_fast32_t id_t; +/** Maximum ID number. */ #define ID_MAX INT_FAST32_MAX /** Memory region flags. */ diff --git a/include/apos/uapi.h b/include/apos/uapi.h index dda4391..fefd1bf 100644 --- a/include/apos/uapi.h +++ b/include/apos/uapi.h @@ -319,6 +319,32 @@ SYSCALL_DECLARE1(putch, ch); */ SYSCALL_DECLARE2(req_mem, size, flags); +/** + * Request one page of memory. The nearest fitting size is chosen. + * + * This might be better implemented as some number of adjacent physical pages, + * but the underlying physical page allocator doesn't really handle it very + * well. This weird design decision is because I don't know if there are devices + * whose drivers need multiple adjacent physical pages, only that at least + * virtio devices need to be able to access the physical address of a single + * page. Basic adjacent physical pages can be made from higher order pages, + * just with a massive overhead. Still, probably good eough for now. + * + * For example, if you need two adjacent 4K pages, you pass size = 8K and you + * get back a 2M page, if one is available. + * + * @param t Current tcb. + * @param size Required size of region. + * @param flags Mapping flags to use. + * @param c Unused. + * @param d Unused. + * @param e Unused. + * + * Returns \ref ERR_OOMEM if no page is available, otherwise \c OK, virtual + * address, actual size, physical size in that order. + */ +SYSCALL_DECLARE2(req_page, size, flags); + /** * Request physical memory syscall. * diff --git a/include/apos/vmem.h b/include/apos/vmem.h index 38bad16..5cbe7db 100644 --- a/include/apos/vmem.h +++ b/include/apos/vmem.h @@ -27,6 +27,19 @@ */ vm_t alloc_uvmem(struct tcb *r, size_t size, vmflags_t flags); +/** + * Allocate one physical page for user virtual memory. + * + * @param r Process to allocate memory in. + * @param size Minimum size of allocation. + * @param flags Flags of allocation. + * @param asize Where to write actual size of allocation. + * @param paddr Where to write physical address of page. + * @return Start of allocation when succesful, \c NULL otherwise. + */ +vm_t alloc_uvpage(struct tcb *r, size_t size, vmflags_t flags, + size_t *asize, pm_t *paddr); + /** * Allocate fixed user virtual memory. * -- cgit v1.3