Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright (C) 2020 Arm Limited
0004  */
0005 
0006 #define pr_fmt(fmt) "smccc: " fmt
0007 
0008 #include <linux/cache.h>
0009 #include <linux/init.h>
0010 #include <linux/arm-smccc.h>
0011 #include <linux/kernel.h>
0012 #include <linux/platform_device.h>
0013 #include <asm/archrandom.h>
0014 
0015 static u32 smccc_version = ARM_SMCCC_VERSION_1_0;
0016 static enum arm_smccc_conduit smccc_conduit = SMCCC_CONDUIT_NONE;
0017 
0018 bool __ro_after_init smccc_trng_available = false;
0019 u64 __ro_after_init smccc_has_sve_hint = false;
0020 
0021 void __init arm_smccc_version_init(u32 version, enum arm_smccc_conduit conduit)
0022 {
0023     smccc_version = version;
0024     smccc_conduit = conduit;
0025 
0026     smccc_trng_available = smccc_probe_trng();
0027     if (IS_ENABLED(CONFIG_ARM64_SVE) &&
0028         smccc_version >= ARM_SMCCC_VERSION_1_3)
0029         smccc_has_sve_hint = true;
0030 }
0031 
0032 enum arm_smccc_conduit arm_smccc_1_1_get_conduit(void)
0033 {
0034     if (smccc_version < ARM_SMCCC_VERSION_1_1)
0035         return SMCCC_CONDUIT_NONE;
0036 
0037     return smccc_conduit;
0038 }
0039 EXPORT_SYMBOL_GPL(arm_smccc_1_1_get_conduit);
0040 
0041 u32 arm_smccc_get_version(void)
0042 {
0043     return smccc_version;
0044 }
0045 EXPORT_SYMBOL_GPL(arm_smccc_get_version);
0046 
0047 static int __init smccc_devices_init(void)
0048 {
0049     struct platform_device *pdev;
0050 
0051     if (smccc_trng_available) {
0052         pdev = platform_device_register_simple("smccc_trng", -1,
0053                                NULL, 0);
0054         if (IS_ERR(pdev))
0055             pr_err("smccc_trng: could not register device: %ld\n",
0056                    PTR_ERR(pdev));
0057     }
0058 
0059     return 0;
0060 }
0061 device_initcall(smccc_devices_init);