1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2008 Freescale Semiconductor, Inc.
9 struct addrmap address_map[CONFIG_SYS_NUM_ADDR_MAP];
11 phys_addr_t addrmap_virt_to_phys(void * vaddr)
15 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
16 u64 base, upper, addr;
18 if (address_map[i].size == 0)
21 addr = (u64)((u32)vaddr);
22 base = (u64)(address_map[i].vaddr);
23 upper = (u64)(address_map[i].size) + base - 1;
25 if (addr >= base && addr <= upper) {
26 return addr - address_map[i].vaddr + address_map[i].paddr;
30 return (phys_addr_t)(~0);
33 void *addrmap_phys_to_virt(phys_addr_t paddr)
37 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
38 phys_addr_t base, upper;
40 if (address_map[i].size == 0)
43 base = address_map[i].paddr;
44 upper = address_map[i].size + base - 1;
46 if (paddr >= base && paddr <= upper) {
49 offset = address_map[i].paddr - address_map[i].vaddr;
51 return (void *)(unsigned long)(paddr - offset);
58 void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
59 phys_size_t size, int idx)
61 if (idx > CONFIG_SYS_NUM_ADDR_MAP)
64 address_map[idx].vaddr = vaddr;
65 address_map[idx].paddr = paddr;
66 address_map[idx].size = size;