Re: [RFC PATCH v3 2/2] USB: add HCD_NO_COHERENT_MEM host controller driver flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2 Mar 2010, Albert Herranz wrote:

> The HCD_NO_COHERENT_MEM USB host controller driver flag can be enabled
> to instruct the USB stack to avoid allocating coherent memory for USB
> buffers.

This patch appears to be based on your earlier work, not on the current 
development kernel.

> --- a/drivers/usb/core/buffer.c
> +++ b/drivers/usb/core/buffer.c
> @@ -53,8 +53,9 @@ int hcd_buffer_create(struct usb_hcd *hcd)
>  	char		name[16];
>  	int 		i, size;
>  
> -	if (!hcd->self.controller->dma_mask &&
> -	    !(hcd->driver->flags & HCD_LOCAL_MEM))
> +	if ((!hcd->self.controller->dma_mask &&
> +	    !(hcd->driver->flags & HCD_LOCAL_MEM)) ||
> +	    (hcd->driver->flags & HCD_NO_COHERENT_MEM))
>  		return 0;
>  
>  	for (i = 0; i < HCD_BUFFER_POOLS; i++) {
> @@ -109,8 +110,9 @@ void *hcd_buffer_alloc(
>  	int 			i;
>  
>  	/* some USB hosts just use PIO */
> -	if (!bus->controller->dma_mask &&
> -	    !(hcd->driver->flags & HCD_LOCAL_MEM)) {
> +	if ((!bus->controller->dma_mask &&
> +	    !(hcd->driver->flags & HCD_LOCAL_MEM)) ||
> +	    (hcd->driver->flags & HCD_NO_COHERENT_MEM)) {
>  		*dma = ~(dma_addr_t) 0;
>  		return kmalloc(size, mem_flags);
>  	}
> @@ -135,8 +137,9 @@ void hcd_buffer_free(
>  	if (!addr)
>  		return;
>  
> -	if (!bus->controller->dma_mask &&
> -	    !(hcd->driver->flags & HCD_LOCAL_MEM)) {
> +	if ((!bus->controller->dma_mask &&
> +	    !(hcd->driver->flags & HCD_LOCAL_MEM)) ||
> +	    (hcd->driver->flags & HCD_NO_COHERENT_MEM)) {
>  		kfree(addr);
>  		return;
>  	}

These three tests should be encapsulated in a single subroutine.

> --- a/drivers/usb/core/hcd.c
> +++ b/drivers/usb/core/hcd.c
> @@ -1267,6 +1267,16 @@ static void unmap_urb_setup_packet(struct usb_hcd *hcd, struct urb *urb)
>  		dma_unmap_single(hcd->self.controller, urb->setup_dma,
>  				 sizeof(struct usb_ctrlrequest),
>  				 DMA_TO_DEVICE);
> +		/*
> +		 * For the HCD_NO_COHERENT_MEM case we need to reset
> +		 * setup_dma to its original value if the buffer was
> +		 * allocated via usb_buffer_alloc().
> +		 * This is necessary to force a new streaming DMA mapping
> +		 * when the same buffer is used again as the setup packet.

This is a little fragile.  I think it would be better to move the test
for HCD_NO_COHERENT_MEM into the submission path, by combining it with
the URB_NO_SETUP_DMA_MAP test.  Evidently this case has to be covered
either during submission or during giveback, and doing it during
submission would be cleaner.

The same goes for URB_NO_TRANSFER_DMA_SETUP, of course.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux