Message ID | 20230916220151.526140-4-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | tcg/loongarch64: Improvements for 128-bit load/store | expand |
On 2023/9/17 06:01, Richard Henderson wrote: > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > host/include/loongarch64/host/cpuinfo.h | 21 +++++++++++++++ > util/cpuinfo-loongarch.c | 35 +++++++++++++++++++++++++ > util/meson.build | 2 ++ > 3 files changed, 58 insertions(+) > create mode 100644 host/include/loongarch64/host/cpuinfo.h > create mode 100644 util/cpuinfo-loongarch.c > > diff --git a/host/include/loongarch64/host/cpuinfo.h b/host/include/loongarch64/host/cpuinfo.h > new file mode 100644 > index 0000000000..fab664a10b > --- /dev/null > +++ b/host/include/loongarch64/host/cpuinfo.h > @@ -0,0 +1,21 @@ > +/* > + * SPDX-License-Identifier: GPL-2.0-or-later > + * Host specific cpu identification for LoongArch > + */ > + > +#ifndef HOST_CPUINFO_H > +#define HOST_CPUINFO_H > + > +#define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */ > +#define CPUINFO_LSX (1u << 1) > + > +/* Initialized with a constructor. */ > +extern unsigned cpuinfo; > + > +/* > + * We cannot rely on constructor ordering, so other constructors must > + * use the function interface rather than the variable above. > + */ > +unsigned cpuinfo_init(void); > + > +#endif /* HOST_CPUINFO_H */ > diff --git a/util/cpuinfo-loongarch.c b/util/cpuinfo-loongarch.c > new file mode 100644 > index 0000000000..08b6d7460c > --- /dev/null > +++ b/util/cpuinfo-loongarch.c > @@ -0,0 +1,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; > +} > diff --git a/util/meson.build b/util/meson.build > index c4827fd70a..b136f02aa0 100644 > --- a/util/meson.build > +++ b/util/meson.build > @@ -112,6 +112,8 @@ if cpu == 'aarch64' > util_ss.add(files('cpuinfo-aarch64.c')) > elif cpu in ['x86', 'x86_64'] > util_ss.add(files('cpuinfo-i386.c')) > +elif cpu == 'loongarch64' > + util_ss.add(files('cpuinfo-loongarch.c')) > elif cpu in ['ppc', 'ppc64'] > util_ss.add(files('cpuinfo-ppc.c')) > endif Reviewed-by: Jiajie Chen <c@jia.je>
diff --git a/host/include/loongarch64/host/cpuinfo.h b/host/include/loongarch64/host/cpuinfo.h new file mode 100644 index 0000000000..fab664a10b --- /dev/null +++ b/host/include/loongarch64/host/cpuinfo.h @@ -0,0 +1,21 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Host specific cpu identification for LoongArch + */ + +#ifndef HOST_CPUINFO_H +#define HOST_CPUINFO_H + +#define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */ +#define CPUINFO_LSX (1u << 1) + +/* Initialized with a constructor. */ +extern unsigned cpuinfo; + +/* + * We cannot rely on constructor ordering, so other constructors must + * use the function interface rather than the variable above. + */ +unsigned cpuinfo_init(void); + +#endif /* HOST_CPUINFO_H */ diff --git a/util/cpuinfo-loongarch.c b/util/cpuinfo-loongarch.c new file mode 100644 index 0000000000..08b6d7460c --- /dev/null +++ b/util/cpuinfo-loongarch.c @@ -0,0 +1,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; +} diff --git a/util/meson.build b/util/meson.build index c4827fd70a..b136f02aa0 100644 --- a/util/meson.build +++ b/util/meson.build @@ -112,6 +112,8 @@ if cpu == 'aarch64' util_ss.add(files('cpuinfo-aarch64.c')) elif cpu in ['x86', 'x86_64'] util_ss.add(files('cpuinfo-i386.c')) +elif cpu == 'loongarch64' + util_ss.add(files('cpuinfo-loongarch.c')) elif cpu in ['ppc', 'ppc64'] util_ss.add(files('cpuinfo-ppc.c')) endif
Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- host/include/loongarch64/host/cpuinfo.h | 21 +++++++++++++++ util/cpuinfo-loongarch.c | 35 +++++++++++++++++++++++++ util/meson.build | 2 ++ 3 files changed, 58 insertions(+) create mode 100644 host/include/loongarch64/host/cpuinfo.h create mode 100644 util/cpuinfo-loongarch.c