sim_addrenv: support add addrenv dynamically multiple times.
N/A Change-Id: Ie34f6c59bc16fb147c7103978253dbe9403990d3 Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
2969cf7a66
commit
c06bc9eebd
2 changed files with 51 additions and 15 deletions
|
|
@ -23,53 +23,89 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/list.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/drivers/addrenv.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct simple_addrenv_node_s
|
||||
{
|
||||
struct list_node node;
|
||||
FAR const struct simple_addrenv_s *addrenv;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct simple_addrenv_s g_addrenv_dummy;
|
||||
static const struct simple_addrenv_s *g_addrenv = &g_addrenv_dummy;
|
||||
static struct list_node g_addrenv_list = LIST_INITIAL_VALUE(g_addrenv_list);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
void simple_addrenv_initialize(const struct simple_addrenv_s *addrenv)
|
||||
void simple_addrenv_initialize(FAR const struct simple_addrenv_s *addrenv)
|
||||
{
|
||||
g_addrenv = addrenv;
|
||||
FAR struct simple_addrenv_node_s *node;
|
||||
|
||||
if (addrenv != NULL)
|
||||
{
|
||||
node = kmm_malloc(sizeof(*node));
|
||||
if (node != NULL)
|
||||
{
|
||||
node->addrenv = addrenv;
|
||||
list_add_tail(&g_addrenv_list, &node->node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *up_addrenv_pa_to_va(uintptr_t pa)
|
||||
FAR void *up_addrenv_pa_to_va(uintptr_t pa)
|
||||
{
|
||||
FAR struct simple_addrenv_node_s *node;
|
||||
FAR const struct simple_addrenv_s *addrenv;
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; g_addrenv[i].size; i++)
|
||||
list_for_every_entry(&g_addrenv_list, node,
|
||||
struct simple_addrenv_node_s, node)
|
||||
{
|
||||
if (pa - g_addrenv[i].pa < g_addrenv[i].size)
|
||||
addrenv = node->addrenv;
|
||||
for (i = 0; addrenv[i].size; i++)
|
||||
{
|
||||
return (void *)(g_addrenv[i].va + B2C(pa - g_addrenv[i].pa));
|
||||
if (pa - addrenv[i].pa < addrenv[i].size)
|
||||
{
|
||||
return (FAR void *)(addrenv[i].va +
|
||||
B2C(pa - addrenv[i].pa));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (void *)B2C(pa);
|
||||
return (FAR void *)B2C(pa);
|
||||
}
|
||||
|
||||
uintptr_t up_addrenv_va_to_pa(void *va_)
|
||||
uintptr_t up_addrenv_va_to_pa(FAR void *va_)
|
||||
{
|
||||
FAR struct simple_addrenv_node_s *node;
|
||||
FAR const struct simple_addrenv_s *addrenv;
|
||||
uintptr_t va = C2B((uintptr_t)va_);
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; g_addrenv[i].size; i++)
|
||||
list_for_every_entry(&g_addrenv_list, node,
|
||||
struct simple_addrenv_node_s, node)
|
||||
{
|
||||
uintptr_t tmp = C2B(g_addrenv[i].va);
|
||||
if (va - tmp < g_addrenv[i].size)
|
||||
addrenv = node->addrenv;
|
||||
for (i = 0; addrenv[i].size; i++)
|
||||
{
|
||||
return g_addrenv[i].pa + (va - tmp);
|
||||
uintptr_t tmp = C2B(addrenv[i].va);
|
||||
if (va - tmp < addrenv[i].size)
|
||||
{
|
||||
return addrenv[i].pa + (va - tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ extern "C"
|
|||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
void simple_addrenv_initialize(const struct simple_addrenv_s *addrenv);
|
||||
void simple_addrenv_initialize(FAR const struct simple_addrenv_s *addrenv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue