2 * Copyright 2008 Freescale Semiconductor, Inc.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * Version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 } address_map[CONFIG_SYS_NUM_ADDR_MAP];
28 phys_addr_t addrmap_virt_to_phys(void * vaddr)
32 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
33 u64 base, upper, addr;
35 if (address_map[i].size == 0)
38 addr = (u64)((u32)vaddr);
39 base = (u64)(address_map[i].vaddr);
40 upper = (u64)(address_map[i].size) + base - 1;
42 if (addr >= base && addr <= upper) {
43 return addr - address_map[i].vaddr + address_map[i].paddr;
47 return (phys_addr_t)(~0);
50 unsigned long addrmap_phys_to_virt(phys_addr_t paddr)
54 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
55 u64 base, upper, addr;
57 if (address_map[i].size == 0)
61 base = (u64)(address_map[i].paddr);
62 upper = (u64)(address_map[i].size) + base - 1;
64 if (addr >= base && addr <= upper) {
65 return paddr - address_map[i].paddr + address_map[i].vaddr;
69 return (unsigned long)(~0);
72 void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
73 phys_size_t size, int idx)
75 if (idx > CONFIG_SYS_NUM_ADDR_MAP)
78 address_map[idx].vaddr = vaddr;
79 address_map[idx].paddr = paddr;
80 address_map[idx].size = size;