Skip to contentSkip to conversation

Enable BCM2835 mailbox support

RFC PATCH New Craig McGeachie 3 participants 6 messages Sep 13, 2013 – Jun 24, 2014

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/3 Enable BCM2835 mailbox support

Reimplement BCM2835 mailbox support as a device registered with the general purpose mailbox framework.

---

One specific area that I am looking for comment on is the device tree design. I'm not happy with the two attributes for channel numbers and names that have to be matched up in terms of number of elements. I would prefer something like

mailbox {
compatible = "brcm,bcm2835-mbox";
reg = <0x7e00b800 0x400>;
reg = <0x7e00b880 0x40>;

 	interrupts = <0 1>;
	#address-cells = <1>;
	brcm,channel at 0 = {
		reg = <0>;
		brcm,channel-name = "power";
	};
	[...etc...]

};

But I thought that might be too fussy, or too hard for a boot loader to populate.

---

Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt +9 -2
index 75dbb89..1779ad4 100644
@@ -4,12 +4,19 @@ Required properties:
 
 - compatible : should be "brcm,bcm2835-mbox"
 - reg : Specifies base physical address and size of the registers.
-- interrupts : the interrupt number
+- interrupts : the interrupt number. Must be <0 1>, the mailbox interrupt.
+- brcm,channel-nums : The mailbox channels in use.
+- brcm,channel-names : list of symbolic channel names for mailbox clients to
+  use.
+
+The number of channel numbers must match the number of channel names.
 
 Example:
 
 mailbox {
 	compatible = "brcm,bcm2835-mbox";
-	reg = <0x7e00b800 0x400>;
+	reg = <0x7e00b880 0x40>;
 	interrupts = <0 1>;
+	brcm,channel-nums = <0 1 3 8>;
+	brcm,channel-names = "power", "fb", "vchiq", "property";
 };
arch/arm/boot/dts/bcm2835.dtsi +2 -0
index 4fc8a68..88855c0 100644
@@ -33,6 +33,8 @@
 			compatible = "brcm,bcm2835-mbox";
 			reg = <0x7e00b880 0x40>;
 			interrupts = <0 1>;
+			brcm,channel-names = "power", "fb", "vchiq", "property";
+			brcm,channel-nums = <0 1 3 8>;
 		};
 
 		watchdog {
arch/arm/configs/bcm2835_defconfig +7 -5
index 34e9780..cc067bc 100644
@@ -88,6 +88,8 @@ CONFIG_LEDS_TRIGGER_GPIO=y
 CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
 CONFIG_LEDS_TRIGGER_TRANSIENT=y
 CONFIG_LEDS_TRIGGER_CAMERA=y
+CONFIG_MAILBOX=y
+CONFIG_BCM2835_MBOX=y
 # CONFIG_IOMMU_SUPPORT is not set
 CONFIG_EXT2_FS=y
 CONFIG_EXT2_FS_XATTR=y
@@ -109,20 +111,20 @@ CONFIG_NLS_ASCII=y
 CONFIG_NLS_ISO8859_1=y
 CONFIG_NLS_UTF8=y
 CONFIG_PRINTK_TIME=y
+CONFIG_BOOT_PRINTK_DELAY=y
+CONFIG_DYNAMIC_DEBUG=y
+CONFIG_DEBUG_INFO=y
 # CONFIG_ENABLE_WARN_DEPRECATED is not set
 # CONFIG_ENABLE_MUST_CHECK is not set
 CONFIG_UNUSED_SYMBOLS=y
-CONFIG_LOCKUP_DETECTOR=y
-CONFIG_DEBUG_INFO=y
 CONFIG_DEBUG_MEMORY_INIT=y
-CONFIG_BOOT_PRINTK_DELAY=y
+CONFIG_LOCKUP_DETECTOR=y
 CONFIG_SCHED_TRACER=y
 CONFIG_STACK_TRACER=y
 CONFIG_FUNCTION_PROFILER=y
-CONFIG_DYNAMIC_DEBUG=y
+CONFIG_TEST_KSTRTOX=y
 CONFIG_KGDB=y
 CONFIG_KGDB_KDB=y
-CONFIG_TEST_KSTRTOX=y
 CONFIG_STRICT_DEVMEM=y
 CONFIG_DEBUG_LL=y
 CONFIG_EARLY_PRINTK=y
arch/arm/mach-bcm2835/Makefile +1 -1
index 934ab42..4c3892f 100644
@@ -1 +1 @@
-obj-y += bcm2835.o mailbox.o
+obj-y += bcm2835.o
arch/arm/mach-bcm2835/mailbox.c deleted +0 -278

278 lines not on this page · raw message

drivers/mailbox/Kconfig +9 -0
index c8b5c13..b8bb414 100644
@@ -50,4 +50,13 @@ config OMAP_MBOX_KFIFO_SIZE
 	  Specify the default size of mailbox's kfifo buffers (bytes).
 	  This can also be changed at runtime (via the mbox_kfifo_size
 	  module parameter).
+
+config BCM2835_MBOX
+	bool "BCM2835 Mailbox"
+	depends on ARCH_BCM2835
+	help
+	  An implementation of the BCM2385 Mailbox.  It is used to invoke
+	  the services of the Videocore. Say Y here if you want to use the
+	  BCM2835 Mailbox.
+
 endif
drivers/mailbox/Makefile +1 -0
index 2fa343a..a682306 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_OMAP1_MBOX)	+= mailbox_omap1.o
 mailbox_omap1-objs		:= mailbox-omap1.o
 obj-$(CONFIG_OMAP2PLUS_MBOX)	+= mailbox_omap2.o
 mailbox_omap2-objs		:= mailbox-omap2.o
+obj-$(CONFIG_BCM2835_MBOX)	+= bcm2835-mbox.o
drivers/mailbox/bcm2835-mbox.c new file +334 -0

334 lines not on this page · raw message

#1 lore raw

RFC PATCH 2/3 Enable BCM2835 mailbox support

Quoted 9 lines · Craig McGeachie

Reimplement BCM2835 mailbox support as a device registered with the general purpose mailbox framework.

---

One specific area that I am looking for comment on is the device tree design. I'm not happy with the two attributes for channel numbers and names that have to be matched up in terms of number of elements.

That style is very common.

However, I don't think there's any need for channel names at all; devices that exist on the VideoCore side of the mailbox protocol can be represented as child nodes of the main mailbox node, and then their reg property can be used to identify the communication channel; just numbers with no need for names, just like the actual HW (firmware) protocol.

arch/arm/boot/dts/bcm2835.dtsi line 34

Quoted 6 lines

I would prefer something like

mailbox {

arch/arm/boot/dts/bcm2835.dtsi +0 -0
 	compatible = "brcm,bcm2835-mbox";
  	reg = <0x7e00b800 0x400>;
 	reg = <0x7e00b880 0x40>;

You can only have one reg property. It could have two separate entries if required, but I don't see a need for that.

Quoted 2 lines
 	interrupts = <0 1>;
	#address-cells = <1>;

You'll need #size-cells too, probably with value 0 since the concept of size doesn't really apply here.

I wonder if #address-cells might not need to be more than 1 in order to generate unique addresses for the multiple devices that hang off the property channel?

And a blank line before the nodes.

Quoted 1 line
	brcm,channel at 0 = {

Node names don't have a vendor prefix.

Quoted 2 lines
		reg = <0>;
		brcm,channel-name = "power";

I don't see a need for a channel name.

Quoted 6 lines
	};
	[...etc...]

};

But I thought that might be too fussy, or too hard for a boot loader to populate.

Why would the bootloader populate this? Presumably the entire mailbox node (and its children) would be statically part of the DT that the bootloader reads from disk.

Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt Required properties: · line 7

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt +1 -1
index 75dbb89..1779ad4 100644
@@ -4,12 +4,19 @@ Required properties:
 
 - compatible : should be "brcm,bcm2835-mbox"
 - reg : Specifies base physical address and size of the registers.
-- interrupts : the interrupt number
+- interrupts : the interrupt number. Must be <0 1>, the mailbox interrupt.

The binding should specify the schema, not the data. <0 1> is only true in the case where the mailbox IP is hooked into a particular SoC. The binding could theoretically be used on other SoCs with different interrupt assignments.

Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt Required properties: · line 12

Quoted 5 lines
Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt +5 -0
+- brcm,channel-nums : The mailbox channels in use.
+- brcm,channel-names : list of symbolic channel names for mailbox clients to
+  use.
+
+The number of channel numbers must match the number of channel names.

As mentioned above, I see no reason to name/number the channels in this way. I prefer using the reg address in child nodes to represent this information.

Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt Required properties: · line 22

Quoted 10 lines
Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt +3 -1
 Example:
 
 mailbox {
 	compatible = "brcm,bcm2835-mbox";
-	reg = <0x7e00b800 0x400>;
+	reg = <0x7e00b880 0x40>;
 	interrupts = <0 1>;
+	brcm,channel-nums = <0 1 3 8>;
+	brcm,channel-names = "power", "fb", "vchiq", "property";
 };

I would expect to see something like:

mailbox {
	compatible = "brcm,bcm2835-mbox";
	reg = <0x7e00b800 0x400>;
	interrupts = <0 1>;
	#address-cells = <1>;
	#size-cells = <1>;

	regulator at 0 {
		compatible = "brcm,bcm2835-mbox-power";
		reg = <0>;
		... /* various regulator nodes */
	};

	/* or perhaps use @8 for the property FB interface */
	framebuffer at 1 {
		compatible = "brcm,bcm2835-mbox-fb";
		reg = <1>;
		...
	};

	serial at 2 {
		compatible = "brcm,bcm2835-mbox-uart";
		reg = <2>;
		...
	};

	clock at 8 {
		compatible = "brcm,bcm2835-mbox-clock";
		reg = <1>;
		#clock-cells = <1>;
		...
	};

	...
};
#2 lore raw

RFC PATCH 2/3 Enable BCM2835 mailbox support

Quoted 10 lines · Stephen Warren
Quoted 6 lines · Craig McGeachie

I would prefer something like

  mailbox {
  	compatible = "brcm,bcm2835-mbox";
   	reg = <0x7e00b800 0x400>;
  	reg = <0x7e00b880 0x40>;

You can only have one reg property. It could have two separate entries if required, but I don't see a need for that.

Ooops. Sorry, that was a typo. Lubomir's orginal patch had 0x400, and after I figured out 0x40 was a more reasonable size I corrected what I thought was a typo by apparently creating a cut'n'paste error.

Quoted 6 lines
Quoted 3 lines
  	interrupts = <0 1>;
	#address-cells = <1>;

You'll need #size-cells too, probably with value 0 since the concept of size doesn't really apply here.

Yes, I discovered that.

Quoted 3 lines

I wonder if #address-cells might not need to be more than 1 in order to generate unique addresses for the multiple devices that hang off the property channel?

See below.

Quoted 6 lines

And a blank line before the nodes.

Quoted 1 line
	brcm,channel at 0 = {

Node names don't have a vendor prefix.

That's useful to know. I was going by Power_ePAPR_APPROVED_v1.1.pdf which has nothing standard about mailboxes or channels.

Quoted 4 lines
Quoted 2 lines
		reg = <0>;
		brcm,channel-name = "power";

I don't see a need for a channel name.

There is no need for a channel name in the DTS other than documentation, but I now think that a better way to do it is #define's for the numbers.
That works for the reg values, but I'm not so sure about the node names.

Quoted 11 lines
Quoted 7 lines
	};
	[...etc...]

};

But I thought that might be too fussy, or too hard for a boot loader to populate.

Why would the bootloader populate this? Presumably the entire mailbox node (and its children) would be statically part of the DT that the bootloader reads from disk.

That seems like a probable implementation. But I didn't want to second guess the possibility of the boot loader just dynamically generating the lot. Even if that does like a far fetched idea. I only thing that I can be sure of is that the bootloader will have to modify parts of the tree. To the best of my knowledge, it's the only way to get HDMI display dimensions and memory size. And I have both revisions of the model B, so I'd like to get it right.

Quoted 11 lines

Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt Required properties: · line 7

Quoted 6 lines
Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt +1 -1
@@ -4,12 +4,19 @@ Required properties:
 
  - compatible : should be "brcm,bcm2835-mbox"
  - reg : Specifies base physical address and size of the registers.
-- interrupts : the interrupt number
+- interrupts : the interrupt number. Must be <0 1>, the mailbox interrupt.

The binding should specify the schema, not the data. <0 1> is only true in the case where the mailbox IP is hooked into a particular SoC. The binding could theoretically be used on other SoCs with different interrupt assignments.

Noted.

Quoted 9 lines

Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt Required properties: · line 12

Quoted 5 lines
Documentation/devicetree/bindings/mailbox/brcm,bcm2835-mbox.txt +5 -0
+- brcm,channel-nums : The mailbox channels in use.
+- brcm,channel-names : list of symbolic channel names for mailbox clients to
+  use.
+
+The number of channel numbers must match the number of channel names.

As mentioned above, I see no reason to name/number the channels in this way. I prefer using the reg address in child nodes to represent this information.

The channel names simply came about because that's how the mailbox subsystem is implemented. Not that this is a reason to expose names in the DTS. It occurs to me that the string "8" would be just as valid a channel name internally as anything else. Might be a bit cryptic in kernel messages though. As I said, I'm beginning to think that symbolic defines for the channel numbers would be a better form of documentation.
I'd only recently stumbled across a reference to them as something
that dtc now implements.

Quoted 29 lines

I would expect to see something like:

mailbox {
	compatible = "brcm,bcm2835-mbox";
	reg = <0x7e00b800 0x400>;
	interrupts = <0 1>;
	#address-cells = <1>;
	#size-cells = <1>;

	regulator at 0 {
		compatible = "brcm,bcm2835-mbox-power";
		reg = <0>;
		... /* various regulator nodes */
	};

	/* or perhaps use @8 for the property FB interface */
	framebuffer at 1 {
		compatible = "brcm,bcm2835-mbox-fb";
		reg = <1>;
		...
	};

	serial at 2 {
		compatible = "brcm,bcm2835-mbox-uart";
		reg = <2>;
		...
	};

	clock at 8 {
Quoted 8 lines
		compatible = "brcm,bcm2835-mbox-clock";
		reg = <1>;
		#clock-cells = <1>;
		...
	};

	...
};

That's very interesting. I'm not going to make any comments right now.
I need to look at it an think for a few days. But I will leave you
another idea that I started implementing last night:

mailbox {
	compatible = "brcm,bcm2835-mbox";
	reg = <0x7e00b880 0x40>;
	interrupts = <0 1>;
	#address-cells = <1>;
	#size-cells = <0>;
	power at 0 {
		reg = <0>;
	};
	fb at 1 {
		reg = <1>;
	};
	vchiq at 1 {
		reg = <3>;
	};
	props_mbox: property at 8 {
		reg = <8>;
	};
};
thermal {
	compatible = "brcm,bcm2835-thermal";
	brcm,channel = <&props_mbox>;
};

Other than that I have an unresolved bug with getting the right channel number, it seems to work. #address-cells and #size-cells are set as you said, but because the mailbox is not a registered bus, I can't use any of_ functions that rely on it being one. Which means I have to loop over the child node and process the reg properties directly.

I have next to no knowledge about mailboxes on other systems, but I am wondering if actually registering as a bus, or at least a class, would be a good idea. Or some standard of_ support for mailboxes. If it does get written, it won't be me. All I've got is Raspberry Pi's.

Cheers,
Craig.

#3 lore raw

RFC PATCH 2/3 Enable BCM2835 mailbox support

Quoted 20 lines · Craig McGeachie
mailbox {
     compatible = "brcm,bcm2835-mbox";
     reg = <0x7e00b880 0x40>;
     interrupts = <0 1>;
     #address-cells = <1>;
     #size-cells = <0>;
     power at 0 {
         reg = <0>;
     };
     fb at 1 {
         reg = <1>;
     };
     vchiq at 1 {
         reg = <3>;
     };
     props_mbox: property at 8 {
         reg = <8>;
     };
};
Quoted 5 lines
thermal {
     compatible = "brcm,bcm2835-thermal";
     brcm,channel = <&props_mbox>;
};

It's occurred to me that this might not be the best motivating example.
thermal has no register address and does not belong under soc really,
even if it sort of works. It does make more sense for it to live under mailbox, maybe. DMA is the other example that might make more sense.

mailbox {
	compatible = "brcm,bcm2835-mbox";
	reg = <0x7e00b880 0x40>;
	interrupts = <0 1>;
	#address-cells = <1>;
	#size-cells = <0>;
	power at 0 {
		reg = <0>;
	};
	fb at 1 {
		reg = <1>;
	};
	vchiq at 1 {
		reg = <3>;
	};
	props_mbox: property at 8 {
		reg = <8>;
	};
};
dma {
	compatible = "brcm,bcm2835-dma";
	reg = <0x7e007000 0x1000>;
	channel = <&props_mbox>;
	interrupts =
		<1 16>, <1 17>, <1 18>, <1 19>, <1 20>, <1 21>,
		<1 22>, <1 23>, <1 24>, <1 25>, <1 26>, <1 27>,
		<1 28>;
	/* Maybe some other stuff. */
};

/* And thermal somewhere else, I don't know where. */

Access to the properties mailbox channel enables getting a bit mask of DMA channels that the ARM core is permitted to use.

Cheers,
Craig.

#4 lore raw

RFC PATCH 2/3 Enable BCM2835 mailbox support

In reply to Craig McGeachie

Hi Craig,

Quoted 2 lines · Craig McGeachie

Reimplement BCM2835 mailbox support as a device registered with the general purpose mailbox framework.

As the work on common mailbox framework progressed, I've updated the driver to work with v7 of it (I've also ported the cpufreq and vchiq drivers, which I'd like to post once the mailbox framework and your drivers are in):

https://github.com/hackerspace/rpi-linux/commits/lr-vchiq-new-mailbox

I'm not sending inline patches for review, since neither the framework nor your your mbox and thermal drivers are in yet, but I'm wondering if you could take a look and eventually fold the changes back into your drivers? (I've kept them in separate commits in my tree, so that it's easy for you to keep track of the changes).

Thank you,
Lubo

#5 lore raw

RFC PATCH 2/3 Enable BCM2835 mailbox support

Quoted 6 lines · Lubomir Rintel

Hi Craig,
As the work on common mailbox framework progressed, I've updated the driver to work with v7 of it (I've also ported the cpufreq and vchiq drivers, which I'd like to post once the mailbox framework and your drivers are in):

Quoted 7 lines

https://github.com/hackerspace/rpi-linux/commits/lr-vchiq-new-mailbox

I'm not sending inline patches for review, since neither the framework nor your your mbox and thermal drivers are in yet, but I'm wondering if you could take a look and eventually fold the changes back into your drivers? (I've kept them in separate commits in my tree, so that it's easy for you to keep track of the changes).

It's been 9 months since I last looked at this. I've been watching the work on the mailbox framework, with considerable interest, over the last week, but have not actively done anything with it.

I have a few other projects at the moment, and given that I only do this in my spare time in the evenings, it will take several days to get back into it. But I will make an effort to import, build, and try them out. In the meantime I've had a brief look at the changes that you made and can see nothing wrong with any of them. The "useless gotoes" were embarrassing.

Although I can pull your changes back into my tree, I don't feel that this will be helpful in getting them accepted into the mainline. But I'm happy enough to format a patch and submit it somewhere, at some point.

Cheers,
Craig.