aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlof Johansson <olof@lixom.net>2008-03-05 13:25:45 -0500
committerOlof Johansson <olof@lixom.net>2008-03-05 13:26:35 -0500
commitf37203b5ccaf6d58cb5ca6b1840e40f3b587109c (patch)
tree9f598d9e951c9927220a7fbc27d45d58b2d4d2c1
parentafea3278f73c14271ee60ca7593ad74b7a946486 (diff)
[POWERPC] pasemi: Add flag management functions to dma_lib
Add functions to manage the channel syncronization flags to dma_lib Signed-off-by: Olof Johansson <olof@lixom.net> Acked-by: Jeff Garzik <jgarzik@pobox.com>
-rw-r--r--arch/powerpc/platforms/pasemi/dma_lib.c74
-rw-r--r--include/asm-powerpc/pasemi_dma.h6
2 files changed, 80 insertions, 0 deletions
diff --git a/arch/powerpc/platforms/pasemi/dma_lib.c b/arch/powerpc/platforms/pasemi/dma_lib.c
index 48cb7c99962d..07e4e25ef625 100644
--- a/arch/powerpc/platforms/pasemi/dma_lib.c
+++ b/arch/powerpc/platforms/pasemi/dma_lib.c
@@ -27,6 +27,7 @@
27 27
28#define MAX_TXCH 64 28#define MAX_TXCH 64
29#define MAX_RXCH 64 29#define MAX_RXCH 64
30#define MAX_FLAGS 64
30 31
31static struct pasdma_status *dma_status; 32static struct pasdma_status *dma_status;
32 33
@@ -44,6 +45,7 @@ static struct pci_dev *dma_pdev;
44 45
45static DECLARE_BITMAP(txch_free, MAX_TXCH); 46static DECLARE_BITMAP(txch_free, MAX_TXCH);
46static DECLARE_BITMAP(rxch_free, MAX_RXCH); 47static DECLARE_BITMAP(rxch_free, MAX_RXCH);
48static DECLARE_BITMAP(flags_free, MAX_FLAGS);
47 49
48/* pasemi_read_iob_reg - read IOB register 50/* pasemi_read_iob_reg - read IOB register
49 * @reg: Register to read (offset into PCI CFG space) 51 * @reg: Register to read (offset into PCI CFG space)
@@ -374,6 +376,71 @@ void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size,
374} 376}
375EXPORT_SYMBOL(pasemi_dma_free_buf); 377EXPORT_SYMBOL(pasemi_dma_free_buf);
376 378
379/* pasemi_dma_alloc_flag - Allocate a flag (event) for channel syncronization
380 *
381 * Allocates a flag for use with channel syncronization (event descriptors).
382 * Returns allocated flag (0-63), < 0 on error.
383 */
384int pasemi_dma_alloc_flag(void)
385{
386 int bit;
387
388retry:
389 bit = find_next_bit(flags_free, MAX_FLAGS, 0);
390 if (bit >= MAX_FLAGS)
391 return -ENOSPC;
392 if (!test_and_clear_bit(bit, flags_free))
393 goto retry;
394
395 return bit;
396}
397EXPORT_SYMBOL(pasemi_dma_alloc_flag);
398
399
400/* pasemi_dma_free_flag - Deallocates a flag (event)
401 * @flag: Flag number to deallocate
402 *
403 * Frees up a flag so it can be reused for other purposes.
404 */
405void pasemi_dma_free_flag(int flag)
406{
407 BUG_ON(test_bit(flag, flags_free));
408 BUG_ON(flag >= MAX_FLAGS);
409 set_bit(flag, flags_free);
410}
411EXPORT_SYMBOL(pasemi_dma_free_flag);
412
413
414/* pasemi_dma_set_flag - Sets a flag (event) to 1
415 * @flag: Flag number to set active
416 *
417 * Sets the flag provided to 1.
418 */
419void pasemi_dma_set_flag(int flag)
420{
421 BUG_ON(flag >= MAX_FLAGS);
422 if (flag < 32)
423 pasemi_write_dma_reg(PAS_DMA_TXF_SFLG0, 1 << flag);
424 else
425 pasemi_write_dma_reg(PAS_DMA_TXF_SFLG1, 1 << flag);
426}
427EXPORT_SYMBOL(pasemi_dma_set_flag);
428
429/* pasemi_dma_clear_flag - Sets a flag (event) to 0
430 * @flag: Flag number to set inactive
431 *
432 * Sets the flag provided to 0.
433 */
434void pasemi_dma_clear_flag(int flag)
435{
436 BUG_ON(flag >= MAX_FLAGS);
437 if (flag < 32)
438 pasemi_write_dma_reg(PAS_DMA_TXF_CFLG0, 1 << flag);
439 else
440 pasemi_write_dma_reg(PAS_DMA_TXF_CFLG1, 1 << flag);
441}
442EXPORT_SYMBOL(pasemi_dma_clear_flag);
443
377static void *map_onedev(struct pci_dev *p, int index) 444static void *map_onedev(struct pci_dev *p, int index)
378{ 445{
379 struct device_node *dn; 446 struct device_node *dn;
@@ -508,6 +575,13 @@ int pasemi_dma_init(void)
508 /* enable rx section */ 575 /* enable rx section */
509 pasemi_write_dma_reg(PAS_DMA_COM_RXCMD, PAS_DMA_COM_RXCMD_EN); 576 pasemi_write_dma_reg(PAS_DMA_COM_RXCMD, PAS_DMA_COM_RXCMD_EN);
510 577
578 for (i = 0; i < MAX_FLAGS; i++)
579 __set_bit(i, flags_free);
580
581 /* clear all status flags */
582 pasemi_write_dma_reg(PAS_DMA_TXF_CFLG0, 0xffffffff);
583 pasemi_write_dma_reg(PAS_DMA_TXF_CFLG1, 0xffffffff);
584
511 printk(KERN_INFO "PA Semi PWRficient DMA library initialized " 585 printk(KERN_INFO "PA Semi PWRficient DMA library initialized "
512 "(%d tx, %d rx channels)\n", num_txch, num_rxch); 586 "(%d tx, %d rx channels)\n", num_txch, num_rxch);
513 587
diff --git a/include/asm-powerpc/pasemi_dma.h b/include/asm-powerpc/pasemi_dma.h
index 35577b6dec41..ffd413d7dfb0 100644
--- a/include/asm-powerpc/pasemi_dma.h
+++ b/include/asm-powerpc/pasemi_dma.h
@@ -466,6 +466,12 @@ extern void *pasemi_dma_alloc_buf(struct pasemi_dmachan *chan, int size,
466extern void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size, 466extern void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size,
467 dma_addr_t *handle); 467 dma_addr_t *handle);
468 468
469/* Routines to allocate flags (events) for channel syncronization */
470extern int pasemi_dma_alloc_flag(void);
471extern void pasemi_dma_free_flag(int flag);
472extern void pasemi_dma_set_flag(int flag);
473extern void pasemi_dma_clear_flag(int flag);
474
469/* Initialize the library, must be called before any other functions */ 475/* Initialize the library, must be called before any other functions */
470extern int pasemi_dma_init(void); 476extern int pasemi_dma_init(void);
471 477