linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/7] Store the base address in dcr_host_t
@ 2007-09-17  6:05 Michael Ellerman
  2007-09-17  6:05 ` [PATCH 2/7] Update mpic to use dcr_host_t.base Michael Ellerman
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Michael Ellerman @ 2007-09-17  6:05 UTC (permalink / raw)
  To: linuxppc-dev

In its current form, dcr_map() doesn't remember the base address you passed
it, which means you need to store it somewhere else. Rather than adding the
base to another struct it seems simpler to store it in the dcr_host_t.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/sysdev/dcr.c        |    2 +-
 include/asm-powerpc/dcr-mmio.h   |    6 +++++-
 include/asm-powerpc/dcr-native.h |    6 ++++--
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/sysdev/dcr.c b/arch/powerpc/sysdev/dcr.c
index e82d54d..ab11c0b 100644
--- a/arch/powerpc/sysdev/dcr.c
+++ b/arch/powerpc/sysdev/dcr.c
@@ -104,7 +104,7 @@ u64 of_translate_dcr_address(struct device_node *dev,
 dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n,
 		   unsigned int dcr_c)
 {
-	dcr_host_t ret = { .token = NULL, .stride = 0 };
+	dcr_host_t ret = { .token = NULL, .stride = 0, .base = dcr_n };
 	u64 addr;
 
 	pr_debug("dcr_map(%s, 0x%x, 0x%x)\n",
diff --git a/include/asm-powerpc/dcr-mmio.h b/include/asm-powerpc/dcr-mmio.h
index 5dbfca8..6b82c3b 100644
--- a/include/asm-powerpc/dcr-mmio.h
+++ b/include/asm-powerpc/dcr-mmio.h
@@ -23,7 +23,11 @@
 
 #include <asm/io.h>
 
-typedef struct { void __iomem *token; unsigned int stride; } dcr_host_t;
+typedef struct {
+	void __iomem *token;
+	unsigned int stride;
+	unsigned int base;
+} dcr_host_t;
 
 #define DCR_MAP_OK(host)	((host).token != NULL)
 
diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h
index 05af081..f41058c 100644
--- a/include/asm-powerpc/dcr-native.h
+++ b/include/asm-powerpc/dcr-native.h
@@ -22,11 +22,13 @@
 #ifdef __KERNEL__
 #ifndef __ASSEMBLY__
 
-typedef struct {} dcr_host_t;
+typedef struct {
+	unsigned int base;
+} dcr_host_t;
 
 #define DCR_MAP_OK(host)	(1)
 
-#define dcr_map(dev, dcr_n, dcr_c)	((dcr_host_t){})
+#define dcr_map(dev, dcr_n, dcr_c)	((dcr_host_t){ .base = (dcr_n) })
 #define dcr_unmap(host, dcr_n, dcr_c)	do {} while (0)
 #define dcr_read(host, dcr_n)		mfdcr(dcr_n)
 #define dcr_write(host, dcr_n, value)	mtdcr(dcr_n, value)
-- 
1.5.1.3.g7a33b

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

* [PATCH 2/7] Update mpic to use dcr_host_t.base
  2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
@ 2007-09-17  6:05 ` Michael Ellerman
  2007-10-02  5:12   ` Benjamin Herrenschmidt
  2007-09-17  6:05 ` [PATCH 3/7] Use dcr_host_t.base in ibm_emac_mal Michael Ellerman
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Michael Ellerman @ 2007-09-17  6:05 UTC (permalink / raw)
  To: linuxppc-dev

Now that dcr_host_t contains the base address, we can use that in the mpic
code, rather than storing it separately.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/sysdev/mpic.c |   28 +++++++++++-----------------
 include/asm-powerpc/mpic.h |    6 ------
 2 files changed, 11 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 8de29f2..16b1f4b 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -156,8 +156,7 @@ static inline u32 _mpic_read(enum mpic_reg_type type,
 	switch(type) {
 #ifdef CONFIG_PPC_DCR
 	case mpic_access_dcr:
-		return dcr_read(rb->dhost,
-				rb->dbase + reg + rb->doff);
+		return dcr_read(rb->dhost, rb->dhost.base + reg);
 #endif
 	case mpic_access_mmio_be:
 		return in_be32(rb->base + (reg >> 2));
@@ -174,8 +173,7 @@ static inline void _mpic_write(enum mpic_reg_type type,
 	switch(type) {
 #ifdef CONFIG_PPC_DCR
 	case mpic_access_dcr:
-		return dcr_write(rb->dhost,
-				 rb->dbase + reg + rb->doff, value);
+		return dcr_write(rb->dhost, rb->dhost.base + reg, value);
 #endif
 	case mpic_access_mmio_be:
 		return out_be32(rb->base + (reg >> 2), value);
@@ -279,9 +277,11 @@ static void _mpic_map_mmio(struct mpic *mpic, unsigned long phys_addr,
 static void _mpic_map_dcr(struct mpic *mpic, struct mpic_reg_bank *rb,
 			  unsigned int offset, unsigned int size)
 {
-	rb->dbase = mpic->dcr_base;
-	rb->doff = offset;
-	rb->dhost = dcr_map(mpic->irqhost->of_node, rb->dbase + rb->doff, size);
+	const u32 *dbasep;
+
+	dbasep = of_get_property(mpic->irqhost->of_node, "dcr-reg", NULL);
+
+	rb->dhost = dcr_map(mpic->irqhost->of_node, *dbasep + offset, size);
 	BUG_ON(!DCR_MAP_OK(rb->dhost));
 }
 
@@ -1075,20 +1075,14 @@ struct mpic * __init mpic_alloc(struct device_node *node,
 	BUG_ON(paddr == 0 && node == NULL);
 
 	/* If no physical address passed in, check if it's dcr based */
-	if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL)
-		mpic->flags |= MPIC_USES_DCR;
-
+	if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL) {
 #ifdef CONFIG_PPC_DCR
-	if (mpic->flags & MPIC_USES_DCR) {
-		const u32 *dbasep;
-		dbasep = of_get_property(node, "dcr-reg", NULL);
-		BUG_ON(dbasep == NULL);
-		mpic->dcr_base = *dbasep;
+		mpic->flags |= MPIC_USES_DCR;
 		mpic->reg_type = mpic_access_dcr;
-	}
 #else
-	BUG_ON (mpic->flags & MPIC_USES_DCR);
+		BUG();
 #endif /* CONFIG_PPC_DCR */
+	}
 
 	/* If the MPIC is not DCR based, and no physical address was passed
 	 * in, try to obtain one
diff --git a/include/asm-powerpc/mpic.h b/include/asm-powerpc/mpic.h
index edb4a7c..ae84dde 100644
--- a/include/asm-powerpc/mpic.h
+++ b/include/asm-powerpc/mpic.h
@@ -224,8 +224,6 @@ struct mpic_reg_bank {
 	u32 __iomem	*base;
 #ifdef CONFIG_PPC_DCR
 	dcr_host_t	dhost;
-	unsigned int	dbase;
-	unsigned int	doff;
 #endif /* CONFIG_PPC_DCR */
 };
 
@@ -289,10 +287,6 @@ struct mpic
 	struct mpic_reg_bank	cpuregs[MPIC_MAX_CPUS];
 	struct mpic_reg_bank	isus[MPIC_MAX_ISU];
 
-#ifdef CONFIG_PPC_DCR
-	unsigned int		dcr_base;
-#endif
-
 	/* Protected sources */
 	unsigned long		*protected;
 
-- 
1.5.1.3.g7a33b

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

* [PATCH 3/7] Use dcr_host_t.base in ibm_emac_mal
  2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
  2007-09-17  6:05 ` [PATCH 2/7] Update mpic to use dcr_host_t.base Michael Ellerman
@ 2007-09-17  6:05 ` Michael Ellerman
  2007-10-02  5:13   ` Benjamin Herrenschmidt
  2007-09-17  6:05 ` [PATCH 4/7] Update axon_msi to use dcr_host_t.base Michael Ellerman
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Michael Ellerman @ 2007-09-17  6:05 UTC (permalink / raw)
  To: linuxppc-dev

This requires us to do a sort-of fake dcr_map(), so that base is set
properly. This will be fixed/removed when the device-tree-aware emac driver
is merged.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 drivers/net/ibm_emac/ibm_emac_mal.c |    5 ++++-
 drivers/net/ibm_emac/ibm_emac_mal.h |    5 ++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ibm_emac/ibm_emac_mal.c b/drivers/net/ibm_emac/ibm_emac_mal.c
index cabd984..b08da96 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.c
+++ b/drivers/net/ibm_emac/ibm_emac_mal.c
@@ -421,7 +421,10 @@ static int __init mal_probe(struct ocp_device *ocpdev)
 		       ocpdev->def->index);
 		return -ENOMEM;
 	}
-	mal->dcrbase = maldata->dcr_base;
+
+	/* XXX This only works for native dcr for now */
+	mal->dcrhost = dcr_map(NULL, maldata->dcr_base, 0);
+
 	mal->def = ocpdev->def;
 
 	INIT_LIST_HEAD(&mal->poll_list);
diff --git a/drivers/net/ibm_emac/ibm_emac_mal.h b/drivers/net/ibm_emac/ibm_emac_mal.h
index 64bc338..6b1fbeb 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.h
+++ b/drivers/net/ibm_emac/ibm_emac_mal.h
@@ -191,7 +191,6 @@ struct mal_commac {
 };
 
 struct ibm_ocp_mal {
-	int			dcrbase;
 	dcr_host_t		dcrhost;
 
 	struct list_head	poll_list;
@@ -209,12 +208,12 @@ struct ibm_ocp_mal {
 
 static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg)
 {
-	return dcr_read(mal->dcrhost, mal->dcrbase + reg);
+	return dcr_read(mal->dcrhost, mal->dcrhost.base + reg);
 }
 
 static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val)
 {
-	dcr_write(mal->dcrhost, mal->dcrbase + reg, val);
+	dcr_write(mal->dcrhost, mal->dcrhost.base + reg, val);
 }
 
 /* Register MAL devices */
-- 
1.5.1.3.g7a33b

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

* [PATCH 4/7] Update axon_msi to use dcr_host_t.base
  2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
  2007-09-17  6:05 ` [PATCH 2/7] Update mpic to use dcr_host_t.base Michael Ellerman
  2007-09-17  6:05 ` [PATCH 3/7] Use dcr_host_t.base in ibm_emac_mal Michael Ellerman
@ 2007-09-17  6:05 ` Michael Ellerman
  2007-10-02  5:14   ` Benjamin Herrenschmidt
  2007-09-17  6:05 ` [PATCH 5/7] Add dcr_host_t.base in dcr_read()/dcr_write() Michael Ellerman
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Michael Ellerman @ 2007-09-17  6:05 UTC (permalink / raw)
  To: linuxppc-dev

Now that dcr_host_t contains the base address, we can use that in the
axon_msi code, rather than storing it separately.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/platforms/cell/axon_msi.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
index 74407af..23e039a 100644
--- a/arch/powerpc/platforms/cell/axon_msi.c
+++ b/arch/powerpc/platforms/cell/axon_msi.c
@@ -69,7 +69,6 @@ struct axon_msic {
 	dcr_host_t dcr_host;
 	struct list_head list;
 	u32 read_offset;
-	u32 dcr_base;
 };
 
 static LIST_HEAD(axon_msic_list);
@@ -78,12 +77,12 @@ static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
 {
 	pr_debug("axon_msi: dcr_write(0x%x, 0x%x)\n", val, dcr_n);
 
-	dcr_write(msic->dcr_host, msic->dcr_base + dcr_n, val);
+	dcr_write(msic->dcr_host, msic->dcr_host.base + dcr_n, val);
 }
 
 static u32 msic_dcr_read(struct axon_msic *msic, unsigned int dcr_n)
 {
-	return dcr_read(msic->dcr_host, msic->dcr_base + dcr_n);
+	return dcr_read(msic->dcr_host, msic->dcr_host.base + dcr_n);
 }
 
 static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
@@ -324,7 +323,7 @@ static int axon_msi_setup_one(struct device_node *dn)
 	struct page *page;
 	struct axon_msic *msic;
 	unsigned int virq;
-	int dcr_len;
+	int dcr_base, dcr_len;
 
 	pr_debug("axon_msi: setting up dn %s\n", dn->full_name);
 
@@ -335,17 +334,17 @@ static int axon_msi_setup_one(struct device_node *dn)
 		goto out;
 	}
 
-	msic->dcr_base = dcr_resource_start(dn, 0);
+	dcr_base = dcr_resource_start(dn, 0);
 	dcr_len = dcr_resource_len(dn, 0);
 
-	if (msic->dcr_base == 0 || dcr_len == 0) {
+	if (dcr_base == 0 || dcr_len == 0) {
 		printk(KERN_ERR
 		       "axon_msi: couldn't parse dcr properties on %s\n",
 			dn->full_name);
 		goto out;
 	}
 
-	msic->dcr_host = dcr_map(dn, msic->dcr_base, dcr_len);
+	msic->dcr_host = dcr_map(dn, dcr_base, dcr_len);
 	if (!DCR_MAP_OK(msic->dcr_host)) {
 		printk(KERN_ERR "axon_msi: dcr_map failed for %s\n",
 		       dn->full_name);
-- 
1.5.1.3.g7a33b

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

* [PATCH 5/7] Add dcr_host_t.base in dcr_read()/dcr_write()
  2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
                   ` (2 preceding siblings ...)
  2007-09-17  6:05 ` [PATCH 4/7] Update axon_msi to use dcr_host_t.base Michael Ellerman
@ 2007-09-17  6:05 ` Michael Ellerman
  2007-10-02  5:17   ` Benjamin Herrenschmidt
  2007-09-17  6:05 ` [PATCH 6/7] Add dcr_map_reg() helper Michael Ellerman
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Michael Ellerman @ 2007-09-17  6:05 UTC (permalink / raw)
  To: linuxppc-dev

Now that all users of dcr_read()/dcr_write() add the dcr_host_t.base, we can
save them the trouble and do it in dcr_read()/dcr_write().

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/platforms/cell/axon_msi.c |    4 ++--
 arch/powerpc/sysdev/mpic.c             |    4 ++--
 drivers/net/ibm_emac/ibm_emac_mal.h    |    4 ++--
 include/asm-powerpc/dcr-mmio.h         |    4 ++--
 include/asm-powerpc/dcr-native.h       |    4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
index 23e039a..26a5e88 100644
--- a/arch/powerpc/platforms/cell/axon_msi.c
+++ b/arch/powerpc/platforms/cell/axon_msi.c
@@ -77,12 +77,12 @@ static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
 {
 	pr_debug("axon_msi: dcr_write(0x%x, 0x%x)\n", val, dcr_n);
 
-	dcr_write(msic->dcr_host, msic->dcr_host.base + dcr_n, val);
+	dcr_write(msic->dcr_host, dcr_n, val);
 }
 
 static u32 msic_dcr_read(struct axon_msic *msic, unsigned int dcr_n)
 {
-	return dcr_read(msic->dcr_host, msic->dcr_host.base + dcr_n);
+	return dcr_read(msic->dcr_host, dcr_n);
 }
 
 static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index 16b1f4b..61f5730 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -156,7 +156,7 @@ static inline u32 _mpic_read(enum mpic_reg_type type,
 	switch(type) {
 #ifdef CONFIG_PPC_DCR
 	case mpic_access_dcr:
-		return dcr_read(rb->dhost, rb->dhost.base + reg);
+		return dcr_read(rb->dhost, reg);
 #endif
 	case mpic_access_mmio_be:
 		return in_be32(rb->base + (reg >> 2));
@@ -173,7 +173,7 @@ static inline void _mpic_write(enum mpic_reg_type type,
 	switch(type) {
 #ifdef CONFIG_PPC_DCR
 	case mpic_access_dcr:
-		return dcr_write(rb->dhost, rb->dhost.base + reg, value);
+		return dcr_write(rb->dhost, reg, value);
 #endif
 	case mpic_access_mmio_be:
 		return out_be32(rb->base + (reg >> 2), value);
diff --git a/drivers/net/ibm_emac/ibm_emac_mal.h b/drivers/net/ibm_emac/ibm_emac_mal.h
index 6b1fbeb..10dc978 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.h
+++ b/drivers/net/ibm_emac/ibm_emac_mal.h
@@ -208,12 +208,12 @@ struct ibm_ocp_mal {
 
 static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg)
 {
-	return dcr_read(mal->dcrhost, mal->dcrhost.base + reg);
+	return dcr_read(mal->dcrhost, reg);
 }
 
 static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val)
 {
-	dcr_write(mal->dcrhost, mal->dcrhost.base + reg, val);
+	dcr_write(mal->dcrhost, reg, val);
 }
 
 /* Register MAL devices */
diff --git a/include/asm-powerpc/dcr-mmio.h b/include/asm-powerpc/dcr-mmio.h
index 6b82c3b..a7d9eaf 100644
--- a/include/asm-powerpc/dcr-mmio.h
+++ b/include/asm-powerpc/dcr-mmio.h
@@ -37,12 +37,12 @@ extern void dcr_unmap(dcr_host_t host, unsigned int dcr_n, unsigned int dcr_c);
 
 static inline u32 dcr_read(dcr_host_t host, unsigned int dcr_n)
 {
-	return in_be32(host.token + dcr_n * host.stride);
+	return in_be32(host.token + ((host.base + dcr_n) * host.stride));
 }
 
 static inline void dcr_write(dcr_host_t host, unsigned int dcr_n, u32 value)
 {
-	out_be32(host.token + dcr_n * host.stride, value);
+	out_be32(host.token + ((host.base + dcr_n) * host.stride), value);
 }
 
 extern u64 of_translate_dcr_address(struct device_node *dev,
diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h
index f41058c..3bc780f 100644
--- a/include/asm-powerpc/dcr-native.h
+++ b/include/asm-powerpc/dcr-native.h
@@ -30,8 +30,8 @@ typedef struct {
 
 #define dcr_map(dev, dcr_n, dcr_c)	((dcr_host_t){ .base = (dcr_n) })
 #define dcr_unmap(host, dcr_n, dcr_c)	do {} while (0)
-#define dcr_read(host, dcr_n)		mfdcr(dcr_n)
-#define dcr_write(host, dcr_n, value)	mtdcr(dcr_n, value)
+#define dcr_read(host, dcr_n)		mfdcr(dcr_n + host.base)
+#define dcr_write(host, dcr_n, value)	mtdcr(dcr_n + host.base, value)
 
 /* Device Control Registers */
 void __mtdcr(int reg, unsigned int val);
-- 
1.5.1.3.g7a33b

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

* [PATCH 6/7] Add dcr_map_reg() helper
  2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
                   ` (3 preceding siblings ...)
  2007-09-17  6:05 ` [PATCH 5/7] Add dcr_host_t.base in dcr_read()/dcr_write() Michael Ellerman
@ 2007-09-17  6:05 ` Michael Ellerman
  2007-10-02  5:19   ` Benjamin Herrenschmidt
  2007-09-17  6:05 ` [PATCH 7/7] Remove msic_dcr_read() and use dcr_map_reg() in axon_msi.c Michael Ellerman
  2007-10-02  5:10 ` [PATCH 1/7] Store the base address in dcr_host_t Benjamin Herrenschmidt
  6 siblings, 1 reply; 17+ messages in thread
From: Michael Ellerman @ 2007-09-17  6:05 UTC (permalink / raw)
  To: linuxppc-dev

Add a helper routine to map dcr's based on the "dcr-reg" property of
a device node.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/sysdev/dcr.c |   17 +++++++++++++++++
 include/asm-powerpc/dcr.h |    1 +
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/sysdev/dcr.c b/arch/powerpc/sysdev/dcr.c
index ab11c0b..da4f9c6 100644
--- a/arch/powerpc/sysdev/dcr.c
+++ b/arch/powerpc/sysdev/dcr.c
@@ -126,6 +126,23 @@ dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n,
 }
 EXPORT_SYMBOL_GPL(dcr_map);
 
+dcr_host_t dcr_map_reg(struct device_node *dev, unsigned int index)
+{
+	dcr_host_t ret = { .token = NULL };
+
+	unsigned int dcr_n, dcr_c;
+
+	dcr_n = dcr_resource_start(dev, index);
+	if (!dcr_n)
+		return ret;
+
+	dcr_c = dcr_resource_len(dev, index);
+	if (!dcr_c)
+		return ret;
+
+	return dcr_map(dev, dcr_n, dcr_c);
+}
+
 void dcr_unmap(dcr_host_t host, unsigned int dcr_n, unsigned int dcr_c)
 {
 	dcr_host_t h = host;
diff --git a/include/asm-powerpc/dcr.h b/include/asm-powerpc/dcr.h
index 9338d50..4d42f01 100644
--- a/include/asm-powerpc/dcr.h
+++ b/include/asm-powerpc/dcr.h
@@ -38,6 +38,7 @@ extern unsigned int dcr_resource_start(struct device_node *np,
 				       unsigned int index);
 extern unsigned int dcr_resource_len(struct device_node *np,
 				     unsigned int index);
+extern dcr_host_t dcr_map_reg(struct device_node *np, unsigned int index);
 #endif /* CONFIG_PPC_MERGE */
 
 #endif /* CONFIG_PPC_DCR */
-- 
1.5.1.3.g7a33b

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

* [PATCH 7/7] Remove msic_dcr_read() and use dcr_map_reg() in axon_msi.c
  2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
                   ` (4 preceding siblings ...)
  2007-09-17  6:05 ` [PATCH 6/7] Add dcr_map_reg() helper Michael Ellerman
@ 2007-09-17  6:05 ` Michael Ellerman
  2007-10-02  5:20   ` Benjamin Herrenschmidt
  2007-10-02  5:10 ` [PATCH 1/7] Store the base address in dcr_host_t Benjamin Herrenschmidt
  6 siblings, 1 reply; 17+ messages in thread
From: Michael Ellerman @ 2007-09-17  6:05 UTC (permalink / raw)
  To: linuxppc-dev

msic_dcr_read() doesn't really do anything useful, just replace it with
direct calls to dcr_read().

Use dcr_map_reg() in the axon_msi setup code, rather than essentially doing
it by hand.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/platforms/cell/axon_msi.c |   22 +++-------------------
 1 files changed, 3 insertions(+), 19 deletions(-)

diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
index 26a5e88..57a6149 100644
--- a/arch/powerpc/platforms/cell/axon_msi.c
+++ b/arch/powerpc/platforms/cell/axon_msi.c
@@ -80,18 +80,13 @@ static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
 	dcr_write(msic->dcr_host, dcr_n, val);
 }
 
-static u32 msic_dcr_read(struct axon_msic *msic, unsigned int dcr_n)
-{
-	return dcr_read(msic->dcr_host, dcr_n);
-}
-
 static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
 {
 	struct axon_msic *msic = get_irq_data(irq);
 	u32 write_offset, msi;
 	int idx;
 
-	write_offset = msic_dcr_read(msic, MSIC_WRITE_OFFSET_REG);
+	write_offset = dcr_read(msic->dcr_host, MSIC_WRITE_OFFSET_REG);
 	pr_debug("axon_msi: original write_offset 0x%x\n", write_offset);
 
 	/* write_offset doesn't wrap properly, so we have to mask it */
@@ -306,7 +301,7 @@ static int axon_msi_notify_reboot(struct notifier_block *nb,
 	list_for_each_entry(msic, &axon_msic_list, list) {
 		pr_debug("axon_msi: disabling %s\n",
 			  msic->irq_host->of_node->full_name);
-		tmp  = msic_dcr_read(msic, MSIC_CTRL_REG);
+		tmp  = dcr_read(msic->dcr_host, MSIC_CTRL_REG);
 		tmp &= ~MSIC_CTRL_ENABLE & ~MSIC_CTRL_IRQ_ENABLE;
 		msic_dcr_write(msic, MSIC_CTRL_REG, tmp);
 	}
@@ -323,7 +318,6 @@ static int axon_msi_setup_one(struct device_node *dn)
 	struct page *page;
 	struct axon_msic *msic;
 	unsigned int virq;
-	int dcr_base, dcr_len;
 
 	pr_debug("axon_msi: setting up dn %s\n", dn->full_name);
 
@@ -334,17 +328,7 @@ static int axon_msi_setup_one(struct device_node *dn)
 		goto out;
 	}
 
-	dcr_base = dcr_resource_start(dn, 0);
-	dcr_len = dcr_resource_len(dn, 0);
-
-	if (dcr_base == 0 || dcr_len == 0) {
-		printk(KERN_ERR
-		       "axon_msi: couldn't parse dcr properties on %s\n",
-			dn->full_name);
-		goto out;
-	}
-
-	msic->dcr_host = dcr_map(dn, dcr_base, dcr_len);
+	msic->dcr_host = dcr_map_reg(dn, 0);
 	if (!DCR_MAP_OK(msic->dcr_host)) {
 		printk(KERN_ERR "axon_msi: dcr_map failed for %s\n",
 		       dn->full_name);
-- 
1.5.1.3.g7a33b

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

* Re: [PATCH 1/7] Store the base address in dcr_host_t
  2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
                   ` (5 preceding siblings ...)
  2007-09-17  6:05 ` [PATCH 7/7] Remove msic_dcr_read() and use dcr_map_reg() in axon_msi.c Michael Ellerman
@ 2007-10-02  5:10 ` Benjamin Herrenschmidt
  6 siblings, 0 replies; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  5:10 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev


On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> In its current form, dcr_map() doesn't remember the base address you passed
> it, which means you need to store it somewhere else. Rather than adding the
> base to another struct it seems simpler to store it in the dcr_host_t.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/powerpc/sysdev/dcr.c        |    2 +-
>  include/asm-powerpc/dcr-mmio.h   |    6 +++++-
>  include/asm-powerpc/dcr-native.h |    6 ++++--
>  3 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/dcr.c b/arch/powerpc/sysdev/dcr.c
> index e82d54d..ab11c0b 100644
> --- a/arch/powerpc/sysdev/dcr.c
> +++ b/arch/powerpc/sysdev/dcr.c
> @@ -104,7 +104,7 @@ u64 of_translate_dcr_address(struct device_node *dev,
>  dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n,
>  		   unsigned int dcr_c)
>  {
> -	dcr_host_t ret = { .token = NULL, .stride = 0 };
> +	dcr_host_t ret = { .token = NULL, .stride = 0, .base = dcr_n };
>  	u64 addr;
>  
>  	pr_debug("dcr_map(%s, 0x%x, 0x%x)\n",
> diff --git a/include/asm-powerpc/dcr-mmio.h b/include/asm-powerpc/dcr-mmio.h
> index 5dbfca8..6b82c3b 100644
> --- a/include/asm-powerpc/dcr-mmio.h
> +++ b/include/asm-powerpc/dcr-mmio.h
> @@ -23,7 +23,11 @@
>  
>  #include <asm/io.h>
>  
> -typedef struct { void __iomem *token; unsigned int stride; } dcr_host_t;
> +typedef struct {
> +	void __iomem *token;
> +	unsigned int stride;
> +	unsigned int base;
> +} dcr_host_t;
>  
>  #define DCR_MAP_OK(host)	((host).token != NULL)
>  
> diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h
> index 05af081..f41058c 100644
> --- a/include/asm-powerpc/dcr-native.h
> +++ b/include/asm-powerpc/dcr-native.h
> @@ -22,11 +22,13 @@
>  #ifdef __KERNEL__
>  #ifndef __ASSEMBLY__
>  
> -typedef struct {} dcr_host_t;
> +typedef struct {
> +	unsigned int base;
> +} dcr_host_t;
>  
>  #define DCR_MAP_OK(host)	(1)
>  
> -#define dcr_map(dev, dcr_n, dcr_c)	((dcr_host_t){})
> +#define dcr_map(dev, dcr_n, dcr_c)	((dcr_host_t){ .base = (dcr_n) })
>  #define dcr_unmap(host, dcr_n, dcr_c)	do {} while (0)
>  #define dcr_read(host, dcr_n)		mfdcr(dcr_n)
>  #define dcr_write(host, dcr_n, value)	mtdcr(dcr_n, value)

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

* Re: [PATCH 2/7] Update mpic to use dcr_host_t.base
  2007-09-17  6:05 ` [PATCH 2/7] Update mpic to use dcr_host_t.base Michael Ellerman
@ 2007-10-02  5:12   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  5:12 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev


On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> Now that dcr_host_t contains the base address, we can use that in the mpic
> code, rather than storing it separately.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/powerpc/sysdev/mpic.c |   28 +++++++++++-----------------
>  include/asm-powerpc/mpic.h |    6 ------
>  2 files changed, 11 insertions(+), 23 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
> index 8de29f2..16b1f4b 100644
> --- a/arch/powerpc/sysdev/mpic.c
> +++ b/arch/powerpc/sysdev/mpic.c
> @@ -156,8 +156,7 @@ static inline u32 _mpic_read(enum mpic_reg_type type,
>  	switch(type) {
>  #ifdef CONFIG_PPC_DCR
>  	case mpic_access_dcr:
> -		return dcr_read(rb->dhost,
> -				rb->dbase + reg + rb->doff);
> +		return dcr_read(rb->dhost, rb->dhost.base + reg);
>  #endif
>  	case mpic_access_mmio_be:
>  		return in_be32(rb->base + (reg >> 2));
> @@ -174,8 +173,7 @@ static inline void _mpic_write(enum mpic_reg_type type,
>  	switch(type) {
>  #ifdef CONFIG_PPC_DCR
>  	case mpic_access_dcr:
> -		return dcr_write(rb->dhost,
> -				 rb->dbase + reg + rb->doff, value);
> +		return dcr_write(rb->dhost, rb->dhost.base + reg, value);
>  #endif
>  	case mpic_access_mmio_be:
>  		return out_be32(rb->base + (reg >> 2), value);
> @@ -279,9 +277,11 @@ static void _mpic_map_mmio(struct mpic *mpic, unsigned long phys_addr,
>  static void _mpic_map_dcr(struct mpic *mpic, struct mpic_reg_bank *rb,
>  			  unsigned int offset, unsigned int size)
>  {
> -	rb->dbase = mpic->dcr_base;
> -	rb->doff = offset;
> -	rb->dhost = dcr_map(mpic->irqhost->of_node, rb->dbase + rb->doff, size);
> +	const u32 *dbasep;
> +
> +	dbasep = of_get_property(mpic->irqhost->of_node, "dcr-reg", NULL);
> +
> +	rb->dhost = dcr_map(mpic->irqhost->of_node, *dbasep + offset, size);
>  	BUG_ON(!DCR_MAP_OK(rb->dhost));
>  }
>  
> @@ -1075,20 +1075,14 @@ struct mpic * __init mpic_alloc(struct device_node *node,
>  	BUG_ON(paddr == 0 && node == NULL);
>  
>  	/* If no physical address passed in, check if it's dcr based */
> -	if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL)
> -		mpic->flags |= MPIC_USES_DCR;
> -
> +	if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL) {
>  #ifdef CONFIG_PPC_DCR
> -	if (mpic->flags & MPIC_USES_DCR) {
> -		const u32 *dbasep;
> -		dbasep = of_get_property(node, "dcr-reg", NULL);
> -		BUG_ON(dbasep == NULL);
> -		mpic->dcr_base = *dbasep;
> +		mpic->flags |= MPIC_USES_DCR;
>  		mpic->reg_type = mpic_access_dcr;
> -	}
>  #else
> -	BUG_ON (mpic->flags & MPIC_USES_DCR);
> +		BUG();
>  #endif /* CONFIG_PPC_DCR */
> +	}
>  
>  	/* If the MPIC is not DCR based, and no physical address was passed
>  	 * in, try to obtain one
> diff --git a/include/asm-powerpc/mpic.h b/include/asm-powerpc/mpic.h
> index edb4a7c..ae84dde 100644
> --- a/include/asm-powerpc/mpic.h
> +++ b/include/asm-powerpc/mpic.h
> @@ -224,8 +224,6 @@ struct mpic_reg_bank {
>  	u32 __iomem	*base;
>  #ifdef CONFIG_PPC_DCR
>  	dcr_host_t	dhost;
> -	unsigned int	dbase;
> -	unsigned int	doff;
>  #endif /* CONFIG_PPC_DCR */
>  };
>  
> @@ -289,10 +287,6 @@ struct mpic
>  	struct mpic_reg_bank	cpuregs[MPIC_MAX_CPUS];
>  	struct mpic_reg_bank	isus[MPIC_MAX_ISU];
>  
> -#ifdef CONFIG_PPC_DCR
> -	unsigned int		dcr_base;
> -#endif
> -
>  	/* Protected sources */
>  	unsigned long		*protected;
>  

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

* Re: [PATCH 3/7] Use dcr_host_t.base in ibm_emac_mal
  2007-09-17  6:05 ` [PATCH 3/7] Use dcr_host_t.base in ibm_emac_mal Michael Ellerman
@ 2007-10-02  5:13   ` Benjamin Herrenschmidt
  2007-10-02  6:06     ` Michael Ellerman
  0 siblings, 1 reply; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  5:13 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev


On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> This requires us to do a sort-of fake dcr_map(), so that base is set
> properly. This will be fixed/removed when the device-tree-aware emac driver
> is merged.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---

(Have you actually tested btw ? :-)

> ---
>  drivers/net/ibm_emac/ibm_emac_mal.c |    5 ++++-
>  drivers/net/ibm_emac/ibm_emac_mal.h |    5 ++---
>  2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ibm_emac/ibm_emac_mal.c b/drivers/net/ibm_emac/ibm_emac_mal.c
> index cabd984..b08da96 100644
> --- a/drivers/net/ibm_emac/ibm_emac_mal.c
> +++ b/drivers/net/ibm_emac/ibm_emac_mal.c
> @@ -421,7 +421,10 @@ static int __init mal_probe(struct ocp_device *ocpdev)
>  		       ocpdev->def->index);
>  		return -ENOMEM;
>  	}
> -	mal->dcrbase = maldata->dcr_base;
> +
> +	/* XXX This only works for native dcr for now */
> +	mal->dcrhost = dcr_map(NULL, maldata->dcr_base, 0);
> +
>  	mal->def = ocpdev->def;
>  
>  	INIT_LIST_HEAD(&mal->poll_list);
> diff --git a/drivers/net/ibm_emac/ibm_emac_mal.h b/drivers/net/ibm_emac/ibm_emac_mal.h
> index 64bc338..6b1fbeb 100644
> --- a/drivers/net/ibm_emac/ibm_emac_mal.h
> +++ b/drivers/net/ibm_emac/ibm_emac_mal.h
> @@ -191,7 +191,6 @@ struct mal_commac {
>  };
>  
>  struct ibm_ocp_mal {
> -	int			dcrbase;
>  	dcr_host_t		dcrhost;
>  
>  	struct list_head	poll_list;
> @@ -209,12 +208,12 @@ struct ibm_ocp_mal {
>  
>  static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg)
>  {
> -	return dcr_read(mal->dcrhost, mal->dcrbase + reg);
> +	return dcr_read(mal->dcrhost, mal->dcrhost.base + reg);
>  }
>  
>  static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val)
>  {
> -	dcr_write(mal->dcrhost, mal->dcrbase + reg, val);
> +	dcr_write(mal->dcrhost, mal->dcrhost.base + reg, val);
>  }
>  
>  /* Register MAL devices */

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

* Re: [PATCH 4/7] Update axon_msi to use dcr_host_t.base
  2007-09-17  6:05 ` [PATCH 4/7] Update axon_msi to use dcr_host_t.base Michael Ellerman
@ 2007-10-02  5:14   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  5:14 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev


On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> Now that dcr_host_t contains the base address, we can use that in the
> axon_msi code, rather than storing it separately.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/powerpc/platforms/cell/axon_msi.c |   13 ++++++-------
>  1 files changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
> index 74407af..23e039a 100644
> --- a/arch/powerpc/platforms/cell/axon_msi.c
> +++ b/arch/powerpc/platforms/cell/axon_msi.c
> @@ -69,7 +69,6 @@ struct axon_msic {
>  	dcr_host_t dcr_host;
>  	struct list_head list;
>  	u32 read_offset;
> -	u32 dcr_base;
>  };
>  
>  static LIST_HEAD(axon_msic_list);
> @@ -78,12 +77,12 @@ static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
>  {
>  	pr_debug("axon_msi: dcr_write(0x%x, 0x%x)\n", val, dcr_n);
>  
> -	dcr_write(msic->dcr_host, msic->dcr_base + dcr_n, val);
> +	dcr_write(msic->dcr_host, msic->dcr_host.base + dcr_n, val);
>  }
>  
>  static u32 msic_dcr_read(struct axon_msic *msic, unsigned int dcr_n)
>  {
> -	return dcr_read(msic->dcr_host, msic->dcr_base + dcr_n);
> +	return dcr_read(msic->dcr_host, msic->dcr_host.base + dcr_n);
>  }
>  
>  static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
> @@ -324,7 +323,7 @@ static int axon_msi_setup_one(struct device_node *dn)
>  	struct page *page;
>  	struct axon_msic *msic;
>  	unsigned int virq;
> -	int dcr_len;
> +	int dcr_base, dcr_len;
>  
>  	pr_debug("axon_msi: setting up dn %s\n", dn->full_name);
>  
> @@ -335,17 +334,17 @@ static int axon_msi_setup_one(struct device_node *dn)
>  		goto out;
>  	}
>  
> -	msic->dcr_base = dcr_resource_start(dn, 0);
> +	dcr_base = dcr_resource_start(dn, 0);
>  	dcr_len = dcr_resource_len(dn, 0);
>  
> -	if (msic->dcr_base == 0 || dcr_len == 0) {
> +	if (dcr_base == 0 || dcr_len == 0) {
>  		printk(KERN_ERR
>  		       "axon_msi: couldn't parse dcr properties on %s\n",
>  			dn->full_name);
>  		goto out;
>  	}
>  
> -	msic->dcr_host = dcr_map(dn, msic->dcr_base, dcr_len);
> +	msic->dcr_host = dcr_map(dn, dcr_base, dcr_len);
>  	if (!DCR_MAP_OK(msic->dcr_host)) {
>  		printk(KERN_ERR "axon_msi: dcr_map failed for %s\n",
>  		       dn->full_name);

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

* Re: [PATCH 5/7] Add dcr_host_t.base in dcr_read()/dcr_write()
  2007-09-17  6:05 ` [PATCH 5/7] Add dcr_host_t.base in dcr_read()/dcr_write() Michael Ellerman
@ 2007-10-02  5:17   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  5:17 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev


On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> Now that all users of dcr_read()/dcr_write() add the dcr_host_t.base, we can
> save them the trouble and do it in dcr_read()/dcr_write().
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Please, fixup the changeset comment to be more exlicit or provide some
Documentation/powerpc/dcr.txt explaning some of the discussions we had
about why this is actually a good idea :-)

Among others:

 - Initially, the goal was to operate like mfdcr/mtdcr who take absolute
DCR numbers. The reason is that on 4xx hardware, indirect DCR access is
a pain (goes through a table of instructions) and it's useful to have
the compiler resolve an absolute DCR inline.

 - We decided that wasn't worth the API bastardisation since most cases
where absolute DCR values are used are low level 4xx-only code which may
as well continue using mfdcr/mtdcr, while the new API is designed for
device "instances" that can exist on 4xx and Axon type platforms and may
be located at variable DCR offsets.

Something around those lines...

Appart from that, patch is fine, I'll ack with the new comment :-)

Ben.

> ---
>  arch/powerpc/platforms/cell/axon_msi.c |    4 ++--
>  arch/powerpc/sysdev/mpic.c             |    4 ++--
>  drivers/net/ibm_emac/ibm_emac_mal.h    |    4 ++--
>  include/asm-powerpc/dcr-mmio.h         |    4 ++--
>  include/asm-powerpc/dcr-native.h       |    4 ++--
>  5 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
> index 23e039a..26a5e88 100644
> --- a/arch/powerpc/platforms/cell/axon_msi.c
> +++ b/arch/powerpc/platforms/cell/axon_msi.c
> @@ -77,12 +77,12 @@ static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
>  {
>  	pr_debug("axon_msi: dcr_write(0x%x, 0x%x)\n", val, dcr_n);
>  
> -	dcr_write(msic->dcr_host, msic->dcr_host.base + dcr_n, val);
> +	dcr_write(msic->dcr_host, dcr_n, val);
>  }
>  
>  static u32 msic_dcr_read(struct axon_msic *msic, unsigned int dcr_n)
>  {
> -	return dcr_read(msic->dcr_host, msic->dcr_host.base + dcr_n);
> +	return dcr_read(msic->dcr_host, dcr_n);
>  }
>  
>  static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
> diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
> index 16b1f4b..61f5730 100644
> --- a/arch/powerpc/sysdev/mpic.c
> +++ b/arch/powerpc/sysdev/mpic.c
> @@ -156,7 +156,7 @@ static inline u32 _mpic_read(enum mpic_reg_type type,
>  	switch(type) {
>  #ifdef CONFIG_PPC_DCR
>  	case mpic_access_dcr:
> -		return dcr_read(rb->dhost, rb->dhost.base + reg);
> +		return dcr_read(rb->dhost, reg);
>  #endif
>  	case mpic_access_mmio_be:
>  		return in_be32(rb->base + (reg >> 2));
> @@ -173,7 +173,7 @@ static inline void _mpic_write(enum mpic_reg_type type,
>  	switch(type) {
>  #ifdef CONFIG_PPC_DCR
>  	case mpic_access_dcr:
> -		return dcr_write(rb->dhost, rb->dhost.base + reg, value);
> +		return dcr_write(rb->dhost, reg, value);
>  #endif
>  	case mpic_access_mmio_be:
>  		return out_be32(rb->base + (reg >> 2), value);
> diff --git a/drivers/net/ibm_emac/ibm_emac_mal.h b/drivers/net/ibm_emac/ibm_emac_mal.h
> index 6b1fbeb..10dc978 100644
> --- a/drivers/net/ibm_emac/ibm_emac_mal.h
> +++ b/drivers/net/ibm_emac/ibm_emac_mal.h
> @@ -208,12 +208,12 @@ struct ibm_ocp_mal {
>  
>  static inline u32 get_mal_dcrn(struct ibm_ocp_mal *mal, int reg)
>  {
> -	return dcr_read(mal->dcrhost, mal->dcrhost.base + reg);
> +	return dcr_read(mal->dcrhost, reg);
>  }
>  
>  static inline void set_mal_dcrn(struct ibm_ocp_mal *mal, int reg, u32 val)
>  {
> -	dcr_write(mal->dcrhost, mal->dcrhost.base + reg, val);
> +	dcr_write(mal->dcrhost, reg, val);
>  }
>  
>  /* Register MAL devices */
> diff --git a/include/asm-powerpc/dcr-mmio.h b/include/asm-powerpc/dcr-mmio.h
> index 6b82c3b..a7d9eaf 100644
> --- a/include/asm-powerpc/dcr-mmio.h
> +++ b/include/asm-powerpc/dcr-mmio.h
> @@ -37,12 +37,12 @@ extern void dcr_unmap(dcr_host_t host, unsigned int dcr_n, unsigned int dcr_c);
>  
>  static inline u32 dcr_read(dcr_host_t host, unsigned int dcr_n)
>  {
> -	return in_be32(host.token + dcr_n * host.stride);
> +	return in_be32(host.token + ((host.base + dcr_n) * host.stride));
>  }
>  
>  static inline void dcr_write(dcr_host_t host, unsigned int dcr_n, u32 value)
>  {
> -	out_be32(host.token + dcr_n * host.stride, value);
> +	out_be32(host.token + ((host.base + dcr_n) * host.stride), value);
>  }
>  
>  extern u64 of_translate_dcr_address(struct device_node *dev,
> diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h
> index f41058c..3bc780f 100644
> --- a/include/asm-powerpc/dcr-native.h
> +++ b/include/asm-powerpc/dcr-native.h
> @@ -30,8 +30,8 @@ typedef struct {
>  
>  #define dcr_map(dev, dcr_n, dcr_c)	((dcr_host_t){ .base = (dcr_n) })
>  #define dcr_unmap(host, dcr_n, dcr_c)	do {} while (0)
> -#define dcr_read(host, dcr_n)		mfdcr(dcr_n)
> -#define dcr_write(host, dcr_n, value)	mtdcr(dcr_n, value)
> +#define dcr_read(host, dcr_n)		mfdcr(dcr_n + host.base)
> +#define dcr_write(host, dcr_n, value)	mtdcr(dcr_n + host.base, value)
>  
>  /* Device Control Registers */
>  void __mtdcr(int reg, unsigned int val);
> -- 
> 1.5.1.3.g7a33b
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc-dev

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

* Re: [PATCH 6/7] Add dcr_map_reg() helper
  2007-09-17  6:05 ` [PATCH 6/7] Add dcr_map_reg() helper Michael Ellerman
@ 2007-10-02  5:19   ` Benjamin Herrenschmidt
  2007-10-02  5:51     ` Michael Ellerman
  0 siblings, 1 reply; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  5:19 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev


On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> Add a helper routine to map dcr's based on the "dcr-reg" property of
> a device node.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Wouldn't it be more consistent to call it of_map_dcr ? Or maybe find an
even better name, but dcr_map_reg really sucks :-)

Ben.

> ---
>  arch/powerpc/sysdev/dcr.c |   17 +++++++++++++++++
>  include/asm-powerpc/dcr.h |    1 +
>  2 files changed, 18 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/dcr.c b/arch/powerpc/sysdev/dcr.c
> index ab11c0b..da4f9c6 100644
> --- a/arch/powerpc/sysdev/dcr.c
> +++ b/arch/powerpc/sysdev/dcr.c
> @@ -126,6 +126,23 @@ dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n,
>  }
>  EXPORT_SYMBOL_GPL(dcr_map);
>  
> +dcr_host_t dcr_map_reg(struct device_node *dev, unsigned int index)
> +{
> +	dcr_host_t ret = { .token = NULL };
> +
> +	unsigned int dcr_n, dcr_c;
> +
> +	dcr_n = dcr_resource_start(dev, index);
> +	if (!dcr_n)
> +		return ret;
> +
> +	dcr_c = dcr_resource_len(dev, index);
> +	if (!dcr_c)
> +		return ret;
> +
> +	return dcr_map(dev, dcr_n, dcr_c);
> +}
> +
>  void dcr_unmap(dcr_host_t host, unsigned int dcr_n, unsigned int dcr_c)
>  {
>  	dcr_host_t h = host;
> diff --git a/include/asm-powerpc/dcr.h b/include/asm-powerpc/dcr.h
> index 9338d50..4d42f01 100644
> --- a/include/asm-powerpc/dcr.h
> +++ b/include/asm-powerpc/dcr.h
> @@ -38,6 +38,7 @@ extern unsigned int dcr_resource_start(struct device_node *np,
>  				       unsigned int index);
>  extern unsigned int dcr_resource_len(struct device_node *np,
>  				     unsigned int index);
> +extern dcr_host_t dcr_map_reg(struct device_node *np, unsigned int index);
>  #endif /* CONFIG_PPC_MERGE */
>  
>  #endif /* CONFIG_PPC_DCR */

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

* Re: [PATCH 7/7] Remove msic_dcr_read() and use dcr_map_reg() in axon_msi.c
  2007-09-17  6:05 ` [PATCH 7/7] Remove msic_dcr_read() and use dcr_map_reg() in axon_msi.c Michael Ellerman
@ 2007-10-02  5:20   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  5:20 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev


On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> msic_dcr_read() doesn't really do anything useful, just replace it with
> direct calls to dcr_read().
> 
> Use dcr_map_reg() in the axon_msi setup code, rather than essentially doing
> it by hand.
> 
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

> ---
>  arch/powerpc/platforms/cell/axon_msi.c |   22 +++-------------------
>  1 files changed, 3 insertions(+), 19 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/cell/axon_msi.c b/arch/powerpc/platforms/cell/axon_msi.c
> index 26a5e88..57a6149 100644
> --- a/arch/powerpc/platforms/cell/axon_msi.c
> +++ b/arch/powerpc/platforms/cell/axon_msi.c
> @@ -80,18 +80,13 @@ static void msic_dcr_write(struct axon_msic *msic, unsigned int dcr_n, u32 val)
>  	dcr_write(msic->dcr_host, dcr_n, val);
>  }
>  
> -static u32 msic_dcr_read(struct axon_msic *msic, unsigned int dcr_n)
> -{
> -	return dcr_read(msic->dcr_host, dcr_n);
> -}
> -
>  static void axon_msi_cascade(unsigned int irq, struct irq_desc *desc)
>  {
>  	struct axon_msic *msic = get_irq_data(irq);
>  	u32 write_offset, msi;
>  	int idx;
>  
> -	write_offset = msic_dcr_read(msic, MSIC_WRITE_OFFSET_REG);
> +	write_offset = dcr_read(msic->dcr_host, MSIC_WRITE_OFFSET_REG);
>  	pr_debug("axon_msi: original write_offset 0x%x\n", write_offset);
>  
>  	/* write_offset doesn't wrap properly, so we have to mask it */
> @@ -306,7 +301,7 @@ static int axon_msi_notify_reboot(struct notifier_block *nb,
>  	list_for_each_entry(msic, &axon_msic_list, list) {
>  		pr_debug("axon_msi: disabling %s\n",
>  			  msic->irq_host->of_node->full_name);
> -		tmp  = msic_dcr_read(msic, MSIC_CTRL_REG);
> +		tmp  = dcr_read(msic->dcr_host, MSIC_CTRL_REG);
>  		tmp &= ~MSIC_CTRL_ENABLE & ~MSIC_CTRL_IRQ_ENABLE;
>  		msic_dcr_write(msic, MSIC_CTRL_REG, tmp);
>  	}
> @@ -323,7 +318,6 @@ static int axon_msi_setup_one(struct device_node *dn)
>  	struct page *page;
>  	struct axon_msic *msic;
>  	unsigned int virq;
> -	int dcr_base, dcr_len;
>  
>  	pr_debug("axon_msi: setting up dn %s\n", dn->full_name);
>  
> @@ -334,17 +328,7 @@ static int axon_msi_setup_one(struct device_node *dn)
>  		goto out;
>  	}
>  
> -	dcr_base = dcr_resource_start(dn, 0);
> -	dcr_len = dcr_resource_len(dn, 0);
> -
> -	if (dcr_base == 0 || dcr_len == 0) {
> -		printk(KERN_ERR
> -		       "axon_msi: couldn't parse dcr properties on %s\n",
> -			dn->full_name);
> -		goto out;
> -	}
> -
> -	msic->dcr_host = dcr_map(dn, dcr_base, dcr_len);
> +	msic->dcr_host = dcr_map_reg(dn, 0);
>  	if (!DCR_MAP_OK(msic->dcr_host)) {
>  		printk(KERN_ERR "axon_msi: dcr_map failed for %s\n",
>  		       dn->full_name);

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

* Re: [PATCH 6/7] Add dcr_map_reg() helper
  2007-10-02  5:19   ` Benjamin Herrenschmidt
@ 2007-10-02  5:51     ` Michael Ellerman
  2007-10-02  6:22       ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Ellerman @ 2007-10-02  5:51 UTC (permalink / raw)
  To: benh; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 980 bytes --]

On Tue, 2007-10-02 at 15:19 +1000, Benjamin Herrenschmidt wrote:
> On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> > Add a helper routine to map dcr's based on the "dcr-reg" property of
> > a device node.
> > 
> > Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
> 
> Wouldn't it be more consistent to call it of_map_dcr ? Or maybe find an
> even better name, but dcr_map_reg really sucks :-)

That would give us dcr_map(), dcr_unmap() and of_map_dcr() - which
doesn't strike me as more consistent.

I don't particularly like dcr_map_reg(), but I think it's at least
obvious that it's a variant of dcr_map() and that it has something to do
with a "reg" .. maybe even a "dcr-reg" :)

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH 3/7] Use dcr_host_t.base in ibm_emac_mal
  2007-10-02  5:13   ` Benjamin Herrenschmidt
@ 2007-10-02  6:06     ` Michael Ellerman
  0 siblings, 0 replies; 17+ messages in thread
From: Michael Ellerman @ 2007-10-02  6:06 UTC (permalink / raw)
  To: benh; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 1063 bytes --]

On Tue, 2007-10-02 at 15:13 +1000, Benjamin Herrenschmidt wrote:
> On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> > This requires us to do a sort-of fake dcr_map(), so that base is set
> > properly. This will be fixed/removed when the device-tree-aware emac driver
> > is merged.
> > 
> > Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
> 
> Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
> 
> (Have you actually tested btw ? :-)

Hmm, I wrote these in mid June, so to be honest I don't remember. I
don't think I boot tested it on anything, but I think I would have built
it.

I see now that the newemac driver is in Jeff's 24 tree, so it's probably
best to wait for Linus to merge that and then we can fix up it as well
in the one series.

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH 6/7] Add dcr_map_reg() helper
  2007-10-02  5:51     ` Michael Ellerman
@ 2007-10-02  6:22       ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 17+ messages in thread
From: Benjamin Herrenschmidt @ 2007-10-02  6:22 UTC (permalink / raw)
  To: michael; +Cc: linuxppc-dev


On Tue, 2007-10-02 at 15:51 +1000, Michael Ellerman wrote:
> On Tue, 2007-10-02 at 15:19 +1000, Benjamin Herrenschmidt wrote:
> > On Mon, 2007-09-17 at 16:05 +1000, Michael Ellerman wrote:
> > > Add a helper routine to map dcr's based on the "dcr-reg" property of
> > > a device node.
> > > 
> > > Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
> > 
> > Wouldn't it be more consistent to call it of_map_dcr ? Or maybe find an
> > even better name, but dcr_map_reg really sucks :-)
> 
> That would give us dcr_map(), dcr_unmap() and of_map_dcr() - which
> doesn't strike me as more consistent.
> 
> I don't particularly like dcr_map_reg(), but I think it's at least
> obvious that it's a variant of dcr_map() and that it has something to do
> with a "reg" .. maybe even a "dcr-reg" :)

dcr_map_node maybe ? dcr_map_device ? dcr_map_property ? hrm...
allright, keep it that way if you want but heh, at least see if you can
come up with something better before it gets merged :-)

Ben

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

end of thread, other threads:[~2007-10-02  6:22 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-17  6:05 [PATCH 1/7] Store the base address in dcr_host_t Michael Ellerman
2007-09-17  6:05 ` [PATCH 2/7] Update mpic to use dcr_host_t.base Michael Ellerman
2007-10-02  5:12   ` Benjamin Herrenschmidt
2007-09-17  6:05 ` [PATCH 3/7] Use dcr_host_t.base in ibm_emac_mal Michael Ellerman
2007-10-02  5:13   ` Benjamin Herrenschmidt
2007-10-02  6:06     ` Michael Ellerman
2007-09-17  6:05 ` [PATCH 4/7] Update axon_msi to use dcr_host_t.base Michael Ellerman
2007-10-02  5:14   ` Benjamin Herrenschmidt
2007-09-17  6:05 ` [PATCH 5/7] Add dcr_host_t.base in dcr_read()/dcr_write() Michael Ellerman
2007-10-02  5:17   ` Benjamin Herrenschmidt
2007-09-17  6:05 ` [PATCH 6/7] Add dcr_map_reg() helper Michael Ellerman
2007-10-02  5:19   ` Benjamin Herrenschmidt
2007-10-02  5:51     ` Michael Ellerman
2007-10-02  6:22       ` Benjamin Herrenschmidt
2007-09-17  6:05 ` [PATCH 7/7] Remove msic_dcr_read() and use dcr_map_reg() in axon_msi.c Michael Ellerman
2007-10-02  5:20   ` Benjamin Herrenschmidt
2007-10-02  5:10 ` [PATCH 1/7] Store the base address in dcr_host_t Benjamin Herrenschmidt

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).