Am Dienstag, 5. Juni 2007 schrieb Pete Zaitcev:
> On Mon, 04 Jun 2007 10:38:44 +0200, Marcel Holtmann <[EMAIL PROTECTED]> wrote:
> 
> >  static void urb_destroy(struct kref *kref)
> >  {
> >     struct urb *urb = to_urb(kref);
> > +
> > +   if (urb->transfer_flags & URB_FREE_BUFFER)
> > +           usb_buffer_free(urb->dev, urb->transfer_buffer_length,
> > +                           urb->transfer_buffer, urb->transfer_dma);
> > +
> >     kfree(urb);
> >  }
> 
> This looks good to me, although it's useless for the vast majority
> of drivers, because they use kmalloc, or should use kmalloc, but
> use usb_buffer_alloc due to confusion. I'm actually wondering now
> if your driver is one of the latter...

OK, we need to discuss this.

>From Documentation/usb/dma.txt about usb_buffer_alloc():

  The memory buffer returned is "dma-coherent"; sometimes you might need to
  force a consistent memory access ordering by using memory barriers.  It's
  not using a streaming DMA mapping, so it's good for small transfers on
  systems where the I/O would otherwise tie up an IOMMU mapping.  (See
  Documentation/DMA-mapping.txt for definitions of "coherent" and "streaming"

void *hcd_buffer_alloc(
        struct usb_bus  *bus,
        size_t                  size,
        gfp_t                   mem_flags,
        dma_addr_t              *dma
)
{
        struct usb_hcd          *hcd = bus_to_hcd(bus);
        int                     i;

        /* some USB hosts just use PIO */
        if (!bus->controller->dma_mask) {
                *dma = ~(dma_addr_t) 0;
                return kmalloc(size, mem_flags);
        }

        for (i = 0; i < HCD_BUFFER_POOLS; i++) {
                if (size <= pool_max [i])
                        return dma_pool_alloc(hcd->pool [i], mem_flags, dma);
        }
        return dma_alloc_coherent(hcd->self.controller, size, dma, 0);
}

This takes reasonably care of granularity.

So what exactly is the problem? Is the documentation wrong?

        Regards
                Oliver

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to