blob: b37ddd4992f8b7660c52dd8c224882c14b963e8f [file] [log] [blame]
malc902b3d52008-12-10 19:18:40 +00001#include "cache-utils.h"
2
malce58ffeb2009-01-14 18:39:49 +00003#if defined(_ARCH_PPC)
malc902b3d52008-12-10 19:18:40 +00004struct 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
12static 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__
malc47100362008-12-11 19:12:59 +000019
20#define QEMU_AT_NULL 0
21#define QEMU_AT_DCACHEBSIZE 19
22#define QEMU_AT_ICACHEBSIZE 20
malc902b3d52008-12-10 19:18:40 +000023
24static void ppc_init_cacheline_sizes(char **envp)
25{
26 unsigned long *auxv;
27
28 while (*envp++);
29
malc47100362008-12-11 19:12:59 +000030 for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
malc902b3d52008-12-10 19:18:40 +000031 switch (*auxv) {
malc807d5172008-12-11 19:20:41 +000032 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;
malc902b3d52008-12-10 19:18:40 +000034 default: break;
35 }
36 }
37}
38
39#elif defined __APPLE__
40#include <sys/types.h>
41#include <sys/sysctl.h>
42
43static void ppc_init_cacheline_sizes(void)
44{
45 size_t len;
46 unsigned cacheline;
47 int name[2] = { CTL_HW, HW_CACHELINE };
48
49 if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
50 perror("sysctl CTL_HW HW_CACHELINE failed");
51 } else {
52 qemu_cache_conf.dcache_bsize = cacheline;
53 qemu_cache_conf.icache_bsize = cacheline;
54 }
55}
56#endif
57
58#ifdef __linux__
59void qemu_cache_utils_init(char **envp)
60{
61 ppc_init_cacheline_sizes(envp);
62}
63#else
64void qemu_cache_utils_init(char **envp)
65{
66 (void) envp;
67 ppc_init_cacheline_sizes();
68}
69#endif
70
malce58ffeb2009-01-14 18:39:49 +000071#endif /* _ARCH_PPC */