diff mbox series

[v2,03/17] hw/loongarch: Add init_cmdline

Message ID 20231218090059.2678224-4-gaosong@loongson.cn
State New
Headers show
Series Add boot LoongArch elf kernel with FDT | expand

Commit Message

Song Gao Dec. 18, 2023, 9 a.m. UTC
Add init_cmline and set boot_info->a0, a1

Signed-off-by: Song Gao <gaosong@loongson.cn>
---
 hw/loongarch/boot.c         | 21 +++++++++++++++++++++
 include/hw/loongarch/virt.h |  2 ++
 target/loongarch/cpu.h      |  2 ++
 3 files changed, 25 insertions(+)

Comments

maobibo Dec. 21, 2023, 7:20 a.m. UTC | #1
On 2023/12/18 下午5:00, Song Gao wrote:
> Add init_cmline and set boot_info->a0, a1
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
>   hw/loongarch/boot.c         | 21 +++++++++++++++++++++
>   include/hw/loongarch/virt.h |  2 ++
>   target/loongarch/cpu.h      |  2 ++
>   3 files changed, 25 insertions(+)
> 
> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
> index 2be6dfb037..4bfe24274a 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -14,6 +14,20 @@
>   #include "qemu/error-report.h"
>   #include "sysemu/reset.h"
>   
> +static int init_cmdline(struct loongarch_boot_info *info)
> +{
> +    hwaddr cmdline_addr;
> +    cmdline_addr = 0xff00000ULL;
> +
> +    pstrcpy_targphys("cmdline", 0xff00000ULL,
> +                     COMMAND_LINE_SIZE, info->kernel_cmdline);
There are two places using 0xff00000ULL here, it had better be defined 
as macro. Also can address for cmdline be before FDT base 
address(0x100000) rather than strange value 0xff00000 ? -:)

> +
> +    info->a0 = 1;
> +    info->a1 = cmdline_addr;
> +
> +    return 0;
> +}
> +
>   static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
>   {
>       return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
> @@ -63,6 +77,8 @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
>           exit(1);
>       }
>   
> +    init_cmdline(info);
> +
>       return kernel_entry;
>   }
>   
> @@ -73,6 +89,10 @@ static void reset_load_elf(void *opaque)
>   
>       cpu_reset(CPU(cpu));
>       if (env->load_elf) {
> +	if (cpu == LOONGARCH_CPU(first_cpu)) {
> +            env->gpr[4] = env->boot_info->a0;
> +            env->gpr[5] = env->boot_info->a1;
> +        }
>           cpu_set_pc(CPU(cpu), env->elf_address);
>       }
>   }
> @@ -129,6 +149,7 @@ static void loongarch_direct_kernel_boot(LoongArchMachineState *lams,
>           lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
>           lacpu->env.load_elf = true;
>           lacpu->env.elf_address = kernel_addr;
> +        lacpu->env.boot_info = info;
>       }
>   }
>   
> diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
> index e4126dd0e7..d21de2cef4 100644
> --- a/include/hw/loongarch/virt.h
> +++ b/include/hw/loongarch/virt.h
> @@ -31,6 +31,8 @@
>   #define VIRT_GED_MEM_ADDR       (VIRT_GED_EVT_ADDR + ACPI_GED_EVT_SEL_LEN)
>   #define VIRT_GED_REG_ADDR       (VIRT_GED_MEM_ADDR + MEMORY_HOTPLUG_IO_LEN)
>   
> +#define COMMAND_LINE_SIZE       512
The macro COMMAND_LINE_SIZE is already defined in Linux header file, 
maybe standard header file can be used.

/usr/include/asm-generic/setup.h
#define COMMAND_LINE_SIZE      512


Regards
Bibo Mao
> +
>   struct LoongArchMachineState {
>       /*< private >*/
>       MachineState parent_obj;
> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
> index 00d1fba597..c7c695138e 100644
> --- a/target/loongarch/cpu.h
> +++ b/target/loongarch/cpu.h
> @@ -362,6 +362,8 @@ typedef struct CPUArchState {
>       uint64_t elf_address;
>       /* Store ipistate to access from this struct */
>       DeviceState *ipistate;
> +
> +    struct loongarch_boot_info *boot_info;
>   #endif
>   } CPULoongArchState;
>   
>
Song Gao Dec. 25, 2023, 1:09 a.m. UTC | #2
在 2023/12/21 下午3:20, maobibo 写道:
>
>
> On 2023/12/18 下午5:00, Song Gao wrote:
>> Add init_cmline and set boot_info->a0, a1
>>
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> ---
>>   hw/loongarch/boot.c         | 21 +++++++++++++++++++++
>>   include/hw/loongarch/virt.h |  2 ++
>>   target/loongarch/cpu.h      |  2 ++
>>   3 files changed, 25 insertions(+)
>>
>> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
>> index 2be6dfb037..4bfe24274a 100644
>> --- a/hw/loongarch/boot.c
>> +++ b/hw/loongarch/boot.c
>> @@ -14,6 +14,20 @@
>>   #include "qemu/error-report.h"
>>   #include "sysemu/reset.h"
>>   +static int init_cmdline(struct loongarch_boot_info *info)
>> +{
>> +    hwaddr cmdline_addr;
>> +    cmdline_addr = 0xff00000ULL;
>> +
>> +    pstrcpy_targphys("cmdline", 0xff00000ULL,
>> +                     COMMAND_LINE_SIZE, info->kernel_cmdline);
> There are two places using 0xff00000ULL here, it had better be defined 
> as macro. Also can address for cmdline be before FDT base 
> address(0x100000) rather than strange value 0xff00000 ? -:)
>
>> +
>> +    info->a0 = 1;
>> +    info->a1 = cmdline_addr;
>> +
>> +    return 0;
>> +}
>> +
>>   static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t 
>> addr)
>>   {
>>       return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
>> @@ -63,6 +77,8 @@ static int64_t load_kernel_info(struct 
>> loongarch_boot_info *info)
>>           exit(1);
>>       }
>>   +    init_cmdline(info);
>> +
>>       return kernel_entry;
>>   }
>>   @@ -73,6 +89,10 @@ static void reset_load_elf(void *opaque)
>>         cpu_reset(CPU(cpu));
>>       if (env->load_elf) {
>> +    if (cpu == LOONGARCH_CPU(first_cpu)) {
>> +            env->gpr[4] = env->boot_info->a0;
>> +            env->gpr[5] = env->boot_info->a1;
>> +        }
>>           cpu_set_pc(CPU(cpu), env->elf_address);
>>       }
>>   }
>> @@ -129,6 +149,7 @@ static void 
>> loongarch_direct_kernel_boot(LoongArchMachineState *lams,
>>           lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
>>           lacpu->env.load_elf = true;
>>           lacpu->env.elf_address = kernel_addr;
>> +        lacpu->env.boot_info = info;
>>       }
>>   }
>>   diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
>> index e4126dd0e7..d21de2cef4 100644
>> --- a/include/hw/loongarch/virt.h
>> +++ b/include/hw/loongarch/virt.h
>> @@ -31,6 +31,8 @@
>>   #define VIRT_GED_MEM_ADDR       (VIRT_GED_EVT_ADDR + 
>> ACPI_GED_EVT_SEL_LEN)
>>   #define VIRT_GED_REG_ADDR       (VIRT_GED_MEM_ADDR + 
>> MEMORY_HOTPLUG_IO_LEN)
>>   +#define COMMAND_LINE_SIZE       512
> The macro COMMAND_LINE_SIZE is already defined in Linux header file, 
> maybe standard header file can be used.
>
> /usr/include/asm-generic/setup.h
> #define COMMAND_LINE_SIZE      512
>
Yes,
#include <asm-generic/setup.h>

Thanks.
Song Gao
>
> Regards
> Bibo Mao
>> +
>>   struct LoongArchMachineState {
>>       /*< private >*/
>>       MachineState parent_obj;
>> diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
>> index 00d1fba597..c7c695138e 100644
>> --- a/target/loongarch/cpu.h
>> +++ b/target/loongarch/cpu.h
>> @@ -362,6 +362,8 @@ typedef struct CPUArchState {
>>       uint64_t elf_address;
>>       /* Store ipistate to access from this struct */
>>       DeviceState *ipistate;
>> +
>> +    struct loongarch_boot_info *boot_info;
>>   #endif
>>   } CPULoongArchState;
>>
diff mbox series

Patch

diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 2be6dfb037..4bfe24274a 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -14,6 +14,20 @@ 
 #include "qemu/error-report.h"
 #include "sysemu/reset.h"
 
+static int init_cmdline(struct loongarch_boot_info *info)
+{
+    hwaddr cmdline_addr;
+    cmdline_addr = 0xff00000ULL;
+
+    pstrcpy_targphys("cmdline", 0xff00000ULL,
+                     COMMAND_LINE_SIZE, info->kernel_cmdline);
+
+    info->a0 = 1;
+    info->a1 = cmdline_addr;
+
+    return 0;
+}
+
 static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)
 {
     return addr & MAKE_64BIT_MASK(0, TARGET_PHYS_ADDR_SPACE_BITS);
@@ -63,6 +77,8 @@  static int64_t load_kernel_info(struct loongarch_boot_info *info)
         exit(1);
     }
 
+    init_cmdline(info);
+
     return kernel_entry;
 }
 
@@ -73,6 +89,10 @@  static void reset_load_elf(void *opaque)
 
     cpu_reset(CPU(cpu));
     if (env->load_elf) {
+	if (cpu == LOONGARCH_CPU(first_cpu)) {
+            env->gpr[4] = env->boot_info->a0;
+            env->gpr[5] = env->boot_info->a1;
+        }
         cpu_set_pc(CPU(cpu), env->elf_address);
     }
 }
@@ -129,6 +149,7 @@  static void loongarch_direct_kernel_boot(LoongArchMachineState *lams,
         lacpu = LOONGARCH_CPU(qemu_get_cpu(i));
         lacpu->env.load_elf = true;
         lacpu->env.elf_address = kernel_addr;
+        lacpu->env.boot_info = info;
     }
 }
 
diff --git a/include/hw/loongarch/virt.h b/include/hw/loongarch/virt.h
index e4126dd0e7..d21de2cef4 100644
--- a/include/hw/loongarch/virt.h
+++ b/include/hw/loongarch/virt.h
@@ -31,6 +31,8 @@ 
 #define VIRT_GED_MEM_ADDR       (VIRT_GED_EVT_ADDR + ACPI_GED_EVT_SEL_LEN)
 #define VIRT_GED_REG_ADDR       (VIRT_GED_MEM_ADDR + MEMORY_HOTPLUG_IO_LEN)
 
+#define COMMAND_LINE_SIZE       512
+
 struct LoongArchMachineState {
     /*< private >*/
     MachineState parent_obj;
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index 00d1fba597..c7c695138e 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -362,6 +362,8 @@  typedef struct CPUArchState {
     uint64_t elf_address;
     /* Store ipistate to access from this struct */
     DeviceState *ipistate;
+
+    struct loongarch_boot_info *boot_info;
 #endif
 } CPULoongArchState;