[U-Boot] [PATCH 2/5] drivers: dma: Add function to zeroes a range of destination such as memory

Chee, Tien Fong tien.fong.chee at intel.com
Mon Jun 4 07:34:06 UTC 2018


On Fri, 2018-06-01 at 08:24 -0600, Simon Glass wrote:
> Hi Tien,
> 
> On 31 May 2018 at 02:08,  <tien.fong.chee at intel.com> wrote:
> > 
> > From: Tien Fong Chee <tien.fong.chee at intel.com>
> > 
> > This new DMA class function enables DMA being used for initializing
> > a range of destination such as memory to zeros. This is quite
> > useful to
> > help accelerating the performance in scrubbing memory when ECC is
> > enabled.
> > 
> > Signed-off-by: Tien Fong Chee <tien.fong.chee at intel.com>
> > ---
> >  drivers/dma/dma-uclass.c | 15 +++++++++++++++
> >  include/dma.h            | 12 ++++++++++++
> >  2 files changed, 27 insertions(+)
> > 
> > diff --git a/drivers/dma/dma-uclass.c b/drivers/dma/dma-uclass.c
> > index a33f7d5..cb83c24 100644
> > --- a/drivers/dma/dma-uclass.c
> > +++ b/drivers/dma/dma-uclass.c
> > @@ -61,6 +61,21 @@ int dma_memcpy(void *dst, void *src, size_t len)
> >         return ops->transfer(dev, DMA_MEM_TO_MEM, dst, src, len);
> >  }
> > 
> > +int dma_memcpy_zeroes(struct udevice *dev, void *dst, size_t len)
> > +{
> > +       const struct dma_ops *ops;
> > +
> > +       ops = device_get_ops(dev);
> > +       if (!ops->transfer_zeroes)
> > +               return -ENOSYS;
> > +
> > +       /* Invalidate the area, so no writeback into the RAM races
> > with DMA */
> > +       invalidate_dcache_range((unsigned long)dst, (unsigned
> > long)dst +
> > +                               roundup(len, ARCH_DMA_MINALIGN));
> > +
> > +       return ops->transfer_zeroes(dev, dst, len);
> > +}
> > +
> >  UCLASS_DRIVER(dma) = {
> >         .id             = UCLASS_DMA,
> >         .name           = "dma",
> > diff --git a/include/dma.h b/include/dma.h
> > index 50e9652..6bad2264 100644
> > --- a/include/dma.h
> > +++ b/include/dma.h
> > @@ -46,6 +46,7 @@ struct dma_ops {
> >          */
> >         int (*transfer)(struct udevice *dev, int direction, void
> > *dst,
> >                         void *src, size_t len);
> > +       int (*transfer_zeroes)(struct udevice *dev, void *dst,
> > size_t len);
> I wonder if this could be done by using transfer() with a src of NULL
> ?
> 
Yes, may be with some description about src of NULL(just for DMA330
driver) on the doc. Otherwise, it would confuse people, and other DMA
driver may treating src with NULL as error or address 0x0.
What do you think?
> > 
> >  };
> > 
> >  /*
> > @@ -82,4 +83,15 @@ int dma_get_device(u32 transfer_type, struct
> > udevice **devp);
> >   */
> >  int dma_memcpy(void *dst, void *src, size_t len);
> > 
> > +/*
> > + * dma_memcpy_zeroes - Fill up destination with zeros through DMA.
> > + *
> > + * @dev: The DMA device
> > + * @dst: destination pointer
> > + * @len: length to be copied with zero
> > + * @return: on successful transfer returns zero.
> > + *         on failure returns error code.
> > + */
> > +int dma_memcpy_zeroes(struct udevice *dev, void *dst, size_t len);
> > +
> >  #endif /* _DMA_H_ */
> > --
> > 2.2.0
> > 
> 
> Regards,
> Simon


More information about the U-Boot mailing list