diff mbox

[4/7] hw/arm/virt: Support dynamically spawned sysbus devices

Message ID 1404716892-15600-5-git-send-email-eric.auger@linaro.org
State New
Headers show

Commit Message

Auger Eric July 7, 2014, 7:08 a.m. UTC
Allows sysbus devices to be instantiated from command line by
using -device option

---

Inspired from what Alex Graf did in ppc e500
https://lists.gnu.org/archive/html/qemu-ppc/2014-07/msg00012.html

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Eric Auger <eric.auger@linaro.org>
---
 hw/arm/virt.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

Comments

Alexander Graf July 8, 2014, 1:51 p.m. UTC | #1
On 07.07.14 09:08, Eric Auger wrote:
> Allows sysbus devices to be instantiated from command line by
> using -device option
>
> ---
>
> Inspired from what Alex Graf did in ppc e500
> https://lists.gnu.org/archive/html/qemu-ppc/2014-07/msg00012.html
>
> Signed-off-by: Alexander Graf <agraf@suse.de>
> Signed-off-by: Eric Auger <eric.auger@linaro.org>
> ---
>   hw/arm/virt.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 57 insertions(+), 1 deletion(-)
>
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index eeecdbf..3a21db4 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -40,6 +40,8 @@
>   #include "exec/address-spaces.h"
>   #include "qemu/bitops.h"
>   #include "qemu/error-report.h"
> +#include "hw/misc/platform_devices.h"
> +#include "hw/vfio/vfio-platform.h"
>   
>   #define NUM_VIRTIO_TRANSPORTS 32
>   
> @@ -57,6 +59,14 @@
>   #define GIC_FDT_IRQ_PPI_CPU_START 8
>   #define GIC_FDT_IRQ_PPI_CPU_WIDTH 8
>   
> +#define MACHVIRT_PLATFORM_BASE         0xa004000

That's an odd address for a 128MB window. Can you make it 128MB aligned? 
Maybe move the virtio region behind this one?

With a bit of smartness we don't need a virtio-mmio region with this 
patch set anymore btw. We could just generate the virtio-mmio devices on 
our platform bus on the fly.

> +#define MACHVIRT_PLATFORM_HOLE         (128ULL * 1024 * 1024) /* 128 MB */

As Scott mentioned in the e500 review round, "hole" is an odd name ;).


Alex
Peter Maydell July 8, 2014, 1:55 p.m. UTC | #2
On 8 July 2014 14:51, Alexander Graf <agraf@suse.de> wrote:
> On 07.07.14 09:08, Eric Auger wrote:
>>   +#define MACHVIRT_PLATFORM_BASE         0xa004000
>
>
> That's an odd address for a 128MB window. Can you make it 128MB aligned?
> Maybe move the virtio region behind this one?

I'd rather not move things around if we can avoid it. I know in
theory the guest should only ever be looking at the DTB to
find things, but still...

> With a bit of smartness we don't need a virtio-mmio region with this patch
> set anymore btw. We could just generate the virtio-mmio devices on our
> platform bus on the fly.

Hmmm....

thanks
-- PMM
Auger Eric July 23, 2014, 3:01 p.m. UTC | #3
On 07/08/2014 03:51 PM, Alexander Graf wrote:
> 
> On 07.07.14 09:08, Eric Auger wrote:
>> Allows sysbus devices to be instantiated from command line by
>> using -device option
>>
>> ---
>>
>> Inspired from what Alex Graf did in ppc e500
>> https://lists.gnu.org/archive/html/qemu-ppc/2014-07/msg00012.html
>>
>> Signed-off-by: Alexander Graf <agraf@suse.de>
>> Signed-off-by: Eric Auger <eric.auger@linaro.org>
>> ---
>>   hw/arm/virt.c | 58
>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>>   1 file changed, 57 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
>> index eeecdbf..3a21db4 100644
>> --- a/hw/arm/virt.c
>> +++ b/hw/arm/virt.c
>> @@ -40,6 +40,8 @@
>>   #include "exec/address-spaces.h"
>>   #include "qemu/bitops.h"
>>   #include "qemu/error-report.h"
>> +#include "hw/misc/platform_devices.h"
>> +#include "hw/vfio/vfio-platform.h"
>>     #define NUM_VIRTIO_TRANSPORTS 32
>>   @@ -57,6 +59,14 @@
>>   #define GIC_FDT_IRQ_PPI_CPU_START 8
>>   #define GIC_FDT_IRQ_PPI_CPU_WIDTH 8
>>   +#define MACHVIRT_PLATFORM_BASE         0xa004000
> 
> That's an odd address for a 128MB window. Can you make it 128MB aligned?
> Maybe move the virtio region behind this one?
Yes you're right. I didn't pay attention to that. Now we have to find a
hole agreed with everybody if that's feasible ;-)
> 
> With a bit of smartness we don't need a virtio-mmio region with this
> patch set anymore btw. We could just generate the virtio-mmio devices on
> our platform bus on the fly.
> 
>> +#define MACHVIRT_PLATFORM_HOLE         (128ULL * 1024 * 1024) /* 128
>> MB */
> 
> As Scott mentioned in the e500 review round, "hole" is an odd name ;).
OK I will rename that.
> 
> 
> Alex
>
diff mbox

Patch

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index eeecdbf..3a21db4 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -40,6 +40,8 @@ 
 #include "exec/address-spaces.h"
 #include "qemu/bitops.h"
 #include "qemu/error-report.h"
+#include "hw/misc/platform_devices.h"
+#include "hw/vfio/vfio-platform.h"
 
 #define NUM_VIRTIO_TRANSPORTS 32
 
@@ -57,6 +59,14 @@ 
 #define GIC_FDT_IRQ_PPI_CPU_START 8
 #define GIC_FDT_IRQ_PPI_CPU_WIDTH 8
 
+#define MACHVIRT_PLATFORM_BASE         0xa004000
+#define MACHVIRT_PLATFORM_HOLE         (128ULL * 1024 * 1024) /* 128 MB */
+#define MACHVIRT_PLATFORM_PAGE_SHIFT   12
+#define MACHVIRT_PLATFORM_HOLE_PAGES   (MACHVIRT_PLATFORM_HOLE >> \
+                                    MACHVIRT_PLATFORM_PAGE_SHIFT)
+#define MACHVIRT_PLATFORM_FIRST_IRQ    48
+#define MACHVIRT_PLATFORM_NUM_IRQS     20
+
 enum {
     VIRT_FLASH,
     VIRT_MEM,
@@ -66,6 +76,7 @@  enum {
     VIRT_UART,
     VIRT_MMIO,
     VIRT_RTC,
+    VIRT_PLATFORM,
 };
 
 typedef struct MemMapEntry {
@@ -108,6 +119,7 @@  static const MemMapEntry a15memmap[] = {
     [VIRT_MMIO] = { 0xa000000, 0x200 },
     /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
     /* 0x10000000 .. 0x40000000 reserved for PCI */
+    [VIRT_PLATFORM] = {MACHVIRT_PLATFORM_BASE , MACHVIRT_PLATFORM_HOLE},
     [VIRT_MEM] = { 0x40000000, 30ULL * 1024 * 1024 * 1024 },
 };
 
@@ -115,6 +127,15 @@  static const int a15irqmap[] = {
     [VIRT_UART] = 1,
     [VIRT_RTC] = 2,
     [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
+    [VIRT_PLATFORM] = MACHVIRT_PLATFORM_FIRST_IRQ,
+};
+
+static PlatformParams machvirt_params = {
+    .has_platform_bus = true,
+    .platform_bus_base = MACHVIRT_PLATFORM_BASE,
+    .platform_bus_size = MACHVIRT_PLATFORM_HOLE,
+    .platform_bus_first_irq = MACHVIRT_PLATFORM_FIRST_IRQ,
+    .platform_bus_num_irqs = MACHVIRT_PLATFORM_NUM_IRQS
 };
 
 static VirtBoardInfo machines[] = {
@@ -437,6 +458,18 @@  static void create_virtio_devices(const VirtBoardInfo *vbi, qemu_irq *pic)
     fdt_add_virtio_nodes(vbi);
 }
 
+static void machvirt_prep_device_tree(VirtBoardInfo *vbi)
+{
+    create_fdt(vbi);
+    fdt_add_timer_nodes(vbi);
+    fdt_add_cpu_nodes(vbi);
+    fdt_add_psci_node(vbi);
+    fdt_add_gic_node(vbi);
+    fdt_add_uart_node(vbi);
+    fdt_add_rtc_node(vbi);
+    fdt_add_virtio_nodes(vbi);
+}
+
 static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size)
 {
     const VirtBoardInfo *board = (const VirtBoardInfo *)binfo;
@@ -445,14 +478,27 @@  static void *machvirt_dtb(const struct arm_boot_info *binfo, int *fdt_size)
     return board->fdt;
 }
 
+static void machvirt_reset_device_tree(void *opaque)
+{
+    VirtBoardInfo *board = (VirtBoardInfo *)opaque;
+    struct arm_boot_info *info = &board->bootinfo;
+    hwaddr dtb_start = QEMU_ALIGN_UP(info->initrd_start + info->initrd_size,
+                                     4096);
+    machvirt_prep_device_tree(board);
+    platform_bus_create_devtree(&machvirt_params, board->fdt, "/intc");
+
+    load_dtb(dtb_start, info);
+}
+
 static void machvirt_init(MachineState *machine)
 {
-    qemu_irq pic[NUM_IRQS];
+    qemu_irq *pic = g_new(qemu_irq, NUM_IRQS);
     MemoryRegion *sysmem = get_system_memory();
     int n;
     MemoryRegion *ram = g_new(MemoryRegion, 1);
     const char *cpu_model = machine->cpu_model;
     VirtBoardInfo *vbi;
+    PlatformBusNotifier *notifier;
 
     if (!cpu_model) {
         cpu_model = "cortex-a15";
@@ -526,6 +572,13 @@  static void machvirt_init(MachineState *machine)
      */
     create_virtio_devices(vbi, pic);
 
+    notifier = g_new(PlatformBusNotifier, 1);
+    notifier->notifier.notify = platform_bus_init_notify;
+    notifier->address_space_mem = sysmem;
+    notifier->mpic = pic;
+    notifier->params = machvirt_params;
+    qemu_add_machine_init_done_notifier(&notifier->notifier);
+
     vbi->bootinfo.ram_size = machine->ram_size;
     vbi->bootinfo.kernel_filename = machine->kernel_filename;
     vbi->bootinfo.kernel_cmdline = machine->kernel_cmdline;
@@ -535,6 +588,8 @@  static void machvirt_init(MachineState *machine)
     vbi->bootinfo.loader_start = vbi->memmap[VIRT_MEM].base;
     vbi->bootinfo.get_dtb = machvirt_dtb;
     arm_load_kernel(ARM_CPU(first_cpu), &vbi->bootinfo);
+
+    qemu_register_reset(machvirt_reset_device_tree, vbi);
 }
 
 static QEMUMachine machvirt_a15_machine = {
@@ -542,6 +597,7 @@  static QEMUMachine machvirt_a15_machine = {
     .desc = "ARM Virtual Machine",
     .init = machvirt_init,
     .max_cpus = 4,
+    .has_dynamic_sysbus = true,
 };
 
 static void machvirt_machine_init(void)