xref: /haiku/src/system/kernel/arch/arm64/PMAPPhysicalPageMapper.cpp (revision 9a6a20d4689307142a7ed26a1437ba47e244e73f)
1 /*
2  * Copyright 2022 Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #include "PMAPPhysicalPageMapper.h"
6 
7 
8 status_t
9 PMAPPhysicalPageMapper::GetPage(
10 	phys_addr_t physicalAddress, addr_t* _virtualAddress, void** _handle)
11 {
12 	ASSERT(physicalAddress < KERNEL_PMAP_SIZE);
13 
14 	*_virtualAddress = KERNEL_PMAP_BASE + physicalAddress;
15 	*_handle = NULL;
16 
17 	return B_OK;
18 }
19 
20 
21 status_t
22 PMAPPhysicalPageMapper::PutPage(addr_t virtualAddress, void* handle)
23 {
24 	return B_OK;
25 }
26 
27 
28 status_t
29 PMAPPhysicalPageMapper::MemsetPhysical(phys_addr_t address, int value, phys_size_t length)
30 {
31 	ASSERT(address < KERNEL_PMAP_SIZE);
32 	memset(reinterpret_cast<void*>(KERNEL_PMAP_BASE + address), value, length);
33 
34 	return B_OK;
35 }
36 
37 status_t
38 PMAPPhysicalPageMapper::MemcpyFromPhysical(void* to, phys_addr_t from, size_t length, bool user)
39 {
40 	ASSERT(from < KERNEL_PMAP_SIZE);
41 
42 	if (!user) {
43 		memcpy(to, reinterpret_cast<void*>(KERNEL_PMAP_BASE + from), length);
44 		return B_OK;
45 	} else {
46 		return user_memcpy(to, reinterpret_cast<void*>(KERNEL_PMAP_BASE + from), length);
47 	}
48 }
49 
50 
51 status_t
52 PMAPPhysicalPageMapper::MemcpyToPhysical(phys_addr_t to, const void* from, size_t length, bool user)
53 {
54 	ASSERT(to < KERNEL_PMAP_SIZE);
55 
56 	if (!user) {
57 		memcpy(reinterpret_cast<void*>(KERNEL_PMAP_BASE + to), from, length);
58 		return B_OK;
59 	} else {
60 		return user_memcpy(reinterpret_cast<void*>(KERNEL_PMAP_BASE + to), from, length);
61 	}
62 
63 	return B_OK;
64 }
65 
66 
67 void
68 PMAPPhysicalPageMapper::MemcpyPhysicalPage(phys_addr_t to, phys_addr_t from)
69 {
70 	ASSERT(to < KERNEL_PMAP_SIZE);
71 	ASSERT(from < KERNEL_PMAP_SIZE);
72 	memcpy(reinterpret_cast<void*>(KERNEL_PMAP_BASE + to),
73 		reinterpret_cast<void*>(KERNEL_PMAP_BASE + from), B_PAGE_SIZE);
74 }
75