mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zong Li <zongbox@gmail.com>
To: tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com,
	palmer@sifive.com, albert@sifive.com,
	linux-kernel@vger.kernel.org, patches@groups.riscv.org,
	greentime@andestech.com, zong@andestech.com
Cc: Zong Li <zongbox@gmail.com>
Subject: [PATCH] irqchip/riscv-plic: fix address alignment of the plic enable bits
Date: Tue, 19 Dec 2017 15:44:38 +0800	[thread overview]
Message-ID: <1513669478-32438-1-git-send-email-zongbox@gmail.com> (raw)

When the interrupt sourece id > 31, the register address is not 4 byte
alignment. Arithmetic on void pointer has no size extension, it just
add the result of 'hwirq/32' directly.

Signed-off-by: Zong Li <zongbox@gmail.com>
---
 drivers/irqchip/irq-riscv-plic.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/irqchip/irq-riscv-plic.c b/drivers/irqchip/irq-riscv-plic.c
index b5182b4..0a43763 100644
--- a/drivers/irqchip/irq-riscv-plic.c
+++ b/drivers/irqchip/irq-riscv-plic.c
@@ -92,6 +92,8 @@
  */
 #define ENABLE_BASE		0x2000
 #define ENABLE_PER_HART		0x80
+#define ENABLE_SOURCES		32
+#define ENABLE_SOURCES_OFFSET	4
 
 /*
  * Each hart context has a set of control registers associated with it.  Right
@@ -128,9 +130,10 @@ struct plic_data {
 
 /* Addressing helper functions. */
 static inline
-void __iomem *plic_enable_vector(struct plic_data *data, int contextid)
+void __iomem *plic_enable_vector(struct plic_data *data, int contextid, int hwirq)
 {
-	return data->reg + ENABLE_BASE + contextid * ENABLE_PER_HART;
+	return data->reg + ENABLE_BASE + contextid * ENABLE_PER_HART +
+		(hwirq / ENABLE_SOURCES) * ENABLE_SOURCES_OFFSET;
 }
 
 static inline
@@ -172,8 +175,8 @@ void plic_complete(struct plic_data *data, int contextid, u32 claim)
 /* Explicit interrupt masking. */
 static void plic_disable(struct plic_data *data, int contextid, int hwirq)
 {
-	void __iomem *reg = plic_enable_vector(data, contextid) + (hwirq / 32);
-	u32 mask = ~(1 << (hwirq % 32));
+	void __iomem *reg = plic_enable_vector(data, contextid, hwirq);
+	u32 mask = ~(1 << (hwirq % ENABLE_SOURCES));
 
 	spin_lock(&data->lock);
 	writel(readl(reg) & mask, reg);
@@ -182,8 +185,8 @@ static void plic_disable(struct plic_data *data, int contextid, int hwirq)
 
 static void plic_enable(struct plic_data *data, int contextid, int hwirq)
 {
-	void __iomem *reg = plic_enable_vector(data, contextid) + (hwirq / 32);
-	u32 bit = 1 << (hwirq % 32);
+	void __iomem *reg = plic_enable_vector(data, contextid, hwirq);
+	u32 bit = 1 << (hwirq % ENABLE_SOURCES);
 
 	spin_lock(&data->lock);
 	writel(readl(reg) | bit, reg);
-- 
2.7.4

             reply	other threads:[~2017-12-19  8:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-19  7:44 Zong Li [this message]
2017-12-21 18:50 ` [patches] " Palmer Dabbelt

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=1513669478-32438-1-git-send-email-zongbox@gmail.com \
    --to=zongbox@gmail.com \
    --cc=albert@sifive.com \
    --cc=greentime@andestech.com \
    --cc=jason@lakedaemon.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=palmer@sifive.com \
    --cc=patches@groups.riscv.org \
    --cc=tglx@linutronix.de \
    --cc=zong@andestech.com \
    /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

all inboxes | Powered by JetHome®