[EXTERNAL] Re: [PATCH v10 3/6] remoteproc: pru: Add enum for PRU Core Indentifiers.

Md Danish Anwar a0501179 at ti.com
Thu Dec 1 05:43:42 PST 2022


Hi Roger,

On 01/12/22 5:28 pm, Roger Quadros wrote:
> Danish,
> 
> On 01/12/2022 13:04, MD Danish Anwar wrote:
>> Introducing enum pruss_pru_id for PRU Core Identifiers.
>> PRUSS_PRU0 indicates PRU Core 0.
>> PRUSS_PRU1 indicates PRU Core 1.
>> PRUSS_NUM_PRUS indicates the total number of PRU Cores.
>>
>> Signed-off-by: MD Danish Anwar <danishanwar at ti.com>
>> ---
>>   drivers/remoteproc/pru_rproc.c | 16 ++++++++++++----
>>   include/linux/pruss.h          | 19 +++++++++++++++++--
>>   2 files changed, 29 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c
>> index b4498a505108..7d4ed39b3772 100644
>> --- a/drivers/remoteproc/pru_rproc.c
>> +++ b/drivers/remoteproc/pru_rproc.c
>> @@ -186,6 +186,7 @@ static struct rproc *__pru_rproc_get(struct device_node *np, int index)
>>    * pru_rproc_get() - get the PRU rproc instance from a device node
>>    * @np: the user/client device node
>>    * @index: index to use for the ti,prus property
>> + * @pru_id: optional pointer to return the PRU remoteproc processor id
>>    *
>>    * This function looks through a client device node's "ti,prus" property at
>>    * index @index and returns the rproc handle for a valid PRU remote processor if
>> @@ -193,13 +194,17 @@ static struct rproc *__pru_rproc_get(struct device_node *np, int index)
>>    * time. Caller must call pru_rproc_put() when done with using the rproc, not
>>    * required if the function returns a failure.
>>    *
>> + * When optional @pru_id pointer is passed the PRU remoteproc processor id is
>> + * returned.
>> + *
>>    * Return: rproc handle on success, and an ERR_PTR on failure using one
>>    * of the following error values
>>    *    -ENODEV if device is not found
>>    *    -EBUSY if PRU is already acquired by anyone
>>    *    -EPROBE_DEFER is PRU device is not probed yet
>>    */
>> -struct rproc *pru_rproc_get(struct device_node *np, int index)
>> +struct rproc *pru_rproc_get(struct device_node *np, int index,
>> +			    enum pruss_pru_id *pru_id)
> 
> You just introduced pru_rproc_get() in the previous patch and are
> now updating it here.
> 

That's because there is dependency between these two patches. The enum 
pruss_pru_id is declared inside linux/pruss.h file which is introduced 
in pru_rproc_get() patch. But pru_rproc_get() and pru_rproc_put() APIs 
use the enum as function argument. So I decided to keep pru_rproc_get() 
patch as second patch of this series(as it introduces <linux/pruss.h> 
where eventually the enum will be introduced).

Then I kept the enum introduction patch as third patch of the series and 
with this patch I modified pru_rproc_get() API by adding pru_id field in 
the function argument.

> Instead, what you need to do is, first introduce enum pruss_pru_id
> and make any changes to code using hardcoded values for PRU ID.
> This patch will have to introduce <linux/pruss.h> as it doesn't exist yet.

This also came to my mind. But I thought introduction of enum 
pruss_pru_id patch should just introduce the enum and modify APIs which 
uses the enum accordingly. I wanted to keep the introduction of 
<linux/pruss.h> file with the pru_rproc_get() patch as it was. That's 
why I kept pru_rproc_get() patch ahead of enum patch.

> Hopefully this clears the chicken/egg situation.
> 
> Then introduce pru_rproc_get() patch with the final desired arguments.
> 
>>   {
>>   	struct rproc *rproc;
>>   	struct pru_rproc *pru;
>> @@ -226,6 +231,9 @@ struct rproc *pru_rproc_get(struct device_node *np, int index)
>>   
>>   	mutex_unlock(&pru->lock);
>>   
>> +	if (pru_id)
>> +		*pru_id = pru->id;
>> +
>>   	return rproc;
>>   
>>   err_no_rproc_handle:
>> @@ -556,7 +564,7 @@ static void *pru_d_da_to_va(struct pru_rproc *pru, u32 da, size_t len)
>>   	dram0 = pruss->mem_regions[PRUSS_MEM_DRAM0];
>>   	dram1 = pruss->mem_regions[PRUSS_MEM_DRAM1];
>>   	/* PRU1 has its local RAM addresses reversed */
>> -	if (pru->id == 1)
>> +	if (pru->id == PRUSS_PRU1)
>>   		swap(dram0, dram1);
>>   	shrd_ram = pruss->mem_regions[PRUSS_MEM_SHRD_RAM2];
>>   
>> @@ -865,14 +873,14 @@ static int pru_rproc_set_id(struct pru_rproc *pru)
>>   	case RTU0_IRAM_ADDR_MASK:
>>   		fallthrough;
>>   	case PRU0_IRAM_ADDR_MASK:
>> -		pru->id = 0;
>> +		pru->id = PRUSS_PRU0;
>>   		break;
>>   	case TX_PRU1_IRAM_ADDR_MASK:
>>   		fallthrough;
>>   	case RTU1_IRAM_ADDR_MASK:
>>   		fallthrough;
>>   	case PRU1_IRAM_ADDR_MASK:
>> -		pru->id = 1;
>> +		pru->id = PRUSS_PRU1;
>>   		break;
>>   	default:
>>   		ret = -EINVAL;
>> diff --git a/include/linux/pruss.h b/include/linux/pruss.h
>> index 5c5d14b1249d..efe89c586b4b 100644
>> --- a/include/linux/pruss.h
>> +++ b/include/linux/pruss.h
>> @@ -14,17 +14,32 @@
>>   
>>   #define PRU_RPROC_DRVNAME "pru-rproc"
>>   
>> +/**
>> + * enum pruss_pru_id - PRU core identifiers
>> + * @PRUSS_PRU0: PRU Core 0.
>> + * @PRUSS_PRU1: PRU Core 1.
>> + * @PRUSS_NUM_PRUS: Total number of PRU Cores available.
>> + *
>> + */
>> +
>> +enum pruss_pru_id {
>> +	PRUSS_PRU0 = 0,
>> +	PRUSS_PRU1,
>> +	PRUSS_NUM_PRUS,
>> +};
>> +
>>   struct device_node;
>>   
>>   #if IS_ENABLED(CONFIG_PRU_REMOTEPROC)
>>   
>> -struct rproc *pru_rproc_get(struct device_node *np, int index);
>> +struct rproc *pru_rproc_get(struct device_node *np, int index,
>> +			    enum pruss_pru_id *pru_id);
>>   void pru_rproc_put(struct rproc *rproc);
>>   
>>   #else
>>   
>>   static inline struct rproc *
>> -pru_rproc_get(struct device_node *np, int index)
>> +pru_rproc_get(struct device_node *np, int index, enum pruss_pru_id *pru_id)
>>   {
>>   	return ERR_PTR(-EOPNOTSUPP);
>>   }
> 
> --
> cheers,
> -roger

Thanks,
Danish.



More information about the linux-arm-kernel mailing list