Skip to contentSkip to conversation

RPi firmware driver v2

PATCH Superseded Eric Anholt 4 participants 26 messages May 13, 2015 – May 28, 2015 1 message not in the archive

Subsystems (3)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

Here's a new version of the firmware driver. This series applies on top of for-rpi-next from Lee Jones's tree:

git://git.kernel.org/pub/scm/linux/kernel/git/rpi/linux-rpi.git

But it won't actually probe without merging in mailbox-for-next:

https://git.linaro.org/landing-teams/working/fujitsu/integration.git

I've dropped the pm-domains code for now, since it wasn't doing anything useful for us yet without the drivers/base support. However, this code has been useful for building a proper clk provider for the Pi, which can be found at:

https://github.com/anholt/linux/tree/rpi-dt-clocks

Andrea Merello apparently got a cpufreq driver working on top of the non-DT version of this clk provider:

https://github.com/andreamerello/linux-mach-bcm/tree/bcm2836-cpufreq

I think we might manage with a generic dt-cpufreq implementation, though.

#1 lore raw

PATCH v2 1/3 dt/bindings: Add binding for the Raspberry Pi firmware driver

This driver will provide support for calls into the firmware that will be used by other drivers like cpufreq and vc4.

---

v2: Improve commit message, point to mailbox.txt for how mboxes work.

 .../devicetree/bindings/arm/bcm/raspberrypi,firmware.txt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +16 -0
new file mode 100644
index 0000000..33b0043
@@ -0,0 +1,16 @@
+Raspberry Pi VideoCore firmware driver
+
+Required properties:
+
+- compatible:		Should be "rasbperrypi,firmware"
+- mboxes:		Single-entry list which specifies which mailbox
+			  controller and channel is used.  See
+			  Documentation/devicetree/bindings/mailbox/mailbox.txt
+			  for the semantics of this property
+
+Example:
+
+firmware {
+	compatible = "rasbperrypi,firmware";
+	mboxes = <&mailbox>;
+};
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH 1/3 v2] dt/bindings: Add binding for the Raspberry Pi firmware driver

Quoted 18 lines · Eric Anholt

This driver will provide support for calls into the firmware that will be used by other drivers like cpufreq and vc4.

---

v2: Improve commit message, point to mailbox.txt for how mboxes work.

 .../devicetree/bindings/arm/bcm/raspberrypi,firmware.txt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +0 -0
new file mode 100644
index 0000000..33b0043

Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +9 -0
@@ -0,0 +1,16 @@
+Raspberry Pi VideoCore firmware driver
+
+Required properties:
+
+- compatible:		Should be "rasbperrypi,firmware"
+- mboxes:		Single-entry list which specifies which mailbox
+			  controller and channel is used.  See
+			  Documentation/devicetree/bindings/mailbox/mailbox.txt
+			  for the semantics of this property

That's not what it looks like to me. There is no mention of channels in a 0 cell property. Keep it simple. How about:

Phandle to the firmware device's Mailbox. (See: ../mailbox/mailbox.txt for more information)

Quoted 6 lines
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +6 -0
+Example:
+
+firmware {
+	compatible = "rasbperrypi,firmware";
+	mboxes = <&mailbox>;
+};
#3 lore raw

Re: [PATCH 1/3 v2] dt/bindings: Add binding for the Raspberry Pi firmware driver

Quoted 33 lines · Lee Jones
Quoted 18 lines · Eric Anholt

This driver will provide support for calls into the firmware that will be used by other drivers like cpufreq and vc4.

---

v2: Improve commit message, point to mailbox.txt for how mboxes work.

 .../devicetree/bindings/arm/bcm/raspberrypi,firmware.txt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +0 -0
new file mode 100644
index 0000000..33b0043

Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt line 9

Quoted 9 lines
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +9 -0
@@ -0,0 +1,16 @@
+Raspberry Pi VideoCore firmware driver
+
+Required properties:
+
+- compatible:		Should be "rasbperrypi,firmware"
+- mboxes:		Single-entry list which specifies which mailbox
+			  controller and channel is used.  See
+			  Documentation/devicetree/bindings/mailbox/mailbox.txt
+			  for the semantics of this property

That's not what it looks like to me. There is no mention of channels in a 0 cell property. Keep it simple. How about:

Quoted 2 lines

Phandle to the firmware device's Mailbox. (See: ../mailbox/mailbox.txt for more information)

Sounds good to me.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150514/43d070d7/attachment.sig>

#4 lore raw

Re: [PATCH 1/3 v2] dt/bindings: Add binding for the Raspberry Pi firmware driver

In reply to Eric Anholt

Den 13.05.2015 21:00, skrev Eric Anholt:

Quoted 22 lines

This driver will provide support for calls into the firmware that will be used by other drivers like cpufreq and vc4.

---

v2: Improve commit message, point to mailbox.txt for how mboxes work.

  .../devicetree/bindings/arm/bcm/raspberrypi,firmware.txt | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)

create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt

Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +4 -0
new file mode 100644
index 0000000..33b0043
@@ -0,0 +1,16 @@
+Raspberry Pi VideoCore firmware driver
+
+Required properties:
+

Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt line 14

Quoted 10 lines
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +10 -0
+- compatible:		Should be "rasbperrypi,firmware"
+- mboxes:		Single-entry list which specifies which mailbox
+			  controller and channel is used.  See
+			  Documentation/devicetree/bindings/mailbox/mailbox.txt
+			  for the semantics of this property
+
+Example:
+
+firmware {
+	compatible = "rasbperrypi,firmware";

Typo: rasbperrypi -> raspberrypi

Quoted 2 lines
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +2 -0
+	mboxes = <&mailbox>;
+};
#5 lore raw

PATCH v3 1/3 dt/bindings: Add binding for the Raspberry Pi firmware driver

In reply to Eric Anholt

This driver will provide support for calls into the firmware that will be used by other drivers like cpufreq and vc4.
---

v2: Improve commit message, point to mailbox.txt for how mboxes work.
v3: Use Lee's suggestion for mailbox phandle docs, fix spelling of
"raspberry".

 .../devicetree/bindings/arm/bcm/raspberrypi,firmware.txt   | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt
Documentation/devicetree/bindings/arm/bcm/raspberrypi,firmware.txt new file +14 -0
new file mode 100644
index 0000000..dbf60f9
@@ -0,0 +1,14 @@
+Raspberry Pi VideoCore firmware driver
+
+Required properties:
+
+- compatible:		Should be "rasbperrypi,firmware"
+- mboxes:		Phandle to the firmware device's Mailbox.
+			  (See: ../mailbox/mailbox.txt for more information)
+
+Example:
+
+firmware {
+	compatible = "raspberrypi,firmware";
+	mboxes = <&mailbox>;
+};
Signature · 1 line
2.1.4
Acked-by on v3 1/3
#6 lore raw

Re: [PATCH 1/3 v3] dt/bindings: Add binding for the Raspberry Pi firmware driver

Quoted 2 lines · Eric Anholt

This driver will provide support for calls into the firmware that will be used by other drivers like cpufreq and vc4.

This patch,

(although Lee's comment on patch 2/3 about the property name being rather generic does ring true)

#7 lore raw

PATCH v2 2/3 ARM: bcm2835: Add the Raspberry Pi firmware driver

In reply to Eric Anholt

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

---

v2: Drop power-domains stuff for now since we don't have the driver
core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next.

Note that I don't think I've done what srwarren wanted for -EPROBE_DEFER, because I'm not clear what he wants. I think he might just be asking for a function that does:

/*
* Returns 0 if the firmware device is probed and available, otherwise
* -EPROBE_DEFER.
*/
int rpi_firmware_get(struct device_node *firmware_node)

{
	struct platform_device *pdev = of_find_device_by_node(of_node);
	if (!platform_get_drvdata(pdev))
		return -EPROBE_DEFER;
	return 0;
}

EXPORT_SYMBOL(rpi_firmware_get)

If that's all, I'm happy to add it.

Note that a client could currently do this:

	ret = rpi_firmware_property_list(firmware_node, NULL, 0);

in exchange for a bit of overhead in the case that it's actually probed already.

 drivers/firmware/Makefile                          |   1 +
 drivers/firmware/raspberrypi.c                     | 224 +++++++++++++++++++++
 .../soc/bcm2835/raspberrypi-firmware-property.h    | 114 +++++++++++
 3 files changed, 339 insertions(+)
 create mode 100644 drivers/firmware/raspberrypi.c
 create mode 100644 include/soc/bcm2835/raspberrypi-firmware-property.h
drivers/firmware/Makefile +1 -0
index 3fdd391..41ced28 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_ISCSI_IBFT)	+= iscsi_ibft.o
 obj-$(CONFIG_FIRMWARE_MEMMAP)	+= memmap.o
 obj-$(CONFIG_QCOM_SCM)		+= qcom_scm.o
 CFLAGS_qcom_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1)
+obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o
 
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
drivers/firmware/raspberrypi.c new file +224 -0

224 lines not on this page · raw message

include/soc/bcm2835/raspberrypi-firmware-property.h new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.1.4
#8 lore raw

Re: [PATCH 2/3 v2] ARM: bcm2835: Add the Raspberry Pi firmware driver

Den 13.05.2015 21:00, skrev Eric Anholt:

Quoted 45 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

---

v2: Drop power-domains stuff for now since we don't have the driver
core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next.

Note that I don't think I've done what srwarren wanted for -EPROBE_DEFER, because I'm not clear what he wants. I think he might just be asking for a function that does:

/*
* Returns 0 if the firmware device is probed and available, otherwise
* -EPROBE_DEFER.
*/
int rpi_firmware_get(struct device_node *firmware_node)

{
	struct platform_device *pdev = of_find_device_by_node(of_node);
	if (!platform_get_drvdata(pdev))
		return -EPROBE_DEFER;
	return 0;
}

EXPORT_SYMBOL(rpi_firmware_get)

If that's all, I'm happy to add it.

Note that a client could currently do this:

	ret = rpi_firmware_property_list(firmware_node, NULL, 0);

in exchange for a bit of overhead in the case that it's actually probed already.

[...]

Quoted 1 line
drivers/firmware/raspberrypi.c +0 -0

[...]

Quoted 18 lines
drivers/firmware/raspberrypi.c +18 -0
+int rpi_firmware_property_list(struct device_node *of_node,
+			       void *data, size_t tag_size)
+{
+	struct platform_device *pdev = of_find_device_by_node(of_node);
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+	size_t size = tag_size + 12;
+	u32 *buf;
+	dma_addr_t bus_addr;
+	int ret = 0;
+
+	if (!fw)
+		return -EPROBE_DEFER;
+
+	/* Packets are processed a dword at a time. */
+	if (size & 3)
+		return -EINVAL;
+
+	buf = dma_alloc_coherent(fw->cl.dev, PAGE_ALIGN(size), &bus_addr,

[...]

drivers/firmware/raspberrypi.c line 122

Quoted 1 line
drivers/firmware/raspberrypi.c +1 -0
+	dma_free_coherent(NULL, PAGE_ALIGN(size), buf, bus_addr);

Should probably pass the device when freeing as well.

Quoted 6 lines
drivers/firmware/raspberrypi.c +6 -0
+static int rpi_firmware_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	int ret = 0;
+	struct rpi_firmware *fw;
+

drivers/firmware/raspberrypi.c line 177

Quoted 10 lines
drivers/firmware/raspberrypi.c +10 -0
+	fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
+	if (!fw)
+		return -ENOMEM;
+
+	fw->cl.dev = dev;
+	fw->cl.rx_callback = response_callback;
+	fw->cl.tx_block = true;
+
+	fw->chan = mbox_request_channel(&fw->cl, 0);
+	if (IS_ERR(fw->chan)) {

Definition of ret can be move here.

drivers/firmware/raspberrypi.c line 182

Quoted 5 lines
drivers/firmware/raspberrypi.c +5 -0
+		ret = PTR_ERR(fw->chan);
+		/* An -EBUSY from the core means it couldn't find our
+		 * channel, because the mailbox driver hadn't
+		 * registered yet.
+		 */

You forgot to remove this comment.

drivers/firmware/raspberrypi.c line 186

Quoted 4 lines
drivers/firmware/raspberrypi.c +4 -0
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get mbox channel: %d\n", ret);
+		return ret;
+	}

Why not turn the comments into kernel-doc comments:
(Thunderbird converts my tabs into spaces, sorry about that)

/**
* struct rpi_firmware_property_tag_header - Firmware property tag header
* @tag: One of enum_mbox_property_tag.
* @buf_size: The number of bytes in the value buffer following this
struct.
* @req_resp_size: On submit, the length of the request (though it doesn't
* appear to be currently used by the firmware). On
return,
* the length of the response (always 4 byte aligned), with
* the low bit set.
*/

struct rpi_firmware_property_tag_header {
         u32 tag;
         u32 buf_size;
         u32 req_resp_size;
};

/**
* rpi_firmware_property_list - Submit firmware property list

  * @of_node:    Pointer to the firmware Device Tree node.
  * @data:       Buffer holding tags.
  * @tag_size:   Size of tags buffer.

*
* Submits a set of concatenated tags to the VPU firmware through the
* mailbox property interface.
*
* The buffer header and the ending tag are added by this function and
* don't need to be supplied, just the actual tags for your operation.
* See struct rpi_firmware_property_tag_header for the per-tag
* structure.
*/
int rpi_firmware_property_list(struct device_node *of_node,
void *data, size_t tag_size)

/**
* rpi_firmware_property - Submit single firmware property

  * @of_node:    Pointer to the firmware Device Tree node.
  * @tag:        One of enum_mbox_property_tag.
  * @tag_data:   Tag data buffer.
  * @buf_size:   Buffer size.

*
* Submits a single tag to the VPU firmware through the mailbox
* property interface.
*
* This is a convenience wrapper around
* rpi_firmware_property_list() to avoid some of the
* boilerplate in property calls.
*/
int rpi_firmware_property(struct device_node *of_node,
u32 tag, void *tag_data, size_t buf_size)

#9 lore raw

Re: [PATCH 2/3 v2] ARM: bcm2835: Add the Raspberry Pi firmware driver

In reply to Eric Anholt

Den 13.05.2015 21:00, skrev Eric Anholt:

Quoted 6 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

---

[...]

drivers/firmware/raspberrypi.c line 137

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+/*
+ * Submits a single tag to the VPU firmware through the mailbox
+ * property interface.
+ *
+ * This is a convenience wrapper around
+ * rpi_firmware_property_list() to avoid some of the
+ * boilerplate in property calls.
+ */
+int rpi_firmware_property(struct device_node *of_node,
+			  u32 tag, void *tag_data, size_t buf_size)

To use the firmware property functions, I need a DT node pointer. Since Device Tree is dynamic now, should I fetch the firmware node each time, or should I do that in probe and store the node pointer?

Device Tree:

         firmware: firmware {
             compatible = "raspberrypi,firmware";
         };

         thermal {
             compatible = "brcm,bcm2835-thermal";
             firmware = <&firmware>;
         };

Rewritten (not tested) function from downstream bcm2835-thermal driver:

static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev,
unsigned long *temp, unsigned tag_id)

{
     struct device *dev = <get device somehow>;
     struct device_node *np;
     struct {
         u32 id;
         u32 val;
     } tag_buf;

     np = of_parse_phandle(dev->of_node, "firmware", 0);
     if (!np)
         return -EINVAL;

     ret = rpi_firmware_property(np, tag_id, &tag_buf, sizeof(tag_buf));
     if (ret)
         return ret;

     *temp = val;

     return 0;
}
#10 lore raw

Re: [PATCH 2/3 v2] ARM: bcm2835: Add the Raspberry Pi firmware driver

Quoted 26 lines · Noralf Tr?nnes

Den 13.05.2015 21:00, skrev Eric Anholt:

Quoted 6 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

---

[...]

drivers/firmware/raspberrypi.c line 137

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+/*
+ * Submits a single tag to the VPU firmware through the mailbox
+ * property interface.
+ *
+ * This is a convenience wrapper around
+ * rpi_firmware_property_list() to avoid some of the
+ * boilerplate in property calls.
+ */
+int rpi_firmware_property(struct device_node *of_node,
+			  u32 tag, void *tag_data, size_t buf_size)

To use the firmware property functions, I need a DT node pointer. Since Device Tree is dynamic now, should I fetch the firmware node each time, or should I do that in probe and store the node pointer?

Device Tree:

Quoted 8 lines
         firmware: firmware {
             compatible = "raspberrypi,firmware";
         };

         thermal {
             compatible = "brcm,bcm2835-thermal";
             firmware = <&firmware>;
         };

I'm doing it in probe in my clients -- I don't see why the firmware
device's node would change.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150518/8519ace7/attachment.sig>

#11 lore raw

PATCH v3 2/3 ARM: bcm2835: Add the Raspberry Pi firmware driver

In reply to Eric Anholt

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

---

v2: Drop power-domains stuff for now since we don't have the driver
core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next.

v3: Use kernel-doc style for big comments (from Noralf), drop stale
comment, use "dev" when freeing DMA as well.

 drivers/firmware/Makefile                          |   1 +
 drivers/firmware/raspberrypi.c                     | 230 +++++++++++++++++++++
 .../soc/bcm2835/raspberrypi-firmware-property.h    | 112 ++++++++++
 3 files changed, 343 insertions(+)
 create mode 100644 drivers/firmware/raspberrypi.c
 create mode 100644 include/soc/bcm2835/raspberrypi-firmware-property.h
drivers/firmware/Makefile +1 -0
index 3fdd391..41ced28 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_ISCSI_IBFT)	+= iscsi_ibft.o
 obj-$(CONFIG_FIRMWARE_MEMMAP)	+= memmap.o
 obj-$(CONFIG_QCOM_SCM)		+= qcom_scm.o
 CFLAGS_qcom_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1)
+obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o
 
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
drivers/firmware/raspberrypi.c new file +230 -0

230 lines not on this page · raw message

include/soc/bcm2835/raspberrypi-firmware-property.h new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.1.4

A message that is not in the archive (sent off-list or not yet received): 20150528112610.GO11677@x1

#13 lore raw

Re: [PATCH 2/3 v2] ARM: bcm2835: Add the Raspberry Pi firmware driver

Few nits, nothing major.

Quoted 73 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

---

v2: Drop power-domains stuff for now since we don't have the driver
core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next.

Note that I don't think I've done what srwarren wanted for -EPROBE_DEFER, because I'm not clear what he wants. I think he might just be asking for a function that does:

/*
* Returns 0 if the firmware device is probed and available, otherwise
* -EPROBE_DEFER.
*/
int rpi_firmware_get(struct device_node *firmware_node)

{
	struct platform_device *pdev = of_find_device_by_node(of_node);
	if (!platform_get_drvdata(pdev))
		return -EPROBE_DEFER;
	return 0;
}

EXPORT_SYMBOL(rpi_firmware_get)

If that's all, I'm happy to add it.

Note that a client could currently do this:

	ret = rpi_firmware_property_list(firmware_node, NULL, 0);

in exchange for a bit of overhead in the case that it's actually probed already.

 drivers/firmware/Makefile                          |   1 +
 drivers/firmware/raspberrypi.c                     | 224 +++++++++++++++++++++
 .../soc/bcm2835/raspberrypi-firmware-property.h    | 114 +++++++++++
 3 files changed, 339 insertions(+)
 create mode 100644 drivers/firmware/raspberrypi.c
 create mode 100644 include/soc/bcm2835/raspberrypi-firmware-property.h
drivers/firmware/Makefile +1 -0
index 3fdd391..41ced28 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_ISCSI_IBFT)	+= iscsi_ibft.o
 obj-$(CONFIG_FIRMWARE_MEMMAP)	+= memmap.o
 obj-$(CONFIG_QCOM_SCM)		+= qcom_scm.o
 CFLAGS_qcom_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1)
+obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o
 
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
drivers/firmware/raspberrypi.c new file +2 -0
new file mode 100644
index 0000000..61bde1b
@@ -0,0 +1,224 @@
+/*
+ *  Copyright ? 2015 Broadcom

drivers/firmware/raspberrypi.c line 12

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/*
+ * Defines interfaces for interacting wtih the Raspberry Pi firmware's
+ * property channel.
+ */

No need to separate this from the header comment above.

Quoted 61 lines
drivers/firmware/raspberrypi.c new file +61 -0
+#include <linux/dma-mapping.h>
+#include <linux/mailbox_client.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <soc/bcm2835/raspberrypi-firmware-property.h>
+
+#define MBOX_MSG(chan, data28)		(((data28) & ~0xf) | ((chan) & 0xf))
+#define MBOX_CHAN(msg)			((msg) & 0xf)
+#define MBOX_DATA28(msg)		((msg) & ~0xf)
+#define MBOX_CHAN_PROPERTY		8
+
+struct rpi_firmware {
+	struct mbox_client cl;
+	struct mbox_chan *chan; /* The property channel. */
+	struct completion c;
+	u32 enabled;
+};
+
+static DEFINE_MUTEX(transaction_lock);
+
+static void response_callback(struct mbox_client *cl, void *msg)
+{
+	struct rpi_firmware *fw = container_of(cl, struct rpi_firmware, cl);
+	complete(&fw->c);
+}
+
+/*
+ * Sends a request to the firmware through the BCM2835 mailbox driver,
+ * and synchronously waits for the reply.
+ */
+static int
+rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data)
+{
+	u32 message = MBOX_MSG(chan, data);
+	int ret;
+
+	WARN_ON(data & 0xf);
+
+	mutex_lock(&transaction_lock);
+	reinit_completion(&fw->c);
+	ret = mbox_send_message(fw->chan, &message);
+	if (ret >= 0) {
+		wait_for_completion(&fw->c);
+		ret = 0;
+	} else {
+		dev_err(fw->cl.dev, "mbox_send_message returned %d\n", ret);
+	}
+	mutex_unlock(&transaction_lock);
+
+	return ret;
+}
+
+/*
+ * Submits a set of concatenated tags to the VPU firmware through the
+ * mailbox property interface.
+ *
+ * The buffer header and the ending tag are added by this function and
+ * don't need to be supplied, just the actual tags for your operation.
+ * See struct rpi_firmware_property_tag_header for the per-tag
+ * structure.

drivers/firmware/raspberrypi.c line 84

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+ */
+int rpi_firmware_property_list(struct device_node *of_node,
+			       void *data, size_t tag_size)
+{
+	struct platform_device *pdev = of_find_device_by_node(of_node);
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+	size_t size = tag_size + 12;
+	u32 *buf;
+	dma_addr_t bus_addr;
+	int ret = 0;

No need to re-initialise.

Quoted 95 lines
drivers/firmware/raspberrypi.c new file +95 -0
+	if (!fw)
+		return -EPROBE_DEFER;
+
+	/* Packets are processed a dword at a time. */
+	if (size & 3)
+		return -EINVAL;
+
+	buf = dma_alloc_coherent(fw->cl.dev, PAGE_ALIGN(size), &bus_addr,
+				 GFP_ATOMIC);
+	if (!buf)
+		return -ENOMEM;
+
+	/* The firmware will error out without parsing in this case. */
+	WARN_ON(size >= 1024 * 1024);
+
+	buf[0] = size;
+	buf[1] = RPI_FIRMWARE_STATUS_REQUEST;
+	memcpy(&buf[2], data, tag_size);
+	buf[size / 4 - 1] = RPI_FIRMWARE_PROPERTY_END;
+	wmb();
+
+	ret = rpi_firmware_transaction(fw, MBOX_CHAN_PROPERTY, bus_addr);
+
+	rmb();
+	memcpy(data, &buf[2], tag_size);
+	if (ret == 0 && buf[1] != RPI_FIRMWARE_STATUS_SUCCESS) {
+		/*
+		 * The tag name here might not be the one causing the
+		 * error, if there were multiple tags in the request.
+		 * But single-tag is the most common, so go with it.
+		 */
+		dev_err(fw->cl.dev, "Request 0x%08x returned status 0x%08x\n",
+			buf[2], buf[1]);
+		ret = -EINVAL;
+	}
+
+	dma_free_coherent(NULL, PAGE_ALIGN(size), buf, bus_addr);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(rpi_firmware_property_list);
+
+/*
+ * Submits a single tag to the VPU firmware through the mailbox
+ * property interface.
+ *
+ * This is a convenience wrapper around
+ * rpi_firmware_property_list() to avoid some of the
+ * boilerplate in property calls.
+ */
+int rpi_firmware_property(struct device_node *of_node,
+			  u32 tag, void *tag_data, size_t buf_size)
+{
+	/* Single tags are very small (generally 8 bytes), so the
+	 * stack should be safe.
+	 */
+	u8 data[buf_size + sizeof(struct rpi_firmware_property_tag_header)];
+	struct rpi_firmware_property_tag_header *header =
+		(struct rpi_firmware_property_tag_header *)data;
+	int ret;
+
+	header->tag = tag;
+	header->buf_size = buf_size;
+	header->req_resp_size = 0;
+	memcpy(data + sizeof(struct rpi_firmware_property_tag_header),
+	       tag_data, buf_size);
+
+	ret = rpi_firmware_property_list(of_node, &data, sizeof(data));
+	memcpy(tag_data,
+	       data + sizeof(struct rpi_firmware_property_tag_header),
+	       buf_size);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(rpi_firmware_property);
+
+static int rpi_firmware_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	int ret = 0;
+	struct rpi_firmware *fw;
+
+	fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
+	if (!fw)
+		return -ENOMEM;
+
+	fw->cl.dev = dev;
+	fw->cl.rx_callback = response_callback;
+	fw->cl.tx_block = true;
+
+	fw->chan = mbox_request_channel(&fw->cl, 0);
+	if (IS_ERR(fw->chan)) {
+		ret = PTR_ERR(fw->chan);
+		/* An -EBUSY from the core means it couldn't find our
+		 * channel, because the mailbox driver hadn't

drivers/firmware/raspberrypi.c line 190

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+		 * registered yet.
+		 */
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get mbox channel: %d\n", ret);
+		return ret;
+	}
+
+	init_completion(&fw->c);
+
+	dev_info(dev, "Firmware driver\n");

We don't normally print unless data (such as version/revision number) has been acquired from the h/w.

Quoted 6 lines
drivers/firmware/raspberrypi.c new file +6 -0
+	platform_set_drvdata(pdev, fw);
+
+	return 0;
+}
+
+static int rpi_firmware_remove(struct platform_device *pdev)

drivers/firmware/raspberrypi.c line 206

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+{
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+
+	mbox_free_channel(fw->chan);
+
+	return 0;
+}
+
+static const struct of_device_id rpi_firmware_of_match[] = {
+	{ .compatible = "raspberrypi,firmware", },

"firmware" sounds very generic. Is there any other information you can use to make it more specific, in order to future-proof the addition of new incarnations? I'm thinking "bcm2835-firmware" for instance.

drivers/firmware/raspberrypi.c line 214

Quoted 8 lines
drivers/firmware/raspberrypi.c new file +8 -0
+	{},
+};
+MODULE_DEVICE_TABLE(of, rpi_firmware_of_match);
+
+static struct platform_driver rpi_firmware_driver = {
+	.driver = {
+		.name = "raspberrypi-firmware",
+		.owner = THIS_MODULE,

Remove this, it's taken care of elsewhere.

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+		.of_match_table = rpi_firmware_of_match,
+	},
+	.probe		= rpi_firmware_probe,
+	.remove		= rpi_firmware_remove,
+};
+module_platform_driver(rpi_firmware_driver);
+
+MODULE_AUTHOR("Eric Anholt <[email protected]>");
+MODULE_DESCRIPTION("Raspberry Pi firmware driver");
+MODULE_LICENSE("GPL v2");
#14 lore raw

PATCH v4 2/3 ARM: bcm2835: Add the Raspberry Pi firmware driver

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

---

v2: Drop power-domains stuff for now since we don't have the driver
core support to make it useful. Move to drivers/firmware/. Capitalize the enums. De-global the firmware variable. Use the firmware device to allocate our DMA buffer, so that the dma-ranges DT property gets respected. Simplify the property tag transaction interface even more, leaving a multi-tag interface still available. For conciseness, rename "raspberrypi" to "rpi" on all functions/enums/structs, and the "firmware" variable to "fw". Print when the driver is probed successfully, since debugging -EPROBE_DEFER handling is such a big part of bcm2835 development. Drop -EBUSY mailbox handling since the mailbox core has been fixed to return -EPROBE_DEFER in -next.

v3: Use kernel-doc style for big comments (from Noralf), drop stale
comment, use "dev" when freeing DMA as well.

v4: Move description comment into copyright comment, drop a dead
initialization of "ret", and print the firmware revision at probe time.

 drivers/firmware/Makefile                          |   1 +
 drivers/firmware/raspberrypi.c                     | 248 +++++++++++++++++++++
 .../soc/bcm2835/raspberrypi-firmware-property.h    | 112 ++++++++++
 3 files changed, 361 insertions(+)
 create mode 100644 drivers/firmware/raspberrypi.c
 create mode 100644 include/soc/bcm2835/raspberrypi-firmware-property.h
drivers/firmware/Makefile +1 -0
index 3fdd391..41ced28 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_ISCSI_IBFT)	+= iscsi_ibft.o
 obj-$(CONFIG_FIRMWARE_MEMMAP)	+= memmap.o
 obj-$(CONFIG_QCOM_SCM)		+= qcom_scm.o
 CFLAGS_qcom_scm.o :=$(call as-instr,.arch_extension sec,-DREQUIRES_SEC=1)
+obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o
 
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-$(CONFIG_EFI)		+= efi/
drivers/firmware/raspberrypi.c new file +248 -0

248 lines not on this page · raw message

include/soc/bcm2835/raspberrypi-firmware-property.h new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.1.4
#15 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

Quoted 3 lines · Eric Anholt

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

This thread was rather hard to follow since updated versions of patches were sent "in response" to the original posting rather than as a new thread. Generally it's best to post a complete copy of each new version of the series, and as a completely standalone thread.

drivers/firmware/Makefile

Quoted 3 lines
drivers/firmware/Makefile +1 -0
 
+obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o

I think this warrants its own Kconfig option that depends on _MBOX.

drivers/firmware/raspberrypi.c line 82

Quoted 6 lines
drivers/firmware/raspberrypi.c +4 -0
 
+int rpi_firmware_property_list(struct device_node *of_node,
+			       void *data, size_t tag_size)
+{
+	struct platform_device *pdev = of_find_device_by_node(of_node);

I would expect the of_node -> pdev mapping to happen at client device probe time. Simplest for this driver would be if the client-probe-time-mapping function returned the "struct rpi_firmware" and the client passed that to this function.

drivers/firmware/raspberrypi.c line 90

Quoted 8 lines
drivers/firmware/raspberrypi.c +8 -0
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+	size_t size = tag_size + 12;
+	u32 *buf;
+	dma_addr_t bus_addr;
+	int ret;
+
+	if (!fw)
+		return -EPROBE_DEFER;

That return code should only be used in functions called at probe time. While I do see the expectation is that clients call this function once at probe time and hence guarantee to see -EPROBE_DEFER at probe time (if at all), it's rather odd for a function that's intended to be called at times other that probe() to ever have the possibility of returning -EPROBE_DEFER. If somehow that values gets returned at another time, it's going to be rather confusing to the client.

drivers/firmware/raspberrypi.c line 107

Quoted 4 lines
drivers/firmware/raspberrypi.c +4 -0
+	buf[0] = size;
+	buf[1] = RPI_FIRMWARE_STATUS_REQUEST;
+	memcpy(&buf[2], data, tag_size);
+	buf[size / 4 - 1] = RPI_FIRMWARE_PROPERTY_END;

Out of curiosity, why not require the client to format the entire message itself? In theory at least, the client could submit a whole "string" of tags at once, so it really seems like the client should be constructing the whole message.

Still, this is something that's easy to modify later without affecting much (and in particular, has zero impact on DT), so feel free to ignore this for now.

...

drivers/firmware/raspberrypi.c line 123

Quoted 10 lines
drivers/firmware/raspberrypi.c +10 -0
+	if (ret == 0 && buf[1] != RPI_FIRMWARE_STATUS_SUCCESS) {
+		/*
+		 * The tag name here might not be the one causing the
+		 * error, if there were multiple tags in the request.
+		 * But single-tag is the most common, so go with it.
+		 */
+		dev_err(fw->cl.dev, "Request 0x%08x returned status 0x%08x\n",
+			buf[2], buf[1]);
+		ret = -EINVAL;
+	}

If this driver were solely a transport, and required the client driver to construct the whole message and parse the whole response, the gotcha that's documented above would be solved; the client would know exactly which set of tags to look at for errors.

Alternatively, iterating over all the tags is quite simple, since each one has a size field and there's a sentinel tag at the end. That enhancement could also be added later though.

Quoted 6 lines
drivers/firmware/raspberrypi.c +6 -0
+rpi_firmware_print_firmware_revision(struct device *dev)
+{
+	u32 packet;
+	int ret = rpi_firmware_property(dev->of_node,
+					RPI_FIRMWARE_GET_FIRMWARE_REVISION,
+					&packet, sizeof(packet));

...

drivers/firmware/raspberrypi.c line 182

Quoted 1 line
drivers/firmware/raspberrypi.c +1 -0
+		time_to_tm(packet, 0, &tm);

Oh, the revision value is a time? Is so, it'd be nice if the documentation could be updated to state this:

https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface

#16 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

Den 28.05.2015 23:28, skrev Stephen Warren:

Quoted 4 lines · Eric Anholt
Quoted 3 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 8 lines

drivers/firmware/raspberrypi.c line 82

Quoted 4 lines
drivers/firmware/raspberrypi.c new file +4 -0
+int rpi_firmware_property_list(struct device_node *of_node,
+			       void *data, size_t tag_size)
+{
+	struct platform_device *pdev = of_find_device_by_node(of_node);

I would expect the of_node -> pdev mapping to happen at client device probe time. Simplest for this driver would be if the client-probe-time-mapping function returned the "struct rpi_firmware" and the client passed that to this function.

What if the firmware driver/device is removed or reloaded? In that case the client has an invalid pointer. It wouldn't know about the change.

#17 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

Quoted 16 lines · Noralf Tr?nnes

Den 28.05.2015 23:28, skrev Stephen Warren:

Quoted 4 lines · Eric Anholt
Quoted 3 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 8 lines

drivers/firmware/raspberrypi.c line 82

Quoted 4 lines
drivers/firmware/raspberrypi.c new file +4 -0
+int rpi_firmware_property_list(struct device_node *of_node,
+                   void *data, size_t tag_size)
+{
+    struct platform_device *pdev = of_find_device_by_node(of_node);

I would expect the of_node -> pdev mapping to happen at client device probe time. Simplest for this driver would be if the client-probe-time-mapping function returned the "struct rpi_firmware" and the client passed that to this function.

Quoted 3 lines

What if the firmware driver/device is removed or reloaded? In that case the client has an invalid pointer. It wouldn't know about the change.

A provider can't be removed if it has clients. So, you'd have to remove all clients first, then remove the provider. This may require adding some code to increment/decrement the module use count when clients look up the provider and are themselves removed.

#18 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

In reply to Stephen Warren
Quoted 9 lines · Stephen Warren
Quoted 3 lines · Eric Anholt

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

This thread was rather hard to follow since updated versions of patches were sent "in response" to the original posting rather than as a new thread. Generally it's best to post a complete copy of each new version of the series, and as a completely standalone thread.

Will do.

Quoted 5 lines

drivers/firmware/Makefile

Quoted 3 lines
drivers/firmware/Makefile +1 -0
 
+obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o

I think this warrants its own Kconfig option that depends on _MBOX.

Done, called it RASPBERRPI_FIRMWARE

Quoted 11 lines

drivers/firmware/raspberrypi.c line 82

Quoted 6 lines
drivers/firmware/raspberrypi.c +4 -0
 
+int rpi_firmware_property_list(struct device_node *of_node,
+			       void *data, size_t tag_size)
+{
+	struct platform_device *pdev = of_find_device_by_node(of_node);

I would expect the of_node -> pdev mapping to happen at client device probe time. Simplest for this driver would be if the client-probe-time-mapping function returned the "struct rpi_firmware" and the client passed that to this function.

Done.

Quoted 9 lines

drivers/firmware/raspberrypi.c line 90

Quoted 8 lines
drivers/firmware/raspberrypi.c +8 -0
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+	size_t size = tag_size + 12;
+	u32 *buf;
+	dma_addr_t bus_addr;
+	int ret;
+
+	if (!fw)
+		return -EPROBE_DEFER;
Quoted 7 lines

That return code should only be used in functions called at probe time. While I do see the expectation is that clients call this function once at probe time and hence guarantee to see -EPROBE_DEFER at probe time (if at all), it's rather odd for a function that's intended to be called at times other that probe() to ever have the possibility of returning -EPROBE_DEFER. If somehow that values gets returned at another time, it's going to be rather confusing to the client.

Dropped now that I'm passing fw in.

Quoted 9 lines

drivers/firmware/raspberrypi.c line 107

Quoted 4 lines
drivers/firmware/raspberrypi.c +4 -0
+	buf[0] = size;
+	buf[1] = RPI_FIRMWARE_STATUS_REQUEST;
+	memcpy(&buf[2], data, tag_size);
+	buf[size / 4 - 1] = RPI_FIRMWARE_PROPERTY_END;

Out of curiosity, why not require the client to format the entire message itself? In theory at least, the client could submit a whole "string" of tags at once, so it really seems like the client should be constructing the whole message.

Because it's something extra for the client to screw up? I mean, if we were going for super high performance, we'd have the client asking us for a DMA buffer to write into, and they'd write the whole thing, and submit that back to us. But we don't need that, because the property channel is used so rarely.

I briefly used multi-tag in a not-for-upstream KMS-using-the-firmware
branch, but it turned out the FB MBOX channel was strictly better (once
I worked around a fw bug).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150528/c3a5e414/attachment.sig>

#19 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

In reply to Eric Anholt

Den 28.05.2015 20:33, skrev Eric Anholt:

Quoted 5 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 25 lines
drivers/firmware/raspberrypi.c new file +25 -0
+static int rpi_firmware_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rpi_firmware *fw;
+
+	fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
+	if (!fw)
+		return -ENOMEM;
+
+	fw->cl.dev = dev;
+	fw->cl.rx_callback = response_callback;
+	fw->cl.tx_block = true;
+
+	fw->chan = mbox_request_channel(&fw->cl, 0);
+	if (IS_ERR(fw->chan)) {
+		int ret = PTR_ERR(fw->chan);
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get mbox channel: %d\n", ret);
+		return ret;
+	}
+
+	init_completion(&fw->c);
+
+	platform_set_drvdata(pdev, fw);
+

drivers/firmware/raspberrypi.c line 225

Quoted 10 lines
drivers/firmware/raspberrypi.c new file +10 -0
+	rpi_firmware_print_firmware_revision(dev);
+
+	return 0;
+}
+
+static int rpi_firmware_remove(struct platform_device *pdev)
+{
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+
+	mbox_free_channel(fw->chan);

I guess driver data has to be reset here:
platform_set_drvdata(pdev, NULL);

Quoted 3 lines
drivers/firmware/raspberrypi.c new file +3 -0
+
+	return 0;
+}
#20 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

Quoted 6 lines · Noralf Tr?nnes

Den 28.05.2015 20:33, skrev Eric Anholt:

Quoted 3 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

Quoted 8 lines

drivers/firmware/raspberrypi.c line 225

Quoted 5 lines
drivers/firmware/raspberrypi.c new file +5 -0
+static int rpi_firmware_remove(struct platform_device *pdev)
+{
+    struct rpi_firmware *fw = platform_get_drvdata(pdev);
+
+    mbox_free_channel(fw->chan);

I guess driver data has to be reset here:
platform_set_drvdata(pdev, NULL);

The value of the drvdata is irrelevant before the device has probed, or after it has been removed. Hence, drivers should not manually clear drvdata. (Many drivers used to, but that code is being purged out).

#21 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

In reply to Noralf Trønnes
Quoted 37 lines · Noralf Tr?nnes

Den 28.05.2015 20:33, skrev Eric Anholt:

Quoted 5 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 30 lines
drivers/firmware/raspberrypi.c new file +30 -0
+static int rpi_firmware_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rpi_firmware *fw;
+
+	fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
+	if (!fw)
+		return -ENOMEM;
+
+	fw->cl.dev = dev;
+	fw->cl.rx_callback = response_callback;
+	fw->cl.tx_block = true;
+
+	fw->chan = mbox_request_channel(&fw->cl, 0);
+	if (IS_ERR(fw->chan)) {
+		int ret = PTR_ERR(fw->chan);
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get mbox channel: %d\n", ret);
+		return ret;
+	}
+
+	init_completion(&fw->c);
+
+	platform_set_drvdata(pdev, fw);
+
+	rpi_firmware_print_firmware_revision(dev);
+
+	return 0;
+}
+
Quoted 8 lines

drivers/firmware/raspberrypi.c line 225

Quoted 5 lines
drivers/firmware/raspberrypi.c new file +5 -0
+static int rpi_firmware_remove(struct platform_device *pdev)
+{
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+
+	mbox_free_channel(fw->chan);

I guess driver data has to be reset here:
platform_set_drvdata(pdev, NULL);

Fixed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150528/19ceeedb/attachment.sig>

#22 lore raw

Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver

Den 29.05.2015 00:38, skrev Eric Anholt:

Quoted 46 lines
Quoted 36 lines · Noralf Tr?nnes

Den 28.05.2015 20:33, skrev Eric Anholt:

Quoted 5 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 29 lines
drivers/firmware/raspberrypi.c new file +29 -0
+static int rpi_firmware_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct rpi_firmware *fw;
+
+	fw = devm_kzalloc(dev, sizeof(*fw), GFP_KERNEL);
+	if (!fw)
+		return -ENOMEM;
+
+	fw->cl.dev = dev;
+	fw->cl.rx_callback = response_callback;
+	fw->cl.tx_block = true;
+
+	fw->chan = mbox_request_channel(&fw->cl, 0);
+	if (IS_ERR(fw->chan)) {
+		int ret = PTR_ERR(fw->chan);
+		if (ret != -EPROBE_DEFER)
+			dev_err(dev, "Failed to get mbox channel: %d\n", ret);
+		return ret;
+	}
+
+	init_completion(&fw->c);
+
+	platform_set_drvdata(pdev, fw);
+
+	rpi_firmware_print_firmware_revision(dev);
+
+	return 0;
+}
Quoted 8 lines

drivers/firmware/raspberrypi.c line 225

Quoted 6 lines
drivers/firmware/raspberrypi.c new file +6 -0
+
+static int rpi_firmware_remove(struct platform_device *pdev)
+{
+	struct rpi_firmware *fw = platform_get_drvdata(pdev);
+
+	mbox_free_channel(fw->chan);

I guess driver data has to be reset here:
platform_set_drvdata(pdev, NULL);

Quoted 2 lines

Fixed.

I was wrong about this one as Stephen pointed out.
My point became mute now that rpi_firmware_property_list() doesn't look up driver data anymore.

#23 lore raw

Re: [PATCH 2/3 v2] ARM: bcm2835: Add the Raspberry Pi firmware driver

In reply to Eric Anholt
Quoted 3 lines · Eric Anholt

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 15 lines

Note that I don't think I've done what srwarren wanted for -EPROBE_DEFER, because I'm not clear what he wants. I think he might just be asking for a function that does:

/*
* Returns 0 if the firmware device is probed and available, otherwise
* -EPROBE_DEFER.
*/
int rpi_firmware_get(struct device_node *firmware_node)

{
	struct platform_device *pdev = of_find_device_by_node(of_node);
	if (!platform_get_drvdata(pdev))
		return -EPROBE_DEFER;
	return 0;
}
Quoted 3 lines

EXPORT_SYMBOL(rpi_firmware_get)

If that's all, I'm happy to add it.

Yes, there definitely needs to be something that clients can call at probe() time to make sure the firmware driver is there already. That check is quite different from actually sending a request to the FW, so I'd certainly expect a separate function for that.

#24 lore raw

Re: [PATCH 2/3 v2] ARM: bcm2835: Add the Raspberry Pi firmware driver

Den 28.05.2015 23:17, skrev Stephen Warren:

Quoted 9 lines · Eric Anholt
Quoted 3 lines

This gives us a function for making mailbox property channel requests of the firmware, which is most notable in that it will let us get and set clock rates.

...

Quoted 4 lines

Note that I don't think I've done what srwarren wanted for -EPROBE_DEFER, because I'm not clear what he wants. I think he might just be asking for a function that does:

Quoted 8 lines
Quoted 8 lines

/*
* Returns 0 if the firmware device is probed and available, otherwise
* -EPROBE_DEFER.
*/
int rpi_firmware_get(struct device_node *firmware_node)

{
	struct platform_device *pdev = of_find_device_by_node(of_node);
	if (!platform_get_drvdata(pdev))

of_find_device_by_node() can return NULL if the device can't be found. platform_get_drvdata() can't handle a NULL pointer.

Quoted 10 lines
Quoted 6 lines
		return -EPROBE_DEFER;
	return 0;
}

EXPORT_SYMBOL(rpi_firmware_get)

If that's all, I'm happy to add it.

Yes, there definitely needs to be something that clients can call at probe() time to make sure the firmware driver is there already. That check is quite different from actually sending a request to the FW, so I'd certainly expect a separate function for that.

A try_module_get() here would make sure this module won't go away while a client relies on it. For that we would need a rpi_firmware_put() as well.

#25 lore raw

PATCH v2 3/3 ARM: bcm2835: Add the firmware driver information to the RPi DT

In reply to Eric Anholt

---

v2: Drop pm-domains stuff since I've dropped it from the firmware
driver for now, until we get drivers/base fixed.

 arch/arm/boot/dts/bcm2835-rpi.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/boot/dts/bcm2835-rpi.dtsi +7 -0
index 46780bb..ace33f6 100644
@@ -14,6 +14,13 @@
 			linux,default-trigger = "heartbeat";
 		};
 	};
+
+	soc {
+		firmware: firmware {
+			compatible = "raspberrypi,firmware";
+			mboxes = <&mailbox>;
+		};
+	};
 };
 
 &gpio {
Signature · 1 line
2.1.4