xen: pvblock: Use uclass_probe_all
[platform/kernel/u-boot.git] / lib / addr_map.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2008 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <addr_map.h>
8 #include <mapmem.h>
9
10 struct addrmap address_map[CONFIG_SYS_NUM_ADDR_MAP];
11
12 phys_addr_t addrmap_virt_to_phys(void * vaddr)
13 {
14         int i;
15
16         for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
17                 u64 base, upper, addr;
18
19                 if (address_map[i].size == 0)
20                         continue;
21
22                 addr = map_to_sysmem(vaddr);
23                 base = (u64)(address_map[i].vaddr);
24                 upper = (u64)(address_map[i].size) + base - 1;
25
26                 if (addr >= base && addr <= upper) {
27                         return addr - address_map[i].vaddr + address_map[i].paddr;
28                 }
29         }
30
31         return (phys_addr_t)(~0);
32 }
33
34 void *addrmap_phys_to_virt(phys_addr_t paddr)
35 {
36         int i;
37
38         for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
39                 phys_addr_t base, upper;
40
41                 if (address_map[i].size == 0)
42                         continue;
43
44                 base = address_map[i].paddr;
45                 upper = address_map[i].size + base - 1;
46
47                 if (paddr >= base && paddr <= upper) {
48                         phys_addr_t offset;
49
50                         offset = address_map[i].paddr - address_map[i].vaddr;
51
52                         return map_sysmem(paddr - offset, 0);
53                 }
54         }
55
56         return (void *)(~0);
57 }
58
59 void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
60                         phys_size_t size, int idx)
61 {
62         if (idx > CONFIG_SYS_NUM_ADDR_MAP)
63                 return;
64
65         address_map[idx].vaddr = vaddr;
66         address_map[idx].paddr = paddr;
67         address_map[idx].size  = size;
68 }