qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>, qemu-ppc@nongnu.org
Subject: [Qemu-devel] [PATCH 53/64] openpic: Unfold write_IRQreg
Date: Thu,  6 Oct 2011 10:05:55 +0200	[thread overview]
Message-ID: <1317888366-10509-54-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1317888366-10509-1-git-send-email-agraf@suse.de>

The helper function write_IRQreg was always called with a specific argument on
the type of register to access. Inside the function we were simply doing a
switch on that constant argument again. It's a lot easier to just unfold this
into two separate functions and call each individually.

Reported-by: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/openpic.c |   79 +++++++++++++++++++++++++++------------------------------
 1 files changed, 37 insertions(+), 42 deletions(-)

diff --git a/hw/openpic.c b/hw/openpic.c
index fbd8837..43b8f27 100644
--- a/hw/openpic.c
+++ b/hw/openpic.c
@@ -482,30 +482,25 @@ static inline uint32_t read_IRQreg_ipvp(openpic_t *opp, int n_IRQ)
     return opp->src[n_IRQ].ipvp;
 }
 
-static inline void write_IRQreg (openpic_t *opp, int n_IRQ,
-                                 uint32_t reg, uint32_t val)
+static inline void write_IRQreg_ide(openpic_t *opp, int n_IRQ, uint32_t val)
 {
     uint32_t tmp;
 
-    switch (reg) {
-    case IRQ_IPVP:
-        /* NOTE: not fully accurate for special IRQs, but simple and
-           sufficient */
-        /* ACTIVITY bit is read-only */
-        opp->src[n_IRQ].ipvp =
-            (opp->src[n_IRQ].ipvp & 0x40000000) |
-            (val & 0x800F00FF);
-        openpic_update_irq(opp, n_IRQ);
-        DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n",
-                n_IRQ, val, opp->src[n_IRQ].ipvp);
-        break;
-    case IRQ_IDE:
-        tmp = val & 0xC0000000;
-        tmp |= val & ((1ULL << MAX_CPU) - 1);
-        opp->src[n_IRQ].ide = tmp;
-        DPRINTF("Set IDE %d to 0x%08x\n", n_IRQ, opp->src[n_IRQ].ide);
-        break;
-    }
+    tmp = val & 0xC0000000;
+    tmp |= val & ((1ULL << MAX_CPU) - 1);
+    opp->src[n_IRQ].ide = tmp;
+    DPRINTF("Set IDE %d to 0x%08x\n", n_IRQ, opp->src[n_IRQ].ide);
+}
+
+static inline void write_IRQreg_ipvp(openpic_t *opp, int n_IRQ, uint32_t val)
+{
+    /* NOTE: not fully accurate for special IRQs, but simple and sufficient */
+    /* ACTIVITY bit is read-only */
+    opp->src[n_IRQ].ipvp = (opp->src[n_IRQ].ipvp & 0x40000000)
+                         | (val & 0x800F00FF);
+    openpic_update_irq(opp, n_IRQ);
+    DPRINTF("Set IPVP %d to 0x%08x -> 0x%08x\n", n_IRQ, val,
+            opp->src[n_IRQ].ipvp);
 }
 
 #if 0 // Code provision for Intel model
@@ -535,10 +530,10 @@ static void write_doorbell_register (penpic_t *opp, int n_dbl,
 {
     switch (offset) {
     case DBL_IVPR_OFFSET:
-        write_IRQreg(opp, IRQ_DBL0 + n_dbl, IRQ_IPVP, value);
+        write_IRQreg_ipvp(opp, IRQ_DBL0 + n_dbl, value);
         break;
     case DBL_IDE_OFFSET:
-        write_IRQreg(opp, IRQ_DBL0 + n_dbl, IRQ_IDE, value);
+        write_IRQreg_ide(opp, IRQ_DBL0 + n_dbl, value);
         break;
     case DBL_DMR_OFFSET:
         opp->doorbells[n_dbl].dmr = value;
@@ -576,10 +571,10 @@ static void write_mailbox_register (openpic_t *opp, int n_mbx,
         opp->mailboxes[n_mbx].mbr = value;
         break;
     case MBX_IVPR_OFFSET:
-        write_IRQreg(opp, IRQ_MBX0 + n_mbx, IRQ_IPVP, value);
+        write_IRQreg_ipvp(opp, IRQ_MBX0 + n_mbx, value);
         break;
     case MBX_DMR_OFFSET:
-        write_IRQreg(opp, IRQ_MBX0 + n_mbx, IRQ_IDE, value);
+        write_IRQreg_ide(opp, IRQ_MBX0 + n_mbx, value);
         break;
     }
 }
@@ -636,7 +631,7 @@ static void openpic_gbl_write (void *opaque, target_phys_addr_t addr, uint32_t v
         {
             int idx;
             idx = (addr - 0x10A0) >> 4;
-            write_IRQreg(opp, opp->irq_ipi0 + idx, IRQ_IPVP, val);
+            write_IRQreg_ipvp(opp, opp->irq_ipi0 + idx, val);
         }
         break;
     case 0x10E0: /* SPVE */
@@ -729,10 +724,10 @@ static void openpic_timer_write (void *opaque, uint32_t addr, uint32_t val)
         opp->timers[idx].tibc = val;
         break;
     case 0x20: /* TIVP */
-        write_IRQreg(opp, opp->irq_tim0 + idx, IRQ_IPVP, val);
+        write_IRQreg_ipvp(opp, opp->irq_tim0 + idx, val);
         break;
     case 0x30: /* TIDE */
-        write_IRQreg(opp, opp->irq_tim0 + idx, IRQ_IDE, val);
+        write_IRQreg_ide(opp, opp->irq_tim0 + idx, val);
         break;
     }
 }
@@ -782,10 +777,10 @@ static void openpic_src_write (void *opaque, uint32_t addr, uint32_t val)
     idx = addr >> 5;
     if (addr & 0x10) {
         /* EXDE / IFEDE / IEEDE */
-        write_IRQreg(opp, idx, IRQ_IDE, val);
+        write_IRQreg_ide(opp, idx, val);
     } else {
         /* EXVP / IFEVP / IEEVP */
-        write_IRQreg(opp, idx, IRQ_IPVP, val);
+        write_IRQreg_ipvp(opp, idx, val);
     }
 }
 
@@ -835,8 +830,8 @@ static void openpic_cpu_write_internal(void *opaque, target_phys_addr_t addr,
     case 0x70:
         idx = (addr - 0x40) >> 4;
         /* we use IDE as mask which CPUs to deliver the IPI to still. */
-        write_IRQreg(opp, opp->irq_ipi0 + idx, IRQ_IDE,
-                     opp->src[opp->irq_ipi0 + idx].ide | val);
+        write_IRQreg_ide(opp, opp->irq_ipi0 + idx,
+                         opp->src[opp->irq_ipi0 + idx].ide | val);
         openpic_set_irq(opp, opp->irq_ipi0 + idx, 1);
         openpic_set_irq(opp, opp->irq_ipi0 + idx, 0);
         break;
@@ -1330,13 +1325,13 @@ static void mpic_timer_write (void *opaque, target_phys_addr_t addr, uint32_t va
         mpp->timers[idx].tibc = val;
         break;
     case 0x20: /* GTIVPR */
-        write_IRQreg(mpp, MPIC_TMR_IRQ + idx, IRQ_IPVP, val);
+        write_IRQreg_ipvp(mpp, MPIC_TMR_IRQ + idx, val);
         break;
     case 0x30: /* GTIDR & TFRR */
         if ((addr & 0xF0) == 0xF0)
             mpp->dst[cpu].tfrr = val;
         else
-            write_IRQreg(mpp, MPIC_TMR_IRQ + idx, IRQ_IDE, val);
+            write_IRQreg_ide(mpp, MPIC_TMR_IRQ + idx, val);
         break;
     }
 }
@@ -1391,10 +1386,10 @@ static void mpic_src_ext_write (void *opaque, target_phys_addr_t addr,
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
             /* EXDE / IFEDE / IEEDE */
-            write_IRQreg(mpp, idx, IRQ_IDE, val);
+            write_IRQreg_ide(mpp, idx, val);
         } else {
             /* EXVP / IFEVP / IEEVP */
-            write_IRQreg(mpp, idx, IRQ_IPVP, val);
+            write_IRQreg_ipvp(mpp, idx, val);
         }
     }
 }
@@ -1441,10 +1436,10 @@ static void mpic_src_int_write (void *opaque, target_phys_addr_t addr,
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
             /* EXDE / IFEDE / IEEDE */
-            write_IRQreg(mpp, idx, IRQ_IDE, val);
+            write_IRQreg_ide(mpp, idx, val);
         } else {
             /* EXVP / IFEVP / IEEVP */
-            write_IRQreg(mpp, idx, IRQ_IPVP, val);
+            write_IRQreg_ipvp(mpp, idx, val);
         }
     }
 }
@@ -1491,10 +1486,10 @@ static void mpic_src_msg_write (void *opaque, target_phys_addr_t addr,
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
             /* EXDE / IFEDE / IEEDE */
-            write_IRQreg(mpp, idx, IRQ_IDE, val);
+            write_IRQreg_ide(mpp, idx, val);
         } else {
             /* EXVP / IFEVP / IEEVP */
-            write_IRQreg(mpp, idx, IRQ_IPVP, val);
+            write_IRQreg_ipvp(mpp, idx, val);
         }
     }
 }
@@ -1541,10 +1536,10 @@ static void mpic_src_msi_write (void *opaque, target_phys_addr_t addr,
         idx += (addr & 0xFFF0) >> 5;
         if (addr & 0x10) {
             /* EXDE / IFEDE / IEEDE */
-            write_IRQreg(mpp, idx, IRQ_IDE, val);
+            write_IRQreg_ide(mpp, idx, val);
         } else {
             /* EXVP / IFEVP / IEEVP */
-            write_IRQreg(mpp, idx, IRQ_IPVP, val);
+            write_IRQreg_ipvp(mpp, idx, val);
         }
     }
 }
-- 
1.6.0.2

  parent reply	other threads:[~2011-10-06  8:06 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-06  8:05 [Qemu-devel] [PULL 00/64] ppc patch queue 2011-10-06 Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 01/64] spapr: proper qdevification Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 02/64] spapr: prepare for qdevification of irq Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 03/64] spapr: make irq customizable via qdev Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 04/64] PPC: Move openpic to target specific code compilation Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 05/64] PPC: Add CPU local MMIO regions to MPIC Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 06/64] PPC: Extend MPIC MMIO range Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 07/64] PPC: Fix IPI support in MPIC Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 08/64] PPC: Set MPIC IDE for IPI to 0 Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 09/64] PPC: MPIC: Remove read functionality for WO registers Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 10/64] PPC: MPIC: Fix CI bit definitions Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 11/64] PPC: Bump MPIC up to 32 supported CPUs Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 12/64] PPC: E500: create multiple envs Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 13/64] PPC: E500: Generate IRQ lines for many CPUs Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 14/64] device tree: add nop_node Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 15/64] PPC: bamboo: Move host fdt copy to target Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 16/64] PPC: KVM: Add generic function to read host clockfreq Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 17/64] PPC: E500: Use generic kvm function for freq Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 18/64] PPC: E500: Remove mpc8544_copy_soc_cell Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 19/64] PPC: bamboo: Use kvm api for freq and clock frequencies Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 20/64] PPC: KVM: Remove kvmppc_read_host_property Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 21/64] PPC: KVM: Add stubs for kvm helper functions Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 22/64] PPC: E500: Update freqs for all CPUs Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 23/64] PPC: E500: Remove unneeded CPU nodes Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 24/64] PPC: E500: Add PV spinning code Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 25/64] PPC: E500: Update cpu-release-addr property in cpu nodes Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 26/64] device tree: add add_subnode command Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 27/64] device tree: dont fail operations Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 28/64] device tree: give dt more size Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 29/64] MPC8544DS: Remove CPU nodes Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 30/64] MPC8544DS: Generate CPU nodes on init Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 31/64] PPC: E500: Bump CPU count to 15 Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 32/64] PPC: Add new target config for pseries Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 33/64] KVM: update kernel headers Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 34/64] PPC: Enable to use PAPR with PR style KVM Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 35/64] PPC: SPAPR: Use KVM function for time info Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 36/64] pseries: Bugfixes for interrupt numbering in XICS code Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 37/64] pseries: Add a phandle to the xicp interrupt controller device tree node Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 38/64] pseries: interrupt controller should not have a 'reg' property Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 39/64] pseries: More complete WIMG validation in H_ENTER code Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 40/64] PPC: Fix sync instructions problem in SMP Alexander Graf
2011-10-06  8:24   ` Elie Richa
2011-10-06  8:05 ` [Qemu-devel] [PATCH 41/64] pseries: Add real mode debugging hcalls Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 42/64] pseries: use macro for firmware filename Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 43/64] KVM: Update kernel headers Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 44/64] kvm: ppc: booke206: use MMU API Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 45/64] ppc: booke206: add "info tlb" support Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 46/64] ppc: booke206: use MAV=2.0 TSIZE definition, fix 4G pages Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 47/64] Implement POWER7's CFAR in TCG Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 48/64] pseries: Implement hcall-bulk hypervisor interface Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 49/64] vscsi: send the CHECK_CONDITION status down together with autosense data Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 50/64] Gdbstub: handle read of fpscr Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 51/64] ppc405: use RAM_ADDR_FMT instead of %08lx Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 52/64] openpic: Unfold read_IRQreg Alexander Graf
2011-10-06  8:05 ` Alexander Graf [this message]
2011-10-06  8:05 ` [Qemu-devel] [PATCH 54/64] ppc: move ADB stuff from ppc_mac.h to adb.h Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 55/64] PPC: Fix via-cuda memory registration Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 56/64] PPC: Fix heathrow PIC to use little endian MMIO Alexander Graf
2011-10-06  8:05 ` [Qemu-devel] [PATCH 57/64] KVM: Update kernel headers Alexander Graf
2011-10-06  8:06 ` [Qemu-devel] [PATCH 58/64] " Alexander Graf
2011-10-06  8:06 ` [Qemu-devel] [PATCH 59/64] KVM: PPC: Use HIOR setting for -M pseries with PR KVM Alexander Graf
2011-10-06  8:06 ` [Qemu-devel] [PATCH 60/64] PPC: booke timers Alexander Graf
2011-10-06  8:06 ` [Qemu-devel] [PATCH 61/64] PPC: Clean up BookE timer code Alexander Graf
2011-10-06  8:06 ` [Qemu-devel] [PATCH 62/64] pseries: Refactor spapr irq allocation Alexander Graf
2011-10-06  8:06 ` [Qemu-devel] [PATCH 63/64] pseries: Implement set-time-of-day RTAS function Alexander Graf
2011-10-06  8:06 ` [Qemu-devel] [PATCH 64/64] ppc64: Fix linker script Alexander Graf
2011-10-08 10:17 ` [Qemu-devel] [PULL 00/64] ppc patch queue 2011-10-06 Blue Swirl

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=1317888366-10509-54-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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 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).