On RISC-V, the logical CPU ID should be the same as Linux's ID. A logical CPU ID is mapped to a HART, the physical ID (phys_id).
All communication with the SBI interface require specification of physical HART IDs. Signed-off-by: Ralf Ramsauer <ralf.ramsa...@oth-regensburg.de> --- hypervisor/arch/riscv/control.c | 7 ------- hypervisor/arch/riscv/lib.c | 25 +++++++++++++++++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/hypervisor/arch/riscv/control.c b/hypervisor/arch/riscv/control.c index ab0bb449..b848994b 100644 --- a/hypervisor/arch/riscv/control.c +++ b/hypervisor/arch/riscv/control.c @@ -69,10 +69,3 @@ void arch_park_cpu(unsigned int cpu_id) void arch_send_event(struct public_per_cpu *target_data) { } - -// Likely misplaced -#include <jailhouse/processor.h> -unsigned int cpu_by_phys_processor_id(u64 phys_id) -{ - return -1; -} diff --git a/hypervisor/arch/riscv/lib.c b/hypervisor/arch/riscv/lib.c index 5fe45bc7..2ea1d5b6 100644 --- a/hypervisor/arch/riscv/lib.c +++ b/hypervisor/arch/riscv/lib.c @@ -1,19 +1,36 @@ /* * Jailhouse, a Linux-based partitioning hypervisor * - * Copyright (c) Siemens AG, 2020 + * Copyright (c) OTH Regensburg, 2022 * * Authors: - * Jan Kiszka <jan.kis...@siemens.com> + * Ralf Ramsauer <ralf.ramsa...@oth-regensburg.de> * * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. */ +#include <jailhouse/control.h> +#include <jailhouse/printk.h> #include <jailhouse/processor.h> +#include <jailhouse/percpu.h> -// Check if it be moved elsewhere unsigned long phys_processor_id(void) { - return 0; + return this_cpu_public()->phys_id; +} + +unsigned int cpu_by_phys_processor_id(u64 phys) +{ + const struct jailhouse_cpu *map = jailhouse_cell_cpus(root_cell.config); + unsigned int num_cpus = root_cell.config->num_cpus; + unsigned int cpu; + + for (cpu = 0; cpu < num_cpus; cpu++, map++) + if (map->phys_id == phys) + return cpu; + + /* this should never happen */ + panic_printk("FATAL: unknown HART ID %llu\n", phys); + panic_stop(); } -- 2.40.1 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to jailhouse-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/20230519204033.643200-36-ralf.ramsauer%40oth-regensburg.de.