hw/arm: Add 'virt' platform
Subsystems (2)
v8 cover hw/arm: Add 'virt' platform
This patch series adds a 'virt' platform which uses the kernel's mach-virt (fully device-tree driven) support to create a simple minimalist platform intended for use for KVM VM guests.
v6->v7 change is just flipping the order we put the virtio nodes into the device tree, to match vexpress and ppc precedent.
Since that's a pretty minor change I plan to put this into a pullreq to go into 1.7 soonish (read: probably this weekend). Yell now if you disagree.
Sample command line:
qemu-system-arm -machine type=virt -display none \
-kernel zImage \
-append 'root=/dev/vda rw console=ttyAMA0 rootwait' -cpu cortex-a15 \
-device virtio-blk-device,drive=foo \
-drive if=none,file=arm-wheezy.img,id=foo \
-m 2048 -serial stdio
Note that there is no earlyprintk via the PL011 because there's no defined device tree binding for "hey, here is your earlyprintk UART".
*** NOTE *** to get the PL011 to work you'll need to tweak the kernel a bit:
arch/arm/mach-virt/virt.c +2 -0
@@ -21,11 +21,13 @@#include <linux/of_irq.h> #include <linux/of_platform.h> #include <linux/smp.h> +#include <linux/clk-provider.h> #include <asm/mach/arch.h> static void __init virt_init (void ) { +of_clk_init (NULL );of_platform_populate (NULL , of_default_bus_match_table,NULL ,NULL ); }
Otherwise the kernel doesn't ever add the clock to its list, and then it refuses to probe for the PL011. (I'm told this isn't really the right fix, though, and ideally the call should be done in some generic location rather than in every machine's init function.)
The alternative would be for the kernel to be fixed to follow its own device tree binding documentation and not require clocks/clock-names properties on the pl011 node.
Changes from John Rigby's v3->my v4:
* renamed user-facing machine to just "virt"
* removed the A9 support (it can't work since the A9 has no generic timers)
* added virtio-mmio transports instead of random set of 'soc' devices
* instead of updating io_base as we step through adding devices, define a memory map with an array (similar to vexpress)
* folded in some minor fixes from John's aarch64-support patch
* rather than explicitly doing endian-swapping on FDT cells, use fdt APIs that let us just pass in host-endian values and let the fdt layer take care of the swapping
* miscellaneous minor code cleanups and style fixes
Changes v4->v5:
* removed outdated TODO remarks from commit messages
Changes v5->v6:
* adjusted the memory map as per Anup's review comments (actually made the changes this time!)
Changes v6->v7:
* added a PL011 UART, at Alex's suggestion (and the accompanying fake clock dtb node that this requires)
* added an irqmap[] in parallel with the memmap[] so that our assignment of devices to irq lines is neatly in one place
* the removal of arm_pic allows us to get rid of an irritating array sized to the number of CPUs
* included the "terminate dtb reservemap" patch since it's a dependency to get the kernel to boot
Changes v7->v8:
* iterate through virtio-mmio nodes the opposite way round so that they appear in the device tree lowest-address-first; this matches PPC behaviour and the vexpress code
John Rigby (1):
hw/arm/boot: Allow boards to provide an fdt blob
Peter Maydell (2):
device_tree.c: Terminate the empty reservemap in create_device_tree() hw/arm: Add 'virt' platform
device_tree.c | 4 + hw/arm/Makefile.objs | 2 +- hw/arm/boot.c | 32 ++-- hw/arm/virt.c | 418 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/arm/arm.h | 7 + 5 files changed, 450 insertions(+), 13 deletions(-) create mode 100644 hw/arm/virt.c
Signature · 1 line
1.7.9.5
PATCH v8 1/3 device_tree.c: Terminate the empty reservemap in create_device_tree()
Device trees created with create_device_tree() may not have any entries in their reservemap, because the FDT API requires that the reservemap is completed before any FDT nodes are added, and create_device_tree() itself creates a node. However we were not calling fdt_finish_reservemap(), which meant that there was no terminator in the reservemap list and whatever happened to be at the start of the FDT data section would end up being interpreted as reservemap entries. Avoid this by calling fdt_finish_reservemap() to add the terminator.
--- device_tree.c | 4 ++++ 1 file changed, 4 insertions(+)
device_tree.c +4 -0
@@ -41,6 +41,10 @@ void *create_device_tree(int *sizep)if (ret <0 ) { goto fail; } + ret =fdt_finish_reservemap (fdt); +if (ret <0 ) { + goto fail; + } ret =fdt_begin_node (fdt,"" );if (ret <0 ) { goto fail;
Signature · 1 line
1.7.9.5
Quoted 8 lines · Peter Maydell
This patch series adds a 'virt' platform which uses the kernel's mach-virt (fully device-tree driven) support to create a simple minimalist platform intended for use for KVM VM guests.
v6->v7change is just flipping the order we put the virtio nodes into the device tree, to match vexpress and ppc precedent.
that's v7->v8 changes right?
-Christoffer
Quoted 11 lines · Christoffer Dall
Quoted 8 lines · Peter Maydell
This patch series adds a 'virt' platform which uses the kernel's mach-virt (fully device-tree driven) support to create a simple minimalist platform intended for use for KVM VM guests.
v6->v7change is just flipping the order we put the virtio nodes into the device tree, to match vexpress and ppc precedent.that's
v7->v8changes right?
doh, yes.
-- PMM
PATCH v8 2/3 hw/arm/boot: Allow boards to provide an fdt blob
In reply to Peter MaydellFrom: John Rigby <[email protected]>
If no fdt is provided on command line and the new field get_dtb in struct arm_boot_info is set then call it to get a device tree blob.
--- hw/arm/boot.c | 32 ++++++++++++++++++++------------ include/hw/arm/arm.h | 7 +++++++ 2 files changed, 27 insertions(+), 12 deletions(-)
hw/arm/boot.c +20 -12
@@ -228,23 +228,31 @@ static void set_kernel_args_old(const struct arm_boot_info *info)static int load_dtb (hwaddr addr,const struct arm_boot_info *binfo) {void *fdt =NULL ; -char *filename;int size, rc;uint32_t acells, scells; - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , binfo->dtb_filename); -if (!filename) { -fprintf (stderr,"Couldn't open dtb file %s\n" , binfo->dtb_filename); - goto fail; - } +if (binfo->dtb_filename) { +char *filename; + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , binfo->dtb_filename); +if (!filename) { +fprintf (stderr,"Couldn't open dtb file %s\n" , binfo->dtb_filename); + goto fail; + } - fdt =load_device_tree (filename, &size); -if (!fdt) { -fprintf (stderr,"Couldn't open dtb file %s\n" , filename); + fdt =load_device_tree (filename, &size); +if (!fdt) { +fprintf (stderr,"Couldn't open dtb file %s\n" , filename); +g_free (filename); + goto fail; + }g_free (filename); - goto fail; + }else if (binfo->get_dtb) { + fdt = binfo->get_dtb (binfo, &size); +if (!fdt) { +fprintf (stderr,"Board was unable to create a dtb blob\n" ); + goto fail; + } } -g_free (filename); acells =qemu_devtree_getprop_cell (fdt,"/" ,"#address-cells" ); scells =qemu_devtree_getprop_cell (fdt,"/" ,"#size-cells" );
@@ -436,7 +444,7 @@ void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)/* for device tree boot, we pass the DTB directly in r2. Otherwise * we point to the kernel args. */ -if (info->dtb_filename) { +if (info->dtb_filename || info->get_dtb) {/* Place the DTB after the initrd in memory. Note that some * kernels will trash anything in the 4K page the initrd * ends in, so make sure the DTB isn't caught up in that.
include/hw/arm/arm.h +7 -0
@@ -50,6 +50,13 @@ struct arm_boot_info { const struct arm_boot_info *info);void (*secondary_cpu_reset_hook)(ARMCPU *cpu,const struct arm_boot_info *info); +/* if a board is able to create a dtb without a dtb file then it +* sets get_dtb. This will only be used if no dtb file is provided +* by the user. On success, sets *size to the length of the created +* dtb, and returns a pointer to it. (The caller must free this memory +* with g_free() when it has finished with it.) On failure, returns NULL. +*/ +void *(*get_dtb)(const struct arm_boot_info *info,int *size);/* if a board needs to be able to modify a device tree provided by * the user it should implement this hook. */
Signature · 1 line
1.7.9.5
PATCH v8 3/3 hw/arm: Add 'virt' platform
In reply to Peter MaydellAdd 'virt' platform support corresponding to arch/arm/mach-virt in the Linux kernel tree. This has no platform-specific code but can use any device whose kernel driver is is able to work purely from a device tree node. We use this to instantiate a minimal set of devices: a GIC and some virtio-mmio transports.
[PMM:
Significantly overhauled:
* renamed user-facing machine to just "virt"
* removed the A9 support (it can't work since the A9 has no generic timers)
* added virtio-mmio transports instead of random set of 'soc' devices (though we retain a pl011 UART)
* instead of updating io_base as we step through adding devices, define a memory map with an array (similar to vexpress)
* similarly, define irqmap with an array
* folded in some minor fixes from John's aarch64-support patch
* rather than explicitly doing endian-swapping on FDT cells, use fdt APIs that let us just pass in host-endian values and let the fdt layer take care of the swapping
* miscellaneous minor code cleanups and style fixes
]
--- hw/arm/Makefile.objs | 2 +- hw/arm/virt.c | 418 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 hw/arm/virt.c
hw/arm/Makefile.objs +1 -1
@@ -1,7 +1,7 @@ obj-y += boot.o collie.o exynos4_boards.o gumstix.o highbank.o obj-y += integratorcp.o kzm.o mainstone.o musicpal.o nseries.o obj-y += omap_sx1.o palm.o realview.o spitz.o stellaris.o -obj-y += tosa.o versatilepb.o vexpress.o xilinx_zynq.o z2.o +obj-y += tosa.o versatilepb.o vexpress.o virt.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o
hw/arm/virt.c new file +418 -0
418 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Quoted 13 lines · Peter Maydell
Add 'virt' platform support corresponding to
arch/arm/mach-virtin the Linux kernel tree. This has no platform-specific code but can use any device whose kernel driver is is able to work purely from a device tree node. We use this to instantiate a minimal set of devices: a GIC and some virtio-mmio transports.hw/arm/virt.c new file +7
-0+/* Addresses and sizes of our components. +* We leave the first 64K free for possible use later for +* flash (for running boot code such as UEFI); following +* that is I/O, and then everything else is RAM (which may +* happily spill over into the high memory region beyond 4GB). +*/ +static const MemMapEntry a15memmap[] = {
hw/arm/virt.c line 105
Quoted 10 lines
hw/arm/virt.c new file +10
-0+ [VIRT_FLASH] = { 0, 0x1000000 }, + [VIRT_CPUPERIPHS ] = {0x1000000 ,0x8000 }, + /* GIC distributor and CPU interfaces sit inside the CPU peripheral space */ + [VIRT_GIC_DIST] = { 0x1001000, 0x1000 }, + [VIRT_GIC_CPU] = { 0x1002000, 0x1000 }, + [VIRT_UART] = { 0x1008000, 0x1000 }, + [VIRT_MMIO ] = {0x2000000 ,0x200 }, + /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ + [VIRT_MEM] = { 0x8000000, 30ULL * 1024 * 1024 * 1024 }, +};
So, following some conversations at Linaro Connect this week it occurred to me that it might be better to arrange the mach-virt memory map with some space so that if a miracle occurs and we can get pci-e support into it then we don't have to have a migration compat break when we move the RAM around.
Something like:
0 .. 0.25GB: flash, cpu periphs, etc, virtio-mmio as above 0.25GB..1GB: space here for PCI memory window
1GB and up: RAM
but since I don't have much PCI experience I dunno whether that makes sense as a set of sizes. Comments/corrections welcome.
thanks
-- PMM
Quoted 9 lines · Peter Maydell
This patch series adds a 'virt' platform which uses the kernel's mach-virt (fully device-tree driven) support to create a simple minimalist platform intended for use for KVM VM guests.
Changes
v7->v8:
* iterate through virtio-mmio nodes the opposite way round so that they appear in the device tree lowest-address-first; this matches PPC behaviour and the vexpress code
...it turns out this isn't quite right. We need to create the actual devices in forwards order (so that devices created on the qemu command line populate the transports lowest address first) and then create the dtb nodes in reverse order (so that the transports appear in the final dtb lowest address first). Ugh.
Given this plus the fact that you still need a kernel patch to get the thing to boot at all [would anybody on the kernel side like to pick up that particular ball?], I'm leaning toward not putting this in 1.7 now.
-- PMM
Quoted 17 lines · Peter Maydell
Quoted 9 lines · Peter Maydell
This patch series adds a 'virt' platform which uses the kernel's mach-virt (fully device-tree driven) support to create a simple minimalist platform intended for use for KVM VM guests.
Changes
v7->v8:
* iterate through virtio-mmio nodes the opposite way round so that they appear in the device tree lowest-address-first; this matches PPC behaviour and the vexpress code...it turns out this isn't quite right. We need to create the actual devices in forwards order (so that devices created on the qemu command line populate the transports lowest address first) and then create the dtb nodes in reverse order (so that the transports appear in the final dtb lowest address first). Ugh.
Quoted 4 lines
Given this plus the fact that you still need a kernel patch to get the thing to boot at all [would anybody on the kernel side like to pick up that particular ball?], I'm leaning toward not putting this in 1.7 now.
We could add a fdt_append_subnode_namelen() function that instead of putting it after the parent's properties puts the new node after all subnodes. While we're waiting for it to trickle into libfdt we could keep a copy in device_tree.c.
Then we just switch everything to "natural" non-reverse order append_subnode().
Alex