aboutsummaryrefslogtreecommitdiff
path: root/include/apos
diff options
context:
space:
mode:
Diffstat (limited to 'include/apos')
-rw-r--r--include/apos/mem.h8
-rw-r--r--include/apos/syscalls.h3
-rw-r--r--include/apos/types.h1
-rw-r--r--include/apos/uapi.h26
-rw-r--r--include/apos/vmem.h13
5 files changed, 51 insertions, 0 deletions
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
@@ -196,6 +196,14 @@ extern size_t __mm_page_shift;
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.
*
* @param max_order Maximum order the current system supports.
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
@@ -320,6 +320,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.
*
* Allocates at least the specified size of allocation which includes the
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
@@ -28,6 +28,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.
*
* Virtual memory start address is chosen so that \c start is within the