Skip to content

Commit

Permalink
Merge "fix(rmm): fix MISRA C 2012 violations" into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
soby-mathew authored and TrustedFirmware Code Review committed Dec 11, 2023
2 parents ff10c06 + 0e37813 commit e0fc446
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 91 deletions.
18 changes: 9 additions & 9 deletions lib/arch/include/simd.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
* Z register.
*/
#define SVE_Z_REG_MIN_SIZE U(16)
#define SVE_P_REG_MIN_SIZE (SVE_Z_REG_MIN_SIZE / 8)
#define SVE_FFR_REG_MIN_SIZE (SVE_Z_REG_MIN_SIZE / 8)
#define SVE_P_REG_MIN_SIZE (SVE_Z_REG_MIN_SIZE / 8U)
#define SVE_FFR_REG_MIN_SIZE (SVE_Z_REG_MIN_SIZE / 8U)

/* Number of Z, P, FFR registers */
#define SVE_Z_REG_NUM U(32)
#define SVE_P_REG_NUM U(16)
#define SVE_FFR_REG_NUM U(1)

#define SVE_Z_REGS_SIZE(vq) (((vq) + 1) * (SVE_Z_REG_MIN_SIZE * SVE_Z_REG_NUM))
#define SVE_P_REGS_SIZE(vq) (((vq) + 1) * (SVE_P_REG_MIN_SIZE * SVE_P_REG_NUM))
#define SVE_FFR_REGS_SIZE(vq) (((vq) + 1) * (SVE_FFR_REG_MIN_SIZE * \
#define SVE_Z_REGS_SIZE(vq) (((vq) + 1U) * (SVE_Z_REG_MIN_SIZE * SVE_Z_REG_NUM))
#define SVE_P_REGS_SIZE(vq) (((vq) + 1U) * (SVE_P_REG_MIN_SIZE * SVE_P_REG_NUM))
#define SVE_FFR_REGS_SIZE(vq) (((vq) + 1U) * (SVE_FFR_REG_MIN_SIZE * \
SVE_FFR_REG_NUM))

/* SVE vq architecture limit */
Expand Down Expand Up @@ -178,10 +178,10 @@ struct simd_context {
* TODO: Auto generate header file simd-asm-offsets.h during build and use it
* in assembly routines.
*/
COMPILER_ASSERT(offsetof(struct fpu_regs, q) == (size_t)FPU_REGS_OFFSET_Q);
COMPILER_ASSERT(offsetof(struct sve_regs, z) == (size_t)SVE_REGS_OFFSET_Z);
COMPILER_ASSERT(offsetof(struct sve_regs, p) == (size_t)SVE_REGS_OFFSET_P);
COMPILER_ASSERT(offsetof(struct sve_regs, ffr) == (size_t)SVE_REGS_OFFSET_FFR);
COMPILER_ASSERT((U(offsetof(struct fpu_regs, q))) == FPU_REGS_OFFSET_Q);
COMPILER_ASSERT((U(offsetof(struct sve_regs, z))) == SVE_REGS_OFFSET_Z);
COMPILER_ASSERT((U(offsetof(struct sve_regs, p))) == SVE_REGS_OFFSET_P);
COMPILER_ASSERT((U(offsetof(struct sve_regs, ffr))) == SVE_REGS_OFFSET_FFR);

/* Initialize SIMD layer based on CPU support for FPU or SVE */
void simd_init(void);
Expand Down
36 changes: 18 additions & 18 deletions lib/measurement/include/measurement.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ struct measurement_desc_data {
*/
SET_MEMBER(unsigned char content[MAX_MEASUREMENT_SIZE], 0x60, 0x100);
};
COMPILER_ASSERT(sizeof(struct measurement_desc_data) == 0x100);
COMPILER_ASSERT(sizeof(struct measurement_desc_data) == 0x100UL);

COMPILER_ASSERT(offsetof(struct measurement_desc_data, desc_type) == 0x0);
COMPILER_ASSERT(offsetof(struct measurement_desc_data, len) == 0x8);
COMPILER_ASSERT(offsetof(struct measurement_desc_data, rim) == 0x10);
COMPILER_ASSERT(offsetof(struct measurement_desc_data, ipa) == 0x50);
COMPILER_ASSERT(offsetof(struct measurement_desc_data, flags) == 0x58);
COMPILER_ASSERT(offsetof(struct measurement_desc_data, content) == 0x60);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_data, desc_type)) == 0x0U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_data, len)) == 0x8U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_data, rim)) == 0x10U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_data, ipa)) == 0x50U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_data, flags)) == 0x58U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_data, content)) == 0x60U);

/* RmmMeasurementDescriptorRec type as per RMM spec */
struct measurement_desc_rec {
Expand All @@ -85,12 +85,12 @@ struct measurement_desc_rec {
/* Hash of 4KB page which contains REC parameters data structure */
SET_MEMBER(unsigned char content[MAX_MEASUREMENT_SIZE], 0x50, 0x100);
};
COMPILER_ASSERT(sizeof(struct measurement_desc_rec) == 0x100);
COMPILER_ASSERT(sizeof(struct measurement_desc_rec) == 0x100UL);

COMPILER_ASSERT(offsetof(struct measurement_desc_rec, desc_type) == 0x0);
COMPILER_ASSERT(offsetof(struct measurement_desc_rec, len) == 0x8);
COMPILER_ASSERT(offsetof(struct measurement_desc_rec, rim) == 0x10);
COMPILER_ASSERT(offsetof(struct measurement_desc_rec, content) == 0x50);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_rec, desc_type)) == 0x0U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_rec, len)) == 0x8U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_rec, rim)) == 0x10U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_rec, content)) == 0x50U);

/* RmmMeasurementDescriptorRipas type as per RMM spec */
struct measurement_desc_ripas {
Expand All @@ -105,13 +105,13 @@ struct measurement_desc_ripas {
/* Top IPA at which the RIPAS change occurred */
SET_MEMBER(unsigned long top, 0x58, 0x100);
};
COMPILER_ASSERT(sizeof(struct measurement_desc_ripas) == 0x100);
COMPILER_ASSERT(sizeof(struct measurement_desc_ripas) == 0x100UL);

COMPILER_ASSERT(offsetof(struct measurement_desc_ripas, desc_type) == 0x0);
COMPILER_ASSERT(offsetof(struct measurement_desc_ripas, len) == 0x8);
COMPILER_ASSERT(offsetof(struct measurement_desc_ripas, rim) == 0x10);
COMPILER_ASSERT(offsetof(struct measurement_desc_ripas, base) == 0x50);
COMPILER_ASSERT(offsetof(struct measurement_desc_ripas, top) == 0x58);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_ripas, desc_type)) == 0x0U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_ripas, len)) == 0x8U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_ripas, rim)) == 0x10U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_ripas, base)) == 0x50U);
COMPILER_ASSERT(U(offsetof(struct measurement_desc_ripas, top)) == 0x58U);

/*
* Calculate the hash of data with algorithm hash_algo to the buffer `out`.
Expand Down
2 changes: 1 addition & 1 deletion lib/realm/include/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum buffer_slot {
* If the max aux granules is 0, no slots will
* be reserved.
*/
SLOT_RTT = SLOT_REC_AUX0 + MAX_REC_AUX_GRANULES,
SLOT_RTT = U(SLOT_REC_AUX0) + MAX_REC_AUX_GRANULES,
SLOT_RTT2, /* Some commands access two RTT granules at a time*/
SLOT_RSI_CALL,
NR_CPU_SLOTS
Expand Down
4 changes: 2 additions & 2 deletions lib/realm/src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <xlat_high_va.h>
#include <xlat_tables.h>

COMPILER_ASSERT(XLAT_HIGH_VA_SLOT_NUM >= NR_CPU_SLOTS);
COMPILER_ASSERT(XLAT_HIGH_VA_SLOT_NUM >= U(NR_CPU_SLOTS));

/* coverity[misra_c_2012_rule_8_7_violation:SUPPRESS] */
uintptr_t slot_to_va(enum buffer_slot slot)
Expand Down Expand Up @@ -86,7 +86,7 @@ bool check_cpu_slots_empty(void)
{
for (unsigned int i = 0U; i < (unsigned int)NR_CPU_SLOTS; i++) {
if (slot_to_descriptor((enum buffer_slot)i) !=
TRANSIENT_DESC) {
TRANSIENT_DESC) {
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/rmm_el3_ifc/include/rmm_el3_ifc.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ struct rmm_core_manifest {
struct ns_dram_info plat_dram; /* Platform DRAM data */
};

COMPILER_ASSERT(offsetof(struct rmm_core_manifest, version) == 0);
COMPILER_ASSERT(offsetof(struct rmm_core_manifest, plat_data) == 8);
COMPILER_ASSERT(offsetof(struct rmm_core_manifest, plat_dram) == 16);
COMPILER_ASSERT(U(offsetof(struct rmm_core_manifest, version)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rmm_core_manifest, plat_data)) == 8U);
COMPILER_ASSERT(U(offsetof(struct rmm_core_manifest, plat_dram)) == 16U);

/*
* Accessors to the Boot Manifest data
Expand Down
2 changes: 1 addition & 1 deletion lib/smc/include/smc.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
(IS_SMC32_FID_STD_FAST(_fid) && IS_SMC32_FID_IN_RANGE(_range, _fid))

#define SMC64_NUM_FIDS_IN_RANGE(_range) \
(SMC64_##_range##_FNUM_MAX - SMC64_##_range##_FNUM_MIN + 1)
(SMC64_##_range##_FNUM_MAX - SMC64_##_range##_FNUM_MIN + 1U)

/* Gets the offset in a range. Inputs must be pre-verified */
#define SMC64_FID_OFFSET_FROM_RANGE_MIN(_range, _fid) \
Expand Down
90 changes: 45 additions & 45 deletions lib/smc/src/smc-rmi-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@
#include <smc-rmi.h>
#include <stddef.h>

COMPILER_ASSERT(sizeof(struct rmi_realm_params) == 0x1000);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, flags) == 0);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, s2sz) == 0x8);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, sve_vl) == 0x10);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, num_bps) == 0x18);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, num_wps) == 0x20);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, pmu_num_ctrs) == 0x28);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, algorithm) == 0x30);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, rpv) == 0x400);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, vmid) == 0x800);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, rtt_base) == 0x808);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, rtt_level_start) == 0x810);
COMPILER_ASSERT(offsetof(struct rmi_realm_params, rtt_num_start) == 0x818);
COMPILER_ASSERT(sizeof(struct rmi_realm_params) == 0x1000UL);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, flags)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, s2sz)) == 0x8U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, sve_vl)) == 0x10U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, num_bps)) == 0x18U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, num_wps)) == 0x20U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, pmu_num_ctrs)) == 0x28U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, algorithm)) == 0x30U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, rpv)) == 0x400U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, vmid)) == 0x800U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, rtt_base)) == 0x808U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, rtt_level_start)) == 0x810U);
COMPILER_ASSERT(U(offsetof(struct rmi_realm_params, rtt_num_start)) == 0x818U);

COMPILER_ASSERT(sizeof(struct rmi_rec_params) == 0x1000);
COMPILER_ASSERT(offsetof(struct rmi_rec_params, flags) == 0);
COMPILER_ASSERT(offsetof(struct rmi_rec_params, mpidr) == 0x100);
COMPILER_ASSERT(offsetof(struct rmi_rec_params, pc) == 0x200);
COMPILER_ASSERT(offsetof(struct rmi_rec_params, gprs) == 0x300);
COMPILER_ASSERT(offsetof(struct rmi_rec_params, num_aux) == 0x800);
COMPILER_ASSERT(offsetof(struct rmi_rec_params, aux) == 0x808);
COMPILER_ASSERT(sizeof(struct rmi_rec_params) == 0x1000UL);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_params, flags)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_params, mpidr)) == 0x100U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_params, pc)) == 0x200U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_params, gprs)) == 0x300U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_params, num_aux)) == 0x800U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_params, aux)) == 0x808U);

COMPILER_ASSERT(sizeof(struct rmi_rec_enter) == 0x800);
COMPILER_ASSERT(offsetof(struct rmi_rec_enter, flags) == 0);
COMPILER_ASSERT(offsetof(struct rmi_rec_enter, gprs) == 0x200);
COMPILER_ASSERT(offsetof(struct rmi_rec_enter, gicv3_hcr) == 0x300);
COMPILER_ASSERT(offsetof(struct rmi_rec_enter, gicv3_lrs) == 0x308);
COMPILER_ASSERT(sizeof(struct rmi_rec_enter) == 0x800UL);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_enter, flags)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_enter, gprs)) == 0x200U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_enter, gicv3_hcr)) == 0x300U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_enter, gicv3_lrs)) == 0x308U);

COMPILER_ASSERT(offsetof(struct rmi_rec_exit, exit_reason) == 0);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, esr) == 0x100);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, far) == 0x108);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, hpfar) == 0x110);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, gprs) == 0x200);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, gicv3_hcr) == 0x300);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, gicv3_lrs) == 0x308);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, gicv3_misr) == 0x388);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, gicv3_vmcr) == 0x390);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, cntp_ctl) == 0x400);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, cntp_cval) == 0x408);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, cntv_ctl) == 0x410);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, cntv_cval) == 0x418);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, ripas_base) == 0x500);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, ripas_top) == 0x508);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, ripas_value) == 0x510);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, imm) == 0x600);
COMPILER_ASSERT(offsetof(struct rmi_rec_exit, pmu_ovf_status) == 0x700);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, exit_reason)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, esr)) == 0x100U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, far)) == 0x108U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, hpfar)) == 0x110U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, gprs)) == 0x200U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, gicv3_hcr)) == 0x300U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, gicv3_lrs)) == 0x308U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, gicv3_misr)) == 0x388U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, gicv3_vmcr)) == 0x390U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, cntp_ctl)) == 0x400U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, cntp_cval)) == 0x408U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, cntv_ctl)) == 0x410U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, cntv_cval)) == 0x418U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, ripas_base)) == 0x500U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, ripas_top)) == 0x508U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, ripas_value)) == 0x510U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, imm)) == 0x600U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_exit, pmu_ovf_status)) == 0x700U);

COMPILER_ASSERT(sizeof(struct rmi_rec_run) <= GRANULE_SIZE);
COMPILER_ASSERT(offsetof(struct rmi_rec_run, enter) == 0);
COMPILER_ASSERT(offsetof(struct rmi_rec_run, exit) == 0x800);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_run, enter)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rmi_rec_run, exit)) == 0x800U);
18 changes: 9 additions & 9 deletions lib/smc/src/smc-rsi-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include <stddef.h>
#include <utils_def.h>

COMPILER_ASSERT(sizeof(struct rsi_realm_config) == 0x1000);
COMPILER_ASSERT(offsetof(struct rsi_realm_config, ipa_width) == 0);
COMPILER_ASSERT(offsetof(struct rsi_realm_config, algorithm) == 8);
COMPILER_ASSERT(sizeof(struct rsi_realm_config) == 0x1000UL);
COMPILER_ASSERT(U(offsetof(struct rsi_realm_config, ipa_width)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rsi_realm_config, algorithm)) == 8U);

COMPILER_ASSERT(sizeof(struct rsi_host_call) == 0x100);
COMPILER_ASSERT(offsetof(struct rsi_host_call, imm) == 0);
COMPILER_ASSERT(offsetof(struct rsi_host_call, gprs[0]) == 8);
COMPILER_ASSERT(offsetof(struct rsi_host_call,
gprs[RSI_HOST_CALL_NR_GPRS - 1]) ==
(8UL * RSI_HOST_CALL_NR_GPRS));
COMPILER_ASSERT(sizeof(struct rsi_host_call) == 0x100UL);
COMPILER_ASSERT(U(offsetof(struct rsi_host_call, imm)) == 0U);
COMPILER_ASSERT(U(offsetof(struct rsi_host_call, gprs[0U])) == 8U);
COMPILER_ASSERT(U(offsetof(struct rsi_host_call,
gprs[RSI_HOST_CALL_NR_GPRS - 1U])) ==
U(8U * RSI_HOST_CALL_NR_GPRS));
2 changes: 1 addition & 1 deletion lib/xlat/include/xlat_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
* attributes field as a flag to know if a tte corresponds to a transient
* address or not.
*/
#define TRANSIENT_FLAG_SHIFT U(55)
#define TRANSIENT_FLAG_SHIFT UL(55)
#define TRANSIENT_FLAG_WIDTH U(1)

/*
Expand Down
4 changes: 2 additions & 2 deletions runtime/rmi/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <smc-handler.h>
#include <smc-rmi.h>

COMPILER_ASSERT(RMI_ABI_VERSION_MAJOR <= 0x7FFF);
COMPILER_ASSERT(RMI_ABI_VERSION_MINOR <= 0xFFFF);
COMPILER_ASSERT(RMI_ABI_VERSION_MAJOR <= 0x7FFFUL);
COMPILER_ASSERT(RMI_ABI_VERSION_MINOR <= 0xFFFFUL);

void smc_version(unsigned long rmi_version, struct smc_result *res)
{
Expand Down

0 comments on commit e0fc446

Please sign in to comment.