1 /*
2  * Copyright 2014, General Dynamics C4 Systems
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 #pragma once
8 
9 #include <plat/machine.h>
10 #include <machine/registerset.h>
11 #include <hardware.h>
12 
13 /* When translating a physical address into an address accessible to the
14  * kernel via virtual addressing we always use the mapping of the memory
15  * into the physical memory window, even if the mapping originally
16  * referred to a kernel virtual address. */
ptrFromPAddr(paddr_t paddr)17 static inline void *CONST ptrFromPAddr(paddr_t paddr)
18 {
19     return (void *)(paddr + PPTR_BASE_OFFSET);
20 }
21 
22 /* When obtaining a physical address from a reference to any object in
23  * the physical mapping window, this function must be used. */
addrFromPPtr(const void * pptr)24 static inline paddr_t CONST addrFromPPtr(const void *pptr)
25 {
26     return (paddr_t)pptr - PPTR_BASE_OFFSET;
27 }
28 
29 /* When obtaining a physical address from a reference to an address from
30  * the kernel ELF mapping, this function must be used. */
addrFromKPPtr(const void * pptr)31 static inline paddr_t CONST addrFromKPPtr(const void *pptr)
32 {
33     assert((paddr_t)pptr >= KERNEL_ELF_BASE);
34     assert((paddr_t)pptr <= KERNEL_ELF_TOP);
35     return (paddr_t)pptr - KERNEL_ELF_BASE_OFFSET;
36 }
37 
paddr_to_pptr_reg(const p_region_t p_reg)38 static inline region_t CONST paddr_to_pptr_reg(const p_region_t p_reg)
39 {
40     return (region_t) {
41         p_reg.start + PPTR_BASE_OFFSET, p_reg.end + PPTR_BASE_OFFSET
42     };
43 }
44 
pptr_to_paddr_reg(const region_t reg)45 static inline p_region_t CONST pptr_to_paddr_reg(const region_t reg)
46 {
47     return (p_region_t) {
48         reg.start - PPTR_BASE_OFFSET, reg.end - PPTR_BASE_OFFSET
49     };
50 }
51 
52 #define paddr_to_pptr(x)   ptrFromPAddr(x)
53 #define pptr_to_paddr(x)   addrFromPPtr(x)
54 #define kpptr_to_paddr(x)  addrFromKPPtr(x)
55 
56 #include <mode/machine.h>
57