blob: 7aa477d27e86ecb473845832570c1ef74bd47ea8 [file] [log] [blame]
Sughosh Ganu18f513d2018-05-16 17:22:35 +05301/*
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +05302 * Copyright (c) 2018-2021, ARM Limited and Contributors. All rights reserved.
Sughosh Ganu18f513d2018-05-16 17:22:35 +05303 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Sughosh Ganu18f513d2018-05-16 17:22:35 +05307#include <assert.h>
Sughosh Ganu18f513d2018-05-16 17:22:35 +05308#include <string.h>
9
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <bl31/interrupt_mgmt.h>
11#include <lib/el3_runtime/context_mgmt.h>
12#include <lib/extensions/ras.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000013#include <plat/arm/common/arm_spm_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <plat/common/platform.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <services/sdei.h>
Paul Beesleye9754e62019-10-15 12:51:55 +000016#include <services/spm_mm_svc.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000018#include <sgi_ras.h>
19
Sughosh Ganu18f513d2018-05-16 17:22:35 +053020static int sgi_ras_intr_handler(const struct err_record_info *err_rec,
21 int probe_data,
22 const struct err_handler_data *const data);
23struct efi_guid {
24 uint32_t data1;
25 uint16_t data2;
26 uint16_t data3;
27 uint8_t data4[8];
28};
29
30typedef struct mm_communicate_header {
31 struct efi_guid header_guid;
32 size_t message_len;
33 uint8_t data[8];
34} mm_communicate_header_t;
35
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053036/*
37 * GUID to indicate that the MM communication message is intended for DMC-620
38 * MM driver.
39 */
40const struct efi_guid dmc620_ecc_event_guid = {
41 0x5ef0afd5, 0xe01a, 0x4c30,
42 {0x86, 0x19, 0x45, 0x46, 0x26, 0x91, 0x80, 0x98}
43};
44
Sughosh Ganu70661cf2018-05-16 17:26:40 +053045struct sgi_ras_ev_map sgi575_ras_map[] = {
46
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053047 /* DMC 0 error ECC error interrupt*/
48 {SGI_SDEI_DS_EVENT_0, 35},
Sughosh Ganu70661cf2018-05-16 17:26:40 +053049
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053050 /* DMC 1 error ECC error interrupt*/
51 {SGI_SDEI_DS_EVENT_1, 39},
Sughosh Ganu70661cf2018-05-16 17:26:40 +053052};
53
54#define SGI575_RAS_MAP_SIZE ARRAY_SIZE(sgi575_ras_map)
55
56struct err_record_info sgi_err_records[] = {
57 {
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053058 /* DMC 0 error record info */
Sughosh Ganu70661cf2018-05-16 17:26:40 +053059 .handler = &sgi_ras_intr_handler,
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053060 .aux_data = (void *)0,
61 }, {
62 /* DMC 1 error record info */
63 .handler = &sgi_ras_intr_handler,
64 .aux_data = (void *)1,
Sughosh Ganu70661cf2018-05-16 17:26:40 +053065 },
66};
67
68struct ras_interrupt sgi_ras_interrupts[] = {
69 {
Sughosh Ganu70661cf2018-05-16 17:26:40 +053070 .intr_number = 35,
71 .err_record = &sgi_err_records[0],
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053072 }, {
73 .intr_number = 39,
74 .err_record = &sgi_err_records[1],
Sughosh Ganu70661cf2018-05-16 17:26:40 +053075 }
76};
77
78REGISTER_ERR_RECORD_INFO(sgi_err_records);
79REGISTER_RAS_INTERRUPTS(sgi_ras_interrupts);
80
81static struct sgi_ras_ev_map *plat_sgi_get_ras_ev_map(void)
82{
83 return sgi575_ras_map;
84}
85
86static int plat_sgi_get_ras_ev_map_size(void)
87{
88 return SGI575_RAS_MAP_SIZE;
89}
90
Sughosh Ganu18f513d2018-05-16 17:22:35 +053091/*
92 * Find event mapping for a given interrupt number: On success, returns pointer
93 * to the event mapping. On error, returns NULL.
94 */
95static struct sgi_ras_ev_map *find_ras_event_map_by_intr(uint32_t intr_num)
96{
97 struct sgi_ras_ev_map *map = plat_sgi_get_ras_ev_map();
98 int i;
99 int size = plat_sgi_get_ras_ev_map_size();
100
101 for (i = 0; i < size; i++) {
102 if (map->intr == intr_num)
103 return map;
104
105 map++;
106 }
107
108 return NULL;
109}
110
111static void sgi_ras_intr_configure(int intr)
112{
113 plat_ic_set_interrupt_type(intr, INTR_TYPE_EL3);
114 plat_ic_set_interrupt_priority(intr, PLAT_RAS_PRI);
115 plat_ic_clear_interrupt_pending(intr);
116 plat_ic_set_spi_routing(intr, INTR_ROUTING_MODE_ANY,
117 (u_register_t)read_mpidr_el1());
118 plat_ic_enable_interrupt(intr);
119}
120
121static int sgi_ras_intr_handler(const struct err_record_info *err_rec,
122 int probe_data,
123 const struct err_handler_data *const data)
124{
125 struct sgi_ras_ev_map *ras_map;
126 mm_communicate_header_t *header;
127 uint32_t intr;
Ming Huangaba1d662020-11-09 17:22:05 +0800128 int ret;
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530129
130 cm_el1_sysregs_context_save(NON_SECURE);
131 intr = data->interrupt;
132
133 /*
134 * Find if this is a RAS interrupt. There must be an event against
135 * this interrupt
136 */
137 ras_map = find_ras_event_map_by_intr(intr);
Ming Huangc15ed682021-01-11 11:00:12 +0800138 assert(ras_map != NULL);
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530139
140 /*
141 * Populate the MM_COMMUNICATE payload to share the
142 * event info with StandaloneMM code. This allows us to use
143 * MM_COMMUNICATE as a common entry mechanism into S-EL0. The
144 * header data will be parsed in StandaloneMM to process the
145 * corresponding event.
146 *
147 * TBD - Currently, the buffer allocated by SPM for communication
148 * between EL3 and S-EL0 is being used(PLAT_SPM_BUF_BASE). But this
149 * should happen via a dynamic mem allocation, which should be
150 * managed by SPM -- the individual platforms then call the mem
151 * alloc api to get memory for the payload.
152 */
153 header = (void *) PLAT_SPM_BUF_BASE;
154 memset(header, 0, sizeof(*header));
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +0530155 memcpy(&header->data, &err_rec->aux_data, sizeof(err_rec->aux_data));
156 header->message_len = sizeof(err_rec->aux_data);
157 memcpy(&header->header_guid, (void *) &dmc620_ecc_event_guid,
158 sizeof(const struct efi_guid));
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530159
Paul Beesleye9754e62019-10-15 12:51:55 +0000160 spm_mm_sp_call(MM_COMMUNICATE_AARCH64, (uint64_t)header, 0,
161 plat_my_core_pos());
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530162
163 /*
Paul Beesleye9754e62019-10-15 12:51:55 +0000164 * Do an EOI of the RAS interrupt. This allows the
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530165 * sdei event to be dispatched at the SDEI event's
166 * priority.
167 */
168 plat_ic_end_of_interrupt(intr);
169
170 /* Dispatch the event to the SDEI client */
Ming Huangaba1d662020-11-09 17:22:05 +0800171 ret = sdei_dispatch_event(ras_map->sdei_ev_num);
172 if (ret != 0) {
173 /*
174 * sdei_dispatch_event() may return failing result in some cases,
175 * for example kernel may not have registered a handler or RAS event
176 * may happen early during boot. We restore the NS context when
177 * sdei_dispatch_event() returns failing result.
178 */
179 ERROR("SDEI dispatch failed: %d", ret);
180 cm_el1_sysregs_context_restore(NON_SECURE);
181 cm_set_next_eret_context(NON_SECURE);
182 }
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530183
Ming Huangaba1d662020-11-09 17:22:05 +0800184 return ret;
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530185}
186
187int sgi_ras_intr_handler_setup(void)
188{
189 int i;
190 struct sgi_ras_ev_map *map = plat_sgi_get_ras_ev_map();
191 int size = plat_sgi_get_ras_ev_map_size();
192
193 for (i = 0; i < size; i++) {
194 sgi_ras_intr_configure(map->intr);
195 map++;
196 }
197
198 INFO("SGI: RAS Interrupt Handler successfully registered\n");
199
200 return 0;
201}