Fix compiling without MREMAP_FIXED
[qemu/mini2440.git] / cache-utils.c
blob0b4a5acb82f12fdda225bd602be6d0ae000125e8
1 #include "cache-utils.h"
3 #ifdef __powerpc__
4 struct qemu_cache_conf qemu_cache_conf = {
5 .dcache_bsize = 16,
6 .icache_bsize = 16
7 };
9 #if defined _AIX
10 #include <sys/systemcfg.h>
12 static void ppc_init_cacheline_sizes(void)
14 qemu_cache_conf.icache_bsize = _system_configuration.icache_line;
15 qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line;
18 #elif defined __linux__
19 #include <linux/auxvec.h>
21 static void ppc_init_cacheline_sizes(char **envp)
23 unsigned long *auxv;
25 while (*envp++);
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;
36 #elif defined __APPLE__
37 #include <sys/types.h>
38 #include <sys/sysctl.h>
40 static void ppc_init_cacheline_sizes(void)
42 size_t len;
43 unsigned cacheline;
44 int name[2] = { CTL_HW, HW_CACHELINE };
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;
53 #endif
55 #ifdef __linux__
56 void qemu_cache_utils_init(char **envp)
58 ppc_init_cacheline_sizes(envp);
60 #else
61 void qemu_cache_utils_init(char **envp)
63 (void) envp;
64 ppc_init_cacheline_sizes();
66 #endif
68 #endif /* __powerpc__ */