blob: 6c1dc9f9bb6262bae23de2e5b461cc13c4ba5589 [file] [log] [blame]
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +00001/*
Govindraj Rajaeee28e72023-08-01 15:52:40 -05002 * Copyright (c) 2018, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
7#include <lib/extensions/ras_arch.h>
8#include <lib/utils_def.h>
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +00009
10/*
11 * Probe for error in memory-mapped registers containing error records
12 * implemented Standard Error Record format. Upon detecting an error, set probe
13 * data to the index of the record in error, and return 1; otherwise, return 0.
14 */
15int ser_probe_memmap(uintptr_t base, unsigned int size_num_k, int *probe_data)
16{
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010017 unsigned int num_records, num_group_regs, i;
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000018 uint64_t gsr;
19
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010020 assert(base != 0UL);
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000021
22 /* Only 4K supported for now */
23 assert(size_num_k == STD_ERR_NODE_SIZE_NUM_K);
24
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010025 num_records = (unsigned int)
26 (mmio_read_32(ERR_DEVID(base, size_num_k)) & ERR_DEVID_MASK);
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000027
28 /* A group register shows error status for 2^6 error records */
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010029 num_group_regs = (num_records >> 6U) + 1U;
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000030
31 /* Iterate through group registers to find a record in error */
32 for (i = 0; i < num_group_regs; i++) {
33 gsr = mmio_read_64(ERR_GSR(base, size_num_k, i));
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010034 if (gsr == 0ULL)
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000035 continue;
36
37 /* Return the index of the record in error */
38 if (probe_data != NULL)
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010039 *probe_data = (((int) (i << 6U)) + __builtin_ctzll(gsr));
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000040
41 return 1;
42 }
43
44 return 0;
45}
46
47/*
48 * Probe for error in System Registers where error records are implemented in
49 * Standard Error Record format. Upon detecting an error, set probe data to the
50 * index of the record in error, and return 1; otherwise, return 0.
51 */
52int ser_probe_sysreg(unsigned int idx_start, unsigned int num_idx, int *probe_data)
53{
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010054 unsigned int i;
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000055 uint64_t status;
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010056 unsigned int max_idx __unused =
57 ((unsigned int) read_erridr_el1()) & ERRIDR_MASK;
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000058
59 assert(idx_start < max_idx);
Jeenu Viswambharan067a3572018-09-07 16:30:58 +010060 assert(check_u32_overflow(idx_start, num_idx) == 0);
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010061 assert((idx_start + num_idx - 1U) < max_idx);
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000062
63 for (i = 0; i < num_idx; i++) {
64 /* Select the error record */
65 ser_sys_select_record(idx_start + i);
66
67 /* Retrieve status register from the error record */
68 status = read_erxstatus_el1();
69
70 /* Check for valid field in status */
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010071 if (ERR_STATUS_GET_FIELD(status, V) != 0U) {
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000072 if (probe_data != NULL)
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010073 *probe_data = (int) i;
Jeenu Viswambharan19f6cf22017-12-07 08:43:05 +000074 return 1;
75 }
76 }
77
78 return 0;
79}