devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <Valentina.FernandezAlanis@microchip.com>
To: <samuel.holland@sifive.com>
Cc: <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-remoteproc@vger.kernel.org>,
	<paul.walmsley@sifive.com>, <palmer@dabbelt.com>,
	<aou@eecs.berkeley.edu>, <peterlin@andestech.com>,
	<dminus@andestech.com>, <Conor.Dooley@microchip.com>,
	<conor+dt@kernel.org>, <ycliang@andestech.com>,
	<jassisinghbrar@gmail.com>, <robh@kernel.org>,
	<krzk+dt@kernel.org>, <andersson@kernel.org>,
	<mathieu.poirier@linaro.org>
Subject: Re: [PATCH v1 3/5] mailbox: add Microchip IPC support
Date: Mon, 16 Sep 2024 09:25:08 +0000	[thread overview]
Message-ID: <657d3fec-ed98-4b9c-81c8-1f5fc6e1c913@microchip.com> (raw)
In-Reply-To: <22dd1d53-9ac5-4672-ad68-e82499038283@sifive.com>

On 12/09/2024 22:30, Samuel Holland wrote:
> [You don't often get email from samuel.holland@sifive.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Hi Valentina,
> 
> On 2024-09-12 12:00 PM, Valentina Fernandez wrote:
>> +static int mchp_ipc_probe(struct platform_device *pdev)
>> +{
>> +     struct device *dev = &pdev->dev;
>> +     struct mchp_ipc_probe ipc_info;
>> +     struct microchip_ipc *ipc;
>> +     struct ipc_chan_info *priv;
>> +     bool irq_avail = false;
>> +     int ret;
>> +     u32 chan_id;
>> +
>> +     ret = sbi_probe_extension(SBI_EXT_MICROCHIP_TECHNOLOGY);
>> +     if (ret <= 0)
>> +             return dev_err_probe(dev, ret, "Microchip SBI extension not detected\n");
>> +
>> +     ipc = devm_kzalloc(dev, sizeof(*ipc), GFP_KERNEL);
>> +     if (!ipc)
>> +             return -ENOMEM;
>> +
>> +     platform_set_drvdata(pdev, ipc);
>> +
>> +     ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(IPC_DMA_BIT_MASK));
>> +     if (ret)
>> +             return dev_err_probe(dev, ret, "dma_set_mask_and_coherent failed\n");
>> +
>> +     ipc->buf_base = dmam_alloc_coherent(dev, sizeof(u32), &ipc->dma_addr, GFP_KERNEL);
>> +
>> +     if (!ipc->buf_base)
>> +             return -ENOMEM;
> 
> One drive-by comment here: you don't need to use the DMA API to get a physical
> address for passing to the SBI interface. You can use __pa() on a kmalloc'd
> buffer, since kmalloc() returns memory from the linear map. This has the
> advantage of 1) using cacheable memory and 2) not rounding up the allocation
> size to a whole page.
Hi Samuel,

Thanks for the suggestion, I will take a look into that approach
for the next iterarion of the series.

Thanks,
Valentina
> 
>> +
>> +     ret = mchp_ipc_sbi_send(SBI_EXT_IPC_PROBE, ipc->dma_addr);
>> +     if (ret < 0)
>> +             return dev_err_probe(dev, ret, "could not probe IPC SBI service\n");
>> +
>> +     memcpy(&ipc_info, ipc->buf_base, sizeof(struct mchp_ipc_probe));
> 
> Here sizeof(struct mchp_ipc_probe) > sizeof(u32), so if the DMA API wasn't
> rounding up the allocation size, this would be a buffer overflow.
> 
> Regards,
> Samuel
> 
>> +     ipc->num_channels = ipc_info.num_channels;
>> +     ipc->hw_type = ipc_info.hw_type;
>> +
>> +     ipc->chans = devm_kcalloc(dev, ipc->num_channels, sizeof(*ipc->chans), GFP_KERNEL);
>> +     if (!ipc->chans)
>> +             return -ENOMEM;
>> +
>> +     ipc->dev = dev;
>> +     ipc->controller.txdone_irq = true;
>> +     ipc->controller.dev = ipc->dev;
>> +     ipc->controller.ops = &mchp_ipc_ops;
>> +     ipc->controller.chans = ipc->chans;
>> +     ipc->controller.num_chans = ipc->num_channels;
>> +     ipc->controller.of_xlate = mchp_ipc_mbox_xlate;
>> +
>> +     for (chan_id = 0; chan_id < ipc->num_channels; chan_id++) {
>> +             priv = devm_kmalloc(dev, sizeof(*priv), GFP_KERNEL);
>> +             if (!priv)
>> +                     return -ENOMEM;
>> +
>> +             ipc->chans[chan_id].con_priv = priv;
>> +             priv->id = chan_id;
>> +     }
>> +
>> +     if (ipc->hw_type == MIV_IHC) {
>> +             ipc->cluster_cfg = devm_kcalloc(dev, num_online_cpus(),
>> +                                             sizeof(struct mchp_ipc_cluster_cfg),
>> +                                             GFP_KERNEL);
>> +             if (!ipc->cluster_cfg)
>> +                     return -ENOMEM;
>> +
>> +             if (mchp_ipc_get_cluster_aggr_irq(ipc))
>> +                     irq_avail = true;
>> +     }
>> +
>> +     if (!irq_avail)
>> +             return dev_err_probe(dev, -ENODEV, "missing interrupt property\n");
>> +
>> +     ret = devm_mbox_controller_register(dev, &ipc->controller);
>> +     if (ret)
>> +             return dev_err_probe(dev, ret,
>> +                                      "Inter-Processor communication (IPC) registration failed\n");
>> +
>> +     return 0;
>> +}
> 


  reply	other threads:[~2024-09-16  9:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-12 17:00 [PATCH v1 0/5] Add Microchip IPC mailbox and remoteproc support Valentina Fernandez
2024-09-12 17:00 ` [PATCH v1 1/5] riscv: asm: vendorid_list: Add Microchip Technology to the vendor list Valentina Fernandez
2024-09-12 17:16   ` Conor Dooley
2024-09-12 17:00 ` [PATCH v1 2/5] dt-bindings: mailbox: add binding for Microchip IPC mailbox driver Valentina Fernandez
2024-09-12 17:15   ` Conor Dooley
2024-09-12 21:23   ` Samuel Holland
2024-09-16 16:31     ` Conor Dooley
2024-09-18 15:35       ` Rob Herring
2024-09-19  7:40         ` Conor Dooley
2024-09-12 17:00 ` [PATCH v1 3/5] mailbox: add Microchip IPC support Valentina Fernandez
2024-09-12 21:30   ` Samuel Holland
2024-09-16  9:25     ` Valentina.FernandezAlanis [this message]
2024-09-16 20:21   ` Krzysztof Kozlowski
2024-09-12 17:00 ` [PATCH v1 4/5] dt-bindings: remoteproc: add binding for Microchip IPC remoteproc Valentina Fernandez
2024-09-16 20:14   ` Krzysztof Kozlowski
2024-10-15 12:09     ` Valentina.FernandezAlanis
2024-10-15 13:35       ` Krzysztof Kozlowski
2024-10-15 20:22         ` Conor Dooley
2024-09-12 17:00 ` [PATCH v1 5/5] remoteproc: add support for Microchip IPC remoteproc platform driver Valentina Fernandez
2024-09-16 20:18   ` Krzysztof Kozlowski
2024-09-18 15:51     ` Valentina.FernandezAlanis
2024-09-22 20:21       ` Krzysztof Kozlowski
2024-09-13 14:44 ` [PATCH v1 0/5] Add Microchip IPC mailbox and remoteproc support Mathieu Poirier
2024-09-16 15:04 ` Mathieu Poirier
2024-09-16 22:28 ` Bo Gan
2024-09-17 10:45   ` Valentina.FernandezAlanis
2024-09-17 12:42     ` Conor Dooley

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=657d3fec-ed98-4b9c-81c8-1f5fc6e1c913@microchip.com \
    --to=valentina.fernandezalanis@microchip.com \
    --cc=Conor.Dooley@microchip.com \
    --cc=andersson@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dminus@andestech.com \
    --cc=jassisinghbrar@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=peterlin@andestech.com \
    --cc=robh@kernel.org \
    --cc=samuel.holland@sifive.com \
    --cc=ycliang@andestech.com \
    /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;
as well as URLs for NNTP newsgroup(s).