mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Philipp Zabel <p.zabel@pengutronix.de>, barebox@lists.infradead.org
Subject: Re: [PATCH 1/4] firmware: Add request/release_firmware() calls
Date: Thu, 30 Mar 2023 10:30:24 +0200	[thread overview]
Message-ID: <637b2c61-2484-9394-58b0-034962889a43@pengutronix.de> (raw)
In-Reply-To: <20230329105638.1258096-1-p.zabel@pengutronix.de>

On 29.03.23 12:56, Philipp Zabel wrote:
> Add request_firmware() and release_firmware() calls that allow drivers
> to load a firmware file. Also move the struct firmware definition from
> remoteproc.h into firmware.h.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  common/firmware.c          | 33 +++++++++++++++++++++++++++++++++
>  include/firmware.h         | 16 ++++++++++++++++
>  include/linux/remoteproc.h |  5 -----
>  3 files changed, 49 insertions(+), 5 deletions(-)
> 
> diff --git a/common/firmware.c b/common/firmware.c
> index e4ad6ac867b0..c6668fd528b6 100644
> --- a/common/firmware.c
> +++ b/common/firmware.c
> @@ -17,6 +17,7 @@
>  #include <linux/stat.h>
>  #include <linux/err.h>
>  #include <uncompress.h>
> +#include <unistd.h>
>  #include <filetype.h>
>  
>  #define BUFSIZ 4096
> @@ -304,6 +305,38 @@ out:
>  	return ret;
>  }
>  
> +/*
> + * request_firmware - load a firmware to a device
> + */
> +int request_firmware(const struct firmware **out, const char *fw_name, struct device *dev)
> +{
> +	char fw_path[PATH_MAX + 1];
> +	struct firmware *fw;
> +	int ret;
> +
> +	fw = kzalloc(sizeof(struct firmware), GFP_KERNEL);
> +	if (!fw)
> +		return -ENOMEM;
> +
> +	snprintf(fw_path, sizeof(fw_path), "%s/%s", firmware_path, fw_name);
> +
> +	ret = read_file_2(fw_path, &fw->size, (void *)&fw->data, FILESIZE_MAX);
> +	if (ret) {
> +		kfree(fw);
> +		return ret;
> +	}
> +
> +	*out = fw;
> +
> +	return 0;
> +}
> +
> +void release_firmware(const struct firmware *fw)
> +{
> +	kfree_const(fw->data);
> +	kfree_const(fw);
> +}
> +
>  static int firmware_init(void)
>  {
>  	firmware_path = strdup("/env/firmware");
> diff --git a/include/firmware.h b/include/firmware.h
> index 05433f2f7858..b4fa40a3ab44 100644
> --- a/include/firmware.h
> +++ b/include/firmware.h
> @@ -13,6 +13,11 @@
>  #include <debug_ll.h>
>  #include <linux/kernel.h>
>  
> +struct firmware {
> +	size_t size;
> +	const u8 *data;
> +};
> +
>  struct firmware_handler {
>  	char *id; /* unique identifier for this firmware device */
>  	char *model; /* description for this device */
> @@ -37,6 +42,8 @@ struct firmware_mgr *firmwaremgr_find_by_node(struct device_node *np);
>  int firmwaremgr_load_file(struct firmware_mgr *, const char *path);
>  char *firmware_get_searchpath(void);
>  void firmware_set_searchpath(const char *path);
> +int request_firmware(const struct firmware **fw, const char *fw_name, struct device *dev);
> +void release_firmware(const struct firmware *fw);
>  #else
>  static inline struct firmware_mgr *firmwaremgr_find_by_node(struct device_node *np)
>  {
> @@ -57,6 +64,15 @@ static inline void firmware_set_searchpath(const char *path)
>  {
>  }
>  
> +static inline int request_firmware(const struct firmware **fw, const char *fw_name,
> +				   struct device *dev)
> +{
> +	return -EOPNOTSUPP;

Kernel returns -EINVAL here. We should do the same.

With this addressed,

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> +}
> +
> +static inline void release_firmware(const struct firmware *fw)
> +{
> +}
>  #endif
>  
>  void firmwaremgr_list_handlers(void);
> diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
> index 170fff7987fb..33fe2f81b748 100644
> --- a/include/linux/remoteproc.h
> +++ b/include/linux/remoteproc.h
> @@ -18,11 +18,6 @@ struct resource_table {
>  	u32 offset[0];
>  } __packed;
>  
> -struct firmware {
> -	size_t size;
> -	const u8 *data;
> -};
> -
>  struct rproc;
>  
>  struct rproc_ops {

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |




      parent reply	other threads:[~2023-03-30  8:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29 10:56 Philipp Zabel
2023-03-29 10:56 ` [PATCH 2/4] video: Add of_get_display_timing Philipp Zabel
2023-03-30  8:32   ` Ahmad Fatoum
2023-03-29 10:56 ` [PATCH 3/4] video: add MIPI DBI framebuffer helpers Philipp Zabel
2023-03-30  8:43   ` Ahmad Fatoum
2023-03-30 12:02     ` Philipp Zabel
2023-03-29 10:56 ` [PATCH 4/4] video: Add MIPI DBI compatible SPI driver Philipp Zabel
2023-03-30  8:56   ` Ahmad Fatoum
2023-03-30  8:30 ` Ahmad Fatoum [this message]

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=637b2c61-2484-9394-58b0-034962889a43@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=p.zabel@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox