11a8916eeSNayna Jain // SPDX-License-Identifier: GPL-2.0
21a8916eeSNayna Jain /*
31a8916eeSNayna Jain * Copyright (C) 2019 IBM Corporation
41a8916eeSNayna Jain * Author: Nayna Jain
51a8916eeSNayna Jain */
61a8916eeSNayna Jain #include <linux/types.h>
71a8916eeSNayna Jain #include <linux/of.h>
81a8916eeSNayna Jain #include <asm/secure_boot.h>
91a8916eeSNayna Jain
get_ppc_fw_sb_node(void)101a8916eeSNayna Jain static struct device_node *get_ppc_fw_sb_node(void)
111a8916eeSNayna Jain {
121a8916eeSNayna Jain static const struct of_device_id ids[] = {
131a8916eeSNayna Jain { .compatible = "ibm,secureboot", },
141a8916eeSNayna Jain { .compatible = "ibm,secureboot-v1", },
151a8916eeSNayna Jain { .compatible = "ibm,secureboot-v2", },
161a8916eeSNayna Jain {},
171a8916eeSNayna Jain };
181a8916eeSNayna Jain
191a8916eeSNayna Jain return of_find_matching_node(NULL, ids);
201a8916eeSNayna Jain }
211a8916eeSNayna Jain
is_ppc_secureboot_enabled(void)221a8916eeSNayna Jain bool is_ppc_secureboot_enabled(void)
231a8916eeSNayna Jain {
241a8916eeSNayna Jain struct device_node *node;
251a8916eeSNayna Jain bool enabled = false;
26*61f879d9SNayna Jain u32 secureboot;
271a8916eeSNayna Jain
281a8916eeSNayna Jain node = get_ppc_fw_sb_node();
291a8916eeSNayna Jain enabled = of_property_read_bool(node, "os-secureboot-enforcing");
301a8916eeSNayna Jain of_node_put(node);
311a8916eeSNayna Jain
32*61f879d9SNayna Jain if (enabled)
33*61f879d9SNayna Jain goto out;
34*61f879d9SNayna Jain
35*61f879d9SNayna Jain if (!of_property_read_u32(of_root, "ibm,secure-boot", &secureboot))
36*61f879d9SNayna Jain enabled = (secureboot > 1);
37*61f879d9SNayna Jain
38*61f879d9SNayna Jain out:
391a8916eeSNayna Jain pr_info("Secure boot mode %s\n", enabled ? "enabled" : "disabled");
401a8916eeSNayna Jain
411a8916eeSNayna Jain return enabled;
421a8916eeSNayna Jain }
432702809aSNayna Jain
is_ppc_trustedboot_enabled(void)442702809aSNayna Jain bool is_ppc_trustedboot_enabled(void)
452702809aSNayna Jain {
462702809aSNayna Jain struct device_node *node;
472702809aSNayna Jain bool enabled = false;
48*61f879d9SNayna Jain u32 trustedboot;
492702809aSNayna Jain
502702809aSNayna Jain node = get_ppc_fw_sb_node();
512702809aSNayna Jain enabled = of_property_read_bool(node, "trusted-enabled");
522702809aSNayna Jain of_node_put(node);
532702809aSNayna Jain
54*61f879d9SNayna Jain if (enabled)
55*61f879d9SNayna Jain goto out;
56*61f879d9SNayna Jain
57*61f879d9SNayna Jain if (!of_property_read_u32(of_root, "ibm,trusted-boot", &trustedboot))
58*61f879d9SNayna Jain enabled = (trustedboot > 0);
59*61f879d9SNayna Jain
60*61f879d9SNayna Jain out:
612702809aSNayna Jain pr_info("Trusted boot mode %s\n", enabled ? "enabled" : "disabled");
622702809aSNayna Jain
632702809aSNayna Jain return enabled;
642702809aSNayna Jain }
65