All of lore.kernel.org
 help / color / mirror / Atom feed
From: swarren@wwwdotorg.org (Stephen Warren)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver
Date: Thu, 28 May 2015 15:28:15 -0600	[thread overview]
Message-ID: <5567886F.5080108@wwwdotorg.org> (raw)
In-Reply-To: <1432837987-22861-1-git-send-email-eric@anholt.net>

On 05/28/2015 12:33 PM, Eric Anholt wrote:
> 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.

> diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile

> +obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o

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

> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c

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

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

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

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

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

WARNING: multiple messages have this Message-ID (diff)
From: Stephen Warren <swarren@wwwdotorg.org>
To: Eric Anholt <eric@anholt.net>
Cc: linux-arm-kernel@lists.infradead.org,
	linux-rpi-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Lee Jones <lee@kernel.org>,
	devicetree@vger.kernel.org
Subject: Re: [PATCH 2/3 v4] ARM: bcm2835: Add the Raspberry Pi firmware driver
Date: Thu, 28 May 2015 15:28:15 -0600	[thread overview]
Message-ID: <5567886F.5080108@wwwdotorg.org> (raw)
In-Reply-To: <1432837987-22861-1-git-send-email-eric@anholt.net>

On 05/28/2015 12:33 PM, Eric Anholt wrote:
> 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.

> diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile

> +obj-$(CONFIG_BCM2835_MBOX)	+= raspberrypi.o

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

> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c

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

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

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

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

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

  reply	other threads:[~2015-05-28 21:28 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13 19:00 RPi firmware driver v2 Eric Anholt
2015-05-13 19:00 ` Eric Anholt
2015-05-13 19:00 ` [PATCH 1/3 v2] dt/bindings: Add binding for the Raspberry Pi firmware driver Eric Anholt
2015-05-13 19:00   ` Eric Anholt
2015-05-14  8:40   ` Lee Jones
2015-05-14  8:40     ` Lee Jones
2015-05-14  8:40     ` Lee Jones
2015-05-14  9:57     ` Eric Anholt
2015-05-14  9:57       ` Eric Anholt
2015-05-14  9:57       ` Eric Anholt
2015-05-17 17:11   ` Noralf Trønnes
2015-05-17 17:11     ` Noralf Trønnes
2015-05-18 17:59   ` [PATCH 1/3 v3] " Eric Anholt
2015-05-18 17:59     ` Eric Anholt
2015-05-28 21:12     ` Stephen Warren
2015-05-28 21:12       ` Stephen Warren
2015-05-28 21:12       ` Stephen Warren
2015-05-13 19:00 ` [PATCH 2/3 v2] ARM: bcm2835: Add " Eric Anholt
2015-05-13 19:00   ` Eric Anholt
2015-05-13 19:00   ` Eric Anholt
2015-05-17 17:30   ` Noralf Trønnes
2015-05-17 17:30     ` Noralf Trønnes
2015-05-17 18:26   ` Noralf Trønnes
2015-05-17 18:26     ` Noralf Trønnes
2015-05-17 18:26     ` Noralf Trønnes
2015-05-18 17:34     ` Eric Anholt
2015-05-18 17:34       ` Eric Anholt
2015-05-18 18:00   ` [PATCH 2/3 v3] " Eric Anholt
2015-05-18 18:00     ` Eric Anholt
     [not found]   ` <20150528112610.GO11677@x1>
2015-05-28 11:45     ` [PATCH 2/3 v2] " Lee Jones
2015-05-28 11:45       ` Lee Jones
2015-05-28 11:45       ` Lee Jones
2015-05-28 18:33       ` [PATCH 2/3 v4] " Eric Anholt
2015-05-28 18:33         ` Eric Anholt
2015-05-28 18:33         ` Eric Anholt
2015-05-28 21:28         ` Stephen Warren [this message]
2015-05-28 21:28           ` Stephen Warren
2015-05-28 21:39           ` Noralf Trønnes
2015-05-28 21:39             ` Noralf Trønnes
2015-05-28 21:39             ` Noralf Trønnes
2015-05-28 22:09             ` Stephen Warren
2015-05-28 22:09               ` Stephen Warren
2015-05-28 22:09               ` Stephen Warren
2015-05-28 22:36           ` Eric Anholt
2015-05-28 22:36             ` Eric Anholt
2015-05-28 21:42         ` Noralf Trønnes
2015-05-28 21:42           ` Noralf Trønnes
2015-05-28 22:10           ` Stephen Warren
2015-05-28 22:10             ` Stephen Warren
2015-05-28 22:10             ` Stephen Warren
2015-05-28 22:38           ` Eric Anholt
2015-05-28 22:38             ` Eric Anholt
2015-05-28 22:38             ` Eric Anholt
2015-05-28 22:43             ` Noralf Trønnes
2015-05-28 22:43               ` Noralf Trønnes
2015-05-28 22:43               ` Noralf Trønnes
2015-05-28 21:17   ` [PATCH 2/3 v2] " Stephen Warren
2015-05-28 21:17     ` Stephen Warren
2015-05-28 21:17     ` Stephen Warren
2015-05-28 22:40     ` Noralf Trønnes
2015-05-28 22:40       ` Noralf Trønnes
2015-05-28 22:40       ` Noralf Trønnes
2015-05-13 19:00 ` [PATCH 3/3 v2] ARM: bcm2835: Add the firmware driver information to the RPi DT Eric Anholt
2015-05-13 19:00   ` Eric Anholt
2015-05-28 21:29   ` Stephen Warren
2015-05-28 21:29     ` Stephen Warren
2015-05-28 21:29     ` Stephen Warren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5567886F.5080108@wwwdotorg.org \
    --to=swarren@wwwdotorg.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.