Commit c1baa7bd authored by Federico Vaga's avatar Federico Vaga Committed by Federico Vaga

rt: add shm type

It adds the shared memory type. This is useful so that the compiler
can detect errors when using the operation function with a wrong
SHM type
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 0cb761a7
...@@ -28,15 +28,30 @@ ...@@ -28,15 +28,30 @@
* @{ * @{
*/ */
#define TRTL_SMEM_RANGE_ADD 0x10000
#define TRTL_SMEM_RANGE_SUB 0x20000
#define TRTL_SMEM_RANGE_SET 0x30000
#define TRTL_SMEM_RANGE_CLEAR 0x40000
#define TRTL_SMEM_RANGE_FLIP 0x50000
#define TRTL_SMEM_RANGE_TEST_AND_SET 0x60000
/**
* List of supported Shared Memory operations
*/
enum trtl_smem_type {
TRTL_SMEM_TYPE_ADD = 1, /**< Atomic addition */
TRTL_SMEM_TYPE_SUB, /**< Atomic subtraction */
TRTL_SMEM_TYPE_SET, /**< Atomic bit set */
TRTL_SMEM_TYPE_CLR, /**< Atomic bit clear */
TRTL_SMEM_TYPE_FLP, /**< Atomic bit flip */
TRTL_SMEM_TYPE_TST_SET, /**< Atomic test and set */
};
/** /**
* It generates the SHM address range for a given SHM operations * It generates the SHM address range for a given SHM operations
*/ */
#define SMEM_RANGE_ADD 0x10000 #define TRTL_SMEM_TYPE_TO_RANGE(_type) ((_type) * 0x10000)
#define SMEM_RANGE_SUB 0x20000
#define SMEM_RANGE_SET 0x30000
#define SMEM_RANGE_CLEAR 0x40000
#define SMEM_RANGE_FLIP 0x50000
#define SMEM_RANGE_TEST_AND_SET 0x60000
/** /**
...@@ -62,9 +77,10 @@ ...@@ -62,9 +77,10 @@
* @param[in] x second operation argument * @param[in] x second operation argument
* @param[in] type operation type * @param[in] type operation type
*/ */
static inline void __smem_atomic_op(volatile int *p, int x, unsigned int type) static inline void __smem_atomic_op(volatile int *p, int x,
enum trtl_smem_type type)
{ {
*(volatile int *)(p + (type >> 2)) = x; *(volatile int *)(p + (TRTL_SMEM_TYPE_TO_RANGE(type) >> 2)) = x;
} }
...@@ -78,7 +94,7 @@ static inline void __smem_atomic_op(volatile int *p, int x, unsigned int type) ...@@ -78,7 +94,7 @@ static inline void __smem_atomic_op(volatile int *p, int x, unsigned int type)
*/ */
static inline void smem_atomic_add(volatile int *p, int x) static inline void smem_atomic_add(volatile int *p, int x)
{ {
__smem_atomic_op(p, x, SMEM_RANGE_ADD); __smem_atomic_op(p, x, TRTL_SMEM_RANGE_ADD);
} }
...@@ -92,7 +108,7 @@ static inline void smem_atomic_add(volatile int *p, int x) ...@@ -92,7 +108,7 @@ static inline void smem_atomic_add(volatile int *p, int x)
*/ */
static inline void smem_atomic_sub(volatile int *p, int x) static inline void smem_atomic_sub(volatile int *p, int x)
{ {
__smem_atomic_op(p, x, SMEM_RANGE_SUB); __smem_atomic_op(p, x, TRTL_SMEM_RANGE_SUB);
} }
...@@ -106,7 +122,7 @@ static inline void smem_atomic_sub(volatile int *p, int x) ...@@ -106,7 +122,7 @@ static inline void smem_atomic_sub(volatile int *p, int x)
*/ */
static inline void smem_atomic_or(volatile int *p, int x) static inline void smem_atomic_or(volatile int *p, int x)
{ {
__smem_atomic_op(p, x, SMEM_RANGE_SET); __smem_atomic_op(p, x, TRTL_SMEM_RANGE_SET);
} }
...@@ -120,7 +136,7 @@ static inline void smem_atomic_or(volatile int *p, int x) ...@@ -120,7 +136,7 @@ static inline void smem_atomic_or(volatile int *p, int x)
*/ */
static inline void smem_atomic_and_not(volatile int *p, int x) static inline void smem_atomic_and_not(volatile int *p, int x)
{ {
__smem_atomic_op(p, x, SMEM_RANGE_CLEAR); __smem_atomic_op(p, x, TRTL_SMEM_RANGE_CLEAR);
} }
...@@ -134,7 +150,7 @@ static inline void smem_atomic_and_not(volatile int *p, int x) ...@@ -134,7 +150,7 @@ static inline void smem_atomic_and_not(volatile int *p, int x)
*/ */
static inline void smem_atomic_xor(int *p, int x) static inline void smem_atomic_xor(int *p, int x)
{ {
__smem_atomic_op(p, x, SMEM_RANGE_FLIP); __smem_atomic_op(p, x, TRTL_SMEM_RANGE_FLIP);
} }
...@@ -155,7 +171,7 @@ static inline void smem_atomic_xor(int *p, int x) ...@@ -155,7 +171,7 @@ static inline void smem_atomic_xor(int *p, int x)
static inline int smem_atomic_test_and_set(int *p) static inline int smem_atomic_test_and_set(int *p)
{ {
/* shift right translates range in bytes into range in words */ /* shift right translates range in bytes into range in words */
return *(volatile int *)(p + (SMEM_RANGE_TEST_AND_SET >> 2)); return *(volatile int *)(p + (TRTL_SMEM_RANGE_TEST_AND_SET >> 2));
} }
/**@}*/ /**@}*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment