Hi, On 30/01/2025 13:34, Maxime Ripard wrote: >> This patch introduces a cma-heap probe function, allowing >> users to register custom cma heaps in the device tree. >> >> A "memory-region" is bound to the cma heap at probe time >> allowing allocation of DMA buffers from that heap. >> >> Use cases: >> - registration of carved out secure heaps. Some devices >> are implementing secure memory by reserving a specific >> memory regions for that purpose. For example, this is the >> case of platforms making use of early version of >> ARM TrustZone. > > In such a case, the CMA heap would de-facto become un-mappable for > userspace, right? > It could be that the CMA heap or alternative carved-out types of heaps are made mappable to user space. An example would be an integrator decided to implement a single carved-out secure heap and have both user and kernel space programs allocate from it (using the DMA heap framework). In the case of Mali CSF GPUs, this same integrator could have decided to share the secure heap with the whole system and protect its usage with a secure FW. >> - registration of multiple memory regions at different >> locations for efficiency or HW integration reasons. >> For example, a peripheral may expect to share data at a >> specific location in RAM. This information could have been >> programmed by a FW prior to the kernel boot. > > How would you differentiate between them? For that situation, I relied on the API exposed by this proposal: - https://lore.kernel.org/lkml/20230911023038.30649-1-yong.wu@xxxxxxxxxxxx/#t The heaps would be distinguished by the name they are given. Therefore, in the CMA patch, I retrieved the name of the heap using the label of DTB node. We could do it differently and have a specific field in the DTB node to assign the name. I assumed it would be possible to call `dma_heap_find()` from the kernel driver. The name of the heap would be known by the integrator. This person may decide to hard code the name of the heap in the importer kernel driver, or pass it as a property of some sort: insmod module parameter, DTB, etc to make it generic. Florent