1 /*
2  * Copyright (c) 2014 Travis Geiselbrecht
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files
6  * (the "Software"), to deal in the Software without restriction,
7  * including without limitation the rights to use, copy, modify, merge,
8  * publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #pragma once
24 
25 #include <stdint.h>
26 #include <sys/types.h>
27 #include <kernel/vm.h>
28 
29 /* simple boot time allocator state */
30 extern uintptr_t boot_alloc_start;
31 extern uintptr_t boot_alloc_end;
32 
33 /**
34  * struct vmm_res_obj - Object reserving address space with no physical backing.
35  * @vmm_obj: The underlying vmm object.
36  * @regions: The regions mapped inside this object.
37  */
38 struct vmm_res_obj {
39     struct vmm_obj vmm_obj;
40     struct bst_root regions;
41 };
42 
43 void vmm_init_preheap(void);
44 void vmm_init(void);
45 
46 /* Reserve a number of pages, ensuring that backing physical memory exists. Reserved pages
47  * can only be mapped using PMM_ALLOC_FLAG_FROM_RESERVED.
48 */
49 status_t pmm_reserve_pages(uint count);
50 
51 /* Unreserve a number of pages. */
52 void pmm_unreserve_pages(uint count);
53 
54 
55 /* private interface between pmm and vm */
56 void *pmm_paddr_to_kvaddr(paddr_t pa);
57 
58 /* Check whether the given vmm_obj is a pmm whose memory
59  * needs to be cleared before mapping.
60  */
61 bool pmm_vmm_is_pmm_that_needs_clear(struct vmm_obj* vmm);
62 
63 /* Check whether the given vmm_obj is a pmm whose memory
64  * is allowed to be mapped tagged.
65  */
66 bool pmm_vmm_is_pmm_that_allows_tagged(struct vmm_obj* vmm);
67 
68 /* Declare that the memory associated with this vmm_obj
69  * (which must be a pmm_obj) was cleared
70  */
71 void pmm_set_cleared(struct vmm_obj* vmm, size_t offset, size_t size);
72 
73 /* Declare that the memory associated with this vmm_obj
74  * (which must be a pmm_obj) has been mapped as tagged
75  */
76 void pmm_set_tagged(struct vmm_obj* vmm);
77