Skip to contentSkip to conversation

ppc/prep: add IBM RS/6000 43p machine

RFC In review Hervé Poussineau 3 participants 14 messages Apr 14, 2013 – Apr 27, 2013

lore
Share & tools
lore
#0 lore raw

v2 cover ppc/prep: add IBM RS/6000 43p machine

Hi,

This patchset (sent as RFC) adds an emulation of the IBM RS/6000 43p, also known as 7248.

Andreas did some preliminary patches for OpenBIOS to support PReP machines, available at
git://repo.or.cz/openbios/afaerber.git branch prep.
43p emulation has been tested with this firmware, and also with the official firmware, named P93H1904.IMG.

Command line may look like
qemu-system-ppc -M 43p -readconfig ibm_43p.cfg
-device ide-hd,drive=hd0 -drive if=none,id=hd0,cache=writeback,file="hda.qcow2"

Changes RFC v1 -> RFC v2:
- rebased on master
- works with OpenBIOS
- rework on m48t59 patches
- remove rs6000 debug port emulation (not strictly required)
- checkpatch.pl doesn't complain anymore

Known bugs/missing parts:
- incomplete MPC105 (PCI host bridge) emulation (memory controller)
- no video card (should be a S3)
- QEMU can't change endianness at runtime

OpenBIOS status:
- detects CPU and memory, then freezes with a "Dictionary space overflow"

Official firmware status:
- can boot from a IDE hard disk containing a PReP boot partition
- can't boot from IDE cdroms (overlapping commands not supported by QEMU IDE emulation)
- can't boot from floppies (READ commands are issued, but it seems completion is ignored)
- can't boot from network (detects the netcard, but doesn't use it)
- needs a hack to m48t59 device to work (patch 7/7)

Please comment.

Regards,

Hervé

Hervé Poussineau (7):
pci: add MPC105 PCI host bridge emulation
m48t59: move ISA ports registration to QOM constructor
m48t59: register a QOM type for each nvram type we support
m48t59: use DeviceState in public functions
prep: add IBM RS/6000 7248 (43p) machine emulation
prep: QOM'ify System I/O
m48t59: hack(?) to make it work on IBM 43p

 default-configs/ppc-softmmu.mak |    1 +
 docs/ibm_43p.cfg                |   42 ++++
 hw/pci-host/Makefile.objs       |    1 +
 hw/pci-host/mpc105.c            |  487 +++++++++++++++++++++++++++++++++++++++
 hw/ppc/Makefile.objs            |    1 +
 hw/ppc/prep.c                   |  223 +++++++++++++++++-
 hw/ppc/prep_systemio.c          |  290 +++++++++++++++++++++++
 hw/sparc/sun4m.c                |    7 +-
 hw/sparc64/sun4u.c              |    6 +-
 hw/timer/m48t59.c               |  257 +++++++++++++++------
 include/hw/pci/pci_ids.h        |    1 +
 include/hw/timer/m48t59.h       |   14 +-
 trace-events                    |   11 +
 13 files changed, 1248 insertions(+), 93 deletions(-)
 create mode 100644 docs/ibm_43p.cfg
 create mode 100644 hw/pci-host/mpc105.c
 create mode 100644 hw/ppc/prep_systemio.c
Signature · 1 line
1.7.10.4
#1 lore raw

RFC v2 1/7 pci: add MPC105 PCI host bridge emulation

Non-contiguous I/O is not implemented.

There is also somewhere a bug in the memory controller, which means that some real firmwares may not detect the correct amount of memory. This can be bypassed by adding '-m 1G' on the command line.

Add x-auto-conf property, to automatically configure the memory controller at startup. This will be required by OpenBIOS, which doesn't know how to do it.

---
 default-configs/ppc-softmmu.mak |    1 +
 hw/pci-host/Makefile.objs       |    1 +
 hw/pci-host/mpc105.c            |  487 +++++++++++++++++++++++++++++++++++++++
 include/hw/pci/pci_ids.h        |    1 +
 trace-events                    |    7 +
 5 files changed, 497 insertions(+)
 create mode 100644 hw/pci-host/mpc105.c
default-configs/ppc-softmmu.mak +1 -0
index 50034fc..750d482 100644
@@ -27,6 +27,7 @@ CONFIG_MAC_NVRAM=y
 CONFIG_MAC_DBDMA=y
 CONFIG_HEATHROW_PIC=y
 CONFIG_GRACKLE_PCI=y
+CONFIG_MPC105_PCI=y
 CONFIG_UNIN_PCI=y
 CONFIG_DEC_PCI=y
 CONFIG_PPCE500_PCI=y
hw/pci-host/Makefile.objs +1 -0
index 909e702..ec4427b 100644
@@ -3,6 +3,7 @@ common-obj-y += pam.o
 # PPC devices
 common-obj-$(CONFIG_PREP_PCI) += prep.o
 common-obj-$(CONFIG_GRACKLE_PCI) += grackle.o
+common-obj-$(CONFIG_MPC105_PCI) += mpc105.o
 # NewWorld PowerMac
 common-obj-$(CONFIG_UNIN_PCI) += uninorth.o
 common-obj-$(CONFIG_DEC_PCI) += dec.o
hw/pci-host/mpc105.c new file +487 -0

487 lines not on this page · raw message

include/hw/pci/pci_ids.h +1 -0
index d8dc2f1..933b987 100644
@@ -69,6 +69,7 @@
 #define PCI_VENDOR_ID_TI                 0x104c
 
 #define PCI_VENDOR_ID_MOTOROLA           0x1057
+#define PCI_DEVICE_ID_MOTOROLA_MPC105    0x0001
 #define PCI_DEVICE_ID_MOTOROLA_MPC106    0x0002
 #define PCI_DEVICE_ID_MOTOROLA_RAVEN     0x4801
 
trace-events +7 -0
index 412f7e4..8b0ad9c 100644
@@ -761,6 +761,13 @@ pc87312_info_ide(uint32_t base) "base 0x%x"
 pc87312_info_parallel(uint32_t base, uint32_t irq) "base 0x%x, irq %u"
 pc87312_info_serial(int n, uint32_t base, uint32_t irq) "id=%d, base 0x%x, irq %u"
 
+# hw/mpc105.c
+mpc105_unassigned_mem_read(uint64_t addr) "Unassigned mem read %" PRIx64
+mpc105_unassigned_mem_write(uint64_t addr, uint64_t val) "Unassigned mem write %" PRIx64 " = 0x%" PRIx64
+mpc105_simm_enable(int id, uint32_t start, uint32_t end) "SIMM #%d 0x%08x-0x%08x"
+mpc105_simm_disable(int id) "SIMM #%d disabled"
+mpc105_simm_size(int id, uint32_t size) "SIMM #%d is %u MB"
+
 # xen-all.c
 xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: %#lx, size %#lx"
 xen_client_set_memory(uint64_t start_addr, unsigned long size, bool log_dirty) "%#"PRIx64" size %#lx, log_dirty %i"
Signature · 1 line
1.7.10.4
#2 lore raw

RFC v2 2/7 m48t59: move ISA ports registration to QOM constructor

In reply to Hervé Poussineau

-device m48t59 can now be used to create a fully functional nvram, and m48t59_init_isa() becomes a much simpler helper.

---
 hw/timer/m48t59.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
hw/timer/m48t59.c +4 -5
index 5019e06..41022f2 100644
@@ -676,11 +676,6 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     d = DO_UPCAST(M48t59ISAState, busdev, dev);
     s = &d->state;
 
-    memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
-    if (io_base != 0) {
-        isa_register_ioport(dev, &d->io, io_base);
-    }
-
     return s;
 }
 
@@ -703,6 +698,10 @@ static int m48t59_init_isa1(ISADevice *dev)
 
     isa_init_irq(dev, &s->IRQ, 8);
     m48t59_init_common(s);
+    memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
+    if (s->io_base != 0) {
+        isa_register_ioport(dev, &d->io, s->io_base);
+    }
 
     return 0;
 }
Signature · 1 line
1.7.10.4
#3 lore raw

RFC v2 3/7 m48t59: register a QOM type for each nvram type we support

In reply to Hervé Poussineau

As m48t59 devices can only be created with m48t59_init() or m48t59_init_isa(), we know exactly which nvram types are required. Register only those three types.
Remove .model and .size properties as they can be infered from nvram name. Remove .io_base ISA address port as m48t59_init_isa() is always called with ioport 0x74.

---
 hw/timer/m48t59.c |  187 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 126 insertions(+), 61 deletions(-)
hw/timer/m48t59.c +126 -61
index 41022f2..29ec462 100644
@@ -43,6 +43,13 @@
  * PPC platform there is also a nvram lock function.
  */
 
+typedef struct M48txxInfo {
+    const char *isa_name;
+    const char *sysbus_name;
+    uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
+    uint32_t size;
+} M48txxInfo;
+
 /*
  * Chipset docs:
  * http://www.st.com/stonline/products/literature/ds/2410/m48t02.pdf
@@ -54,7 +61,6 @@ struct M48t59State {
     /* Hardware parameters */
     qemu_irq IRQ;
     MemoryRegion iomem;
-    uint32_t io_base;
     uint32_t size;
     /* RTC management */
     time_t   time_offset;
@@ -78,12 +84,39 @@ typedef struct M48t59ISAState {
     MemoryRegion io;
 } M48t59ISAState;
 
+typedef struct M48txxISADeviceClass {
+    ISADeviceClass parent_class;
+    M48txxInfo info;
+} M48txxISADeviceClass;
+
 typedef struct M48t59SysBusState {
     SysBusDevice busdev;
     M48t59State state;
     MemoryRegion io;
 } M48t59SysBusState;
 
+typedef struct M48txxSysBusDeviceClass {
+    SysBusDeviceClass parent_class;
+    M48txxInfo info;
+} M48txxSysBusDeviceClass;
+
+static M48txxInfo m48txx_info[] = {
+    {
+        .sysbus_name = "m48t02",
+        .model = 2,
+        .size = 0x800,
+    },{
+        .sysbus_name = "m48t08",
+        .model = 8,
+        .size = 0x2000,
+    },{
+        .isa_name = "m48t59_isa",
+        .model = 59,
+        .size = 0x2000,
+    }
+};
+
+
 /* Fake timer functions */
 
 /* Alarm management */
@@ -640,25 +673,34 @@ M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
     SysBusDevice *s;
     M48t59SysBusState *d;
     M48t59State *state;
+    int i;
 
-    dev = qdev_create(NULL, "m48t59");
-    qdev_prop_set_uint32(dev, "model", model);
-    qdev_prop_set_uint32(dev, "size", size);
-    qdev_prop_set_uint32(dev, "io_base", io_base);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    d = FROM_SYSBUS(M48t59SysBusState, s);
-    state = &d->state;
-    sysbus_connect_irq(s, 0, IRQ);
-    memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
-    if (io_base != 0) {
-        memory_region_add_subregion(get_system_io(), io_base, &d->io);
-    }
-    if (mem_base != 0) {
-        sysbus_mmio_map(s, 0, mem_base);
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].sysbus_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
+
+        dev = qdev_create(NULL, m48txx_info[i].sysbus_name);
+        qdev_init_nofail(dev);
+        s = SYS_BUS_DEVICE(dev);
+        d = FROM_SYSBUS(M48t59SysBusState, s);
+        state = &d->state;
+        sysbus_connect_irq(s, 0, IRQ);
+        memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
+        if (io_base != 0) {
+            memory_region_add_subregion(get_system_io(), io_base, &d->io);
+        }
+        if (mem_base != 0) {
+            sysbus_mmio_map(s, 0, mem_base);
+        }
+
+        return state;
     }
 
-    return state;
+    assert(false);
+    return NULL;
 }
 
 M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
@@ -667,16 +709,27 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     M48t59ISAState *d;
     ISADevice *dev;
     M48t59State *s;
+    int i;
+
+    assert(io_base == 0x74);
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].isa_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
 
-    dev = isa_create(bus, "m48t59_isa");
-    qdev_prop_set_uint32(&dev->qdev, "model", model);
-    qdev_prop_set_uint32(&dev->qdev, "size", size);
-    qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
-    qdev_init_nofail(&dev->qdev);
-    d = DO_UPCAST(M48t59ISAState, busdev, dev);
-    s = &d->state;
+        dev = isa_create(bus, m48txx_info[i].isa_name);
+        qdev_init_nofail(&dev->qdev);
+        d = DO_UPCAST(M48t59ISAState, busdev, dev);
+        s = &d->state;
 
-    return s;
+        return s;
+    }
+
+    assert(false);
+    return NULL;
 }
 
 static void m48t59_init_common(M48t59State *s)
@@ -693,24 +746,32 @@ static void m48t59_init_common(M48t59State *s)
 
 static int m48t59_init_isa1(ISADevice *dev)
 {
+    ISADeviceClass *ic = ISA_DEVICE_GET_CLASS(dev);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     isa_init_irq(dev, &s->IRQ, 8);
     m48t59_init_common(s);
     memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
-    if (s->io_base != 0) {
-        isa_register_ioport(dev, &d->io, s->io_base);
-    }
+    isa_register_ioport(dev, &d->io, 0x74);
 
     return 0;
 }
 
 static int m48t59_init1(SysBusDevice *dev)
 {
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_GET_CLASS(dev);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
     M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     sysbus_init_irq(dev, &s->IRQ);
 
     memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
@@ -720,58 +781,62 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
-static Property m48t59_isa_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59ISAState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59ISAState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
+    M48txxInfo *info = data;
+
     ic->init = m48t59_init_isa1;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
-    dc->props = m48t59_isa_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
-    .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(M48t59ISAState),
-    .class_init    = m48t59_init_class_isa1,
-};
-
-static Property m48t59_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59SysBusState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void m48t59_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
+    M48txxInfo *info = data;
 
     k->init = m48t59_init1;
     dc->reset = m48t59_reset_sysbus;
-    dc->props = m48t59_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_info = {
-    .name          = "m48t59",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(M48t59SysBusState),
-    .class_init    = m48t59_class_init,
-};
-
 static void m48t59_register_types(void)
 {
-    type_register_static(&m48t59_info);
-    type_register_static(&m48t59_isa_info);
+    TypeInfo m48txx_type_info = {
+        .parent = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(M48t59SysBusState),
+        .class_size = sizeof(M48txxSysBusDeviceClass),
+        .class_init = m48t59_class_init,
+    };
+    TypeInfo m48txx_isa_type_info = {
+        .parent = TYPE_ISA_DEVICE,
+        .instance_size = sizeof(M48t59ISAState),
+        .class_size = sizeof(M48txxISADeviceClass),
+        .class_init = m48t59_isa_class_init,
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (m48txx_info[i].sysbus_name) {
+            m48txx_type_info.name = m48txx_info[i].sysbus_name;
+            m48txx_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_type_info);
+        }
+
+        if (m48txx_info[i].isa_name) {
+            m48txx_isa_type_info.name = m48txx_info[i].isa_name;
+            m48txx_isa_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_isa_type_info);
+        }
+    }
 }
 
 type_init(m48t59_register_types)
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [Qemu-devel] [RFC v2 3/7] m48t59: register a QOM type for each nvram type we support

Quoted 5 lines · Hervé Poussineau

As m48t59 devices can only be created with m48t59_init() or m48t59_init_isa(), we know exactly which nvram types are required. Register only those three types.
Remove .model and .size properties as they can be infered from nvram name. Remove .io_base ISA address port as m48t59_init_isa() is always called with ioport 0x74.

While this it indeed how it's currently called, this is wrong for the sun4u emulation.
The isa (ebus) variant of the sun4u m48t59_init_isa() should be called with a mem_base, not io_base.
Do you think it should be implemented as another device type?

Quoted 291 lines
---
 hw/timer/m48t59.c |  187 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 126 insertions(+), 61 deletions(-)
hw/timer/m48t59.c +126 -62
index 41022f2..29ec462 100644
@@ -43,6 +43,13 @@
  * PPC platform there is also a nvram lock function.
  */
 
+typedef struct M48txxInfo {
+    const char *isa_name;
+    const char *sysbus_name;
+    uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
+    uint32_t size;
+} M48txxInfo;
+
 /*
  * Chipset docs:
  * http://www.st.com/stonline/products/literature/ds/2410/m48t02.pdf
@@ -54,7 +61,6 @@ struct M48t59State {
     /* Hardware parameters */
     qemu_irq IRQ;
     MemoryRegion iomem;
-    uint32_t io_base;
     uint32_t size;
     /* RTC management */
     time_t   time_offset;
@@ -78,12 +84,39 @@ typedef struct M48t59ISAState {
     MemoryRegion io;
 } M48t59ISAState;
 
+typedef struct M48txxISADeviceClass {
+    ISADeviceClass parent_class;
+    M48txxInfo info;
+} M48txxISADeviceClass;
+
 typedef struct M48t59SysBusState {
     SysBusDevice busdev;
     M48t59State state;
     MemoryRegion io;
 } M48t59SysBusState;
 
+typedef struct M48txxSysBusDeviceClass {
+    SysBusDeviceClass parent_class;
+    M48txxInfo info;
+} M48txxSysBusDeviceClass;
+
+static M48txxInfo m48txx_info[] = {
+    {
+        .sysbus_name = "m48t02",
+        .model = 2,
+        .size = 0x800,
+    },{
+        .sysbus_name = "m48t08",
+        .model = 8,
+        .size = 0x2000,
+    },{
+        .isa_name = "m48t59_isa",
+        .model = 59,
+        .size = 0x2000,
+    }
+};
+
+
 /* Fake timer functions */
 
 /* Alarm management */
@@ -640,25 +673,34 @@ M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
     SysBusDevice *s;
     M48t59SysBusState *d;
     M48t59State *state;
+    int i;
 
-    dev = qdev_create(NULL, "m48t59");
-    qdev_prop_set_uint32(dev, "model", model);
-    qdev_prop_set_uint32(dev, "size", size);
-    qdev_prop_set_uint32(dev, "io_base", io_base);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    d = FROM_SYSBUS(M48t59SysBusState, s);
-    state = &d->state;
-    sysbus_connect_irq(s, 0, IRQ);
-    memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
-    if (io_base != 0) {
-        memory_region_add_subregion(get_system_io(), io_base, &d->io);
-    }
-    if (mem_base != 0) {
-        sysbus_mmio_map(s, 0, mem_base);
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].sysbus_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
+
+        dev = qdev_create(NULL, m48txx_info[i].sysbus_name);
+        qdev_init_nofail(dev);
+        s = SYS_BUS_DEVICE(dev);
+        d = FROM_SYSBUS(M48t59SysBusState, s);
+        state = &d->state;
+        sysbus_connect_irq(s, 0, IRQ);
+        memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
+        if (io_base != 0) {
+            memory_region_add_subregion(get_system_io(), io_base, &d->io);
+        }
+        if (mem_base != 0) {
+            sysbus_mmio_map(s, 0, mem_base);
+        }
+
+        return state;
     }
 
-    return state;
+    assert(false);
+    return NULL;
 }
 
 M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
@@ -667,16 +709,27 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     M48t59ISAState *d;
     ISADevice *dev;
     M48t59State *s;
+    int i;
+
+    assert(io_base == 0x74);
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].isa_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
 
-    dev = isa_create(bus, "m48t59_isa");
-    qdev_prop_set_uint32(&dev->qdev, "model", model);
-    qdev_prop_set_uint32(&dev->qdev, "size", size);
-    qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
-    qdev_init_nofail(&dev->qdev);
-    d = DO_UPCAST(M48t59ISAState, busdev, dev);
-    s = &d->state;
+        dev = isa_create(bus, m48txx_info[i].isa_name);
+        qdev_init_nofail(&dev->qdev);
+        d = DO_UPCAST(M48t59ISAState, busdev, dev);
+        s = &d->state;
 
-    return s;
+        return s;
+    }
+
+    assert(false);
+    return NULL;
 }
 
 static void m48t59_init_common(M48t59State *s)
@@ -693,24 +746,32 @@ static void m48t59_init_common(M48t59State *s)
 
 static int m48t59_init_isa1(ISADevice *dev)
 {
+    ISADeviceClass *ic = ISA_DEVICE_GET_CLASS(dev);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     isa_init_irq(dev, &s->IRQ, 8);
     m48t59_init_common(s);
     memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
-    if (s->io_base != 0) {
-        isa_register_ioport(dev, &d->io, s->io_base);
-    }
+    isa_register_ioport(dev, &d->io, 0x74);
 
     return 0;
 }
 
 static int m48t59_init1(SysBusDevice *dev)
 {
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_GET_CLASS(dev);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
     M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     sysbus_init_irq(dev, &s->IRQ);
 
     memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
@@ -720,58 +781,62 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
-static Property m48t59_isa_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59ISAState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59ISAState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
+    M48txxInfo *info = data;
+
     ic->init = m48t59_init_isa1;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
-    dc->props = m48t59_isa_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
-    .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(M48t59ISAState),
-    .class_init    = m48t59_init_class_isa1,
-};
-
-static Property m48t59_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59SysBusState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void m48t59_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
+    M48txxInfo *info = data;
 
     k->init = m48t59_init1;
     dc->reset = m48t59_reset_sysbus;
-    dc->props = m48t59_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_info = {
-    .name          = "m48t59",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(M48t59SysBusState),
-    .class_init    = m48t59_class_init,
-};
-
 static void m48t59_register_types(void)
 {
-    type_register_static(&m48t59_info);
-    type_register_static(&m48t59_isa_info);
+    TypeInfo m48txx_type_info = {
+        .parent = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(M48t59SysBusState),
+        .class_size = sizeof(M48txxSysBusDeviceClass),
+        .class_init = m48t59_class_init,
+    };
+    TypeInfo m48txx_isa_type_info = {
+        .parent = TYPE_ISA_DEVICE,
+        .instance_size = sizeof(M48t59ISAState),
+        .class_size = sizeof(M48txxISADeviceClass),
+        .class_init = m48t59_isa_class_init,
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (m48txx_info[i].sysbus_name) {
+            m48txx_type_info.name = m48txx_info[i].sysbus_name;
+            m48txx_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_type_info);
+        }
+
+        if (m48txx_info[i].isa_name) {
+            m48txx_isa_type_info.name = m48txx_info[i].isa_name;
+            m48txx_isa_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_isa_type_info);
+        }
+    }
 }
 
 type_init(m48t59_register_types)
--
Quoted 3 lines

1.7.10.4

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

#5 lore raw

Re: [Qemu-devel] [RFC v2 3/7] m48t59: register a QOM type for each nvram type we support

Quoted 7 lines · Artyom Tarasenko
Quoted 5 lines · Hervé Poussineau

As m48t59 devices can only be created with m48t59_init() or m48t59_init_isa(), we know exactly which nvram types are required. Register only those three types.
Remove .model and .size properties as they can be infered from nvram name. Remove .io_base ISA address port as m48t59_init_isa() is always called with ioport 0x74.

Quoted 6 lines

While this it indeed how it's currently called, this is wrong for the sun4u emulation.
The isa (ebus) variant of the sun4u m48t59_init_isa() should be called with a mem_base, not io_base.
Do you think it should be implemented as another device type?

I don't know EBUS, but I think it should be implemented either as a completly new bus (1), or as a child of the ISA bus type (2). For 1), you'll need to add a another device type to be plugged on EBUS.
For 2), I let experts answer :)

In all cases, maybe the m48t59_init() wrapper is what you need? You can already give him a membase.
Otherwise, you can maybe use sysbus_create_simple("m48t59"), get the resulting MemoryRegion from the device, and add it in whatever MemoryRegion.

Hervé

#6 lore raw

Re: [Qemu-devel] [RFC v2 3/7] m48t59: register a QOM type for each nvram type we support

In reply to Artyom Tarasenko
Quoted 11 lines · Artyom Tarasenko
Quoted 5 lines · Hervé Poussineau

As m48t59 devices can only be created with m48t59_init() or m48t59_init_isa(), we know exactly which nvram types are required. Register only those three types.
Remove .model and .size properties as they can be infered from nvram name. Remove .io_base ISA address port as m48t59_init_isa() is always called with ioport 0x74.

While this it indeed how it's currently called, this is wrong for the sun4u emulation.
The isa (ebus) variant of the sun4u m48t59_init_isa() should be called with a mem_base, not io_base.

Why? I don't see much difference between EBUS and ISA and with the memory API, the difference between PIO and MMIO is almost nonexistent anyway.

But it should be possible to change the base to match real HW, whatever it is:
http://git.kernel.org/cgit/linux/kernel/git/davem/prtconfs.git/tree/ultra5#n273

So NACK for the original patch.

Quoted 306 lines

Do you think it should be implemented as another device type?

Quoted 291 lines
---
 hw/timer/m48t59.c |  187 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 126 insertions(+), 61 deletions(-)
hw/timer/m48t59.c +126 -62
index 41022f2..29ec462 100644
@@ -43,6 +43,13 @@
  * PPC platform there is also a nvram lock function.
  */
 
+typedef struct M48txxInfo {
+    const char *isa_name;
+    const char *sysbus_name;
+    uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
+    uint32_t size;
+} M48txxInfo;
+
 /*
  * Chipset docs:
  * http://www.st.com/stonline/products/literature/ds/2410/m48t02.pdf
@@ -54,7 +61,6 @@ struct M48t59State {
     /* Hardware parameters */
     qemu_irq IRQ;
     MemoryRegion iomem;
-    uint32_t io_base;
     uint32_t size;
     /* RTC management */
     time_t   time_offset;
@@ -78,12 +84,39 @@ typedef struct M48t59ISAState {
     MemoryRegion io;
 } M48t59ISAState;
 
+typedef struct M48txxISADeviceClass {
+    ISADeviceClass parent_class;
+    M48txxInfo info;
+} M48txxISADeviceClass;
+
 typedef struct M48t59SysBusState {
     SysBusDevice busdev;
     M48t59State state;
     MemoryRegion io;
 } M48t59SysBusState;
 
+typedef struct M48txxSysBusDeviceClass {
+    SysBusDeviceClass parent_class;
+    M48txxInfo info;
+} M48txxSysBusDeviceClass;
+
+static M48txxInfo m48txx_info[] = {
+    {
+        .sysbus_name = "m48t02",
+        .model = 2,
+        .size = 0x800,
+    },{
+        .sysbus_name = "m48t08",
+        .model = 8,
+        .size = 0x2000,
+    },{
+        .isa_name = "m48t59_isa",
+        .model = 59,
+        .size = 0x2000,
+    }
+};
+
+
 /* Fake timer functions */
 
 /* Alarm management */
@@ -640,25 +673,34 @@ M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
     SysBusDevice *s;
     M48t59SysBusState *d;
     M48t59State *state;
+    int i;
 
-    dev = qdev_create(NULL, "m48t59");
-    qdev_prop_set_uint32(dev, "model", model);
-    qdev_prop_set_uint32(dev, "size", size);
-    qdev_prop_set_uint32(dev, "io_base", io_base);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    d = FROM_SYSBUS(M48t59SysBusState, s);
-    state = &d->state;
-    sysbus_connect_irq(s, 0, IRQ);
-    memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
-    if (io_base != 0) {
-        memory_region_add_subregion(get_system_io(), io_base, &d->io);
-    }
-    if (mem_base != 0) {
-        sysbus_mmio_map(s, 0, mem_base);
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].sysbus_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
+
+        dev = qdev_create(NULL, m48txx_info[i].sysbus_name);
+        qdev_init_nofail(dev);
+        s = SYS_BUS_DEVICE(dev);
+        d = FROM_SYSBUS(M48t59SysBusState, s);
+        state = &d->state;
+        sysbus_connect_irq(s, 0, IRQ);
+        memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
+        if (io_base != 0) {
+            memory_region_add_subregion(get_system_io(), io_base, &d->io);
+        }
+        if (mem_base != 0) {
+            sysbus_mmio_map(s, 0, mem_base);
+        }
+
+        return state;
     }
 
-    return state;
+    assert(false);
+    return NULL;
 }
 
 M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
@@ -667,16 +709,27 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     M48t59ISAState *d;
     ISADevice *dev;
     M48t59State *s;
+    int i;
+
+    assert(io_base == 0x74);
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].isa_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
 
-    dev = isa_create(bus, "m48t59_isa");
-    qdev_prop_set_uint32(&dev->qdev, "model", model);
-    qdev_prop_set_uint32(&dev->qdev, "size", size);
-    qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
-    qdev_init_nofail(&dev->qdev);
-    d = DO_UPCAST(M48t59ISAState, busdev, dev);
-    s = &d->state;
+        dev = isa_create(bus, m48txx_info[i].isa_name);
+        qdev_init_nofail(&dev->qdev);
+        d = DO_UPCAST(M48t59ISAState, busdev, dev);
+        s = &d->state;
 
-    return s;
+        return s;
+    }
+
+    assert(false);
+    return NULL;
 }
 
 static void m48t59_init_common(M48t59State *s)
@@ -693,24 +746,32 @@ static void m48t59_init_common(M48t59State *s)
 
 static int m48t59_init_isa1(ISADevice *dev)
 {
+    ISADeviceClass *ic = ISA_DEVICE_GET_CLASS(dev);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     isa_init_irq(dev, &s->IRQ, 8);
     m48t59_init_common(s);
     memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
-    if (s->io_base != 0) {
-        isa_register_ioport(dev, &d->io, s->io_base);
-    }
+    isa_register_ioport(dev, &d->io, 0x74);
 
     return 0;
 }
 
 static int m48t59_init1(SysBusDevice *dev)
 {
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_GET_CLASS(dev);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
     M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     sysbus_init_irq(dev, &s->IRQ);
 
     memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
@@ -720,58 +781,62 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
-static Property m48t59_isa_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59ISAState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59ISAState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
+    M48txxInfo *info = data;
+
     ic->init = m48t59_init_isa1;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
-    dc->props = m48t59_isa_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
-    .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(M48t59ISAState),
-    .class_init    = m48t59_init_class_isa1,
-};
-
-static Property m48t59_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59SysBusState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void m48t59_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
+    M48txxInfo *info = data;
 
     k->init = m48t59_init1;
     dc->reset = m48t59_reset_sysbus;
-    dc->props = m48t59_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_info = {
-    .name          = "m48t59",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(M48t59SysBusState),
-    .class_init    = m48t59_class_init,
-};
-
 static void m48t59_register_types(void)
 {
-    type_register_static(&m48t59_info);
-    type_register_static(&m48t59_isa_info);
+    TypeInfo m48txx_type_info = {
+        .parent = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(M48t59SysBusState),
+        .class_size = sizeof(M48txxSysBusDeviceClass),
+        .class_init = m48t59_class_init,
+    };
+    TypeInfo m48txx_isa_type_info = {
+        .parent = TYPE_ISA_DEVICE,
+        .instance_size = sizeof(M48t59ISAState),
+        .class_size = sizeof(M48txxISADeviceClass),
+        .class_init = m48t59_isa_class_init,
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (m48txx_info[i].sysbus_name) {
+            m48txx_type_info.name = m48txx_info[i].sysbus_name;
+            m48txx_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_type_info);
+        }
+
+        if (m48txx_info[i].isa_name) {
+            m48txx_isa_type_info.name = m48txx_info[i].isa_name;
+            m48txx_isa_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_isa_type_info);
+        }
+    }
 }
 
 type_init(m48t59_register_types)
--
Quoted 3 lines

1.7.10.4

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

#7 lore raw

Re: [Qemu-devel] [RFC v2 3/7] m48t59: register a QOM type for each nvram type we support

Quoted 8 lines · Blue Swirl
Quoted 7 lines · Artyom Tarasenko
Quoted 5 lines · Hervé Poussineau

As m48t59 devices can only be created with m48t59_init() or m48t59_init_isa(), we know exactly which nvram types are required. Register only those three types.
Remove .model and .size properties as they can be infered from nvram name. Remove .io_base ISA address port as m48t59_init_isa() is always called with ioport 0x74.

Quoted 8 lines
Quoted 4 lines

While this it indeed how it's currently called, this is wrong for the sun4u emulation.
The isa (ebus) variant of the sun4u m48t59_init_isa() should be called with a mem_base, not io_base.

Why? I don't see much difference between EBUS and ISA and with the memory API, the difference between PIO and MMIO is almost nonexistent anyway.

Can you elaborate? Do you mean we just need to change the io_base?

Quoted 2 lines

But it should be possible to change the base to match real HW, whatever it is:
http://git.kernel.org/cgit/linux/kernel/git/davem/prtconfs.git/tree/ultra5#n273

Yes, I know where it is supposed to be, I'm just asking how to achieve this best with our current tooling.

Quoted 308 lines

So NACK for the original patch.

Quoted 306 lines

Do you think it should be implemented as another device type?

Quoted 291 lines
---
 hw/timer/m48t59.c |  187 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 126 insertions(+), 61 deletions(-)
hw/timer/m48t59.c +126 -62
index 41022f2..29ec462 100644
@@ -43,6 +43,13 @@
  * PPC platform there is also a nvram lock function.
  */
 
+typedef struct M48txxInfo {
+    const char *isa_name;
+    const char *sysbus_name;
+    uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
+    uint32_t size;
+} M48txxInfo;
+
 /*
  * Chipset docs:
  * http://www.st.com/stonline/products/literature/ds/2410/m48t02.pdf
@@ -54,7 +61,6 @@ struct M48t59State {
     /* Hardware parameters */
     qemu_irq IRQ;
     MemoryRegion iomem;
-    uint32_t io_base;
     uint32_t size;
     /* RTC management */
     time_t   time_offset;
@@ -78,12 +84,39 @@ typedef struct M48t59ISAState {
     MemoryRegion io;
 } M48t59ISAState;
 
+typedef struct M48txxISADeviceClass {
+    ISADeviceClass parent_class;
+    M48txxInfo info;
+} M48txxISADeviceClass;
+
 typedef struct M48t59SysBusState {
     SysBusDevice busdev;
     M48t59State state;
     MemoryRegion io;
 } M48t59SysBusState;
 
+typedef struct M48txxSysBusDeviceClass {
+    SysBusDeviceClass parent_class;
+    M48txxInfo info;
+} M48txxSysBusDeviceClass;
+
+static M48txxInfo m48txx_info[] = {
+    {
+        .sysbus_name = "m48t02",
+        .model = 2,
+        .size = 0x800,
+    },{
+        .sysbus_name = "m48t08",
+        .model = 8,
+        .size = 0x2000,
+    },{
+        .isa_name = "m48t59_isa",
+        .model = 59,
+        .size = 0x2000,
+    }
+};
+
+
 /* Fake timer functions */
 
 /* Alarm management */
@@ -640,25 +673,34 @@ M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
     SysBusDevice *s;
     M48t59SysBusState *d;
     M48t59State *state;
+    int i;
 
-    dev = qdev_create(NULL, "m48t59");
-    qdev_prop_set_uint32(dev, "model", model);
-    qdev_prop_set_uint32(dev, "size", size);
-    qdev_prop_set_uint32(dev, "io_base", io_base);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    d = FROM_SYSBUS(M48t59SysBusState, s);
-    state = &d->state;
-    sysbus_connect_irq(s, 0, IRQ);
-    memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
-    if (io_base != 0) {
-        memory_region_add_subregion(get_system_io(), io_base, &d->io);
-    }
-    if (mem_base != 0) {
-        sysbus_mmio_map(s, 0, mem_base);
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].sysbus_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
+
+        dev = qdev_create(NULL, m48txx_info[i].sysbus_name);
+        qdev_init_nofail(dev);
+        s = SYS_BUS_DEVICE(dev);
+        d = FROM_SYSBUS(M48t59SysBusState, s);
+        state = &d->state;
+        sysbus_connect_irq(s, 0, IRQ);
+        memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
+        if (io_base != 0) {
+            memory_region_add_subregion(get_system_io(), io_base, &d->io);
+        }
+        if (mem_base != 0) {
+            sysbus_mmio_map(s, 0, mem_base);
+        }
+
+        return state;
     }
 
-    return state;
+    assert(false);
+    return NULL;
 }
 
 M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
@@ -667,16 +709,27 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     M48t59ISAState *d;
     ISADevice *dev;
     M48t59State *s;
+    int i;
+
+    assert(io_base == 0x74);
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].isa_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
 
-    dev = isa_create(bus, "m48t59_isa");
-    qdev_prop_set_uint32(&dev->qdev, "model", model);
-    qdev_prop_set_uint32(&dev->qdev, "size", size);
-    qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
-    qdev_init_nofail(&dev->qdev);
-    d = DO_UPCAST(M48t59ISAState, busdev, dev);
-    s = &d->state;
+        dev = isa_create(bus, m48txx_info[i].isa_name);
+        qdev_init_nofail(&dev->qdev);
+        d = DO_UPCAST(M48t59ISAState, busdev, dev);
+        s = &d->state;
 
-    return s;
+        return s;
+    }
+
+    assert(false);
+    return NULL;
 }
 
 static void m48t59_init_common(M48t59State *s)
@@ -693,24 +746,32 @@ static void m48t59_init_common(M48t59State *s)
 
 static int m48t59_init_isa1(ISADevice *dev)
 {
+    ISADeviceClass *ic = ISA_DEVICE_GET_CLASS(dev);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     isa_init_irq(dev, &s->IRQ, 8);
     m48t59_init_common(s);
     memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
-    if (s->io_base != 0) {
-        isa_register_ioport(dev, &d->io, s->io_base);
-    }
+    isa_register_ioport(dev, &d->io, 0x74);
 
     return 0;
 }
 
 static int m48t59_init1(SysBusDevice *dev)
 {
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_GET_CLASS(dev);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
     M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     sysbus_init_irq(dev, &s->IRQ);
 
     memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
@@ -720,58 +781,62 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
-static Property m48t59_isa_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59ISAState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59ISAState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
+    M48txxInfo *info = data;
+
     ic->init = m48t59_init_isa1;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
-    dc->props = m48t59_isa_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
-    .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(M48t59ISAState),
-    .class_init    = m48t59_init_class_isa1,
-};
-
-static Property m48t59_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59SysBusState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void m48t59_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
+    M48txxInfo *info = data;
 
     k->init = m48t59_init1;
     dc->reset = m48t59_reset_sysbus;
-    dc->props = m48t59_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_info = {
-    .name          = "m48t59",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(M48t59SysBusState),
-    .class_init    = m48t59_class_init,
-};
-
 static void m48t59_register_types(void)
 {
-    type_register_static(&m48t59_info);
-    type_register_static(&m48t59_isa_info);
+    TypeInfo m48txx_type_info = {
+        .parent = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(M48t59SysBusState),
+        .class_size = sizeof(M48txxSysBusDeviceClass),
+        .class_init = m48t59_class_init,
+    };
+    TypeInfo m48txx_isa_type_info = {
+        .parent = TYPE_ISA_DEVICE,
+        .instance_size = sizeof(M48t59ISAState),
+        .class_size = sizeof(M48txxISADeviceClass),
+        .class_init = m48t59_isa_class_init,
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (m48txx_info[i].sysbus_name) {
+            m48txx_type_info.name = m48txx_info[i].sysbus_name;
+            m48txx_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_type_info);
+        }
+
+        if (m48txx_info[i].isa_name) {
+            m48txx_isa_type_info.name = m48txx_info[i].isa_name;
+            m48txx_isa_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_isa_type_info);
+        }
+    }
 }
 
 type_init(m48t59_register_types)
--
Quoted 3 lines

1.7.10.4

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

#8 lore raw

Re: [Qemu-devel] [RFC v2 3/7] m48t59: register a QOM type for each nvram type we support

Quoted 14 lines · Artyom Tarasenko
Quoted 13 lines · Blue Swirl
Quoted 11 lines · Artyom Tarasenko
Quoted 5 lines · Hervé Poussineau

As m48t59 devices can only be created with m48t59_init() or m48t59_init_isa(), we know exactly which nvram types are required. Register only those three types.
Remove .model and .size properties as they can be infered from nvram name. Remove .io_base ISA address port as m48t59_init_isa() is always called with ioport 0x74.

While this it indeed how it's currently called, this is wrong for the sun4u emulation.
The isa (ebus) variant of the sun4u m48t59_init_isa() should be called with a mem_base, not io_base.

Quoted 5 lines
Quoted 3 lines

Why? I don't see much difference between EBUS and ISA and with the memory API, the difference between PIO and MMIO is almost nonexistent anyway.

Can you elaborate? Do you mean we just need to change the io_base?

Why wouldn't that work?

Quoted 323 lines
Quoted 2 lines

But it should be possible to change the base to match real HW, whatever it is:
http://git.kernel.org/cgit/linux/kernel/git/davem/prtconfs.git/tree/ultra5#n273

Yes, I know where it is supposed to be, I'm just asking how to achieve this best with our current tooling.

Quoted 308 lines

So NACK for the original patch.

Quoted 306 lines

Do you think it should be implemented as another device type?

Quoted 291 lines
---
 hw/timer/m48t59.c |  187 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 126 insertions(+), 61 deletions(-)
hw/timer/m48t59.c +126 -62
index 41022f2..29ec462 100644
@@ -43,6 +43,13 @@
  * PPC platform there is also a nvram lock function.
  */
 
+typedef struct M48txxInfo {
+    const char *isa_name;
+    const char *sysbus_name;
+    uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
+    uint32_t size;
+} M48txxInfo;
+
 /*
  * Chipset docs:
  * http://www.st.com/stonline/products/literature/ds/2410/m48t02.pdf
@@ -54,7 +61,6 @@ struct M48t59State {
     /* Hardware parameters */
     qemu_irq IRQ;
     MemoryRegion iomem;
-    uint32_t io_base;
     uint32_t size;
     /* RTC management */
     time_t   time_offset;
@@ -78,12 +84,39 @@ typedef struct M48t59ISAState {
     MemoryRegion io;
 } M48t59ISAState;
 
+typedef struct M48txxISADeviceClass {
+    ISADeviceClass parent_class;
+    M48txxInfo info;
+} M48txxISADeviceClass;
+
 typedef struct M48t59SysBusState {
     SysBusDevice busdev;
     M48t59State state;
     MemoryRegion io;
 } M48t59SysBusState;
 
+typedef struct M48txxSysBusDeviceClass {
+    SysBusDeviceClass parent_class;
+    M48txxInfo info;
+} M48txxSysBusDeviceClass;
+
+static M48txxInfo m48txx_info[] = {
+    {
+        .sysbus_name = "m48t02",
+        .model = 2,
+        .size = 0x800,
+    },{
+        .sysbus_name = "m48t08",
+        .model = 8,
+        .size = 0x2000,
+    },{
+        .isa_name = "m48t59_isa",
+        .model = 59,
+        .size = 0x2000,
+    }
+};
+
+
 /* Fake timer functions */
 
 /* Alarm management */
@@ -640,25 +673,34 @@ M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
     SysBusDevice *s;
     M48t59SysBusState *d;
     M48t59State *state;
+    int i;
 
-    dev = qdev_create(NULL, "m48t59");
-    qdev_prop_set_uint32(dev, "model", model);
-    qdev_prop_set_uint32(dev, "size", size);
-    qdev_prop_set_uint32(dev, "io_base", io_base);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    d = FROM_SYSBUS(M48t59SysBusState, s);
-    state = &d->state;
-    sysbus_connect_irq(s, 0, IRQ);
-    memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
-    if (io_base != 0) {
-        memory_region_add_subregion(get_system_io(), io_base, &d->io);
-    }
-    if (mem_base != 0) {
-        sysbus_mmio_map(s, 0, mem_base);
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].sysbus_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
+
+        dev = qdev_create(NULL, m48txx_info[i].sysbus_name);
+        qdev_init_nofail(dev);
+        s = SYS_BUS_DEVICE(dev);
+        d = FROM_SYSBUS(M48t59SysBusState, s);
+        state = &d->state;
+        sysbus_connect_irq(s, 0, IRQ);
+        memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
+        if (io_base != 0) {
+            memory_region_add_subregion(get_system_io(), io_base, &d->io);
+        }
+        if (mem_base != 0) {
+            sysbus_mmio_map(s, 0, mem_base);
+        }
+
+        return state;
     }
 
-    return state;
+    assert(false);
+    return NULL;
 }
 
 M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
@@ -667,16 +709,27 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     M48t59ISAState *d;
     ISADevice *dev;
     M48t59State *s;
+    int i;
+
+    assert(io_base == 0x74);
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].isa_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
 
-    dev = isa_create(bus, "m48t59_isa");
-    qdev_prop_set_uint32(&dev->qdev, "model", model);
-    qdev_prop_set_uint32(&dev->qdev, "size", size);
-    qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
-    qdev_init_nofail(&dev->qdev);
-    d = DO_UPCAST(M48t59ISAState, busdev, dev);
-    s = &d->state;
+        dev = isa_create(bus, m48txx_info[i].isa_name);
+        qdev_init_nofail(&dev->qdev);
+        d = DO_UPCAST(M48t59ISAState, busdev, dev);
+        s = &d->state;
 
-    return s;
+        return s;
+    }
+
+    assert(false);
+    return NULL;
 }
 
 static void m48t59_init_common(M48t59State *s)
@@ -693,24 +746,32 @@ static void m48t59_init_common(M48t59State *s)
 
 static int m48t59_init_isa1(ISADevice *dev)
 {
+    ISADeviceClass *ic = ISA_DEVICE_GET_CLASS(dev);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     isa_init_irq(dev, &s->IRQ, 8);
     m48t59_init_common(s);
     memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
-    if (s->io_base != 0) {
-        isa_register_ioport(dev, &d->io, s->io_base);
-    }
+    isa_register_ioport(dev, &d->io, 0x74);
 
     return 0;
 }
 
 static int m48t59_init1(SysBusDevice *dev)
 {
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_GET_CLASS(dev);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
     M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     sysbus_init_irq(dev, &s->IRQ);
 
     memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
@@ -720,58 +781,62 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
-static Property m48t59_isa_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59ISAState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59ISAState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
+    M48txxInfo *info = data;
+
     ic->init = m48t59_init_isa1;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
-    dc->props = m48t59_isa_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
-    .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(M48t59ISAState),
-    .class_init    = m48t59_init_class_isa1,
-};
-
-static Property m48t59_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59SysBusState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void m48t59_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
+    M48txxInfo *info = data;
 
     k->init = m48t59_init1;
     dc->reset = m48t59_reset_sysbus;
-    dc->props = m48t59_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_info = {
-    .name          = "m48t59",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(M48t59SysBusState),
-    .class_init    = m48t59_class_init,
-};
-
 static void m48t59_register_types(void)
 {
-    type_register_static(&m48t59_info);
-    type_register_static(&m48t59_isa_info);
+    TypeInfo m48txx_type_info = {
+        .parent = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(M48t59SysBusState),
+        .class_size = sizeof(M48txxSysBusDeviceClass),
+        .class_init = m48t59_class_init,
+    };
+    TypeInfo m48txx_isa_type_info = {
+        .parent = TYPE_ISA_DEVICE,
+        .instance_size = sizeof(M48t59ISAState),
+        .class_size = sizeof(M48txxISADeviceClass),
+        .class_init = m48t59_isa_class_init,
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (m48txx_info[i].sysbus_name) {
+            m48txx_type_info.name = m48txx_info[i].sysbus_name;
+            m48txx_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_type_info);
+        }
+
+        if (m48txx_info[i].isa_name) {
+            m48txx_isa_type_info.name = m48txx_info[i].isa_name;
+            m48txx_isa_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_isa_type_info);
+        }
+    }
 }
 
 type_init(m48t59_register_types)
--
Quoted 3 lines

1.7.10.4

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

#9 lore raw

Re: [Qemu-devel] [RFC v2 3/7] m48t59: register a QOM type for each nvram type we support

Quoted 15 lines · Blue Swirl
Quoted 14 lines · Artyom Tarasenko
Quoted 13 lines · Blue Swirl
Quoted 11 lines · Artyom Tarasenko
Quoted 5 lines · Hervé Poussineau

As m48t59 devices can only be created with m48t59_init() or m48t59_init_isa(), we know exactly which nvram types are required. Register only those three types.
Remove .model and .size properties as they can be infered from nvram name. Remove .io_base ISA address port as m48t59_init_isa() is always called with ioport 0x74.

While this it indeed how it's currently called, this is wrong for the sun4u emulation.
The isa (ebus) variant of the sun4u m48t59_init_isa() should be called with a mem_base, not io_base.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Why? I don't see much difference between EBUS and ISA and with the memory API, the difference between PIO and MMIO is almost nonexistent anyway.

Can you elaborate? Do you mean we just need to change the io_base?

Why wouldn't that work?

Because the PIO variant registers just 4 ports, whereas MMIO registers the whole device (0x2000 bytes).
The sun4u machines use a slightly different modification of the ISA Mostek chip. It has MMIO, 1968 as a base year and no IRQ line. Since it matches our m48t08, I'll send a patch fixing it.

Quoted 317 lines
Quoted 317 lines
Quoted 2 lines

But it should be possible to change the base to match real HW, whatever it is:
http://git.kernel.org/cgit/linux/kernel/git/davem/prtconfs.git/tree/ultra5#n273

Yes, I know where it is supposed to be, I'm just asking how to achieve this best with our current tooling.

Quoted 308 lines

So NACK for the original patch.

Quoted 306 lines

Do you think it should be implemented as another device type?

Quoted 291 lines
---
 hw/timer/m48t59.c |  187 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 126 insertions(+), 61 deletions(-)
hw/timer/m48t59.c +126 -62
index 41022f2..29ec462 100644
@@ -43,6 +43,13 @@
  * PPC platform there is also a nvram lock function.
  */
 
+typedef struct M48txxInfo {
+    const char *isa_name;
+    const char *sysbus_name;
+    uint32_t model; /* 2 = m48t02, 8 = m48t08, 59 = m48t59 */
+    uint32_t size;
+} M48txxInfo;
+
 /*
  * Chipset docs:
  * http://www.st.com/stonline/products/literature/ds/2410/m48t02.pdf
@@ -54,7 +61,6 @@ struct M48t59State {
     /* Hardware parameters */
     qemu_irq IRQ;
     MemoryRegion iomem;
-    uint32_t io_base;
     uint32_t size;
     /* RTC management */
     time_t   time_offset;
@@ -78,12 +84,39 @@ typedef struct M48t59ISAState {
     MemoryRegion io;
 } M48t59ISAState;
 
+typedef struct M48txxISADeviceClass {
+    ISADeviceClass parent_class;
+    M48txxInfo info;
+} M48txxISADeviceClass;
+
 typedef struct M48t59SysBusState {
     SysBusDevice busdev;
     M48t59State state;
     MemoryRegion io;
 } M48t59SysBusState;
 
+typedef struct M48txxSysBusDeviceClass {
+    SysBusDeviceClass parent_class;
+    M48txxInfo info;
+} M48txxSysBusDeviceClass;
+
+static M48txxInfo m48txx_info[] = {
+    {
+        .sysbus_name = "m48t02",
+        .model = 2,
+        .size = 0x800,
+    },{
+        .sysbus_name = "m48t08",
+        .model = 8,
+        .size = 0x2000,
+    },{
+        .isa_name = "m48t59_isa",
+        .model = 59,
+        .size = 0x2000,
+    }
+};
+
+
 /* Fake timer functions */
 
 /* Alarm management */
@@ -640,25 +673,34 @@ M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
     SysBusDevice *s;
     M48t59SysBusState *d;
     M48t59State *state;
+    int i;
 
-    dev = qdev_create(NULL, "m48t59");
-    qdev_prop_set_uint32(dev, "model", model);
-    qdev_prop_set_uint32(dev, "size", size);
-    qdev_prop_set_uint32(dev, "io_base", io_base);
-    qdev_init_nofail(dev);
-    s = SYS_BUS_DEVICE(dev);
-    d = FROM_SYSBUS(M48t59SysBusState, s);
-    state = &d->state;
-    sysbus_connect_irq(s, 0, IRQ);
-    memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
-    if (io_base != 0) {
-        memory_region_add_subregion(get_system_io(), io_base, &d->io);
-    }
-    if (mem_base != 0) {
-        sysbus_mmio_map(s, 0, mem_base);
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].sysbus_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
+
+        dev = qdev_create(NULL, m48txx_info[i].sysbus_name);
+        qdev_init_nofail(dev);
+        s = SYS_BUS_DEVICE(dev);
+        d = FROM_SYSBUS(M48t59SysBusState, s);
+        state = &d->state;
+        sysbus_connect_irq(s, 0, IRQ);
+        memory_region_init_io(&d->io, &m48t59_io_ops, state, "m48t59", 4);
+        if (io_base != 0) {
+            memory_region_add_subregion(get_system_io(), io_base, &d->io);
+        }
+        if (mem_base != 0) {
+            sysbus_mmio_map(s, 0, mem_base);
+        }
+
+        return state;
     }
 
-    return state;
+    assert(false);
+    return NULL;
 }
 
 M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
@@ -667,16 +709,27 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     M48t59ISAState *d;
     ISADevice *dev;
     M48t59State *s;
+    int i;
+
+    assert(io_base == 0x74);
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (!m48txx_info[i].isa_name ||
+            m48txx_info[i].size != size ||
+            m48txx_info[i].model != model) {
+            continue;
+        }
 
-    dev = isa_create(bus, "m48t59_isa");
-    qdev_prop_set_uint32(&dev->qdev, "model", model);
-    qdev_prop_set_uint32(&dev->qdev, "size", size);
-    qdev_prop_set_uint32(&dev->qdev, "io_base", io_base);
-    qdev_init_nofail(&dev->qdev);
-    d = DO_UPCAST(M48t59ISAState, busdev, dev);
-    s = &d->state;
+        dev = isa_create(bus, m48txx_info[i].isa_name);
+        qdev_init_nofail(&dev->qdev);
+        d = DO_UPCAST(M48t59ISAState, busdev, dev);
+        s = &d->state;
 
-    return s;
+        return s;
+    }
+
+    assert(false);
+    return NULL;
 }
 
 static void m48t59_init_common(M48t59State *s)
@@ -693,24 +746,32 @@ static void m48t59_init_common(M48t59State *s)
 
 static int m48t59_init_isa1(ISADevice *dev)
 {
+    ISADeviceClass *ic = ISA_DEVICE_GET_CLASS(dev);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     isa_init_irq(dev, &s->IRQ, 8);
     m48t59_init_common(s);
     memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
-    if (s->io_base != 0) {
-        isa_register_ioport(dev, &d->io, s->io_base);
-    }
+    isa_register_ioport(dev, &d->io, 0x74);
 
     return 0;
 }
 
 static int m48t59_init1(SysBusDevice *dev)
 {
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_GET_CLASS(dev);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
     M48t59SysBusState *d = FROM_SYSBUS(M48t59SysBusState, dev);
     M48t59State *s = &d->state;
 
+    s->model = u->info.model;
+    s->size = u->info.size;
     sysbus_init_irq(dev, &s->IRQ);
 
     memory_region_init_io(&s->iomem, &nvram_ops, s, "m48t59.nvram", s->size);
@@ -720,58 +781,62 @@ static int m48t59_init1(SysBusDevice *dev)
     return 0;
 }
 
-static Property m48t59_isa_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59ISAState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59ISAState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59ISAState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
-static void m48t59_init_class_isa1(ObjectClass *klass, void *data)
+static void m48t59_isa_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
+    M48txxISADeviceClass *u = container_of(ic, M48txxISADeviceClass,
+                                           parent_class);
+    M48txxInfo *info = data;
+
     ic->init = m48t59_init_isa1;
     dc->no_user = 1;
     dc->reset = m48t59_reset_isa;
-    dc->props = m48t59_isa_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_isa_info = {
-    .name          = "m48t59_isa",
-    .parent        = TYPE_ISA_DEVICE,
-    .instance_size = sizeof(M48t59ISAState),
-    .class_init    = m48t59_init_class_isa1,
-};
-
-static Property m48t59_properties[] = {
-    DEFINE_PROP_UINT32("size",    M48t59SysBusState, state.size,    -1),
-    DEFINE_PROP_UINT32("model",   M48t59SysBusState, state.model,   -1),
-    DEFINE_PROP_HEX32( "io_base", M48t59SysBusState, state.io_base,  0),
-    DEFINE_PROP_END_OF_LIST(),
-};
-
 static void m48t59_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    M48txxSysBusDeviceClass *u = container_of(k, M48txxSysBusDeviceClass,
+                                              parent_class);
+    M48txxInfo *info = data;
 
     k->init = m48t59_init1;
     dc->reset = m48t59_reset_sysbus;
-    dc->props = m48t59_properties;
+    u->info = *info;
 }
 
-static const TypeInfo m48t59_info = {
-    .name          = "m48t59",
-    .parent        = TYPE_SYS_BUS_DEVICE,
-    .instance_size = sizeof(M48t59SysBusState),
-    .class_init    = m48t59_class_init,
-};
-
 static void m48t59_register_types(void)
 {
-    type_register_static(&m48t59_info);
-    type_register_static(&m48t59_isa_info);
+    TypeInfo m48txx_type_info = {
+        .parent = TYPE_SYS_BUS_DEVICE,
+        .instance_size = sizeof(M48t59SysBusState),
+        .class_size = sizeof(M48txxSysBusDeviceClass),
+        .class_init = m48t59_class_init,
+    };
+    TypeInfo m48txx_isa_type_info = {
+        .parent = TYPE_ISA_DEVICE,
+        .instance_size = sizeof(M48t59ISAState),
+        .class_size = sizeof(M48txxISADeviceClass),
+        .class_init = m48t59_isa_class_init,
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(m48txx_info); i++) {
+        if (m48txx_info[i].sysbus_name) {
+            m48txx_type_info.name = m48txx_info[i].sysbus_name;
+            m48txx_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_type_info);
+        }
+
+        if (m48txx_info[i].isa_name) {
+            m48txx_isa_type_info.name = m48txx_info[i].isa_name;
+            m48txx_isa_type_info.class_data = &m48txx_info[i];
+            type_register(&m48txx_isa_type_info);
+        }
+    }
 }
 
 type_init(m48t59_register_types)
--
Quoted 3 lines

1.7.10.4

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

Quoted 6 lines
Quoted 6 lines

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu

#10 lore raw

RFC v2 4/7 m48t59: use DeviceState in public functions

In reply to Hervé Poussineau

There is no reason to use a custom type (M48t59State) in public nvram functions. Replace it by a DeviceState.

read/write/toggle_lock functions may later be added to some NVRAM interface.

---
 hw/ppc/prep.c             |   12 +++----
 hw/sparc/sun4m.c          |    7 ++--
 hw/sparc64/sun4u.c        |    6 ++--
 hw/timer/m48t59.c         |   79 ++++++++++++++++++++++++++++++++++-----------
 include/hw/timer/m48t59.h |   14 ++++----
 5 files changed, 81 insertions(+), 37 deletions(-)
hw/ppc/prep.c +6 -6
index cceab3e..8de8625 100644
@@ -179,7 +179,7 @@ static const MemoryRegionOps PPC_XCSR_ops = {
 /* Fake super-io ports for PREP platform (Intel 82378ZB) */
 typedef struct sysctrl_t {
     qemu_irq reset_irq;
-    M48t59State *nvram;
+    DeviceState *nvram;
     uint8_t state;
     uint8_t syscontrol;
     int contiguous_map;
@@ -233,12 +233,12 @@ static void PREP_io_800_writeb (void *opaque, uint32_t addr, uint32_t val)
     case 0x0810:
         /* Password protect 1 register */
         if (sysctrl->nvram != NULL)
-            m48t59_toggle_lock(sysctrl->nvram, 1);
+            m48txx_toggle_lock(sysctrl->nvram, 1);
         break;
     case 0x0812:
         /* Password protect 2 register */
         if (sysctrl->nvram != NULL)
-            m48t59_toggle_lock(sysctrl->nvram, 2);
+            m48txx_toggle_lock(sysctrl->nvram, 2);
         break;
     case 0x0814:
         /* L2 invalidate register */
@@ -443,7 +443,7 @@ static void ppc_prep_init(QEMUMachineInitArgs *args)
     CPUPPCState *env = NULL;
     char *filename;
     nvram_t nvram;
-    M48t59State *m48t59;
+    DeviceState *m48t59;
     MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1);
 #if 0
     MemoryRegion *xcsr = g_new(MemoryRegion, 1);
@@ -646,8 +646,8 @@ static void ppc_prep_init(QEMUMachineInitArgs *args)
 
     /* Initialise NVRAM */
     nvram.opaque = m48t59;
-    nvram.read_fn = &m48t59_read;
-    nvram.write_fn = &m48t59_write;
+    nvram.read_fn = &m48txx_read;
+    nvram.write_fn = &m48txx_write;
     PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,
                          kernel_base, kernel_size,
                          kernel_cmdline,
hw/sparc/sun4m.c +4 -3
index 31beb32..7ba4576 100644
@@ -167,7 +167,7 @@ static int fw_cfg_boot_set(void *opaque, const char *boot_device)
     return 0;
 }
 
-static void nvram_init(M48t59State *nvram, uint8_t *macaddr,
+static void nvram_init(DeviceState *nvram, uint8_t *macaddr,
                        const char *cmdline, const char *boot_devices,
                        ram_addr_t RAM_size, uint32_t kernel_size,
                        int width, int height, int depth,
@@ -211,7 +211,7 @@ static void nvram_init(M48t59State *nvram, uint8_t *macaddr,
                     nvram_machine_id);
 
     for (i = 0; i < sizeof(image); i++)
-        m48t59_write(nvram, i, image[i]);
+        m48txx_write(nvram, i, image[i]);
 }
 
 static DeviceState *slavio_intctl;
@@ -866,7 +866,8 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
                           const char *initrd_filename, const char *cpu_model)
 {
     unsigned int i;
-    void *iommu, *espdma, *ledma, *nvram;
+    void *iommu, *espdma, *ledma;
+    DeviceState *nvram;
     qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
         espdma_irq, ledma_irq;
     qemu_irq esp_reset, dma_enable;
hw/sparc64/sun4u.c +3 -3
index 0d29620..0197bfc 100644
@@ -130,7 +130,7 @@ static int fw_cfg_boot_set(void *opaque, const char *boot_device)
     return 0;
 }
 
-static int sun4u_NVRAM_set_params(M48t59State *nvram, uint16_t NVRAM_size,
+static int sun4u_NVRAM_set_params(DeviceState *nvram, uint16_t NVRAM_size,
                                   const char *arch, ram_addr_t RAM_size,
                                   const char *boot_devices,
                                   uint32_t kernel_image, uint32_t kernel_size,
@@ -177,7 +177,7 @@ static int sun4u_NVRAM_set_params(M48t59State *nvram, uint16_t NVRAM_size,
     Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80);
 
     for (i = 0; i < sizeof(image); i++)
-        m48t59_write(nvram, i, image[i]);
+        m48txx_write(nvram, i, image[i]);
 
     return 0;
 }
@@ -810,7 +810,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
                         const struct hwdef *hwdef)
 {
     SPARCCPU *cpu;
-    M48t59State *nvram;
+    DeviceState *nvram;
     unsigned int i;
     uint64_t initrd_addr, initrd_size, kernel_addr, kernel_size, kernel_entry;
     PCIBus *pci_bus, *pci_bus2, *pci_bus3;
hw/timer/m48t59.c +61 -18

128 lines not on this page · raw message

include/hw/timer/m48t59.h +7 -7
index 59337fa..7ec4173 100644
@@ -2,8 +2,8 @@
 #define NVRAM_H
 
 /* NVRAM helpers */
-typedef uint32_t (*nvram_read_t)(void *private, uint32_t addr);
-typedef void (*nvram_write_t)(void *private, uint32_t addr, uint32_t val);
+typedef uint32_t (*nvram_read_t)(DeviceState *dev, uint32_t addr);
+typedef void (*nvram_write_t)(DeviceState *dev, uint32_t addr, uint32_t val);
 typedef struct nvram_t {
     void *opaque;
     nvram_read_t read_fn;
@@ -23,12 +23,12 @@ int PPC_NVRAM_set_params (nvram_t *nvram, uint16_t NVRAM_size,
                           int width, int height, int depth);
 typedef struct M48t59State M48t59State;
 
-void m48t59_write (void *private, uint32_t addr, uint32_t val);
-uint32_t m48t59_read (void *private, uint32_t addr);
-void m48t59_toggle_lock (void *private, int lock);
-M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
+void m48txx_write(DeviceState *dev, uint32_t addr, uint32_t val);
+uint32_t m48txx_read(DeviceState *dev, uint32_t addr);
+void m48txx_toggle_lock(DeviceState *dev, int lock);
+DeviceState *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
                              int type);
-M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
+DeviceState *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
                          uint32_t io_base, uint16_t size, int type);
 
 #endif /* !NVRAM_H */
Signature · 1 line
1.7.10.4
#11 lore raw

RFC v2 5/7 prep: add IBM RS/6000 7248 (43p) machine emulation

In reply to Hervé Poussineau

Machine is very simple (only one PCI host bridge and an ISA bridge). Provide a ibm_43p.cfg file to add more devices to this machine.

Syntax is:
qemu-system-ppc -M 43p -readconfig ibm_43p.cfg

---
 docs/ibm_43p.cfg |   37 ++++++++++
 hw/ppc/prep.c    |  211 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 248 insertions(+)
 create mode 100644 docs/ibm_43p.cfg
docs/ibm_43p.cfg new file +37 -0
new file mode 100644
index 0000000..0950dd7
@@ -0,0 +1,37 @@
+############################################################################
+#
+# qemu-system-ppc -M 43p creates a bare machine with just the very essential
+# chipset devices being present:
+#
+#     00.0 - Host bridge
+#     0b.0 - ISA bridge
+#
+# This config file documents the other devices and how they are
+# created.  You can simply use "-readconfig $thisfile" to create
+# them all.
+
+[device]
+  driver = "m48t59_isa"
+
+[device]
+  driver = "i8042"
+
+[device]
+  driver = "pc87312"
+  config = "12"
+
+[device]
+  driver = "pcnet"
+  addr = "12.0"
+
+[device]
+  driver = "isa-ide"
+  iobase = "0x1f0"
+  iobase2 = "0x3f6"
+  irq = "14"
+
+[device]
+  driver = "isa-ide"
+  iobase = "0x170"
+  iobase2 = "0x376"
+  irq = "15"
hw/ppc/prep.c +211 -0

250 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#12 lore raw

RFC v2 6/7 prep: QOM'ify System I/O

In reply to Hervé Poussineau

Most of the functionality is extracted from hw/ppc/prep.c. Also add support for board identification/equipment registers.

Document it for the IBM 43p emulation.

---
 docs/ibm_43p.cfg       |    5 +
 hw/ppc/Makefile.objs   |    1 +
 hw/ppc/prep_systemio.c |  290 ++++++++++++++++++++++++++++++++++++++++++++++++
 trace-events           |    4 +
 4 files changed, 300 insertions(+)
 create mode 100644 hw/ppc/prep_systemio.c
docs/ibm_43p.cfg +5 -0
index 0950dd7..a265c01 100644
@@ -35,3 +35,8 @@
   iobase = "0x170"
   iobase2 = "0x376"
   irq = "15"
+
+[device]
+  driver = "prep-systemio800"
+  ibm-planar-id = "0xc0"
+  equipment = "0xff"
hw/ppc/Makefile.objs +1 -0
index be00d1d..cd1eb1b 100644
@@ -9,6 +9,7 @@ obj-y += ppc405_boards.o ppc4xx_devs.o ppc405_uc.o ppc440_bamboo.o
 obj-y += ppc4xx_pci.o
 # PReP
 obj-y += prep.o
+obj-y += prep_systemio.o
 # OldWorld PowerMac
 obj-y += mac_oldworld.o
 # NewWorld PowerMac
hw/ppc/prep_systemio.c new file +290 -0

290 lines not on this page · raw message

trace-events +4 -0
index 8b0ad9c..ba5b71a 100644
@@ -761,6 +761,10 @@ pc87312_info_ide(uint32_t base) "base 0x%x"
 pc87312_info_parallel(uint32_t base, uint32_t irq) "base 0x%x, irq %u"
 pc87312_info_serial(int n, uint32_t base, uint32_t irq) "id=%d, base 0x%x, irq %u"
 
+# hw/ppc/prep_systemio.c
+prep_systemio_read(uint32_t addr, uint32_t val) "read addr=%x val=%x"
+prep_systemio_write(uint32_t addr, uint32_t val) "write addr=%x val=%x"
+
 # hw/mpc105.c
 mpc105_unassigned_mem_read(uint64_t addr) "Unassigned mem read %" PRIx64
 mpc105_unassigned_mem_write(uint64_t addr, uint64_t val) "Unassigned mem write %" PRIx64 " = 0x%" PRIx64
Signature · 1 line
1.7.10.4
#13 lore raw

RFC v2 7/7 m48t59: hack(?) to make it work on IBM 43p

In reply to Hervé Poussineau
---
 hw/timer/m48t59.c |    2 ++
 1 file changed, 2 insertions(+)
hw/timer/m48t59.c +2 -0
index afcd5f5..4956cd7 100644
@@ -571,6 +571,7 @@ static void NVRAM_writeb(void *opaque, hwaddr addr, uint64_t val,
         NVRAM->addr &= ~0xFF00;
         NVRAM->addr |= val << 8;
         break;
+    case 2:
     case 3:
         m48t59_write(NVRAM, NVRAM->addr, val);
         NVRAM->addr = 0x0000;
@@ -586,6 +587,7 @@ static uint64_t NVRAM_readb(void *opaque, hwaddr addr, unsigned size)
     uint32_t retval;
 
     switch (addr) {
+    case 2:
     case 3:
         retval = m48t59_read(NVRAM, NVRAM->addr);
         break;
Signature · 1 line
1.7.10.4