All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Chubb <peterc@gelato.unsw.edu.au>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: davidm@ok-labs.com, Peter Chubb <peter.chubb@nicta.com.au>,
	qemu-devel@nongnu.org, philipo@ok-labs.com,
	Paul Brook <paul@codesourcery.com>
Subject: Re: [Qemu-devel] [PATCH] [ARM] Fix sp804 dual-timer
Date: Tue, 22 Nov 2011 09:05:24 +1100	[thread overview]
Message-ID: <w4k46tm8rf.wl%peter@chubb.wattle.id.au> (raw)
In-Reply-To: <CAFEAcA-4Kp_BWMzfd7AryuEF7CjWwGdQO6gtVv8wCMVbD1tU3g@mail.gmail.com>

Hi Peter,
   Here's a fixed patch for the sp804 timer.

Properly implement the dual-timer read/write for the sp804 dual timer module.
Based on ARM specs at
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0271d/index.html

Signed-off-by: Peter Chubb <peter.chubb@nicta.com.au>
Signed-off-by: David Mirabito <david.mirabito@nicta.com.au>
Signed-off-by: Hans Jang <hsjang@ok-labs.com>
---
 hw/arm_timer.c |   45 +++++++++++++++++++++++++++++++++++++--------
 1 file changed, 37 insertions(+), 8 deletions(-)

Index: qemu-working/hw/arm_timer.c
===================================================================
--- qemu-working.orig/hw/arm_timer.c	2011-11-21 09:05:05.566351984 +1100
+++ qemu-working/hw/arm_timer.c	2011-11-21 09:05:10.582372066 +1100
@@ -163,64 +163,93 @@ static arm_timer_state *arm_timer_init(u
     s->freq = freq;
     s->control = TIMER_CTRL_IE;
 
     bh = qemu_bh_new(arm_timer_tick, s);
     s->timer = ptimer_init(bh);
     vmstate_register(NULL, -1, &vmstate_arm_timer, s);
     return s;
 }
 
 /* ARM PrimeCell SP804 dual timer module.
-   Docs for this device don't seem to be publicly available.  This
-   implementation is based on guesswork, the linux kernel sources and the
-   Integrator/CP timer modules.  */
+ * Docs at
+ * http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0271d/index.html
+*/
 
 typedef struct {
     SysBusDevice busdev;
     MemoryRegion iomem;
     arm_timer_state *timer[2];
     int level[2];
     qemu_irq irq;
 } sp804_state;
 
+static const uint8_t sp804_ids[] = {
+    /* Timer ID */
+    0x04, 0x18, 0x14, 0,
+    /* PrimeCell ID */
+    0xd, 0xf0, 0x05, 0xb1
+};
+
 /* Merge the IRQs from the two component devices.  */
 static void sp804_set_irq(void *opaque, int irq, int level)
 {
     sp804_state *s = (sp804_state *)opaque;
 
     s->level[irq] = level;
     qemu_set_irq(s->irq, s->level[0] || s->level[1]);
 }
 
 static uint64_t sp804_read(void *opaque, target_phys_addr_t offset,
                            unsigned size)
 {
     sp804_state *s = (sp804_state *)opaque;
 
-    /* ??? Don't know the PrimeCell ID for this device.  */
     if (offset < 0x20) {
         return arm_timer_read(s->timer[0], offset);
-    } else {
+    }
+    if (offset < 0x40) {
         return arm_timer_read(s->timer[1], offset - 0x20);
     }
+
+    /* TimerPeriphID */
+    if (offset >= 0xfe0 && offset <= 0xffc) {
+        return sp804_ids[(offset - 0xfe0) >> 2];
+    }
+
+    switch (offset) {
+    /* Integration Test control registers, which we won't support */
+    case 0xf00: /* TimerITCR */
+    case 0xf04: /* TimerITOP (strictly write only but..) */
+        return 0;
+    }
+
+    hw_error("sp804_read: Bad offset %x\n", (int)offset);
+    return 0;
 }
 
 static void sp804_write(void *opaque, target_phys_addr_t offset,
                         uint64_t value, unsigned size)
 {
     sp804_state *s = (sp804_state *)opaque;
 
     if (offset < 0x20) {
         arm_timer_write(s->timer[0], offset, value);
-    } else {
+        return;
+    }
+
+    if (offset < 0x40) {
         arm_timer_write(s->timer[1], offset - 0x20, value);
+        return;
     }
+
+    /* Technically we could be writing to the Test Registers, but not likely */
+    hw_error("sp804_write: Bad offset %x\n", (int)offset);
 }
 
 static const MemoryRegionOps sp804_ops = {
     .read = sp804_read,
     .write = sp804_write,
     .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
 static const VMStateDescription vmstate_sp804 = {
     .name = "sp804",
@@ -263,35 +292,35 @@ typedef struct {
 
 static uint64_t icp_pit_read(void *opaque, target_phys_addr_t offset,
                              unsigned size)
 {
     icp_pit_state *s = (icp_pit_state *)opaque;
     int n;
 
     /* ??? Don't know the PrimeCell ID for this device.  */
     n = offset >> 8;
     if (n > 2) {
-        hw_error("sp804_read: Bad timer %d\n", n);
+        hw_error("icp_pit_read: Bad timer %d\n", n);
     }
 
     return arm_timer_read(s->timer[n], offset & 0xff);
 }
 
 static void icp_pit_write(void *opaque, target_phys_addr_t offset,
                           uint64_t value, unsigned size)
 {
     icp_pit_state *s = (icp_pit_state *)opaque;
     int n;
 
     n = offset >> 8;
     if (n > 2) {
-        hw_error("sp804_write: Bad timer %d\n", n);
+        hw_error("icp_pit_write: Bad timer %d\n", n);
     }
 
     arm_timer_write(s->timer[n], offset & 0xff, value);
 }
 
 static const MemoryRegionOps icp_pit_ops = {
     .read = icp_pit_read,
     .write = icp_pit_write,
     .endianness = DEVICE_NATIVE_ENDIAN,
 };

--
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au           ERTOS within National ICT Australia
--
Dr Peter Chubb  http://www.gelato.unsw.edu.au  peterc AT gelato.unsw.edu.au
http://www.ertos.nicta.com.au           ERTOS within National ICT Australia

  parent reply	other threads:[~2011-11-21 22:05 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-29  2:34 [Qemu-devel] [PATCH] [ARM] Fix sp804 dual-timer Peter Chubb
2011-09-29  9:58 ` Peter Maydell
2011-09-30  0:20   ` Peter Chubb
2011-09-30  9:04     ` Peter Maydell
2011-09-30  9:23       ` Peter Chubb
2011-09-30 10:07         ` Peter Maydell
     [not found]   ` <w4y5x6g8gk.wl%peter@chubb.wattle.id.au>
     [not found]     ` <CAFEAcA8-iByH0xgjkMUo3hvkrLc8NV-Lq4GbHU-d7UoF8GSX-Q@mail.gmail.com>
2011-11-21 21:58       ` [Qemu-devel] [PATCH] imx.31 and KZM board support Peter Chubb
2011-11-21 22:45         ` Andreas Färber
2011-11-21 23:04           ` Peter Chubb
2011-11-21 23:10             ` Peter Maydell
2011-11-21 23:41         ` Peter Maydell
2011-11-21 23:54           ` Peter Chubb
2011-11-22  0:12             ` Peter Maydell
2011-11-22  0:27               ` Peter Chubb
2011-11-22  0:32                 ` Peter Maydell
2011-11-22  4:31           ` [Qemu-devel] [PATCH V2 0/4] " Peter Chubb
2011-11-22  4:32             ` [Qemu-devel] [PATCH V2 1/4] imx.31 and KZM board support: UART support Peter Chubb
2011-11-24 18:53               ` Peter Maydell
2011-11-24 22:18                 ` Peter Chubb
2011-11-22  4:33             ` [Qemu-devel] [PATCH V2 2/4] imx.31 and KZM board support: Timer support Peter Chubb
2011-11-24 17:01               ` Peter Maydell
2011-11-24 19:06               ` Peter Maydell
2011-11-22  4:34             ` [Qemu-devel] [PATCH V2 3/4] imx.31 and KZM board support: interrupt controller Peter Chubb
2011-11-24 19:37               ` Peter Maydell
2011-11-22  4:34             ` [Qemu-devel] [PATCH V2 4/4] imx.31 and KZM board support: Makefile and board Peter Chubb
2011-11-24 19:41               ` Peter Maydell
2011-11-24 20:19                 ` Andreas Färber
2011-11-24 21:31                   ` Peter Maydell
2011-11-24 21:46                     ` Andreas Färber
2011-11-24 21:52                       ` Peter Maydell
2011-11-23  0:51             ` [Qemu-devel] [PATCH V2 0/4] imx.31 and KZM board support Peter Chubb
2011-11-24 19:07               ` Andreas Färber
2011-11-26  5:21                 ` Peter Chubb
2011-11-26 19:35                   ` Peter Maydell
2011-11-22 11:06         ` [Qemu-devel] [PATCH] " Juan Quintela
2011-11-22 11:14           ` Peter Maydell
2011-11-23 14:24             ` Juan Quintela
2011-11-23  0:48           ` Peter Chubb
2011-11-21 22:05   ` Peter Chubb [this message]
2011-11-21 23:01     ` [Qemu-devel] [PATCH] [ARM] Fix sp804 dual-timer Andreas Färber
2011-11-22  0:20       ` [Qemu-devel] [PATCH] [ARM] fix function names in error messages in arm_timer.c Peter Chubb
2011-11-22  3:20       ` [Qemu-devel] [PATCH] [ARM] Fix hw_error messages from arm_timer.c Peter Chubb
2011-12-05 19:53         ` andrzej zaborowski
2011-11-22  3:25       ` [Qemu-devel] [PATCH] [ARM] Fix sp804 dual-timer Peter Chubb
2011-11-24 17:46         ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=w4k46tm8rf.wl%peter@chubb.wattle.id.au \
    --to=peterc@gelato.unsw.edu.au \
    --cc=davidm@ok-labs.com \
    --cc=paul@codesourcery.com \
    --cc=peter.chubb@nicta.com.au \
    --cc=peter.maydell@linaro.org \
    --cc=philipo@ok-labs.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.