xref: /openbmc/linux/drivers/firmware/smccc/smccc.c (revision 85250a24)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2020 Arm Limited
4  */
5 
6 #define pr_fmt(fmt) "smccc: " fmt
7 
8 #include <linux/cache.h>
9 #include <linux/init.h>
10 #include <linux/arm-smccc.h>
11 #include <linux/kernel.h>
12 #include <linux/platform_device.h>
13 #include <asm/archrandom.h>
14 
15 static u32 smccc_version = ARM_SMCCC_VERSION_1_0;
16 static enum arm_smccc_conduit smccc_conduit = SMCCC_CONDUIT_NONE;
17 
18 bool __ro_after_init smccc_trng_available = false;
19 u64 __ro_after_init smccc_has_sve_hint = false;
20 
21 void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit)
22 {
23 	smccc_version = version;
24 	smccc_conduit = conduit;
25 
26 	smccc_trng_available = smccc_probe_trng();
27 	if (IS_ENABLED(CONFIG_ARM64_SVE) &&
28 	    smccc_version >= ARM_SMCCC_VERSION_1_3)
29 		smccc_has_sve_hint = true;
30 }
31 
32 enum arm_smccc_conduit arm_smccc_1_1_get_conduit(void)
33 {
34 	if (smccc_version < ARM_SMCCC_VERSION_1_1)
35 		return SMCCC_CONDUIT_NONE;
36 
37 	return smccc_conduit;
38 }
39 EXPORT_SYMBOL_GPL(arm_smccc_1_1_get_conduit);
40 
41 u32 arm_smccc_get_version(void)
42 {
43 	return smccc_version;
44 }
45 EXPORT_SYMBOL_GPL(arm_smccc_get_version);
46 
47 static int __init smccc_devices_init(void)
48 {
49 	struct platform_device *pdev;
50 
51 	if (smccc_trng_available) {
52 		pdev = platform_device_register_simple("smccc_trng", -1,
53 						       NULL, 0);
54 		if (IS_ERR(pdev))
55 			pr_err("smccc_trng: could not register device: %ld\n",
56 			       PTR_ERR(pdev));
57 	}
58 
59 	return 0;
60 }
61 device_initcall(smccc_devices_init);
62