cache-utils.c 1.5 KB
Newer Older
M
malc 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "cache-utils.h"

#ifdef __powerpc__
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__
19 20 21 22

#define QEMU_AT_NULL        0
#define QEMU_AT_DCACHEBSIZE 19
#define QEMU_AT_ICACHEBSIZE 20
M
malc 已提交
23 24 25 26 27 28 29

static void ppc_init_cacheline_sizes(char **envp)
{
    unsigned long *auxv;

    while (*envp++);

30
    for (auxv = (unsigned long *) envp; *auxv != QEMU_AT_NULL; auxv += 2) {
M
malc 已提交
31
        switch (*auxv) {
32 33
        case QEMU_AT_DCACHEBSIZE: qemu_cache_conf.dcache_bsize = auxv[1]; break
        case QEMU_AT_ICACHEBSIZE: qemu_cache_conf.icache_bsize = auxv[1]; break
M
malc 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        default: break;
        }
    }
}

#elif defined __APPLE__
#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 };

    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

#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

#endif /* __powerpc__ */