Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: dt3155: use the fbuffer pointer instead of looking it up

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>

authored by

H Hartley Sweeten and committed by
Greg Kroah-Hartman
843894ad dd85c991

+79 -90
+22 -22
drivers/staging/dt3155/dt3155_drv.c
··· 55 55 56 56 */ 57 57 58 - extern void printques(int); 59 - 60 58 #include <linux/module.h> 61 59 #include <linux/interrupt.h> 62 60 #include <linux/pci.h> ··· 327 329 local_irq_disable(); 328 330 329 331 #ifdef DEBUG_QUES_B 330 - printques(minor); 332 + printques(fb); 331 333 #endif 332 334 if (fb->nbuffers > 2) 333 335 { 334 - if (!are_empty_buffers(minor)) 336 + if (!are_empty_buffers(fb)) 335 337 { 336 338 /* The number of active + locked buffers is 337 339 * at most 2, and since there are none empty, there 338 340 * must be at least nbuffers-2 ready buffers. 339 341 * This is where we 'drop frames', oldest first. */ 340 - push_empty(pop_ready(minor), minor); 342 + push_empty(fb, pop_ready(fb)); 341 343 } 342 344 343 345 /* The ready_que can't be full, since we know 344 346 * there is one active buffer right now, so it's safe 345 347 * to push the active buf on the ready_que. */ 346 - push_ready(minor, fb->active_buf); 348 + push_ready(fb, fb->active_buf); 347 349 /* There's at least 1 empty -- make it active */ 348 - fb->active_buf = pop_empty(minor); 350 + fb->active_buf = pop_empty(fb); 349 351 fb->frame_info[fb->active_buf].tag = ++unique_tag; 350 352 } 351 353 else /* nbuffers == 2, special case */ ··· 355 357 */ 356 358 if (fb->locked_buf < 0) 357 359 { 358 - push_ready(minor, fb->active_buf); 359 - if (are_empty_buffers(minor)) 360 + push_ready(fb, fb->active_buf); 361 + if (are_empty_buffers(fb)) 360 362 { 361 - fb->active_buf = pop_empty(minor); 363 + fb->active_buf = pop_empty(fb); 362 364 } 363 365 else 364 366 { /* no empty or locked buffers, so use a readybuf */ 365 - fb->active_buf = pop_ready(minor); 367 + fb->active_buf = pop_ready(fb); 366 368 } 367 369 } 368 370 } 369 371 370 372 #ifdef DEBUG_QUES_B 371 - printques(minor); 373 + printques(fb); 372 374 #endif 373 375 374 376 fb->even_happened = 0; ··· 557 559 { 558 560 if (dts->state != DT3155_STATE_IDLE) 559 561 return -EBUSY; 560 - return dt3155_flush(minor); 562 + return dt3155_flush(fb); 561 563 } 562 564 case DT3155_STOP: 563 565 { ··· 667 669 { 668 670 int minor = MINOR(inode->i_rdev); /* what device are we opening? */ 669 671 struct dt3155_status *dts = &dt3155_status[minor]; 672 + struct dt3155_fbuffer *fb = &dts->fbuffer; 670 673 671 674 if (dt3155_dev_open[minor]) { 672 675 printk ("DT3155: Already opened by another process.\n"); ··· 691 692 692 693 dt3155_dev_open[minor] = 1 ; 693 694 694 - dt3155_flush(minor); 695 + dt3155_flush(fb); 695 696 696 697 /* Disable ALL interrupts */ 697 698 writel(0, dt3155_lbase[minor] + INT_CSR); ··· 766 767 /* non-blocking reads should return if no data */ 767 768 if (filep->f_flags & O_NDELAY) 768 769 { 769 - if ((frame_index = dt3155_get_ready_buffer(minor)) < 0) { 770 - /*printk("dt3155: no buffers available (?)\n");*/ 771 - /* printques(minor); */ 770 + if ((frame_index = dt3155_get_ready_buffer(fb)) < 0) { 771 + /* printk("dt3155: no buffers available (?)\n"); */ 772 + /* printques(fb); */ 772 773 return -EAGAIN; 773 774 } 774 775 } ··· 779 780 * Note that wait_event_interruptible() does not actually 780 781 * sleep/wait if it's condition evaluates to true upon entry. 781 782 */ 782 - wait_event_interruptible(dt3155_read_wait_queue[minor], 783 - (frame_index = dt3155_get_ready_buffer(minor)) 784 - >= 0); 783 + frame_index = dt3155_get_ready_buffer(fb); 784 + wait_event_interruptible(dt3155_read_wait_queue[minor], frame_index >= 0); 785 785 786 786 if (frame_index < 0) 787 787 { 788 788 printk ("DT3155: read: interrupted\n"); 789 789 quick_stop (minor); 790 - printques(minor); 790 + printques(fb); 791 791 return -EINTR; 792 792 } 793 793 } ··· 811 813 static unsigned int dt3155_poll (struct file * filp, poll_table *wait) 812 814 { 813 815 int minor = MINOR(filp->f_dentry->d_inode->i_rdev); 816 + struct dt3155_status *dts = &dt3155_status[minor]; 817 + struct dt3155_fbuffer *fb = &dts->fbuffer; 814 818 815 - if (!is_ready_buf_empty(minor)) 819 + if (!is_ready_buf_empty(fb)) 816 820 return POLLIN | POLLRDNORM; 817 821 818 822 poll_wait (filp, &dt3155_read_wait_queue[minor], wait);
+28 -47
drivers/staging/dt3155/dt3155_isr.c
··· 68 68 /*************************** 69 69 * are_empty_buffers 70 70 ***************************/ 71 - bool are_empty_buffers(int minor) 71 + bool are_empty_buffers(struct dt3155_fbuffer *fb) 72 72 { 73 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 74 - 75 73 return fb->empty_len; 76 74 } 77 75 ··· 82 84 * given by fb->empty_buffers[0]. 83 85 * empty_buffers should never fill up, though this is not checked. 84 86 **************************/ 85 - void push_empty(int index, int minor) 87 + void push_empty(struct dt3155_fbuffer *fb, int index) 86 88 { 87 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 88 - 89 89 fb->empty_buffers[fb->empty_len] = index; 90 90 fb->empty_len++; 91 91 } ··· 91 95 /************************** 92 96 * pop_empty 93 97 **************************/ 94 - int pop_empty(int minor) 98 + int pop_empty(struct dt3155_fbuffer *fb) 95 99 { 96 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 97 - 98 100 fb->empty_len--; 99 101 return fb->empty_buffers[fb->empty_len]; 100 102 } ··· 100 106 /************************* 101 107 * is_ready_buf_empty 102 108 *************************/ 103 - bool is_ready_buf_empty(int minor) 109 + bool is_ready_buf_empty(struct dt3155_fbuffer *fb) 104 110 { 105 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 106 - 107 111 return fb->ready_len == 0; 108 112 } 109 113 ··· 112 120 * buffers, since it corresponds to nbuffers ready buffers!! 113 121 * 7/31/02: total rewrite. --NJC 114 122 *************************/ 115 - bool is_ready_buf_full(int minor) 123 + bool is_ready_buf_full(struct dt3155_fbuffer *fb) 116 124 { 117 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 118 - 119 125 return fb->ready_len == fb->nbuffers; 120 126 } 121 127 122 128 /***************************************************** 123 129 * push_ready 124 130 *****************************************************/ 125 - void push_ready(int minor, int index) 131 + void push_ready(struct dt3155_fbuffer *fb, int index) 126 132 { 127 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 128 133 int head = fb->ready_head; 129 134 130 135 fb->ready_que[head] = index; ··· 134 145 * 135 146 * Simply comptutes the tail given the head and the length. 136 147 *****************************************************/ 137 - static int get_tail(int minor) 148 + static int get_tail(struct dt3155_fbuffer *fb) 138 149 { 139 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 140 - 141 150 return (fb->ready_head - fb->ready_len + fb->nbuffers) % fb->nbuffers; 142 151 } 143 152 ··· 145 158 * This assumes that there is a ready buffer ready... should 146 159 * be checked (e.g. with is_ready_buf_empty() prior to call. 147 160 *****************************************************/ 148 - int pop_ready(int minor) 161 + int pop_ready(struct dt3155_fbuffer *fb) 149 162 { 150 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 151 - int tail = get_tail(minor); 163 + int tail = get_tail(fb); 152 164 153 165 fb->ready_len--; 154 166 return fb->ready_que[tail]; ··· 156 170 /***************************************************** 157 171 * printques 158 172 *****************************************************/ 159 - void printques(int minor) 173 + void printques(struct dt3155_fbuffer *fb) 160 174 { 161 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 162 175 int i; 163 176 164 177 printk(KERN_INFO "\n R:"); 165 - for (i = get_tail(minor); i != fb->ready_head; i++, i %= fb->nbuffers) 178 + for (i = get_tail(fb); i != fb->ready_head; i++, i %= fb->nbuffers) 166 179 printk(" %d ", fb->ready_que[i]); 167 180 168 181 printk(KERN_INFO "\n E:"); ··· 334 349 } 335 350 336 351 fb->frame_info[index].addr = rambuff_acm; 337 - push_empty(index, minor); 352 + push_empty(fb, index); 338 353 /* printk(" - Buffer : %lx\n", fb->frame_info[index].addr); */ 339 354 fb->nbuffers += 1; 340 355 rambuff_acm += bufsize; 341 356 } 342 357 343 358 /* Make sure there is an active buffer there. */ 344 - fb->active_buf = pop_empty(minor); 359 + fb->active_buf = pop_empty(fb); 345 360 fb->even_happened = 0; 346 361 fb->even_stopped = 0; 347 362 ··· 367 382 * The internal function for releasing a locked buffer. 368 383 * It assumes interrupts are turned off. 369 384 *****************************************************/ 370 - static void internal_release_locked_buffer(int minor) 385 + static void internal_release_locked_buffer(struct dt3155_fbuffer *fb) 371 386 { 372 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 373 - 374 387 if (fb->locked_buf >= 0) { 375 - push_empty(fb->locked_buf, minor); 388 + push_empty(fb, fb->locked_buf); 376 389 fb->locked_buf = -1; 377 390 } 378 391 } ··· 380 397 * 381 398 * The user function of the above. 382 399 *****************************************************/ 383 - void dt3155_release_locked_buffer(int minor) 400 + void dt3155_release_locked_buffer(struct dt3155_fbuffer *fb) 384 401 { 385 402 unsigned long int flags; 386 403 387 404 local_save_flags(flags); 388 405 local_irq_disable(); 389 - internal_release_locked_buffer(minor); 406 + internal_release_locked_buffer(fb); 390 407 local_irq_restore(flags); 391 408 } 392 409 393 410 /***************************************************** 394 411 * dt3155_flush 395 412 *****************************************************/ 396 - int dt3155_flush(int minor) 413 + int dt3155_flush(struct dt3155_fbuffer *fb) 397 414 { 398 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 399 415 unsigned long int flags; 400 416 int index; 401 417 402 418 local_save_flags(flags); 403 419 local_irq_disable(); 404 420 405 - internal_release_locked_buffer(minor); 421 + internal_release_locked_buffer(fb); 406 422 fb->empty_len = 0; 407 423 408 424 for (index = 0; index < fb->nbuffers; index++) 409 - push_empty(index, minor); 425 + push_empty(fb, index); 410 426 411 427 /* Make sure there is an active buffer there. */ 412 - fb->active_buf = pop_empty(minor); 428 + fb->active_buf = pop_empty(fb); 413 429 414 430 fb->even_happened = 0; 415 431 fb->even_stopped = 0; ··· 430 448 * If the user has a buffer locked it will unlock 431 449 * that buffer before returning the new one. 432 450 *****************************************************/ 433 - int dt3155_get_ready_buffer(int minor) 451 + int dt3155_get_ready_buffer(struct dt3155_fbuffer *fb) 434 452 { 435 - struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer; 436 453 unsigned long int flags; 437 454 int frame_index; 438 455 ··· 439 458 local_irq_disable(); 440 459 441 460 #ifdef DEBUG_QUES_A 442 - printques(minor); 461 + printques(fb); 443 462 #endif 444 463 445 - internal_release_locked_buffer(minor); 464 + internal_release_locked_buffer(fb); 446 465 447 - if (is_ready_buf_empty(minor)) { 466 + if (is_ready_buf_empty(fb)) { 448 467 frame_index = -1; 449 468 } else { 450 - frame_index = pop_ready(minor); 469 + frame_index = pop_ready(fb); 451 470 fb->locked_buf = frame_index; 452 - } 471 + } 453 472 454 473 #ifdef DEBUG_QUES_B 455 - printques(minor); 474 + printques(fb); 456 475 #endif 457 476 458 477 local_irq_restore(flags);
+29 -21
drivers/staging/dt3155/dt3155_isr.h
··· 36 36 #ifndef DT3155_ISR_H 37 37 #define DT3155_ISR_H 38 38 39 - /* User functions for buffering */ 40 - /* Initialize the buffering system. This should */ 41 - /* be called prior to enabling interrupts */ 39 + /********************************** 40 + * User functions for buffering 41 + **********************************/ 42 42 43 + /* 44 + * Initialize the buffering system. 45 + * This should be called prior to enabling interrupts 46 + */ 43 47 u32 dt3155_setup_buffers(u32 *allocatorAddr); 44 48 45 - /* Get the next frame of data if it is ready. Returns */ 46 - /* zero if no data is ready. If there is data but */ 47 - /* the user has a locked buffer, it will unlock that */ 48 - /* buffer and return it to the free list. */ 49 + /* 50 + * Get the next frame of data if it is ready. 51 + * Returns zero if no data is ready. If there is data but the user has a 52 + * locked buffer, it will unlock that buffer and return it to the free list. 53 + */ 54 + int dt3155_get_ready_buffer(struct dt3155_fbuffer *fb); 49 55 50 - int dt3155_get_ready_buffer(int minor); 56 + /* 57 + * Return a locked buffer to the free list. 58 + */ 59 + void dt3155_release_locked_buffer(struct dt3155_fbuffer *fb); 51 60 52 - /* Return a locked buffer to the free list */ 53 - 54 - void dt3155_release_locked_buffer(int minor); 55 - 56 - /* Flush the buffer system */ 57 - int dt3155_flush(int minor); 61 + /* 62 + * Flush the buffer system. 63 + */ 64 + int dt3155_flush(struct dt3155_fbuffer *fb); 58 65 59 66 /********************************** 60 67 * Simple array based que struct 61 68 **********************************/ 62 69 63 - bool are_empty_buffers(int minor); 64 - void push_empty(int index, int minor); 70 + bool are_empty_buffers(struct dt3155_fbuffer *fb); 71 + void push_empty(struct dt3155_fbuffer *fb, int index); 65 72 66 - int pop_empty(int minor); 73 + int pop_empty(struct dt3155_fbuffer *fb); 67 74 68 - bool is_ready_buf_empty(int minor); 69 - bool is_ready_buf_full(int minor); 75 + bool is_ready_buf_empty(struct dt3155_fbuffer *fb); 76 + bool is_ready_buf_full(struct dt3155_fbuffer *fb); 70 77 71 - void push_ready(int minor, int index); 72 - int pop_ready(int minor); 78 + void push_ready(struct dt3155_fbuffer *fb, int index); 79 + int pop_ready(struct dt3155_fbuffer *fb); 73 80 81 + void printques(struct dt3155_fbuffer *fb); 74 82 75 83 #endif