QOM realize for IndustryPack
PATCH 2/6 ipack: QOM parent field cleanup for IPackBus
In reply to Andreas FärberClean up the only user of IPackBus::qbus field and rename it.
--- hw/char/ipack.c | 2 +- hw/char/ipack.h | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-)
hw/char/ipack.c +1 -1
@@ -28,7 +28,7 @@ void ipack_bus_new_inplace(IPackBus *bus, DeviceState *parent, const char *name, uint8_t n_slots, qemu_irq_handler handler) { - qbus_create_inplace(&bus->qbus, TYPE_IPACK_BUS, parent, name); +qbus_create_inplace (bus ,TYPE_IPACK_BUS ,parent ,name ); bus->n_slots = n_slots; bus->set_irq = handler; }
hw/char/ipack.h +3 -1
@@ -19,7 +19,9 @@ typedef struct IPackBus IPackBus;#define IPACK_BUS (obj) OBJECT_CHECK(IPackBus, (obj), TYPE_IPACK_BUS)struct IPackBus { -BusState qbus; +/*< private >*/ +BusState parent_obj; +/* All fields are private */ uint8_t n_slots;uint8_t free_slot;
Signature · 1 line
1.8.1.4
PATCH 1/6 ipack: Convert to QOM realize
In reply to Andreas Färber--- hw/char/ipack.c | 40 ++++++++++++++++------------------------ hw/char/ipack.h | 5 ++--- hw/char/ipoctal232.c | 18 +++++++++++++----- 3 files changed, 31 insertions(+), 32 deletions(-)
hw/char/ipack.c +16 -24
@@ -33,37 +33,28 @@ void ipack_bus_new_inplace(IPackBus *bus, DeviceState *parent, bus->set_irq = handler; } -static int ipack_device_dev_init (DeviceState *qdev) +static void ipack_device_realize (DeviceState *dev,Error **errp) { -IPackBus *bus =IPACK_BUS (qdev_get_parent_bus (qdev)); -IPackDevice *dev =IPACK_DEVICE (qdev); -IPackDeviceClass *k =IPACK_DEVICE_GET_CLASS (dev); +IPackDevice *idev =IPACK_DEVICE (dev); +IPackBus *bus =IPACK_BUS (qdev_get_parent_bus (dev)); -if (dev->slot <0 ) { - dev->slot = bus->free_slot; +if (idev->slot <0 ) { + idev->slot = bus->free_slot; } -if (dev->slot >= bus->n_slots) { -return -1 ; +if (idev->slot >= bus->n_slots) { +error_setg (errp,"Only %" PRIu8" slots available." , bus->n_slots); +return ; } - bus->free_slot = dev->slot +1 ; + bus->free_slot = idev->slot +1 ; - dev->irq =qemu_allocate_irqs (bus->set_irq, dev,2 ); - -return k->init (dev); + idev->irq =qemu_allocate_irqs (bus->set_irq, idev,2 ); } -static int ipack_device_dev_exit (DeviceState *qdev) +static void ipack_device_unrealize (DeviceState *dev,Error **errp) { -IPackDevice *dev =IPACK_DEVICE (qdev); -IPackDeviceClass *k =IPACK_DEVICE_GET_CLASS (dev); - -if (k->exit) { - k->exit (dev); - } +IPackDevice *idev =IPACK_DEVICE (dev); -qemu_free_irqs (dev->irq); - -return 0 ; +qemu_free_irqs (idev->irq); }static Property ipack_device_props[] = {
@@ -74,10 +65,11 @@ static Property ipack_device_props[] = {static void ipack_device_class_init (ObjectClass *klass,void *data) {DeviceClass *k =DEVICE_CLASS (klass); +set_bit (DEVICE_CATEGORY_INPUT , k->categories); k->bus_type =TYPE_IPACK_BUS ; - k->init = ipack_device_dev_init; - k->exit = ipack_device_dev_exit; + k->realize = ipack_device_realize; + k->unrealize = ipack_device_unrealize; k->props = ipack_device_props; }
hw/char/ipack.h +2 -3
@@ -38,10 +38,9 @@ typedef struct IPackDeviceClass IPackDeviceClass; OBJECT_GET_CLASS(IPackDeviceClass, (obj), TYPE_IPACK_DEVICE)struct IPackDeviceClass { +/*< private >*/ DeviceClass parent_class; - -int (*init)(IPackDevice *dev); -int (*exit)(IPackDevice *dev); +/*< public >*/ uint16_t (*io_read)(IPackDevice *dev,uint8_t addr);void (*io_write)(IPackDevice *dev,uint8_t addr,uint16_t val);
hw/char/ipoctal232.c +13 -5
@@ -118,6 +118,8 @@ struct IPOctalState {#define IPOCTAL (obj) \ OBJECT_CHECK(IPOctalState, (obj), TYPE_IPOCTAL) +#define IPOCTAL_GET_PARENT_CLASS (obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_IPOCTAL)static const VMStateDescription vmstate_scc2698_channel = { .name ="scc2698_channel" ,
@@ -534,11 +536,19 @@ static void hostdev_event(void *opaque, int event) } } -static int ipoctal_init (IPackDevice *ip) +static void ipoctal_realize (DeviceState *dev,Error **errp) { -IPOctalState *s =IPOCTAL (ip); +IPOctalState *s =IPOCTAL (dev); +DeviceClass *parent_dc =DEVICE_CLASS (IPOCTAL_GET_PARENT_CLASS (dev)); +Error *err =NULL ;unsigned i; + parent_dc->realize (dev, &err); +if (err !=NULL ) { +error_propagate (errp, err); +return ; + } +for (i =0 ; i <N_CHANNELS ; i++) {SCC2698Channel *ch = &s->ch[i]; ch->ipoctal = s;
@@ -552,8 +562,6 @@ static int ipoctal_init(IPackDevice *ip)DPRINTF ("Could not redirect channel %u, no chardev set\n" , i); } } - -return 0 ; }static Property ipoctal_properties[] = {
@@ -573,7 +581,6 @@ static void ipoctal_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass);IPackDeviceClass *ic =IPACK_DEVICE_CLASS (klass); - ic->init = ipoctal_init; ic->io_read = io_read; ic->io_write = io_write; ic->id_read = id_read;
@@ -585,6 +592,7 @@ static void ipoctal_class_init(ObjectClass *klass, void *data) ic->mem_read8 = mem_read8; ic->mem_write8 = mem_write8; + dc->realize = ipoctal_realize;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); dc->desc ="GE IP-Octal 232 8-channel RS-232 IndustryPack" ; dc->props = ipoctal_properties;
Signature · 1 line
1.8.1.4
cover QOM realize for IndustryPack
Hello,
This series converts IndustryPack devices to QOM realize/unrealize.
It goes on to clean up file placement, promoting IndustryPack to use its own subdirectory like PCI, ISA, virtio, etc.
Available from:
https://github.com/afaerber/qemu-cpu/commits/realize-ipack.v1git://github.com/afaerber/qemu-cpu.git realize-ipack.v1
Regards,
Andreas
Andreas Färber (6):
ipack: Convert to QOM realize
ipack: QOM parent field cleanup for IPackBus
ipack: QOM parent field cleanup for IPackDevice
ipack: Simplify VMSTATE_IPACK_DEVICE() macro
ipoctal232: QOM parent field cleanup
ipack: Move IndustryPack out of hw/char/
hw/Makefile.objs | 1 +
hw/char/Makefile.objs | 2 +-
hw/char/ipoctal232.c | 30 ++++++++++++++++--------
hw/ipack/Makefile.objs | 2 ++
hw/{char => ipack}/ipack.c | 44 ++++++++++++++---------------------
hw/{char => ipack}/tpci200.c | 2 +-
{hw/char => include/hw/ipack}/ipack.h | 24 +++++++++++++------
7 files changed, 60 insertions(+), 45 deletions(-)
create mode 100644 hw/ipack/Makefile.objs
rename hw/{char => ipack}/ipack.c (70%)
rename hw/{char => ipack}/tpci200.c (99%)
rename {hw/char => include/hw/ipack}/ipack.h (75%)Signature · 1 line
1.8.1.4
PATCH 3/6 ipack: QOM parent field cleanup for IPackDevice
Rename the IPackDevice::qdev field to avoid accidental use.
--- hw/char/ipack.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/char/ipack.h +4 -1
@@ -61,7 +61,10 @@ struct IPackDeviceClass { };struct IPackDevice { -DeviceState qdev; +/*< private >*/ +DeviceState parent_obj; +/*< public >*/ +int32_t slot;/* IRQ objects for the IndustryPack INT0# and INT1# */ qemu_irq *irq;
Signature · 1 line
1.8.1.4
PATCH 4/6 ipack: Simplify VMSTATE_IPACK_DEVICE() macro
In reply to Andreas FärberHardcode name and offset to avoid having to pass parent_obj to it.
--- hw/char/ipack.h | 10 ++++++++-- hw/char/ipoctal232.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-)
hw/char/ipack.h +8 -2
@@ -72,8 +72,14 @@ struct IPackDevice {extern const VMStateDescription vmstate_ipack_device; -#define VMSTATE_IPACK_DEVICE (_field, _state) \ - VMSTATE_STRUCT(_field, _state, 1, vmstate_ipack_device, IPackDevice) +#define VMSTATE_IPACK_DEVICE () { \ + .name = "parent_obj", \ + .size = sizeof(IPackDevice), \ + .version_id = 1, \ + .vmsd = &vmstate_ipack_device, \ + .flags = VMS_STRUCT, \ + .offset = 0, \ +}IPackDevice *ipack_device_find (IPackBus *bus,int32_t slot); void ipack_bus_new_inplace(IPackBus *bus, DeviceState *parent,
hw/char/ipoctal232.c +1 -1
@@ -156,7 +156,7 @@ static const VMStateDescription vmstate_ipoctal = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField []) { -VMSTATE_IPACK_DEVICE (dev, IPOctalState), +VMSTATE_IPACK_DEVICE (),VMSTATE_STRUCT_ARRAY (ch, IPOctalState,N_CHANNELS ,1 , vmstate_scc2698_channel, SCC2698Channel), VMSTATE_STRUCT_ARRAY(blk, IPOctalState, N_BLOCKS, 1,
Signature · 1 line
1.8.1.4
PATCH 6/6 ipack: Move IndustryPack out of hw/char/
In reply to Andreas FärberMove the header defining an IPackBus and IPackDevice base class into a new include/ directory and move their implementation and a PCI-IndustryPack bridge out of hw/char/ directory into a new hw/ipack/.
---
hw/Makefile.objs | 1 +
hw/char/Makefile.objs | 2 +-
hw/char/ipoctal232.c | 2 +-
hw/ipack/Makefile.objs | 2 ++
hw/{char => ipack}/ipack.c | 2 +-
hw/{char => ipack}/tpci200.c | 2 +-
{hw/char => include/hw/ipack}/ipack.h | 0
7 files changed, 7 insertions(+), 4 deletions(-)
create mode 100644 hw/ipack/Makefile.objs
rename hw/{char => ipack}/ipack.c (98%)
rename hw/{char => ipack}/tpci200.c (99%)
rename {hw/char => include/hw/ipack}/ipack.h (100%)hw/Makefile.objs +1 -0
@@ -12,6 +12,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += i2c/ devices-dirs-$(CONFIG_SOFTMMU) += ide/ devices-dirs-$(CONFIG_SOFTMMU) += input/ devices-dirs-$(CONFIG_SOFTMMU) += intc/ +devices-dirs-$(CONFIG_IPACK) += ipack/ devices-dirs-$(CONFIG_SOFTMMU) += isa/ devices-dirs-$(CONFIG_SOFTMMU) += misc/ devices-dirs-$(CONFIG_SOFTMMU) += net/
hw/char/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_IPACK) += tpci200.o ipoctal232.o ipack.o +common-obj-$(CONFIG_IPACK) += ipoctal232.o common-obj-$(CONFIG_ESCC) += escc.o common-obj-$(CONFIG_PARALLEL) += parallel.o common-obj-$(CONFIG_PL011) += pl011.o
hw/char/ipoctal232.c +1 -1
@@ -8,7 +8,7 @@* later version. */ -#include "ipack.h" +#include "hw/ipack/ipack.h" #include "qemu/bitops.h" #include "sysemu/char.h"
hw/ipack/Makefile.objs new file +2 -0
@@ -0,0 +1,2 @@ +common-obj-$(CONFIG_IPACK) += ipack.o +common-obj-$(CONFIG_IPACK) += tpci200.o
hw/ipack/ipack.c renamed from hw/char/ipack.c +1 -1
@@ -8,7 +8,7 @@* later version. */ -#include "ipack.h" +#include "hw/ipack/ipack.h" IPackDevice *ipack_device_find (IPackBus *bus,int32_t slot) {
hw/ipack/tpci200.c renamed from hw/char/tpci200.c +1 -1
@@ -8,7 +8,7 @@* later version. */ -#include "ipack.h" +#include "hw/ipack/ipack.h" #include "hw/pci/pci.h" #include "qemu/bitops.h" #include <stdio.h>
include/hw/ipack/ipack.h renamed from hw/char/ipack.h +0 -0
Signature · 1 line
1.8.1.4
PATCH 5/6 ipoctal232: QOM parent field cleanup
In reply to Andreas FärberClean up accesses to IPOctalState::dev field and rename it.
--- hw/char/ipoctal232.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
hw/char/ipoctal232.c +5 -3
@@ -108,7 +108,8 @@ struct SCC2698Block { };struct IPOctalState { -IPackDevice dev; +IPackDevice parent_obj; +SCC2698Channel ch[N_CHANNELS ];SCC2698Block blk[N_BLOCKS ];uint8_t irq_vector;
@@ -174,6 +175,7 @@ static const uint8_t id_prom_data[] = {static void update_irq (IPOctalState *dev,unsigned block) { +IPackDevice *idev =IPACK_DEVICE (dev);/* Blocks A and B interrupt on INT0#, C and D on INT1#. Thus, to get the status we have to check two blocks. */ SCC2698Block *blk0 = &dev->blk[block];
@@ -181,9 +183,9 @@ static void update_irq(IPOctalState *dev, unsigned block)unsigned intno = block /2 ;if ((blk0->isr & blk0->imr) || (blk1->isr & blk1->imr)) { -qemu_irq_raise (dev->dev.irq[intno]); +qemu_irq_raise (idev->irq[intno]); }else { -qemu_irq_lower (dev->dev.irq[intno]); +qemu_irq_lower (idev->irq[intno]); } }
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH qom-next for-next 1/6] ipack: Convert to QOM realize
In reply to Andreas Färberhw/char/ipoctal232.c struct IPOctalState { · line 122
Quoted 2 lines · Andreas Färber
hw/char/ipoctal232.c +2
-0+#define IPOCTAL_GET_PARENT_CLASS (obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_IPOCTAL)
Hey, I cannot make it compile with the latest master:
hw/char/ipoctal232.c: In function ‘ipoctal_realize’:hw/char/ipoctal232.c:544:5: error: implicit declaration of function ‘OBJECT_GET_PARENT_CLASS’ [-Werror=implicit-function-declaration] hw/char/ipoctal232.c:544:5: error: nested extern declaration of ‘OBJECT_GET_PARENT_CLASS’ [-Werror=nested-externs]
Berto
Re: [Qemu-devel] [PATCH qom-next for-next 1/6] ipack: Convert to QOM realize
Am 05.08.2013 17:16, schrieb Alberto Garcia:
Quoted 10 lines · Andreas Färber
hw/char/ipoctal232.c struct IPOctalState { · line 122
Quoted 3 lines
hw/char/ipoctal232.c +2
-0+#define IPOCTAL_GET_PARENT_CLASS (obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_IPOCTAL)Hey, I cannot make it compile with the latest master:
hw/char/ipoctal232.c: In function ‘ipoctal_realize’:hw/char/ipoctal232.c:544:5: error: implicit declaration of function ‘OBJECT_GET_PARENT_CLASS’ [-Werror=implicit-function-declaration]hw/char/ipoctal232.c:544:5: error: nested extern declaration of ‘OBJECT_GET_PARENT_CLASS’ [-Werror=nested-externs]
Sorry, forgot to mention that in the cover letter: The branch linked to has one patch before this series introducing that macro. It's on the list as part of the virtio conversion series:
http://patchwork.ozlabs.org/patch/263863/
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 5 lines · Andreas Färber
This series converts IndustryPack devices to QOM realize/unrealize.
It goes on to clean up file placement, promoting IndustryPack to use its own subdirectory like PCI, ISA, virtio, etc.
Quoted 7 lines
Andreas Färber (6):
ipack: Convert to QOM realize
ipack: QOM parent field cleanup for IPackBus
ipack: QOM parent field cleanup for IPackDevice
ipack: SimplifyVMSTATE_IPACK_DEVICE()macro
ipoctal232: QOM parent field cleanup
ipack: Move IndustryPack out of hw/char/
Berto
Am 06.08.2013 10:48, schrieb Alberto Garcia:
Quoted 11 lines · Andreas Färber
Quoted 10 lines
This series converts IndustryPack devices to QOM realize/unrealize.
It goes on to clean up file placement, promoting IndustryPack to use its own subdirectory like PCI, ISA, virtio, etc.
Andreas Färber (6):
ipack: Convert to QOM realize
ipack: QOM parent field cleanup for IPackBus
ipack: QOM parent field cleanup for IPackDevice
I've now applied these three to qom-next.
Quoted 1 line
Quoted 1 line
ipack: Simplify
VMSTATE_IPACK_DEVICE()macro
mst disliked the according change for a PCI VMState macro, so I've not applied this; but my RFC VMState series has not received a lot of review either since then, in particular not from Juan, and I've just uncovered an issue with armv7m_nvic requiring a v2. I'll extend v2 to drop this macro completely.
Quoted 1 line
Quoted 1 line
ipoctal232: QOM parent field cleanup
Rebased on lack of preceding patch as follows:
hw/char/ipoctal232.c +1 -1
@@ -155,7 +155,7 @@ static const VMStateDescription vmstate_ipoctal = { .minimum_version_id = 1, .minimum_version_id_old = 1, .fields = (VMStateField []) { -VMSTATE_IPACK_DEVICE (dev, IPOctalState), +VMSTATE_IPACK_DEVICE (parent_obj, IPOctalState),VMSTATE_STRUCT_ARRAY (ch, IPOctalState,N_CHANNELS ,1 , vmstate_scc2698_channel, SCC2698Channel), VMSTATE_STRUCT_ARRAY(blk, IPOctalState, N_BLOCKS, 1,
Quoted 1 line
Quoted 1 line
ipack: Move IndustryPack out of hw/char/
There were unresolved IRC discussions with Paolo where exactly to place which IndustryPack files, so that this series has been lying around. Patch 03/06 makes it obvious that the header should live somewhere in include/ for documenting the base QOM type though.
A minimally invasive alternative would be to move it from hw/char/ to include/hw/char/ - would that be acceptable for everyone as first step?
The other issue was that while the ipoctal232 device is right in hw/char/, tpci200.c and ipack.[hc] have nothing to do with char devices
- therefore this patch proposed hw/ipack/, matching drivers/ipack/ in Linux.
Quoted 1 line
Acked-by Alberto Garcia <[email protected]>
https://github.com/afaerber/qemu-cpu/commits/qom-next
Thanks,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Il 08/02/2014 20:58, Andreas Färber ha scritto:
Quoted 5 lines
Patch 03/06 makes it obvious that the header should live somewhere in
include/for documenting the base QOM type though.A minimally invasive alternative would be to move it from hw/char/ to
include/hw/char/- would that be acceptable for everyone as first step?
Ok.
Quoted 3 lines
The other issue was that while the ipoctal232 device is right in hw/char/,
tpci200.cand ipack.[hc] have nothing to do with char devices
- therefore this patch proposed hw/ipack/, matchingdrivers/ipack/in Linux.
It's okay, but I think I asked what other IPack modules exist and I had no answer.
Paolo
Quoted 5 lines · Andreas Färber
Quoted 1 line
Quoted 1 line
ipack: Move IndustryPack out of hw/char/
There were unresolved IRC discussions with Paolo where exactly to place which IndustryPack files, so that this series has been lying around.
As I had explained some time ago I was only interested in the combination of the TPCI200 and IPOctal boards, but I decided to emulate them as separate devices because it seemed like a better design to me. But I'm fine with whatever solution, even merging those source files if it makes sense.
Berto
Il 09/02/2014 00:31, Paolo Bonzini ha scritto:
Quoted 8 lines
Quoted 5 lines
The other issue was that while the ipoctal232 device is right in hw/char/,
tpci200.cand ipack.[hc] have nothing to do with char devices
- therefore this patch proposed hw/ipack/, matchingdrivers/ipack/in Linux.It's okay, but I think I asked what other IPack modules exist and I had no answer.
I found more IPack here: http://www.acromag.com/catalog/84/Embedded_I_O_Boards/Industry_Pack_I_O_Modules
so hw/ipack is fine.
Paolo
Quoted 6 lines · Paolo Bonzini
Quoted 2 lines
It's okay, but I think I asked what other IPack modules exist and I had no answer.
I found more IPack here: http://www.acromag.com/catalog/84/Embedded_I_O_Boards/Industry_Pack_I_O_Modules
so hw/ipack is fine.
Also:
http://defense.ge-ip.com/products/industrypack-modules/c36
including the IPOctal-232.
Berto
Am 09.02.2014 22:31, schrieb Paolo Bonzini:
Quoted 7 lines
Il 09/02/2014 00:31, Paolo Bonzini ha scritto:
Quoted 6 lines
Quoted 5 lines
The other issue was that while the ipoctal232 device is right in hw/char/,
tpci200.cand ipack.[hc] have nothing to do with char devices
- therefore this patch proposed hw/ipack/, matchingdrivers/ipack/in Linux.
Quoted 8 lines
Quoted 2 lines
It's okay, but I think I asked what other IPack modules exist and I had no answer.
I found more IPack here:
http://www.acromag.com/catalog/84/Embedded_I_O_Boards/Industry_Pack_I_O_Modulesso hw/ipack is fine.
Okay, so applying the original patch after all:
https://github.com/afaerber/qemu-cpu/commits/qom-next
Another old branch gone. :)
Cheers,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg