*/
-extern void printques(int);
-
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
local_irq_disable();
#ifdef DEBUG_QUES_B
- printques(minor);
+ printques(fb);
#endif
if (fb->nbuffers > 2)
{
- if (!are_empty_buffers(minor))
+ if (!are_empty_buffers(fb))
{
/* The number of active + locked buffers is
* at most 2, and since there are none empty, there
* must be at least nbuffers-2 ready buffers.
* This is where we 'drop frames', oldest first. */
- push_empty(pop_ready(minor), minor);
+ push_empty(fb, pop_ready(fb));
}
/* The ready_que can't be full, since we know
* there is one active buffer right now, so it's safe
* to push the active buf on the ready_que. */
- push_ready(minor, fb->active_buf);
+ push_ready(fb, fb->active_buf);
/* There's at least 1 empty -- make it active */
- fb->active_buf = pop_empty(minor);
+ fb->active_buf = pop_empty(fb);
fb->frame_info[fb->active_buf].tag = ++unique_tag;
}
else /* nbuffers == 2, special case */
*/
if (fb->locked_buf < 0)
{
- push_ready(minor, fb->active_buf);
- if (are_empty_buffers(minor))
+ push_ready(fb, fb->active_buf);
+ if (are_empty_buffers(fb))
{
- fb->active_buf = pop_empty(minor);
+ fb->active_buf = pop_empty(fb);
}
else
{ /* no empty or locked buffers, so use a readybuf */
- fb->active_buf = pop_ready(minor);
+ fb->active_buf = pop_ready(fb);
}
}
}
#ifdef DEBUG_QUES_B
- printques(minor);
+ printques(fb);
#endif
fb->even_happened = 0;
{
if (dts->state != DT3155_STATE_IDLE)
return -EBUSY;
- return dt3155_flush(minor);
+ return dt3155_flush(fb);
}
case DT3155_STOP:
{
{
int minor = MINOR(inode->i_rdev); /* what device are we opening? */
struct dt3155_status *dts = &dt3155_status[minor];
+ struct dt3155_fbuffer *fb = &dts->fbuffer;
if (dt3155_dev_open[minor]) {
printk ("DT3155: Already opened by another process.\n");
dt3155_dev_open[minor] = 1 ;
- dt3155_flush(minor);
+ dt3155_flush(fb);
/* Disable ALL interrupts */
writel(0, dt3155_lbase[minor] + INT_CSR);
/* non-blocking reads should return if no data */
if (filep->f_flags & O_NDELAY)
{
- if ((frame_index = dt3155_get_ready_buffer(minor)) < 0) {
- /*printk("dt3155: no buffers available (?)\n");*/
- /* printques(minor); */
+ if ((frame_index = dt3155_get_ready_buffer(fb)) < 0) {
+ /* printk("dt3155: no buffers available (?)\n"); */
+ /* printques(fb); */
return -EAGAIN;
}
}
* Note that wait_event_interruptible() does not actually
* sleep/wait if it's condition evaluates to true upon entry.
*/
- wait_event_interruptible(dt3155_read_wait_queue[minor],
- (frame_index = dt3155_get_ready_buffer(minor))
- >= 0);
+ frame_index = dt3155_get_ready_buffer(fb);
+ wait_event_interruptible(dt3155_read_wait_queue[minor], frame_index >= 0);
if (frame_index < 0)
{
printk ("DT3155: read: interrupted\n");
quick_stop (minor);
- printques(minor);
+ printques(fb);
return -EINTR;
}
}
static unsigned int dt3155_poll (struct file * filp, poll_table *wait)
{
int minor = MINOR(filp->f_dentry->d_inode->i_rdev);
+ struct dt3155_status *dts = &dt3155_status[minor];
+ struct dt3155_fbuffer *fb = &dts->fbuffer;
- if (!is_ready_buf_empty(minor))
+ if (!is_ready_buf_empty(fb))
return POLLIN | POLLRDNORM;
poll_wait (filp, &dt3155_read_wait_queue[minor], wait);
/***************************
* are_empty_buffers
***************************/
-bool are_empty_buffers(int minor)
+bool are_empty_buffers(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
-
return fb->empty_len;
}
* given by fb->empty_buffers[0].
* empty_buffers should never fill up, though this is not checked.
**************************/
-void push_empty(int index, int minor)
+void push_empty(struct dt3155_fbuffer *fb, int index)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
-
fb->empty_buffers[fb->empty_len] = index;
fb->empty_len++;
}
/**************************
* pop_empty
**************************/
-int pop_empty(int minor)
+int pop_empty(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
-
fb->empty_len--;
return fb->empty_buffers[fb->empty_len];
}
/*************************
* is_ready_buf_empty
*************************/
-bool is_ready_buf_empty(int minor)
+bool is_ready_buf_empty(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
-
return fb->ready_len == 0;
}
* buffers, since it corresponds to nbuffers ready buffers!!
* 7/31/02: total rewrite. --NJC
*************************/
-bool is_ready_buf_full(int minor)
+bool is_ready_buf_full(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
-
return fb->ready_len == fb->nbuffers;
}
/*****************************************************
* push_ready
*****************************************************/
-void push_ready(int minor, int index)
+void push_ready(struct dt3155_fbuffer *fb, int index)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
int head = fb->ready_head;
fb->ready_que[head] = index;
*
* Simply comptutes the tail given the head and the length.
*****************************************************/
-static int get_tail(int minor)
+static int get_tail(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
-
return (fb->ready_head - fb->ready_len + fb->nbuffers) % fb->nbuffers;
}
* This assumes that there is a ready buffer ready... should
* be checked (e.g. with is_ready_buf_empty() prior to call.
*****************************************************/
-int pop_ready(int minor)
+int pop_ready(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
- int tail = get_tail(minor);
+ int tail = get_tail(fb);
fb->ready_len--;
return fb->ready_que[tail];
/*****************************************************
* printques
*****************************************************/
-void printques(int minor)
+void printques(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
int i;
printk(KERN_INFO "\n R:");
- for (i = get_tail(minor); i != fb->ready_head; i++, i %= fb->nbuffers)
+ for (i = get_tail(fb); i != fb->ready_head; i++, i %= fb->nbuffers)
printk(" %d ", fb->ready_que[i]);
printk(KERN_INFO "\n E:");
}
fb->frame_info[index].addr = rambuff_acm;
- push_empty(index, minor);
+ push_empty(fb, index);
/* printk(" - Buffer : %lx\n", fb->frame_info[index].addr); */
fb->nbuffers += 1;
rambuff_acm += bufsize;
}
/* Make sure there is an active buffer there. */
- fb->active_buf = pop_empty(minor);
+ fb->active_buf = pop_empty(fb);
fb->even_happened = 0;
fb->even_stopped = 0;
* The internal function for releasing a locked buffer.
* It assumes interrupts are turned off.
*****************************************************/
-static void internal_release_locked_buffer(int minor)
+static void internal_release_locked_buffer(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
-
if (fb->locked_buf >= 0) {
- push_empty(fb->locked_buf, minor);
+ push_empty(fb, fb->locked_buf);
fb->locked_buf = -1;
}
}
*
* The user function of the above.
*****************************************************/
-void dt3155_release_locked_buffer(int minor)
+void dt3155_release_locked_buffer(struct dt3155_fbuffer *fb)
{
unsigned long int flags;
local_save_flags(flags);
local_irq_disable();
- internal_release_locked_buffer(minor);
+ internal_release_locked_buffer(fb);
local_irq_restore(flags);
}
/*****************************************************
* dt3155_flush
*****************************************************/
-int dt3155_flush(int minor)
+int dt3155_flush(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
unsigned long int flags;
int index;
local_save_flags(flags);
local_irq_disable();
- internal_release_locked_buffer(minor);
+ internal_release_locked_buffer(fb);
fb->empty_len = 0;
for (index = 0; index < fb->nbuffers; index++)
- push_empty(index, minor);
+ push_empty(fb, index);
/* Make sure there is an active buffer there. */
- fb->active_buf = pop_empty(minor);
+ fb->active_buf = pop_empty(fb);
fb->even_happened = 0;
fb->even_stopped = 0;
* If the user has a buffer locked it will unlock
* that buffer before returning the new one.
*****************************************************/
-int dt3155_get_ready_buffer(int minor)
+int dt3155_get_ready_buffer(struct dt3155_fbuffer *fb)
{
- struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
unsigned long int flags;
int frame_index;
local_irq_disable();
#ifdef DEBUG_QUES_A
- printques(minor);
+ printques(fb);
#endif
- internal_release_locked_buffer(minor);
+ internal_release_locked_buffer(fb);
- if (is_ready_buf_empty(minor)) {
+ if (is_ready_buf_empty(fb)) {
frame_index = -1;
} else {
- frame_index = pop_ready(minor);
+ frame_index = pop_ready(fb);
fb->locked_buf = frame_index;
- }
+ }
#ifdef DEBUG_QUES_B
- printques(minor);
+ printques(fb);
#endif
local_irq_restore(flags);
#ifndef DT3155_ISR_H
#define DT3155_ISR_H
-/* User functions for buffering */
-/* Initialize the buffering system. This should */
-/* be called prior to enabling interrupts */
+/**********************************
+ * User functions for buffering
+ **********************************/
+/*
+ * Initialize the buffering system.
+ * This should be called prior to enabling interrupts
+ */
u32 dt3155_setup_buffers(u32 *allocatorAddr);
-/* Get the next frame of data if it is ready. Returns */
-/* zero if no data is ready. If there is data but */
-/* the user has a locked buffer, it will unlock that */
-/* buffer and return it to the free list. */
-
-int dt3155_get_ready_buffer(int minor);
-
-/* Return a locked buffer to the free list */
+/*
+ * Get the next frame of data if it is ready.
+ * Returns zero if no data is ready. If there is data but the user has a
+ * locked buffer, it will unlock that buffer and return it to the free list.
+ */
+int dt3155_get_ready_buffer(struct dt3155_fbuffer *fb);
-void dt3155_release_locked_buffer(int minor);
+/*
+ * Return a locked buffer to the free list.
+ */
+void dt3155_release_locked_buffer(struct dt3155_fbuffer *fb);
-/* Flush the buffer system */
-int dt3155_flush(int minor);
+/*
+ * Flush the buffer system.
+ */
+int dt3155_flush(struct dt3155_fbuffer *fb);
/**********************************
* Simple array based que struct
**********************************/
-bool are_empty_buffers(int minor);
-void push_empty(int index, int minor);
+bool are_empty_buffers(struct dt3155_fbuffer *fb);
+void push_empty(struct dt3155_fbuffer *fb, int index);
-int pop_empty(int minor);
+int pop_empty(struct dt3155_fbuffer *fb);
-bool is_ready_buf_empty(int minor);
-bool is_ready_buf_full(int minor);
+bool is_ready_buf_empty(struct dt3155_fbuffer *fb);
+bool is_ready_buf_full(struct dt3155_fbuffer *fb);
-void push_ready(int minor, int index);
-int pop_ready(int minor);
+void push_ready(struct dt3155_fbuffer *fb, int index);
+int pop_ready(struct dt3155_fbuffer *fb);
+void printques(struct dt3155_fbuffer *fb);
#endif