blob: be8beceeb4972a89215b51c66870e7a7c287323a [file] [log] [blame]
Jeenu Viswambharan2e2e8812017-12-08 15:38:21 +00001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +01007#include <stdbool.h>
Jeenu Viswambharan2e2e8812017-12-08 15:38:21 +00008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <arch_helpers.h>
10#include <bl31/ea_handle.h>
11#include <bl31/ehf.h>
12#include <common/debug.h>
13#include <lib/extensions/ras.h>
14#include <lib/extensions/ras_arch.h>
15#include <plat/common/platform.h>
16
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000017#ifndef PLAT_RAS_PRI
18# error Platform must define RAS priority value
19#endif
20
Jeenu Viswambharan2e2e8812017-12-08 15:38:21 +000021/* Handler that receives External Aborts on RAS-capable systems */
22int ras_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
23 void *handle, uint64_t flags)
24{
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010025 unsigned int i, n_handled = 0;
26 int probe_data, ret;
Jeenu Viswambharan2e2e8812017-12-08 15:38:21 +000027 struct err_record_info *info;
28
29 const struct err_handler_data err_data = {
30 .version = ERR_HANDLER_VERSION,
31 .ea_reason = ea_reason,
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000032 .interrupt = 0,
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010033 .syndrome = (uint32_t) syndrome,
Jeenu Viswambharan2e2e8812017-12-08 15:38:21 +000034 .flags = flags,
35 .cookie = cookie,
36 .handle = handle
37 };
38
39 for_each_err_record_info(i, info) {
40 assert(info->probe != NULL);
41 assert(info->handler != NULL);
42
43 /* Continue probing until the record group signals no error */
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010044 while (true) {
Jeenu Viswambharan2e2e8812017-12-08 15:38:21 +000045 if (info->probe(info, &probe_data) == 0)
46 break;
47
48 /* Handle error */
49 ret = info->handler(info, probe_data, &err_data);
50 if (ret != 0)
51 return ret;
52
53 n_handled++;
54 }
55 }
56
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010057 return (n_handled != 0U) ? 1 : 0;
Jeenu Viswambharan2e2e8812017-12-08 15:38:21 +000058}
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000059
60#if ENABLE_ASSERTIONS
61static void assert_interrupts_sorted(void)
62{
63 unsigned int i, last;
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010064 struct ras_interrupt *start = ras_interrupt_mappings.intrs;
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000065
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010066 if (ras_interrupt_mappings.num_intrs == 0UL)
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000067 return;
68
69 last = start[0].intr_number;
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010070 for (i = 1; i < ras_interrupt_mappings.num_intrs; i++) {
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000071 assert(start[i].intr_number > last);
72 last = start[i].intr_number;
73 }
74}
75#endif
76
77/*
78 * Given an RAS interrupt number, locate the registered handler and call it. If
79 * no handler was found for the interrupt number, this function panics.
80 */
81static int ras_interrupt_handler(uint32_t intr_raw, uint32_t flags,
82 void *handle, void *cookie)
83{
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010084 struct ras_interrupt *ras_inrs = ras_interrupt_mappings.intrs;
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000085 struct ras_interrupt *selected = NULL;
86 int start, end, mid, probe_data, ret __unused;
87
88 const struct err_handler_data err_data = {
89 .version = ERR_HANDLER_VERSION,
90 .interrupt = intr_raw,
91 .flags = flags,
92 .cookie = cookie,
93 .handle = handle
94 };
95
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010096 assert(ras_interrupt_mappings.num_intrs > 0UL);
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +000097
98 start = 0;
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +010099 end = (int) ras_interrupt_mappings.num_intrs;
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +0000100 while (start <= end) {
101 mid = ((end + start) / 2);
102 if (intr_raw == ras_inrs[mid].intr_number) {
103 selected = &ras_inrs[mid];
104 break;
105 } else if (intr_raw < ras_inrs[mid].intr_number) {
106 /* Move left */
107 end = mid - 1;
108 } else {
109 /* Move right */
110 start = mid + 1;
111 }
112 }
113
114 if (selected == NULL) {
115 ERROR("RAS interrupt %u has no handler!\n", intr_raw);
116 panic();
117 }
118
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +0100119 if (selected->err_record->probe != NULL) {
Sughosh Ganud51f80f2018-05-12 11:02:31 +0530120 ret = selected->err_record->probe(selected->err_record, &probe_data);
121 assert(ret != 0);
122 }
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +0000123
124 /* Call error handler for the record group */
125 assert(selected->err_record->handler != NULL);
Jeenu Viswambharan31ac01e2018-08-02 10:14:12 +0100126 (void) selected->err_record->handler(selected->err_record, probe_data,
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +0000127 &err_data);
128
129 return 0;
130}
131
Daniel Boulby5753e492018-09-20 14:12:46 +0100132void __init ras_init(void)
Jeenu Viswambharand86cc5b2017-12-12 10:34:58 +0000133{
134#if ENABLE_ASSERTIONS
135 /* Check RAS interrupts are sorted */
136 assert_interrupts_sorted();
137#endif
138
139 /* Register RAS priority handler */
140 ehf_register_priority_handler(PLAT_RAS_PRI, ras_interrupt_handler);
141}