1*0297e91bSJoel Stanley // SPDX-License-Identifier: GPL-2.0-or-later
2*0297e91bSJoel Stanley /* Copyright 2022 IBM Corp. */
3*0297e91bSJoel Stanley
4*0297e91bSJoel Stanley #include <linux/io.h>
5*0297e91bSJoel Stanley #include <linux/of.h>
6*0297e91bSJoel Stanley #include <linux/of_address.h>
7*0297e91bSJoel Stanley #include <linux/of_platform.h>
8*0297e91bSJoel Stanley #include <linux/debugfs.h>
9*0297e91bSJoel Stanley
10*0297e91bSJoel Stanley #define SEC_STATUS 0x14
11*0297e91bSJoel Stanley #define ABR_IMAGE_SOURCE BIT(13)
12*0297e91bSJoel Stanley #define OTP_PROTECTED BIT(8)
13*0297e91bSJoel Stanley #define LOW_SEC_KEY BIT(7)
14*0297e91bSJoel Stanley #define SECURE_BOOT BIT(6)
15*0297e91bSJoel Stanley #define UART_BOOT BIT(5)
16*0297e91bSJoel Stanley
17*0297e91bSJoel Stanley struct sbe {
18*0297e91bSJoel Stanley u8 abr_image;
19*0297e91bSJoel Stanley u8 low_security_key;
20*0297e91bSJoel Stanley u8 otp_protected;
21*0297e91bSJoel Stanley u8 secure_boot;
22*0297e91bSJoel Stanley u8 invert;
23*0297e91bSJoel Stanley u8 uart_boot;
24*0297e91bSJoel Stanley };
25*0297e91bSJoel Stanley
26*0297e91bSJoel Stanley static struct sbe sbe;
27*0297e91bSJoel Stanley
aspeed_sbc_init(void)28*0297e91bSJoel Stanley static int __init aspeed_sbc_init(void)
29*0297e91bSJoel Stanley {
30*0297e91bSJoel Stanley struct device_node *np;
31*0297e91bSJoel Stanley void __iomem *base;
32*0297e91bSJoel Stanley struct dentry *sbc_dir;
33*0297e91bSJoel Stanley u32 security_status;
34*0297e91bSJoel Stanley
35*0297e91bSJoel Stanley /* AST2600 only */
36*0297e91bSJoel Stanley np = of_find_compatible_node(NULL, NULL, "aspeed,ast2600-sbc");
37*0297e91bSJoel Stanley if (!of_device_is_available(np))
38*0297e91bSJoel Stanley return -ENODEV;
39*0297e91bSJoel Stanley
40*0297e91bSJoel Stanley base = of_iomap(np, 0);
41*0297e91bSJoel Stanley if (!base) {
42*0297e91bSJoel Stanley of_node_put(np);
43*0297e91bSJoel Stanley return -ENODEV;
44*0297e91bSJoel Stanley }
45*0297e91bSJoel Stanley
46*0297e91bSJoel Stanley security_status = readl(base + SEC_STATUS);
47*0297e91bSJoel Stanley
48*0297e91bSJoel Stanley iounmap(base);
49*0297e91bSJoel Stanley of_node_put(np);
50*0297e91bSJoel Stanley
51*0297e91bSJoel Stanley sbe.abr_image = !!(security_status & ABR_IMAGE_SOURCE);
52*0297e91bSJoel Stanley sbe.low_security_key = !!(security_status & LOW_SEC_KEY);
53*0297e91bSJoel Stanley sbe.otp_protected = !!(security_status & OTP_PROTECTED);
54*0297e91bSJoel Stanley sbe.secure_boot = !!(security_status & SECURE_BOOT);
55*0297e91bSJoel Stanley /* Invert the bit, as 1 is boot from SPI/eMMC */
56*0297e91bSJoel Stanley sbe.uart_boot = !(security_status & UART_BOOT);
57*0297e91bSJoel Stanley
58*0297e91bSJoel Stanley pr_info("AST2600 secure boot %s\n", sbe.secure_boot ? "enabled" : "disabled");
59*0297e91bSJoel Stanley
60*0297e91bSJoel Stanley sbc_dir = debugfs_create_dir("sbc", arch_debugfs_dir);
61*0297e91bSJoel Stanley if (IS_ERR(sbc_dir))
62*0297e91bSJoel Stanley return PTR_ERR(sbc_dir);
63*0297e91bSJoel Stanley
64*0297e91bSJoel Stanley debugfs_create_u8("abr_image", 0444, sbc_dir, &sbe.abr_image);
65*0297e91bSJoel Stanley debugfs_create_u8("low_security_key", 0444, sbc_dir, &sbe.low_security_key);
66*0297e91bSJoel Stanley debugfs_create_u8("otp_protected", 0444, sbc_dir, &sbe.otp_protected);
67*0297e91bSJoel Stanley debugfs_create_u8("uart_boot", 0444, sbc_dir, &sbe.uart_boot);
68*0297e91bSJoel Stanley debugfs_create_u8("secure_boot", 0444, sbc_dir, &sbe.secure_boot);
69*0297e91bSJoel Stanley
70*0297e91bSJoel Stanley return 0;
71*0297e91bSJoel Stanley }
72*0297e91bSJoel Stanley
73*0297e91bSJoel Stanley subsys_initcall(aspeed_sbc_init);
74