public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] irqchip/mbigen: Fix mbigen node address layout
@ 2024-07-20  1:35 Yipeng Zou
  2024-07-29 10:15 ` Thomas Gleixner
  0 siblings, 1 reply; 3+ messages in thread
From: Yipeng Zou @ 2024-07-20  1:35 UTC (permalink / raw)
  To: tglx, maz, majun258, guohanjun, wangwudi, liaochang1,
	linux-kernel
  Cc: zouyipeng

Mbigen chip contains several mbigen nodes, and mapped address space per
nodes one by one.

                    mbigen chip
       |-----------------|------------|--------------|
   mgn_node_0         mgn_node_1     ...         mgn_node_i
|--------------|   |--------------|       |----------------------|
[0x0000, 0x1000)   [0x1000, 0x2000)       [i*0x1000, (i+1)*0x1000)

Mbigen also defined a clear register with all other mbigen nodes in
uniform address space.

                         mbigen chip
    |-----------|--------|--------|---------------|--------|
mgn_node_0  mgn_node_1  ...  mgn_clear_register  ...   mgn_node_i
                            |-----------------|
                             [0xA000, 0xB000)

Everything is OK for now, when the mbigen nodes number less than 10,
there is no conflict with clear register.

Once we defined mbigen node more than 10, it's going to touch clear
register in unexpected way.

There should have a gap of 0x1000 between mgn_node9 and mgn_node10.

The simplest solution is directly skip clear register when access to
more than 10 mbigen nodes.

Fixes: a6c2f87b8820 ("irqchip/mbigen: Implement the mbigen irq chip operation functions")
Signed-off-by: Yipeng Zou <zouyipeng@huawei.com>
---
 drivers/irqchip/irq-mbigen.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/irqchip/irq-mbigen.c b/drivers/irqchip/irq-mbigen.c
index 58881d313979..b600637f5cd7 100644
--- a/drivers/irqchip/irq-mbigen.c
+++ b/drivers/irqchip/irq-mbigen.c
@@ -64,6 +64,20 @@ struct mbigen_device {
 	void __iomem		*base;
 };
 
+static inline unsigned int get_mbigen_node_offset(unsigned int nid)
+{
+	unsigned int offset = nid * MBIGEN_NODE_OFFSET;
+
+	/**
+	 * To avoid touched clear register in unexpected way, we need to directly
+	 * skip clear register when access to more than 10 mbigen nodes.
+	 */
+	if (nid >= (REG_MBIGEN_CLEAR_OFFSET / MBIGEN_NODE_OFFSET))
+		offset += MBIGEN_NODE_OFFSET;
+
+	return offset;
+}
+
 static inline unsigned int get_mbigen_vec_reg(irq_hw_number_t hwirq)
 {
 	unsigned int nid, pin;
@@ -72,7 +86,7 @@ static inline unsigned int get_mbigen_vec_reg(irq_hw_number_t hwirq)
 	nid = hwirq / IRQS_PER_MBIGEN_NODE + 1;
 	pin = hwirq % IRQS_PER_MBIGEN_NODE;
 
-	return pin * 4 + nid * MBIGEN_NODE_OFFSET
+	return pin * 4 + get_mbigen_node_offset(nid)
 			+ REG_MBIGEN_VEC_OFFSET;
 }
 
@@ -88,7 +102,7 @@ static inline void get_mbigen_type_reg(irq_hw_number_t hwirq,
 	*mask = 1 << (irq_ofst % 32);
 	ofst = irq_ofst / 32 * 4;
 
-	*addr = ofst + nid * MBIGEN_NODE_OFFSET
+	*addr = ofst + get_mbigen_node_offset(nid)
 		+ REG_MBIGEN_TYPE_OFFSET;
 }
 
-- 
2.34.1


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

end of thread, other threads:[~2024-07-30  1:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-20  1:35 [PATCH] irqchip/mbigen: Fix mbigen node address layout Yipeng Zou
2024-07-29 10:15 ` Thomas Gleixner
2024-07-30  1:43   ` Yipeng Zou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox