drivers/media/pci/ngene/ngene-dvb.c

Source file repositories/reference/linux-study-clean/drivers/media/pci/ngene/ngene-dvb.c

File Facts

System
Linux kernel
Corpus path
drivers/media/pci/ngene/ngene-dvb.c
Extension
.c
Size
8400 bytes
Lines
341
Domain
Driver Families
Bucket
drivers/media
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations ci_fops = {
	.owner   = THIS_MODULE,
	.read    = ts_read,
	.write   = ts_write,
	.open    = dvb_generic_open,
	.release = dvb_generic_release,
	.poll    = ts_poll,
	.mmap    = NULL,
};

struct dvb_device ngene_dvbdev_ci = {
	.priv    = NULL,
	.readers = 1,
	.writers = 1,
	.users   = 2,
	.fops    = &ci_fops,
};


/****************************************************************************/
/* DVB functions and API interface ******************************************/
/****************************************************************************/

static void swap_buffer(u32 *p, u32 len)
{
	while (len) {
		*p = swab32(*p);
		p++;
		len -= 4;
	}
}

/* start of filler packet */
static u8 fill_ts[] = { 0x47, 0x1f, 0xff, 0x10, TS_FILLER };

static int tsin_find_offset(void *buf, u32 len)
{
	int i, l;

	l = len - sizeof(fill_ts);
	if (l <= 0)
		return -1;

	for (i = 0; i < l; i++) {
		if (((char *)buf)[i] == 0x47) {
			if (!memcmp(buf + i, fill_ts, sizeof(fill_ts)))
				return i % 188;
		}
	}

	return -1;
}

static inline void tsin_copy_stripped(struct ngene *dev, void *buf)
{
	if (memcmp(buf, fill_ts, sizeof(fill_ts)) != 0) {
		if (dvb_ringbuffer_free(&dev->tsin_rbuf) >= 188) {
			dvb_ringbuffer_write(&dev->tsin_rbuf, buf, 188);
			wake_up(&dev->tsin_rbuf.queue);
		}
	}
}

void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
{
	struct ngene_channel *chan = priv;
	struct ngene *dev = chan->dev;
	int tsoff;

	if (flags & DF_SWAP32)
		swap_buffer(buf, len);

	if (dev->ci.en && chan->number == 2) {
		/* blindly copy buffers if ci_tsfix is disabled */
		if (!ci_tsfix) {
			while (len >= 188) {
				tsin_copy_stripped(dev, buf);

				buf += 188;
				len -= 188;
			}
			return NULL;
		}

		/* ci_tsfix = 1 */

		/*
		 * since the remainder of the TS packet which got cut off
		 * in the previous tsin_exchange() run is at the beginning
		 * of the new TS buffer, append this to the temp buffer and

Annotation

Implementation Notes