root / cache-utils.c @ a8a358bf
History | View | Annotate | Download (1.6 kB)
1 | 902b3d5c | malc | #include "cache-utils.h" |
---|---|---|---|
2 | 902b3d5c | malc | |
3 | e58ffeb3 | malc | #if defined(_ARCH_PPC)
|
4 | 902b3d5c | malc | struct qemu_cache_conf qemu_cache_conf = {
|
5 | 902b3d5c | malc | .dcache_bsize = 16,
|
6 | 902b3d5c | malc | .icache_bsize = 16
|
7 | 902b3d5c | malc | }; |
8 | 902b3d5c | malc | |
9 | 902b3d5c | malc | #if defined _AIX
|
10 | 902b3d5c | malc | #include <sys/systemcfg.h> |
11 | 902b3d5c | malc | |
12 | 902b3d5c | malc | static void ppc_init_cacheline_sizes(void) |
13 | 902b3d5c | malc | { |
14 | 902b3d5c | malc | qemu_cache_conf.icache_bsize = _system_configuration.icache_line; |
15 | 902b3d5c | malc | qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line; |
16 | 902b3d5c | malc | } |
17 | 902b3d5c | malc | |
18 | 902b3d5c | malc | #elif defined __linux__
|
19 | 4710036a | malc | |
20 | 4710036a | malc | #define QEMU_AT_NULL 0 |
21 | 4710036a | malc | #define QEMU_AT_DCACHEBSIZE 19 |
22 | 4710036a | malc | #define QEMU_AT_ICACHEBSIZE 20 |
23 | 902b3d5c | malc | |
24 | 902b3d5c | malc | static void ppc_init_cacheline_sizes(char **envp) |
25 | 902b3d5c | malc | { |
26 | 902b3d5c | malc | unsigned long *auxv; |
27 | 902b3d5c | malc | |
28 | 902b3d5c | malc | while (*envp++);
|
29 | 902b3d5c | malc | |
30 | 4710036a | malc | for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) { |
31 | 902b3d5c | malc | switch (*auxv) {
|
32 | 807d5170 | malc | case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break; |
33 | 807d5170 | malc | case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break; |
34 | 902b3d5c | malc | default: break; |
35 | 902b3d5c | malc | } |
36 | 902b3d5c | malc | } |
37 | 902b3d5c | malc | } |
38 | 902b3d5c | malc | |
39 | 902b3d5c | malc | #elif defined __APPLE__
|
40 | 7344da06 | malc | #include <stdio.h> |
41 | 902b3d5c | malc | #include <sys/types.h> |
42 | 902b3d5c | malc | #include <sys/sysctl.h> |
43 | 902b3d5c | malc | |
44 | 902b3d5c | malc | static void ppc_init_cacheline_sizes(void) |
45 | 902b3d5c | malc | { |
46 | 902b3d5c | malc | size_t len; |
47 | 902b3d5c | malc | unsigned cacheline;
|
48 | 902b3d5c | malc | int name[2] = { CTL_HW, HW_CACHELINE }; |
49 | 902b3d5c | malc | |
50 | 7344da06 | malc | len = sizeof(cacheline);
|
51 | 902b3d5c | malc | if (sysctl(name, 2, &cacheline, &len, NULL, 0)) { |
52 | 902b3d5c | malc | perror("sysctl CTL_HW HW_CACHELINE failed");
|
53 | 902b3d5c | malc | } else {
|
54 | 902b3d5c | malc | qemu_cache_conf.dcache_bsize = cacheline; |
55 | 902b3d5c | malc | qemu_cache_conf.icache_bsize = cacheline; |
56 | 902b3d5c | malc | } |
57 | 902b3d5c | malc | } |
58 | 902b3d5c | malc | #endif
|
59 | 902b3d5c | malc | |
60 | 902b3d5c | malc | #ifdef __linux__
|
61 | 902b3d5c | malc | void qemu_cache_utils_init(char **envp) |
62 | 902b3d5c | malc | { |
63 | 902b3d5c | malc | ppc_init_cacheline_sizes(envp); |
64 | 902b3d5c | malc | } |
65 | 902b3d5c | malc | #else
|
66 | 902b3d5c | malc | void qemu_cache_utils_init(char **envp) |
67 | 902b3d5c | malc | { |
68 | 902b3d5c | malc | (void) envp;
|
69 | 902b3d5c | malc | ppc_init_cacheline_sizes(); |
70 | 902b3d5c | malc | } |
71 | 902b3d5c | malc | #endif
|
72 | 902b3d5c | malc | |
73 | e58ffeb3 | malc | #endif /* _ARCH_PPC */ |