xref: /haiku/src/system/boot/platform/efi/mmu.h (revision 9e25244c5e9051f6cd333820d6332397361abd6c)
1 /*
2  * Copyright 2014, Henry Harrington, henry.harrington@gmail.com.
3  * Copyright 2019-2022, Haiku, Inc. All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef MMU_H
7 #define MMU_H
8 
9 
10 #ifndef _ASSEMBLER
11 
12 
13 #include "efi_platform.h"
14 
15 #include <util/FixedWidthPointer.h>
16 
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 static const uint32 kDefaultPageFlags = 0x3;
23     // present, R/W
24 static const uint64 kTableMappingFlags = 0x7;
25     // present, R/W, user
26 static const uint64 kLargePageMappingFlags = 0x183;
27     // present, R/W, user, global, large
28 static const uint64 kPageMappingFlags = 0x103;
29     // present, R/W, user, global
30 
31 
32 extern addr_t get_next_virtual_address(size_t size);
33 extern addr_t get_current_virtual_address();
34 
35 extern void mmu_init();
36 
37 extern phys_addr_t mmu_allocate_page();
38 
39 bool mmu_next_region(void** cookie, addr_t* vaddr, phys_addr_t* paddr, size_t* size);
40 
41 extern addr_t mmu_map_physical_memory(addr_t physicalAddress, size_t size,
42 	uint32 flags);
43 
44 extern status_t platform_kernel_address_to_bootloader_address(addr_t address,
45 	void **_result);
46 
47 extern status_t platform_bootloader_address_to_kernel_address(void *address,
48 	addr_t *_result);
49 
50 extern status_t platform_allocate_lomem(void **_address, size_t size);
51 
52 #ifdef __cplusplus
53 }
54 #endif
55 
56 
57 /*! Convert a 32-bit address to a 64-bit address. */
58 inline addr_t
59 fix_address(addr_t address)
60 {
61 	addr_t result;
62 	if (platform_bootloader_address_to_kernel_address((void *)address, &result)
63 		!= B_OK) {
64 		return address;
65 	} else
66 		return result;
67 }
68 
69 
70 template<typename Type>
71 inline void
72 fix_address(FixedWidthPointer<Type>& p)
73 {
74 	if (p != NULL)
75 		p.SetTo(fix_address(p.Get()));
76 }
77 
78 
79 #endif	// !_ASSEMBLER
80 
81 #endif	/* MMU_H */
82