crypto: x86/sha - load modules based on CPU features
[platform/kernel/linux-starfive.git] / arch / x86 / crypto / sha256_ssse3_glue.c
index 3a5f6be..d25235f 100644 (file)
 #include <crypto/sha2.h>
 #include <crypto/sha256_base.h>
 #include <linux/string.h>
+#include <asm/cpu_device_id.h>
 #include <asm/simd.h>
 
 asmlinkage void sha256_transform_ssse3(struct sha256_state *state,
                                       const u8 *data, int blocks);
 
+static const struct x86_cpu_id module_cpu_ids[] = {
+       X86_MATCH_FEATURE(X86_FEATURE_AVX2, NULL),
+       X86_MATCH_FEATURE(X86_FEATURE_AVX, NULL),
+       X86_MATCH_FEATURE(X86_FEATURE_SSSE3, NULL),
+       {}
+};
+MODULE_DEVICE_TABLE(x86cpu, module_cpu_ids);
+
 static int _sha256_update(struct shash_desc *desc, const u8 *data,
                          unsigned int len, sha256_block_fn *sha256_xform)
 {
@@ -366,6 +375,9 @@ static inline void unregister_sha256_ni(void) { }
 
 static int __init sha256_ssse3_mod_init(void)
 {
+       if (!x86_match_cpu(module_cpu_ids))
+               return -ENODEV;
+
        if (register_sha256_ssse3())
                goto fail;