usb: gadget: uvc: Copy XU descriptors during .bind()
authorDaniel Scally <dan.scally@ideasonboard.com>
Mon, 6 Feb 2023 16:17:55 +0000 (16:17 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 7 Feb 2023 07:46:36 +0000 (08:46 +0100)
Now that extension unit support is available through configfs we need
to copy the descriptors for the XUs during uvc_function_bind() so that
they're exposed to the usb subsystem.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
Link: https://lore.kernel.org/r/20230206161802.892954-5-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_uvc.c
drivers/usb/gadget/function/uvc.h

index 443333471b4d6dabc2992ff3fddd7a9e7bc5ce4b..f6fd5decdcb7a61ba39353fe57ca287c5a617541 100644 (file)
@@ -478,6 +478,25 @@ uvc_register_video(struct uvc_device *uvc)
                } \
        } while (0)
 
+#define UVC_COPY_XU_DESCRIPTOR(mem, dst, desc)                                 \
+       do {                                                                    \
+               *(dst)++ = mem;                                                 \
+               memcpy(mem, desc, 22); /* bLength to bNrInPins */               \
+               mem += 22;                                                      \
+                                                                               \
+               memcpy(mem, (desc)->baSourceID, (desc)->bNrInPins);             \
+               mem += (desc)->bNrInPins;                                       \
+                                                                               \
+               memcpy(mem, &(desc)->bControlSize, 1);                          \
+               mem++;                                                          \
+                                                                               \
+               memcpy(mem, (desc)->bmControls, (desc)->bControlSize);          \
+               mem += (desc)->bControlSize;                                    \
+                                                                               \
+               memcpy(mem, &(desc)->iExtension, 1);                            \
+               mem++;                                                          \
+       } while (0)
+
 static struct usb_descriptor_header **
 uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
 {
@@ -489,6 +508,7 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
        const struct usb_descriptor_header * const *src;
        struct usb_descriptor_header **dst;
        struct usb_descriptor_header **hdr;
+       struct uvcg_extension *xu;
        unsigned int control_size;
        unsigned int streaming_size;
        unsigned int n_desc;
@@ -556,6 +576,13 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
                bytes += (*src)->bLength;
                n_desc++;
        }
+
+       list_for_each_entry(xu, uvc->desc.extension_units, list) {
+               control_size += xu->desc.bLength;
+               bytes += xu->desc.bLength;
+               n_desc++;
+       }
+
        for (src = (const struct usb_descriptor_header **)uvc_streaming_cls;
             *src; ++src) {
                streaming_size += (*src)->bLength;
@@ -582,6 +609,10 @@ uvc_copy_descriptors(struct uvc_device *uvc, enum usb_device_speed speed)
        uvc_control_header = mem;
        UVC_COPY_DESCRIPTORS(mem, dst,
                (const struct usb_descriptor_header **)uvc_control_desc);
+
+       list_for_each_entry(xu, uvc->desc.extension_units, list)
+               UVC_COPY_XU_DESCRIPTOR(mem, dst, &xu->desc);
+
        uvc_control_header->wTotalLength = cpu_to_le16(control_size);
        uvc_control_header->bInCollection = 1;
        uvc_control_header->baInterfaceNr[0] = uvc->streaming_intf;
@@ -1025,6 +1056,8 @@ static struct usb_function *uvc_alloc(struct usb_function_instance *fi)
                return ERR_PTR(-EBUSY);
        }
 
+       uvc->desc.extension_units = &opts->extension_units;
+
        ++opts->refcnt;
        mutex_unlock(&opts->lock);
 
index daf226610f493f07fafed9fbdca81d2a6d793eaf..100475b1363e4c26af4dba791af87f6b684ef9ce 100644 (file)
@@ -143,6 +143,7 @@ struct uvc_device {
                const struct uvc_descriptor_header * const *fs_streaming;
                const struct uvc_descriptor_header * const *hs_streaming;
                const struct uvc_descriptor_header * const *ss_streaming;
+               struct list_head *extension_units;
        } desc;
 
        unsigned int control_intf;