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:
Inaky Perez-Gonzalez 2017-01-11 14:49:41 -08:00 committed by Anas Nashif
commit 1f2ee5c6bc
9 changed files with 148 additions and 79 deletions

View file

@ -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 */