summaryrefslogtreecommitdiff
path: root/include/common
diff options
context:
space:
mode:
authorDimitris Papastamos <dimitris.papastamos@arm.com>2018-10-04 16:46:53 +0100
committerGitHub <noreply@github.com>2018-10-04 16:46:53 +0100
commit5634a493e7182d0f8abd184a7fe23d0182545b84 (patch)
treed68dc7a0dbf1505bee6084ae222f53ef4ef3b9d9 /include/common
parent68e0fca13926defe9ffa42ead330e68c89b38040 (diff)
parent81542c00d0d3d0609cfedf91f8d6f455672af684 (diff)
Merge pull request #1611 from antonio-nino-diaz-arm/an/misra-common
Remove some MISRA defects in common code
Diffstat (limited to 'include/common')
-rw-r--r--include/common/bl_common.h52
-rw-r--r--include/common/fdt_wrappers.h2
-rw-r--r--include/common/runtime_svc.h53
3 files changed, 57 insertions, 50 deletions
diff --git a/include/common/bl_common.h b/include/common/bl_common.h
index bfe1d8c8..af598d0d 100644
--- a/include/common/bl_common.h
+++ b/include/common/bl_common.h
@@ -11,26 +11,26 @@
#include <param_header.h>
#include <utils_def.h>
-#define UP 1
-#define DOWN 0
+#define UP U(1)
+#define DOWN U(0)
/*******************************************************************************
* Constants to identify the location of a memory region in a given memory
* layout.
******************************************************************************/
-#define TOP 0x1
-#define BOTTOM !TOP
+#define TOP U(0x1)
+#define BOTTOM U(0x0)
/*
* The following are used for image state attributes.
* Image can only be in one of the following state.
*/
-#define IMAGE_STATE_RESET 0
-#define IMAGE_STATE_COPIED 1
-#define IMAGE_STATE_COPYING 2
-#define IMAGE_STATE_AUTHENTICATED 3
-#define IMAGE_STATE_EXECUTED 4
-#define IMAGE_STATE_INTERRUPTED 5
+#define IMAGE_STATE_RESET U(0)
+#define IMAGE_STATE_COPIED U(1)
+#define IMAGE_STATE_COPYING U(2)
+#define IMAGE_STATE_AUTHENTICATED U(3)
+#define IMAGE_STATE_EXECUTED U(4)
+#define IMAGE_STATE_INTERRUPTED U(5)
#define IMAGE_ATTRIB_SKIP_LOADING U(0x02)
#define IMAGE_ATTRIB_PLAT_SETUP U(0x04)
@@ -40,22 +40,22 @@
/*******************************************************************************
* Constants to indicate type of exception to the common exception handler.
******************************************************************************/
-#define SYNC_EXCEPTION_SP_EL0 0x0
-#define IRQ_SP_EL0 0x1
-#define FIQ_SP_EL0 0x2
-#define SERROR_SP_EL0 0x3
-#define SYNC_EXCEPTION_SP_ELX 0x4
-#define IRQ_SP_ELX 0x5
-#define FIQ_SP_ELX 0x6
-#define SERROR_SP_ELX 0x7
-#define SYNC_EXCEPTION_AARCH64 0x8
-#define IRQ_AARCH64 0x9
-#define FIQ_AARCH64 0xa
-#define SERROR_AARCH64 0xb
-#define SYNC_EXCEPTION_AARCH32 0xc
-#define IRQ_AARCH32 0xd
-#define FIQ_AARCH32 0xe
-#define SERROR_AARCH32 0xf
+#define SYNC_EXCEPTION_SP_EL0 U(0x0)
+#define IRQ_SP_EL0 U(0x1)
+#define FIQ_SP_EL0 U(0x2)
+#define SERROR_SP_EL0 U(0x3)
+#define SYNC_EXCEPTION_SP_ELX U(0x4)
+#define IRQ_SP_ELX U(0x5)
+#define FIQ_SP_ELX U(0x6)
+#define SERROR_SP_ELX U(0x7)
+#define SYNC_EXCEPTION_AARCH64 U(0x8)
+#define IRQ_AARCH64 U(0x9)
+#define FIQ_AARCH64 U(0xa)
+#define SERROR_AARCH64 U(0xb)
+#define SYNC_EXCEPTION_AARCH32 U(0xc)
+#define IRQ_AARCH32 U(0xd)
+#define FIQ_AARCH32 U(0xe)
+#define SERROR_AARCH32 U(0xf)
#ifndef __ASSEMBLY__
#include <cassert.h>
diff --git a/include/common/fdt_wrappers.h b/include/common/fdt_wrappers.h
index 18a6d103..3eae944e 100644
--- a/include/common/fdt_wrappers.h
+++ b/include/common/fdt_wrappers.h
@@ -10,7 +10,7 @@
#define __FDT_WRAPPERS__
/* Number of cells, given total length in bytes. Each cell is 4 bytes long */
-#define NCELLS(len) ((len) / 4)
+#define NCELLS(len) ((len) / 4U)
int fdtw_read_cells(const void *dtb, int node, const char *prop,
unsigned int cells, void *value);
diff --git a/include/common/runtime_svc.h b/include/common/runtime_svc.h
index b8cf8ded..6fe0a941 100644
--- a/include/common/runtime_svc.h
+++ b/include/common/runtime_svc.h
@@ -21,15 +21,15 @@
* descriptor
*/
#ifdef AARCH32
-#define RT_SVC_SIZE_LOG2 4
-#define RT_SVC_DESC_INIT 8
-#define RT_SVC_DESC_HANDLE 12
+#define RT_SVC_SIZE_LOG2 U(4)
+#define RT_SVC_DESC_INIT U(8)
+#define RT_SVC_DESC_HANDLE U(12)
#else
-#define RT_SVC_SIZE_LOG2 5
-#define RT_SVC_DESC_INIT 16
-#define RT_SVC_DESC_HANDLE 24
+#define RT_SVC_SIZE_LOG2 U(5)
+#define RT_SVC_DESC_INIT U(16)
+#define RT_SVC_DESC_HANDLE U(24)
#endif /* AARCH32 */
-#define SIZEOF_RT_SVC_DESC (1 << RT_SVC_SIZE_LOG2)
+#define SIZEOF_RT_SVC_DESC (U(1) << RT_SVC_SIZE_LOG2)
/*
@@ -43,9 +43,9 @@
* handler and so the total number of runtime services is 32.
*/
#if SMCCC_MAJOR_VERSION == 1
-#define MAX_RT_SVCS 128
+#define MAX_RT_SVCS U(128)
#elif SMCCC_MAJOR_VERSION == 2
-#define MAX_RT_SVCS 32
+#define MAX_RT_SVCS U(32)
#endif
#ifndef __ASSEMBLY__
@@ -146,35 +146,42 @@ CASSERT(RT_SVC_DESC_HANDLE == __builtin_offsetof(rt_svc_desc_t, handle), \
#if SMCCC_MAJOR_VERSION == 1
/*
- * This macro combines the call type and the owning entity number corresponding
- * to a runtime service to generate a unique owning entity number. This unique
- * oen is used to access an entry in the 'rt_svc_descs_indices' array. The entry
- * contains the index of the service descriptor in the 'rt_svc_descs' array.
+ * This function combines the call type and the owning entity number
+ * corresponding to a runtime service to generate a unique owning entity number.
+ * This unique oen is used to access an entry in the 'rt_svc_descs_indices'
+ * array. The entry contains the index of the service descriptor in the
+ * 'rt_svc_descs' array.
*/
-#define get_unique_oen(oen, call_type) \
- (((uint32_t)(oen) & FUNCID_OEN_MASK) | \
- (((uint32_t)(call_type) & FUNCID_TYPE_MASK) << FUNCID_OEN_WIDTH))
+static inline uint32_t get_unique_oen(uint32_t oen, uint32_t call_type)
+{
+ return ((call_type & FUNCID_TYPE_MASK) << FUNCID_OEN_WIDTH) |
+ (oen & FUNCID_OEN_MASK);
+}
/*
- * This macro generates the unique owning entity number from the SMC Function
+ * This function generates the unique owning entity number from the SMC Function
* ID. This unique oen is used to access an entry in the 'rt_svc_descs_indices'
* array to invoke the corresponding runtime service handler during SMC
* handling.
*/
-#define get_unique_oen_from_smc_fid(fid) \
- get_unique_oen(GET_SMC_OEN(fid), GET_SMC_TYPE(fid))
+static inline uint32_t get_unique_oen_from_smc_fid(uint32_t fid)
+{
+ return get_unique_oen(GET_SMC_OEN(fid), GET_SMC_TYPE(fid));
+}
#elif SMCCC_MAJOR_VERSION == 2
/*
- * This macro combines the owning entity number corresponding to a runtime
+ * This function combines the owning entity number corresponding to a runtime
* service with one extra bit for the vendor namespace to generate an index into
* the 'rt_svc_descs_indices' array. The entry contains the index of the service
* descriptor in the 'rt_svc_descs' array.
*/
-#define get_rt_desc_idx(oen, is_vendor) \
- (((uint32_t)(oen) & FUNCID_OEN_MASK) | \
- (((uint32_t)(is_vendor) & 1U) << FUNCID_OEN_WIDTH))
+static inline uint32_t get_rt_desc_idx(uint32_t oen, uint32_t is_vendor)
+{
+ return ((is_vendor & 1U) << FUNCID_OEN_WIDTH) |
+ (oen & FUNCID_OEN_MASK);
+}
#endif