Fix the size of the property fields.
[qemu/navara.git] / cache-utils.c
blobe1e4c82681a768f5f53996a25fc6e03d30a56af0
1 #include <stdint.h>
2 #include "cache-utils.h"
4 #if defined(_ARCH_PPC)
5 struct qemu_cache_conf qemu_cache_conf = {
6 .dcache_bsize = 16,
7 .icache_bsize = 16
8 };
10 #if defined _AIX
11 #include <sys/systemcfg.h>
13 static void ppc_init_cacheline_sizes(void)
15 qemu_cache_conf.icache_bsize = _system_configuration.icache_line;
16 qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line;
19 #elif defined __linux__
21 #define QEMU_AT_NULL 0
22 #define QEMU_AT_DCACHEBSIZE 19
23 #define QEMU_AT_ICACHEBSIZE 20
25 static void ppc_init_cacheline_sizes(char **envp)
27 unsigned long *auxv;
29 while (*envp++);
31 for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
32 switch (*auxv) {
33 case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
34 case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
35 default: break;
40 #elif defined __APPLE__
41 #include <stdio.h>
42 #include <sys/types.h>
43 #include <sys/sysctl.h>
45 static void ppc_init_cacheline_sizes(void)
47 size_t len;
48 unsigned cacheline;
49 int name[2] = { CTL_HW, HW_CACHELINE };
51 len = sizeof(cacheline);
52 if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
53 perror("sysctl CTL_HW HW_CACHELINE failed");
54 } else {
55 qemu_cache_conf.dcache_bsize = cacheline;
56 qemu_cache_conf.icache_bsize = cacheline;
59 #endif
61 #ifdef __linux__
62 void qemu_cache_utils_init(char **envp)
64 ppc_init_cacheline_sizes(envp);
66 #else
67 void qemu_cache_utils_init(char **envp)
69 (void) envp;
70 ppc_init_cacheline_sizes();
72 #endif
74 #endif /* _ARCH_PPC */