xref: /arm-trusted-firmware/plat/marvell/armada/a3k/common/a3700_ea.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (C) 2019 Repk repk@triplefau.lt
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier:	BSD-3-Clause
5*91f16700Schasinglulu  * https://spdx.org/licenses
6*91f16700Schasinglulu  */
7*91f16700Schasinglulu 
8*91f16700Schasinglulu #include <inttypes.h>
9*91f16700Schasinglulu #include <stdint.h>
10*91f16700Schasinglulu 
11*91f16700Schasinglulu #include <common/bl_common.h>
12*91f16700Schasinglulu #include <common/debug.h>
13*91f16700Schasinglulu #include <arch_helpers.h>
14*91f16700Schasinglulu #include <plat/common/platform.h>
15*91f16700Schasinglulu #include <bl31/ea_handle.h>
16*91f16700Schasinglulu 
17*91f16700Schasinglulu #define A53_SERR_INT_AXI_SLVERR_ON_EXTERNAL_ACCESS 0xbf000002
18*91f16700Schasinglulu 
19*91f16700Schasinglulu /*
20*91f16700Schasinglulu  * This source file with custom plat_ea_handler function is compiled only when
21*91f16700Schasinglulu  * building TF-A with compile option HANDLE_EA_EL3_FIRST_NS=1
22*91f16700Schasinglulu  */
23*91f16700Schasinglulu void plat_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
24*91f16700Schasinglulu 		void *handle, uint64_t flags)
25*91f16700Schasinglulu {
26*91f16700Schasinglulu 	unsigned int level = (unsigned int)GET_EL(read_spsr_el3());
27*91f16700Schasinglulu 
28*91f16700Schasinglulu 	/*
29*91f16700Schasinglulu 	 * Asynchronous External Abort with syndrome 0xbf000002 on Cortex A53
30*91f16700Schasinglulu 	 * core means SError interrupt caused by AXI SLVERR on external access.
31*91f16700Schasinglulu 	 *
32*91f16700Schasinglulu 	 * In most cases this indicates a bug in U-Boot or Linux kernel driver
33*91f16700Schasinglulu 	 * pci-aardvark.c which implements access to A3700 PCIe config space.
34*91f16700Schasinglulu 	 * Driver does not wait for PCIe PIO transfer completion and try to
35*91f16700Schasinglulu 	 * start a new PCIe PIO transfer while previous has not finished yet.
36*91f16700Schasinglulu 	 * A3700 PCIe controller in this case sends SLVERR via AXI which results
37*91f16700Schasinglulu 	 * in a fatal Asynchronous SError interrupt on Cortex A53 CPU.
38*91f16700Schasinglulu 	 *
39*91f16700Schasinglulu 	 * Following patches fix that bug in U-Boot and Linux kernel drivers:
40*91f16700Schasinglulu 	 * https://source.denx.de/u-boot/u-boot/-/commit/eccbd4ad8e4e182638eafbfb87ac139c04f24a01
41*91f16700Schasinglulu 	 * https://git.kernel.org/stable/c/f18139966d072dab8e4398c95ce955a9742e04f7
42*91f16700Schasinglulu 	 *
43*91f16700Schasinglulu 	 * As a hacky workaround for unpatched U-Boot and Linux kernel drivers
44*91f16700Schasinglulu 	 * ignore all asynchronous aborts with that syndrome value received on
45*91f16700Schasinglulu 	 * CPU from level lower than EL3.
46*91f16700Schasinglulu 	 *
47*91f16700Schasinglulu 	 * Because these aborts are delivered on CPU asynchronously, they are
48*91f16700Schasinglulu 	 * imprecise and we cannot check the real reason of abort and neither
49*91f16700Schasinglulu 	 * who and why sent this abort. We expect that on A3700 it is always
50*91f16700Schasinglulu 	 * PCIe controller.
51*91f16700Schasinglulu 	 *
52*91f16700Schasinglulu 	 * Hence ignoring all aborts with this syndrome value is just a giant
53*91f16700Schasinglulu 	 * hack that we need only because of bugs in old U-Boot and Linux kernel
54*91f16700Schasinglulu 	 * versions and because it was decided that TF-A would implement this
55*91f16700Schasinglulu 	 * hack for U-Boot and Linux kernel it in this way. New patched U-Boot
56*91f16700Schasinglulu 	 * and kernel versions do not need it anymore.
57*91f16700Schasinglulu 	 *
58*91f16700Schasinglulu 	 * Links to discussion about this workaround:
59*91f16700Schasinglulu 	 * https://lore.kernel.org/linux-pci/20190316161243.29517-1-repk@triplefau.lt/
60*91f16700Schasinglulu 	 * https://lore.kernel.org/linux-pci/971be151d24312cc533989a64bd454b4@www.loen.fr/
61*91f16700Schasinglulu 	 * https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/1541
62*91f16700Schasinglulu 	 */
63*91f16700Schasinglulu 	if (level < MODE_EL3 && ea_reason == ERROR_EA_ASYNC &&
64*91f16700Schasinglulu 	    syndrome == A53_SERR_INT_AXI_SLVERR_ON_EXTERNAL_ACCESS) {
65*91f16700Schasinglulu 		ERROR_NL();
66*91f16700Schasinglulu 		ERROR("Ignoring Asynchronous External Abort with"
67*91f16700Schasinglulu 		     " syndrome 0x%" PRIx64 " received on 0x%lx from %s\n",
68*91f16700Schasinglulu 		     syndrome, read_mpidr_el1(), get_el_str(level));
69*91f16700Schasinglulu 		ERROR("SError interrupt: AXI SLVERR on external access\n");
70*91f16700Schasinglulu 		ERROR("This indicates a bug in pci-aardvark.c driver\n");
71*91f16700Schasinglulu 		ERROR("Please update U-Boot/Linux to the latest version\n");
72*91f16700Schasinglulu 		ERROR_NL();
73*91f16700Schasinglulu 		console_flush();
74*91f16700Schasinglulu 		return;
75*91f16700Schasinglulu 	}
76*91f16700Schasinglulu 
77*91f16700Schasinglulu 	plat_default_ea_handler(ea_reason, syndrome, cookie, handle, flags);
78*91f16700Schasinglulu }
79