sys_bitfield*(): use 'void *' instead of memaddr_t
Current users of sys_bitfield*() are bending over backwards to cast what is most of the times a pointer into an integer. Bitfields can be better described with an void *, so uint{8,16,32,64}_t or any other container can be used. Most sys_bitfield*() operations, by extension, can do the same. Note void * has byte arithmetic, like char *. This change will also make it implicit, for any future split of the address space between virtual (what the SW is seeing) and physical (what the HW is seeing) way clearer, as the functions dealing with physical, non directly referentiable/mappeable addreses to use an integer type, like mem_addr_t. - include/arch/ARCH/*asm_inline*: - sys_bitfield*() all modified to take 'void *' Note 'void *' arihtmethic is byte based, which makes some things easier. - include/sys_io.h: - introduces DEFINE_BITFIELD - update docs - tests/kernel/bitfield: remove all the cast contortions, use DEFINE_BITFIELD PENDING: update other TCs - include/arch/nios/nios2.h, drivers/interrupt_controller/ioapic_intr.c: remove cast contortions Change-Id: I901e62c76af46f26ff0d29cdc37099597f884511 Jira: ZEP-1347 Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
This commit is contained in:
parent
e86c503185
commit
1f2ee5c6bc
9 changed files with 148 additions and 79 deletions
|
@ -266,29 +266,37 @@ static ALWAYS_INLINE
|
|||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
void sys_bitfield_set_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
/* Doing memory offsets in terms of 32-bit values to prevent
|
||||
* alignment issues
|
||||
* alignment issues. The 4 * is needed because void *
|
||||
* arithmethic is byte based and by dividing by 32, we have
|
||||
* the index of the four-byte block where the bit is.
|
||||
*/
|
||||
sys_set_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
sys_set_bit(_addr + 4 * (bit / 32), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
void sys_bitfield_clear_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
sys_clear_bit(_addr + 4 * (bit / 32), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
return sys_test_bit(_addr + 4 * (bit / 32), bit & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_and_set_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -299,7 +307,7 @@ static ALWAYS_INLINE
|
|||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_and_clear_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
|
|
@ -143,29 +143,36 @@ static ALWAYS_INLINE
|
|||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
void sys_bitfield_set_bit(void *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);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
sys_set_bit(_addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
void sys_bitfield_clear_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
sys_clear_bit(_addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_bit(const void *addr, unsigned int bit)
|
||||
{
|
||||
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
return sys_test_bit(_addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_and_set_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -176,7 +183,7 @@ static ALWAYS_INLINE
|
|||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_and_clear_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
|
|
@ -85,29 +85,35 @@ static ALWAYS_INLINE
|
|||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
void sys_bitfield_set_bit(void *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);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
sys_set_bit(_addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
void sys_bitfield_clear_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
sys_clear_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
sys_clear_bit(_addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
return sys_test_bit(addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
return sys_test_bit(_addr + ((bit >> 5) << 2), bit & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_set_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_and_set_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
@ -118,7 +124,7 @@ static ALWAYS_INLINE
|
|||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_clear_bit(mem_addr_t addr, unsigned int bit)
|
||||
int sys_bitfield_test_and_clear_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
|
|
@ -474,11 +474,51 @@ static ALWAYS_INLINE
|
|||
return ret;
|
||||
}
|
||||
|
||||
#define sys_bitfield_set_bit sys_set_bit
|
||||
#define sys_bitfield_clear_bit sys_clear_bit
|
||||
#define sys_bitfield_test_bit sys_test_bit
|
||||
#define sys_bitfield_test_and_set_bit sys_test_and_set_bit
|
||||
#define sys_bitfield_test_and_clear_bit sys_test_and_clear_bit
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_set_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
mem_addr_t _addr = (unsigned long) addr;
|
||||
|
||||
/* Doing memory offsets in terms of 32-bit values to prevent
|
||||
* alignment issues. The 4 * is needed because void *
|
||||
* arithmethic is byte based and by dividing by 32, we have
|
||||
* the index of the four-byte block where the bit is.
|
||||
*/
|
||||
sys_set_bit(_addr + 4 * (bit / 32), bit & 0x1F);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
void sys_bitfield_clear_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
sys_clear_bit((unsigned long) addr, bit);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_bit(void *addr, unsigned int bit)
|
||||
{
|
||||
return sys_test_bit((mem_addr_t) addr, bit);
|
||||
}
|
||||
|
||||
|
||||
static ALWAYS_INLINE
|
||||
int sys_bitfield_test_and_set_bit(void *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(void *addr, unsigned int bit)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sys_bitfield_test_bit(addr, bit);
|
||||
sys_bitfield_clear_bit(addr, bit);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* _ASMLANGUAGE */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue