Aligned malloc for dma and mbufs for powerpc ppc405gp

Feng, Shuchen feng at bnl.gov
Wed Nov 10 03:56:46 UTC 2004


Gene Smith wrote :

> I have a requirement to allocate a block of memory (on a 4KB boundary 
> according to the manual) for dma descriptor. I also need to have my 
> mbufs allocated on 32 byte boundaries as dma buffers. This is due to the

> ppc405gp emac and mal devices and cache line boundaries. Is there a way 
> to do this in rtems using the standard API? If not, any suggestions on 
>how this should be done?

For 32 bytes aligned, one can do :

  struct GTeth_softc *sc;

  /* Make certain elements e.g. descriptor lists are aligned. */
  softc_mem = rtems_bsdnet_malloc(sizeof(*sc) + SOFTC_ALIGN, M_FREE,
M_NOWAIT);

  /* Check for the very unlikely case of no memory. */
  if (softc_mem == NULL)
     rtems_panic("GT64260eth: OUT OF MEMORY");

  sc = (void *)(((long)softc_mem + SOFTC_ALIGN) & ~SOFTC_ALIGN);
  memset(sc, 0, sizeof(*sc))


Please note:
An mbuf cluster is aligned on a cluster-sized (2 kbyte) boundary.
Network mbufs are aligned on an mbuf-sized (128 byte) boundary. 

You can reference the network driver for my mvme5500 BSP at
http://www.nsls.bnl.gov/organization/UserScience/Detectors/Software


>Since my driver is not working I think this must be part of the problem.

Yes, it has to be done right.

Regards,
Kate



More information about the users mailing list