drivers/addrenv.c: Move up_addrenv_ implemenation to common folder.

This commit is contained in:
Xiang Xiao 2019-11-03 19:45:05 -06:00 committed by Gregory Nutt
parent c397692532
commit 0c50499027
4 changed files with 181 additions and 0 deletions

View File

@ -3,6 +3,10 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
config DEV_SIMPLE_ADDRENV
bool "Simple AddrEnv"
default n
config DEV_NULL
bool "Enable /dev/null"
default y

View File

@ -88,6 +88,10 @@ ifeq ($(CONFIG_SPECIFIC_DRIVERS),y)
include platform$(DELIM)Make.defs
endif
ifeq ($(CONFIG_DEV_SIMPLE_ADDRENV),y)
CSRCS += addrenv.c
endif
CSRCS += dev_null.c dev_zero.c
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)

92
drivers/addrenv.c Normal file
View File

@ -0,0 +1,92 @@
/****************************************************************************
* drivers/addrenv.c
*
* Copyright (C) 2018 Pinecone Inc. All rights reserved.
* Author: Guiding Li<liguiding@pinecone.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <nuttx/drivers/addrenv.h>
/****************************************************************************
* Private Data
****************************************************************************/
static const struct simple_addrenv_s g_addrenv_dummy;
static const struct simple_addrenv_s *g_addrenv = &g_addrenv_dummy;
/****************************************************************************
* Public Functions
****************************************************************************/
void simple_addrenv_initialize(const struct simple_addrenv_s *addrenv)
{
g_addrenv = addrenv;
}
void *up_addrenv_pa_to_va(uintptr_t pa)
{
uint32_t i;
for (i = 0; g_addrenv[i].size; i++)
{
if (pa - g_addrenv[i].pa < g_addrenv[i].size)
{
return (void *)(g_addrenv[i].va + B2C(pa - g_addrenv[i].pa));
}
}
return (void *)B2C(pa);
}
uintptr_t up_addrenv_va_to_pa(void *va_)
{
uintptr_t va = C2B((uintptr_t)va_);
uint32_t i;
for (i = 0; g_addrenv[i].size; i++)
{
uintptr_t tmp = C2B(g_addrenv[i].va);
if (va - tmp < g_addrenv[i].size)
{
return g_addrenv[i].pa + (va - tmp);
}
}
return va;
}

View File

@ -0,0 +1,81 @@
/****************************************************************************
* include/nuttx/drivers/addrenv.h
*
* Copyright (C) 2018 Pinecone Inc. All rights reserved.
* Author: Guiding Li<liguiding@pinecone.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __INCLUDE_NUTTX_DRIVERS_ADDRENV_H
#define __INCLUDE_NUTTX_DRIVERS_ADDRENV_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <sys/types.h>
/****************************************************************************
* Public Types
****************************************************************************/
struct simple_addrenv_s
{
uintptr_t va;
uintptr_t pa;
size_t size;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
void simple_addrenv_initialize(const struct simple_addrenv_s *addrenv);
#ifdef __cplusplus
}
#endif
#endif /* __INCLUDE_NUTTX_DRIVERS_ADDRENV_H */