2008-12-10 20:18:40 +01:00
|
|
|
#include "cache-utils.h"
|
|
|
|
|
2009-01-14 19:39:49 +01:00
|
|
|
#if defined(_ARCH_PPC)
|
2008-12-10 20:18:40 +01:00
|
|
|
struct qemu_cache_conf qemu_cache_conf = {
|
|
|
|
.dcache_bsize = 16,
|
|
|
|
.icache_bsize = 16
|
|
|
|
};
|
|
|
|
|
|
|
|
#if defined _AIX
|
|
|
|
#include <sys/systemcfg.h>
|
|
|
|
|
|
|
|
static void ppc_init_cacheline_sizes(void)
|
|
|
|
{
|
|
|
|
qemu_cache_conf.icache_bsize = _system_configuration.icache_line;
|
|
|
|
qemu_cache_conf.dcache_bsize = _system_configuration.dcache_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined __linux__
|
2008-12-11 20:12:59 +01:00
|
|
|
|
|
|
|
#define QEMU_AT_NULL 0
|
|
|
|
#define QEMU_AT_DCACHEBSIZE 19
|
|
|
|
#define QEMU_AT_ICACHEBSIZE 20
|
2008-12-10 20:18:40 +01:00
|
|
|
|
|
|
|
static void ppc_init_cacheline_sizes(char **envp)
|
|
|
|
{
|
|
|
|
unsigned long *auxv;
|
|
|
|
|
|
|
|
while (*envp++);
|
|
|
|
|
2008-12-11 20:12:59 +01:00
|
|
|
for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
|
2008-12-10 20:18:40 +01:00
|
|
|
switch (*auxv) {
|
2008-12-11 20:20:41 +01:00
|
|
|
case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break;
|
|
|
|
case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break;
|
2008-12-10 20:18:40 +01:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined __APPLE__
|
2009-02-04 21:39:09 +01:00
|
|
|
#include <stdio.h>
|
2008-12-10 20:18:40 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
static void ppc_init_cacheline_sizes(void)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
unsigned cacheline;
|
|
|
|
int name[2] = { CTL_HW, HW_CACHELINE };
|
|
|
|
|
2009-02-04 21:39:09 +01:00
|
|
|
len = sizeof(cacheline);
|
2008-12-10 20:18:40 +01:00
|
|
|
if (sysctl(name, 2, &cacheline, &len, NULL, 0)) {
|
|
|
|
perror("sysctl CTL_HW HW_CACHELINE failed");
|
|
|
|
} else {
|
|
|
|
qemu_cache_conf.dcache_bsize = cacheline;
|
|
|
|
qemu_cache_conf.icache_bsize = cacheline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-19 19:28:23 +01:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2010-03-12 22:50:15 +01:00
|
|
|
#include <errno.h>
|
2010-02-19 19:28:23 +01:00
|
|
|
#include <stdio.h>
|
2010-03-12 22:50:15 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-02-19 19:28:23 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
static void ppc_init_cacheline_sizes(void)
|
|
|
|
{
|
|
|
|
size_t len = 4;
|
|
|
|
unsigned cacheline;
|
|
|
|
|
|
|
|
if (sysctlbyname ("machdep.cacheline_size", &cacheline, &len, NULL, 0)) {
|
|
|
|
fprintf(stderr, "sysctlbyname machdep.cacheline_size failed: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
qemu_cache_conf.dcache_bsize = cacheline;
|
|
|
|
qemu_cache_conf.icache_bsize = cacheline;
|
|
|
|
}
|
2010-10-31 22:53:19 +01:00
|
|
|
#endif
|
2010-02-19 19:28:23 +01:00
|
|
|
|
2008-12-10 20:18:40 +01:00
|
|
|
#ifdef __linux__
|
|
|
|
void qemu_cache_utils_init(char **envp)
|
|
|
|
{
|
|
|
|
ppc_init_cacheline_sizes(envp);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void qemu_cache_utils_init(char **envp)
|
|
|
|
{
|
|
|
|
(void) envp;
|
|
|
|
ppc_init_cacheline_sizes();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-01-14 19:39:49 +01:00
|
|
|
#endif /* _ARCH_PPC */
|