Allow sysbus devices to be attached via commandline
v2 cover Allow sysbus devices to be attached via commandline
This patch allows sysbus devices to be attached via command line arguments.
This can be used to build an entire machine from the command line or to just add devices that aren't in the machine_init code.
A peripheral can be added with the following syntax:
-device cadence_uart,addr=0xE0000000,irq=27
A CPU can be added with either of the following:
-device cpu,model=cortex-a9,type=arm-cpu,reset-cbar=0xF8F00000,midr=0x413 FC090
-sysbusdev device=cpu,name=microblaze-cp
RAM or ROM can be attached with this command:
-device memory,name=zynq.ext_ram,addr=0x00000000,size=0x8000000
Multiple IRQ lines can be used as well as multiple properties:
-device pl330,addr=0xF8003000,irq=13,irq=14,irq=15,irq=16,irq=17,\
irq=40,irq=41,irq=42,irq=43,num_chnls=8,num_periph_req=4,num_events=16
This implementation uses a three round multi-pass method. This will hopefully allow devices attached via the command line to be connected to other command line devices (I haven't managed to get that working yet though)
With Li Guang's blob loader implemented it is also possible to boot images while using "-M none".
V2:
Use -device to attach the devices (Thanks Markus Armbruster) Make the method much more generic
Allow CPUs and Memory to be attached via command line Allow properties to be passed in via the command line
Thanks to Markus Armbruster and Peter Crosthwaite for feedback on the first version
Alistair Francis (4):
qemu-option.c: Add qemu_opt functions that step over arguments
qdev-monitor: Implement three functions used to connect devices vl.c: Enable adding devices to the system bus qemu-options.hx: Update the command line documentation for -device
include/hw/boards.h | 2 + include/monitor/qdev.h | 3 + include/qemu/option.h | 2 + include/qemu/option_int.h | 1 + qdev-monitor.c | 237 ++++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 8 +- util/qemu-option.c | 30 ++++++ vl.c | 74 +++++++++++++- 8 files changed, 346 insertions(+), 11 deletions(-)
PATCH v2 1/4 qemu-option.c: Add qemu_opt functions that step over arguments
This adds two functions, qemu_opt_step() and qemu_opt_name_step() which iterate over the comma separated stings in the QemuOpts* argument. This allows accessing multiple arguments with the same name by iterating over all of the arguments
---
include/qemu/option.h | 2 ++ util/qemu-option.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-)
include/qemu/option.h +2 -0
@@ -110,6 +110,8 @@ struct QemuOptsList { };const char *qemu_opt_get (QemuOpts *opts,const char *name); +const char *qemu_opt_name_step (QemuOpts *opts,int num); +const char *qemu_opt_step (QemuOpts *opts,int num);/** * qemu_opt_has_help_opt: * @opts: options to search for a help request
util/qemu-option.c +30 -0
@@ -541,6 +541,36 @@ void print_option_help(QEMUOptionParameter *list)/* ------------------------------------------------------------------ */ +const char *qemu_opt_name_step (QemuOpts *opts,int num) +{ +QemuOpt *opt; +int i =0 ; + + QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) { +if (i < num) { + i++; +continue ; + } +return opt->name; + } +return NULL ; +} + +const char *qemu_opt_step (QemuOpts *opts,int num) +{ +QemuOpt *opt; +int i =0 ; + + QTAILQ_FOREACH_REVERSE(opt, &opts->head, QemuOptHead, next) { +if (i < num) { + i++; +continue ; + } +return opt->str; + } +return NULL ; +} +static QemuOpt *qemu_opt_find (QemuOpts *opts,const char *name) {QemuOpt *opt;
Signature · 1 line
1.7.1
PATCH v2 2/4 qdev-monitor: Implement three functions used to connect devices
In reply to Alistair FrancisThese functions are used to attach devices that are passed in via the command line using the -device argument.
The reason for using three functions is to allow a multi-pass approach. This can then be extended to allow devices to connect to other devices that are being connected via the command line (for example DMA/ethernet AXI-Stream).
---
include/hw/boards.h | 2 + include/monitor/qdev.h | 3 + include/qemu/option_int.h | 1 + qdev-monitor.c | 237 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 241 insertions(+), 2 deletions(-)
include/hw/boards.h +2 -0
@@ -15,6 +15,8 @@ typedef struct QEMUMachineInitArgs {const char *kernel_cmdline;const char *initrd_filename;const char *cpu_model; +DeviceState *intc; +Object *cpu; } QEMUMachineInitArgs;typedef void QEMUMachineInitFunc (QEMUMachineInitArgs *args);
include/monitor/qdev.h +3 -0
@@ -11,5 +11,8 @@ void do_info_qdm(Monitor *mon, const QDict *qdict);int do_device_add (Monitor *mon,const QDict *qdict,QObject **ret_data);int qdev_device_help (QemuOpts *opts);DeviceState *qdev_device_add (QemuOpts *opts); +DeviceState *qdev_device_create (QemuOpts *opts); +DeviceState *qdev_device_init (QemuOpts *opts,DeviceState * intc); +DeviceState *qdev_device_connect (QemuOpts *opts,DeviceState * intc);#endif
include/qemu/option_int.h +1 -0
@@ -47,6 +47,7 @@ struct QemuOpts {char *id;QemuOptsList *list;Location loc; +void *opaque; QTAILQ_HEAD(QemuOptHead, QemuOpt) head;QTAILQ_ENTRY (QemuOpts) next; };
qdev-monitor.c +235 -2
257 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 3/4 vl.c: Enable adding devices to the system bus
In reply to Alistair FrancisThis removes the old method to connect devices and replaces it with three calls to the three qdev-monitor functions added in the previous patch.
This allows complete machines to be built via the command line as well as just attaching simple sysbus devices.
---
vl.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 68 insertions(+), 6 deletions(-)
vl.c +68 -6
@@ -97,6 +97,7 @@ int main(int argc, char **argv)#include "qemu-options.h" #include "qmp-commands.h" #include "qemu/main-loop.h" +#include "qemu/option_int.h" #ifdef CONFIG_VIRTFS #include "fsdev/qemu-fsdev.h" #endif
@@ -2381,14 +2382,63 @@ static int device_help_func(QemuOpts *opts, void *opaque)return qdev_device_help (opts); } +static int device_add_func (QemuOpts *opts,void *opaque) +{ +DeviceState *dev; + +if (strcmp (qemu_opt_get (opts,"driver" ),"memory" ) && +strcmp (qemu_opt_get (opts,"driver" ),"cpu" ) && + opts->opaque ==NULL ) { + dev =qdev_device_add (opts); +if (!dev) { +return -1 ; + } +object_unref (OBJECT (dev)); + } +return 0 ; +} + +static int device_create_func (QemuOpts *opts,void *opaque) +{ +DeviceState *dev; + + dev =qdev_device_create (opts); + +return 0 ; +} +static int device_init_func (QemuOpts *opts,void *opaque) {DeviceState *dev; +QEMUMachineInitArgs *current_machine = (QEMUMachineInitArgs *) opaque; +DeviceState *intc = current_machine->intc; - dev =qdev_device_add (opts); -if (!dev) -return -1 ; -object_unref (OBJECT (dev)); + dev =qdev_device_init (opts, intc); + +if (dev && (dev->num_gpio_in >32 )) { +/* Store the Interupt Controller */ + current_machine->intc = dev; + } + +return 0 ; +} + +static int device_connect_func (QemuOpts *opts,void *opaque) +{ +DeviceState *dev; +QEMUMachineInitArgs *current_machine = (QEMUMachineInitArgs *) opaque; +DeviceState *intc = current_machine->intc; + + dev =qdev_device_connect (opts, intc); + +if (dev && (dev->num_gpio_in >0 )) { +/* Store the Interupt Controller */ + current_machine->intc = dev; + } + +if (dev) { +object_unref (OBJECT (dev)); + }return 0 ; }
@@ -4377,11 +4427,21 @@ int main(int argc, char **argv, char **envp) .kernel_filename = kernel_filename, .kernel_cmdline = kernel_cmdline, .initrd_filename = initrd_filename, - .cpu_model = cpu_model }; + .cpu_model = cpu_model, + .intc = NULL }; current_machine->init_args = args; machine->init (¤t_machine->init_args); +/* Create devices */ +qemu_opts_foreach (qemu_find_opts ("device" ), device_create_func,NULL ,1 ); +/* Init devices */ +qemu_opts_foreach (qemu_find_opts ("device" ), device_init_func, + ¤t_machine->init_args,1 ); +/* Init devices */ +qemu_opts_foreach (qemu_find_opts ("device" ), device_connect_func, + ¤t_machine->init_args,1 ); +audio_init ();cpu_synchronize_all_post_init ();
@@ -4395,8 +4455,10 @@ int main(int argc, char **argv, char **envp) }/* init generic devices */ -if (qemu_opts_foreach (qemu_find_opts ("device" ), device_init_func,NULL ,1 ) !=0 ) +if (qemu_opts_foreach (qemu_find_opts ("device" ), device_add_func, +NULL ,1 ) !=0 ) {exit (1 ); + }net_check_clients ();
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v2 3/4] vl.c: Enable adding devices to the system bus
Quoted 13 lines · Alistair Francis
This removes the old method to connect devices and replaces it with three calls to the three qdev-monitor functions added in the previous patch.
This allows complete machines to be built via the command line as well as just attaching simple sysbus devices.
static int
device_init_func(QemuOpts *opts, void *opaque){ DeviceState *dev;vl.c +2
-0+QEMUMachineInitArgs *current_machine = (QEMUMachineInitArgs *) opaque; +DeviceState *intc = current_machine->intc;
vl.c static int device_help_func(QemuOpts *opts, void *opaque) · line 2421
Quoted 10 lines
vl.c +6
-4- dev =qdev_device_add (opts); -if (!dev) -return -1 ; -object_unref (OBJECT (dev)); + dev =qdev_device_init (opts, intc); + +if (dev && (dev->num_gpio_in >32 )) { +/* Store the Interupt Controller */ + current_machine->intc = dev; + }
What is this doing here?? Interrupt controllers should not be special cases, and they're certainly not guaranteed to be the only things with 32 GPIO inputs...
thanks
-- PMM
PATCH v2 4/4 qemu-options.hx: Update the command line documentation for -device
In reply to Alistair FrancisUpdate the command line documentation to include the new sysbus connection ability
---
qemu-options.hx | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
qemu-options.hx +5 -3
@@ -315,8 +315,8 @@ DEF("device", HAS_ARG, QEMU_OPTION_device, "-device driver[,prop[=value][,...]]\n" " add device (based on driver)\n" " prop=value,... sets driver properties\n" - " use '-device help' to print all possible drivers\n" - " use '-device driver,help' to print all possible properties\n", + " use '-device help' to print all possible non sysbus drivers\n" + " use '-device driver,help' to print all possible non sysbus properties\n", QEMU_ARCH_ALL) STEXI @item -device @var{driver}[,@var{prop}[=@var{value}][,...]]
@@ -324,7 +324,9 @@ STEXI Add device @var{driver}. @var{prop}=@var{value} sets driver properties. Valid properties depend on the driver. To get help on possible drivers and properties, use @code{-device help} and -@code{-device @var{driver},help}. +@code{-device @var{driver},help}. Valid properties for sysbus devices +include: addr and irq. Which specifies the sysbus device base address +and irq number respectivly. ETEXI DEF("name", HAS_ARG, QEMU_OPTION_name,
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v2 4/4] qemu-options.hx: Update the command line documentation for -device
Quoted 14 lines · Alistair Francis
Update the command line documentation to include the new sysbus connection ability
Signed-off-by Alistair Francis <[email protected]>---
qemu-options.hx | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)qemu-options.hx +0
-0
qemu-options.hx DEF("device", HAS_ARG, QEMU_OPTION_device, · line 318
Quoted 6 lines
qemu-options.hx +1
-2@@ -315,8 +315,8 @@ DEF("device", HAS_ARG, QEMU_OPTION_device, "-device driver[,prop[=value][,...]]\n" " add device (based on driver)\n" " prop=value,... sets driver properties\n" - " use '-device help' to print all possible drivers\n" - " use '-device driver,help' to print all possible properties\n", + " use '-device help' to print all possible non sysbus drivers\n"
I'm not sure why sysbus devs should be excluded here - is this just a bug?
qemu-options.hx DEF("device", HAS_ARG, QEMU_OPTION_device, · line 319
Quoted 1 line
qemu-options.hx +1
-0+ " use '-device driver,help' to print all possible non sysbus properties\n",
Any reason this doesn't work?
Regards,
Peter
Quoted 18 lines
qemu-options.hx +3
-2QEMU_ARCH_ALL) STEXI @item -device @var{driver}[,@var{prop}[=@var{value}][,...]]@@ -324,7 +324,9 @@ STEXI Add device @var{driver}. @var{prop}=@var{value} sets driver properties. Valid properties depend on the driver. To get help on possible drivers and properties, use @code{-device help} and -@code{-device @var{driver},help}. +@code{-device @var{driver},help}. Valid properties for sysbus devices +include: addr and irq. Which specifies the sysbus device base address +and irq number respectivly. ETEXI DEF("name", HAS_ARG, QEMU_OPTION_name, --1.7.1
CC Konstanty
Quoted 55 lines · Alistair Francis
This patch allows sysbus devices to be attached via command line arguments.
This can be used to build an entire machine from the command line or to just add devices that aren't in the
machine_initcode.A peripheral can be added with the following syntax:
-device cadence_uart,addr=0xE0000000,irq=27A CPU can be added with either of the following:
(quoted diff) +0
-2-device cpu,model=cortex-a9,type=arm-cpu,reset-cbar=0xF8F00000,midr=0x413 FC090 -sysbusdev device=cpu,name=microblaze-cpRAM or ROM can be attached with this command:
-device memory,name=zynq.ext_ram,addr=0x00000000,size=0x8000000Multiple IRQ lines can be used as well as multiple properties:
-device pl330,addr=0xF8003000,irq=13,irq=14,irq=15,irq=16,irq=17,\
irq=40,irq=41,irq=42,irq=43,num_chnls=8,num_periph_req=4,num_events=16This implementation uses a three round multi-pass method. This will hopefully allow devices attached via the command line to be connected to other command line devices (I haven't managed to get that working yet though)
With Li Guang's blob loader implemented it is also possible to boot images while using "-M none".
V2:
Use -device to attach the devices (Thanks Markus Armbruster) Make the method much more generic
Allow CPUs and Memory to be attached via command line Allow properties to be passed in via the command lineThanks to Markus Armbruster and Peter Crosthwaite for feedback on the first version
Alistair Francis (4):
qemu-option.c: Addqemu_optfunctions that step over arguments
qdev-monitor: Implement three functions used to connect devicesvl.c: Enable adding devices to the system bus qemu-options.hx: Update the command line documentation for -deviceinclude/hw/boards.h | 2 + include/monitor/qdev.h | 3 + include/qemu/option.h | 2 + include/qemu/option_int.h | 1 + qdev-monitor.c | 237 ++++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 8 +- util/qemu-option.c | 30 ++++++ vl.c | 74 +++++++++++++- 8 files changed, 346 insertions(+), 11 deletions(-)
Review
Quoted 13 lines · Alistair Francis
This patch allows sysbus devices to be attached via command line arguments.
This can be used to build an entire machine from the command line or to just add devices that aren't in the
machine_initcode.A peripheral can be added with the following syntax:
-device cadence_uart,addr=0xE0000000,irq=27A CPU can be added with either of the following:
(quoted diff) +0
-2-device cpu,model=cortex-a9,type=arm-cpu,reset-cbar=0xF8F00000,midr=0x413 FC090 -sysbusdev device=cpu,name=microblaze-cp
I don't see how this can possibly be sufficient information to wire up the CPU properly. How would you specify where the generic timer outputs go on an A15?
How are you going to handle the private peripheral mappings? Is the user supposed to provide another argument for the a9mpcore_priv device?
Quoted 2 lines
RAM or ROM can be attached with this command:
-device memory,name=zynq.ext_ram,addr=0x00000000,size=0x8000000
How would you use this if you needed to manage multiple separate address spaces? I'm hoping we can get rid of address_space_memory at some point in favour of actually properly modelling when different CPUs or DMA masters have different views of the world, so I don't want us to tie ourselves into an incorrect model by command line back-compat problems.
Quoted 3 lines
Multiple IRQ lines can be used as well as multiple properties:
-device pl330,addr=0xF8003000,irq=13,irq=14,irq=15,irq=16,irq=17,\
irq=40,irq=41,irq=42,irq=43,num_chnls=8,num_periph_req=4,num_events=16
This doesn't seem to actually specify anywhere how those IRQ numbers are supposed to be interpreted. You need to somehow say "connect this IRQ output line up to device X's GPIO input line Y" (where X will usually but not necessarily be an interrupt controller).
Again addr= is assuming a single system wide address space.
I also think that "allow machine specification by the command line" is a terrible goal -- certainly we should allow users the flexibility to put machines together from individual devices, but we should do that with a reasonably usable configuration or scripting language (and then we can use that internally for our own board models). If you try to specify things using command line argument syntax as your primary approach then the result is going to end up with hard-coded shortcuts (like the address space and which-interrupt-controller problems I mention above) that you've ended up with to try to make the command line vaguely comprehensible. But the real comprehensibility problem is from trying to do it with a single line of text with highly constrained syntax conventions.
thanks
-- PMM
Quoted 43 lines · Peter Maydell
Review
Quoted 13 lines · Alistair Francis
This patch allows sysbus devices to be attached via command line arguments.
This can be used to build an entire machine from the command line or to just add devices that aren't in the
machine_initcode.A peripheral can be added with the following syntax:
-device cadence_uart,addr=0xE0000000,irq=27A CPU can be added with either of the following:
(quoted diff) +0
-2-device cpu,model=cortex-a9,type=arm-cpu,reset-cbar=0xF8F00000,midr=0x413 FC090 -sysbusdev device=cpu,name=microblaze-cpI don't see how this can possibly be sufficient information to wire up the CPU properly. How would you specify where the generic timer outputs go on an A15?
How are you going to handle the private peripheral mappings? Is the user supposed to provide another argument for thea9mpcore_privdevice?Quoted 2 lines
RAM or ROM can be attached with this command:
-device memory,name=zynq.ext_ram,addr=0x00000000,size=0x8000000How would you use this if you needed to manage multiple separate address spaces? I'm hoping we can get rid of
address_space_memoryat some point in favour of actually properly modelling when different CPUs or DMA masters have different views of the world, so I don't want us to tie ourselves into an incorrect model by command line back-compat problems.Quoted 3 lines
Multiple IRQ lines can be used as well as multiple properties:
-device pl330,addr=0xF8003000,irq=13,irq=14,irq=15,irq=16,irq=17,\
irq=40,irq=41,irq=42,irq=43,num_chnls=8,num_periph_req=4,num_events=16This doesn't seem to actually specify anywhere how those IRQ numbers are supposed to be interpreted. You need to somehow say "connect this IRQ output line up to device X's GPIO input line Y" (where X will usually but not necessarily be an interrupt controller).
Again addr= is assuming a single system wide address space.
Quoted 14 lines
I also think that "allow machine specification by the command line" is a terrible goal -- certainly we should allow users the flexibility to put machines together from individual devices, but we should do that with a reasonably usable configuration or scripting language (and then we can use that internally for our own board models). If you try to specify things using command line argument syntax as your primary approach then the result is going to end up with hard-coded shortcuts (like the address space and which-interrupt-controller problems I mention above) that you've ended up with to try to make the command line vaguely comprehensible. But the real comprehensibility problem is from trying to do it with a single line of text with highly constrained syntax conventions.
I agree. And both things should be orthogonal goals. I think it makes a lot of sense to work towards converting machine files into say python scripts.
But even then users will still want to define additional devices using -device on the command line on top of that base machine file. So we need a solution to link up devices with "facilities provided by the boad" as well - to a certain extent.
I'm not sure if it's worth it to worry about the case where a -device provides interfaces that you would need to hook up to from -device again. We already have working interfaces for that really.
Alex
Quoted 25 lines · Peter Maydell
Review
Quoted 13 lines · Alistair Francis
This patch allows sysbus devices to be attached via command line arguments.
This can be used to build an entire machine from the command line or to just add devices that aren't in the
machine_initcode.A peripheral can be added with the following syntax:
-device cadence_uart,addr=0xE0000000,irq=27A CPU can be added with either of the following:
(quoted diff) +0
-2-device cpu,model=cortex-a9,type=arm-cpu,reset-cbar=0xF8F00000,midr=0x413 FC090 -sysbusdev device=cpu,name=microblaze-cpI don't see how this can possibly be sufficient information to wire up the CPU properly. How would you specify where the generic timer outputs go on an A15?
How are you going to handle the private peripheral mappings? Is the user supposed to provide another argument for thea9mpcore_privdevice?Quoted 2 lines
RAM or ROM can be attached with this command:
-device memory,name=zynq.ext_ram,addr=0x00000000,size=0x8000000
Quoted 8 lines
How would you use this if you needed to manage multiple separate address spaces? I'm hoping we can get rid of
address_space_memoryat some point in favour of actually properly modelling when different CPUs or DMA masters have different views of the world, so I don't want us to tie ourselves into an incorrect model by command line back-compat problems.
And sys-busses should be referencable and instantiable objects in their own right. Can we create a sysbus with:
-device sysbus,name=blah
This should all work somehow with Edgars recent per-master-address series. Masters then also need to specify their attachments in a data driven way.
-device arm-cpu,master-bus=blah
Quoted 10 lines
Quoted 3 lines
Multiple IRQ lines can be used as well as multiple properties:
-device pl330,addr=0xF8003000,irq=13,irq=14,irq=15,irq=16,irq=17,\
irq=40,irq=41,irq=42,irq=43,num_chnls=8,num_periph_req=4,num_events=16This doesn't seem to actually specify anywhere how those IRQ numbers are supposed to be interpreted. You need to somehow say "connect this IRQ output line up to device X's GPIO input line Y" (where X will usually but not necessarily be an interrupt controller).
This is probably blocked by consolidation of GPIOs and IRQs. Unforuntately, Sysbus keeps it's own data structure and APIs for IRQs quite separate from TYPE_DEVICEs GPIO API. I also think purely numbered and unnamed GPIOs need to be phased-out as its a blocker on quite a few features.
So anyways heres my proposal around IRQs/GPIOs. I have a series on list that adds the capability to name GPIOs. We can use it to consolidate sysbus::IRQ and device::GPIO by naming all sysbus IRQ lists (lets just call them "irqs") and moving them into the regular device->gpio structure. Existing sysbus_foo_irq APIs just back onto this change so there is no tree-wide change needed. Then instead of command line IRQ support we add command line GPIO support and the one soln. just works for all forms of wires.
Quoted 15 lines
Again addr= is assuming a single system wide address space.
I also think that "allow machine specification by the command line" is a terrible goal -- certainly we should allow users the flexibility to put machines together from individual devices, but we should do that with a reasonably usable configuration or scripting language (and then we can use that internally for our own board models). If you try to specify things using command line argument syntax as your primary approach then the result is going to end up with hard-coded shortcuts (like the address space and which-interrupt-controller problems I mention above) that you've ended up with to try to make the command line vaguely comprehensible.
I feel its something of the opposite here. The ultimate goal of an entire machine on the command line brings to light all these issues around generalization that are ultimately applicable to machine extension. Whether not you actually use -M none { -device } is beside the point. If you assume you have nothing, and aim to be able to do anything you have less worries about future incapability.
But the real comprehensibility
Quoted 3 lines
problem is from trying to do it with a single line of text with highly constrained syntax conventions.
And this email thread has quite nicely listed out those constraints. I think we should get rid of them and continue evolving this idea until it works.
Regards,
Peter
Quoted 3 lines
thanks
-- PMM