mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/10] RPi mailbox support
@ 2013-10-19 12:18 Andre Heider
  2013-10-19 12:18 ` [PATCH 01/10] ARM: cache: restore cache functions from the PBL Andre Heider
                   ` (11 more replies)
  0 siblings, 12 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:18 UTC (permalink / raw)
  To: barebox

This adds a bcm2835 mailbox driver for the RPi to talk to the on-SoC
VideoCore. See [1] for a description.

This patchset uses it to get two properties, the eMMC clock and the
memory size.

The RPi backend needs to use this driver early on, namely before the
MMU setup. We also want to use the driver in the future after the MMU setup,
like setting up simplefb for the kernel. Patch 1 and 2 lay the groundwork
for that.

The mailbox driver also needs to handle timouts, so patch 5 and 6 are
making the clocksource accessible earlier.

Patch 7 is the driver itself, providing a helper macro for users based on
a new common macro from patch 3.

Patch 8 and 9 switch the bc2835_mci driver from a local mailbox
implementation to the new driver.

Patch 10 uses the driver to get the proper memory size.

Patch 4 is just a cleanup.

Thanks,
Andre

[1] https://github.com/raspberrypi/firmware/wiki/Mailboxes

Andre Heider (10):
  ARM: cache: restore cache functions from the PBL
  ARM: cache: do not crash when the MMU isn't yet setup
  common: add a macro to align an array on the stack
  ARM: bcm2835: cleanup clock registering
  ARM: bcm2835: register the clocksource driver earlier
  ARM: bcm2835: register the clocksource device earlier
  ARM: bcm2835: add a mailbox driver for VideoCore
  ARM: rpi: register a clkdev for the eMMC clock
  mci: bcm2835: use the registered device clkdev
  ARM: rpi: use the proper ARM memory size

 arch/arm/boards/raspberry-pi/rpi.c        |  75 +++++-
 arch/arm/cpu/cache.c                      |  18 +-
 arch/arm/cpu/start.c                      |   4 +-
 arch/arm/mach-bcm2835/Makefile            |   2 +-
 arch/arm/mach-bcm2835/core.c              |  32 +--
 arch/arm/mach-bcm2835/include/mach/mbox.h | 420 ++++++++++++++++++++++++++++++
 arch/arm/mach-bcm2835/mbox.c              | 152 +++++++++++
 drivers/clocksource/bcm2835.c             |   2 +-
 drivers/mci/mci-bcm2835.c                 |  93 ++-----
 drivers/mci/mci-bcm2835.h                 |  48 ----
 include/common.h                          |  11 +
 11 files changed, 700 insertions(+), 157 deletions(-)
 create mode 100644 arch/arm/mach-bcm2835/include/mach/mbox.h
 create mode 100644 arch/arm/mach-bcm2835/mbox.c

-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 01/10] ARM: cache: restore cache functions from the PBL
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
@ 2013-10-19 12:18 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 02/10] ARM: cache: do not crash when the MMU isn't yet setup Andre Heider
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:18 UTC (permalink / raw)
  To: barebox

When using CONFIG_MMU_EARLY combined with CONFIG_PBL_IMAGE, the barebox
setup reuses the MMU setup from the PBL, but doesn't setup the cache
functions.

Set these up to guarantee proper early cache handing before mmu_initcall().

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/cpu/start.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index f8d343f..f0a7df3 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -70,7 +70,9 @@ static noinline __noreturn void __start(uint32_t membase, uint32_t memsize,
 		endmem &= ~0x3fff;
 		endmem -= SZ_16K; /* ttb */
 
-		if (!IS_ENABLED(CONFIG_PBL_IMAGE)) {
+		if (IS_ENABLED(CONFIG_PBL_IMAGE)) {
+			arm_set_cache_functions();
+		} else {
 			arm_early_mmu_cache_invalidate();
 			mmu_early_enable(membase, memsize, endmem);
 		}
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 02/10] ARM: cache: do not crash when the MMU isn't yet setup
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
  2013-10-19 12:18 ` [PATCH 01/10] ARM: cache: restore cache functions from the PBL Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 03/10] common: add a macro to align an array on the stack Andre Heider
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

Drivers currently cannot implement explicit cache handling and rely on
running the same code before and after mmu_initcall() without crashing.

Depending on the chosen config options, the cache functions are not yet
setup and using them early on ends in a null pointer dereference.

The RPi's mailbox driver is such a case; it requires cache handling once
the MMU is fully set up and yet the RPi setup needs to use the driver to
get the memory size before mem_initcall() and hence mmu_initcall().

Fix this by checking the cache_fns pointer before dereferencing it.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/cpu/cache.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/arch/arm/cpu/cache.c b/arch/arm/cpu/cache.c
index 7aab55b..223e308 100644
--- a/arch/arm/cpu/cache.c
+++ b/arch/arm/cpu/cache.c
@@ -41,32 +41,38 @@ DEFINE_CPU_FNS(v7)
 
 void __dma_clean_range(unsigned long start, unsigned long end)
 {
-	cache_fns->dma_clean_range(start, end);
+	if (cache_fns)
+		cache_fns->dma_clean_range(start, end);
 }
 
 void __dma_flush_range(unsigned long start, unsigned long end)
 {
-	cache_fns->dma_flush_range(start, end);
+	if (cache_fns)
+		cache_fns->dma_flush_range(start, end);
 }
 
 void __dma_inv_range(unsigned long start, unsigned long end)
 {
-	cache_fns->dma_inv_range(start, end);
+	if (cache_fns)
+		cache_fns->dma_inv_range(start, end);
 }
 
 void __mmu_cache_on(void)
 {
-	cache_fns->mmu_cache_on();
+	if (cache_fns)
+		cache_fns->mmu_cache_on();
 }
 
 void __mmu_cache_off(void)
 {
-	cache_fns->mmu_cache_off();
+	if (cache_fns)
+		cache_fns->mmu_cache_off();
 }
 
 void __mmu_cache_flush(void)
 {
-	cache_fns->mmu_cache_flush();
+	if (cache_fns)
+		cache_fns->mmu_cache_flush();
 }
 
 int arm_set_cache_functions(void)
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 03/10] common: add a macro to align an array on the stack
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
  2013-10-19 12:18 ` [PATCH 01/10] ARM: cache: restore cache functions from the PBL Andre Heider
  2013-10-19 12:20 ` [PATCH 02/10] ARM: cache: do not crash when the MMU isn't yet setup Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 04/10] ARM: bcm2835: cleanup clock registering Andre Heider
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

The macro can be used for temporary stack buffers which need to meet
a minimum alignment requirement.

This will be used by bcm2835 mailbox users, where all buffers need to
be aligned.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 include/common.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/common.h b/include/common.h
index 0f0ba08..00f1642 100644
--- a/include/common.h
+++ b/include/common.h
@@ -192,6 +192,17 @@ int run_shell(void);
 #define ARRAY_SIZE(arr)		(sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 #define ARRAY_AND_SIZE(x)	(x), ARRAY_SIZE(x)
 
+/*
+ * The STACK_ALIGN_ARRAY macro is used to allocate a buffer on the stack that
+ * meets a minimum alignment requirement.
+ *
+ * Note that the size parameter is the number of array elements to allocate,
+ * not the number of bytes.
+ */
+#define STACK_ALIGN_ARRAY(type, name, size, align)		\
+	char __##name[sizeof(type) * (size) + (align) - 1];	\
+	type *name = (type *)ALIGN((uintptr_t)__##name, align)
+
 /**
  * container_of - cast a member of a structure out to the containing structure
  * @ptr:	the pointer to the member.
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 04/10] ARM: bcm2835: cleanup clock registering
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (2 preceding siblings ...)
  2013-10-19 12:20 ` [PATCH 03/10] common: add a macro to align an array on the stack Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 05/10] ARM: bcm2835: register the clocksource driver earlier Andre Heider
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

Sync exposed names while at it.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/mach-bcm2835/core.c | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)

diff --git a/arch/arm/mach-bcm2835/core.c b/arch/arm/mach-bcm2835/core.c
index 906e434..6835960 100644
--- a/arch/arm/mach-bcm2835/core.c
+++ b/arch/arm/mach-bcm2835/core.c
@@ -32,37 +32,20 @@
 #include <mach/core.h>
 #include <linux/amba/bus.h>
 
-enum brcm_clks {
-	dummy, clk_ref_3, clk_ref_1, clks_max
-};
-
-static struct clk *clks[clks_max];
-
 static int bcm2835_clk_init(void)
 {
-	int ret;
-
-	clks[dummy] = clk_fixed("dummy", 0);
-	clks[clk_ref_3] = clk_fixed("ref3", 3 * 1000 * 1000);
-	clks[clk_ref_1] = clk_fixed("ref1", 1 * 1000 * 1000);
+	struct clk *clk;
 
-	ret = clk_register_clkdev(clks[dummy], "apb_pclk", NULL);
-	if (ret)
-		goto clk_err;
+	clk = clk_fixed("apb_pclk", 0);
+	clk_register_clkdev(clk, "apb_pclk", NULL);
 
-	ret = clk_register_clkdev(clks[clk_ref_3], NULL, "uart0-pl0110");
-	if (ret)
-		goto clk_err;
+	clk = clk_fixed("uart0-pl0110", 3 * 1000 * 1000);
+	clk_register_clkdev(clk, NULL, "uart0-pl0110");
 
-	ret = clk_register_clkdev(clks[clk_ref_1], NULL, "bcm2835-cs");
-	if (ret)
-		goto clk_err;
+	clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000);
+	clk_register_clkdev(clk, NULL, "bcm2835-cs");
 
 	return 0;
-
-clk_err:
-	return ret;
-
 }
 postcore_initcall(bcm2835_clk_init);
 
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 05/10] ARM: bcm2835: register the clocksource driver earlier
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (3 preceding siblings ...)
  2013-10-19 12:20 ` [PATCH 04/10] ARM: bcm2835: cleanup clock registering Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 06/10] ARM: bcm2835: register the clocksource device earlier Andre Heider
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

RPi's mailbox driver is used early and it needs clock functions to
handle timeouts.

Promote to a core_initcall().

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 drivers/clocksource/bcm2835.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clocksource/bcm2835.c b/drivers/clocksource/bcm2835.c
index d5fe0f0..d1df3d2 100644
--- a/drivers/clocksource/bcm2835.c
+++ b/drivers/clocksource/bcm2835.c
@@ -87,4 +87,4 @@ static int bcm2835_cs_init(void)
 {
 	return platform_driver_register(&bcm2835_cs_driver);
 }
-coredevice_initcall(bcm2835_cs_init);
+core_initcall(bcm2835_cs_init);
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 06/10] ARM: bcm2835: register the clocksource device earlier
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (4 preceding siblings ...)
  2013-10-19 12:20 ` [PATCH 05/10] ARM: bcm2835: register the clocksource driver earlier Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 07/10] ARM: bcm2835: add a mailbox driver for VideoCore Andre Heider
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

RPi's mailbox driver is used early and it needs clock functions to
handle timeouts.

Register the driver straight after its clkdev.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/mach-bcm2835/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-bcm2835/core.c b/arch/arm/mach-bcm2835/core.c
index 6835960..cba7bf6 100644
--- a/arch/arm/mach-bcm2835/core.c
+++ b/arch/arm/mach-bcm2835/core.c
@@ -45,6 +45,8 @@ static int bcm2835_clk_init(void)
 	clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000);
 	clk_register_clkdev(clk, NULL, "bcm2835-cs");
 
+	add_generic_device("bcm2835-cs", DEVICE_ID_SINGLE, NULL, BCM2835_ST_BASE, 0x1C, IORESOURCE_MEM, NULL);
+
 	return 0;
 }
 postcore_initcall(bcm2835_clk_init);
@@ -52,7 +54,6 @@ postcore_initcall(bcm2835_clk_init);
 static int bcm2835_dev_init(void)
 {
 	add_generic_device("bcm2835-gpio", 0, NULL, BCM2835_GPIO_BASE, 0xB0, IORESOURCE_MEM, NULL);
-	add_generic_device("bcm2835-cs", DEVICE_ID_SINGLE, NULL, BCM2835_ST_BASE, 0x1C, IORESOURCE_MEM, NULL);
 	add_generic_device("bcm2835_mci", 0, NULL, BCM2835_EMMC_BASE, 0xFC, IORESOURCE_MEM, NULL);
 	return 0;
 }
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 07/10] ARM: bcm2835: add a mailbox driver for VideoCore
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (5 preceding siblings ...)
  2013-10-19 12:20 ` [PATCH 06/10] ARM: bcm2835: register the clocksource device earlier Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 08/10] ARM: rpi: register a clkdev for the eMMC clock Andre Heider
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

This allows exchanging data with the on-SoC GPU.

Based on U-Boot code by Stephen Warren.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/mach-bcm2835/Makefile            |   2 +-
 arch/arm/mach-bcm2835/include/mach/mbox.h | 420 ++++++++++++++++++++++++++++++
 arch/arm/mach-bcm2835/mbox.c              | 152 +++++++++++
 3 files changed, 573 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-bcm2835/include/mach/mbox.h
 create mode 100644 arch/arm/mach-bcm2835/mbox.c

diff --git a/arch/arm/mach-bcm2835/Makefile b/arch/arm/mach-bcm2835/Makefile
index 820eb10..940f98c 100644
--- a/arch/arm/mach-bcm2835/Makefile
+++ b/arch/arm/mach-bcm2835/Makefile
@@ -1 +1 @@
-obj-y += core.o
+obj-y += core.o mbox.o
diff --git a/arch/arm/mach-bcm2835/include/mach/mbox.h b/arch/arm/mach-bcm2835/include/mach/mbox.h
new file mode 100644
index 0000000..6c36389
--- /dev/null
+++ b/arch/arm/mach-bcm2835/include/mach/mbox.h
@@ -0,0 +1,420 @@
+/*
+ * based on U-Boot code
+ *
+ * (C) Copyright 2012 Stephen Warren
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef _BCM2835_MBOX_H
+#define _BCM2835_MBOX_H
+
+#include <common.h>
+
+/*
+ * The BCM2835 SoC contains (at least) two CPUs; the VideoCore (a/k/a "GPU")
+ * and the ARM CPU. The ARM CPU is often thought of as the main CPU.
+ * However, the VideoCore actually controls the initial SoC boot, and hides
+ * much of the hardware behind a protocol. This protocol is transported
+ * using the SoC's mailbox hardware module.
+ *
+ * The mailbox hardware supports passing 32-bit values back and forth.
+ * Presumably by software convention of the firmware, the bottom 4 bits of the
+ * value are used to indicate a logical channel, and the upper 28 bits are the
+ * actual payload. Various channels exist using these simple raw messages. See
+ * https://github.com/raspberrypi/firmware/wiki/Mailboxes for a list. As an
+ * example, the messages on the power management channel are a bitmask of
+ * devices whose power should be enabled.
+ *
+ * The property mailbox channel passes messages that contain the (16-byte
+ * aligned) ARM physical address of a memory buffer. This buffer is passed to
+ * the VC for processing, is modified in-place by the VC, and the address then
+ * passed back to the ARM CPU as the response mailbox message to indicate
+ * request completion. The buffers have a generic and extensible format; each
+ * buffer contains a standard header, a list of "tags", and a terminating zero
+ * entry. Each tag contains an ID indicating its type, and length fields for
+ * generic parsing. With some limitations, an arbitrary set of tags may be
+ * combined together into a single message buffer. This file defines structs
+ * representing the header and many individual tag layouts and IDs.
+ */
+
+/* Raw mailbox HW */
+
+#define BCM2835_MBOX_PHYSADDR	0x2000b880
+
+struct bcm2835_mbox_regs {
+	u32 read;
+	u32 rsvd0[5];
+	u32 status;
+	u32 config;
+	u32 write;
+};
+
+#define BCM2835_MBOX_STATUS_WR_FULL	0x80000000
+#define BCM2835_MBOX_STATUS_RD_EMPTY	0x40000000
+
+/* Lower 4-bits are channel ID */
+#define BCM2835_CHAN_MASK		0xf
+#define BCM2835_MBOX_PACK(chan, data)	(((data) & (~BCM2835_CHAN_MASK)) | \
+					 (chan & BCM2835_CHAN_MASK))
+#define BCM2835_MBOX_UNPACK_CHAN(val)	((val) & BCM2835_CHAN_MASK)
+#define BCM2835_MBOX_UNPACK_DATA(val)	((val) & (~BCM2835_CHAN_MASK))
+
+/* Property mailbox buffer structures */
+
+#define BCM2835_MBOX_PROP_CHAN		8
+
+/* All message buffers must start with this header */
+struct bcm2835_mbox_hdr {
+	u32 buf_size;
+	u32 code;
+};
+
+#define BCM2835_MBOX_REQ_CODE		0
+#define BCM2835_MBOX_RESP_CODE_SUCCESS	0x80000000
+
+#define BCM2835_MBOX_STACK_ALIGN(type, name) \
+	STACK_ALIGN_ARRAY(type, name, 1, BCM2835_CHAN_MASK + 1)
+
+#define BCM2835_MBOX_INIT_HDR(_m_) { \
+		memset((_m_), 0, sizeof(*(_m_))); \
+		(_m_)->hdr.buf_size = sizeof(*(_m_)); \
+		(_m_)->hdr.code = 0; \
+		(_m_)->end_tag = 0; \
+	}
+
+/*
+ * A message buffer contains a list of tags. Each tag must also start with
+ * a standardized header.
+ */
+struct bcm2835_mbox_tag_hdr {
+	u32 tag;
+	u32 val_buf_size;
+	u32 val_len;
+};
+
+#define BCM2835_MBOX_INIT_TAG(_t_, _id_) { \
+		(_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \
+		(_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \
+		(_t_)->tag_hdr.val_len = sizeof((_t_)->body.req); \
+	}
+
+#define BCM2835_MBOX_INIT_TAG_NO_REQ(_t_, _id_) { \
+		(_t_)->tag_hdr.tag = BCM2835_MBOX_TAG_##_id_; \
+		(_t_)->tag_hdr.val_buf_size = sizeof((_t_)->body); \
+		(_t_)->tag_hdr.val_len = 0; \
+	}
+
+/* When responding, the VC sets this bit in val_len to indicate a response */
+#define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE	0x80000000
+
+/*
+ * Below we define the ID and struct for many possible tags. This header only
+ * defines individual tag structs, not entire message structs, since in
+ * general an arbitrary set of tags may be combined into a single message.
+ * Clients of the mbox API are expected to define their own overall message
+ * structures by combining the header, a set of tags, and a terminating
+ * entry. For example,
+ *
+ * struct msg {
+ *     struct bcm2835_mbox_hdr hdr;
+ *     struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
+ *     ... perhaps other tags here ...
+ *     u32 end_tag;
+ * };
+ */
+
+#define BCM2835_MBOX_TAG_GET_ARM_MEMORY		0x00010005
+
+struct bcm2835_mbox_tag_get_arm_mem {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+		} req;
+		struct {
+			u32 mem_base;
+			u32 mem_size;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_GET_CLOCK_RATE	0x00030002
+
+#define BCM2835_MBOX_CLOCK_ID_EMMC	1
+#define BCM2835_MBOX_CLOCK_ID_UART	2
+#define BCM2835_MBOX_CLOCK_ID_ARM	3
+#define BCM2835_MBOX_CLOCK_ID_CORE	4
+#define BCM2835_MBOX_CLOCK_ID_V3D	5
+#define BCM2835_MBOX_CLOCK_ID_H264	6
+#define BCM2835_MBOX_CLOCK_ID_ISP	7
+#define BCM2835_MBOX_CLOCK_ID_SDRAM	8
+#define BCM2835_MBOX_CLOCK_ID_PIXEL	9
+#define BCM2835_MBOX_CLOCK_ID_PWM	10
+
+struct bcm2835_mbox_tag_get_clock_rate {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+			u32 clock_id;
+		} req;
+		struct {
+			u32 clock_id;
+			u32 rate_hz;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_ALLOCATE_BUFFER	0x00040001
+
+struct bcm2835_mbox_tag_allocate_buffer {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+			u32 alignment;
+		} req;
+		struct {
+			u32 fb_address;
+			u32 fb_size;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_RELEASE_BUFFER		0x00048001
+
+struct bcm2835_mbox_tag_release_buffer {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+		} req;
+		struct {
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_BLANK_SCREEN		0x00040002
+
+struct bcm2835_mbox_tag_blank_screen {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+			/* bit 0 means on, other bits reserved */
+			u32 state;
+		} req;
+		struct {
+			u32 state;
+		} resp;
+	} body;
+};
+
+/* Physical means output signal */
+#define BCM2835_MBOX_TAG_GET_PHYSICAL_W_H	0x00040003
+#define BCM2835_MBOX_TAG_TEST_PHYSICAL_W_H	0x00044003
+#define BCM2835_MBOX_TAG_SET_PHYSICAL_W_H	0x00048003
+
+struct bcm2835_mbox_tag_physical_w_h {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		/* req not used for get */
+		struct {
+			u32 width;
+			u32 height;
+		} req;
+		struct {
+			u32 width;
+			u32 height;
+		} resp;
+	} body;
+};
+
+/* Virtual means display buffer */
+#define BCM2835_MBOX_TAG_GET_VIRTUAL_W_H	0x00040004
+#define BCM2835_MBOX_TAG_TEST_VIRTUAL_W_H	0x00044004
+#define BCM2835_MBOX_TAG_SET_VIRTUAL_W_H	0x00048004
+
+struct bcm2835_mbox_tag_virtual_w_h {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		/* req not used for get */
+		struct {
+			u32 width;
+			u32 height;
+		} req;
+		struct {
+			u32 width;
+			u32 height;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_GET_DEPTH		0x00040005
+#define BCM2835_MBOX_TAG_TEST_DEPTH		0x00044005
+#define BCM2835_MBOX_TAG_SET_DEPTH		0x00048005
+
+struct bcm2835_mbox_tag_depth {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		/* req not used for get */
+		struct {
+			u32 bpp;
+		} req;
+		struct {
+			u32 bpp;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_GET_PIXEL_ORDER	0x00040006
+#define BCM2835_MBOX_TAG_TEST_PIXEL_ORDER	0x00044005
+#define BCM2835_MBOX_TAG_SET_PIXEL_ORDER	0x00048006
+
+#define BCM2835_MBOX_PIXEL_ORDER_BGR		0
+#define BCM2835_MBOX_PIXEL_ORDER_RGB		1
+
+struct bcm2835_mbox_tag_pixel_order {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		/* req not used for get */
+		struct {
+			u32 order;
+		} req;
+		struct {
+			u32 order;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_GET_ALPHA_MODE		0x00040007
+#define BCM2835_MBOX_TAG_TEST_ALPHA_MODE	0x00044007
+#define BCM2835_MBOX_TAG_SET_ALPHA_MODE		0x00048007
+
+#define BCM2835_MBOX_ALPHA_MODE_0_OPAQUE	0
+#define BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT	1
+#define BCM2835_MBOX_ALPHA_MODE_IGNORED		2
+
+struct bcm2835_mbox_tag_alpha_mode {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		/* req not used for get */
+		struct {
+			u32 alpha;
+		} req;
+		struct {
+			u32 alpha;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_GET_PITCH		0x00040008
+
+struct bcm2835_mbox_tag_pitch {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+		} req;
+		struct {
+			u32 pitch;
+		} resp;
+	} body;
+};
+
+/* Offset of display window within buffer */
+#define BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET	0x00040009
+#define BCM2835_MBOX_TAG_TEST_VIRTUAL_OFFSET	0x00044009
+#define BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET	0x00048009
+
+struct bcm2835_mbox_tag_virtual_offset {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		/* req not used for get */
+		struct {
+			u32 x;
+			u32 y;
+		} req;
+		struct {
+			u32 x;
+			u32 y;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_GET_OVERSCAN		0x0004000a
+#define BCM2835_MBOX_TAG_TEST_OVERSCAN		0x0004400a
+#define BCM2835_MBOX_TAG_SET_OVERSCAN		0x0004800a
+
+struct bcm2835_mbox_tag_overscan {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		/* req not used for get */
+		struct {
+			u32 top;
+			u32 bottom;
+			u32 left;
+			u32 right;
+		} req;
+		struct {
+			u32 top;
+			u32 bottom;
+			u32 left;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_GET_PALETTE		0x0004000b
+
+struct bcm2835_mbox_tag_get_palette {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+		} req;
+		struct {
+			u32 data[1024];
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_TEST_PALETTE		0x0004400b
+
+struct bcm2835_mbox_tag_test_palette {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+			u32 offset;
+			u32 num_entries;
+			u32 data[256];
+		} req;
+		struct {
+			u32 is_invalid;
+		} resp;
+	} body;
+};
+
+#define BCM2835_MBOX_TAG_SET_PALETTE		0x0004800b
+
+struct bcm2835_mbox_tag_set_palette {
+	struct bcm2835_mbox_tag_hdr tag_hdr;
+	union {
+		struct {
+			u32 offset;
+			u32 num_entries;
+			u32 data[256];
+		} req;
+		struct {
+			u32 is_invalid;
+		} resp;
+	} body;
+};
+
+/*
+ * Pass a complete property-style buffer to the VC, and wait until it has
+ * been processed.
+ *
+ * This function expects a pointer to the mbox_hdr structure in an attempt
+ * to ensure some degree of type safety. However, some number of tags and
+ * a termination value are expected to immediately follow the header in
+ * memory, as required by the property protocol.
+ *
+ * Returns 0 for success, any other value for error.
+ */
+int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer);
+
+#endif
diff --git a/arch/arm/mach-bcm2835/mbox.c b/arch/arm/mach-bcm2835/mbox.c
new file mode 100644
index 0000000..2bca567
--- /dev/null
+++ b/arch/arm/mach-bcm2835/mbox.c
@@ -0,0 +1,152 @@
+/*
+ * based on U-Boot code
+ *
+ * (C) Copyright 2012 Stephen Warren
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <asm/io.h>
+#include <asm/mmu.h>
+#include <common.h>
+#include <clock.h>
+
+#include <mach/mbox.h>
+
+#define TIMEOUT (MSECOND * 100) /* 100mS */
+
+static int bcm2835_mbox_call_raw(u32 chan, struct bcm2835_mbox_hdr *buffer,
+					u32 *recv)
+{
+	struct bcm2835_mbox_regs __iomem *regs =
+		(struct bcm2835_mbox_regs *)BCM2835_MBOX_PHYSADDR;
+	uint64_t starttime = get_time_ns();
+	u32 send = virt_to_phys(buffer);
+	u32 val;
+
+	if (send & BCM2835_CHAN_MASK) {
+		printf("mbox: Illegal mbox data 0x%08x\n", send);
+		return -EINVAL;
+	}
+
+	/* Drain any stale responses */
+	for (;;) {
+		val = readl(&regs->status);
+		if (val & BCM2835_MBOX_STATUS_RD_EMPTY)
+			break;
+		if (is_timeout(starttime, TIMEOUT)) {
+			printf("mbox: Timeout draining stale responses\n");
+			return -ETIMEDOUT;
+		}
+		val = readl(&regs->read);
+	}
+
+	/* Wait for space to send */
+	for (;;) {
+		val = readl(&regs->status);
+		if (!(val & BCM2835_MBOX_STATUS_WR_FULL))
+			break;
+		if (is_timeout(starttime, TIMEOUT)) {
+			printf("mbox: Timeout waiting for send space\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* Send the request */
+	val = BCM2835_MBOX_PACK(chan, send);
+	debug("mbox: TX raw: 0x%08x\n", val);
+	dma_flush_range(send, send + buffer->buf_size);
+	writel(val, &regs->write);
+
+	/* Wait for the response */
+	for (;;) {
+		val = readl(&regs->status);
+		if (!(val & BCM2835_MBOX_STATUS_RD_EMPTY))
+			break;
+		if (is_timeout(starttime, TIMEOUT)) {
+			printf("mbox: Timeout waiting for response\n");
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* Read the response */
+	val = readl(&regs->read);
+	debug("mbox: RX raw: 0x%08x\n", val);
+	dma_inv_range(send, send + buffer->buf_size);
+
+	/* Validate the response */
+	if (BCM2835_MBOX_UNPACK_CHAN(val) != chan) {
+		printf("mbox: Response channel mismatch\n");
+		return -EIO;
+	}
+
+	*recv = BCM2835_MBOX_UNPACK_DATA(val);
+
+	return 0;
+}
+
+#ifdef DEBUG
+void dump_buf(struct bcm2835_mbox_hdr *buffer)
+{
+	u32 *p;
+	u32 words;
+	int i;
+
+	p = (u32 *)buffer;
+	words = buffer->buf_size / 4;
+	for (i = 0; i < words; i++)
+		printf("    0x%04x: 0x%08x\n", i * 4, p[i]);
+}
+#endif
+
+int bcm2835_mbox_call_prop(u32 chan, struct bcm2835_mbox_hdr *buffer)
+{
+	int ret;
+	u32 rbuffer;
+	struct bcm2835_mbox_tag_hdr *tag;
+	int tag_index;
+
+#ifdef DEBUG
+	printf("mbox: TX buffer\n");
+	dump_buf(buffer);
+#endif
+
+	ret = bcm2835_mbox_call_raw(chan, buffer, &rbuffer);
+	if (ret)
+		return ret;
+	if (rbuffer != (u32)buffer) {
+		printf("mbox: Response buffer mismatch\n");
+		return -EIO;
+	}
+
+#ifdef DEBUG
+	printf("mbox: RX buffer\n");
+	dump_buf(buffer);
+#endif
+
+	/* Validate overall response status */
+	if (buffer->code != BCM2835_MBOX_RESP_CODE_SUCCESS) {
+		printf("mbox: Header response code invalid\n");
+		return -EIO;
+	}
+
+	/* Validate each tag's response status */
+	tag = (void *)(buffer + 1);
+	tag_index = 0;
+	while (tag->tag) {
+		if (!(tag->val_len & BCM2835_MBOX_TAG_VAL_LEN_RESPONSE)) {
+			printf("mbox: Tag %d missing val_len response bit\n",
+				tag_index);
+			return -EIO;
+		}
+		/*
+		 * Clear the reponse bit so clients can just look right at the
+		 * length field without extra processing
+		 */
+		tag->val_len &= ~BCM2835_MBOX_TAG_VAL_LEN_RESPONSE;
+		tag = (void *)(((u8 *)tag) + sizeof(*tag) + tag->val_buf_size);
+		tag_index++;
+	}
+
+	return 0;
+}
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 08/10] ARM: rpi: register a clkdev for the eMMC clock
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (6 preceding siblings ...)
  2013-10-19 12:20 ` [PATCH 07/10] ARM: bcm2835: add a mailbox driver for VideoCore Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:20 ` [PATCH 09/10] mci: bcm2835: use the registered device clkdev Andre Heider
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

Use the mailbox driver to query the clock frequency and create
a clkdev for the bcm2835_mci driver.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/boards/raspberry-pi/rpi.c | 40 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
index 971a603..d3c6b11 100644
--- a/arch/arm/boards/raspberry-pi/rpi.c
+++ b/arch/arm/boards/raspberry-pi/rpi.c
@@ -17,11 +17,44 @@
 #include <init.h>
 #include <fs.h>
 #include <linux/stat.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
 #include <envfs.h>
 #include <asm/armlinux.h>
 #include <generated/mach-types.h>
 
 #include <mach/core.h>
+#include <mach/mbox.h>
+
+struct msg_get_clock_rate {
+	struct bcm2835_mbox_hdr hdr;
+	struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
+	u32 end_tag;
+};
+
+static int rpi_register_clkdev(u32 clock_id, const char *name)
+{
+	BCM2835_MBOX_STACK_ALIGN(struct msg_get_clock_rate, msg);
+	struct clk *clk;
+	int ret;
+
+	BCM2835_MBOX_INIT_HDR(msg);
+	BCM2835_MBOX_INIT_TAG(&msg->get_clock_rate, GET_CLOCK_RATE);
+	msg->get_clock_rate.body.req.clock_id = clock_id;
+
+	ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
+	if (ret)
+		return ret;
+
+	clk = clk_fixed(name, msg->get_clock_rate.body.resp.rate_hz);
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+
+	if (!clk_register_clkdev(clk, NULL, name))
+		return -ENODEV;
+
+	return 0;
+}
 
 static int rpi_mem_init(void)
 {
@@ -40,6 +73,13 @@ static int rpi_console_init(void)
 }
 console_initcall(rpi_console_init);
 
+static int rpi_clock_init(void)
+{
+	rpi_register_clkdev(BCM2835_MBOX_CLOCK_ID_EMMC, "bcm2835_mci0");
+	return 0;
+}
+postconsole_initcall(rpi_clock_init);
+
 static int rpi_env_init(void)
 {
 	struct stat s;
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 09/10] mci: bcm2835: use the registered device clkdev
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (7 preceding siblings ...)
  2013-10-19 12:20 ` [PATCH 08/10] ARM: rpi: register a clkdev for the eMMC clock Andre Heider
@ 2013-10-19 12:20 ` Andre Heider
  2013-10-19 12:21 ` [PATCH 10/10] ARM: rpi: use the proper ARM memory size Andre Heider
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:20 UTC (permalink / raw)
  To: barebox

Switch from local mailbox code to using the newly created clock device.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 drivers/mci/mci-bcm2835.c | 93 ++++++++++-------------------------------------
 drivers/mci/mci-bcm2835.h | 48 ------------------------
 2 files changed, 19 insertions(+), 122 deletions(-)

diff --git a/drivers/mci/mci-bcm2835.c b/drivers/mci/mci-bcm2835.c
index 2ffdeec..7d8997c 100644
--- a/drivers/mci/mci-bcm2835.c
+++ b/drivers/mci/mci-bcm2835.c
@@ -28,13 +28,14 @@
  * Author: Wilhelm Lundgren <wilhelm.lundgren@cybercom.com>
  */
 
-#include <asm/mmu.h>
 #include <common.h>
 #include <init.h>
 #include <mci.h>
 #include <io.h>
 #include <malloc.h>
 #include <clock.h>
+#include <linux/clk.h>
+
 #include "mci-bcm2835.h"
 #include "sdhci.h"
 
@@ -469,53 +470,6 @@ int bcm2835_mci_reset(struct mci_host *mci, struct device_d *mci_dev)
 	return bcm2835_mci_wait_command_done(host);
 }
 
-static u32 bcm2835_mci_get_emmc_clock(struct msg_get_clock_rate *clk_data)
-{
-	u32 val;
-	struct bcm2835_mbox_regs __iomem *regs =
-			(struct bcm2835_mbox_regs *) BCM2835_MBOX_PHYSADDR;
-
-	/*Read out old msg*/
-	while (true) {
-		val = readl(&regs->status);
-		if (val & BCM2835_MBOX_STATUS_RD_EMPTY)
-			break;
-		val = readl(&regs->read);
-	}
-
-	/*Check for ok to write*/
-	while (true) {
-		val = readl(&regs->status);
-		if (!(val & BCM2835_MBOX_STATUS_WR_FULL))
-			break;
-	}
-	val = BCM2835_MBOX_PROP_CHAN + ((u32) &clk_data->hdr);
-	dma_flush_range((u32)clk_data, (u32)clk_data + sizeof(*clk_data));
-	writel(val, &regs->write);
-
-	while (true) {
-		/* Wait for the response */
-		while (true) {
-			val = readl(&regs->status);
-			if (!(val & BCM2835_MBOX_STATUS_RD_EMPTY))
-				break;
-		}
-
-		/* Read the response */
-		val = readl(&regs->read);
-		if ((val & 0x0F) == BCM2835_MBOX_PROP_CHAN)
-			break;
-	}
-
-	dma_inv_range((u32)clk_data, (u32)clk_data + sizeof(*clk_data));
-
-	if ((val & ~0x0F) == ((u32) &clk_data->hdr))
-		if (clk_data->get_clock_rate.tag_hdr.val_len
-				& BCM2835_MBOX_TAG_VAL_LEN_RESPONSE)
-			return 1;
-	return 0;
-}
-
 static int bcm2835_mci_detect(struct device_d *dev)
 {
 	struct bcm2835_mci_host *host = dev->priv;
@@ -526,7 +480,22 @@ static int bcm2835_mci_detect(struct device_d *dev)
 static int bcm2835_mci_probe(struct device_d *hw_dev)
 {
 	struct bcm2835_mci_host *host;
-	struct msg_get_clock_rate *clk_data;
+	static struct clk *clk;
+	int ret;
+
+	clk = clk_get(hw_dev, NULL);
+	if (IS_ERR(clk)) {
+		ret = PTR_ERR(clk);
+		dev_err(hw_dev, "clock not found: %d\n", ret);
+		return ret;
+	}
+
+	ret = clk_enable(clk);
+	if (ret) {
+		dev_err(hw_dev, "clock failed to enable: %d\n", ret);
+		clk_put(clk);
+		return ret;
+	}
 
 	host = xzalloc(sizeof(*host));
 	host->mci.send_cmd = bcm2835_mci_request;
@@ -534,31 +503,7 @@ static int bcm2835_mci_probe(struct device_d *hw_dev)
 	host->mci.init = bcm2835_mci_reset;
 	host->mci.hw_dev = hw_dev;
 	host->hw_dev = hw_dev;
-
-	/* Allocate a buffer thats 16 bytes aligned in memory
-	 * Of the 32 bits address passed into the mbox 28 bits
-	 * are the address of the buffer, lower 4 bits is channel
-	 */
-	clk_data = memalign(16, sizeof(struct msg_get_clock_rate));
-	memset(clk_data, 0, sizeof(struct msg_get_clock_rate));
-	clk_data->hdr.buf_size = sizeof(struct msg_get_clock_rate);
-	clk_data->get_clock_rate.tag_hdr.tag = BCM2835_MBOX_TAG_GET_CLOCK_RATE;
-	clk_data->get_clock_rate.tag_hdr.val_buf_size =
-			sizeof(clk_data->get_clock_rate.body);
-	clk_data->get_clock_rate.tag_hdr.val_len =
-			sizeof(clk_data->get_clock_rate.body.req);
-	clk_data->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
-
-	if (!bcm2835_mci_get_emmc_clock(clk_data)) {
-		dev_warn(host->hw_dev,
-				"Failed getting emmc clock, lets go anyway with 50MHz\n");
-		host->max_clock = 50000000;
-	} else {
-		host->max_clock = clk_data->get_clock_rate.body.resp.rate_hz;
-		dev_info(host->hw_dev, "Got emmc clock at %d Hz\n",
-				host->max_clock);
-	}
-
+	host->max_clock = clk_get_rate(clk);
 	host->regs = dev_request_mem_region(hw_dev, 0);
 	if (host->regs == NULL) {
 		dev_err(host->hw_dev, "Failed request mem region, aborting...\n");
diff --git a/drivers/mci/mci-bcm2835.h b/drivers/mci/mci-bcm2835.h
index 4158a18..2c95e03 100644
--- a/drivers/mci/mci-bcm2835.h
+++ b/drivers/mci/mci-bcm2835.h
@@ -23,51 +23,3 @@
 
 #define MAX_CLK_DIVIDER_V3	2046
 #define MAX_CLK_DIVIDER_V2	256
-
-/*this is only for mbox comms*/
-#define BCM2835_MBOX_PHYSADDR				0x2000b880
-#define BCM2835_MBOX_TAG_GET_CLOCK_RATE		0x00030002
-#define BCM2835_MBOX_CLOCK_ID_EMMC			1
-#define BCM2835_MBOX_STATUS_WR_FULL			0x80000000
-#define BCM2835_MBOX_STATUS_RD_EMPTY		0x40000000
-#define BCM2835_MBOX_PROP_CHAN				8
-#define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE	0x80000000
-
-struct bcm2835_mbox_regs {
-	u32 read;
-	u32 rsvd0[5];
-	u32 status;
-	u32 config;
-	u32 write;
-};
-
-
-struct bcm2835_mbox_hdr {
-	u32 buf_size;
-	u32 code;
-};
-
-struct bcm2835_mbox_tag_hdr {
-	u32 tag;
-	u32 val_buf_size;
-	u32 val_len;
-};
-
-struct bcm2835_mbox_tag_get_clock_rate {
-	struct bcm2835_mbox_tag_hdr tag_hdr;
-	union {
-		struct {
-			u32 clock_id;
-		} req;
-		struct {
-			u32 clock_id;
-			u32 rate_hz;
-		} resp;
-	} body;
-};
-
-struct msg_get_clock_rate {
-	struct bcm2835_mbox_hdr hdr;
-	struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
-	u32 end_tag;
-};
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 10/10] ARM: rpi: use the proper ARM memory size
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (8 preceding siblings ...)
  2013-10-19 12:20 ` [PATCH 09/10] mci: bcm2835: use the registered device clkdev Andre Heider
@ 2013-10-19 12:21 ` Andre Heider
  2013-10-21  8:46 ` [PATCH 00/10] RPi mailbox support Sascha Hauer
  2013-10-22 13:34 ` Sascha Hauer
  11 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-19 12:21 UTC (permalink / raw)
  To: barebox

Use the mailbox driver to query the size. This properly takes the
firmware's VideoCore/ARM memory split into account.

Linux can now be booted with more than 128 MiB.

Signed-off-by: Andre Heider <a.heider@gmail.com>
---
 arch/arm/boards/raspberry-pi/rpi.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/raspberry-pi/rpi.c b/arch/arm/boards/raspberry-pi/rpi.c
index d3c6b11..06c43f3 100644
--- a/arch/arm/boards/raspberry-pi/rpi.c
+++ b/arch/arm/boards/raspberry-pi/rpi.c
@@ -26,12 +26,35 @@
 #include <mach/core.h>
 #include <mach/mbox.h>
 
+struct msg_get_arm_mem {
+	struct bcm2835_mbox_hdr hdr;
+	struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
+	u32 end_tag;
+};
+
 struct msg_get_clock_rate {
 	struct bcm2835_mbox_hdr hdr;
 	struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
 	u32 end_tag;
 };
 
+static int rpi_get_arm_mem(u32 *size)
+{
+	BCM2835_MBOX_STACK_ALIGN(struct msg_get_arm_mem, msg);
+	int ret;
+
+	BCM2835_MBOX_INIT_HDR(msg);
+	BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
+
+	ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
+	if (ret)
+		return ret;
+
+	*size = msg->get_arm_mem.body.resp.mem_size;
+
+	return 0;
+}
+
 static int rpi_register_clkdev(u32 clock_id, const char *name)
 {
 	BCM2835_MBOX_STACK_ALIGN(struct msg_get_clock_rate, msg);
@@ -58,8 +81,16 @@ static int rpi_register_clkdev(u32 clock_id, const char *name)
 
 static int rpi_mem_init(void)
 {
-	bcm2835_add_device_sdram(0);
-	return 0;
+	u32 size = 0;
+	int ret;
+
+	ret = rpi_get_arm_mem(&size);
+	if (ret)
+		printf("could not query ARM memory size\n");
+
+	bcm2835_add_device_sdram(size);
+
+	return ret;
 }
 mem_initcall(rpi_mem_init);
 
-- 
1.8.3.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 00/10] RPi mailbox support
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (9 preceding siblings ...)
  2013-10-19 12:21 ` [PATCH 10/10] ARM: rpi: use the proper ARM memory size Andre Heider
@ 2013-10-21  8:46 ` Sascha Hauer
  2013-10-21 15:32   ` Andre Heider
  2013-10-22 13:34 ` Sascha Hauer
  11 siblings, 1 reply; 16+ messages in thread
From: Sascha Hauer @ 2013-10-21  8:46 UTC (permalink / raw)
  To: Andre Heider; +Cc: barebox

Hi Andre,

On Sat, Oct 19, 2013 at 02:18:41PM +0200, Andre Heider wrote:
> This adds a bcm2835 mailbox driver for the RPi to talk to the on-SoC
> VideoCore. See [1] for a description.
> 
> This patchset uses it to get two properties, the eMMC clock and the
> memory size.
> 
> The RPi backend needs to use this driver early on, namely before the
> MMU setup. We also want to use the driver in the future after the MMU setup,
> like setting up simplefb for the kernel. Patch 1 and 2 lay the groundwork
> for that.
> 
> The mailbox driver also needs to handle timouts, so patch 5 and 6 are
> making the clocksource accessible earlier.
> 
> Patch 7 is the driver itself, providing a helper macro for users based on
> a new common macro from patch 3.
> 
> Patch 8 and 9 switch the bc2835_mci driver from a local mailbox
> implementation to the new driver.
> 
> Patch 10 uses the driver to get the proper memory size.
> 
> Patch 4 is just a cleanup.

I'm in Edinburgh this week and won't have much time. I'll have a loser
look next week. This series isn't lost. Thanks for working on this.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 00/10] RPi mailbox support
  2013-10-21  8:46 ` [PATCH 00/10] RPi mailbox support Sascha Hauer
@ 2013-10-21 15:32   ` Andre Heider
  0 siblings, 0 replies; 16+ messages in thread
From: Andre Heider @ 2013-10-21 15:32 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Mon, Oct 21, 2013 at 10:46:21AM +0200, Sascha Hauer wrote:
> Hi Andre,
> 
> On Sat, Oct 19, 2013 at 02:18:41PM +0200, Andre Heider wrote:
> > This adds a bcm2835 mailbox driver for the RPi to talk to the on-SoC
> > VideoCore. See [1] for a description.
> > 
> > This patchset uses it to get two properties, the eMMC clock and the
> > memory size.
> > 
> > The RPi backend needs to use this driver early on, namely before the
> > MMU setup. We also want to use the driver in the future after the MMU setup,
> > like setting up simplefb for the kernel. Patch 1 and 2 lay the groundwork
> > for that.
> > 
> > The mailbox driver also needs to handle timouts, so patch 5 and 6 are
> > making the clocksource accessible earlier.
> > 
> > Patch 7 is the driver itself, providing a helper macro for users based on
> > a new common macro from patch 3.
> > 
> > Patch 8 and 9 switch the bc2835_mci driver from a local mailbox
> > implementation to the new driver.
> > 
> > Patch 10 uses the driver to get the proper memory size.
> > 
> > Patch 4 is just a cleanup.
> 
> I'm in Edinburgh this week and won't have much time. I'll have a loser
> look next week. This series isn't lost. Thanks for working on this.

No worries, there's no need to rush :)

Regards,
Andre

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 00/10] RPi mailbox support
  2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
                   ` (10 preceding siblings ...)
  2013-10-21  8:46 ` [PATCH 00/10] RPi mailbox support Sascha Hauer
@ 2013-10-22 13:34 ` Sascha Hauer
  2013-10-22 16:57   ` Andre Heider
  11 siblings, 1 reply; 16+ messages in thread
From: Sascha Hauer @ 2013-10-22 13:34 UTC (permalink / raw)
  To: Andre Heider; +Cc: barebox

On Sat, Oct 19, 2013 at 02:18:41PM +0200, Andre Heider wrote:
> This adds a bcm2835 mailbox driver for the RPi to talk to the on-SoC
> VideoCore. See [1] for a description.
> 
> This patchset uses it to get two properties, the eMMC clock and the
> memory size.
> 
> The RPi backend needs to use this driver early on, namely before the
> MMU setup. We also want to use the driver in the future after the MMU setup,
> like setting up simplefb for the kernel. Patch 1 and 2 lay the groundwork
> for that.
> 
> The mailbox driver also needs to handle timouts, so patch 5 and 6 are
> making the clocksource accessible earlier.
> 
> Patch 7 is the driver itself, providing a helper macro for users based on
> a new common macro from patch 3.
> 
> Patch 8 and 9 switch the bc2835_mci driver from a local mailbox
> implementation to the new driver.
> 
> Patch 10 uses the driver to get the proper memory size.
> 
> Patch 4 is just a cleanup.

Applied, thanks. I'll probably have a closer look at the caching bits
later, but looks good for now.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 00/10] RPi mailbox support
  2013-10-22 13:34 ` Sascha Hauer
@ 2013-10-22 16:57   ` Andre Heider
  2013-10-22 21:37     ` Sascha Hauer
  0 siblings, 1 reply; 16+ messages in thread
From: Andre Heider @ 2013-10-22 16:57 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Tue, Oct 22, 2013 at 03:34:05PM +0200, Sascha Hauer wrote:
> On Sat, Oct 19, 2013 at 02:18:41PM +0200, Andre Heider wrote:
> > This adds a bcm2835 mailbox driver for the RPi to talk to the on-SoC
> > VideoCore. See [1] for a description.
> > 
> > This patchset uses it to get two properties, the eMMC clock and the
> > memory size.
> > 
> > The RPi backend needs to use this driver early on, namely before the
> > MMU setup. We also want to use the driver in the future after the MMU setup,
> > like setting up simplefb for the kernel. Patch 1 and 2 lay the groundwork
> > for that.
> > 
> > The mailbox driver also needs to handle timouts, so patch 5 and 6 are
> > making the clocksource accessible earlier.
> > 
> > Patch 7 is the driver itself, providing a helper macro for users based on
> > a new common macro from patch 3.
> > 
> > Patch 8 and 9 switch the bc2835_mci driver from a local mailbox
> > implementation to the new driver.
> > 
> > Patch 10 uses the driver to get the proper memory size.
> > 
> > Patch 4 is just a cleanup.
> 
> Applied, thanks. I'll probably have a closer look at the caching bits
> later, but looks good for now.

Thanks Sascha!
Any particular concerns about the caching bits?

Regards,
Andre

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 00/10] RPi mailbox support
  2013-10-22 16:57   ` Andre Heider
@ 2013-10-22 21:37     ` Sascha Hauer
  0 siblings, 0 replies; 16+ messages in thread
From: Sascha Hauer @ 2013-10-22 21:37 UTC (permalink / raw)
  To: Andre Heider; +Cc: barebox

On Tue, Oct 22, 2013 at 06:57:29PM +0200, Andre Heider wrote:
> On Tue, Oct 22, 2013 at 03:34:05PM +0200, Sascha Hauer wrote:
> > On Sat, Oct 19, 2013 at 02:18:41PM +0200, Andre Heider wrote:
> > > This adds a bcm2835 mailbox driver for the RPi to talk to the on-SoC
> > > VideoCore. See [1] for a description.
> > > 
> > > This patchset uses it to get two properties, the eMMC clock and the
> > > memory size.
> > > 
> > > The RPi backend needs to use this driver early on, namely before the
> > > MMU setup. We also want to use the driver in the future after the MMU setup,
> > > like setting up simplefb for the kernel. Patch 1 and 2 lay the groundwork
> > > for that.
> > > 
> > > The mailbox driver also needs to handle timouts, so patch 5 and 6 are
> > > making the clocksource accessible earlier.
> > > 
> > > Patch 7 is the driver itself, providing a helper macro for users based on
> > > a new common macro from patch 3.
> > > 
> > > Patch 8 and 9 switch the bc2835_mci driver from a local mailbox
> > > implementation to the new driver.
> > > 
> > > Patch 10 uses the driver to get the proper memory size.
> > > 
> > > Patch 4 is just a cleanup.
> > 
> > Applied, thanks. I'll probably have a closer look at the caching bits
> > later, but looks good for now.
> 
> Thanks Sascha!
> Any particular concerns about the caching bits?

I'm concerned about "only invalidate caches if we have functions to do
so". This could lead to some quiet bugs when we really ought to
invalidate caches but missed to setup the functions early enough.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2013-10-22 21:38 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-19 12:18 [PATCH 00/10] RPi mailbox support Andre Heider
2013-10-19 12:18 ` [PATCH 01/10] ARM: cache: restore cache functions from the PBL Andre Heider
2013-10-19 12:20 ` [PATCH 02/10] ARM: cache: do not crash when the MMU isn't yet setup Andre Heider
2013-10-19 12:20 ` [PATCH 03/10] common: add a macro to align an array on the stack Andre Heider
2013-10-19 12:20 ` [PATCH 04/10] ARM: bcm2835: cleanup clock registering Andre Heider
2013-10-19 12:20 ` [PATCH 05/10] ARM: bcm2835: register the clocksource driver earlier Andre Heider
2013-10-19 12:20 ` [PATCH 06/10] ARM: bcm2835: register the clocksource device earlier Andre Heider
2013-10-19 12:20 ` [PATCH 07/10] ARM: bcm2835: add a mailbox driver for VideoCore Andre Heider
2013-10-19 12:20 ` [PATCH 08/10] ARM: rpi: register a clkdev for the eMMC clock Andre Heider
2013-10-19 12:20 ` [PATCH 09/10] mci: bcm2835: use the registered device clkdev Andre Heider
2013-10-19 12:21 ` [PATCH 10/10] ARM: rpi: use the proper ARM memory size Andre Heider
2013-10-21  8:46 ` [PATCH 00/10] RPi mailbox support Sascha Hauer
2013-10-21 15:32   ` Andre Heider
2013-10-22 13:34 ` Sascha Hauer
2013-10-22 16:57   ` Andre Heider
2013-10-22 21:37     ` Sascha Hauer

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