blob: ac4610d2162a28887b4afeb5265d4c84a057238c [file] [log] [blame]
Sughosh Ganu18f513d2018-05-16 17:22:35 +05301/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arm_spm_def.h>
8#include <assert.h>
9#include <context_mgmt.h>
10#include <interrupt_mgmt.h>
11#include <mm_svc.h>
12#include <ras.h>
13#include <sgi_ras.h>
14#include <platform.h>
15#include <spm_svc.h>
16#include <sdei.h>
17#include <string.h>
18
19static int sgi_ras_intr_handler(const struct err_record_info *err_rec,
20 int probe_data,
21 const struct err_handler_data *const data);
22struct efi_guid {
23 uint32_t data1;
24 uint16_t data2;
25 uint16_t data3;
26 uint8_t data4[8];
27};
28
29typedef struct mm_communicate_header {
30 struct efi_guid header_guid;
31 size_t message_len;
32 uint8_t data[8];
33} mm_communicate_header_t;
34
Sughosh Ganu70661cf2018-05-16 17:26:40 +053035struct sgi_ras_ev_map sgi575_ras_map[] = {
36
37 /* DMC620 error overflow interrupt*/
38 {SP_DMC_ERROR_OVERFLOW_EVENT_AARCH64, SGI_SDEI_DS_EVENT_1, 33},
39
40 /* DMC620 error ECC error interrupt*/
41 {SP_DMC_ERROR_ECC_EVENT_AARCH64, SGI_SDEI_DS_EVENT_0, 35},
42};
43
44#define SGI575_RAS_MAP_SIZE ARRAY_SIZE(sgi575_ras_map)
45
46struct err_record_info sgi_err_records[] = {
47 {
48 .handler = &sgi_ras_intr_handler,
49 },
50};
51
52struct ras_interrupt sgi_ras_interrupts[] = {
53 {
54 .intr_number = 33,
55 .err_record = &sgi_err_records[0],
56 },
57 {
58 .intr_number = 35,
59 .err_record = &sgi_err_records[0],
60 }
61};
62
63REGISTER_ERR_RECORD_INFO(sgi_err_records);
64REGISTER_RAS_INTERRUPTS(sgi_ras_interrupts);
65
66static struct sgi_ras_ev_map *plat_sgi_get_ras_ev_map(void)
67{
68 return sgi575_ras_map;
69}
70
71static int plat_sgi_get_ras_ev_map_size(void)
72{
73 return SGI575_RAS_MAP_SIZE;
74}
75
Sughosh Ganu18f513d2018-05-16 17:22:35 +053076/*
77 * Find event mapping for a given interrupt number: On success, returns pointer
78 * to the event mapping. On error, returns NULL.
79 */
80static struct sgi_ras_ev_map *find_ras_event_map_by_intr(uint32_t intr_num)
81{
82 struct sgi_ras_ev_map *map = plat_sgi_get_ras_ev_map();
83 int i;
84 int size = plat_sgi_get_ras_ev_map_size();
85
86 for (i = 0; i < size; i++) {
87 if (map->intr == intr_num)
88 return map;
89
90 map++;
91 }
92
93 return NULL;
94}
95
96static void sgi_ras_intr_configure(int intr)
97{
98 plat_ic_set_interrupt_type(intr, INTR_TYPE_EL3);
99 plat_ic_set_interrupt_priority(intr, PLAT_RAS_PRI);
100 plat_ic_clear_interrupt_pending(intr);
101 plat_ic_set_spi_routing(intr, INTR_ROUTING_MODE_ANY,
102 (u_register_t)read_mpidr_el1());
103 plat_ic_enable_interrupt(intr);
104}
105
106static int sgi_ras_intr_handler(const struct err_record_info *err_rec,
107 int probe_data,
108 const struct err_handler_data *const data)
109{
110 struct sgi_ras_ev_map *ras_map;
111 mm_communicate_header_t *header;
112 uint32_t intr;
113
114 cm_el1_sysregs_context_save(NON_SECURE);
115 intr = data->interrupt;
116
117 /*
118 * Find if this is a RAS interrupt. There must be an event against
119 * this interrupt
120 */
121 ras_map = find_ras_event_map_by_intr(intr);
122 assert(ras_map);
123
124 /*
125 * Populate the MM_COMMUNICATE payload to share the
126 * event info with StandaloneMM code. This allows us to use
127 * MM_COMMUNICATE as a common entry mechanism into S-EL0. The
128 * header data will be parsed in StandaloneMM to process the
129 * corresponding event.
130 *
131 * TBD - Currently, the buffer allocated by SPM for communication
132 * between EL3 and S-EL0 is being used(PLAT_SPM_BUF_BASE). But this
133 * should happen via a dynamic mem allocation, which should be
134 * managed by SPM -- the individual platforms then call the mem
135 * alloc api to get memory for the payload.
136 */
137 header = (void *) PLAT_SPM_BUF_BASE;
138 memset(header, 0, sizeof(*header));
139 memcpy(&header->data, &ras_map->ras_ev_num,
140 sizeof(ras_map->ras_ev_num));
141 header->message_len = 4;
142
143 spm_sp_call(MM_COMMUNICATE_AARCH64, (uint64_t)header, 0,
144 plat_my_core_pos());
145
146 /*
147 * Do an EOI of the RAS interuupt. This allows the
148 * sdei event to be dispatched at the SDEI event's
149 * priority.
150 */
151 plat_ic_end_of_interrupt(intr);
152
153 /* Dispatch the event to the SDEI client */
154 sdei_dispatch_event(ras_map->sdei_ev_num);
155
156 return 0;
157}
158
159int sgi_ras_intr_handler_setup(void)
160{
161 int i;
162 struct sgi_ras_ev_map *map = plat_sgi_get_ras_ev_map();
163 int size = plat_sgi_get_ras_ev_map_size();
164
165 for (i = 0; i < size; i++) {
166 sgi_ras_intr_configure(map->intr);
167 map++;
168 }
169
170 INFO("SGI: RAS Interrupt Handler successfully registered\n");
171
172 return 0;
173}