1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2008 Freescale Semiconductor, Inc.
13 } address_map[CONFIG_SYS_NUM_ADDR_MAP];
15 phys_addr_t addrmap_virt_to_phys(void * vaddr)
19 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
20 u64 base, upper, addr;
22 if (address_map[i].size == 0)
25 addr = (u64)((u32)vaddr);
26 base = (u64)(address_map[i].vaddr);
27 upper = (u64)(address_map[i].size) + base - 1;
29 if (addr >= base && addr <= upper) {
30 return addr - address_map[i].vaddr + address_map[i].paddr;
34 return (phys_addr_t)(~0);
37 void *addrmap_phys_to_virt(phys_addr_t paddr)
41 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
42 phys_addr_t base, upper;
44 if (address_map[i].size == 0)
47 base = address_map[i].paddr;
48 upper = address_map[i].size + base - 1;
50 if (paddr >= base && paddr <= upper) {
53 offset = address_map[i].paddr - address_map[i].vaddr;
55 return (void *)(unsigned long)(paddr - offset);
62 void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
63 phys_size_t size, int idx)
65 if (idx > CONFIG_SYS_NUM_ADDR_MAP)
68 address_map[idx].vaddr = vaddr;
69 address_map[idx].paddr = paddr;
70 address_map[idx].size = size;