All of lore.kernel.org
 help / color / mirror / Atom feed
From: padmanabha <padmanabha@tesbv.com>
To: linuxppc-embedded@ozlabs.org,  reynekejunk@hotmail.com
Subject: PPC4xx memory to memory DMA
Date: Tue, 08 Jan 2008 15:23:16 +0530	[thread overview]
Message-ID: <4783480C.1070600@tesbv.com> (raw)

Hi,

I  am using 2.6.23  kernel for ppc 440spe based board. When i tried 
memory to memory DMA  ( please find  the code given below )
 DMA is not happening.

I am trying the same for last few days.... without any success.  Can any 
one guide me.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/delay.h>

#include<asm/ppc4xx_dma.h>
#include<asm/io.h>
#include<linux/slab.h>

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("PPC4xx Mem to Mem DMA  demo");
MODULE_AUTHOR("padmanabha@tesbv.com");

extern void flush_dcache_all(void);

#define DMA_CHANNEL_NUM                         0
#define SIZE                                                    4096

ppc_dma_ch_t  ppc_dma_channel;
ppc_dma_ch_t p_init;

void * vir_dst_addr;
void * vir_src_addr;

unsigned long int  phy_src;
unsigned long int  phy_dst;

int ret, offset;

void dma_trns(void)
{

      memset( (char *)&p_init, 0, sizeof(p_init));

      p_init.polarity = 0;
      p_init.pwidth   = PW_8;

      ret = ppc4xx_init_dma_channel( DMA_CHANNEL_NUM, &p_init);

      if (ret  ==   DMA_STATUS_GOOD)
      {
          printk("%s: init_dma_channel return %d, dest is 
%p\n",__FUNCTION__, ret, vir_dst_addr);
      }

      else if(ret  ==   DMA_STATUS_BAD_CHANNEL)
      {

        printk("TS2: bad channel \n");

      }

      flush_dcache_all();

      ppc4xx_clr_dma_status( DMA_CHANNEL_NUM);

      ppc4xx_set_dma_mode(DMA_CHANNEL_NUM,DMA_MODE_MM);
      ppc4xx_set_src_addr( DMA_CHANNEL_NUM, (phys_addr_t) phy_src);
      ppc4xx_set_dst_addr(DMA_CHANNEL_NUM,  (phys_addr_t) phy_dst);
      ppc4xx_set_dma_count(DMA_CHANNEL_NUM,(SIZE * 2 ));

      ppc4xx_set_channel_priority(DMA_CHANNEL_NUM,PRIORITY_HIGH);

      ppc4xx_enable_dma(DMA_CHANNEL_NUM);


      // wait till completion of DMA


       while( 1)
       {
            mdelay(100);

            ret = 1;
            ret = ppc4xx_get_dma_residue( DMA_CHANNEL_NUM);

            if( ret == 0)
            {
                printk(" no dma operation is pending\n");
                break;
            }

       }

     ppc4xx_disable_dma( DMA_CHANNEL_NUM);

    return  ;
}

static int dma_test_init(void)
{

    vir_src_addr = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA, 1);

    if( vir_src_addr == NULL )
    {
        printk( " Memory not allocated\n");
        return 1;
    }
    printk("%s: virtual address for src buffer is 0x%p \n",__FUNCTION__, 
(unsigned int *)vir_src_addr);
    memset( (unsigned long *)vir_src_addr, 0x55, sizeof(unsigned long) * 
(SIZE *2));

#if SRC_DISPLAY

    ret = 0;

    while(ret < 100)
    {

        printk( "%s: value at virtual addr 0x%p is 0x%X \n", 
__FUNCTION__,( (unsigned int *)vir_src_addr + ret ),\

        *( (unsigned int *)vir_src_addr + ret));

        ret++;

    }

#endif

    vir_dst_addr = (void *) __get_free_pages(GFP_KERNEL | GFP_DMA,1);

    if( vir_dst_addr == NULL )
    {
        printk( " Memory not allocated\n");
        free_pages( (unsigned long)vir_src_addr, 1);
        return 1;
    }
    printk("%s: virtual address for dst buffer is 0x%p 
\n",__FUNCTION__,(unsigned int *)vir_dst_addr);
    memset( (unsigned long *)vir_dst_addr, 0, sizeof(unsigned long) * 
(SIZE *2));

#if DST_DISPLAY

    ret = 0;
    while(ret < 100)
    {

        printk( "%s: value at virtual addr 0x%p is 0x%X \n", 
__FUNCTION__,( (unsigned int *)vir_dst_addr + ret ),\
        *( (unsigned int *)vir_dst_addr + ret));

        ret++;

    }
#endif

//      phy_src = virt_to_bus(vir_src_addr);
//      phy_dst = virt_to_bus(vir_dst_addr);

      phy_src = iopa( (unsigned long ) vir_src_addr);
      phy_dst =  iopa(  (unsigned long )vir_dst_addr);

    dma_trns();

      ret = 1;
      ret = ppc4xx_get_dma_residue( DMA_CHANNEL_NUM);
      if( ret == 0)
      {
          printk(" no dma operation is pending\n");

      }

    return 0;
}


void dma_test_exit(void)
{
      ret = ppc4xx_get_channel_config( DMA_CHANNEL_NUM, &ppc_dma_channel);

      if( ret != DMA_STATUS_GOOD )
      {
         printk("TS2: DMA STATUS  is not good \n");
      }
      else
      {
         printk("TS2:  DMA STATUS  good \n");

      }

      ret = 0;

      while(ret < 100)
      {

         printk( "%s: value at virtual addr 0x%p after dma is 0x%X \n", 
__FUNCTION__,( (unsigned int *)vir_dst_addr + ret ), \
         *( (unsigned int *)vir_dst_addr + ret)) ;

         ret++;
      }

     mdelay(100);

     free_pages( (unsigned long)vir_src_addr, 1);
     free_pages( (unsigned long)vir_dst_addr, 1);

}

module_init(dma_test_init);
module_exit(dma_test_exit);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Thanks and Regards,
Padmanabha.s

                 reply	other threads:[~2008-01-08  9:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4783480C.1070600@tesbv.com \
    --to=padmanabha@tesbv.com \
    --cc=linuxppc-embedded@ozlabs.org \
    --cc=reynekejunk@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.