vmstate: add VMS_MUST_EXIST
[qemu/ar7.git] / util / cache-utils.c
blob047003008bc3b7e08d964075fcb2095d6958a09e
1 #include "qemu-common.h"
2 #include "qemu/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 void qemu_cache_utils_init(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__
20 #include "qemu/osdep.h"
21 #include "elf.h"
23 void qemu_cache_utils_init(void)
25 unsigned long dsize = qemu_getauxval(AT_DCACHEBSIZE);
26 unsigned long isize = qemu_getauxval(AT_ICACHEBSIZE);
28 if (dsize == 0 || isize == 0) {
29 if (dsize == 0) {
30 fprintf(stderr, "getauxval AT_DCACHEBSIZE failed\n");
32 if (isize == 0) {
33 fprintf(stderr, "getauxval AT_ICACHEBSIZE failed\n");
35 exit(1);
38 qemu_cache_conf.dcache_bsize = dsize;
39 qemu_cache_conf.icache_bsize = isize;
42 #elif defined __APPLE__
43 #include <stdio.h>
44 #include <sys/types.h>
45 #include <sys/sysctl.h>
47 void qemu_cache_utils_init(void)
49 size_t len;
50 unsigned cacheline;
51 int name[2] = { CTL_HW, HW_CACHELINE };
53 len = sizeof(cacheline);
54 if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
55 perror("sysctl CTL_HW HW_CACHELINE failed");
56 } else {
57 qemu_cache_conf.dcache_bsize = cacheline;
58 qemu_cache_conf.icache_bsize = cacheline;
62 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
63 #include <errno.h>
64 #include <stdio.h>
65 #include <stdlib.h>
66 #include <string.h>
67 #include <sys/types.h>
68 #include <sys/sysctl.h>
70 void qemu_cache_utils_init(void)
72 size_t len = 4;
73 unsigned cacheline;
75 if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
76 fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
77 strerror(errno));
78 exit(1);
81 qemu_cache_conf.dcache_bsize = cacheline;
82 qemu_cache_conf.icache_bsize = cacheline;
84 #endif
86 #endif /* _ARCH_PPC */