aarch64: refactor HW ARM CRC32c detection
[fio.git] / os / os-linux.h
index 894dc850904f0717d745ac61ce2805e349aff210..1d400a0d3aed1d10a31e564513ff19a1d92669f3 100644 (file)
 #include <linux/fs.h>
 #include <scsi/sg.h>
 
+#ifdef ARCH_HAVE_CRC_CRYPTO
+#include <sys/auxv.h>
+#ifndef HWCAP_CRC32
+#define HWCAP_CRC32             (1 << 7)
+#endif /* HWCAP_CRC32 */
+#endif /* ARCH_HAVE_CRC_CRYPTO */
+
 #include "./os-linux-syscall.h"
 #include "binject.h"
 #include "../file.h"
@@ -410,4 +417,24 @@ static inline bool fio_fallocate(struct fio_file *f, uint64_t offset,
 }
 #endif
 
+#define FIO_HAVE_CPU_HAS
+static inline bool os_cpu_has(cpu_features feature)
+{
+       bool have_feature;
+       unsigned long fio_unused hwcap;
+
+       switch (feature) {
+#ifdef ARCH_HAVE_CRC_CRYPTO
+       case CPU_ARM64_CRC32C:
+               hwcap = getauxval(AT_HWCAP);
+               have_feature = (hwcap & HWCAP_CRC32) != 0;
+               break;
+#endif
+       default:
+               have_feature = false;
+       }
+
+       return have_feature;
+}
+
 #endif