From: Markus Armbruster <armbru@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Rob Herring" <robh@kernel.org>,
"xiaoqiang zhao" <zxq_yx_007@163.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Alistair Francis" <alistair.francis@xilinx.com>,
qemu-arm <qemu-arm@nongnu.org>,
"Антон Павлов" <antonynpavlov@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [Qemu-arm] [Qemu-devel] [PATCH 1/6] hw/char: QOM'ify pl011 model
Date: Mon, 30 May 2016 13:35:09 +0200 [thread overview]
Message-ID: <87fuszeq36.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAFEAcA8oEjC0wUudEpKKmtbk86eB87KOh-__QB+GrcW6LFy5uA@mail.gmail.com> (Peter Maydell's message of "Wed, 25 May 2016 14:08:08 +0100")
Peter Maydell <peter.maydell@linaro.org> writes:
> On 25 May 2016 at 11:58, xiaoqiang zhao <zxq_yx_007@163.com> wrote:
>> * drop qemu_char_get_next_serial and use chardev prop
>> * add pl011_create wrapper function to create pl011 uart device
>> * change affected board code to use the new way
>>
>> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
>> ---
>> hw/arm/bcm2835_peripherals.c | 16 +++-----------
>> hw/arm/highbank.c | 3 ++-
>> hw/arm/integratorcp.c | 5 +++--
>> hw/arm/realview.c | 9 ++++----
>> hw/arm/stellaris.c | 6 +++--
>> hw/arm/versatilepb.c | 9 ++++----
>> hw/arm/vexpress.c | 9 ++++----
>> hw/arm/virt.c | 1 +
>> hw/char/pl011.c | 11 +++++-----
>> include/hw/char/pl011.h | 52 ++++++++++++++++++++++++++++++++++++++++++++
>> 10 files changed, 86 insertions(+), 35 deletions(-)
>> create mode 100644 include/hw/char/pl011.h
>>
>> diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
>> index 234d518..46c320f 100644
>> --- a/hw/arm/bcm2835_peripherals.c
>> +++ b/hw/arm/bcm2835_peripherals.c
>> @@ -14,6 +14,7 @@
>> #include "hw/misc/bcm2835_mbox_defs.h"
>> #include "hw/arm/raspi_platform.h"
>> #include "sysemu/char.h"
>> +#include "sysemu/sysemu.h"
>>
>> /* Peripheral base address on the VC (GPU) system bus */
>> #define BCM2835_VC_PERI_BASE 0x7e000000
>> @@ -106,7 +107,6 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
>> MemoryRegion *ram;
>> Error *err = NULL;
>> uint32_t ram_size, vcram_size;
>> - CharDriverState *chr;
>> int n;
>>
>> obj = object_property_get_link(OBJECT(dev), "ram", &err);
>> @@ -147,6 +147,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
>> sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic));
>>
>> /* UART0 */
>> + qdev_prop_set_chr(DEVICE(&s->uart0), "chardev", serial_hds[0]);
>> object_property_set_bool(OBJECT(s->uart0), true, "realized", &err);
>> if (err) {
>> error_propagate(errp, err);
>> @@ -158,17 +159,8 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
>> sysbus_connect_irq(s->uart0, 0,
>> qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
>> INTERRUPT_UART));
>> -
>> /* AUX / UART1 */
>> - /* TODO: don't call qemu_char_get_next_serial() here, instead set
>> - * chardev properties for each uart at the board level, once pl011
>> - * (uart0) has been updated to avoid qemu_char_get_next_serial()
>> - */
>
> This comment says this should be fixed by having board-level
> properties; you've removed it but this patch isn't adding
> the properties to this (SoC-level) device. I think the board
> level should be looking at serial_hds[], not this code.
Device models should not fish backends out of global state. Whether
they fish directly or via some helper like qemu_char_get_next_serial()
doesn't matter. The ones that still do need to set
cannot_instantiate_with_device_add_yet with a suitable comment.
>> @@ -310,8 +312,7 @@ static void pl011_class_init(ObjectClass *oc, void *data)
>>
>> dc->realize = pl011_realize;
>> dc->vmsd = &vmstate_pl011;
>> - /* Reason: realize() method uses qemu_char_get_next_serial() */
>> - dc->cannot_instantiate_with_device_add_yet = true;
>
> Why does instantiating with device_add work now? There's
> still no way to wire up interrupt lines or map mmio regions.
> (This has never made much sense to me -- Markus?)
Uh, which part does "this" refer to?
I systematically reviewed devices for my "Clean up and fix no_user"
series (commit f976b09..7ea5e78), and wrote down my findings in
"Reason:" comments next to cannot_instantiate_with_device_add_yet
assignments. Any such assignment must have such a comment.
Testing can catch cases where we missed *all* reasons. Example: my "Fix
device introspection regressions" series (commit b37686f..33fe968). It
can't catch cases where we missed *some* reasons.
Note that cannot_instantiate_with_device_add_yet can get set by
(possibly abstract) parent devices as well. If a parent device sets it,
its children should nevertheless set it *again* if they have additional
reasons. I believe this is such a case. I'm not 100% sure, because I
haven't been 100% sure about anything related to sysbus devices ever
since Alex's commit 33cd52b "sysbus: Make devices spawnable via -device"
dropped cannot_instantiate_with_device_add_yet from
sysbus_device_class_init(), quoted below. As you see, that assignment
covered "no way to wire up interrupt lines or map mmio regions."
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 19437e6..7bfe381 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -283,13 +283,6 @@ static void sysbus_device_class_init(ObjectClass *klass, vo
id *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = sysbus_device_init;
k->bus_type = TYPE_SYSTEM_BUS;
- /*
- * device_add plugs devices into suitable bus. For "real" buses,
- * that actually connects the device. For sysbus, the connections
- * need to be made separately, and device_add can't do that. The
- * device would be left unconnected, and could not possibly work.
- */
- k->cannot_instantiate_with_device_add_yet = true;
}
WARNING: multiple messages have this Message-ID (diff)
From: Markus Armbruster <armbru@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "xiaoqiang zhao" <zxq_yx_007@163.com>,
"Rob Herring" <robh@kernel.org>,
"Peter Crosthwaite" <crosthwaite.peter@gmail.com>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Alistair Francis" <alistair.francis@xilinx.com>,
qemu-arm <qemu-arm@nongnu.org>,
"Антон Павлов" <antonynpavlov@gmail.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/6] hw/char: QOM'ify pl011 model
Date: Mon, 30 May 2016 13:35:09 +0200 [thread overview]
Message-ID: <87fuszeq36.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <CAFEAcA8oEjC0wUudEpKKmtbk86eB87KOh-__QB+GrcW6LFy5uA@mail.gmail.com> (Peter Maydell's message of "Wed, 25 May 2016 14:08:08 +0100")
Peter Maydell <peter.maydell@linaro.org> writes:
> On 25 May 2016 at 11:58, xiaoqiang zhao <zxq_yx_007@163.com> wrote:
>> * drop qemu_char_get_next_serial and use chardev prop
>> * add pl011_create wrapper function to create pl011 uart device
>> * change affected board code to use the new way
>>
>> Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
>> ---
>> hw/arm/bcm2835_peripherals.c | 16 +++-----------
>> hw/arm/highbank.c | 3 ++-
>> hw/arm/integratorcp.c | 5 +++--
>> hw/arm/realview.c | 9 ++++----
>> hw/arm/stellaris.c | 6 +++--
>> hw/arm/versatilepb.c | 9 ++++----
>> hw/arm/vexpress.c | 9 ++++----
>> hw/arm/virt.c | 1 +
>> hw/char/pl011.c | 11 +++++-----
>> include/hw/char/pl011.h | 52 ++++++++++++++++++++++++++++++++++++++++++++
>> 10 files changed, 86 insertions(+), 35 deletions(-)
>> create mode 100644 include/hw/char/pl011.h
>>
>> diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
>> index 234d518..46c320f 100644
>> --- a/hw/arm/bcm2835_peripherals.c
>> +++ b/hw/arm/bcm2835_peripherals.c
>> @@ -14,6 +14,7 @@
>> #include "hw/misc/bcm2835_mbox_defs.h"
>> #include "hw/arm/raspi_platform.h"
>> #include "sysemu/char.h"
>> +#include "sysemu/sysemu.h"
>>
>> /* Peripheral base address on the VC (GPU) system bus */
>> #define BCM2835_VC_PERI_BASE 0x7e000000
>> @@ -106,7 +107,6 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
>> MemoryRegion *ram;
>> Error *err = NULL;
>> uint32_t ram_size, vcram_size;
>> - CharDriverState *chr;
>> int n;
>>
>> obj = object_property_get_link(OBJECT(dev), "ram", &err);
>> @@ -147,6 +147,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
>> sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic));
>>
>> /* UART0 */
>> + qdev_prop_set_chr(DEVICE(&s->uart0), "chardev", serial_hds[0]);
>> object_property_set_bool(OBJECT(s->uart0), true, "realized", &err);
>> if (err) {
>> error_propagate(errp, err);
>> @@ -158,17 +159,8 @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp)
>> sysbus_connect_irq(s->uart0, 0,
>> qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
>> INTERRUPT_UART));
>> -
>> /* AUX / UART1 */
>> - /* TODO: don't call qemu_char_get_next_serial() here, instead set
>> - * chardev properties for each uart at the board level, once pl011
>> - * (uart0) has been updated to avoid qemu_char_get_next_serial()
>> - */
>
> This comment says this should be fixed by having board-level
> properties; you've removed it but this patch isn't adding
> the properties to this (SoC-level) device. I think the board
> level should be looking at serial_hds[], not this code.
Device models should not fish backends out of global state. Whether
they fish directly or via some helper like qemu_char_get_next_serial()
doesn't matter. The ones that still do need to set
cannot_instantiate_with_device_add_yet with a suitable comment.
>> @@ -310,8 +312,7 @@ static void pl011_class_init(ObjectClass *oc, void *data)
>>
>> dc->realize = pl011_realize;
>> dc->vmsd = &vmstate_pl011;
>> - /* Reason: realize() method uses qemu_char_get_next_serial() */
>> - dc->cannot_instantiate_with_device_add_yet = true;
>
> Why does instantiating with device_add work now? There's
> still no way to wire up interrupt lines or map mmio regions.
> (This has never made much sense to me -- Markus?)
Uh, which part does "this" refer to?
I systematically reviewed devices for my "Clean up and fix no_user"
series (commit f976b09..7ea5e78), and wrote down my findings in
"Reason:" comments next to cannot_instantiate_with_device_add_yet
assignments. Any such assignment must have such a comment.
Testing can catch cases where we missed *all* reasons. Example: my "Fix
device introspection regressions" series (commit b37686f..33fe968). It
can't catch cases where we missed *some* reasons.
Note that cannot_instantiate_with_device_add_yet can get set by
(possibly abstract) parent devices as well. If a parent device sets it,
its children should nevertheless set it *again* if they have additional
reasons. I believe this is such a case. I'm not 100% sure, because I
haven't been 100% sure about anything related to sysbus devices ever
since Alex's commit 33cd52b "sysbus: Make devices spawnable via -device"
dropped cannot_instantiate_with_device_add_yet from
sysbus_device_class_init(), quoted below. As you see, that assignment
covered "no way to wire up interrupt lines or map mmio regions."
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 19437e6..7bfe381 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -283,13 +283,6 @@ static void sysbus_device_class_init(ObjectClass *klass, vo
id *data)
DeviceClass *k = DEVICE_CLASS(klass);
k->init = sysbus_device_init;
k->bus_type = TYPE_SYSTEM_BUS;
- /*
- * device_add plugs devices into suitable bus. For "real" buses,
- * that actually connects the device. For sysbus, the connections
- * need to be made separately, and device_add can't do that. The
- * device would be left unconnected, and could not possibly work.
- */
- k->cannot_instantiate_with_device_add_yet = true;
}
next prev parent reply other threads:[~2016-05-30 11:35 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-25 10:58 [Qemu-devel] [PATCH 0/6] Drop the qemu_char_get_next_serial function xiaoqiang zhao
2016-05-25 10:58 ` xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-devel] [PATCH 1/6] hw/char: QOM'ify pl011 model xiaoqiang zhao
2016-05-25 10:58 ` xiaoqiang zhao
2016-05-25 13:01 ` [Qemu-arm] " Paolo Bonzini
2016-05-25 13:01 ` [Qemu-devel] " Paolo Bonzini
2016-05-25 13:08 ` Peter Maydell
2016-05-25 13:08 ` Peter Maydell
2016-05-25 13:15 ` [Qemu-arm] " Paolo Bonzini
2016-05-25 13:15 ` [Qemu-devel] " Paolo Bonzini
2016-05-27 2:13 ` xiaoqiang zhao
2016-05-27 9:40 ` [Qemu-arm] " Paolo Bonzini
2016-05-27 9:40 ` Paolo Bonzini
2016-05-27 2:06 ` [Qemu-arm] " xiaoqiang zhao
2016-05-27 2:06 ` xiaoqiang zhao
2016-05-27 9:01 ` [Qemu-arm] " Peter Maydell
2016-05-27 9:01 ` Peter Maydell
2016-05-27 9:42 ` [Qemu-arm] " Paolo Bonzini
2016-05-27 9:42 ` Paolo Bonzini
2016-05-27 11:36 ` [Qemu-arm] " xiaoqiang zhao
2016-05-27 11:36 ` xiaoqiang zhao
2016-05-30 11:35 ` Markus Armbruster [this message]
2016-05-30 11:35 ` Markus Armbruster
2016-05-25 10:58 ` [Qemu-devel] [PATCH 2/6] hw/char: QOM'ify cadence_uart model xiaoqiang zhao
2016-05-25 10:58 ` xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-arm] [PATCH 3/6] hw/char: QOM'ify digic-uart model xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-devel] " xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-arm] [PATCH 4/6] hw/char: QOM'ify stm32f2xx_usart model xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-devel] " xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-devel] [PATCH 5/6] hw/char: QOM'ify xilinx_uartlite model xiaoqiang zhao
2016-05-25 10:58 ` xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-arm] [PATCH 6/6] char: get rid of qemu_char_get_next_serial xiaoqiang zhao
2016-05-25 10:58 ` [Qemu-devel] " xiaoqiang zhao
2016-05-25 13:03 ` [Qemu-arm] " Paolo Bonzini
2016-05-25 13:03 ` [Qemu-devel] " Paolo Bonzini
2016-05-25 13:03 ` [Qemu-arm] [PATCH 0/6] Drop the qemu_char_get_next_serial function Paolo Bonzini
2016-05-25 13:03 ` [Qemu-devel] " Paolo Bonzini
2016-06-03 18:24 ` Peter Maydell
2016-06-03 18:24 ` Peter Maydell
2016-06-04 7:13 ` xiaoqiang zhao
2016-06-04 7:13 ` xiaoqiang zhao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fuszeq36.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=alistair.francis@xilinx.com \
--cc=antonynpavlov@gmail.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=robh@kernel.org \
--cc=zxq_yx_007@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.