drivers/media/usb/pvrusb2/pvrusb2-io.c

Source file repositories/reference/linux-study-clean/drivers/media/usb/pvrusb2/pvrusb2-io.c

File Facts

System
Linux kernel
Corpus path
drivers/media/usb/pvrusb2/pvrusb2-io.c
Extension
.c
Size
17826 bytes
Lines
673
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct pvr2_stream {
	/* Buffers queued for reading */
	struct list_head queued_list;
	unsigned int q_count;
	unsigned int q_bcount;
	/* Buffers with retrieved data */
	struct list_head ready_list;
	unsigned int r_count;
	unsigned int r_bcount;
	/* Buffers available for use */
	struct list_head idle_list;
	unsigned int i_count;
	unsigned int i_bcount;
	/* Pointers to all buffers */
	struct pvr2_buffer **buffers;
	/* Array size of buffers */
	unsigned int buffer_slot_count;
	/* Total buffers actually in circulation */
	unsigned int buffer_total_count;
	/* Designed number of buffers to be in circulation */
	unsigned int buffer_target_count;
	/* Executed when ready list become non-empty */
	pvr2_stream_callback callback_func;
	void *callback_data;
	/* Context for transfer endpoint */
	struct usb_device *dev;
	int endpoint;
	/* Overhead for mutex enforcement */
	spinlock_t list_lock;
	struct mutex mutex;
	/* Tracking state for tolerating errors */
	unsigned int fail_count;
	unsigned int fail_tolerance;

	unsigned int buffers_processed;
	unsigned int buffers_failed;
	unsigned int bytes_processed;
};

struct pvr2_buffer {
	int id;
	int signature;
	enum pvr2_buffer_state state;
	void *ptr;               /* Pointer to storage area */
	unsigned int max_count;  /* Size of storage area */
	unsigned int used_count; /* Amount of valid data in storage area */
	int status;              /* Transfer result status */
	struct pvr2_stream *stream;
	struct list_head list_overhead;
	struct urb *purb;
};

static const char *pvr2_buffer_state_decode(enum pvr2_buffer_state st)
{
	switch (st) {
	case pvr2_buffer_state_none: return "none";
	case pvr2_buffer_state_idle: return "idle";
	case pvr2_buffer_state_queued: return "queued";
	case pvr2_buffer_state_ready: return "ready";
	}
	return "unknown";
}

#ifdef SANITY_CHECK_BUFFERS
static void pvr2_buffer_describe(struct pvr2_buffer *bp, const char *msg)
{
	pvr2_trace(PVR2_TRACE_INFO,
		   "buffer%s%s %p state=%s id=%d status=%d stream=%p purb=%p sig=0x%x",
		   (msg ? " " : ""),
		   (msg ? msg : ""),
		   bp,
		   (bp ? pvr2_buffer_state_decode(bp->state) : "(invalid)"),
		   (bp ? bp->id : 0),
		   (bp ? bp->status : 0),
		   (bp ? bp->stream : NULL),
		   (bp ? bp->purb : NULL),
		   (bp ? bp->signature : 0));
}
#endif  /*  SANITY_CHECK_BUFFERS  */

static void pvr2_buffer_remove(struct pvr2_buffer *bp)
{
	unsigned int *cnt;
	unsigned int *bcnt;
	unsigned int ccnt;
	struct pvr2_stream *sp = bp->stream;
	switch (bp->state) {
	case pvr2_buffer_state_idle:
		cnt = &sp->i_count;
		bcnt = &sp->i_bcount;

Annotation

Implementation Notes