linux/drivers/media/usb/uvc/uvcvideo.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _USB_VIDEO_H_
#define _USB_VIDEO_H_

#ifndef __KERNEL__
#error "The uvcvideo.h header is deprecated, use linux/uvcvideo.h instead."
#endif /* __KERNEL__ */

#include <linux/atomic.h>
#include <linux/kernel.h>
#include <linux/poll.h>
#include <linux/usb.h>
#include <linux/usb/video.h>
#include <linux/uvcvideo.h>
#include <linux/videodev2.h>
#include <linux/workqueue.h>
#include <media/media-device.h>
#include <media/v4l2-device.h>
#include <media/v4l2-event.h>
#include <media/v4l2-fh.h>
#include <media/videobuf2-v4l2.h>

/* --------------------------------------------------------------------------
 * UVC constants
 */

#define UVC_TERM_INPUT
#define UVC_TERM_OUTPUT
#define UVC_TERM_DIRECTION(term)

#define UVC_ENTITY_TYPE(entity)
#define UVC_ENTITY_IS_UNIT(entity)
#define UVC_ENTITY_IS_TERM(entity)
#define UVC_ENTITY_IS_ITERM(entity)
#define UVC_ENTITY_IS_OTERM(entity)

#define UVC_EXT_GPIO_UNIT
#define UVC_EXT_GPIO_UNIT_ID

/* ------------------------------------------------------------------------
 * Driver specific constants.
 */

#define DRIVER_VERSION

/* Number of isochronous URBs. */
#define UVC_URBS
/* Maximum number of packets per URB. */
#define UVC_MAX_PACKETS

#define UVC_CTRL_CONTROL_TIMEOUT
#define UVC_CTRL_STREAMING_TIMEOUT

/* Maximum allowed number of control mappings per device */
#define UVC_MAX_CONTROL_MAPPINGS
#define UVC_MAX_CONTROL_MENU_ENTRIES

/* Devices quirks */
#define UVC_QUIRK_STATUS_INTERVAL
#define UVC_QUIRK_PROBE_MINMAX
#define UVC_QUIRK_PROBE_EXTRAFIELDS
#define UVC_QUIRK_BUILTIN_ISIGHT
#define UVC_QUIRK_STREAM_NO_FID
#define UVC_QUIRK_IGNORE_SELECTOR_UNIT
#define UVC_QUIRK_FIX_BANDWIDTH
#define UVC_QUIRK_PROBE_DEF
#define UVC_QUIRK_RESTRICT_FRAME_RATE
#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT
#define UVC_QUIRK_FORCE_Y8
#define UVC_QUIRK_FORCE_BPP
#define UVC_QUIRK_WAKE_AUTOSUSPEND
#define UVC_QUIRK_NO_RESET_RESUME
#define UVC_QUIRK_DISABLE_AUTOSUSPEND
#define UVC_QUIRK_INVALID_DEVICE_SOF

/* Format flags */
#define UVC_FMT_FLAG_COMPRESSED
#define UVC_FMT_FLAG_STREAM

/* ------------------------------------------------------------------------
 * Structures.
 */

struct gpio_desc;
struct sg_table;
struct uvc_control;
struct uvc_device;
struct uvc_video_chain;

/*
 * TODO: Put the most frequently accessed fields at the beginning of
 * structures to maximize cache efficiency.
 */
struct uvc_control_info {};

struct uvc_control_mapping {};

struct uvc_control {};

/*
 * The term 'entity' refers to both UVC units and UVC terminals.
 *
 * The type field is either the terminal type (wTerminalType in the terminal
 * descriptor), or the unit type (bDescriptorSubtype in the unit descriptor).
 * As the bDescriptorSubtype field is one byte long, the type value will
 * always have a null MSB for units. All terminal types defined by the UVC
 * specification have a non-null MSB, so it is safe to use the MSB to
 * differentiate between units and terminals as long as the descriptor parsing
 * code makes sure terminal types have a non-null MSB.
 *
 * For terminals, the type's most significant bit stores the terminal
 * direction (either UVC_TERM_INPUT or UVC_TERM_OUTPUT). The type field should
 * always be accessed with the UVC_ENTITY_* macros and never directly.
 */

#define UVC_ENTITY_FLAG_DEFAULT

struct uvc_entity {};

struct uvc_frame {};

struct uvc_format {};

struct uvc_streaming_header {};

enum uvc_buffer_state {};

struct uvc_buffer {};

#define UVC_QUEUE_DISCONNECTED
#define UVC_QUEUE_DROP_CORRUPTED

struct uvc_video_queue {};

struct uvc_video_chain {};

struct uvc_stats_frame {};

struct uvc_stats_stream {};

#define UVC_METADATA_BUF_SIZE

/**
 * struct uvc_copy_op: Context structure to schedule asynchronous memcpy
 *
 * @buf: active buf object for this operation
 * @dst: copy destination address
 * @src: copy source address
 * @len: copy length
 */
struct uvc_copy_op {};

/**
 * struct uvc_urb - URB context management structure
 *
 * @urb: the URB described by this context structure
 * @stream: UVC streaming context
 * @buffer: memory storage for the URB
 * @dma: Allocated DMA handle
 * @sgt: sgt_table with the urb locations in memory
 * @async_operations: counter to indicate the number of copy operations
 * @copy_operations: work descriptors for asynchronous copy operations
 * @work: work queue entry for asynchronous decode
 */
struct uvc_urb {};

struct uvc_streaming {};

#define for_each_uvc_urb(uvc_urb, uvc_streaming)

static inline u32 uvc_urb_index(const struct uvc_urb *uvc_urb)
{}

struct uvc_device_info {};

struct uvc_status_streaming {} __packed;

struct uvc_status_control {} __packed;

struct uvc_status {} __packed;

struct uvc_device {};

enum uvc_handle_state {};

struct uvc_fh {};

struct uvc_driver {};

/* ------------------------------------------------------------------------
 * Debugging, printing and logging
 */

#define UVC_DBG_PROBE
#define UVC_DBG_DESCR
#define UVC_DBG_CONTROL
#define UVC_DBG_FORMAT
#define UVC_DBG_CAPTURE
#define UVC_DBG_CALLS
#define UVC_DBG_FRAME
#define UVC_DBG_SUSPEND
#define UVC_DBG_STATUS
#define UVC_DBG_VIDEO
#define UVC_DBG_STATS
#define UVC_DBG_CLOCK

#define UVC_WARN_MINMAX
#define UVC_WARN_PROBE_DEF
#define UVC_WARN_XU_GET_RES

extern unsigned int uvc_clock_param;
extern unsigned int uvc_no_drop_param;
extern unsigned int uvc_dbg_param;
extern unsigned int uvc_timeout_param;
extern unsigned int uvc_hw_timestamps_param;

#define uvc_dbg(_dev, flag, fmt, ...)

#define uvc_dbg_cont(flag, fmt, ...)

#define uvc_warn_once(_dev, warn, fmt, ...)

/* --------------------------------------------------------------------------
 * Internal functions.
 */

/* Core driver */
extern struct uvc_driver uvc_driver;

struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);

/* Video buffers queue management. */
int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
		   int drop_corrupted);
void uvc_queue_release(struct uvc_video_queue *queue);
int uvc_request_buffers(struct uvc_video_queue *queue,
			struct v4l2_requestbuffers *rb);
int uvc_query_buffer(struct uvc_video_queue *queue,
		     struct v4l2_buffer *v4l2_buf);
int uvc_create_buffers(struct uvc_video_queue *queue,
		       struct v4l2_create_buffers *v4l2_cb);
int uvc_queue_buffer(struct uvc_video_queue *queue,
		     struct media_device *mdev,
		     struct v4l2_buffer *v4l2_buf);
int uvc_export_buffer(struct uvc_video_queue *queue,
		      struct v4l2_exportbuffer *exp);
int uvc_dequeue_buffer(struct uvc_video_queue *queue,
		       struct v4l2_buffer *v4l2_buf, int nonblocking);
int uvc_queue_streamon(struct uvc_video_queue *queue, enum v4l2_buf_type type);
int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type);
void uvc_queue_cancel(struct uvc_video_queue *queue, int disconnect);
struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
					 struct uvc_buffer *buf);
struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue);
void uvc_queue_buffer_release(struct uvc_buffer *buf);
int uvc_queue_mmap(struct uvc_video_queue *queue,
		   struct vm_area_struct *vma);
__poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
			poll_table *wait);
#ifndef CONFIG_MMU
unsigned long uvc_queue_get_unmapped_area(struct uvc_video_queue *queue,
					  unsigned long pgoff);
#endif
int uvc_queue_allocated(struct uvc_video_queue *queue);
static inline int uvc_queue_streaming(struct uvc_video_queue *queue)
{}

static inline struct uvc_streaming *
uvc_queue_to_stream(struct uvc_video_queue *queue)
{}

/* V4L2 interface */
extern const struct v4l2_ioctl_ops uvc_ioctl_ops;
extern const struct v4l2_file_operations uvc_fops;

/* Media controller */
int uvc_mc_register_entities(struct uvc_video_chain *chain);
void uvc_mc_cleanup_entity(struct uvc_entity *entity);

/* Video */
int uvc_video_init(struct uvc_streaming *stream);
int uvc_video_suspend(struct uvc_streaming *stream);
int uvc_video_resume(struct uvc_streaming *stream, int reset);
int uvc_video_start_streaming(struct uvc_streaming *stream);
void uvc_video_stop_streaming(struct uvc_streaming *stream);
int uvc_probe_video(struct uvc_streaming *stream,
		    struct uvc_streaming_control *probe);
int uvc_query_ctrl(struct uvc_device *dev, u8 query, u8 unit,
		   u8 intfnum, u8 cs, void *data, u16 size);
void uvc_video_clock_update(struct uvc_streaming *stream,
			    struct vb2_v4l2_buffer *vbuf,
			    struct uvc_buffer *buf);
int uvc_meta_register(struct uvc_streaming *stream);

int uvc_register_video_device(struct uvc_device *dev,
			      struct uvc_streaming *stream,
			      struct video_device *vdev,
			      struct uvc_video_queue *queue,
			      enum v4l2_buf_type type,
			      const struct v4l2_file_operations *fops,
			      const struct v4l2_ioctl_ops *ioctl_ops);

/* Status */
int uvc_status_init(struct uvc_device *dev);
void uvc_status_unregister(struct uvc_device *dev);
void uvc_status_cleanup(struct uvc_device *dev);
int uvc_status_start(struct uvc_device *dev, gfp_t flags);
void uvc_status_stop(struct uvc_device *dev);

/* Controls */
extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops;

int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
			struct v4l2_queryctrl *v4l2_ctrl);
int uvc_query_v4l2_menu(struct uvc_video_chain *chain,
			struct v4l2_querymenu *query_menu);

int uvc_ctrl_add_mapping(struct uvc_video_chain *chain,
			 const struct uvc_control_mapping *mapping);
int uvc_ctrl_init_device(struct uvc_device *dev);
void uvc_ctrl_cleanup_device(struct uvc_device *dev);
int uvc_ctrl_restore_values(struct uvc_device *dev);
bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain,
				 struct uvc_control *ctrl, const u8 *data);
void uvc_ctrl_status_event(struct uvc_video_chain *chain,
			   struct uvc_control *ctrl, const u8 *data);

int uvc_ctrl_begin(struct uvc_video_chain *chain);
int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback,
		      struct v4l2_ext_controls *ctrls);
static inline int uvc_ctrl_commit(struct uvc_fh *handle,
				  struct v4l2_ext_controls *ctrls)
{}
static inline int uvc_ctrl_rollback(struct uvc_fh *handle)
{}

int uvc_ctrl_get(struct uvc_video_chain *chain, struct v4l2_ext_control *xctrl);
int uvc_ctrl_set(struct uvc_fh *handle, struct v4l2_ext_control *xctrl);
int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id,
			   const struct v4l2_ext_controls *ctrls,
			   unsigned long ioctl);

int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
		      struct uvc_xu_control_query *xqry);

/* Utility functions */
struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts,
					    u8 epaddr);
u16 uvc_endpoint_max_bpi(struct usb_device *dev, struct usb_host_endpoint *ep);

/* Quirks support */
void uvc_video_decode_isight(struct uvc_urb *uvc_urb,
			     struct uvc_buffer *buf,
			     struct uvc_buffer *meta_buf);

/* debugfs and statistics */
void uvc_debugfs_init(void);
void uvc_debugfs_cleanup(void);
void uvc_debugfs_init_stream(struct uvc_streaming *stream);
void uvc_debugfs_cleanup_stream(struct uvc_streaming *stream);

size_t uvc_video_stats_dump(struct uvc_streaming *stream, char *buf,
			    size_t size);

#endif