Skip to content

Commit

Permalink
Staging: dt3155: use the fbuffer pointer instead of looking it up
Browse files Browse the repository at this point in the history
Instead of passing the minor number and having to look up the fbuffer, just
pass the fbuffer directly to the buffer management code.

Also, to make the code more consistent, change the push_empty() call so
that the fbuffer is passed as the first parameter.

Prototype the printques routine to avoid having to declare it as extern.

Cleanup some of the comments in dt3155_isr.h.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Scott Smedley <ss@aao.gov.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Jul 22, 2010
1 parent dd85c99 commit 843894a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 90 deletions.
44 changes: 22 additions & 22 deletions drivers/staging/dt3155/dt3155_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ MA 02111-1307 USA
*/

extern void printques(int);

#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
Expand Down Expand Up @@ -329,25 +327,25 @@ static void dt3155_isr(int irq, void *dev_id, struct pt_regs *regs)
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 */
Expand All @@ -357,20 +355,20 @@ static void dt3155_isr(int irq, void *dev_id, struct pt_regs *regs)
*/
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;
Expand Down Expand Up @@ -559,7 +557,7 @@ static int dt3155_ioctl(struct inode *inode,
{
if (dts->state != DT3155_STATE_IDLE)
return -EBUSY;
return dt3155_flush(minor);
return dt3155_flush(fb);
}
case DT3155_STOP:
{
Expand Down Expand Up @@ -669,6 +667,7 @@ static int dt3155_open(struct inode* inode, struct file* filep)
{
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");
Expand All @@ -692,7 +691,7 @@ static int dt3155_open(struct inode* inode, struct file* filep)

dt3155_dev_open[minor] = 1 ;

dt3155_flush(minor);
dt3155_flush(fb);

/* Disable ALL interrupts */
writel(0, dt3155_lbase[minor] + INT_CSR);
Expand Down Expand Up @@ -767,9 +766,9 @@ static ssize_t dt3155_read(struct file *filep, char __user *buf,
/* 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;
}
}
Expand All @@ -780,15 +779,14 @@ static ssize_t dt3155_read(struct file *filep, char __user *buf,
* 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;
}
}
Expand All @@ -813,8 +811,10 @@ static ssize_t dt3155_read(struct file *filep, char __user *buf,
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);
Expand Down
75 changes: 28 additions & 47 deletions drivers/staging/dt3155/dt3155_isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ Purpose: Buffer management routines, and other routines for the ISR
/***************************
* 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;
}

Expand All @@ -84,32 +82,26 @@ bool are_empty_buffers(int minor)
* 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;
}

Expand All @@ -120,19 +112,16 @@ bool is_ready_buf_empty(int minor)
* 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;
Expand All @@ -145,10 +134,8 @@ void push_ready(int minor, int 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;
}

Expand All @@ -158,10 +145,9 @@ static int get_tail(int minor)
* 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];
Expand All @@ -170,13 +156,12 @@ int pop_ready(int minor)
/*****************************************************
* 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:");
Expand Down Expand Up @@ -349,14 +334,14 @@ u32 dt3155_setup_buffers(u32 *allocatorAddr)
}

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;

Expand All @@ -382,12 +367,10 @@ u32 dt3155_setup_buffers(u32 *allocatorAddr)
* 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;
}
}
Expand All @@ -397,36 +380,35 @@ static void internal_release_locked_buffer(int minor)
*
* 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;
Expand All @@ -448,30 +430,29 @@ int dt3155_flush(int minor)
* 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_save_flags(flags);
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);
Expand Down
Loading

0 comments on commit 843894a

Please sign in to comment.