feat(lib/realm): modify struct granule
This patch makes the following changes:
- val of spinlock_t type changes from unsigned int
to unsigned char;
- 'enum granule_state' removed and replaced with
macro definitions;
- type of 'struct granule' state changed to unsigned char;
- type of 'struct granule' refcount changed from unsigned long
to unsigned short, as its maximum value cannot exceed 512.
- 'refcount' access functions modified to use 16-bit values.
These modifications change the size of 'struct granule' from
16 to 4 bytes and reduce the total size of 'granules[]'
array from 16MB to 4MB for default RMM_MAX_GRANULES = 0x100000.
Change-Id: I611ed3f349806b033e03c52c5f60a0f903f93e11
Signed-off-by: AlexeiFedorov <Alexei.Fedorov@arm.com>
diff --git a/lib/arch/include/fake_host/atomics.h b/lib/arch/include/fake_host/atomics.h
index fd555e3..b923e38 100644
--- a/lib/arch/include/fake_host/atomics.h
+++ b/lib/arch/include/fake_host/atomics.h
@@ -12,7 +12,7 @@
/*
* Atomically adds @val to the 64-bit value stored at memory location @loc.
*/
-static inline void atomic_add_64(uint64_t *loc, long val)
+static inline void atomic_add_64(uint64_t *loc, uint64_t val)
{
*loc = *loc + val;
}
@@ -22,9 +22,30 @@
* Stores to memory with release semantics.
* Returns the old value.
*/
-static inline unsigned long atomic_load_add_release_64(uint64_t *loc, long val)
+static inline uint64_t atomic_load_add_release_64(uint64_t *loc, uint64_t val)
{
- unsigned long old_val = *loc;
+ uint64_t old_val = *loc;
+
+ *loc = *loc + val;
+ return old_val;
+}
+
+/*
+ * Atomically adds @val to the 16-bit value stored at memory location @loc.
+ */
+static inline void atomic_add_16(uint16_t *loc, uint16_t val)
+{
+ *loc = *loc + val;
+}
+
+/*
+ * Atomically adds @val to the 16-bit value stored at memory location @loc.
+ * Stores to memory with release semantics.
+ * Returns the old value.
+ */
+static inline uint16_t atomic_load_add_release_16(uint16_t *loc, uint16_t val)
+{
+ uint16_t old_val = *loc;
*loc = *loc + val;
return old_val;
@@ -69,7 +90,7 @@
static inline bool atomic_bit_set_acquire_release_64(uint64_t *loc, unsigned int bit)
{
uint64_t mask = (1UL << bit);
- unsigned long old_val = *loc & mask;
+ uint16_t old_val = *loc & mask;
*loc |= mask;
return (old_val != 0UL);
diff --git a/lib/arch/include/fake_host/memory.h b/lib/arch/include/fake_host/memory.h
index 3f182a4..645f5d2 100644
--- a/lib/arch/include/fake_host/memory.h
+++ b/lib/arch/include/fake_host/memory.h
@@ -37,4 +37,19 @@
}
#define SCA_READ64_ACQUIRE(_p) ((typeof(*(_p)))__sca_read64_acquire((uint64_t *)(_p)))
+/* Single-Copy Atomic 16-bit read */
+static inline uint16_t __sca_read16(uint16_t *ptr)
+{
+ return *ptr;
+}
+#define SCA_READ16(_p) ((typeof(*(_p)))__sca_read16((uint16_t *)(_p)))
+
+/* Single-Copy Atomic 16-bit read with ACQUIRE memory ordering semantics */
+static inline uint16_t __sca_read16_acquire(uint16_t *ptr)
+{
+ return *ptr;
+}
+#define SCA_READ16_ACQUIRE(_p) ((typeof(*(_p)))__sca_read16_acquire((uint16_t *)(_p)))
+
+
#endif /* MEMORY_H */
diff --git a/lib/arch/include/fake_host/spinlock.h b/lib/arch/include/fake_host/spinlock.h
index 7aa4b29..e279825 100644
--- a/lib/arch/include/fake_host/spinlock.h
+++ b/lib/arch/include/fake_host/spinlock.h
@@ -22,4 +22,18 @@
host_spinlock_release(l);
}
+typedef struct byte_spinlock_s {
+ unsigned char val;
+} byte_spinlock_t;
+
+static inline void byte_spinlock_acquire(byte_spinlock_t *l)
+{
+ host_byte_spinlock_acquire(l);
+}
+
+static inline void byte_spinlock_release(byte_spinlock_t *l)
+{
+ host_byte_spinlock_release(l);
+}
+
#endif /* SPINLOCK_H */