1 // SPDX-License-Identifier: GPL-2.0
3 * PowerNV code for secure variables
5 * Copyright (C) 2019 IBM Corporation
6 * Author: Claudio Carvalho
9 * APIs to access secure variables managed by OPAL.
12 #define pr_fmt(fmt) "secvar: "fmt
14 #include <linux/types.h>
15 #include <linux/platform_device.h>
16 #include <linux/of_platform.h>
18 #include <asm/secvar.h>
19 #include <asm/secure_boot.h>
21 static int opal_status_to_err(int rc)
29 case OPAL_UNSUPPORTED:
57 static int opal_get_variable(const char *key, uint64_t ksize,
58 u8 *data, uint64_t *dsize)
65 *dsize = cpu_to_be64(*dsize);
67 rc = opal_secvar_get(key, ksize, data, dsize);
69 *dsize = be64_to_cpu(*dsize);
71 return opal_status_to_err(rc);
74 static int opal_get_next_variable(const char *key, uint64_t *keylen,
82 *keylen = cpu_to_be64(*keylen);
84 rc = opal_secvar_get_next(key, keylen, keybufsize);
86 *keylen = be64_to_cpu(*keylen);
88 return opal_status_to_err(rc);
91 static int opal_set_variable(const char *key, uint64_t ksize, u8 *data,
99 rc = opal_secvar_enqueue_update(key, ksize, data, dsize);
101 return opal_status_to_err(rc);
104 static const struct secvar_operations opal_secvar_ops = {
105 .get = opal_get_variable,
106 .get_next = opal_get_next_variable,
107 .set = opal_set_variable,
110 static int opal_secvar_probe(struct platform_device *pdev)
112 if (!opal_check_token(OPAL_SECVAR_GET)
113 || !opal_check_token(OPAL_SECVAR_GET_NEXT)
114 || !opal_check_token(OPAL_SECVAR_ENQUEUE_UPDATE)) {
115 pr_err("OPAL doesn't support secure variables\n");
119 set_secvar_ops(&opal_secvar_ops);
124 static const struct of_device_id opal_secvar_match[] = {
125 { .compatible = "ibm,secvar-backend",},
129 static struct platform_driver opal_secvar_driver = {
132 .of_match_table = opal_secvar_match,
136 static int __init opal_secvar_init(void)
138 return platform_driver_probe(&opal_secvar_driver, opal_secvar_probe);
140 device_initcall(opal_secvar_init);