linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] MIPS: OCTEON: flash: syncronize bootbus access
@ 2015-03-05 14:31 Aleksey Makarov
  2015-03-05 14:31 ` [PATCH v2 1/3] MIPS: OCTEON: Add semaphore to serialize bootbus accesses Aleksey Makarov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Aleksey Makarov @ 2015-03-05 14:31 UTC (permalink / raw)
  To: linux-mips; +Cc: linux-kernel, David Daney, Aleksey Makarov

Changes in v2:

- Rebase to v4.0-rc2

Summary:

- Use semaphore to protect access to bootbus.  
- Use device tree to probe for flash chips.

Version 1:

https://lkml.kernel.org/g/<1419337623-16101-1-git-send-email-aleksey.makarov@auriga.com>

David Daney (3):
  MIPS: OCTEON: Add semaphore to serialize bootbus accesses.
  MIPS: OCTEON: Protect accesses to bootbus flash with
    octeon_bootbus_sem.
  MIPS: OCTEON: Use device tree to probe for flash chips.

 arch/mips/Kconfig                     |  1 +
 arch/mips/cavium-octeon/flash_setup.c | 84 ++++++++++++++++++++++++++++++++---
 arch/mips/cavium-octeon/setup.c       |  3 ++
 arch/mips/include/asm/octeon/octeon.h |  2 +
 4 files changed, 84 insertions(+), 6 deletions(-)

-- 
2.3.0


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

* [PATCH v2 1/3] MIPS: OCTEON: Add semaphore to serialize bootbus accesses.
  2015-03-05 14:31 [PATCH v2 0/3] MIPS: OCTEON: flash: syncronize bootbus access Aleksey Makarov
@ 2015-03-05 14:31 ` Aleksey Makarov
  2015-03-05 14:31 ` [PATCH v2 2/3] MIPS: OCTEON: Protect accesses to bootbus flash with octeon_bootbus_sem Aleksey Makarov
  2015-03-05 14:31 ` [PATCH v2 3/3] MIPS: OCTEON: Use device tree to probe for flash chips Aleksey Makarov
  2 siblings, 0 replies; 5+ messages in thread
From: Aleksey Makarov @ 2015-03-05 14:31 UTC (permalink / raw)
  To: linux-mips
  Cc: linux-kernel, David Daney, Aleksey Makarov, Chandrakala Chavva,
	Ralf Baechle

From: David Daney <david.daney@cavium.com>

Some hardware blocks attached to the OCTEON bootbus run asynchronously
to accesses from the CPUs.  These include MMC/SD host, CF(when using
DMA), and NAND controller.  A bus error, or corrupt data may occur if
a CPU is trying to access a bootbus connected device at the same time
the bus is running asynchronous operations.

To work around these problems we add this semaphore that must be
acquired before initiating bootbus activity.  Subsequent patches will
add users for this.

Signed-off-by: David Daney <david.daney@cavium.com>
[aleksey.makarov@auriga.com: combine the patches]
Signed-off-by: Aleksey Makarov <aleksey.makarov@auriga.com>
Signed-off-by: Chandrakala Chavva <cchavva@caviumnetworks.com>
---
 arch/mips/cavium-octeon/setup.c       | 3 +++
 arch/mips/include/asm/octeon/octeon.h | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/arch/mips/cavium-octeon/setup.c b/arch/mips/cavium-octeon/setup.c
index a42110e..01130e9 100644
--- a/arch/mips/cavium-octeon/setup.c
+++ b/arch/mips/cavium-octeon/setup.c
@@ -51,6 +51,9 @@ extern void pci_console_init(const char *arg);
 
 static unsigned long long MAX_MEMORY = 512ull << 20;
 
+DEFINE_SEMAPHORE(octeon_bootbus_sem);
+EXPORT_SYMBOL(octeon_bootbus_sem);
+
 struct octeon_boot_descriptor *octeon_boot_desc_ptr;
 
 struct cvmx_bootinfo *octeon_bootinfo;
diff --git a/arch/mips/include/asm/octeon/octeon.h b/arch/mips/include/asm/octeon/octeon.h
index 0415965..de9f74e 100644
--- a/arch/mips/include/asm/octeon/octeon.h
+++ b/arch/mips/include/asm/octeon/octeon.h
@@ -335,4 +335,6 @@ void octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t);
 
 extern void octeon_fixup_irqs(void);
 
+extern struct semaphore octeon_bootbus_sem;
+
 #endif /* __ASM_OCTEON_OCTEON_H */
-- 
2.3.0


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

* [PATCH v2 2/3] MIPS: OCTEON: Protect accesses to bootbus flash with octeon_bootbus_sem.
  2015-03-05 14:31 [PATCH v2 0/3] MIPS: OCTEON: flash: syncronize bootbus access Aleksey Makarov
  2015-03-05 14:31 ` [PATCH v2 1/3] MIPS: OCTEON: Add semaphore to serialize bootbus accesses Aleksey Makarov
@ 2015-03-05 14:31 ` Aleksey Makarov
  2015-03-05 14:31 ` [PATCH v2 3/3] MIPS: OCTEON: Use device tree to probe for flash chips Aleksey Makarov
  2 siblings, 0 replies; 5+ messages in thread
From: Aleksey Makarov @ 2015-03-05 14:31 UTC (permalink / raw)
  To: linux-mips; +Cc: linux-kernel, David Daney, Aleksey Makarov, Ralf Baechle

From: David Daney <david.daney@cavium.com>

Without this, we get bus errors.

Signed-off-by: David Daney <david.daney@cavium.com>
Signed-off-by: Aleksey Makarov <aleksey.makarov@auriga.com>
---
 arch/mips/Kconfig                     |  1 +
 arch/mips/cavium-octeon/flash_setup.c | 42 ++++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index c7a1690..f7804e9 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -793,6 +793,7 @@ config CAVIUM_OCTEON_SOC
 	select SYS_SUPPORTS_SMP
 	select NR_CPUS_DEFAULT_16
 	select BUILTIN_DTB
+	select MTD_COMPLEX_MAPPINGS
 	help
 	  This option supports all of the Octeon reference boards from Cavium
 	  Networks. It builds a kernel that dynamically determines the Octeon
diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
index 237e5b1..39e26df 100644
--- a/arch/mips/cavium-octeon/flash_setup.c
+++ b/arch/mips/cavium-octeon/flash_setup.c
@@ -9,6 +9,7 @@
  */
 #include <linux/kernel.h>
 #include <linux/export.h>
+#include <linux/semaphore.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
 #include <linux/mtd/partitions.h>
@@ -25,6 +26,41 @@ static const char *part_probe_types[] = {
 	NULL
 };
 
+static map_word octeon_flash_map_read(struct map_info *map, unsigned long ofs)
+{
+	map_word r;
+
+	down(&octeon_bootbus_sem);
+	r = inline_map_read(map, ofs);
+	up(&octeon_bootbus_sem);
+
+	return r;
+}
+
+static void octeon_flash_map_write(struct map_info *map, const map_word datum,
+				   unsigned long ofs)
+{
+	down(&octeon_bootbus_sem);
+	inline_map_write(map, datum, ofs);
+	up(&octeon_bootbus_sem);
+}
+
+static void octeon_flash_map_copy_from(struct map_info *map, void *to,
+				       unsigned long from, ssize_t len)
+{
+	down(&octeon_bootbus_sem);
+	inline_map_copy_from(map, to, from, len);
+	up(&octeon_bootbus_sem);
+}
+
+static void octeon_flash_map_copy_to(struct map_info *map, unsigned long to,
+				     const void *from, ssize_t len)
+{
+	down(&octeon_bootbus_sem);
+	inline_map_copy_to(map, to, from, len);
+	up(&octeon_bootbus_sem);
+}
+
 /**
  * Module/ driver initialization.
  *
@@ -56,7 +92,11 @@ static int __init flash_init(void)
 		flash_map.virt = ioremap(flash_map.phys, flash_map.size);
 		pr_notice("Bootbus flash: Setting flash for %luMB flash at "
 			  "0x%08llx\n", flash_map.size >> 20, flash_map.phys);
-		simple_map_init(&flash_map);
+		WARN_ON(!map_bankwidth_supported(flash_map.bankwidth));
+		flash_map.read = octeon_flash_map_read;
+		flash_map.write = octeon_flash_map_write;
+		flash_map.copy_from = octeon_flash_map_copy_from;
+		flash_map.copy_to = octeon_flash_map_copy_to;
 		mymtd = do_map_probe("cfi_probe", &flash_map);
 		if (mymtd) {
 			mymtd->owner = THIS_MODULE;
-- 
2.3.0


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

* [PATCH v2 3/3] MIPS: OCTEON: Use device tree to probe for flash chips.
  2015-03-05 14:31 [PATCH v2 0/3] MIPS: OCTEON: flash: syncronize bootbus access Aleksey Makarov
  2015-03-05 14:31 ` [PATCH v2 1/3] MIPS: OCTEON: Add semaphore to serialize bootbus accesses Aleksey Makarov
  2015-03-05 14:31 ` [PATCH v2 2/3] MIPS: OCTEON: Protect accesses to bootbus flash with octeon_bootbus_sem Aleksey Makarov
@ 2015-03-05 14:31 ` Aleksey Makarov
  2015-03-15 18:30   ` Aaro Koskinen
  2 siblings, 1 reply; 5+ messages in thread
From: Aleksey Makarov @ 2015-03-05 14:31 UTC (permalink / raw)
  To: linux-mips; +Cc: linux-kernel, David Daney, Aleksey Makarov, Ralf Baechle

From: David Daney <david.daney@cavium.com>

Don't assume they are there, the device tree will tell us.

Signed-off-by: David Daney <david.daney@cavium.com>
Signed-off-by: Aleksey Makarov <aleksey.makarov@auriga.com>
---
 arch/mips/cavium-octeon/flash_setup.c | 42 ++++++++++++++++++++++++++++++-----
 1 file changed, 37 insertions(+), 5 deletions(-)

diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
index 39e26df..a3d609d 100644
--- a/arch/mips/cavium-octeon/flash_setup.c
+++ b/arch/mips/cavium-octeon/flash_setup.c
@@ -8,10 +8,11 @@
  * Copyright (C) 2007, 2008 Cavium Networks
  */
 #include <linux/kernel.h>
-#include <linux/export.h>
+#include <linux/module.h>
 #include <linux/semaphore.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/map.h>
+#include <linux/of_platform.h>
 #include <linux/mtd/partitions.h>
 
 #include <asm/octeon/octeon.h>
@@ -66,14 +67,22 @@ static void octeon_flash_map_copy_to(struct map_info *map, unsigned long to,
  *
  * Returns Zero on success
  */
-static int __init flash_init(void)
+static int octeon_flash_probe(struct platform_device *pdev)
 {
+	union cvmx_mio_boot_reg_cfgx region_cfg;
+	u32 cs;
+	int r;
+	struct device_node *np = pdev->dev.of_node;
+
+	r = of_property_read_u32(np, "reg", &cs);
+	if (r)
+		return r;
+
 	/*
 	 * Read the bootbus region 0 setup to determine the base
 	 * address of the flash.
 	 */
-	union cvmx_mio_boot_reg_cfgx region_cfg;
-	region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(0));
+	region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
 	if (region_cfg.s.en) {
 		/*
 		 * The bootloader always takes the flash and sets its
@@ -109,4 +118,27 @@ static int __init flash_init(void)
 	return 0;
 }
 
-late_initcall(flash_init);
+static const struct of_device_id of_flash_match[] = {
+	{
+		.compatible	= "cfi-flash",
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, of_flash_match);
+
+static struct platform_driver of_flash_driver = {
+	.driver = {
+		.name = "octeon-of-flash",
+		.owner = THIS_MODULE,
+		.of_match_table = of_flash_match,
+	},
+	.probe		= octeon_flash_probe,
+};
+
+static int octeon_flash_init(void)
+{
+	return platform_driver_register(&of_flash_driver);
+}
+late_initcall(octeon_flash_init);
+
+MODULE_LICENSE("GPL");
-- 
2.3.0


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

* Re: [PATCH v2 3/3] MIPS: OCTEON: Use device tree to probe for flash chips.
  2015-03-05 14:31 ` [PATCH v2 3/3] MIPS: OCTEON: Use device tree to probe for flash chips Aleksey Makarov
@ 2015-03-15 18:30   ` Aaro Koskinen
  0 siblings, 0 replies; 5+ messages in thread
From: Aaro Koskinen @ 2015-03-15 18:30 UTC (permalink / raw)
  To: Aleksey Makarov; +Cc: linux-mips, linux-kernel, David Daney, Ralf Baechle

Hi,

On Thu, Mar 05, 2015 at 05:31:31PM +0300, Aleksey Makarov wrote:
> From: David Daney <david.daney@cavium.com>
> 
> Don't assume they are there, the device tree will tell us.
> 
> Signed-off-by: David Daney <david.daney@cavium.com>
> Signed-off-by: Aleksey Makarov <aleksey.makarov@auriga.com>

Tested-by: Aaro Koskinen <aaro.koskinen@iki.fi>

A.

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

end of thread, other threads:[~2015-03-15 18:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-05 14:31 [PATCH v2 0/3] MIPS: OCTEON: flash: syncronize bootbus access Aleksey Makarov
2015-03-05 14:31 ` [PATCH v2 1/3] MIPS: OCTEON: Add semaphore to serialize bootbus accesses Aleksey Makarov
2015-03-05 14:31 ` [PATCH v2 2/3] MIPS: OCTEON: Protect accesses to bootbus flash with octeon_bootbus_sem Aleksey Makarov
2015-03-05 14:31 ` [PATCH v2 3/3] MIPS: OCTEON: Use device tree to probe for flash chips Aleksey Makarov
2015-03-15 18:30   ` Aaro Koskinen

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