2 * Copyright 2008 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0
14 } address_map[CONFIG_SYS_NUM_ADDR_MAP];
16 phys_addr_t addrmap_virt_to_phys(void * vaddr)
20 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
21 u64 base, upper, addr;
23 if (address_map[i].size == 0)
26 addr = (u64)((u32)vaddr);
27 base = (u64)(address_map[i].vaddr);
28 upper = (u64)(address_map[i].size) + base - 1;
30 if (addr >= base && addr <= upper) {
31 return addr - address_map[i].vaddr + address_map[i].paddr;
35 return (phys_addr_t)(~0);
38 void *addrmap_phys_to_virt(phys_addr_t paddr)
42 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
43 phys_addr_t base, upper;
45 if (address_map[i].size == 0)
48 base = address_map[i].paddr;
49 upper = address_map[i].size + base - 1;
51 if (paddr >= base && paddr <= upper) {
54 offset = address_map[i].paddr - address_map[i].vaddr;
56 return (void *)(unsigned long)(paddr - offset);
63 void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
64 phys_size_t size, int idx)
66 if (idx > CONFIG_SYS_NUM_ADDR_MAP)
69 address_map[idx].vaddr = vaddr;
70 address_map[idx].paddr = paddr;
71 address_map[idx].size = size;