xref: /nrf52832-nimble/rt-thread/components/vmm/vmm_iomap.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  *  VMM IO map table
3  *
4  * COPYRIGHT (C) 2013-2014, Real-Thread Information Technology Ltd
5  * All rights reserved
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  *
9  * Change Logs:
10  * Date           Author       Notes
11  * 2013-06-15     Bernard      the first verion
12  */
13 #include <rtthread.h>
14 #include "vmm.h"
15 
16 static struct vmm_iomap _vmm_iomap[RT_VMM_IOMAP_MAXNR];
17 
vmm_iomap_init(struct vmm_iomap * iomap)18 void vmm_iomap_init(struct vmm_iomap *iomap)
19 {
20     rt_memcpy(_vmm_iomap, iomap, sizeof(_vmm_iomap));
21 }
22 
23 /* find virtual address according to name */
vmm_find_iomap(const char * name)24 unsigned long vmm_find_iomap(const char *name)
25 {
26     int i;
27 
28     for (i = 0; i < ARRAY_SIZE(_vmm_iomap); i++)
29     {
30         if (rt_strcmp(_vmm_iomap[i].name, name) == 0)
31             return (unsigned long)_vmm_iomap[i].va;
32     }
33 
34     return 0;
35 }
36 
37 /* find virtual address according to physcal address */
vmm_find_iomap_by_pa(unsigned long pa)38 unsigned long vmm_find_iomap_by_pa(unsigned long pa)
39 {
40     int i;
41 
42     for (i = 0; i < ARRAY_SIZE(_vmm_iomap); i++)
43     {
44         if (_vmm_iomap[i].pa == pa)
45             return (unsigned long)_vmm_iomap[i].va;
46     }
47 
48     return 0;
49 }
50