refactor: add explicit underlying types to enums
* Set the underlying type of `ffa_error` to `uint32_t`. This reduces the
need for explicit casts in most cases.
* Set the underlying types for other enums to `uint32_t`, where they are
specified as such in the FF-A specification (`ffa_version`,
`ffa_feature_id`, `ffa_mem_perm`, `ffa_framework_msg_func`).
* Set the underlying types of `ffa_data_access`,
`ffa_instruction_access`, `ffa_memory_type`,
`ffa_memory_cacheability`, `ffa_memory_shareability`,
`ffa_memory_security` to `uint8_t`. This allows them to be stored
directly in the `ffa_data_access_t` and `ffa_memory_attributes_t`
structs without increasing their size.
Change-Id: I7da103f7507929ffb2e66914daa3cd9e67186300
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/src/api.c b/src/api.c
index ebb6561..9a183a8 100644
--- a/src/api.c
+++ b/src/api.c
@@ -2408,7 +2408,7 @@
static_assert(sizeof(enum ffa_version) == 4,
"enum ffa_version must be 4 bytes wide");
- const struct ffa_value error = {.func = (uint32_t)FFA_NOT_SUPPORTED};
+ const struct ffa_value error = {.func = FFA_NOT_SUPPORTED};
struct vm_locked current_vm_locked;
uint16_t compiled_major = ffa_version_get_major(FFA_VERSION_COMPILED);
@@ -2456,7 +2456,7 @@
current_vm_locked.vm->ffa_version = requested_version;
vm_unlock(¤t_vm_locked);
- return (struct ffa_value){.func = (uint32_t)FFA_VERSION_COMPILED};
+ return (struct ffa_value){.func = FFA_VERSION_COMPILED};
}
/**
diff --git a/src/arch/aarch64/hftest/power_mgmt.c b/src/arch/aarch64/hftest/power_mgmt.c
index 68a2c33..aefa120 100644
--- a/src/arch/aarch64/hftest/power_mgmt.c
+++ b/src/arch/aarch64/hftest/power_mgmt.c
@@ -46,6 +46,7 @@
}
}
+/* NOLINTBEGIN(readability-redundant-casting) */
static_assert((uint32_t)POWER_STATUS_ON == (uint32_t)PSCI_RETURN_ON,
"power_status enum values must match PSCI return values.");
static_assert((uint32_t)POWER_STATUS_OFF == (uint32_t)PSCI_RETURN_OFF,
@@ -53,6 +54,7 @@
static_assert((uint32_t)POWER_STATUS_ON_PENDING ==
(uint32_t)PSCI_RETURN_ON_PENDING,
"power_status enum values must match PSCI return values.");
+/* NOLINTEND(readability-redundant-casting) */
/**
* Returns the power status of the given CPU.
diff --git a/src/arch/aarch64/inc/hf/arch/vm/power_mgmt.h b/src/arch/aarch64/inc/hf/arch/vm/power_mgmt.h
index 7bf8d4b..e41edf6 100644
--- a/src/arch/aarch64/inc/hf/arch/vm/power_mgmt.h
+++ b/src/arch/aarch64/inc/hf/arch/vm/power_mgmt.h
@@ -13,7 +13,7 @@
#include "hf/arch/types.h"
-enum power_status {
+enum power_status : uint32_t {
POWER_STATUS_ON,
POWER_STATUS_OFF,
POWER_STATUS_ON_PENDING,
diff --git a/src/arch/aarch64/psci.h b/src/arch/aarch64/psci.h
index 55fc17d..c90ec94 100644
--- a/src/arch/aarch64/psci.h
+++ b/src/arch/aarch64/psci.h
@@ -13,7 +13,7 @@
/* clang-format off */
/* The following are PSCI version codes. */
-enum psci_version {
+enum psci_version : uint32_t {
PSCI_VERSION_0_2 = 0x00000002,
PSCI_VERSION_1_0 = 0x00010000,
PSCI_VERSION_1_1 = 0x00010001,
@@ -43,7 +43,7 @@
#define PSCI_MEM_PROTECT_CHECK_RANGE 0x84000014
/* The following are return codes for PSCI. */
-enum psci_return_code {
+enum psci_return_code : uint32_t {
PSCI_RETURN_ON_PENDING = 2,
PSCI_RETURN_OFF = 1,
PSCI_RETURN_ON = 0,
diff --git a/src/ffa/hypervisor/init.c b/src/ffa/hypervisor/init.c
index b87ca54..f9c98e8 100644
--- a/src/ffa/hypervisor/init.c
+++ b/src/ffa/hypervisor/init.c
@@ -66,7 +66,7 @@
*/
ret = arch_other_world_call((struct ffa_value){
.func = FFA_VERSION_32, .arg1 = FFA_VERSION_COMPILED});
- if (ret.func == (uint32_t)FFA_NOT_SUPPORTED) {
+ if (ret.func == FFA_NOT_SUPPORTED) {
panic("Hypervisor and SPMC versions are not compatible.\n");
}