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