blob: 4f03ac4c653b37a7522d2810e21c2aa5f6845ba7 [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);
Sughosh Ganu18f513d2018-05-16 17:22:35 +053023typedef struct mm_communicate_header {
24 struct efi_guid header_guid;
25 size_t message_len;
26 uint8_t data[8];
27} mm_communicate_header_t;
28
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053029/*
30 * GUID to indicate that the MM communication message is intended for DMC-620
31 * MM driver.
32 */
33const struct efi_guid dmc620_ecc_event_guid = {
34 0x5ef0afd5, 0xe01a, 0x4c30,
35 {0x86, 0x19, 0x45, 0x46, 0x26, 0x91, 0x80, 0x98}
36};
37
Sughosh Ganu70661cf2018-05-16 17:26:40 +053038struct sgi_ras_ev_map sgi575_ras_map[] = {
39
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053040 /* DMC 0 error ECC error interrupt*/
41 {SGI_SDEI_DS_EVENT_0, 35},
Sughosh Ganu70661cf2018-05-16 17:26:40 +053042
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053043 /* DMC 1 error ECC error interrupt*/
44 {SGI_SDEI_DS_EVENT_1, 39},
Sughosh Ganu70661cf2018-05-16 17:26:40 +053045};
46
47#define SGI575_RAS_MAP_SIZE ARRAY_SIZE(sgi575_ras_map)
48
49struct err_record_info sgi_err_records[] = {
50 {
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053051 /* DMC 0 error record info */
Sughosh Ganu70661cf2018-05-16 17:26:40 +053052 .handler = &sgi_ras_intr_handler,
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053053 .aux_data = (void *)0,
54 }, {
55 /* DMC 1 error record info */
56 .handler = &sgi_ras_intr_handler,
57 .aux_data = (void *)1,
Sughosh Ganu70661cf2018-05-16 17:26:40 +053058 },
59};
60
61struct ras_interrupt sgi_ras_interrupts[] = {
62 {
Sughosh Ganu70661cf2018-05-16 17:26:40 +053063 .intr_number = 35,
64 .err_record = &sgi_err_records[0],
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +053065 }, {
66 .intr_number = 39,
67 .err_record = &sgi_err_records[1],
Sughosh Ganu70661cf2018-05-16 17:26:40 +053068 }
69};
70
71REGISTER_ERR_RECORD_INFO(sgi_err_records);
72REGISTER_RAS_INTERRUPTS(sgi_ras_interrupts);
73
74static struct sgi_ras_ev_map *plat_sgi_get_ras_ev_map(void)
75{
76 return sgi575_ras_map;
77}
78
79static int plat_sgi_get_ras_ev_map_size(void)
80{
81 return SGI575_RAS_MAP_SIZE;
82}
83
Sughosh Ganu18f513d2018-05-16 17:22:35 +053084/*
85 * Find event mapping for a given interrupt number: On success, returns pointer
86 * to the event mapping. On error, returns NULL.
87 */
88static struct sgi_ras_ev_map *find_ras_event_map_by_intr(uint32_t intr_num)
89{
90 struct sgi_ras_ev_map *map = plat_sgi_get_ras_ev_map();
91 int i;
92 int size = plat_sgi_get_ras_ev_map_size();
93
94 for (i = 0; i < size; i++) {
95 if (map->intr == intr_num)
96 return map;
97
98 map++;
99 }
100
101 return NULL;
102}
103
104static void sgi_ras_intr_configure(int intr)
105{
106 plat_ic_set_interrupt_type(intr, INTR_TYPE_EL3);
107 plat_ic_set_interrupt_priority(intr, PLAT_RAS_PRI);
108 plat_ic_clear_interrupt_pending(intr);
109 plat_ic_set_spi_routing(intr, INTR_ROUTING_MODE_ANY,
110 (u_register_t)read_mpidr_el1());
111 plat_ic_enable_interrupt(intr);
112}
113
114static int sgi_ras_intr_handler(const struct err_record_info *err_rec,
115 int probe_data,
116 const struct err_handler_data *const data)
117{
118 struct sgi_ras_ev_map *ras_map;
119 mm_communicate_header_t *header;
120 uint32_t intr;
Ming Huangaba1d662020-11-09 17:22:05 +0800121 int ret;
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530122
123 cm_el1_sysregs_context_save(NON_SECURE);
124 intr = data->interrupt;
125
126 /*
127 * Find if this is a RAS interrupt. There must be an event against
128 * this interrupt
129 */
130 ras_map = find_ras_event_map_by_intr(intr);
Ming Huangc15ed682021-01-11 11:00:12 +0800131 assert(ras_map != NULL);
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530132
133 /*
134 * Populate the MM_COMMUNICATE payload to share the
135 * event info with StandaloneMM code. This allows us to use
136 * MM_COMMUNICATE as a common entry mechanism into S-EL0. The
137 * header data will be parsed in StandaloneMM to process the
138 * corresponding event.
139 *
140 * TBD - Currently, the buffer allocated by SPM for communication
141 * between EL3 and S-EL0 is being used(PLAT_SPM_BUF_BASE). But this
142 * should happen via a dynamic mem allocation, which should be
143 * managed by SPM -- the individual platforms then call the mem
144 * alloc api to get memory for the payload.
145 */
146 header = (void *) PLAT_SPM_BUF_BASE;
147 memset(header, 0, sizeof(*header));
Omkar Anand Kulkarnie164e262020-08-25 23:53:17 +0530148 memcpy(&header->data, &err_rec->aux_data, sizeof(err_rec->aux_data));
149 header->message_len = sizeof(err_rec->aux_data);
150 memcpy(&header->header_guid, (void *) &dmc620_ecc_event_guid,
151 sizeof(const struct efi_guid));
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530152
Paul Beesleye9754e62019-10-15 12:51:55 +0000153 spm_mm_sp_call(MM_COMMUNICATE_AARCH64, (uint64_t)header, 0,
154 plat_my_core_pos());
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530155
156 /*
Paul Beesleye9754e62019-10-15 12:51:55 +0000157 * Do an EOI of the RAS interrupt. This allows the
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530158 * sdei event to be dispatched at the SDEI event's
159 * priority.
160 */
161 plat_ic_end_of_interrupt(intr);
162
163 /* Dispatch the event to the SDEI client */
Ming Huangaba1d662020-11-09 17:22:05 +0800164 ret = sdei_dispatch_event(ras_map->sdei_ev_num);
165 if (ret != 0) {
166 /*
167 * sdei_dispatch_event() may return failing result in some cases,
168 * for example kernel may not have registered a handler or RAS event
169 * may happen early during boot. We restore the NS context when
170 * sdei_dispatch_event() returns failing result.
171 */
172 ERROR("SDEI dispatch failed: %d", ret);
173 cm_el1_sysregs_context_restore(NON_SECURE);
174 cm_set_next_eret_context(NON_SECURE);
175 }
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530176
Ming Huangaba1d662020-11-09 17:22:05 +0800177 return ret;
Sughosh Ganu18f513d2018-05-16 17:22:35 +0530178}
179
180int sgi_ras_intr_handler_setup(void)
181{
182 int i;
183 struct sgi_ras_ev_map *map = plat_sgi_get_ras_ev_map();
184 int size = plat_sgi_get_ras_ev_map_size();
185
186 for (i = 0; i < size; i++) {
187 sgi_ras_intr_configure(map->intr);
188 map++;
189 }
190
191 INFO("SGI: RAS Interrupt Handler successfully registered\n");
192
193 return 0;
194}