All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yoshinori Sato <ysato@users.sourceforge.jp>
To: qemu-devel@nongnu.org
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Subject: [PATCH] hw/timer/renesas_tmr.c cleanup read operation.
Date: Sun, 12 Jul 2020 00:42:42 +0900	[thread overview]
Message-ID: <20200711154242.41222-1-ysato@users.sourceforge.jp> (raw)

Cleanup read operation.
This module different return of access size.

Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp>
---
 hw/timer/renesas_tmr.c | 106 ++++++++++++++++++++++-------------------
 1 file changed, 57 insertions(+), 49 deletions(-)

diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c
index 446f2eacdd..d7b21edf39 100644
--- a/hw/timer/renesas_tmr.c
+++ b/hw/timer/renesas_tmr.c
@@ -187,59 +187,67 @@ static uint64_t tmr_read(void *opaque, hwaddr addr, unsigned size)
                       addr);
         return UINT64_MAX;
     }
-    switch (addr & 0x0e) {
-    case A_TCR:
-        ret = 0;
-        ret = FIELD_DP8(ret, TCR, CCLR,
-                        FIELD_EX8(tmr->tcr[ch], TCR, CCLR));
-        ret = FIELD_DP8(ret, TCR, OVIE,
-                        FIELD_EX8(tmr->tcr[ch], TCR, OVIE));
-        ret = FIELD_DP8(ret, TCR, CMIEA,
-                        FIELD_EX8(tmr->tcr[ch], TCR, CMIEA));
-        ret = FIELD_DP8(ret, TCR, CMIEB,
-                        FIELD_EX8(tmr->tcr[ch], TCR, CMIEB));
-        return ret;
-    case A_TCSR:
-        ret = 0;
-        ret = FIELD_DP8(ret, TCSR, OSA,
-                        FIELD_EX8(tmr->tcsr[ch], TCSR, OSA));
-        ret = FIELD_DP8(ret, TCSR, OSB,
-                        FIELD_EX8(tmr->tcsr[ch], TCSR, OSB));
-        switch (ch) {
-        case 0:
-            ret = FIELD_DP8(ret, TCSR, ADTE,
-                            FIELD_EX8(tmr->tcsr[ch], TCSR, ADTE));
-            break;
-        case 1: /* CH1 ADTE unimplement always 1 */
-            ret = FIELD_DP8(ret, TCSR, ADTE, 1);
-            break;
-        }
-        return ret;
-    case A_TCORA:
-        if (size == 1) {
+    switch (size) {
+    case 1:
+        switch (addr & 0x0e) {
+        case A_TCR:
+            ret = 0;
+            ret = FIELD_DP8(ret, TCR, CCLR,
+                            FIELD_EX8(tmr->tcr[ch], TCR, CCLR));
+            ret = FIELD_DP8(ret, TCR, OVIE,
+                            FIELD_EX8(tmr->tcr[ch], TCR, OVIE));
+            ret = FIELD_DP8(ret, TCR, CMIEA,
+                            FIELD_EX8(tmr->tcr[ch], TCR, CMIEA));
+            ret = FIELD_DP8(ret, TCR, CMIEB,
+                            FIELD_EX8(tmr->tcr[ch], TCR, CMIEB));
+            return ret;
+        case A_TCSR:
+            ret = 0;
+            ret = FIELD_DP8(ret, TCSR, OSA,
+                            FIELD_EX8(tmr->tcsr[ch], TCSR, OSA));
+            ret = FIELD_DP8(ret, TCSR, OSB,
+                            FIELD_EX8(tmr->tcsr[ch], TCSR, OSB));
+            switch (ch) {
+            case 0:
+                ret = FIELD_DP8(ret, TCSR, ADTE,
+                                FIELD_EX8(tmr->tcsr[ch], TCSR, ADTE));
+                break;
+            case 1: /* CH1 ADTE unimplement always 1 */
+                ret = FIELD_DP8(ret, TCSR, ADTE, 1);
+                break;
+            }
+            return ret;
+        case A_TCORA:
             return tmr->tcora[ch];
-        } else if (ch == 0) {
-            return concat_reg(tmr->tcora);
-        }
-    case A_TCORB:
-        if (size == 1) {
+        case A_TCORB:
             return tmr->tcorb[ch];
-        } else {
-            return concat_reg(tmr->tcorb);
-        }
-    case A_TCNT:
-        return read_tcnt(tmr, size, ch);
-    case A_TCCR:
-        if (size == 1) {
+        case A_TCNT:
+            return read_tcnt(tmr, size, ch);
+        case A_TCCR:
             return read_tccr(tmr->tccr[ch]);
-        } else {
-            return read_tccr(tmr->tccr[0]) << 8 | read_tccr(tmr->tccr[1]);
+        default:
+            qemu_log_mask(LOG_UNIMP, "renesas_tmr: Register 0x%" HWADDR_PRIX
+                          " not implemented\n",
+                          addr);
+            break;
+        }
+    case 2:
+        switch (addr) {
+        case A_TCORA:
+            return concat_reg(tmr->tcora);
+        case A_TCORB:
+            return concat_reg(tmr->tcora);
+        case A_TCNT:
+            return read_tcnt(tmr, size, ch);
+        case A_TCCR:
+            return read_tccr(tmr->tccr[ch]) << 8 | read_tccr(tmr->tccr[1]);
+        default:
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "renesas_tmr: Register 0x%" HWADDR_PRIX
+                          " invalid access size\n",
+                          addr);
+            break;
         }
-    default:
-        qemu_log_mask(LOG_UNIMP, "renesas_tmr: Register 0x%" HWADDR_PRIX
-                                 " not implemented\n",
-                      addr);
-        break;
     }
     return UINT64_MAX;
 }
-- 
2.20.1



             reply	other threads:[~2020-07-11 15:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-11 15:42 Yoshinori Sato [this message]
2020-10-28 20:57 ` [PATCH] hw/timer/renesas_tmr.c cleanup read operation Thomas Huth

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=20200711154242.41222-1-ysato@users.sourceforge.jp \
    --to=ysato@users.sourceforge.jp \
    --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.