refactor: use bitfields for interrupt_descriptor struct
To remove the use of hardcoded values when setting the
attributes of the type_config_sec_state field in the
interrupt_descriptor, use bitfields so each field can
be set individually. This reduces the need for get and
set functions so remove them and just access the fields
in the struct directly.
Signed-off-by: Daniel Boulby <daniel.boulby@arm.com>
Change-Id: I66d2f292e4f64f654516649094f158f50625375f
diff --git a/inc/hf/interrupt_desc.h b/inc/hf/interrupt_desc.h
index b97bfb0..03d32fc 100644
--- a/inc/hf/interrupt_desc.h
+++ b/inc/hf/interrupt_desc.h
@@ -52,12 +52,6 @@
}
/**
- * Legal values to change the security state of an interrupt.
- */
-#define INT_SEC_STATE_NS 0
-#define INT_SEC_STATE_S 1
-
-/**
* Legal values to enable or disable an interrupt through the
* `INT_RECONFIGURE_ENABLE` command using the `HF_INTERRUPT_RECONFIGURE`
* paravirtualized interface.
@@ -66,16 +60,6 @@
#define INT_ENABLE 1
/**
- * Attributes encoding in the manifest:
-
- * Field Bit(s)
- * ---------------------------
- * Priority 7:0
- * Security_State 8
- * Config(Edge/Level) 9
- * Type(SPI/PPI/SGI) 11:10
- * Reserved 31:12
- *
* Implementation defined Encodings for various fields:
*
* Security_State:
@@ -91,140 +75,23 @@
* - SGI: 0b00
*
*/
+#define INT_DESC_SEC_STATE_NS 0
+#define INT_DESC_SEC_STATE_S 1
#define INT_DESC_TYPE_SPI 2
#define INT_DESC_TYPE_PPI 1
#define INT_DESC_TYPE_SGI 0
-/** Interrupt Descriptor field masks and shifts. */
-
-#define INT_DESC_PRIORITY_SHIFT 0
-#define INT_DESC_SEC_STATE_SHIFT 8
-#define INT_DESC_CONFIG_SHIFT 9
-#define INT_DESC_TYPE_SHIFT 10
-
struct interrupt_descriptor {
uint32_t interrupt_id;
- /**
- * Bit fields Position
- * ---------------------
- * reserved: 7:4
- * type: 3:2
- * config: 1
- * sec_state: 0
- */
- uint8_t type_config_sec_state;
+ uint8_t res : 4;
+ uint8_t type : 2;
+ uint8_t config : 1;
+ uint8_t sec_state : 1;
uint8_t priority;
bool valid;
bool mpidr_valid;
uint64_t mpidr;
bool enabled;
};
-
-/**
- * Helper APIs for accessing interrupt_descriptor member variables.
- */
-static inline uint32_t interrupt_desc_get_id(
- struct interrupt_descriptor int_desc)
-{
- return int_desc.interrupt_id;
-}
-
-static inline uint8_t interrupt_desc_get_sec_state(
- struct interrupt_descriptor int_desc)
-{
- return ((int_desc.type_config_sec_state >> 0) & 1U);
-}
-
-static inline uint8_t interrupt_desc_get_config(
- struct interrupt_descriptor int_desc)
-{
- return ((int_desc.type_config_sec_state >> 1) & 1U);
-}
-
-static inline uint8_t interrupt_desc_get_type(
- struct interrupt_descriptor int_desc)
-{
- return ((int_desc.type_config_sec_state >> 2) & 3U);
-}
-
-static inline uint8_t interrupt_desc_get_priority(
- struct interrupt_descriptor int_desc)
-{
- return int_desc.priority;
-}
-
-static inline uint64_t interrupt_desc_get_mpidr(
- struct interrupt_descriptor int_desc)
-{
- return int_desc.mpidr;
-}
-
-static inline bool interrupt_desc_get_mpidr_valid(
- struct interrupt_descriptor int_desc)
-{
- return int_desc.mpidr_valid;
-}
-
-static inline bool interrupt_desc_get_valid(
- struct interrupt_descriptor int_desc)
-{
- return int_desc.valid;
-}
-
-static inline void interrupt_desc_set_id(struct interrupt_descriptor *int_desc,
- uint32_t interrupt_id)
-{
- int_desc->interrupt_id = interrupt_id;
-}
-
-static inline void interrupt_desc_set_mpidr(
- struct interrupt_descriptor *int_desc, uint64_t mpidr)
-{
- int_desc->mpidr_valid = true;
- int_desc->mpidr = mpidr;
-}
-
-static inline void interrupt_desc_set_mpidr_invalid(
- struct interrupt_descriptor *int_desc)
-{
- int_desc->mpidr_valid = false;
- int_desc->mpidr = 0;
-}
-
-static inline void interrupt_desc_set_type_config_sec_state(
- struct interrupt_descriptor *int_desc, uint8_t value)
-{
- int_desc->type_config_sec_state = value;
-}
-
-static inline void interrupt_desc_set_sec_state(
- struct interrupt_descriptor *int_desc, uint8_t value)
-{
- /*
- * Note that the type_config_sec_state field is 8 bit wide. Modify only
- * the bit[0] of the type_config_sec_state field as it represents the
- * security state of the interrupt.
- */
- int_desc->type_config_sec_state =
- (int_desc->type_config_sec_state & 0xFE) | (value & 0x1);
-}
-
-static inline void interrupt_desc_set_priority(
- struct interrupt_descriptor *int_desc, uint8_t priority)
-{
- int_desc->priority = priority;
-}
-
-static inline void interrupt_desc_set_valid(
- struct interrupt_descriptor *int_desc, bool valid)
-{
- int_desc->valid = valid;
-}
-
-static inline void interrupt_desc_set_enabled(
- struct interrupt_descriptor *int_desc, bool enable)
-{
- int_desc->enabled = enable;
-}