1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2019 IBM Corporation
4  * Author: Nayna Jain
5  */
6 #include <linux/types.h>
7 #include <linux/of.h>
8 #include <asm/secure_boot.h>
9 
10 static struct device_node *get_ppc_fw_sb_node(void)
11 {
12 	static const struct of_device_id ids[] = {
13 		{ .compatible = "ibm,secureboot", },
14 		{ .compatible = "ibm,secureboot-v1", },
15 		{ .compatible = "ibm,secureboot-v2", },
16 		{},
17 	};
18 
19 	return of_find_matching_node(NULL, ids);
20 }
21 
22 bool is_ppc_secureboot_enabled(void)
23 {
24 	struct device_node *node;
25 	bool enabled = false;
26 
27 	node = get_ppc_fw_sb_node();
28 	enabled = of_property_read_bool(node, "os-secureboot-enforcing");
29 
30 	of_node_put(node);
31 
32 	pr_info("Secure boot mode %s\n", enabled ? "enabled" : "disabled");
33 
34 	return enabled;
35 }
36 
37 bool is_ppc_trustedboot_enabled(void)
38 {
39 	struct device_node *node;
40 	bool enabled = false;
41 
42 	node = get_ppc_fw_sb_node();
43 	enabled = of_property_read_bool(node, "trusted-enabled");
44 
45 	of_node_put(node);
46 
47 	pr_info("Trusted boot mode %s\n", enabled ? "enabled" : "disabled");
48 
49 	return enabled;
50 }
51