ARCH: COMMON: split sys_io.h for MMIO & memory bits functions
As of today 'include/arch/common/sys_io.h" has generic implementation for MMIO accessors and memory bits manipulation functions. That leads to several architectures like ARC, ARM/aarch64, ARM/aarch32/corter_a_r redefine entire 'common/sys_io.h' even if they only have different MMIO accessors implementation. So split 'include/arch/common/sys_io.h" to * sys_io.h - generic MMIO accessors * sys_bitops.h - generic memory bits manipulation functions Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
This commit is contained in:
parent
cb12440322
commit
ebe51e26cb
7 changed files with 122 additions and 91 deletions
|
@ -35,6 +35,7 @@
|
|||
#ifdef CONFIG_CPU_CORTEX_M
|
||||
#include <arch/arm/aarch32/cortex_m/cpu.h>
|
||||
#include <arch/arm/aarch32/cortex_m/memory_map.h>
|
||||
#include <arch/common/sys_bitops.h>
|
||||
#include <arch/common/sys_io.h>
|
||||
#elif defined(CONFIG_CPU_CORTEX_R)
|
||||
#include <arch/arm/aarch32/cortex_a_r/cpu.h>
|
||||
|
|
116
include/arch/common/sys_bitops.h
Normal file
116
include/arch/common/sys_bitops.h
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Wind River Systems, Inc.
|
||||
* Copyright (c) 2017, Oticon A/S
|
||||
* Copyright (c) 2020, Synopsys
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* Memory bits manipulation functions in non-arch-specific C code */
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_ARCH_COMMON_SYS_BITOPS_H_
|
||||
#define ZEPHYR_INCLUDE_ARCH_COMMON_SYS_BITOPS_H_
|
||||
|
||||
#ifndef _ASMLANGUAGE
|
||||
|
||||
#include <toolchain.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <sys/sys_io.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static ALWAYS_INLINE void sys_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
uint32_t temp = *(volatile uint32_t *)addr;
|
||||
|
||||
*(volatile uint32_t *)addr = temp | (1 << bit);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void sys_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
uint32_t temp = *(volatile uint32_t *)addr;
|
||||
|
||||
*(volatile uint32_t *)addr = temp & ~(1 << bit);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE int sys_test_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
uint32_t temp = *(volatile uint32_t *)addr;
|
||||
|
||||
return temp & (1 << bit);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
/* Doing memory offsets in terms of 32-bit values to prevent
|
||||
* alignment issues
|
||||
*/
|
||||
sys_set_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_test_bit(addr, bit);
|
||||
sys_set_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_test_bit(addr, bit);
|
||||
sys_clear_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_bitfield_test_bit(addr, bit);
|
||||
sys_bitfield_set_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_bitfield_test_bit(addr, bit);
|
||||
sys_bitfield_clear_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ASMLANGUAGE */
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_ARCH_COMMON_SYS_BITOPS_H_ */
|
|
@ -5,9 +5,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* "Arch" bit manipulation functions in non-arch-specific C code (uses some
|
||||
* gcc builtins)
|
||||
*/
|
||||
/* Memory mapped registers I/O functions in non-arch-specific C code */
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_ARCH_COMMON_SYS_IO_H_
|
||||
#define ZEPHYR_INCLUDE_ARCH_COMMON_SYS_IO_H_
|
||||
|
@ -52,94 +50,6 @@ static ALWAYS_INLINE void sys_write32(uint32_t data, mem_addr_t addr)
|
|||
*(volatile uint32_t *)addr = data;
|
||||
}
|
||||
|
||||
/* Memory bit manipulation functions */
|
||||
|
||||
static ALWAYS_INLINE void sys_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
uint32_t temp = *(volatile uint32_t *)addr;
|
||||
|
||||
*(volatile uint32_t *)addr = temp | (1 << bit);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void sys_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
uint32_t temp = *(volatile uint32_t *)addr;
|
||||
|
||||
*(volatile uint32_t *)addr = temp & ~(1 << bit);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE int sys_test_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
uint32_t temp = *(volatile uint32_t *)addr;
|
||||
|
||||
return temp & (1 << bit);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
/* Doing memory offsets in terms of 32-bit values to prevent
|
||||
* alignment issues
|
||||
*/
|
||||
sys_set_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_test_bit(addr, bit);
|
||||
sys_set_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_test_bit(addr, bit);
|
||||
sys_clear_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_bitfield_test_bit(addr, bit);
|
||||
sys_bitfield_set_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_bitfield_test_bit(addr, bit);
|
||||
sys_bitfield_clear_bit(addr, bit);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <arch/common/addr_types.h>
|
||||
#include <devicetree.h>
|
||||
#include <arch/nios2/nios2.h>
|
||||
#include <arch/common/sys_bitops.h>
|
||||
#include <arch/common/sys_io.h>
|
||||
#include <arch/common/ffs.h>
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <toolchain/common.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <arch/common/sys_bitops.h>
|
||||
#include <arch/common/sys_io.h>
|
||||
#include <arch/common/ffs.h>
|
||||
#include <arch/posix/posix_soc_if.h>
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <arch/riscv/thread.h>
|
||||
#include <arch/riscv/exp.h>
|
||||
#include <arch/common/sys_bitops.h>
|
||||
#include <arch/common/sys_io.h>
|
||||
#include <arch/common/ffs.h>
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__)
|
||||
#include <zephyr/types.h>
|
||||
#include <toolchain.h>
|
||||
#include <arch/common/sys_bitops.h>
|
||||
#include <arch/common/sys_io.h>
|
||||
#include <arch/common/ffs.h>
|
||||
#include <sw_isr_table.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue