crypto: x86/sha - load modules based on CPU features
[platform/kernel/linux-starfive.git] / arch / x86 / crypto / sha1_ssse3_glue.c
index 44340a1..959afa7 100644 (file)
 #include <linux/types.h>
 #include <crypto/sha1.h>
 #include <crypto/sha1_base.h>
+#include <asm/cpu_device_id.h>
 #include <asm/simd.h>
 
+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 sha1_update(struct shash_desc *desc, const u8 *data,
                             unsigned int len, sha1_block_fn *sha1_xform)
 {
@@ -301,6 +310,9 @@ static inline void unregister_sha1_ni(void) { }
 
 static int __init sha1_ssse3_mod_init(void)
 {
+       if (!x86_match_cpu(module_cpu_ids))
+               return -ENODEV;
+
        if (register_sha1_ssse3())
                goto fail;