linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Add __ioread32_copy() and use it
@ 2015-10-23 20:01 Stephen Boyd
  2015-10-23 20:01 ` [PATCH v3 1/4] frv: io: Accept const void pointers for read{b,w,l}() Stephen Boyd
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Stephen Boyd @ 2015-10-23 20:01 UTC (permalink / raw)
  To: linux-arm-kernel

The SMD driver is reading and writing chunks of data to iomem,
and there's an __iowrite32_copy() function for the writing part, but
no __ioread32_copy() function for the reading part. This series
adds __ioread32_copy() and uses it in two places.

This is a respin with some small fixes found with soaking in -next.

Andrew, the patches should apply cleanly to linux-next, so I hope
you can pick them up directly now, instead of the previous plan where
they would go through Andy's tree.

Changes from v2:
 * Make bcm patch actually compile
 * Add new patch for frv to avoid warnings

Cc: Hauke Mehrtens <hauke@hauke-m.de>
Cc: Rafa? Mi?ecki <zajec5@gmail.com>
Cc: Paul Walmsley <paul@pwsan.com>
Cc: linux-mips at linux-mips.org
Cc: David Howells <dhowells@redhat.com>
Cc: linux-soc at vger.kernel.org

Stephen Boyd (4):
  frv: io: Accept const void pointers for read{b,w,l}()
  lib: iomap_copy: Add __ioread32_copy()
  soc: qcom: smd: Use __ioread32_copy() instead of open-coding it
  FIRMWARE: bcm47xx_nvram: Use __ioread32_copy() instead of open-coding

 arch/frv/include/asm/io.h                 | 17 ++++++++++++++---
 drivers/firmware/broadcom/bcm47xx_nvram.c | 11 +++--------
 drivers/soc/qcom/smd.c                    | 13 ++++---------
 include/linux/io.h                        |  1 +
 lib/iomap_copy.c                          | 21 +++++++++++++++++++++
 5 files changed, 43 insertions(+), 20 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH v3 1/4] frv: io: Accept const void pointers for read{b,w,l}()
  2015-10-23 20:01 [PATCH v3 0/4] Add __ioread32_copy() and use it Stephen Boyd
@ 2015-10-23 20:01 ` Stephen Boyd
  2015-10-23 20:01 ` [PATCH v3 2/4] lib: iomap_copy: Add __ioread32_copy() Stephen Boyd
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2015-10-23 20:01 UTC (permalink / raw)
  To: linux-arm-kernel

The frv port uses compiler builtins, __builtin_read*(), for the
I/O read routines. Unfortunately, these don't accept const void
pointers although the generic ASM implementations do, so generic
code passing const pointers to these APIs cause compilers to emit
warnings. Add wrapper functions that cast away the const to avoid
the warnings.

Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
 arch/frv/include/asm/io.h | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/arch/frv/include/asm/io.h b/arch/frv/include/asm/io.h
index 70dfbea8c8d7..8062fc73fad0 100644
--- a/arch/frv/include/asm/io.h
+++ b/arch/frv/include/asm/io.h
@@ -43,9 +43,20 @@ static inline unsigned long _swapl(unsigned long v)
 //#define __iormb() asm volatile("membar")
 //#define __iowmb() asm volatile("membar")
 
-#define __raw_readb __builtin_read8
-#define __raw_readw __builtin_read16
-#define __raw_readl __builtin_read32
+static inline u8 __raw_readb(const volatile void __iomem *addr)
+{
+	return __builtin_read8((volatile void __iomem *)addr);
+}
+
+static inline u16 __raw_readw(const volatile void __iomem *addr)
+{
+	return __builtin_read16((volatile void __iomem *)addr);
+}
+
+static inline u32 __raw_readl(const volatile void __iomem *addr)
+{
+	return __builtin_read32((volatile void __iomem *)addr);
+}
 
 #define __raw_writeb(datum, addr) __builtin_write8(addr, datum)
 #define __raw_writew(datum, addr) __builtin_write16(addr, datum)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH v3 2/4] lib: iomap_copy: Add __ioread32_copy()
  2015-10-23 20:01 [PATCH v3 0/4] Add __ioread32_copy() and use it Stephen Boyd
  2015-10-23 20:01 ` [PATCH v3 1/4] frv: io: Accept const void pointers for read{b,w,l}() Stephen Boyd
@ 2015-10-23 20:01 ` Stephen Boyd
  2015-10-23 20:01 ` [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it Stephen Boyd
  2015-10-23 20:01 ` [PATCH v3 4/4] FIRMWARE: bcm47xx_nvram: Use __ioread32_copy() instead of open-coding Stephen Boyd
  3 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2015-10-23 20:01 UTC (permalink / raw)
  To: linux-arm-kernel

Some drivers need to read data out of iomem areas 32-bits at a
time. Add an API to do this.

Cc: Bjorn Andersson <bjorn.andersson@sonymobile.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
 include/linux/io.h |  1 +
 lib/iomap_copy.c   | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/io.h b/include/linux/io.h
index de64c1e53612..72c35e0a41d1 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -29,6 +29,7 @@ struct device;
 struct resource;
 
 __visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
+void __ioread32_copy(void *to, const void __iomem *from, size_t count);
 void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
 
 #ifdef CONFIG_MMU
diff --git a/lib/iomap_copy.c b/lib/iomap_copy.c
index 4527e751b5e0..b8f1d6cbb200 100644
--- a/lib/iomap_copy.c
+++ b/lib/iomap_copy.c
@@ -42,6 +42,27 @@ void __attribute__((weak)) __iowrite32_copy(void __iomem *to,
 EXPORT_SYMBOL_GPL(__iowrite32_copy);
 
 /**
+ * __ioread32_copy - copy data from MMIO space, in 32-bit units
+ * @to: destination (must be 32-bit aligned)
+ * @from: source, in MMIO space (must be 32-bit aligned)
+ * @count: number of 32-bit quantities to copy
+ *
+ * Copy data from MMIO space to kernel space, in units of 32 bits at a
+ * time.  Order of access is not guaranteed, nor is a memory barrier
+ * performed afterwards.
+ */
+void __ioread32_copy(void *to, const void __iomem *from, size_t count)
+{
+	u32 *dst = to;
+	const u32 __iomem *src = from;
+	const u32 __iomem *end = src + count;
+
+	while (src < end)
+		*dst++ = __raw_readl(src++);
+}
+EXPORT_SYMBOL_GPL(__ioread32_copy);
+
+/**
  * __iowrite64_copy - copy data to MMIO space, in 64-bit or 32-bit units
  * @to: destination, in MMIO space (must be 64-bit aligned)
  * @from: source (must be 64-bit aligned)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it
  2015-10-23 20:01 [PATCH v3 0/4] Add __ioread32_copy() and use it Stephen Boyd
  2015-10-23 20:01 ` [PATCH v3 1/4] frv: io: Accept const void pointers for read{b,w,l}() Stephen Boyd
  2015-10-23 20:01 ` [PATCH v3 2/4] lib: iomap_copy: Add __ioread32_copy() Stephen Boyd
@ 2015-10-23 20:01 ` Stephen Boyd
  2015-10-23 20:22   ` Bjorn Andersson
  2015-10-26  2:00   ` Andy Gross
  2015-10-23 20:01 ` [PATCH v3 4/4] FIRMWARE: bcm47xx_nvram: Use __ioread32_copy() instead of open-coding Stephen Boyd
  3 siblings, 2 replies; 7+ messages in thread
From: Stephen Boyd @ 2015-10-23 20:01 UTC (permalink / raw)
  To: linux-arm-kernel

Now that we have a generic library function for this, replace the
open-coded instance.

Cc: Bjorn Andersson <bjorn.andersson@sonymobile.com>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
 drivers/soc/qcom/smd.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/soc/qcom/smd.c b/drivers/soc/qcom/smd.c
index 86b598cff91a..498fd0581a45 100644
--- a/drivers/soc/qcom/smd.c
+++ b/drivers/soc/qcom/smd.c
@@ -434,20 +434,15 @@ static void smd_copy_to_fifo(void __iomem *dst,
 /*
  * Copy count bytes of data using 32bit accesses, if that is required.
  */
-static void smd_copy_from_fifo(void *_dst,
-			       const void __iomem *_src,
+static void smd_copy_from_fifo(void *dst,
+			       const void __iomem *src,
 			       size_t count,
 			       bool word_aligned)
 {
-	u32 *dst = (u32 *)_dst;
-	u32 *src = (u32 *)_src;
-
 	if (word_aligned) {
-		count /= sizeof(u32);
-		while (count--)
-			*dst++ = __raw_readl(src++);
+		__ioread32_copy(dst, src, count / sizeof(u32));
 	} else {
-		memcpy_fromio(_dst, _src, count);
+		memcpy_fromio(dst, src, count);
 	}
 }
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH v3 4/4] FIRMWARE: bcm47xx_nvram: Use __ioread32_copy() instead of open-coding
  2015-10-23 20:01 [PATCH v3 0/4] Add __ioread32_copy() and use it Stephen Boyd
                   ` (2 preceding siblings ...)
  2015-10-23 20:01 ` [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it Stephen Boyd
@ 2015-10-23 20:01 ` Stephen Boyd
  3 siblings, 0 replies; 7+ messages in thread
From: Stephen Boyd @ 2015-10-23 20:01 UTC (permalink / raw)
  To: linux-arm-kernel

Now that we have a generic library function for this, replace the
open-coded instance.

Cc: Hauke Mehrtens <hauke@hauke-m.de>
Cc: Rafa? Mi?ecki <zajec5@gmail.com>
Cc: Paul Walmsley <paul@pwsan.com>
Cc: linux-mips at linux-mips.org
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
---
 drivers/firmware/broadcom/bcm47xx_nvram.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c
index e41594510b97..0c2f0a61b0ea 100644
--- a/drivers/firmware/broadcom/bcm47xx_nvram.c
+++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
@@ -56,9 +56,7 @@ static u32 find_nvram_size(void __iomem *end)
 static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
 {
 	struct nvram_header __iomem *header;
-	int i;
 	u32 off;
-	u32 *src, *dst;
 	u32 size;
 
 	if (nvram_len) {
@@ -95,10 +93,7 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
 	return -ENXIO;
 
 found:
-	src = (u32 *)header;
-	dst = (u32 *)nvram_buf;
-	for (i = 0; i < sizeof(struct nvram_header); i += 4)
-		*dst++ = __raw_readl(src++);
+	__ioread32_copy(nvram_buf, header, sizeof(*header) / 4);
 	header = (struct nvram_header *)nvram_buf;
 	nvram_len = header->len;
 	if (nvram_len > size) {
@@ -111,8 +106,8 @@ found:
 		nvram_len = NVRAM_SPACE - 1;
 	}
 	/* proceed reading data after header */
-	for (; i < nvram_len; i += 4)
-		*dst++ = readl(src++);
+	__ioread32_copy(nvram_buf + sizeof(*header), header + 1,
+			DIV_ROUND_UP(nvram_len, 4));
 	nvram_buf[NVRAM_SPACE - 1] = '\0';
 
 	return 0;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it
  2015-10-23 20:01 ` [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it Stephen Boyd
@ 2015-10-23 20:22   ` Bjorn Andersson
  2015-10-26  2:00   ` Andy Gross
  1 sibling, 0 replies; 7+ messages in thread
From: Bjorn Andersson @ 2015-10-23 20:22 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri 23 Oct 13:01 PDT 2015, Stephen Boyd wrote:

> Now that we have a generic library function for this, replace the
> open-coded instance.
> 
> Cc: Bjorn Andersson <bjorn.andersson@sonymobile.com>

Reviewed-by: Bjorn Andersson <bjorn.andersson@sonymobile.com>

Regards,
Bjorn

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

* [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it
  2015-10-23 20:01 ` [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it Stephen Boyd
  2015-10-23 20:22   ` Bjorn Andersson
@ 2015-10-26  2:00   ` Andy Gross
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Gross @ 2015-10-26  2:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Oct 23, 2015 at 01:01:51PM -0700, Stephen Boyd wrote:
> Now that we have a generic library function for this, replace the
> open-coded instance.
> 
> Cc: Bjorn Andersson <bjorn.andersson@sonymobile.com>
> Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
> ---

Acked-by: Andy Gross <agross@codeaurora.org>

-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

end of thread, other threads:[~2015-10-26  2:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-23 20:01 [PATCH v3 0/4] Add __ioread32_copy() and use it Stephen Boyd
2015-10-23 20:01 ` [PATCH v3 1/4] frv: io: Accept const void pointers for read{b,w,l}() Stephen Boyd
2015-10-23 20:01 ` [PATCH v3 2/4] lib: iomap_copy: Add __ioread32_copy() Stephen Boyd
2015-10-23 20:01 ` [PATCH v3 3/4] soc: qcom: smd: Use __ioread32_copy() instead of open-coding it Stephen Boyd
2015-10-23 20:22   ` Bjorn Andersson
2015-10-26  2:00   ` Andy Gross
2015-10-23 20:01 ` [PATCH v3 4/4] FIRMWARE: bcm47xx_nvram: Use __ioread32_copy() instead of open-coding Stephen Boyd

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