1 /*
2  * Copyright (c) 2015 Google, Inc. All rights reserved
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <stddef.h>
11 #include <sys/types.h>
12 #include <lk/compiler.h>
13 
14 // to pick up PAGE_SIZE, PAGE_ALIGN, etc
15 #if WITH_KERNEL_VM
16 #include <kernel/vm.h>
17 #else
18 #include <kernel/novm.h>
19 #endif
20 
21 /* A simple page-aligned wrapper around the pmm or novm implementation of
22  * the underlying physical page allocator. Used by system heaps or any
23  * other user that wants pages of memory but doesn't want to use LK
24  * specific apis.
25  */
26 
27 __BEGIN_CDECLS
28 
29 #define PAGE_ALLOC_ANY_ARENA (-1)
30 
31 /* Pass PAGE_ALLOC_ANY_ARENA as the arena mask if you don't care which arena
32  * the allocation comes from. The arena mask is only used on non-virtual memory
33  * platforms.
34  */
35 void *page_alloc(size_t pages, int arena_mask);
36 void page_free(void *ptr, size_t pages);
37 
38 #if WITH_KERNEL_VM
39 struct page_range {
40     void *address;
41     size_t size;
42 };
43 #endif
44 
45 int page_get_arenas(struct page_range *ranges, int number_of_ranges);
46 
47 // You can call this once at the start, and it will either return a page or it
48 // will return some non-page-aligned memory that would otherwise go to waste.
49 void *page_first_alloc(size_t *size_return);
50 
51 __END_CDECLS
52