Re: [PATCHv4 04/14] remoteproc/omap: Add support to parse internal memories from DT

From: Suman Anna
Date: Thu Jan 09 2020 - 12:19:43 EST


On 1/9/20 3:12 AM, Tero Kristo wrote:
> On 08/01/2020 20:05, Suman Anna wrote:
>> Hi Tero,
>>
>> On 1/2/20 7:18 AM, Tero Kristo wrote:
>>> From: Suman Anna <s-anna@xxxxxx>
>>>
>>> The OMAP remoteproc driver has been enhanced to parse and store
>>> the kernel mappings for different internal RAM memories that may
>>> be present within each remote processor IP subsystem. Different
>>> devices have varying memories present on current SoCs. The current
>>> support handles the L2RAM for all IPU devices on OMAP4+ SoCs. The
>>> DSPs on OMAP4/OMAP5 only have Unicaches and do not have any L1 or
>>> L2 RAM memories.
>>>
>>> IPUs are expected to have the L2RAM at a fixed device address of
>>> 0x20000000, based on the current limitations on Attribute MMU
>>> configurations.
>>>
>>> NOTE:
>>> The current logic doesn't handle the parsing of memories for DRA7
>>> remoteproc devices, and will be added alongside the DRA7 support.
>>>
>>> Signed-off-by: Suman Anna <s-anna@xxxxxx>
>>> [t-kristo: converted to parse mem names / device addresses from pdata]
>>> Signed-off-by: Tero Kristo <t-kristo@xxxxxx>
>>> ---
>>> v4:
>>> ÂÂ - moved device data mem definitions under single struct
>>>
>>> Â drivers/remoteproc/omap_remoteproc.c | 89 ++++++++++++++++++++++++++++
>>> Â 1 file changed, 89 insertions(+)
>>>
>>> diff --git a/drivers/remoteproc/omap_remoteproc.c
>>> b/drivers/remoteproc/omap_remoteproc.c
>>> index 557c439571c1..e429b2296d7a 100644
>>> --- a/drivers/remoteproc/omap_remoteproc.c
>>> +++ b/drivers/remoteproc/omap_remoteproc.c
>>> @@ -39,11 +39,27 @@ struct omap_rproc_boot_data {
>>> ÂÂÂÂÂ unsigned int boot_reg;
>>> Â };
>>> Â +/**
>>> + * struct omap_rproc_mem - internal memory structure
>>> + * @cpu_addr: MPU virtual address of the memory region
>>> + * @bus_addr: bus address used to access the memory region
>>> + * @dev_addr: device address of the memory region from DSP view
>>> + * @size: size of the memory region
>>> + */
>>> +struct omap_rproc_mem {
>>> +ÂÂÂ void __iomem *cpu_addr;
>>> +ÂÂÂ phys_addr_t bus_addr;
>>> +ÂÂÂ u32 dev_addr;
>>> +ÂÂÂ size_t size;
>>> +};
>>> +
>>> Â /**
>>> ÂÂ * struct omap_rproc - omap remote processor state
>>> ÂÂ * @mbox: mailbox channel handle
>>> ÂÂ * @client: mailbox client to request the mailbox channel
>>> ÂÂ * @boot_data: boot data structure for setting processor boot address
>>> + * @mem: internal memory regions data
>>> + * @num_mems: number of internal memory regions
>>> ÂÂ * @rproc: rproc handle
>>> ÂÂ * @reset: reset handle
>>> ÂÂ */
>>> @@ -51,16 +67,30 @@ struct omap_rproc {
>>> ÂÂÂÂÂ struct mbox_chan *mbox;
>>> ÂÂÂÂÂ struct mbox_client client;
>>> ÂÂÂÂÂ struct omap_rproc_boot_data *boot_data;
>>> +ÂÂÂ struct omap_rproc_mem *mem;
>>> +ÂÂÂ int num_mems;
>>> ÂÂÂÂÂ struct rproc *rproc;
>>> ÂÂÂÂÂ struct reset_control *reset;
>>> Â };
>>> Â +/**
>>> + * struct omap_rproc_mem_data - memory definitions for an omap
>>> remote processor
>>> + * @mem_name: name for this memory entry
>>> + * @dev_addr: device address for the memory entry
>>> + */
>>> +struct omap_rproc_mem_data {
>>> +ÂÂÂ const char *name;
>>> +ÂÂÂ const u32 dev_addr;
>>> +};
>>> +
>>> Â /**
>>> ÂÂ * struct omap_rproc_dev_data - device data for the omap remote
>>> processor
>>> ÂÂ * @device_name: device name of the remote processor
>>> + * @mems: memory definitions for this remote processor
>>> ÂÂ */
>>> Â struct omap_rproc_dev_data {
>>> ÂÂÂÂÂ const char *device_name;
>>> +ÂÂÂ const struct omap_rproc_mem_data *mems;
>>> Â };
>>> Â Â /**
>>> @@ -221,12 +251,18 @@ static const struct rproc_ops omap_rproc_ops = {
>>> ÂÂÂÂÂ .kickÂÂÂÂÂÂÂ = omap_rproc_kick,
>>> Â };
>>> Â +static const struct omap_rproc_mem_data ipu_mems[] = {
>>> +ÂÂÂ { .name = "l2ram", .dev_addr = 0x20000000 },
>>> +ÂÂÂ { },
>>> +};
>>> +
>>> Â static const struct omap_rproc_dev_data omap4_dsp_dev_data = {
>>> ÂÂÂÂÂ .device_nameÂÂÂ = "dsp",
>>> Â };
>>> Â Â static const struct omap_rproc_dev_data omap4_ipu_dev_data = {
>>> ÂÂÂÂÂ .device_nameÂÂÂ = "ipu",
>>> +ÂÂÂ .memsÂÂÂÂÂÂÂ = ipu_mems,
>>> Â };
>>> Â Â static const struct omap_rproc_dev_data omap5_dsp_dev_data = {
>>> @@ -235,6 +271,7 @@ static const struct omap_rproc_dev_data
>>> omap5_dsp_dev_data = {
>>> Â Â static const struct omap_rproc_dev_data omap5_ipu_dev_data = {
>>> ÂÂÂÂÂ .device_nameÂÂÂ = "ipu",
>>> +ÂÂÂ .memsÂÂÂÂÂÂÂ = ipu_mems,
>>> Â };
>>> Â Â static const struct of_device_id omap_rproc_of_match[] = {
>>> @@ -309,6 +346,54 @@ static int omap_rproc_get_boot_data(struct
>>> platform_device *pdev,
>>> ÂÂÂÂÂ return 0;
>>> Â }
>>> Â +static int omap_rproc_of_get_internal_memories(struct
>>> platform_device *pdev,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct rproc *rproc)
>>> +{
>>> +ÂÂÂ struct omap_rproc *oproc = rproc->priv;
>>> +ÂÂÂ struct device *dev = &pdev->dev;
>>> +ÂÂÂ const struct omap_rproc_dev_data *data;
>>> +ÂÂÂ struct resource *res;
>>> +ÂÂÂ int num_mems;
>>> +ÂÂÂ int i;
>>> +
>>> +ÂÂÂ data = of_device_get_match_data(&pdev->dev);
>>> +ÂÂÂ if (!data)
>>> +ÂÂÂÂÂÂÂ return -ENODEV;
>>> +
>>> +ÂÂÂ if (!data->mems)
>>> +ÂÂÂÂÂÂÂ return 0;
>>> +
>>> +ÂÂÂ for (num_mems = 0; data->mems[num_mems].name; num_mems++)
>>> +ÂÂÂÂÂÂÂ ;
>>
>> Think you can restore back the ARRAY_SIZE here? Don't think you need the
>> sentinel in the names either.
>
> Can't do that. There is nothing to use the ARRAY_SIZE against here. I
> either need to have the ARRAY_SIZE embedded in the device data, or have
> the sentinel. Having the sentinel is cleaner.

Yeah, ok.

regards
Suman

>
>>
>>> +
>>> +ÂÂÂ oproc->mem = devm_kcalloc(dev, num_mems, sizeof(*oproc->mem),
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
>>> +ÂÂÂ if (!oproc->mem)
>>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>>> +
>>> +ÂÂÂ for (i = 0; i < num_mems; i++) {
>>> +ÂÂÂÂÂÂÂ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ data->mems[i].name);
>>> +ÂÂÂÂÂÂÂ oproc->mem[i].cpu_addr = devm_ioremap_resource(dev, res);
>>> +ÂÂÂÂÂÂÂ if (IS_ERR(oproc->mem[i].cpu_addr)) {
>>> +ÂÂÂÂÂÂÂÂÂÂÂ dev_err(dev, "failed to parse and map %s memory\n",
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ data->mems[i].name);
>>> +ÂÂÂÂÂÂÂÂÂÂÂ return PTR_ERR(oproc->mem[i].cpu_addr);
>>> +ÂÂÂÂÂÂÂ }
>>> +ÂÂÂÂÂÂÂ oproc->mem[i].bus_addr = res->start;
>>> +ÂÂÂÂÂÂÂ oproc->mem[i].dev_addr = data->mems[i].dev_addr;
>>> +ÂÂÂÂÂÂÂ oproc->mem[i].size = resource_size(res);
>>> +
>>> +ÂÂÂÂÂÂÂ dev_dbg(dev, "memory %8s: bus addr %pa size 0x%x va %p da
>>> 0x%x\n",
>>
>> Would appreciate if you can fix up to use %pK here.
>
> Ok, can change those.
>
> -Tero
>
>>
>> regards
>> Suman
>>
>>> +ÂÂÂÂÂÂÂÂÂÂÂ data->mems[i].name, &oproc->mem[i].bus_addr,
>>> +ÂÂÂÂÂÂÂÂÂÂÂ oproc->mem[i].size, oproc->mem[i].cpu_addr,
>>> +ÂÂÂÂÂÂÂÂÂÂÂ oproc->mem[i].dev_addr);
>>> +ÂÂÂ }
>>> +ÂÂÂ oproc->num_mems = num_mems;
>>> +
>>> +ÂÂÂ return 0;
>>> +}
>>> +
>>> Â static int omap_rproc_probe(struct platform_device *pdev)
>>> Â {
>>> ÂÂÂÂÂ struct device_node *np = pdev->dev.of_node;
>>> @@ -348,6 +433,10 @@ static int omap_rproc_probe(struct
>>> platform_device *pdev)
>>> ÂÂÂÂÂ /* All existing OMAP IPU and DSP processors have an MMU */
>>> ÂÂÂÂÂ rproc->has_iommu = true;
>>> Â +ÂÂÂ ret = omap_rproc_of_get_internal_memories(pdev, rproc);
>>> +ÂÂÂ if (ret)
>>> +ÂÂÂÂÂÂÂ goto free_rproc;
>>> +
>>> ÂÂÂÂÂ ret = omap_rproc_get_boot_data(pdev, rproc);
>>> ÂÂÂÂÂ if (ret)
>>> ÂÂÂÂÂÂÂÂÂ goto free_rproc;
>>>
>>
>
> --
> Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
> Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki