OpenRISC Device Tree Support
PATCH v2 2/4 hw/openrisc/openrisc_sim: Parameterize initialization
In reply to Stafford HorneMove magic numbers to variables and enums. These will be reused for upcoming fdt initialization.
--- hw/openrisc/openrisc_sim.c | 42 ++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-)
hw/openrisc/openrisc_sim.c +34 -8
@@ -49,6 +49,29 @@ typedef struct Or1ksimState { } Or1ksimState; +enum { +OR1KSIM_DRAM , +OR1KSIM_UART , +OR1KSIM_ETHOC , +OR1KSIM_OMPIC , +}; + +enum { +OR1KSIM_OMPIC_IRQ =1 , +OR1KSIM_UART_IRQ =2 , +OR1KSIM_ETHOC_IRQ =4 , +}; + +static const struct MemmapEntry { +hwaddr base; +hwaddr size; +} or1ksim_memmap[] = { + [OR1KSIM_DRAM ] = {0x00000000 ,0 }, + [OR1KSIM_UART ] = {0x90000000 ,0x100 }, + [OR1KSIM_ETHOC ] = {0x92000000 ,0x800 }, + [OR1KSIM_OMPIC ] = {0x98000000 ,16 }, +}; +static struct openrisc_boot_info {uint32_t bootstrap_pc; } boot_info;
@@ -176,21 +199,24 @@ static void openrisc_sim_init(MachineState *machine)memory_region_add_subregion (get_system_memory (),0 , ram);if (nd_table[0 ].used) { -openrisc_sim_net_init (0x92000000 ,0x92000400 , smp_cpus, - cpus,4 , nd_table); +openrisc_sim_net_init (or1ksim_memmap[OR1KSIM_ETHOC ].base, + or1ksim_memmap[OR1KSIM_ETHOC ].base +0x400 , + smp_cpus, cpus, +OR1KSIM_ETHOC_IRQ , nd_table); }if (smp_cpus >1 ) { -openrisc_sim_ompic_init (0x98000000 , smp_cpus, cpus,1 ); +openrisc_sim_ompic_init (or1ksim_memmap[OR1KSIM_OMPIC ].base, smp_cpus, + cpus,OR1KSIM_OMPIC_IRQ ); - serial_irq =qemu_irq_split (get_cpu_irq (cpus,0 ,2 ), -get_cpu_irq (cpus,1 ,2 )); + serial_irq =qemu_irq_split (get_cpu_irq (cpus,0 ,OR1KSIM_UART_IRQ ), +get_cpu_irq (cpus,1 ,OR1KSIM_UART_IRQ )); }else { - serial_irq =get_cpu_irq (cpus,0 ,2 ); + serial_irq =get_cpu_irq (cpus,0 ,OR1KSIM_UART_IRQ ); } -serial_mm_init (get_system_memory (),0x90000000 ,0 , serial_irq, -115200 ,serial_hd (0 ),DEVICE_NATIVE_ENDIAN ); +serial_mm_init (get_system_memory (), or1ksim_memmap[OR1KSIM_UART ].base,0 , + serial_irq,115200 ,serial_hd (0 ),DEVICE_NATIVE_ENDIAN );openrisc_load_kernel (ram_size, kernel_filename); }
Signature · 1 line
2.31.1
PATCH v2 4/4 hw/openrisc/openrisc_sim: Add support for initrd loading
In reply to Stafford HorneThe initrd passed via the command line is loaded into memory. It's location and size is then added to the device tree so the kernel knows where to find it.
--- hw/openrisc/openrisc_sim.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
hw/openrisc/openrisc_sim.c +31 -1
@@ -187,6 +187,32 @@ static hwaddr openrisc_load_kernel(ram_addr_t ram_size,return 0 ; } +static hwaddr openrisc_load_initrd (Or1ksimState *s,const char *filename, +hwaddr load_start,uint64_t mem_size) +{ +int size; +hwaddr start; + +/* We put the initrd right after the kernel; page aligned. */ + start =TARGET_PAGE_ALIGN (load_start); + + size =load_ramdisk (filename, start, mem_size - start); +if (size <0 ) { + size =load_image_targphys (filename, start, mem_size - start); +if (size <0 ) { +error_report ("could not load ramdisk '%s'" , filename); +exit (1 ); + } + } + +qemu_fdt_setprop_cell (s->fdt,"/chosen" , +"linux,initrd-start" , start); +qemu_fdt_setprop_cell (s->fdt,"/chosen" , +"linux,initrd-end" , start + size); + +return start + size; +} +static uint32_t openrisc_load_fdt (Or1ksimState *s,hwaddr load_start,uint64_t mem_size) {
@@ -198,7 +224,7 @@ static uint32_t openrisc_load_fdt(Or1ksimState *s, hwaddr load_start,exit (1 ); } -/* We should put fdt right after the kernel */ +/* We put fdt right after the kernel and/or initrd. */ fdt_addr =ROUND_UP (load_start,4 );fdt_pack (s->fdt);
@@ -369,6 +395,10 @@ static void openrisc_sim_init(MachineState *machine) machine->kernel_cmdline); load_addr =openrisc_load_kernel (ram_size, kernel_filename); +if (machine->initrd_filename) { + load_addr =openrisc_load_initrd (s, machine->initrd_filename, + load_addr, machine->ram_size); + } boot_info.fdt_addr =openrisc_load_fdt (s, load_addr, machine->ram_size); }
Signature · 1 line
2.31.1
PATCH v2 3/4 hw/openrisc/openrisc_sim; Add support for loading a device tree
In reply to Stafford HorneUsing the device tree means that qemu can now directly tell the kernel what hardware is configured rather than use having to maintain and update a separate device tree file.
This patch adds device tree support for the OpenRISC simulator. A device tree is built up based on the state of the configure openrisc simulator.
This is then dumped to memory and the load address is passed to the kernel in register r3.
--- configs/targets/or1k-softmmu.mak | 1 + hw/openrisc/openrisc_sim.c | 159 ++++++++++++++++++++++++++++++- 2 files changed, 156 insertions(+), 4 deletions(-)
configs/targets/or1k-softmmu.mak +1 -0
@@ -1,2 +1,3 @@ TARGET_ARCH=openrisc TARGET_WORDS_BIGENDIAN=y +TARGET_NEED_FDT=y
hw/openrisc/openrisc_sim.c +155 -4
234 lines not on this page · raw message
Signature · 1 line
2.31.1
v2 cover OpenRISC Device Tree Support
Changes since v1:
- Fixed typos pointed out by Philippe
- Moved usage of machine state to patch 3/4
- added config dependency on FDT
This series adds device tree support for the OpenRISC SIM hardware.
The simulator will generate an FDT and pass it to the kernel.
For example:
qemu-system-or1k -cpu or1200 -M or1k-sim \
-kernel /home/shorne/work/linux/vmlinux \
-initrd /home/shorne/work/linux/initramfs.cpio.gz \
-serial mon:stdio -nographic -gdb tcp::10001 -m 32Using the linux kernel or1ksim_defconfig we can remove the built-in dts and the kernel will boot as expected. The real benefit here is being able to specify an external initrd which qemu will load into memory and the device tree will tell the kernel where to find it.
Stafford Horne (4):
hw/openrisc/openrisc_sim: Create machine state for or1ksim hw/openrisc/openrisc_sim: Parameterize initialization hw/openrisc/openrisc_sim; Add support for loading a device tree hw/openrisc/openrisc_sim: Add support for initrd loading
configs/targets/or1k-softmmu.mak | 1 + hw/openrisc/openrisc_sim.c | 261 +++++++++++++++++++++++++++++-- 2 files changed, 248 insertions(+), 14 deletions(-)
Signature · 1 line
2.31.1
PATCH v2 1/4 hw/openrisc/openrisc_sim: Create machine state for or1ksim
This will allow us to attach machine state attributes like the device tree fdt.
--- hw/openrisc/openrisc_sim.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-)
hw/openrisc/openrisc_sim.c +28 -2
@@ -37,6 +37,18 @@#define KERNEL_LOAD_ADDR 0x100 +#define TYPE_OR1KSIM_MACHINE MACHINE_TYPE_NAME("or1k-sim") +#define OR1KSIM_MACHINE (obj) \ + OBJECT_CHECK(Or1ksimState, (obj), TYPE_OR1KSIM_MACHINE) + +typedef struct Or1ksimState { +/*< private >*/ +MachineState parent_obj; + +/*< public >*/ + +}Or1ksimState ; +static struct openrisc_boot_info {uint32_t bootstrap_pc; } boot_info;
@@ -183,8 +195,10 @@ static void openrisc_sim_init(MachineState *machine)openrisc_load_kernel (ram_size, kernel_filename); } -static void openrisc_sim_machine_init (MachineClass *mc) +static void openrisc_sim_machine_init (ObjectClass *oc,void *data) { +MachineClass *mc =MACHINE_CLASS (oc); + mc->desc ="or1k simulation" ; mc->init = openrisc_sim_init; mc->max_cpus =2 ;
@@ -192,4 +206,16 @@ static void openrisc_sim_machine_init(MachineClass *mc) mc->default_cpu_type =OPENRISC_CPU_TYPE_NAME ("or1200" ); } -DEFINE_MACHINE ("or1k-sim" , openrisc_sim_machine_init) +static const TypeInfo or1ksim_machine_typeinfo = { + .name =TYPE_OR1KSIM_MACHINE , + .parent =TYPE_MACHINE , + .class_init = openrisc_sim_machine_init, + .instance_size =sizeof (Or1ksimState), +}; + +static void or1ksim_machine_init_register_types (void ) +{ +type_register_static (&or1ksim_machine_typeinfo); +} + +type_init (or1ksim_machine_init_register_types)
Signature · 1 line
2.31.1
Re: [PATCH v2 4/4] hw/openrisc/openrisc_sim: Add support for initrd loading
In reply to Stafford HorneQuoted 15 lines · Stafford Horne
The initrd passed via the command line is loaded into memory. It's location and size is then added to the device tree so the kernel knows where to find it.
Signed-off-by Stafford Horne <[email protected]>--- hw/openrisc/openrisc_sim.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)hw/openrisc/openrisc_sim.c +0
-0
hw/openrisc/openrisc_sim.c static hwaddr openrisc_load_kernel(ram_addr_t ram_size, · line 191
Quoted 5 lines
hw/openrisc/openrisc_sim.c +2
-0@@ -187,6 +187,32 @@ static hwaddr openrisc_load_kernel(ram_addr_t ram_size,return 0 ; } +static hwaddr openrisc_load_initrd (Or1ksimState *s,const char *filename, +hwaddr load_start,uint64_t mem_size)
Indentation here is off.
Otherwise
thanks
-- PMM
Re: [PATCH v2 4/4] hw/openrisc/openrisc_sim: Add support for initrd loading
Quoted 19 lines · Peter Maydell
Quoted 18 lines · Stafford Horne
The initrd passed via the command line is loaded into memory. It's location and size is then added to the device tree so the kernel knows where to find it.
Signed-off-by Stafford Horne <[email protected]>--- hw/openrisc/openrisc_sim.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)hw/openrisc/openrisc_sim.c +0
-0@@ -187,6 +187,32 @@ static hwaddr openrisc_load_kernel(ram_addr_t ram_size,return 0 ; }
Quoted 4 lines
hw/openrisc/openrisc_sim.c static hwaddr openrisc_load_kernel(ram_addr_t ram_size, · line 191
Quoted 2 lines
hw/openrisc/openrisc_sim.c +2
-0+static hwaddr openrisc_load_initrd (Or1ksimState *s,const char *filename, +hwaddr load_start,uint64_t mem_size)Indentation here is off.
Ah, I was going off the indentation already in the file. I will fix this.
i.e. should be:
static hwaddr openrisc_load_initrd(Or1ksimState *s, const char *filename,
hwaddr load_start, uint64_t mem_size)
That's why its like that everywhere. I might as well add another patch to fix up indentation.
Quoted 3 lines
Otherwise
Reviewed-by Peter Maydell <[email protected]>
Thanks!