Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmake-tool/helpers/simulation.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function(GenerateSimulateScript)
set(sim_cpu_opt "")
set(sim_machine "")
set(qemu_sim_extra_args "")
set(sim_smp "${KernelMaxNumNodes}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will apply to all simulation targets, but I have only tested ARM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Qemu argument is the same, it should work. If not, we're not worse off than before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same across all architectures so yes it should be fine.

if(KernelArchX86)
# Try and simulate the correct micro architecture and features
if(KernelX86MicroArchNehalem)
Expand Down Expand Up @@ -202,7 +203,7 @@ function(GenerateSimulateScript)
COMMAND
${CMAKE_COMMAND} -DCONFIGURE_INPUT_FILE=${SIMULATE_SCRIPT}
-DCONFIGURE_OUTPUT_FILE=${sim_path} -DQEMU_SIM_BINARY=${QemuBinaryMachine}
-DQEMU_SIM_CPU=${sim_cpu} -DQEMU_SIM_MACHINE=${sim_machine}
-DQEMU_SIM_CPU=${sim_cpu} -DQEMU_SIM_SMP=${sim_smp} -DQEMU_SIM_MACHINE=${sim_machine}
-DQEMU_SIM_CPU_OPT=${sim_cpu_opt} -DQEMU_SIM_GRAPHIC_OPT=${sim_graphic_opt}
-DQEMU_SIM_SERIAL_OPT=${sim_serial_opt} -DQEMU_SIM_MEM_SIZE_OPT=${QemuMemSize}
-DQEMU_SIM_KERNEL_FILE=${KERNEL_IMAGE_NAME} -DQEMU_SIM_INITRD_FILE=${IMAGE_NAME}
Expand Down
8 changes: 7 additions & 1 deletion cmake-tool/simulate_scripts/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def parse_args():
help="QEMU CPU", default="@QEMU_SIM_CPU@")
parser.add_argument('-o', '--cpu-opt', dest='qemu_sim_cpu_opt', type=str,
help="QEMU CPU Options", default="@QEMU_SIM_CPU_OPT@")
parser.add_argument('--smp', dest='qemu_sim_smp', type=str,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the other main arguments have a single letter variant, -s is already taken though so I didn't know what to put here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe -j, like make does?

help="QEMU SMP", default="@QEMU_SIM_SMP@")
parser.add_argument('-g', '--graphic', dest='qemu_sim_graphic_opt', type=str,
help="QEMU Graphic Options", default="@QEMU_SIM_GRAPHIC_OPT@")
parser.add_argument('-s', '--serial', dest='qemu_sim_serial_opt', type=str,
Expand Down Expand Up @@ -79,7 +81,11 @@ def notice(message):

qemu_sim_mem_size_entry = "-m size=" + args.qemu_sim_mem_size

qemu_simulate_command_opts = [args.qemu_sim_binary, qemu_sim_machine_entry, qemu_sim_cpu_entry, args.qemu_sim_graphic_opt,
qemu_sim_smp_entry = ""
if args.qemu_sim_smp:
qemu_sim_smp_entry = "-smp " + args.qemu_sim_smp

qemu_simulate_command_opts = [args.qemu_sim_binary, qemu_sim_machine_entry, qemu_sim_cpu_entry, qemu_sim_smp_entry, args.qemu_sim_graphic_opt,
args.qemu_sim_serial_opt, qemu_sim_mem_size_entry, args.qemu_sim_extra_args, qemu_sim_images_entry,
qemu_gdbserver_command]
qemu_simulate_command = " ".join(qemu_simulate_command_opts)
Expand Down
10 changes: 5 additions & 5 deletions elfloader-tool/include/arch-arm/psci.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#define PSCI_METHOD_SMC 1
#define PSCI_METHOD_HVC 2

int psci_version(void);
int psci_cpu_suspend(int power_state, unsigned long entry_point,
int psci_version(unsigned int method);
int psci_cpu_suspend(unsigned int method, int power_state, unsigned long entry_point,
unsigned long context_id);
/* this function does not return when successful */
int psci_cpu_off(void);
int psci_cpu_on(unsigned long target_cpu, unsigned long entry_point,
int psci_cpu_off(unsigned int method);
int psci_cpu_on(unsigned int method, unsigned long target_cpu, unsigned long entry_point,
unsigned long context_id);
int psci_system_reset(void);
int psci_system_reset(unsigned int method);
12 changes: 9 additions & 3 deletions elfloader-tool/src/arch-arm/armv/armv7-a/32/smc.S
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should investigate into HVC on 32-bit ARM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be the same as for 64-bit Arm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried that but it failed for 32-bit ARM on QEMU. Will have to debug.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ BEGIN_FUNC(smc)
ldmfd sp!, {r3-r11, pc}
END_FUNC(smc)

BEGIN_FUNC(psci_func)
BEGIN_FUNC(psci_smc_func)
.arch_extension sec
stmfd sp!, {r3-r11, lr}
dsb
smc #0
ldmfd sp!, {r3-r11, pc}
END_FUNC(psci_func)

END_FUNC(psci_smc_func)

BEGIN_FUNC(psci_hvc_func)
.arch_extension sec
stmfd sp!, {r3-r11, lr}
dsb
hvc #0
ldmfd sp!, {r3-r11, pc}
END_FUNC(psci_hvc_func)
9 changes: 7 additions & 2 deletions elfloader-tool/src/arch-arm/armv/armv8-a/64/psci_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@

.text

BEGIN_FUNC(psci_func)
BEGIN_FUNC(psci_smc_func)
smc #0
ret
END_FUNC(psci_func)
END_FUNC(psci_smc_func)

BEGIN_FUNC(psci_hvc_func)
hvc #0
ret
END_FUNC(psci_hvc_func)
6 changes: 1 addition & 5 deletions elfloader-tool/src/arch-arm/drivers/smp-psci.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ static int smp_psci_cpu_on(UNUSED struct elfloader_device *dev,
UNUSED struct elfloader_cpu *cpu, UNUSED void *entry, UNUSED void *stack)
{
#if CONFIG_MAX_NUM_NODES > 1
if (cpu->extra_data == PSCI_METHOD_HVC) {
printf("HVC is not supported for PSCI!\n");
return -1;
}
secondary_data.entry = entry;
secondary_data.stack = stack;
dmb();
int ret = psci_cpu_on(cpu->cpu_id, (unsigned long)&secondary_startup, 0);
int ret = psci_cpu_on(cpu->extra_data, cpu->cpu_id, (unsigned long)&secondary_startup, 0);
if (ret != PSCI_SUCCESS) {
printf("Failed to bring up core 0x%x with error %d\n", cpu->cpu_id, ret);
return -1;
Expand Down
41 changes: 29 additions & 12 deletions elfloader-tool/src/arch-arm/psci.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <autoconf.h>
#include <elfloader/gen_config.h>
#include <printf.h>
#include <psci.h>

#ifdef CONFIG_ARCH_AARCH64
#define SMC_FID_VER 0x84000000
Expand All @@ -23,40 +24,56 @@
#endif


extern int psci_func(unsigned int id, unsigned long param1,
unsigned long param2, unsigned long param3);
extern int psci_smc_func(unsigned int id, unsigned long param1,
unsigned long param2, unsigned long param3);

int psci_version(void)
extern int psci_hvc_func(unsigned int id, unsigned long param1,
unsigned long param2, unsigned long param3);

int psci_func(unsigned int method, unsigned int id, unsigned long param1,
unsigned long param2, unsigned long param3)
{
if (method == PSCI_METHOD_HVC) {
return psci_hvc_func(id, param1, param2, param3);
} else if (method == PSCI_METHOD_SMC) {
return psci_smc_func(id, param1, param2, param3);
} else {
printf("ERROR: PSCI method %u is unsupported\n", method);
return -1;
}
}

int psci_version(unsigned int method)
{
int ver = psci_func(SMC_FID_VER, 0, 0, 0);
int ver = psci_func(method, SMC_FID_VER, 0, 0, 0);
return ver;
}


int psci_cpu_suspend(int power_state, unsigned long entry_point,
int psci_cpu_suspend(unsigned int method, int power_state, unsigned long entry_point,
unsigned long context_id)
{
int ret = psci_func(SMC_FID_CPU_SUSPEND, power_state, entry_point, context_id);
int ret = psci_func(method, SMC_FID_CPU_SUSPEND, power_state, entry_point, context_id);
return ret;
}

/* this function does not return when successful */
int psci_cpu_off(void)
int psci_cpu_off(unsigned int method)
{
int ret = psci_func(SMC_FID_CPU_OFF, 0, 0, 0);
int ret = psci_func(method, SMC_FID_CPU_OFF, 0, 0, 0);
return ret;
}

int psci_cpu_on(unsigned long target_cpu, unsigned long entry_point,
int psci_cpu_on(unsigned int method, unsigned long target_cpu, unsigned long entry_point,
unsigned long context_id)
{
int ret = psci_func(SMC_FID_CPU_ON, target_cpu, entry_point, context_id);
int ret = psci_func(method, SMC_FID_CPU_ON, target_cpu, entry_point, context_id);
return ret;
}

int psci_system_reset(void)
int psci_system_reset(unsigned int method)
{
int ret = psci_func(SMC_FID_SYSTEM_RESET, 0, 0, 0);
int ret = psci_func(method, SMC_FID_SYSTEM_RESET, 0, 0, 0);
return ret;
}

Loading