malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 1 | #include "cache-utils.h" |
| 2 | |
malc | e58ffeb | 2009-01-14 18:39:49 +0000 | [diff] [blame] | 3 | #if defined(_ARCH_PPC) |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 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__ |
malc | 4710036 | 2008-12-11 19:12:59 +0000 | [diff] [blame] | 19 | |
| 20 | #define QEMU_AT_NULL 0 |
| 21 | #define QEMU_AT_DCACHEBSIZE 19 |
| 22 | #define QEMU_AT_ICACHEBSIZE 20 |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 23 | |
| 24 | static void ppc_init_cacheline_sizes(char **envp) |
| 25 | { |
| 26 | unsigned long *auxv; |
| 27 | |
| 28 | while (*envp++); |
| 29 | |
malc | 4710036 | 2008-12-11 19:12:59 +0000 | [diff] [blame] | 30 | for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) { |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 31 | switch (*auxv) { |
malc | 807d517 | 2008-12-11 19:20:41 +0000 | [diff] [blame] | 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; |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 34 | default: break; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | #elif defined __APPLE__ |
malc | 7344da0 | 2009-02-04 20:39:09 +0000 | [diff] [blame] | 40 | #include <stdio.h> |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 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 | |
malc | 7344da0 | 2009-02-04 20:39:09 +0000 | [diff] [blame] | 50 | len = sizeof(cacheline); |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 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 | |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 60 | #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) |
Juergen Lock | 4836a2b | 2010-03-12 22:50:15 +0100 | [diff] [blame] | 61 | #include <errno.h> |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 62 | #include <stdio.h> |
Juergen Lock | 4836a2b | 2010-03-12 22:50:15 +0100 | [diff] [blame] | 63 | #include <stdlib.h> |
| 64 | #include <string.h> |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 65 | #include <sys/types.h> |
| 66 | #include <sys/sysctl.h> |
| 67 | |
| 68 | static void ppc_init_cacheline_sizes(void) |
| 69 | { |
| 70 | size_t len = 4; |
| 71 | unsigned cacheline; |
| 72 | |
| 73 | if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) { |
| 74 | fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n", |
| 75 | strerror(errno)); |
| 76 | exit(1); |
| 77 | } |
| 78 | |
| 79 | qemu_cache_conf.dcache_bsize = cacheline; |
| 80 | qemu_cache_conf.icache_bsize = cacheline; |
| 81 | } |
malc | 12b6278 | 2010-11-01 00:53:19 +0300 | [diff] [blame] | 82 | #endif |
Juergen Lock | e4ee916 | 2010-02-19 19:28:23 +0100 | [diff] [blame] | 83 | |
malc | 902b3d5 | 2008-12-10 19:18:40 +0000 | [diff] [blame] | 84 | #ifdef __linux__ |
| 85 | void qemu_cache_utils_init(char **envp) |
| 86 | { |
| 87 | ppc_init_cacheline_sizes(envp); |
| 88 | } |
| 89 | #else |
| 90 | void qemu_cache_utils_init(char **envp) |
| 91 | { |
| 92 | (void) envp; |
| 93 | ppc_init_cacheline_sizes(); |
| 94 | } |
| 95 | #endif |
| 96 | |
malc | e58ffeb | 2009-01-14 18:39:49 +0000 | [diff] [blame] | 97 | #endif /* _ARCH_PPC */ |