Commit 30a8d96e authored by Jeenu Viswambharan's avatar Jeenu Viswambharan
Browse files

RAS: MISRA fixes



These changes address most of the required MISRA rules. In the process,
some from generic code is also fixed.

No functional changes.

Change-Id: I76cacf6e1d73b09510561b5090c2bb66d81bec88
Signed-off-by: default avatarJeenu Viswambharan <jeenu.viswambharan@arm.com>
parent 03b645ed
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
#ifndef __RAS_COMMON__ #ifndef RAS_COMMON
#define __RAS_COMMON__ #define RAS_COMMON
#define ERR_HANDLER_VERSION 1 #define ERR_HANDLER_VERSION 1U
/* Error record access mechanism */ /* Error record access mechanism */
#define ERR_ACCESS_SYSREG 0 #define ERR_ACCESS_SYSREG 0
...@@ -20,18 +20,18 @@ ...@@ -20,18 +20,18 @@
* are declared. Only then would ARRAY_SIZE() yield a meaningful value. * are declared. Only then would ARRAY_SIZE() yield a meaningful value.
*/ */
#define REGISTER_ERR_RECORD_INFO(_records) \ #define REGISTER_ERR_RECORD_INFO(_records) \
const struct err_record_mapping err_record_mapping = { \ const struct err_record_mapping err_record_mappings = { \
.err_records = _records, \ .err_records = (_records), \
.num_err_records = ARRAY_SIZE(_records), \ .num_err_records = ARRAY_SIZE(_records), \
} }
/* Error record info iterator */ /* Error record info iterator */
#define for_each_err_record_info(_i, _info) \ #define for_each_err_record_info(_i, _info) \
for (_i = 0, _info = err_record_mapping.err_records; \ for ((_i) = 0, (_info) = err_record_mappings.err_records; \
_i < err_record_mapping.num_err_records; \ (_i) < err_record_mappings.num_err_records; \
_i++, _info++) (_i)++, (_info)++)
#define _ERR_RECORD_COMMON(_probe, _handler, _aux) \ #define ERR_RECORD_COMMON_(_probe, _handler, _aux) \
.probe = _probe, \ .probe = _probe, \
.handler = _handler, \ .handler = _handler, \
.aux_data = _aux, .aux_data = _aux,
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
.sysreg.idx_start = _idx_start, \ .sysreg.idx_start = _idx_start, \
.sysreg.num_idx = _num_idx, \ .sysreg.num_idx = _num_idx, \
.access = ERR_ACCESS_SYSREG, \ .access = ERR_ACCESS_SYSREG, \
_ERR_RECORD_COMMON(_probe, _handler, _aux) \ ERR_RECORD_COMMON_(_probe, _handler, _aux) \
} }
#define ERR_RECORD_MEMMAP_V1(_base_addr, _size_num_k, _probe, _handler, _aux) \ #define ERR_RECORD_MEMMAP_V1(_base_addr, _size_num_k, _probe, _handler, _aux) \
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
.memmap.base_addr = _base_addr, \ .memmap.base_addr = _base_addr, \
.memmap.size_num_k = _size_num_k, \ .memmap.size_num_k = _size_num_k, \
.access = ERR_ACCESS_MEMMAP, \ .access = ERR_ACCESS_MEMMAP, \
_ERR_RECORD_COMMON(_probe, _handler, _aux) \ ERR_RECORD_COMMON_(_probe, _handler, _aux) \
} }
/* /*
...@@ -63,8 +63,8 @@ ...@@ -63,8 +63,8 @@
* array is expected to be sorted in the increasing order of interrupt number. * array is expected to be sorted in the increasing order of interrupt number.
*/ */
#define REGISTER_RAS_INTERRUPTS(_array) \ #define REGISTER_RAS_INTERRUPTS(_array) \
const struct ras_interrupt_mapping ras_interrupt_mapping = { \ const struct ras_interrupt_mapping ras_interrupt_mappings = { \
.intrs = _array, \ .intrs = (_array), \
.num_intrs = ARRAY_SIZE(_array), \ .num_intrs = ARRAY_SIZE(_array), \
} }
...@@ -165,8 +165,8 @@ struct ras_interrupt_mapping { ...@@ -165,8 +165,8 @@ struct ras_interrupt_mapping {
size_t num_intrs; size_t num_intrs;
}; };
extern const struct err_record_mapping err_record_mapping; extern const struct err_record_mapping err_record_mappings;
extern const struct ras_interrupt_mapping ras_interrupt_mapping; extern const struct ras_interrupt_mapping ras_interrupt_mappings;
/* /*
...@@ -196,4 +196,4 @@ int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, ...@@ -196,4 +196,4 @@ int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
void ras_init(void); void ras_init(void);
#endif /* __ASSEMBLY__ */ #endif /* __ASSEMBLY__ */
#endif /* __RAS_COMMON__ */ #endif /* RAS_COMMON */
...@@ -11,28 +11,28 @@ ...@@ -11,28 +11,28 @@
* Size of nodes implementing Standard Error Records - currently only 4k is * Size of nodes implementing Standard Error Records - currently only 4k is
* supported. * supported.
*/ */
#define STD_ERR_NODE_SIZE_NUM_K 4 #define STD_ERR_NODE_SIZE_NUM_K 4U
/* /*
* Individual register offsets within an error record in Standard Error Record * Individual register offsets within an error record in Standard Error Record
* format when error records are accessed through memory-mapped registers. * format when error records are accessed through memory-mapped registers.
*/ */
#define ERR_FR(n) (0x0 + (64 * (n))) #define ERR_FR(n) (0x0ULL + (64ULL * (n)))
#define ERR_CTLR(n) (0x8 + (64 * (n))) #define ERR_CTLR(n) (0x8ULL + (64ULL * (n)))
#define ERR_STATUS(n) (0x10 + (64 * (n))) #define ERR_STATUS(n) (0x10ULL + (64ULL * (n)))
#define ERR_ADDR(n) (0x18 + (64 * (n))) #define ERR_ADDR(n) (0x18ULL + (64ULL * (n)))
#define ERR_MISC0(n) (0x20 + (64 * (n))) #define ERR_MISC0(n) (0x20ULL + (64ULL * (n)))
#define ERR_MISC1(n) (0x28 + (64 * (n))) #define ERR_MISC1(n) (0x28ULL + (64ULL * (n)))
/* Group Status Register (ERR_STATUS) offset */ /* Group Status Register (ERR_STATUS) offset */
#define ERR_GSR(base, size_num_k, n) \ #define ERR_GSR(base, size_num_k, n) \
((base) + (0x380 * (size_num_k)) + (8 * (n))) ((base) + (0x380ULL * (size_num_k)) + (8ULL * (n)))
/* Management register offsets */ /* Management register offsets */
#define ERR_DEVID(base, size_num_k) \ #define ERR_DEVID(base, size_num_k) \
((base) + ((0x400 * (size_num_k)) - 0x100) + 0xc8) ((base) + ((0x400ULL * (size_num_k)) - 0x100ULL) + 0xc8ULL)
#define ERR_DEVID_MASK 0xffff #define ERR_DEVID_MASK 0xffffUL
/* Standard Error Record status register fields */ /* Standard Error Record status register fields */
#define ERR_STATUS_AV_SHIFT 31 #define ERR_STATUS_AV_SHIFT 31
...@@ -244,7 +244,8 @@ static inline uint64_t ser_get_misc1(uintptr_t base, unsigned int idx) ...@@ -244,7 +244,8 @@ static inline uint64_t ser_get_misc1(uintptr_t base, unsigned int idx)
*/ */
static inline void ser_sys_select_record(unsigned int idx) static inline void ser_sys_select_record(unsigned int idx)
{ {
unsigned int max_idx __unused = read_erridr_el1() & ERRIDR_MASK; unsigned int max_idx __unused =
(unsigned int) read_erridr_el1() & ERRIDR_MASK;
assert(idx < max_idx); assert(idx < max_idx);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <platform.h> #include <platform.h>
#include <ras.h> #include <ras.h>
#include <ras_arch.h> #include <ras_arch.h>
#include <stdbool.h>
#ifndef PLAT_RAS_PRI #ifndef PLAT_RAS_PRI
# error Platform must define RAS priority value # error Platform must define RAS priority value
...@@ -20,15 +21,15 @@ ...@@ -20,15 +21,15 @@
int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
void *handle, uint64_t flags) void *handle, uint64_t flags)
{ {
unsigned int i, n_handled = 0, ret; unsigned int i, n_handled = 0;
int probe_data; int probe_data, ret;
struct err_record_info *info; struct err_record_info *info;
const struct err_handler_data err_data = { const struct err_handler_data err_data = {
.version = ERR_HANDLER_VERSION, .version = ERR_HANDLER_VERSION,
.ea_reason = ea_reason, .ea_reason = ea_reason,
.interrupt = 0, .interrupt = 0,
.syndrome = syndrome, .syndrome = (uint32_t) syndrome,
.flags = flags, .flags = flags,
.cookie = cookie, .cookie = cookie,
.handle = handle .handle = handle
...@@ -39,7 +40,7 @@ int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, ...@@ -39,7 +40,7 @@ int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
assert(info->handler != NULL); assert(info->handler != NULL);
/* Continue probing until the record group signals no error */ /* Continue probing until the record group signals no error */
while (1) { while (true) {
if (info->probe(info, &probe_data) == 0) if (info->probe(info, &probe_data) == 0)
break; break;
...@@ -52,20 +53,20 @@ int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, ...@@ -52,20 +53,20 @@ int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
} }
} }
return (n_handled != 0); return (n_handled != 0U) ? 1 : 0;
} }
#if ENABLE_ASSERTIONS #if ENABLE_ASSERTIONS
static void assert_interrupts_sorted(void) static void assert_interrupts_sorted(void)
{ {
unsigned int i, last; unsigned int i, last;
struct ras_interrupt *start = ras_interrupt_mapping.intrs; struct ras_interrupt *start = ras_interrupt_mappings.intrs;
if (ras_interrupt_mapping.num_intrs == 0) if (ras_interrupt_mappings.num_intrs == 0UL)
return; return;
last = start[0].intr_number; last = start[0].intr_number;
for (i = 1; i < ras_interrupt_mapping.num_intrs; i++) { for (i = 1; i < ras_interrupt_mappings.num_intrs; i++) {
assert(start[i].intr_number > last); assert(start[i].intr_number > last);
last = start[i].intr_number; last = start[i].intr_number;
} }
...@@ -79,7 +80,7 @@ static void assert_interrupts_sorted(void) ...@@ -79,7 +80,7 @@ static void assert_interrupts_sorted(void)
static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags, static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags,
void *handle, void *cookie) void *handle, void *cookie)
{ {
struct ras_interrupt *ras_inrs = ras_interrupt_mapping.intrs; struct ras_interrupt *ras_inrs = ras_interrupt_mappings.intrs;
struct ras_interrupt *selected = NULL; struct ras_interrupt *selected = NULL;
int start, end, mid, probe_data, ret __unused; int start, end, mid, probe_data, ret __unused;
...@@ -91,10 +92,10 @@ static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags, ...@@ -91,10 +92,10 @@ static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags,
.handle = handle .handle = handle
}; };
assert(ras_interrupt_mapping.num_intrs > 0); assert(ras_interrupt_mappings.num_intrs > 0UL);
start = 0; start = 0;
end = ras_interrupt_mapping.num_intrs; end = (int) ras_interrupt_mappings.num_intrs;
while (start <= end) { while (start <= end) {
mid = ((end + start) / 2); mid = ((end + start) / 2);
if (intr_raw == ras_inrs[mid].intr_number) { if (intr_raw == ras_inrs[mid].intr_number) {
...@@ -114,14 +115,14 @@ static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags, ...@@ -114,14 +115,14 @@ static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags,
panic(); panic();
} }
if (selected->err_record->probe) { if (selected->err_record->probe != NULL) {
ret = selected->err_record->probe(selected->err_record, &probe_data); ret = selected->err_record->probe(selected->err_record, &probe_data);
assert(ret != 0); assert(ret != 0);
} }
/* Call error handler for the record group */ /* Call error handler for the record group */
assert(selected->err_record->handler != NULL); assert(selected->err_record->handler != NULL);
selected->err_record->handler(selected->err_record, probe_data, (void) selected->err_record->handler(selected->err_record, probe_data,
&err_data); &err_data);
return 0; return 0;
......
...@@ -13,28 +13,29 @@ ...@@ -13,28 +13,29 @@
*/ */
int ser_probe_memmap(uintptr_t base, unsigned int size_num_k, int *probe_data) int ser_probe_memmap(uintptr_t base, unsigned int size_num_k, int *probe_data)
{ {
int num_records, num_group_regs, i; unsigned int num_records, num_group_regs, i;
uint64_t gsr; uint64_t gsr;
assert(base != 0); assert(base != 0UL);
/* Only 4K supported for now */ /* Only 4K supported for now */
assert(size_num_k == STD_ERR_NODE_SIZE_NUM_K); assert(size_num_k == STD_ERR_NODE_SIZE_NUM_K);
num_records = (mmio_read_32(ERR_DEVID(base, size_num_k)) & ERR_DEVID_MASK); num_records = (unsigned int)
(mmio_read_32(ERR_DEVID(base, size_num_k)) & ERR_DEVID_MASK);
/* A group register shows error status for 2^6 error records */ /* A group register shows error status for 2^6 error records */
num_group_regs = (num_records >> 6) + 1; num_group_regs = (num_records >> 6U) + 1U;
/* Iterate through group registers to find a record in error */ /* Iterate through group registers to find a record in error */
for (i = 0; i < num_group_regs; i++) { for (i = 0; i < num_group_regs; i++) {
gsr = mmio_read_64(ERR_GSR(base, size_num_k, i)); gsr = mmio_read_64(ERR_GSR(base, size_num_k, i));
if (gsr == 0) if (gsr == 0ULL)
continue; continue;
/* Return the index of the record in error */ /* Return the index of the record in error */
if (probe_data != NULL) if (probe_data != NULL)
*probe_data = ((i << 6) + __builtin_ctz(gsr)); *probe_data = (((int) (i << 6U)) + __builtin_ctzll(gsr));
return 1; return 1;
} }
...@@ -49,13 +50,14 @@ int ser_probe_memmap(uintptr_t base, unsigned int size_num_k, int *probe_data) ...@@ -49,13 +50,14 @@ int ser_probe_memmap(uintptr_t base, unsigned int size_num_k, int *probe_data)
*/ */
int ser_probe_sysreg(unsigned int idx_start, unsigned int num_idx, int *probe_data) int ser_probe_sysreg(unsigned int idx_start, unsigned int num_idx, int *probe_data)
{ {
int i; unsigned int i;
uint64_t status; uint64_t status;
unsigned int max_idx __unused = read_erridr_el1() & ERRIDR_MASK; unsigned int max_idx __unused =
((unsigned int) read_erridr_el1()) & ERRIDR_MASK;
assert(idx_start < max_idx); assert(idx_start < max_idx);
assert(check_u32_overflow(idx_start, num_idx) == 0); assert(check_u32_overflow(idx_start, num_idx));
assert((idx_start + num_idx - 1) < max_idx); assert((idx_start + num_idx - 1U) < max_idx);
for (i = 0; i < num_idx; i++) { for (i = 0; i < num_idx; i++) {
/* Select the error record */ /* Select the error record */
...@@ -65,9 +67,9 @@ int ser_probe_sysreg(unsigned int idx_start, unsigned int num_idx, int *probe_da ...@@ -65,9 +67,9 @@ int ser_probe_sysreg(unsigned int idx_start, unsigned int num_idx, int *probe_da
status = read_erxstatus_el1(); status = read_erxstatus_el1();
/* Check for valid field in status */ /* Check for valid field in status */
if (ERR_STATUS_GET_FIELD(status, V)) { if (ERR_STATUS_GET_FIELD(status, V) != 0U) {
if (probe_data != NULL) if (probe_data != NULL)
*probe_data = i; *probe_data = (int) i;
return 1; return 1;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment