]>
Commit | Line | Data |
---|---|---|
902b3d5c | 1 | #include "cache-utils.h" |
2 | ||
e58ffeb3 | 3 | #if defined(_ARCH_PPC) |
902b3d5c | 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__ | |
4710036a | 19 | |
20 | #define QEMU_AT_NULL 0 | |
21 | #define QEMU_AT_DCACHEBSIZE 19 | |
22 | #define QEMU_AT_ICACHEBSIZE 20 | |
902b3d5c | 23 | |
24 | static void ppc_init_cacheline_sizes(char **envp) | |
25 | { | |
26 | unsigned long *auxv; | |
27 | ||
28 | while (*envp++); | |
29 | ||
4710036a | 30 | for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) { |
902b3d5c | 31 | switch (*auxv) { |
807d5170 | 32 | case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break; |
33 | case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break; | |
902b3d5c | 34 | default: break; |
35 | } | |
36 | } | |
37 | } | |
38 | ||
39 | #elif defined __APPLE__ | |
7344da06 | 40 | #include <stdio.h> |
902b3d5c | 41 | #include <sys/types.h> |
42 | #include <sys/sysctl.h> | |
43 | ||
44 | static void ppc_init_cacheline_sizes(void) | |
45 | { | |
46 | size_t len; | |
47 | unsigned cacheline; | |
48 | int name[2] = { CTL_HW, HW_CACHELINE }; | |
49 | ||
7344da06 | 50 | len = sizeof(cacheline); |
902b3d5c | 51 | if (sysctl(name, 2, &cacheline, &len, NULL, 0)) { |
52 | perror("sysctl CTL_HW HW_CACHELINE failed"); | |
53 | } else { | |
54 | qemu_cache_conf.dcache_bsize = cacheline; | |
55 | qemu_cache_conf.icache_bsize = cacheline; | |
56 | } | |
57 | } | |
58 | #endif | |
59 | ||
e4ee916d JL |
60 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
61 | #include <stdio.h> | |
62 | #include <sys/types.h> | |
63 | #include <sys/sysctl.h> | |
64 | ||
65 | static void ppc_init_cacheline_sizes(void) | |
66 | { | |
67 | size_t len = 4; | |
68 | unsigned cacheline; | |
69 | ||
70 | if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) { | |
71 | fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n", | |
72 | strerror(errno)); | |
73 | exit(1); | |
74 | } | |
75 | ||
76 | qemu_cache_conf.dcache_bsize = cacheline; | |
77 | qemu_cache_conf.icache_bsize = cacheline; | |
78 | } | |
79 | #endif | |
80 | ||
902b3d5c | 81 | #ifdef __linux__ |
82 | void qemu_cache_utils_init(char **envp) | |
83 | { | |
84 | ppc_init_cacheline_sizes(envp); | |
85 | } | |
86 | #else | |
87 | void qemu_cache_utils_init(char **envp) | |
88 | { | |
89 | (void) envp; | |
90 | ppc_init_cacheline_sizes(); | |
91 | } | |
92 | #endif | |
93 | ||
e58ffeb3 | 94 | #endif /* _ARCH_PPC */ |