Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / arch / arm.c
1 #include "acconfig.h"
2 #include "arch/probe.h"
3
4 /* flags we export */
5 int ceph_arch_neon = 0;
6 int ceph_arch_aarch64_crc32 = 0;
7
8 #include <stdio.h>
9
10 #if __linux__
11
12 #include <elf.h>
13 #include <link.h> // ElfW macro
14
15 #if __arm__ || __aarch64__
16 #include <asm/hwcap.h>
17 #endif // __arm__
18
19 static unsigned long get_auxval(unsigned long type)
20 {
21         unsigned long result = 0;
22         FILE *f = fopen("/proc/self/auxv", "r");
23         if (f) {
24                 ElfW(auxv_t) entry;
25                 while (fread(&entry, sizeof(entry), 1, f) == 1) {
26                         if (entry.a_type == type) {
27                                 result = entry.a_un.a_val;
28                                 break;
29                         }
30                 }
31                 fclose(f);
32         }
33         return result;
34 }
35
36 static unsigned long get_hwcap(void)
37 {
38         return get_auxval(AT_HWCAP);
39 }
40
41 #endif // __linux__
42
43 int ceph_arch_arm_probe(void)
44 {
45 #if __arm__ && __linux__
46         ceph_arch_neon = (get_hwcap() & HWCAP_NEON) == HWCAP_NEON;
47 #elif __aarch64__ && __linux__
48         ceph_arch_neon = (get_hwcap() & HWCAP_ASIMD) == HWCAP_ASIMD;
49 # if defined(HAVE_ARMV8_CRC) && defined(HWCAP_CRC32)
50         ceph_arch_aarch64_crc32 = (get_hwcap() & HWCAP_CRC32) == HWCAP_CRC32;
51 # endif
52 #else
53         if (0)
54                 get_hwcap();  // make compiler shut up
55 #endif
56         return 0;
57 }
58