diff mbox series

[v3] firmware: psci: Do not bind driver if U-Boot runs in EL3

Message ID e877cd272916a9802366d5c49e98be1ac35abbf0.1597315400.git.michal.simek@xilinx.com
State Accepted
Commit 10e4d64e345b6b684d27d3da6ed8d887c8e45f76
Delegated to: Tom Rini
Headers show
Series [v3] firmware: psci: Do not bind driver if U-Boot runs in EL3 | expand

Commit Message

Michal Simek Aug. 13, 2020, 10:43 a.m. UTC
There is no reason to bind psci driver if U-Boot runs in EL3 because
SMC/HVC instructions can't be called. That's why detect this state and
don't let user to crash from prompt by performing reset or poweroff
commands (if enabled).

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

Changes in v3:
- guard for ARM64 which implements current_el(). Qemu arm was failing in CI loop
  there is no way to use if (CONFIG_IS_ENABLED because current_el() is not
  defined for arm32

Changes in v2:
- Add missing asm/system.h header

Maybe there is a better way how to do it. Maybe do it in probe instead of
bind. Feel free to comment but this doesn't look right behavior.

Before:

U-Boot SPL 2020.10-rc2-00032-gede802a09435 (Aug 12 2020 - 09:17:01 +0200)
PMUFW:	v1.1
Loading new PMUFW cfg obj (2024 bytes)
EL Level:	EL3
Multiboot:	0
Trying to boot from MMC2
spl: could not initialize mmc. error: -19
Trying to boot from MMC1
spl_load_image_fat_os: error reading image u-boot.bin, err - -2

U-Boot 2020.10-rc2-00032-gede802a09435 (Aug 12 2020 - 09:17:01 +0200)

Model: ZynqMP ZCU104 RevC
Board: Xilinx ZynqMP
DRAM:  2 GiB
PMUFW:	v1.1
EL Level:	EL3
Chip ID:	zu7e
Multiboot:	0
WDT:   Started with servicing (60s timeout)
NAND:  0 MiB
MMC:   mmc@ff170000: 0
In:    serial@ff000000
Out:   serial@ff000000
Err:   serial@ff000000
Bootmode: LVL_SHFT_SD_MODE1
Reset reason:	EXTERNAL
Net:
ZYNQ GEM: ff0e0000, mdio bus ff0e0000, phyaddr 12, interface rgmii-id
eth0: ethernet@ff0e0000
Hit any key to stop autoboot:  0
ZynqMP> reset
resetting ...
"Synchronous Abort" handler, esr 0x5e000000
elr: 0000000008000194 lr : 0000000008000220 (reloc)
elr: 000000007fec9194 lr : 000000007fec9220
x0 : 0000000084000009 x1 : 0000000000000000
x2 : 0000000000000000 x3 : 0000000000000000
x4 : 0000000000000000 x5 : 0000000000000000
x6 : 0000000000000000 x7 : 0000000000000000
x8 : 000000007deaedb0 x9 : 000000000000000c
x10: 00000000000007c4 x11: 000000007deae92c
x12: 0000000000000006 x13: 000000000001869f
x14: 000000007deaedb0 x15: 0000000000000002
x16: 000000007ff2b20c x17: 0000000000000000
x18: 000000007deb8db0 x19: 0000000000000000
x20: 000000007ffb0ae0 x21: 0000000000000000
x22: 000000007debc600 x23: 0000000000000001
x24: 000000007ffc8158 x25: 0000000000000000
x26: 0000000000000000 x27: 0000000000000000
x28: 000000007debc640 x29: 000000007deaeaf0

Code: 00000000 f9020000 00000000 d4000003 (f94003e4)
Resetting CPU ...

 ### ERROR ### Please RESET the board ###

After:

U-Boot SPL 2020.10-rc2-00033-g952b21dcb4b3 (Aug 12 2020 - 09:18:56 +0200)
PMUFW:	v1.1
Loading new PMUFW cfg obj (2024 bytes)
EL Level:	EL3
Multiboot:	0
Trying to boot from MMC2
spl: could not initialize mmc. error: -19
Trying to boot from MMC1
spl_load_image_fat_os: error reading image u-boot.bin, err - -2

U-Boot 2020.10-rc2-00033-g952b21dcb4b3 (Aug 12 2020 - 09:18:56 +0200)

Model: ZynqMP ZCU104 RevC
Board: Xilinx ZynqMP
DRAM:  2 GiB
PMUFW:	v1.1
EL Level:	EL3
Chip ID:	zu7e
Multiboot:	0
WDT:   Started with servicing (60s timeout)
NAND:  0 MiB
MMC:   mmc@ff170000: 0
In:    serial@ff000000
Out:   serial@ff000000
Err:   serial@ff000000
Bootmode: LVL_SHFT_SD_MODE1
Reset reason:	EXTERNAL
Net:
ZYNQ GEM: ff0e0000, mdio bus ff0e0000, phyaddr 12, interface rgmii-id
eth0: ethernet@ff0e0000
Hit any key to stop autoboot:  0
ZynqMP>
ZynqMP> reset
resetting ...
ZynqMP>

---
 drivers/firmware/psci.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Tom Rini Aug. 25, 2020, 12:15 p.m. UTC | #1
On Thu, Aug 13, 2020 at 12:43:22PM +0200, Michal Simek wrote:

> There is no reason to bind psci driver if U-Boot runs in EL3 because
> SMC/HVC instructions can't be called. That's why detect this state and
> don't let user to crash from prompt by performing reset or poweroff
> commands (if enabled).
> 
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/firmware/psci.c b/drivers/firmware/psci.c
index 7d2e49fd3e3b..68953cc4f4e2 100644
--- a/drivers/firmware/psci.c
+++ b/drivers/firmware/psci.c
@@ -19,6 +19,7 @@ 
 #include <linux/errno.h>
 #include <linux/printk.h>
 #include <linux/psci.h>
+#include <asm/system.h>
 
 #define DRIVER_NAME "psci"
 
@@ -73,6 +74,11 @@  static int psci_probe(struct udevice *dev)
 {
 	const char *method;
 
+#if defined(CONFIG_ARM64)
+	if (current_el() == 3)
+		return -EINVAL;
+#endif
+
 	method = ofnode_read_string(dev_ofnode(dev), "method");
 	if (!method) {
 		pr_warn("missing \"method\" property\n");