Re: [PATCH] dma-coherent: add support for multi coherent rmems per dev

From: Greg KH
Date: Thu Feb 01 2024 - 10:41:38 EST


On Thu, Feb 01, 2024 at 10:45:30AM +0000, Robin Murphy wrote:
> On 2024-02-01 9:35 am, Howard Yen wrote:
> > Add support for multiple coherent rmems per device. This patch addes
> > dma_mem_list to device structure to store multiple rmems.
> >
> > These multiple rmems can be assigned to the device one by one by
> > of_reserved_mem_device_init_by_idx() with the memory-region
> > declaration in device tree as below and store the rmem to the dma_mem_list.
> >
> > device1@0 {
> > ...
> > memory-region = <&reserved_mem0>, <&reserved_mem1>;
> > ...
> > };
> >
> > When driver tries to allocate memory from the rmems, looks for the first
> > available rmem and allocates the memory from this rmem.
> >
> > Then if driver removed, of_reserved_mem_device_release() needs to be
> > invoked to release all the rmems assigned to the device.
> >
> > Signed-off-by: Howard Yen <howardyen@xxxxxxxxxx>
> > ---
> > include/linux/device.h | 1 +
> > kernel/dma/coherent.c | 66 +++++++++++++++++++++++++++++++++++-------
> > 2 files changed, 56 insertions(+), 11 deletions(-)
> >
> > diff --git a/include/linux/device.h b/include/linux/device.h
> > index 97c4b046c09d..c8682ee507cf 100644
> > --- a/include/linux/device.h
> > +++ b/include/linux/device.h
> > @@ -751,6 +751,7 @@ struct device {
> > #ifdef CONFIG_DMA_DECLARE_COHERENT
> > struct dma_coherent_mem *dma_mem; /* internal for coherent mem
> > override */
> > + struct list_head dma_mem_list;
>
> I'm not necessarily against the idea, but only if it's implemented sensibly.
> If we're going to have a list of these it should *replace* the existing
> pointer, not do this weird thing with both.

Agreed, it should be one pointer max for this structure for this type of
thing. Why not move it into the dma_coherent_mem structure?

thanks,

greg k-h