qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] hw/arm: add a PL031 driver to the virt machine
@ 2014-06-20 22:32 Aurelien Jarno
  2014-06-20 22:37 ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Aurelien Jarno @ 2014-06-20 22:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Aurelien Jarno

We currently do no have a virtio device for the real time clock. Instead
of having to fetch the date and time from an NTP server, provide a PL031
device in the virt machine.

Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 hw/arm/virt.c |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 72fe030..617f509 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -64,6 +64,7 @@ enum {
     VIRT_GIC_DIST,
     VIRT_GIC_CPU,
     VIRT_UART,
+    VIRT_RTC,
     VIRT_MMIO,
 };
 
@@ -101,6 +102,7 @@ static const MemMapEntry a15memmap[] = {
     [VIRT_GIC_DIST] = { 0x8000000, 0x10000 },
     [VIRT_GIC_CPU] = { 0x8010000, 0x10000 },
     [VIRT_UART] = { 0x9000000, 0x1000 },
+    [VIRT_RTC] = { 0x9010000, 0x1000 },
     [VIRT_MMIO] = { 0xa000000, 0x200 },
     /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
     /* 0x10000000 .. 0x40000000 reserved for PCI */
@@ -109,6 +111,7 @@ static const MemMapEntry a15memmap[] = {
 
 static const int a15irqmap[] = {
     [VIRT_UART] = 1,
+    [VIRT_RTC] = 2,
     [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
 };
 
@@ -353,6 +356,34 @@ static void create_uart(const VirtBoardInfo *vbi, qemu_irq *pic)
     g_free(nodename);
 }
 
+static void create_rtc(const VirtBoardInfo *vbi, qemu_irq *pic)
+{
+    char *nodename;
+    hwaddr base = vbi->memmap[VIRT_RTC].base;
+    hwaddr size = vbi->memmap[VIRT_RTC].size;
+    int irq = vbi->irqmap[VIRT_RTC];
+    const char compat[] = "arm,pl031\0arm,primecell";
+    const char clocknames[] = "apb_pclk";
+
+    sysbus_create_simple("pl031", base, pic[irq]);
+
+    nodename = g_strdup_printf("/pl031@%" PRIx64, base);
+    qemu_fdt_add_subnode(vbi->fdt, nodename);
+    /* Note that we can't use setprop_string because of the embedded NUL */
+    qemu_fdt_setprop(vbi->fdt, nodename, "compatible",
+                         compat, sizeof(compat));
+    qemu_fdt_setprop_sized_cells(vbi->fdt, nodename, "reg",
+                                     2, base, 2, size);
+    qemu_fdt_setprop_cells(vbi->fdt, nodename, "interrupts",
+                               GIC_FDT_IRQ_TYPE_SPI, irq,
+                               GIC_FDT_IRQ_FLAGS_EDGE_LO_HI);
+    qemu_fdt_setprop_cells(vbi->fdt, nodename, "clocks",
+                               vbi->clock_phandle);
+    qemu_fdt_setprop(vbi->fdt, nodename, "clock-names",
+                         clocknames, sizeof(clocknames));
+    g_free(nodename);
+}
+
 static void create_virtio_devices(const VirtBoardInfo *vbi, qemu_irq *pic)
 {
     int i;
@@ -469,6 +500,8 @@ static void machvirt_init(MachineState *machine)
 
     create_uart(vbi, pic);
 
+    create_rtc(vbi, pic);
+
     /* Create mmio transports, so the user can create virtio backends
      * (which will be automatically plugged in to the transports). If
      * no backend is created the transport will just sit harmlessly idle.
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/arm: add a PL031 driver to the virt machine
  2014-06-20 22:32 [Qemu-devel] [PATCH] hw/arm: add a PL031 driver to the virt machine Aurelien Jarno
@ 2014-06-20 22:37 ` Peter Maydell
  2014-06-20 22:53   ` Aurelien Jarno
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2014-06-20 22:37 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: QEMU Developers

On 20 June 2014 23:32, Aurelien Jarno <aurelien@aurel32.net> wrote:
> We currently do no have a virtio device for the real time clock. Instead
> of having to fetch the date and time from an NTP server, provide a PL031
> device in the virt machine.

Erm, I posted a patch for this the other week:
http://patchwork.ozlabs.org/patch/358068/

(part of a series which also added flash).

thanks
-- PMM

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] hw/arm: add a PL031 driver to the virt machine
  2014-06-20 22:37 ` Peter Maydell
@ 2014-06-20 22:53   ` Aurelien Jarno
  0 siblings, 0 replies; 3+ messages in thread
From: Aurelien Jarno @ 2014-06-20 22:53 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers

On Fri, Jun 20, 2014 at 11:37:01PM +0100, Peter Maydell wrote:
> On 20 June 2014 23:32, Aurelien Jarno <aurelien@aurel32.net> wrote:
> > We currently do no have a virtio device for the real time clock. Instead
> > of having to fetch the date and time from an NTP server, provide a PL031
> > device in the virt machine.
> 
> Erm, I posted a patch for this the other week:
> http://patchwork.ozlabs.org/patch/358068/
> 
> (part of a series which also added flash).

Oh great that it's already in the pipe. We ended-up on the same code
modulo comments and indentation, so I have just sent a Tested-by and a
Reviewed-by.

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-20 22:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-20 22:32 [Qemu-devel] [PATCH] hw/arm: add a PL031 driver to the virt machine Aurelien Jarno
2014-06-20 22:37 ` Peter Maydell
2014-06-20 22:53   ` Aurelien Jarno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).