From ebe51e26cbcf3c4041dfd253a9aa09756d1fbf21 Mon Sep 17 00:00:00 2001 From: Eugeniy Paltsev Date: Mon, 20 Jul 2020 23:43:25 +0300 Subject: [PATCH] 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 --- include/arch/arm/aarch32/arch.h | 1 + include/arch/common/sys_bitops.h | 116 ++++++++++++++++++++++++++++ include/arch/common/sys_io.h | 92 +--------------------- include/arch/nios2/arch.h | 1 + include/arch/posix/asm_inline_gcc.h | 1 + include/arch/riscv/arch.h | 1 + include/arch/xtensa/arch.h | 1 + 7 files changed, 122 insertions(+), 91 deletions(-) create mode 100644 include/arch/common/sys_bitops.h diff --git a/include/arch/arm/aarch32/arch.h b/include/arch/arm/aarch32/arch.h index b63bed08c98..d05c6daa6e4 100644 --- a/include/arch/arm/aarch32/arch.h +++ b/include/arch/arm/aarch32/arch.h @@ -35,6 +35,7 @@ #ifdef CONFIG_CPU_CORTEX_M #include #include +#include #include #elif defined(CONFIG_CPU_CORTEX_R) #include diff --git a/include/arch/common/sys_bitops.h b/include/arch/common/sys_bitops.h new file mode 100644 index 00000000000..04940569d28 --- /dev/null +++ b/include/arch/common/sys_bitops.h @@ -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 +#include +#include + +#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_ */ diff --git a/include/arch/common/sys_io.h b/include/arch/common/sys_io.h index 4e1f20b528b..d40a639a705 100644 --- a/include/arch/common/sys_io.h +++ b/include/arch/common/sys_io.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 diff --git a/include/arch/nios2/arch.h b/include/arch/nios2/arch.h index 76bf1582085..13473007ef6 100644 --- a/include/arch/nios2/arch.h +++ b/include/arch/nios2/arch.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/include/arch/posix/asm_inline_gcc.h b/include/arch/posix/asm_inline_gcc.h index 1853bb6d608..1d353d17a3d 100644 --- a/include/arch/posix/asm_inline_gcc.h +++ b/include/arch/posix/asm_inline_gcc.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include diff --git a/include/arch/riscv/arch.h b/include/arch/riscv/arch.h index 17284b430f4..c2880dcdf29 100644 --- a/include/arch/riscv/arch.h +++ b/include/arch/riscv/arch.h @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/include/arch/xtensa/arch.h b/include/arch/xtensa/arch.h index 4f6601fcc48..93f5f50100b 100644 --- a/include/arch/xtensa/arch.h +++ b/include/arch/xtensa/arch.h @@ -19,6 +19,7 @@ #if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) #include #include +#include #include #include #include