mirror of
https://github.com/torvalds/linux.git
synced 2026-05-26 08:02:27 +02:00
media: uvcvideo: use usb_alloc_noncoherent/usb_free_noncoherent()
This will use USB noncoherent API to alloc/free urb buffers, then uvc driver needn't to do dma sync operations by itself. Reviewed-by: Ricardo Ribalda <ribalda@chromium.org> Signed-off-by: Xu Yang <xu.yang_2@nxp.com> Reviewed-by: Hans de Goede <hansg@kernel.org> Link: https://lore.kernel.org/r/20250704095751.73765-3-xu.yang_2@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
488e6eaab8
commit
41b2a7eb1d
|
|
@ -1275,20 +1275,6 @@ static inline enum dma_data_direction uvc_stream_dir(
|
|||
return DMA_TO_DEVICE;
|
||||
}
|
||||
|
||||
static inline struct device *uvc_stream_to_dmadev(struct uvc_streaming *stream)
|
||||
{
|
||||
return bus_to_hcd(stream->dev->udev->bus)->self.sysdev;
|
||||
}
|
||||
|
||||
static int uvc_submit_urb(struct uvc_urb *uvc_urb, gfp_t mem_flags)
|
||||
{
|
||||
/* Sync DMA. */
|
||||
dma_sync_sgtable_for_device(uvc_stream_to_dmadev(uvc_urb->stream),
|
||||
uvc_urb->sgt,
|
||||
uvc_stream_dir(uvc_urb->stream));
|
||||
return usb_submit_urb(uvc_urb->urb, mem_flags);
|
||||
}
|
||||
|
||||
/*
|
||||
* uvc_video_decode_data_work: Asynchronous memcpy processing
|
||||
*
|
||||
|
|
@ -1310,7 +1296,7 @@ static void uvc_video_copy_data_work(struct work_struct *work)
|
|||
uvc_queue_buffer_release(op->buf);
|
||||
}
|
||||
|
||||
ret = uvc_submit_urb(uvc_urb, GFP_KERNEL);
|
||||
ret = usb_submit_urb(uvc_urb->urb, GFP_KERNEL);
|
||||
if (ret < 0)
|
||||
dev_err(&uvc_urb->stream->intf->dev,
|
||||
"Failed to resubmit video URB (%d).\n", ret);
|
||||
|
|
@ -1736,12 +1722,6 @@ static void uvc_video_complete(struct urb *urb)
|
|||
/* Re-initialise the URB async work. */
|
||||
uvc_urb->async_operations = 0;
|
||||
|
||||
/* Sync DMA and invalidate vmap range. */
|
||||
dma_sync_sgtable_for_cpu(uvc_stream_to_dmadev(uvc_urb->stream),
|
||||
uvc_urb->sgt, uvc_stream_dir(stream));
|
||||
invalidate_kernel_vmap_range(uvc_urb->buffer,
|
||||
uvc_urb->stream->urb_size);
|
||||
|
||||
/*
|
||||
* Process the URB headers, and optionally queue expensive memcpy tasks
|
||||
* to be deferred to a work queue.
|
||||
|
|
@ -1750,7 +1730,7 @@ static void uvc_video_complete(struct urb *urb)
|
|||
|
||||
/* If no async work is needed, resubmit the URB immediately. */
|
||||
if (!uvc_urb->async_operations) {
|
||||
ret = uvc_submit_urb(uvc_urb, GFP_ATOMIC);
|
||||
ret = usb_submit_urb(uvc_urb->urb, GFP_ATOMIC);
|
||||
if (ret < 0)
|
||||
dev_err(&stream->intf->dev,
|
||||
"Failed to resubmit video URB (%d).\n", ret);
|
||||
|
|
@ -1765,17 +1745,15 @@ static void uvc_video_complete(struct urb *urb)
|
|||
*/
|
||||
static void uvc_free_urb_buffers(struct uvc_streaming *stream)
|
||||
{
|
||||
struct device *dma_dev = uvc_stream_to_dmadev(stream);
|
||||
struct usb_device *udev = stream->dev->udev;
|
||||
struct uvc_urb *uvc_urb;
|
||||
|
||||
for_each_uvc_urb(uvc_urb, stream) {
|
||||
if (!uvc_urb->buffer)
|
||||
continue;
|
||||
|
||||
dma_vunmap_noncontiguous(dma_dev, uvc_urb->buffer);
|
||||
dma_free_noncontiguous(dma_dev, stream->urb_size, uvc_urb->sgt,
|
||||
uvc_stream_dir(stream));
|
||||
|
||||
usb_free_noncoherent(udev, stream->urb_size, uvc_urb->buffer,
|
||||
uvc_stream_dir(stream), uvc_urb->sgt);
|
||||
uvc_urb->buffer = NULL;
|
||||
uvc_urb->sgt = NULL;
|
||||
}
|
||||
|
|
@ -1786,26 +1764,13 @@ static void uvc_free_urb_buffers(struct uvc_streaming *stream)
|
|||
static bool uvc_alloc_urb_buffer(struct uvc_streaming *stream,
|
||||
struct uvc_urb *uvc_urb, gfp_t gfp_flags)
|
||||
{
|
||||
struct device *dma_dev = uvc_stream_to_dmadev(stream);
|
||||
struct usb_device *udev = stream->dev->udev;
|
||||
|
||||
uvc_urb->sgt = dma_alloc_noncontiguous(dma_dev, stream->urb_size,
|
||||
uvc_stream_dir(stream),
|
||||
gfp_flags, 0);
|
||||
if (!uvc_urb->sgt)
|
||||
return false;
|
||||
uvc_urb->dma = uvc_urb->sgt->sgl->dma_address;
|
||||
|
||||
uvc_urb->buffer = dma_vmap_noncontiguous(dma_dev, stream->urb_size,
|
||||
uvc_urb->sgt);
|
||||
if (!uvc_urb->buffer) {
|
||||
dma_free_noncontiguous(dma_dev, stream->urb_size,
|
||||
uvc_urb->sgt,
|
||||
uvc_stream_dir(stream));
|
||||
uvc_urb->sgt = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
uvc_urb->buffer = usb_alloc_noncoherent(udev, stream->urb_size,
|
||||
gfp_flags, &uvc_urb->dma,
|
||||
uvc_stream_dir(stream),
|
||||
&uvc_urb->sgt);
|
||||
return !!uvc_urb->buffer;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -1953,6 +1918,7 @@ static int uvc_init_video_isoc(struct uvc_streaming *stream,
|
|||
urb->complete = uvc_video_complete;
|
||||
urb->number_of_packets = npackets;
|
||||
urb->transfer_buffer_length = size;
|
||||
urb->sgt = uvc_urb->sgt;
|
||||
|
||||
for (i = 0; i < npackets; ++i) {
|
||||
urb->iso_frame_desc[i].offset = i * psize;
|
||||
|
|
@ -2009,6 +1975,7 @@ static int uvc_init_video_bulk(struct uvc_streaming *stream,
|
|||
size, uvc_video_complete, uvc_urb);
|
||||
urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
|
||||
urb->transfer_dma = uvc_urb->dma;
|
||||
urb->sgt = uvc_urb->sgt;
|
||||
|
||||
uvc_urb->urb = urb;
|
||||
}
|
||||
|
|
@ -2120,7 +2087,7 @@ static int uvc_video_start_transfer(struct uvc_streaming *stream,
|
|||
|
||||
/* Submit the URBs. */
|
||||
for_each_uvc_urb(uvc_urb, stream) {
|
||||
ret = uvc_submit_urb(uvc_urb, gfp_flags);
|
||||
ret = usb_submit_urb(uvc_urb->urb, gfp_flags);
|
||||
if (ret < 0) {
|
||||
dev_err(&stream->intf->dev,
|
||||
"Failed to submit URB %u (%d).\n",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user