0b4a5acb82f12fdda225bd602be6d0ae000125e8
[qemu] / cache-utils.c
1 #include "cache-utils.h"
2
3 #ifdef __powerpc__
4 struct qemu_cache_conf qemu_cache_conf = {
5     .dcache_bsize = 16,
6     .icache_bsize = 16
7 };
8
9 #if defined _AIX
10 #include <sys/systemcfg.h>
11
12 static void ppc_init_cacheline_sizes(void)
13 {
14     qemu_cache_conf.icache_bsize = _system_configuration.icache_line;
15     qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line;
16 }
17
18 #elif defined __linux__
19 #include <linux/auxvec.h>
20
21 static void ppc_init_cacheline_sizes(char **envp)
22 {
23     unsigned long *auxv;
24
25     while (*envp++);
26
27     for (auxv = (unsigned long *) envp; *auxv != AT_NULL; auxv += 2) {
28         switch (*auxv) {
29         case AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
30         case AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
31         default: break;
32         }
33     }
34 }
35
36 #elif defined __APPLE__
37 #include <sys/types.h>
38 #include <sys/sysctl.h>
39
40 static void ppc_init_cacheline_sizes(void)
41 {
42     size_t len;
43     unsigned cacheline;
44     int name[2] = { CTL_HW, HW_CACHELINE };
45
46     if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
47         perror("sysctl CTL_HW HW_CACHELINE failed");
48     } else {
49         qemu_cache_conf.dcache_bsize = cacheline;
50         qemu_cache_conf.icache_bsize = cacheline;
51     }
52 }
53 #endif
54
55 #ifdef __linux__
56 void qemu_cache_utils_init(char **envp)
57 {
58     ppc_init_cacheline_sizes(envp);
59 }
60 #else
61 void qemu_cache_utils_init(char **envp)
62 {
63     (void) envp;
64     ppc_init_cacheline_sizes();
65 }
66 #endif
67
68 #endif /* __powerpc__ */