Re: [PATCH 3/3] misc: fastrpc: Use context device bus for compute banks

From: Vishnu Reddy

Date: Wed Apr 22 2026 - 03:01:44 EST



On 4/19/2026 5:46 AM, Dmitry Baryshkov wrote:
> On Wed, Apr 15, 2026 at 09:35:47PM +0530, Vishnu Reddy wrote:
>>
>> On 4/14/2026 10:01 PM, Ekansh Gupta wrote:
>>> Replace the platform driver approach for compute bank (CB) devices
>>> with the generic context_device_bus_type. Compute bank devices are
>>> synthetic IOMMU context banks, not real platform devices, so using
>>> the context device bus provides a more accurate representation in
>>> the device model.
>>>
>>> Currently, fastrpc used of_platform_populate() to create platform
>>> devices for each "qcom,fastrpc-compute-cb" DT node, with a platform
>>> driver (fastrpc_cb_driver) to handle probe/remove. This approach
>>> had a race condition: device nodes were created before channel
>>> resources (like spin_lock) were initialized, and probe was async,
>>> so applications could open the device before sessions were available.
>>>
>>> This patch addresses the race by manually creating and configuring
>>> CB devices synchronously during fastrpc_rpmsg_probe(), after all
>>> channel resources are initialized. The approach follows the pattern
>>> used in host1x_memory_context_list_init().
>>>
>>> Signed-off-by: Ekansh Gupta <ekansh.gupta@xxxxxxxxxxxxxxxx>
>>> ---
>>> drivers/misc/Kconfig | 1 +
>>> drivers/misc/fastrpc.c | 180 ++++++++++++++++++++++++++++++++++---------------
>>> 2 files changed, 125 insertions(+), 56 deletions(-)
>>>
>>> }
>>> dma_bits = cctx->soc_data->dma_addr_bits_default;
>>> + if (cctx->domain_id == CDSP_DOMAIN_ID)
>>> + dma_bits = cctx->soc_data->dma_addr_bits_cdsp;
>>> +
>>> sess = &cctx->session[cctx->sesscount++];
>>> sess->used = false;
>>> sess->valid = true;
>>> - sess->dev = dev;
>>> - dev_set_drvdata(dev, sess);
>>> + sess->sid = sid;
>>> + spin_unlock_irqrestore(&cctx->lock, flags);
>>> - if (cctx->domain_id == CDSP_DOMAIN_ID)
>>> - dma_bits = cctx->soc_data->dma_addr_bits_cdsp;
>>> + cb_dev = kzalloc_obj(*cb_dev);
>>> + if (!cb_dev)
>>> + return -ENOMEM;
>>> - if (of_property_read_u32(dev->of_node, "reg", &sess->sid))
>>> - dev_info(dev, "FastRPC Session ID not specified in DT\n");
>>> + cb_dev->sess = sess;
>>> - if (sessions > 0) {
>>> - struct fastrpc_session_ctx *dup_sess;
>>> + device_initialize(&cb_dev->dev);
>>> + cb_dev->dev.parent = parent;
>>> + cb_dev->dev.bus = &context_device_bus_type;
>>> + cb_dev->dev.release = fastrpc_cb_dev_release;
>>> + cb_dev->dev.of_node = of_node_get(cb_node);
>>> + cb_dev->dev.dma_mask = &cb_dev->dev.coherent_dma_mask;
>>> + cb_dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
>>> + dev_set_name(&cb_dev->dev, "%s:compute-cb@%u", dev_name(parent), sid);
>>> + rc = device_add(&cb_dev->dev);
>> device_initialize() and device_add() can be replaced with single
>> device_register() call. You can refer the below patch,
> Keep in mind that for several arches device_initialize() sets the
> coherent_dma_mask. So one should set coherent_dma_mask (as it's done
> here) after calling device_initialize().

I can see that device_initialize() sets dma_coherent flag for several arches,
not the coherent_dma_mask. The final dma_coherent flag value is updated later
in of_dma_configure_id() based on the dt dma-coherent property.

Setting the coherent_dma_mask here and calling device_register() which will
call the device_initialize() won't change the coherent_dma_mask value.
Please correct me if I'm wrong?

>> https://lore.kernel.org/all/20260313-kaanapali-iris-v3-4-9c0d1a67af4b@xxxxxxxxxxxxxxxx/
>>