Skip to contentSkip to conversation

sparc64: Fix NVRAM access mode

PATCH In review Artyom Tarasenko 3 participants 7 messages Apr 27, 2013

lore
Share & tools
lore
#0 lore raw

cover sparc64: Fix NVRAM access mode

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, make keep PIO behavior for the 59 model and use MMIO for the 8 model.

This series fixes recognising Mostek RTC in the Linux/sparc64 guest.

Artyom Tarasenko (2):
m48t59: use mmio for the m48t08 model of the m48t59_isa card
sparc64: Use the correct type of the Mostek NVRAM chip

 hw/sparc64/sun4u.c |    5 ++++-
 hw/timer/m48t59.c  |   38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 4 deletions(-)
#1 lore raw

PATCH 1/2 m48t59: use mmio for the m48t08 model of the m48t59_isa card

PrEP and SPARC machines use slightly different variations of a Mostek NVRAM chip. Since the SPARC variant is much closer to a m48t08 type, the model can be used to differentiate between the PIO and MMIO accesses.

---
 hw/timer/m48t59.c |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)
hw/timer/m48t59.c +35 -3
index 5019e06..00ad417 100644
@@ -632,6 +632,33 @@ static const MemoryRegionOps m48t59_io_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
+static uint64_t nvram_read(void *opaque, hwaddr addr, unsigned size)
+{
+    M48t59State *NVRAM = opaque;
+    uint32_t retval;
+
+    retval = m48t59_read(NVRAM, addr);
+    return retval;
+}
+
+static void nvram_write(void *opaque, hwaddr addr, uint64_t value,
+                         unsigned size)
+{
+    M48t59State *NVRAM = opaque;
+
+    m48t59_write(NVRAM, addr, value & 0xff);
+}
+
+static const MemoryRegionOps m48t59_mmio_ops = {
+    .read = nvram_read,
+    .write = nvram_write,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 /* Initialisation routine */
 M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
                          uint32_t io_base, uint16_t size, int model)
@@ -676,7 +703,11 @@ 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 (model == 59) {
+        memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
+    } else {
+        memory_region_init_io(&d->io, &m48t59_mmio_ops, s, "m48t59", size);
+    }
     if (io_base != 0) {
         isa_register_ioport(dev, &d->io, io_base);
     }
@@ -700,8 +731,9 @@ static int m48t59_init_isa1(ISADevice *dev)
 {
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
-
-    isa_init_irq(dev, &s->IRQ, 8);
+    if (s->model == 59) {
+        isa_init_irq(dev, &s->IRQ, 8);
+    }
     m48t59_init_common(s);
 
     return 0;
Signature · 1 line
1.7.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] m48t59: use mmio for the m48t08 model of the m48t59_isa card

Am 27.04.2013 09:12, schrieb Artyom Tarasenko:

Quoted 1 line

PrEP and SPARC machines use slightly different variations of

PReP :)

Quoted 14 lines

a Mostek NVRAM chip. Since the SPARC variant is much closer to a m48t08 type, the model can be used to differentiate between the PIO and MMIO accesses.

---
 hw/timer/m48t59.c |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)
hw/timer/m48t59.c +0 -0
index 5019e06..00ad417 100644

hw/timer/m48t59.c static const MemoryRegionOps m48t59_io_ops = { · line 637

Quoted 6 lines
hw/timer/m48t59.c +3 -0
@@ -632,6 +632,33 @@ static const MemoryRegionOps m48t59_io_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
+static uint64_t nvram_read(void *opaque, hwaddr addr, unsigned size)
+{
+    M48t59State *NVRAM = opaque;

Probably this is just copy&paste from old code, but please use lower_case_names for variables in new code.

hw/timer/m48t59.c static const MemoryRegionOps m48t59_io_ops = { · line 645

Quoted 8 lines
hw/timer/m48t59.c +8 -0
+    uint32_t retval;
+
+    retval = m48t59_read(NVRAM, addr);
+    return retval;
+}
+
+static void nvram_write(void *opaque, hwaddr addr, uint64_t value,
+                         unsigned size)

Indentation one-off.

Quoted 20 lines
hw/timer/m48t59.c +16 -0
+{
+    M48t59State *NVRAM = opaque;
+
+    m48t59_write(NVRAM, addr, value & 0xff);
+}
+
+static const MemoryRegionOps m48t59_mmio_ops = {
+    .read = nvram_read,
+    .write = nvram_write,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 /* Initialisation routine */
 M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
                          uint32_t io_base, uint16_t size, int model)

hw/timer/m48t59.c M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size, · line 709

Quoted 8 lines
hw/timer/m48t59.c +4 -1
@@ -676,7 +703,11 @@ 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 (model == 59) {
+        memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
+    } else {
+        memory_region_init_io(&d->io, &m48t59_mmio_ops, s, "m48t59", size);

If you distinguish here, it may be a good idea to reflect that in the region's name.

Quoted 6 lines
hw/timer/m48t59.c +1 -0
+    }
     if (io_base != 0) {
         isa_register_ioport(dev, &d->io, io_base);
     }
@@ -700,8 +731,9 @@ static int m48t59_init_isa1(ISADevice *dev)
 {

hw/timer/m48t59.c static int m48t59_init_isa1(ISADevice *dev) · line 739

Quoted 10 lines
hw/timer/m48t59.c +3 -2
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
-
-    isa_init_irq(dev, &s->IRQ, 8);
+    if (s->model == 59) {
+        isa_init_irq(dev, &s->IRQ, 8);
+    }
     m48t59_init_common(s);
 
     return 0;

Regarding your question of whether to move this: With my ISA realize series this function becomes a ..._realize function. isa_init_irq() relies on the device being on an ISA bus to retrieve the qemu_irq, so this cannot be done in instance_init, thus in DeviceClass::init/realize. The existing legacy m48t59_init_isa() function should probably rather shrink in size and one day possibly be inlined rather than growing with stuff that was encapsulated in initfn or realizefn.

Regards,
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
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] m48t59: use mmio for the m48t08 model of the m48t59_isa card

Hi Andreas,

Quoted 4 lines · Andreas Färber

Am 27.04.2013 09:12, schrieb Artyom Tarasenko:

Quoted 1 line

PrEP and SPARC machines use slightly different variations of

PReP :)

Ops. :)

Quoted 17 lines
Quoted 17 lines

a Mostek NVRAM chip. Since the SPARC variant is much closer to a m48t08 type, the model can be used to differentiate between the PIO and MMIO accesses.

---
 hw/timer/m48t59.c |   38 +++++++++++++++++++++++++++++++++++---
 1 files changed, 35 insertions(+), 3 deletions(-)
hw/timer/m48t59.c +0 -0
index 5019e06..00ad417 100644
@@ -632,6 +632,33 @@ static const MemoryRegionOps m48t59_io_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
Quoted 6 lines

hw/timer/m48t59.c static const MemoryRegionOps m48t59_io_ops = { · line 637

Quoted 3 lines
hw/timer/m48t59.c +3 -0
+static uint64_t nvram_read(void *opaque, hwaddr addr, unsigned size)
+{
+    M48t59State *NVRAM = opaque;

Probably this is just copy&paste from old code, but please use lower_case_names for variables in new code.

Will do.

Quoted 10 lines

hw/timer/m48t59.c static const MemoryRegionOps m48t59_io_ops = { · line 645

Quoted 8 lines
hw/timer/m48t59.c +8 -0
+    uint32_t retval;
+
+    retval = m48t59_read(NVRAM, addr);
+    return retval;
+}
+
+static void nvram_write(void *opaque, hwaddr addr, uint64_t value,
+                         unsigned size)

Indentation one-off.

Good catch. Is btw a test case for checkpatch.pl - it doesn't complain.

Quoted 23 lines
Quoted 23 lines
hw/timer/m48t59.c +16 -0
+{
+    M48t59State *NVRAM = opaque;
+
+    m48t59_write(NVRAM, addr, value & 0xff);
+}
+
+static const MemoryRegionOps m48t59_mmio_ops = {
+    .read = nvram_read,
+    .write = nvram_write,
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 1,
+    },
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 /* Initialisation routine */
 M48t59State *m48t59_init(qemu_irq IRQ, hwaddr mem_base,
                          uint32_t io_base, uint16_t size, int model)
@@ -676,7 +703,11 @@ M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size,
     d = DO_UPCAST(M48t59ISAState, busdev, dev);
     s = &d->state;
 
Quoted 8 lines

hw/timer/m48t59.c M48t59State *m48t59_init_isa(ISABus *bus, uint32_t io_base, uint16_t size, · line 709

Quoted 5 lines
hw/timer/m48t59.c +4 -1
-    memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
+    if (model == 59) {
+        memory_region_init_io(&d->io, &m48t59_io_ops, s, "m48t59", 4);
+    } else {
+        memory_region_init_io(&d->io, &m48t59_mmio_ops, s, "m48t59", size);

If you distinguish here, it may be a good idea to reflect that in the region's name.

Will do.

Quoted 15 lines
Quoted 15 lines
hw/timer/m48t59.c +4 -2
+    }
     if (io_base != 0) {
         isa_register_ioport(dev, &d->io, io_base);
     }
@@ -700,8 +731,9 @@ static int m48t59_init_isa1(ISADevice *dev)
 {
     M48t59ISAState *d = DO_UPCAST(M48t59ISAState, busdev, dev);
     M48t59State *s = &d->state;
-
-    isa_init_irq(dev, &s->IRQ, 8);
+    if (s->model == 59) {
+        isa_init_irq(dev, &s->IRQ, 8);
+    }
     m48t59_init_common(s);
 
Quoted 9 lines

hw/timer/m48t59.c static int m48t59_init_isa1(ISADevice *dev) · line 739

Quoted 1 line
hw/timer/m48t59.c +0 -0
     return 0;

Regarding your question of whether to move this: With my ISA realize series this function becomes a ..._realize function. isa_init_irq() relies on the device being on an ISA bus to retrieve the qemu_irq, so this cannot be done in instance_init, thus in DeviceClass::init/realize. The existing legacy m48t59_init_isa() function should probably rather shrink in size and one day possibly be inlined rather than growing with stuff that was encapsulated in initfn or realizefn.

Totally agree with this approach. The question is how to model the various chip models. Should M48t59ISAState get an "irq_num" field? Hardcoding interrupt number just doesn't feel right.

Artyom

--
Regards,
Artyom Tarasenko

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

#4 lore raw

PATCH 2/2 sparc64: Use the correct type of the Mostek NVRAM chip

In reply to Artyom Tarasenko

The sun4u machines use an ISA Mostek chip which has MMIO, uses 1968 as a base year and no IRQ line. So, use the m48t08.

Please note that this patch has its OpenBIOS counterpart. Together they fix recognising NVRAM in the sun4u machine.

---
 hw/sparc64/sun4u.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
hw/sparc64/sun4u.c +4 -1
index 5c2bbd4..bfb19d4 100644
@@ -866,7 +866,10 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
         fd[i] = drive_get(IF_FLOPPY, 0, i);
     }
     fdctrl_init_isa(isa_bus, fd);
-    nvram = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);
+
+    /* XXX Ultra-5 has it at the beginning of the EBUS range, but we have
+     * serial port and other isa devices there */
+    nvram = m48t59_init_isa(isa_bus, 0x2000, NVRAM_SIZE, 8);
 
     initrd_size = 0;
     initrd_addr = 0;
Signature · 1 line
1.7.1
#5 lore raw
In reply to Artyom Tarasenko
Quoted 3 lines · Artyom Tarasenko

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, make keep PIO behavior for the 59 model and use MMIO for the 8 model.

The chip is definitely m48t59 (SGS-Thompson, M48T59Y-70MH1), even if the IRQ is not connected and software uses 1968 as the base year.

Please make the base year a qdev property and keep the model unchanged.

Quoted 11 lines

This series fixes recognising Mostek RTC in the Linux/sparc64 guest.

Artyom Tarasenko (2):
m48t59: use mmio for the m48t08 model of the m48t59_isa card
sparc64: Use the correct type of the Mostek NVRAM chip

 hw/sparc64/sun4u.c |    5 ++++-
 hw/timer/m48t59.c  |   38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 4 deletions(-)
#6 lore raw
Quoted 7 lines · Blue Swirl
Quoted 3 lines · Artyom Tarasenko

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, make keep PIO behavior for the 59 model and use MMIO for the 8 model.

The chip is definitely m48t59 (SGS-Thompson, M48T59Y-70MH1), even if the IRQ is not connected and software uses 1968 as the base year.

Ops. But it's not just software afaics - think about leap years. Do you by any chance have any docs beyond m48t59y.pdf? There is no information about base year in there. And in the Linux kernel there is just some CONFIG_SPARC #ifdefery.

Quoted 1 line

Please make the base year a qdev property and keep the model unchanged.

Maybe rather use something like "is_sun" property? It could be used to decide whether the IRQ should be connected and whether a PIO or a MMIO access should be used.

Btw can "isa_init_irq(dev, &s->IRQ, 8)" be moved from m48t59_init_isa1 to m48t59_init_isa ? Or shall the irq be silenced at the isa bridge level?

--
Regards,
Artyom Tarasenko

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