aboutsummaryrefslogtreecommitdiff
path: root/util/cpuinfo-loongarch.c
blob: 08b6d7460c9f690ecbb3bf6a48641ef80e62a0e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * SPDX-License-Identifier: GPL-2.0-or-later
 * Host specific cpu identification for LoongArch.
 */

#include "qemu/osdep.h"
#include "host/cpuinfo.h"

#ifdef CONFIG_GETAUXVAL
# include <sys/auxv.h>
#else
# include "elf.h"
#endif
#include <asm/hwcap.h>

unsigned cpuinfo;

/* Called both as constructor and (possibly) via other constructors. */
unsigned __attribute__((constructor)) cpuinfo_init(void)
{
    unsigned info = cpuinfo;
    unsigned long hwcap;

    if (info) {
        return info;
    }

    hwcap = qemu_getauxval(AT_HWCAP);

    info = CPUINFO_ALWAYS;
    info |= (hwcap & HWCAP_LOONGARCH_LSX ? CPUINFO_LSX : 0);

    cpuinfo = info;
    return info;
}