]> Git Repo - J-u-boot.git/blame - lib/addr_map.c
tpm: add kconfig control in tcg2_create_digest()
[J-u-boot.git] / lib / addr_map.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0
63240ba8
KG
2/*
3 * Copyright 2008 Freescale Semiconductor, Inc.
63240ba8
KG
4 */
5
63240ba8 6#include <addr_map.h>
28199611 7#include <mapmem.h>
63240ba8 8
b5615633 9struct addrmap address_map[CONFIG_SYS_NUM_ADDR_MAP];
63240ba8
KG
10
11phys_addr_t addrmap_virt_to_phys(void * vaddr)
12{
13 int i;
14
15 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
16 u64 base, upper, addr;
17
18 if (address_map[i].size == 0)
19 continue;
20
28199611 21 addr = map_to_sysmem(vaddr);
63240ba8
KG
22 base = (u64)(address_map[i].vaddr);
23 upper = (u64)(address_map[i].size) + base - 1;
24
25 if (addr >= base && addr <= upper) {
26 return addr - address_map[i].vaddr + address_map[i].paddr;
27 }
28 }
29
30 return (phys_addr_t)(~0);
31}
32
7b6e8053 33void *addrmap_phys_to_virt(phys_addr_t paddr)
63240ba8
KG
34{
35 int i;
36
37 for (i = 0; i < CONFIG_SYS_NUM_ADDR_MAP; i++) {
7b6e8053 38 phys_addr_t base, upper;
63240ba8
KG
39
40 if (address_map[i].size == 0)
41 continue;
42
7b6e8053
TT
43 base = address_map[i].paddr;
44 upper = address_map[i].size + base - 1;
63240ba8 45
7b6e8053
TT
46 if (paddr >= base && paddr <= upper) {
47 phys_addr_t offset;
48
49 offset = address_map[i].paddr - address_map[i].vaddr;
50
28199611 51 return map_sysmem(paddr - offset, 0);
63240ba8
KG
52 }
53 }
54
7b6e8053 55 return (void *)(~0);
63240ba8
KG
56}
57
58void addrmap_set_entry(unsigned long vaddr, phys_addr_t paddr,
59 phys_size_t size, int idx)
60{
7dd06b16 61 if (idx >= CONFIG_SYS_NUM_ADDR_MAP)
63240ba8
KG
62 return;
63
64 address_map[idx].vaddr = vaddr;
65 address_map[idx].paddr = paddr;
66 address_map[idx].size = size;
67}
This page took 0.482474 seconds and 4 git commands to generate.