1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2008 Freescale Semiconductor, Inc.
10 struct addrmap address_map[CONFIG_SYS_NUM_ADDR_MAP];
12 phys_addr_t addrmap_virt_to_phys(void * vaddr)
16 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
17 u64 base, upper, addr;
19 if (address_map[i].size == 0)
22 addr = map_to_sysmem(vaddr);
23 base = (u64)(address_map[i].vaddr);
24 upper = (u64)(address_map[i].size) + base - 1;
26 if (addr >= base && addr <= upper) {
27 return addr - address_map[i].vaddr + address_map[i].paddr;
31 return (phys_addr_t)(~0);
34 void *addrmap_phys_to_virt(phys_addr_t paddr)
38 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
39 phys_addr_t base, upper;
41 if (address_map[i].size == 0)
44 base = address_map[i].paddr;
45 upper = address_map[i].size + base - 1;
47 if (paddr >= base && paddr <= upper) {
50 offset = address_map[i].paddr - address_map[i].vaddr;
52 return map_sysmem(paddr - offset, 0);
59 void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
60 phys_size_t size, int idx)
62 if (idx > CONFIG_SYS_NUM_ADDR_MAP)
65 address_map[idx].vaddr = vaddr;
66 address_map[idx].paddr = paddr;
67 address_map[idx].size = size;