Skip to contentSkip to conversation

hw/tricore/triboard: Remove use of &first_cpu

PATCH In review Philippe Mathieu-Daudé 4 participants 5 messages Jan 10, 2025 – Jan 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/tricore/triboard: Remove use of &first_cpu

triboard_machine_init() has access to the single CPU via:

  TriBoardMachineState {
    TC27XSoCState {
      TriCoreCPU cpu;
      ...
    } tc27x_soc;
  } ms;

Pass it as argument to tricore_load_kernel() so we can remove the &first_cpu global use.

---
 hw/tricore/triboard.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
hw/tricore/triboard.c +2 -4
index 4dba0259cd3..9cc8d282ff2 100644
@@ -31,11 +31,10 @@
 #include "hw/tricore/triboard.h"
 #include "hw/tricore/tc27x_soc.h"
 
-static void tricore_load_kernel(const char *kernel_filename)
+static void tricore_load_kernel(TriCoreCPU *cpu, const char *kernel_filename)
 {
     uint64_t entry;
     long kernel_size;
-    TriCoreCPU *cpu;
     CPUTriCoreState *env;
 
     kernel_size = load_elf(kernel_filename, NULL,
@@ -46,7 +45,6 @@ static void tricore_load_kernel(const char *kernel_filename)
         error_report("no kernel file '%s'", kernel_filename);
         exit(1);
     }
-    cpu = TRICORE_CPU(first_cpu);
     env = &cpu->env;
     env->PC = entry;
 }
@@ -62,7 +60,7 @@ static void triboard_machine_init(MachineState *machine)
     sysbus_realize(SYS_BUS_DEVICE(&ms->tc27x_soc), &error_fatal);
 
     if (machine->kernel_filename) {
-        tricore_load_kernel(machine->kernel_filename);
+        tricore_load_kernel(&ms->tc27x_soc.cpu, machine->kernel_filename);
     }
 }
 
Signature · 1 line
2.47.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Philippe Mathieu-Daudé

triboard_machine_init() has access to the single CPU via:

   TriBoardMachineState {
     TC27XSoCState {
       TriCoreCPU cpu;
       ...
     } tc27x_soc;
   } ms;
Quoted 7 lines

Pass it as argument to tricore_load_kernel() so we can remove the &first_cpu global use.

---
  hw/tricore/triboard.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)

r~

Reviewed-by on v1 1/1
#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 43 lines · Philippe Mathieu-Daudé

triboard_machine_init() has access to the single CPU via:

   TriBoardMachineState {
     TC27XSoCState {
       TriCoreCPU cpu;
       ...
     } tc27x_soc;
   } ms;

Pass it as argument to tricore_load_kernel() so we can remove the &first_cpu global use.

---
  hw/tricore/triboard.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
hw/tricore/triboard.c +1 -3
index 4dba0259cd3..9cc8d282ff2 100644
@@ -31,11 +31,10 @@
  #include "hw/tricore/triboard.h"
  #include "hw/tricore/tc27x_soc.h"
 
-static void tricore_load_kernel(const char *kernel_filename)
+static void tricore_load_kernel(TriCoreCPU *cpu, const char *kernel_filename)
  {
      uint64_t entry;
      long kernel_size;
-    TriCoreCPU *cpu;
      CPUTriCoreState *env;
 
      kernel_size = load_elf(kernel_filename, NULL,
@@ -46,7 +45,6 @@ static void tricore_load_kernel(const char *kernel_filename)
          error_report("no kernel file '%s'", kernel_filename);
          exit(1);
      }
-    cpu = TRICORE_CPU(first_cpu);
      env = &cpu->env;
      env->PC = entry;
  }

hw/tricore/triboard.c static void triboard_machine_init(MachineState *machine) · line 66

Quoted 8 lines
hw/tricore/triboard.c +1 -1
@@ -62,7 +60,7 @@ static void triboard_machine_init(MachineState *machine)
      sysbus_realize(SYS_BUS_DEVICE(&ms->tc27x_soc), &error_fatal);
 
      if (machine->kernel_filename) {
-        tricore_load_kernel(machine->kernel_filename);
+        tricore_load_kernel(&ms->tc27x_soc.cpu, machine->kernel_filename);
      }
  }
 
Reviewed-by on v1 1/1
#3 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

triboard_machine_init() has access to the single CPU via:

  TriBoardMachineState {
    TC27XSoCState {
      TriCoreCPU cpu;
      ...
    } tc27x_soc;
  } ms;
Quoted 7 lines

Pass it as argument to tricore_load_kernel() so we can remove the &first_cpu global use.

---
 hw/tricore/triboard.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Cheers,
Bastian

#4 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

triboard_machine_init() has access to the single CPU via:

   TriBoardMachineState {
     TC27XSoCState {
       TriCoreCPU cpu;
       ...
     } tc27x_soc;
   } ms;
Quoted 7 lines

Pass it as argument to tricore_load_kernel() so we can remove the &first_cpu global use.

---
  hw/tricore/triboard.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)

Patch queued.