1 /* 2 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <stdbool.h> 8 #include <stdint.h> 9 10 #include <common/debug.h> 11 #include <lib/bakery_lock.h> 12 #include <lib/extensions/ras.h> 13 #include <lib/utils_def.h> 14 #include <services/sdei.h> 15 16 #include <plat/common/platform.h> 17 #include <platform_def.h> 18 #include <tegra194_ras_private.h> 19 #include <tegra_def.h> 20 #include <tegra_platform.h> 21 #include <tegra_private.h> 22 23 /* 24 * ERR<n>FR bits[63:32], it indicates supported RAS errors which can be enabled 25 * by setting corresponding bits in ERR<n>CTLR 26 */ 27 #define ERR_FR_EN_BITS_MASK 0xFFFFFFFF00000000ULL 28 29 /* bakery lock for platform RAS handler. */ 30 static DEFINE_BAKERY_LOCK(ras_handler_lock); 31 #define ras_lock() bakery_lock_get(&ras_handler_lock) 32 #define ras_unlock() bakery_lock_release(&ras_handler_lock) 33 34 /* 35 * Function to handle an External Abort received at EL3. 36 * This function is invoked by RAS framework. 37 */ 38 static void tegra194_ea_handler(unsigned int ea_reason, uint64_t syndrome, 39 void *cookie, void *handle, uint64_t flags) 40 { 41 int32_t ret; 42 43 ras_lock(); 44 45 ERROR("MPIDR 0x%lx: exception reason=%u syndrome=0x%llx\n", 46 read_mpidr(), ea_reason, syndrome); 47 48 /* Call RAS EA handler */ 49 ret = ras_ea_handler(ea_reason, syndrome, cookie, handle, flags); 50 if (ret != 0) { 51 ERROR("RAS error handled!\n"); 52 ret = sdei_dispatch_event(TEGRA_SDEI_EP_EVENT_0 + 53 plat_my_core_pos()); 54 if (ret != 0) 55 ERROR("sdei_dispatch_event returned %d\n", ret); 56 } else { 57 ERROR("Not a RAS error!\n"); 58 } 59 60 ras_unlock(); 61 } 62 63 /* 64 * Function to enable all supported RAS error report. 65 * 66 * Uncorrected errors are set to report as External abort (SError) 67 * Corrected errors are set to report as interrupt. 68 */ 69 void tegra194_ras_enable(void) 70 { 71 VERBOSE("%s\n", __func__); 72 73 /* skip RAS enablement if not a silicon platform. */ 74 if (!tegra_platform_is_silicon()) { 75 return; 76 } 77 78 /* 79 * Iterate for each group(num_idx ERRSELRs starting from idx_start) 80 * use normal for loop instead of for_each_err_record_info to get rid 81 * of MISRA noise.. 82 */ 83 for (uint32_t i = 0U; i < err_record_mappings.num_err_records; i++) { 84 85 const struct err_record_info *info = &err_record_mappings.err_records[i]; 86 87 uint32_t idx_start = info->sysreg.idx_start; 88 uint32_t num_idx = info->sysreg.num_idx; 89 const struct ras_aux_data *aux_data = (const struct ras_aux_data *)info->aux_data; 90 91 assert(aux_data != NULL); 92 93 for (uint32_t j = 0; j < num_idx; j++) { 94 95 /* ERR<n>CTLR register value. */ 96 uint64_t err_ctrl = 0ULL; 97 /* all supported errors for this node. */ 98 uint64_t err_fr; 99 /* uncorrectable errors */ 100 uint64_t uncorr_errs; 101 /* correctable errors */ 102 uint64_t corr_errs; 103 104 /* 105 * Catch error if something wrong with the RAS aux data 106 * record table. 107 */ 108 assert(aux_data[j].err_ctrl != NULL); 109 110 /* 111 * Write to ERRSELR_EL1 to select the RAS error node. 112 * Always program this at first to select corresponding 113 * RAS node before any other RAS register r/w. 114 */ 115 ser_sys_select_record(idx_start + j); 116 117 err_fr = read_erxfr_el1() & ERR_FR_EN_BITS_MASK; 118 uncorr_errs = aux_data[j].err_ctrl(); 119 corr_errs = ~uncorr_errs & err_fr; 120 121 /* enable error reporting */ 122 ERR_CTLR_ENABLE_FIELD(err_ctrl, ED); 123 124 /* enable SError reporting for uncorrectable errors */ 125 if ((uncorr_errs & err_fr) != 0ULL) { 126 ERR_CTLR_ENABLE_FIELD(err_ctrl, UE); 127 } 128 129 /* generate interrupt for corrected errors. */ 130 if (corr_errs != 0ULL) { 131 ERR_CTLR_ENABLE_FIELD(err_ctrl, CFI); 132 } 133 134 /* enable the supported errors */ 135 err_ctrl |= err_fr; 136 137 VERBOSE("errselr_el1:0x%x, erxfr:0x%llx, err_ctrl:0x%llx\n", 138 idx_start + j, err_fr, err_ctrl); 139 140 /* enable specified errors, or set to 0 if no supported error */ 141 write_erxctlr_el1(err_ctrl); 142 143 /* 144 * Check if all the bit settings have been enabled to detect 145 * uncorrected/corrected errors, if not assert. 146 */ 147 assert(read_erxctlr_el1() == err_ctrl); 148 } 149 } 150 } 151 152 /* 153 * Function to clear RAS ERR<n>STATUS for corrected RAS error. 154 * This function ignores any new RAS error signaled during clearing; it is not 155 * multi-core safe(no ras_lock is taken to reduce overhead). 156 */ 157 void tegra194_ras_corrected_err_clear(void) 158 { 159 uint64_t clear_ce_status = 0ULL; 160 161 ERR_STATUS_SET_FIELD(clear_ce_status, AV, 0x1UL); 162 ERR_STATUS_SET_FIELD(clear_ce_status, V, 0x1UL); 163 ERR_STATUS_SET_FIELD(clear_ce_status, OF, 0x1UL); 164 ERR_STATUS_SET_FIELD(clear_ce_status, MV, 0x1UL); 165 ERR_STATUS_SET_FIELD(clear_ce_status, CE, 0x3UL); 166 167 for (uint32_t i = 0U; i < err_record_mappings.num_err_records; i++) { 168 169 const struct err_record_info *info = &err_record_mappings.err_records[i]; 170 uint32_t idx_start = info->sysreg.idx_start; 171 uint32_t num_idx = info->sysreg.num_idx; 172 173 for (uint32_t j = 0U; j < num_idx; j++) { 174 175 uint64_t status; 176 uint32_t err_idx = idx_start + j; 177 178 write_errselr_el1(err_idx); 179 status = read_erxstatus_el1(); 180 181 if (ERR_STATUS_GET_FIELD(status, CE) != 0U) { 182 write_erxstatus_el1(clear_ce_status); 183 } 184 } 185 } 186 } 187 188 /* Function to probe an error from error record group. */ 189 static int32_t tegra194_ras_record_probe(const struct err_record_info *info, 190 int *probe_data) 191 { 192 /* Skip probing if not a silicon platform */ 193 if (!tegra_platform_is_silicon()) { 194 return 0; 195 } 196 197 return ser_probe_sysreg(info->sysreg.idx_start, info->sysreg.num_idx, probe_data); 198 } 199 200 /* Function to handle error from one given node */ 201 static int32_t tegra194_ras_node_handler(uint32_t errselr, const char *name, 202 const struct ras_error *errors, uint64_t status) 203 { 204 bool found = false; 205 uint32_t ierr = (uint32_t)ERR_STATUS_GET_FIELD(status, IERR); 206 uint32_t serr = (uint32_t)ERR_STATUS_GET_FIELD(status, SERR); 207 uint64_t val = 0; 208 209 /* not a valid error. */ 210 if (ERR_STATUS_GET_FIELD(status, V) == 0U) { 211 return 0; 212 } 213 214 ERR_STATUS_SET_FIELD(val, V, 1); 215 216 /* keep the log print same as linux arm64_ras driver. */ 217 ERROR("**************************************\n"); 218 ERROR("RAS Error in %s, ERRSELR_EL1=0x%x:\n", name, errselr); 219 ERROR("\tStatus = 0x%llx\n", status); 220 221 /* Print uncorrectable errror information. */ 222 if (ERR_STATUS_GET_FIELD(status, UE) != 0U) { 223 224 ERR_STATUS_SET_FIELD(val, UE, 1); 225 ERR_STATUS_SET_FIELD(val, UET, 1); 226 227 /* IERR to error message */ 228 for (uint32_t i = 0; errors[i].error_msg != NULL; i++) { 229 if (ierr == errors[i].error_code) { 230 ERROR("\tIERR = %s: 0x%x\n", 231 errors[i].error_msg, ierr); 232 233 found = true; 234 break; 235 } 236 } 237 238 if (!found) { 239 ERROR("\tUnknown IERR: 0x%x\n", ierr); 240 } 241 242 ERROR("SERR = %s: 0x%x\n", ras_serr_to_str(serr), serr); 243 244 /* Overflow, multiple errors have been detected. */ 245 if (ERR_STATUS_GET_FIELD(status, OF) != 0U) { 246 ERROR("\tOverflow (there may be more errors) - " 247 "Uncorrectable\n"); 248 ERR_STATUS_SET_FIELD(val, OF, 1); 249 } 250 251 ERROR("\tUncorrectable (this is fatal)\n"); 252 253 /* Miscellaneous Register Valid. */ 254 if (ERR_STATUS_GET_FIELD(status, MV) != 0U) { 255 ERROR("\tMISC0 = 0x%lx\n", read_erxmisc0_el1()); 256 ERROR("\tMISC1 = 0x%lx\n", read_erxmisc1_el1()); 257 ERR_STATUS_SET_FIELD(val, MV, 1); 258 } 259 260 /* Address Valid. */ 261 if (ERR_STATUS_GET_FIELD(status, AV) != 0U) { 262 ERROR("\tADDR = 0x%lx\n", read_erxaddr_el1()); 263 ERR_STATUS_SET_FIELD(val, AV, 1); 264 } 265 266 /* Deferred error */ 267 if (ERR_STATUS_GET_FIELD(status, DE) != 0U) { 268 ERROR("\tDeferred error\n"); 269 ERR_STATUS_SET_FIELD(val, DE, 1); 270 } 271 272 } else { 273 /* For corrected error, simply clear it. */ 274 VERBOSE("corrected RAS error is cleared: ERRSELR_EL1:0x%x, " 275 "IERR:0x%x, SERR:0x%x\n", errselr, ierr, serr); 276 ERR_STATUS_SET_FIELD(val, CE, 1); 277 } 278 279 ERROR("**************************************\n"); 280 281 /* Write to clear reported errors. */ 282 write_erxstatus_el1(val); 283 284 /* error handled */ 285 return 0; 286 } 287 288 /* Function to handle one error node from an error record group. */ 289 static int32_t tegra194_ras_record_handler(const struct err_record_info *info, 290 int probe_data, const struct err_handler_data *const data __unused) 291 { 292 uint32_t num_idx = info->sysreg.num_idx; 293 uint32_t idx_start = info->sysreg.idx_start; 294 const struct ras_aux_data *aux_data = info->aux_data; 295 const struct ras_error *errors; 296 uint32_t offset; 297 const char *node_name; 298 299 uint64_t status = 0ULL; 300 301 VERBOSE("%s\n", __func__); 302 303 assert(probe_data >= 0); 304 assert((uint32_t)probe_data < num_idx); 305 306 offset = (uint32_t)probe_data; 307 errors = aux_data[offset].error_records; 308 node_name = aux_data[offset].name; 309 310 assert(errors != NULL); 311 312 /* Write to ERRSELR_EL1 to select the error record */ 313 ser_sys_select_record(idx_start + offset); 314 315 /* Retrieve status register from the error record */ 316 status = read_erxstatus_el1(); 317 318 return tegra194_ras_node_handler(idx_start + offset, node_name, 319 errors, status); 320 } 321 322 323 /* Instantiate RAS nodes */ 324 PER_CORE_RAS_NODE_LIST(DEFINE_ONE_RAS_NODE) 325 PER_CLUSTER_RAS_NODE_LIST(DEFINE_ONE_RAS_NODE) 326 SCF_L3_BANK_RAS_NODE_LIST(DEFINE_ONE_RAS_NODE) 327 CCPLEX_RAS_NODE_LIST(DEFINE_ONE_RAS_NODE) 328 329 /* Instantiate RAS node groups */ 330 static struct ras_aux_data per_core_ras_group[] = { 331 PER_CORE_RAS_GROUP_NODES 332 }; 333 334 static struct ras_aux_data per_cluster_ras_group[] = { 335 PER_CLUSTER_RAS_GROUP_NODES 336 }; 337 338 static struct ras_aux_data scf_l3_ras_group[] = { 339 SCF_L3_BANK_RAS_GROUP_NODES 340 }; 341 342 static struct ras_aux_data ccplex_ras_group[] = { 343 CCPLEX_RAS_GROUP_NODES 344 }; 345 346 /* 347 * We have same probe and handler for each error record group, use a macro to 348 * simply the record definition. 349 */ 350 #define ADD_ONE_ERR_GROUP(errselr_start, group) \ 351 ERR_RECORD_SYSREG_V1((errselr_start), (uint32_t)ARRAY_SIZE((group)), \ 352 &tegra194_ras_record_probe, \ 353 &tegra194_ras_record_handler, (group)) 354 355 /* RAS error record group information */ 356 static struct err_record_info carmel_ras_records[] = { 357 /* 358 * Per core ras error records 359 * ERRSELR starts from 0*256 + Logical_CPU_ID*16 + 0 to 360 * 0*256 + Logical_CPU_ID*16 + 5 for each group. 361 * 8 cores/groups, 6 * 8 nodes in total. 362 */ 363 ADD_ONE_ERR_GROUP(0x000, per_core_ras_group), 364 ADD_ONE_ERR_GROUP(0x010, per_core_ras_group), 365 ADD_ONE_ERR_GROUP(0x020, per_core_ras_group), 366 ADD_ONE_ERR_GROUP(0x030, per_core_ras_group), 367 ADD_ONE_ERR_GROUP(0x040, per_core_ras_group), 368 ADD_ONE_ERR_GROUP(0x050, per_core_ras_group), 369 ADD_ONE_ERR_GROUP(0x060, per_core_ras_group), 370 ADD_ONE_ERR_GROUP(0x070, per_core_ras_group), 371 372 /* 373 * Per cluster ras error records 374 * ERRSELR starts from 2*256 + Logical_Cluster_ID*16 + 0 to 375 * 2*256 + Logical_Cluster_ID*16 + 3. 376 * 4 clusters/groups, 3 * 4 nodes in total. 377 */ 378 ADD_ONE_ERR_GROUP(0x200, per_cluster_ras_group), 379 ADD_ONE_ERR_GROUP(0x210, per_cluster_ras_group), 380 ADD_ONE_ERR_GROUP(0x220, per_cluster_ras_group), 381 ADD_ONE_ERR_GROUP(0x230, per_cluster_ras_group), 382 383 /* 384 * SCF L3_Bank ras error records 385 * ERRSELR: 3*256 + L3_Bank_ID, L3_Bank_ID: 0-3 386 * 1 groups, 4 nodes in total. 387 */ 388 ADD_ONE_ERR_GROUP(0x300, scf_l3_ras_group), 389 390 /* 391 * CCPLEX ras error records 392 * ERRSELR: 4*256 + Unit_ID, Unit_ID: 0 - 4 393 * 1 groups, 5 nodes in total. 394 */ 395 ADD_ONE_ERR_GROUP(0x400, ccplex_ras_group), 396 }; 397 398 REGISTER_ERR_RECORD_INFO(carmel_ras_records); 399 400 /* dummy RAS interrupt */ 401 static struct ras_interrupt carmel_ras_interrupts[] = {}; 402 REGISTER_RAS_INTERRUPTS(carmel_ras_interrupts); 403 404 /******************************************************************************* 405 * RAS handler for the platform 406 ******************************************************************************/ 407 void plat_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie, 408 void *handle, uint64_t flags) 409 { 410 #if RAS_EXTENSION 411 tegra194_ea_handler(ea_reason, syndrome, cookie, handle, flags); 412 #else 413 ERROR("Unhandled External Abort received on 0x%llx at EL3!\n", 414 read_mpidr_el1()); 415 ERROR(" exception reason=%u syndrome=0x%lx\n", ea_reason, syndrome); 416 panic(); 417 #endif 418 } 419