Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
linux-user: Split out cpu/target_proc.h
Move the various open_cpuinfo functions into new files.
Move the m68k open_hardware function as well.
All other guest architectures get a boilerplate empty file.

Tested-by: Helge Deller <deller@gmx.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Sep 1, 2023
1 parent 17780ed commit 121c8dd
Show file tree
Hide file tree
Showing 22 changed files with 226 additions and 170 deletions.
1 change: 1 addition & 0 deletions linux-user/aarch64/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/alpha/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/arm/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/cris/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/hexagon/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
26 changes: 26 additions & 0 deletions linux-user/hppa/target_proc.h
@@ -0,0 +1,26 @@
/*
* HPPA specific proc functions for linux-user
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef HPPA_TARGET_PROC_H
#define HPPA_TARGET_PROC_H

static int open_cpuinfo(CPUArchState *cpu_env, int fd)
{
int i, num_cpus;

num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
for (i = 0; i < num_cpus; i++) {
dprintf(fd, "processor\t: %d\n", i);
dprintf(fd, "cpu family\t: PA-RISC 1.1e\n");
dprintf(fd, "cpu\t\t: PA7300LC (PCX-L2)\n");
dprintf(fd, "capabilities\t: os32\n");
dprintf(fd, "model\t\t: 9000/778/B160L - "
"Merlin L2 160 QEMU (9000/778/B160L)\n\n");
}
return 0;
}
#define HAVE_ARCH_PROC_CPUINFO

#endif /* HPPA_TARGET_PROC_H */
1 change: 1 addition & 0 deletions linux-user/i386/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/loongarch64/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
16 changes: 16 additions & 0 deletions linux-user/m68k/target_proc.h
@@ -0,0 +1,16 @@
/*
* M68K specific proc functions for linux-user
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef M68K_TARGET_PROC_H
#define M68K_TARGET_PROC_H

static int open_hardware(CPUArchState *cpu_env, int fd)
{
dprintf(fd, "Model:\t\tqemu-m68k\n");
return 0;
}
#define HAVE_ARCH_PROC_HARDWARE

#endif /* M68K_TARGET_PROC_H */
1 change: 1 addition & 0 deletions linux-user/microblaze/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/mips/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/mips64/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/nios2/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/openrisc/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
1 change: 1 addition & 0 deletions linux-user/ppc/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
37 changes: 37 additions & 0 deletions linux-user/riscv/target_proc.h
@@ -0,0 +1,37 @@
/*
* RISC-V specific proc functions for linux-user
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef RISCV_TARGET_PROC_H
#define RISCV_TARGET_PROC_H

static int open_cpuinfo(CPUArchState *cpu_env, int fd)
{
int i;
int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
RISCVCPU *cpu = env_archcpu(cpu_env);
const RISCVCPUConfig *cfg = riscv_cpu_cfg((CPURISCVState *) cpu_env);
char *isa_string = riscv_isa_string(cpu);
const char *mmu;

if (cfg->mmu) {
mmu = (cpu_env->xl == MXL_RV32) ? "sv32" : "sv48";
} else {
mmu = "none";
}

for (i = 0; i < num_cpus; i++) {
dprintf(fd, "processor\t: %d\n", i);
dprintf(fd, "hart\t\t: %d\n", i);
dprintf(fd, "isa\t\t: %s\n", isa_string);
dprintf(fd, "mmu\t\t: %s\n", mmu);
dprintf(fd, "uarch\t\t: qemu\n\n");
}

g_free(isa_string);
return 0;
}
#define HAVE_ARCH_PROC_CPUINFO

#endif /* RISCV_TARGET_PROC_H */
109 changes: 109 additions & 0 deletions linux-user/s390x/target_proc.h
@@ -0,0 +1,109 @@
/*
* S390X specific proc functions for linux-user
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef S390X_TARGET_PROC_H
#define S390X_TARGET_PROC_H

/*
* Emulate what a Linux kernel running in qemu-system-s390x -M accel=tcg would
* show in /proc/cpuinfo.
*
* Skip the following in order to match the missing support in op_ecag():
* - show_cacheinfo().
* - show_cpu_topology().
* - show_cpu_mhz().
*
* Use fixed values for certain fields:
* - bogomips per cpu - from a qemu-system-s390x run.
* - max thread id = 0, since SMT / SIGP_SET_MULTI_THREADING is not supported.
*
* Keep the code structure close to arch/s390/kernel/processor.c.
*/

static void show_facilities(int fd)
{
size_t sizeof_stfl_bytes = 2048;
g_autofree uint8_t *stfl_bytes = g_new0(uint8_t, sizeof_stfl_bytes);
unsigned int bit;

dprintf(fd, "facilities :");
s390_get_feat_block(S390_FEAT_TYPE_STFL, stfl_bytes);
for (bit = 0; bit < sizeof_stfl_bytes * 8; bit++) {
if (test_be_bit(bit, stfl_bytes)) {
dprintf(fd, " %d", bit);
}
}
dprintf(fd, "\n");
}

static int cpu_ident(unsigned long n)
{
return deposit32(0, CPU_ID_BITS - CPU_PHYS_ADDR_BITS, CPU_PHYS_ADDR_BITS,
n);
}

static void show_cpu_summary(CPUArchState *cpu_env, int fd)
{
S390CPUModel *model = env_archcpu(cpu_env)->model;
int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
uint32_t elf_hwcap = get_elf_hwcap();
const char *hwcap_str;
int i;

dprintf(fd, "vendor_id : IBM/S390\n"
"# processors : %i\n"
"bogomips per cpu: 13370.00\n",
num_cpus);
dprintf(fd, "max thread id : 0\n");
dprintf(fd, "features\t: ");
for (i = 0; i < sizeof(elf_hwcap) * 8; i++) {
if (!(elf_hwcap & (1 << i))) {
continue;
}
hwcap_str = elf_hwcap_str(i);
if (hwcap_str) {
dprintf(fd, "%s ", hwcap_str);
}
}
dprintf(fd, "\n");
show_facilities(fd);
for (i = 0; i < num_cpus; i++) {
dprintf(fd, "processor %d: "
"version = %02X, "
"identification = %06X, "
"machine = %04X\n",
i, model->cpu_ver, cpu_ident(i), model->def->type);
}
}

static void show_cpu_ids(CPUArchState *cpu_env, int fd, unsigned long n)
{
S390CPUModel *model = env_archcpu(cpu_env)->model;

dprintf(fd, "version : %02X\n", model->cpu_ver);
dprintf(fd, "identification : %06X\n", cpu_ident(n));
dprintf(fd, "machine : %04X\n", model->def->type);
}

static void show_cpuinfo(CPUArchState *cpu_env, int fd, unsigned long n)
{
dprintf(fd, "\ncpu number : %ld\n", n);
show_cpu_ids(cpu_env, fd, n);
}

static int open_cpuinfo(CPUArchState *cpu_env, int fd)
{
int num_cpus = sysconf(_SC_NPROCESSORS_ONLN);
int i;

show_cpu_summary(cpu_env, fd);
for (i = 0; i < num_cpus; i++) {
show_cpuinfo(cpu_env, fd, i);
}
return 0;
}
#define HAVE_ARCH_PROC_CPUINFO

#endif /* S390X_TARGET_PROC_H */
1 change: 1 addition & 0 deletions linux-user/sh4/target_proc.h
@@ -0,0 +1 @@
/* No target-specific /proc support */
16 changes: 16 additions & 0 deletions linux-user/sparc/target_proc.h
@@ -0,0 +1,16 @@
/*
* Sparc specific proc functions for linux-user
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef SPARC_TARGET_PROC_H
#define SPARC_TARGET_PROC_H

static int open_cpuinfo(CPUArchState *cpu_env, int fd)
{
dprintf(fd, "type\t\t: sun4u\n");
return 0;
}
#define HAVE_ARCH_PROC_CPUINFO

#endif /* SPARC_TARGET_PROC_H */

0 comments on commit 121c8dd

Please sign in to comment.