diff mbox

[v2,11/19] remoteproc: core: Add function to get resource table spare bytes information

Message ID 1472676622-32533-12-git-send-email-loic.pallardy@st.com (mailing list archive)
State Superseded
Headers show

Commit Message

Loic PALLARDY Aug. 31, 2016, 8:50 p.m. UTC
Remoteproc needs to know if a resource table has spare resource
allowing resoure table extension.
This function parse resource table to detect spare resource.
If any, it returns available spare bytes and index of spare resource.

Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
---
 drivers/remoteproc/remoteproc_core.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Lee Jones Sept. 8, 2016, 8:32 a.m. UTC | #1
On Wed, 31 Aug 2016, Loic Pallardy wrote:

> Remoteproc needs to know if a resource table has spare resource
> allowing resoure table extension.
> This function parse resource table to detect spare resource.
> If any, it returns available spare bytes and index of spare resource.
> 
> Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
> ---
>  drivers/remoteproc/remoteproc_core.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index ffb56c0..30e9c70 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -951,6 +951,35 @@ int rproc_request_resource(struct rproc *rproc, u32 type, u32 action, void *reso
>  }
>  EXPORT_SYMBOL(rproc_request_resource);
>  
> +static int __get_rsc_tbl_spare_size(struct rproc *rproc,

size_t?

> +					  struct resource_table *table_ptr, int len,
> +					  int *spare_index)
> +{
> +	struct device *dev = &rproc->dev;
> +	int i;
> +
> +	for (i = 0; i < table_ptr->num; i++) {
> +		int offset = table_ptr->offset[i];
> +		struct fw_rsc_hdr *hdr = (void *)table_ptr + offset;
> +		struct fw_rsc_spare *spare = (void *)hdr + sizeof(*hdr);
> +
> +		dev_dbg(dev, "rsc: type %d\n", hdr->type);

This doesn't need to be in upstream code.

> +		if (hdr->type >= RSC_LAST) {
> +			dev_warn(dev, "unsupported resource %d\n", hdr->type);
> +			continue;
> +		}

If we're only interested in RSC_SPARE, I think we can omit this check.

No need to police the resource table everywhere.

> +		if (hdr->type != RSC_SPARE)
> +			continue;
> +
> +		*spare_index = i;
> +		return spare->len;
> +	}
> +
> +	return 0;
> +}
> +
>  static int __verify_rsc_tbl_entry(struct rproc *rproc,
>  				struct rproc_request_resource *request,
>  				struct resource_table *table, int size)
Loic PALLARDY Sept. 8, 2016, 9:47 a.m. UTC | #2
On 09/08/2016 10:32 AM, Lee Jones wrote:
> On Wed, 31 Aug 2016, Loic Pallardy wrote:
>
>> Remoteproc needs to know if a resource table has spare resource
>> allowing resoure table extension.
>> This function parse resource table to detect spare resource.
>> If any, it returns available spare bytes and index of spare resource.
>>
>> Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
>> ---
>>  drivers/remoteproc/remoteproc_core.c | 29 +++++++++++++++++++++++++++++
>>  1 file changed, 29 insertions(+)
>>
>> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
>> index ffb56c0..30e9c70 100644
>> --- a/drivers/remoteproc/remoteproc_core.c
>> +++ b/drivers/remoteproc/remoteproc_core.c
>> @@ -951,6 +951,35 @@ int rproc_request_resource(struct rproc *rproc, u32 type, u32 action, void *reso
>>  }
>>  EXPORT_SYMBOL(rproc_request_resource);
>>
>> +static int __get_rsc_tbl_spare_size(struct rproc *rproc,
>
> size_t?
ok
>
>> +					  struct resource_table *table_ptr, int len,
>> +					  int *spare_index)
>> +{
>> +	struct device *dev = &rproc->dev;
>> +	int i;
>> +
>> +	for (i = 0; i < table_ptr->num; i++) {
>> +		int offset = table_ptr->offset[i];
>> +		struct fw_rsc_hdr *hdr = (void *)table_ptr + offset;
>> +		struct fw_rsc_spare *spare = (void *)hdr + sizeof(*hdr);
>> +
>> +		dev_dbg(dev, "rsc: type %d\n", hdr->type);
>
> This doesn't need to be in upstream code.
Sure
>
>> +		if (hdr->type >= RSC_LAST) {
>> +			dev_warn(dev, "unsupported resource %d\n", hdr->type);
>> +			continue;
>> +		}
>
> If we're only interested in RSC_SPARE, I think we can omit this check.
>
> No need to police the resource table everywhere.
True and complete table sanity check done before.
I'll remove
Thanks,
Loic

>
>> +		if (hdr->type != RSC_SPARE)
>> +			continue;
>> +
>> +		*spare_index = i;
>> +		return spare->len;
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>>  static int __verify_rsc_tbl_entry(struct rproc *rproc,
>>  				struct rproc_request_resource *request,
>>  				struct resource_table *table, int size)
>
--
To unsubscribe from this list: send the line "unsubscribe linux-remoteproc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index ffb56c0..30e9c70 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -951,6 +951,35 @@  int rproc_request_resource(struct rproc *rproc, u32 type, u32 action, void *reso
 }
 EXPORT_SYMBOL(rproc_request_resource);
 
+static int __get_rsc_tbl_spare_size(struct rproc *rproc,
+					  struct resource_table *table_ptr, int len,
+					  int *spare_index)
+{
+	struct device *dev = &rproc->dev;
+	int i;
+
+	for (i = 0; i < table_ptr->num; i++) {
+		int offset = table_ptr->offset[i];
+		struct fw_rsc_hdr *hdr = (void *)table_ptr + offset;
+		struct fw_rsc_spare *spare = (void *)hdr + sizeof(*hdr);
+
+		dev_dbg(dev, "rsc: type %d\n", hdr->type);
+
+		if (hdr->type >= RSC_LAST) {
+			dev_warn(dev, "unsupported resource %d\n", hdr->type);
+			continue;
+		}
+
+		if (hdr->type != RSC_SPARE)
+			continue;
+
+		*spare_index = i;
+		return spare->len;
+	}
+
+	return 0;
+}
+
 static int __verify_rsc_tbl_entry(struct rproc *rproc,
 				struct rproc_request_resource *request,
 				struct resource_table *table, int size)