青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天下

記錄修行的印記

s3c2410的dma操作的一般步驟

s3c2410的dma操作的一般步驟

一般的,在s3c2440中,要想進行dma傳輸,需要一下七個步驟:

一:
/* s3c2410_request_dma
 *
 * get control of an dma channel
*/
int s3c2410_dma_request(unsigned int channel,
                        
struct s3c2410_dma_client *client,
                        
void *dev)
    
s3c2410_dma_client的定義為:
struct s3c2410_dma_client {
    
char    *name;
};

二:
/* DMA configuration for each channel
 *
 * DISRCC -> source of the DMA (AHB(系統總線),APB(外圍總線))
 * DISRC  -> source address of the DMA
 * DIDSTC -> destination of the DMA (AHB,APD)
 * DIDST  -> destination address of the DMA
*/
/* s3c2410_dma_config
 *
 * xfersize:     size of unit in bytes (1,2,4)
 * dcon:         base value of the DCONx register
*/

int s3c2410_dma_config(dmach_t channel,
                       
int xferunit,
                       
int dcon)
根據xferunit以及dcon設置通道的控制寄存器DCONx
xferunit為每次傳輸的數據大小:
0:byte 1:half word 2:word

每個 DMA 通道都有 
9 個控制寄存器(4 個通道 DMA 控制器共計 36 個寄存器)。
6 個寄存器用來控制 DMA 傳輸,其他三個監視 DMA 控制器的狀態。這些寄存器的詳細情況如下:
1)DMA 初始源寄存器(DISRC)
2)DMA初始源控制寄存器(DISRCC)
3)DMA初始目的寄存器(DIDST)
4)DMA初始目的控制寄存器(DIDSTC)
5)DMA控制寄存器(DCON)
6)DMA狀態寄存器(DSTAT)
7)DMA當前源寄存器(DCSRC)
8)DMA當前目的寄存器(DCDST)
9)DMA屏蔽觸發寄存器(DMASKTRIG)

三:
int s3c2410_dma_set_buffdone_fn(dmach_t channel, s3c2410_dma_cbfn_t rtn)
{
    
struct s3c2410_dma_chan *chan = lookup_dma_channel(channel);
    
if (chan == NULL)
        
return -EINVAL;
    pr_debug(
"%s: chan=%p, callback rtn=%p\n", __func__, chan, rtn);
    chan
->callback_fn = rtn;
    
return 0;
}    
設置相應的dma通道完成一次dma傳輸后的回調函數,也即是s3c2410_dma_enqueue完成后會調用的函數

回調函數應具有一下格式:
/* s3c2410_dma_cbfn_t
 *
 * buffer callback routine type
*/
typedef 
void (*s3c2410_dma_cbfn_t)(struct s3c2410_dma_chan *,
                                   
void *buf, int size,
                                   
enum s3c2410_dma_buffresult result);

buf可以傳遞一些有用的數據,在uda1314的驅動中,傳遞的是audio_buf_t結構體


四:
int s3c2410_dma_setflags(dmach_t channel, unsigned int flags)
{
    
struct s3c2410_dma_chan *chan = lookup_dma_channel(channel);
    
if (chan == NULL)
        
return -EINVAL;
    pr_debug(
"%s: chan=%p, flags=%08x\n", __func__, chan, flags);
    chan
->flags = flags;
    
return 0;
}

五:
/* s3c2410_dma_devconfig
 *
 * configure the dma source/destination hardware type and address
 *
 * source:    S3C2410_DMASRC_HW: source is hardware
 *            S3C2410_DMASRC_MEM: source is memory
 *
 * hwcfg:     the value for xxxSTCn register,
 *            bit 0: 0=increment pointer, 1=leave pointer
 *            bit 1: 0=source is AHB, 1=source is APB
 *
 * devaddr:   physical address of the source
*/

int s3c2410_dma_devconfig(int channel,
                          
enum s3c2410_dmasrc source,
                          
int hwcfg,
                          unsigned 
long devaddr)
    
六:
/*
 * Allocate memory for a coherent(連續的) mapping.
 
*/
void *dma_alloc_coherent(struct device *dev,size_t size,dma_addr_t *dma_handle,int flag)
如:        
void *pLogicAddr = NULL;/*邏輯地址*/
dma_addr_t pBusAddr 
= NULL;/*總線地址(實際物理地址)*/
pLogicAddr 
= dma_alloc_coherent(NULL, 480*640&pBusAddr, GFP_KERNEL | GFP_DMA);
        
該函數實際獲得兩個地址,
1、函數的返回值是一個void *,代表緩沖區的內核虛擬地址
2、相關的總線地址,保存在dma_handle中
    
dma關心的是總線地址。
物理地址與總線地址
1) 物理地址是與CPU相關的。在CPU的地址信號線上產生的就是物理地址。在程序指令中的虛擬地址經過段映射和頁面映射后,就生成了物理地址,這個物理地址被放到CPU的地址線上。
2) 總線地址,顧名思義,是與總線相關的,就是總線的地址線或在地址周期上產生的信號。外設使用的是總線地址。
3) 物理地址與總線地址之間的關系由系統的設計決定的。在x86平臺上,物理地址與PCI總線地址是相同的。在其他平臺上,也許會有某種轉換,通常是線性的轉換。    


七:
/* s3c2410_dma_enqueue
 *
 * queue an given buffer for dma transfer.
 *
 * id         the device driver's id information for this buffer
 * data       the physical address of the buffer data
 * size       the size of the buffer in bytes
 *
 * If the channel is not running, then the flag S3C2410_DMAF_AUTOSTART
 * is checked, and if set, the channel is started. If this flag isn't set,
 * then an error will be returned.
 *
 * It is possible to queue more than one DMA buffer onto a channel at
 * once, and the code will deal with the re-loading of the next buffer
 * when necessary.
*/

int s3c2410_dma_enqueue(unsigned int channel, void *id,dma_addr_t data, int size)
將dma_alloc_coherent中得到的dmaphys傳遞給s3c2410_dma_enqueue. 
s3c2410_dma_enqueue提交一次dma請求,當dma通道可用的時候通過s3c2410_dma_loadbuffer開始一次傳輸,傳輸完成后會產生irq中斷。其dma的中斷服務函數中會繼續啟動dma請求隊列中的請求,傳輸剩下的數據。

/* s3c2410_dma_buffdone
 *
 * small wrapper to check if callback routine needs to be called, and
 * if so, call it
*/
static inline void s3c2410_dma_buffdone(struct s3c2410_dma_chan *chan, struct s3c2410_dma_buf *buf,
                                         
enum s3c2410_dma_buffresult result)
{
    
if (chan->callback_fn != NULL) {
        (chan
->callback_fn)(chan, buf->id, buf->size, result);
    }
}    
其中 s3c2410_dma_irq 會調用 s3c2410_dma_buffdone;
static irqreturn_t s3c2410_dma_irq(int irq, void *devpw)
    
/* s3c2410_request_dma
 *
 * get control of an dma channel
*/
int s3c2410_dma_request(unsigned int channel,
                        
struct s3c2410_dma_client *client,
                        
void *dev)
{
    
struct s3c2410_dma_chan *chan;
    unsigned 
long flags;
    
int err;

    pr_debug(
"dma%d: s3c2410_request_dma: client=%s, dev=%p\n",
         channel, client
->name, dev);

    local_irq_save(flags);
    chan 
= s3c2410_dma_map_channel(channel);
    
if (chan == NULL) {
        local_irq_restore(flags);
        
return -EBUSY;
    }
    dbg_showchan(chan);
    chan
->client = client;
    chan
->in_use = 1;
    
if (!chan->irq_claimed) {
        pr_debug(
"dma%d: %s : requesting irq %d\n",
             channel, __func__, chan
->irq);

        chan
->irq_claimed = 1;
        local_irq_restore(flags);
        err 
= request_irq(chan->irq, s3c2410_dma_irq, IRQF_DISABLED,
                  client
->name, (void *)chan);
        local_irq_save(flags);
        
if (err) {
            chan
->in_use = 0;
            chan
->irq_claimed = 0;
            local_irq_restore(flags);
            printk(KERN_ERR 
"%s: cannot get IRQ %d for DMA %d\n",
                   client
->name, chan->irq, chan->number);
            
return err;
        }
        chan
->irq_enabled = 1;
    }
    local_irq_restore(flags);
    
/* need to setup */
    pr_debug(
"%s: channel initialised, %p\n", __func__, chan);
    
return chan->number | DMACH_LOW_LEVEL;
}    


/**
 *    request_irq - allocate an interrupt line
 *    @irq: Interrupt line to allocate
 *    @handler: Function to be called when the IRQ occurs
 *    @irqflags: Interrupt type flags
 *    @devname: An ascii name for the claiming device
 *    @dev_id: A cookie passed back to the handler function
 *
 *    This call allocates interrupt resources and enables the
 *    interrupt line and IRQ handling. From the point this
 *    call is made your handler function may be invoked. Since
 *    your handler function must clear any interrupt the board
 *    raises, you must take care both to initialise your hardware
 *    and to set up the interrupt handler in the right order.
 *
 *    Dev_id must be globally unique. Normally the address of the
 *    device data structure is used as the cookie. Since the handler
 *    receives this value it makes sense to use it.
 *
 *    If your interrupt is shared you must pass a non NULL dev_id
 *    as this is required when freeing the interrupt.
 *
 *    Flags:
 *
 *    IRQF_SHARED        Interrupt is shared
 *    IRQF_DISABLED    Disable local interrupts while processing
 *    IRQF_SAMPLE_RANDOM    The interrupt can be used for entropy
 *
 
*/
int request_irq(unsigned int irq, irq_handler_t handler,
        unsigned 
long irqflags, const char *devname, void *dev_id)
{
    
struct irqaction *action;
    
int retval;
    action 
= kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
    
if (!action)
        
return -ENOMEM;
    action
->handler = handler;
    action
->flags = irqflags;
    cpus_clear(action
->mask);
    action
->name = devname;
    action
->next = NULL;
    action
->dev_id = dev_id;

    select_smp_affinity(irq);

    retval 
= setup_irq(irq, action);
    
if (retval)
        kfree(action);

    
return retval;
}    


/* s3c2410_dma_loadbuffer
 *
 * load a buffer, and update the channel state
*/
static inline int s3c2410_dma_loadbuffer(struct s3c2410_dma_chan *chan,
                                            
struct s3c2410_dma_buf *buf)
{
    unsigned 
long reload;
    pr_debug(
"s3c2410_chan_loadbuffer: loading buff %p (0x%08lx,0x%06x)\n",
         buf, (unsigned 
long)buf->data, buf->size);
    
if (buf == NULL) {
        dmawarn(
"buffer is NULL\n");
        
return -EINVAL;
    }
    
/* check the state of the channel before we do anything */
    
if (chan->load_state == S3C2410_DMALOAD_1LOADED) {
        dmawarn(
"load_state is S3C2410_DMALOAD_1LOADED\n");
    }
    
if (chan->load_state == S3C2410_DMALOAD_1LOADED_1RUNNING) {
        dmawarn(
"state is S3C2410_DMALOAD_1LOADED_1RUNNING\n");
    }
    
/* it would seem sensible if we are the last buffer to not bother
     * with the auto-reload bit, so that the DMA engine will not try
     * and load another transfer after this one has finished
     
*/
    
if (chan->load_state == S3C2410_DMALOAD_NONE) {
        pr_debug(
"load_state is none, checking for noreload (next=%p)\n",
             buf
->next);
        reload 
= (buf->next == NULL) ? S3C2410_DCON_NORELOAD : 0;
    } 
else {
        
//pr_debug("load_state is %d => autoreload\n", chan->load_state);
        reload = S3C2410_DCON_AUTORELOAD;
    }

    
if ((buf->data & 0xf0000000!= 0x30000000) {
        dmawarn(
"dmaload: buffer is %p\n", (void *)buf->data);
    }

    writel(buf
->data, chan->addr_reg);

    dma_wrreg(chan, S3C2410_DMA_DCON,
          chan
->dcon | reload | (buf->size/chan->xfer_unit));

    chan
->next = buf->next;

    
/* update the state of the channel */

    
switch (chan->load_state) {
    
case S3C2410_DMALOAD_NONE:
        chan
->load_state = S3C2410_DMALOAD_1LOADED;
        
break;

    
case S3C2410_DMALOAD_1RUNNING:
        chan
->load_state = S3C2410_DMALOAD_1LOADED_1RUNNING;
        
break;

    
default:
        dmawarn(
"dmaload: unknown state %d in loadbuffer\n",
            chan
->load_state);
        
break;
    }
    
return 0;
}
 
============================================
一些相關函數的說明。供自己日后參考。
--------------------------------------------------------------------------------------
int __init s3c24xx_dma_init_map(struct s3c24xx_dma_selection *sel)
初始化全局變量dma_sel結構,在此函數中大家可能疑惑的是
    nmap 
= kmalloc(map_sz, GFP_KERNEL);
    
if (nmap == NULL)
        
return -ENOMEM;

    memcpy(nmap, sel
->map, map_sz);
    memcpy(
&dma_sel, sel, sizeof(*sel));

    dma_sel.map 
= nmap;
這幾條語句,為什么用memcpy初始化為了dma_sel,而又要用再分配的nmap結構去給dma_sel賦值。其答案是為了保險,因為dma_sel 中的map成員是個指針。對指針的操作是要很小心的。這里在此函數中重新定義一個指針變量,并指向它,就是為了防止別處定義的指針被撤消而造成越界訪問。其實我認為這沒有必要的。

dma_sel的定義為struct s3c24xx_dma_selection dma_sel;
而struct s3c24xx_dma_selection的定義為
struct s3c24xx_dma_selection {
    
struct s3c24xx_dma_map    *map;
    unsigned 
long         map_size;
    unsigned 
long         dcon_mask;

    
void    (*select)(struct s3c2410_dma_chan *chan,
              
struct s3c24xx_dma_map *map);
};


--------------------------------------------------------------------------------------------------------
struct s3c2410_dma_chan *s3c2410_dma_map_channel(int channel)
此函數功能是: turn the 
virtual channel number into a real, and un-used hardware channel.完成DMA通道的虛實映射
在s3c2440_dma_mappings數組中查找相應channel對應的通道(
0--4,有效未使用),并將映射關系記入dma_chan_map[channel]數組中。


---------------------------------------------------------------------------------------------------------
static int __init s3c2410_init_dma(void)
用于初始化s3c2410_dma_chan結構,并完成地址映射。

-----------------------------------------------------------------------------------------------------------
static struct s3c2410_dma_chan *lookup_dma_channel(unsigned int channel)
DMA通道虛實轉換

-----------------------------------------------------------------------------------------------------------
int s3c2410_dma_request(unsigned int channel,
            
struct s3c2410_dma_client *client,
            
void *dev)
通過s3c2410_dma_map_channel函數找到channel對應的通道,并設置相應的通道狀態,申請中斷
-----------------------------------------------------------------------------------------------------------

int s3c2410_dma_started(struct s3c2410_dma_chan *chan)
    
/* if we've only loaded one buffer onto the channel, then chec
     * to see if we have another, and if so, try and load it so when
     * the first buffer is finished, the new one will be loaded onto
    * the channel 
*/
-----------------------------------------------------------------------------------------------------------
int s3c2410_dma_free(dmach_t channel, struct s3c2410_dma_client *client)
/* s3c2410_dma_free
 *
 * release the given channel back to the system, will stop and flush
 * any outstanding transfers, and ensure the channel is ready for the
 * next claimant.
 *
 * Note, although a warning is currently printed if the freeing client
 * info is not the same as the registrant's client info, the free is still
 * allowed to go through.
*/

--------------------------------------------------------------------------------------------------------------
static int s3c2410_dma_flush(struct s3c2410_dma_chan *chan)
 
* stop the channel, and remove all current and pending transfers

--------------------------------------------------------------------------------------------------------------
int s3c2410_dma_config(dmach_t channel,
               
int xferunit,
               
int dcon)
根據xferunit設置通道的控制寄存器
--------------------------------------------------------------------------------------------------------------
int s3c2410_dma_setflags(dmach_t channel, unsigned int flags)
根據flags設置通道的flags
--------------------------------------------------------------------------------------------------------------


int s3c2410_dma_ctrl(dmach_t channel, enum s3c2410_chan_op op);


0

posted on 2012-12-04 08:58 天下 閱讀(839) 評論(0)  編輯 收藏 引用 所屬分類: kernel & Driver

<2012年10月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

導航

統計

常用鏈接

留言簿(4)

隨筆分類(378)

隨筆檔案(329)

鏈接

最新隨筆

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品theporn88| 亚洲综合清纯丝袜自拍| 久久久999国产| 狠狠色综合日日| 免费日韩视频| 欧美电影资源| 亚洲一级网站| 欧美一区影院| 亚洲黄色免费| 亚洲天天影视| 激情欧美丁香| 9色porny自拍视频一区二区| 国产精品你懂得| 麻豆国产精品777777在线| 欧美不卡福利| 欧美亚洲尤物久久| 久久美女性网| 亚洲在线日韩| 美女精品一区| 欧美一级片一区| 蜜臀久久久99精品久久久久久| 亚洲精品少妇30p| 亚洲已满18点击进入久久 | 欧美二区乱c少妇| 欧美精品激情在线| 欧美在线关看| 欧美日韩精品一区| 久久婷婷人人澡人人喊人人爽| 欧美精品日韩一本| 久久久亚洲成人| 欧美日韩福利| 欧美福利影院| 国产自产v一区二区三区c| 亚洲精品日日夜夜| 一区二区三区中文在线观看| 一区二区不卡在线视频 午夜欧美不卡在 | 亚洲激情一区二区| 国产伦一区二区三区色一情| 亚洲国产精彩中文乱码av在线播放| 国产精品久久久久久av福利软件| 欧美国产日产韩国视频| 国产视频亚洲| 亚洲无玛一区| 亚洲一区二区三区视频| 欧美成人免费播放| 免费欧美电影| 精品不卡在线| 欧美在线观看你懂的| 亚洲欧美国产精品专区久久| 欧美精品一区二区三区很污很色的 | 尤物网精品视频| 亚洲欧美日韩人成在线播放| 在线亚洲自拍| 欧美日韩成人综合| 亚洲国产乱码最新视频| 在线不卡亚洲| 久久这里有精品视频| 巨胸喷奶水www久久久免费动漫| 国产热re99久久6国产精品| 日韩视频免费| 午夜影视日本亚洲欧洲精品| 小辣椒精品导航| 国产精品乱看| 午夜精品福利在线观看| 欧美中文字幕在线播放| 国产美女精品视频| 欧美一区二区黄色| 久久久伊人欧美| 黄色亚洲大片免费在线观看| 久久精品青青大伊人av| 免播放器亚洲一区| 亚洲国产视频a| 欧美经典一区二区| 一区二区日韩| 久久国产精品久久w女人spa| 国产一区二区三区自拍| 欧美中文字幕第一页| 久久午夜精品| 亚洲人成网在线播放| 欧美日韩国产成人在线91| 一区二区欧美在线| 久久riav二区三区| 亚洲二区三区四区| 欧美激情一区二区三级高清视频| 亚洲人成在线播放网站岛国| 亚洲一区二区在线播放| 国产视频久久网| 欧美成人免费在线观看| 99av国产精品欲麻豆| 欧美中文在线免费| 在线精品视频一区二区三四| 欧美日韩成人综合天天影院| 亚洲欧美视频在线观看| 欧美国产一区二区在线观看 | 黄色精品一区二区| 欧美日韩1234| 欧美呦呦网站| 亚洲日韩中文字幕在线播放| 午夜精品久久久久影视| 亚洲电影免费| 国产精品久久婷婷六月丁香| 久久女同互慰一区二区三区| 日韩视频在线观看免费| 久久频这里精品99香蕉| 亚洲视频欧美在线| 在线精品国精品国产尤物884a| 欧美日韩中文字幕在线| 久久色在线播放| 亚洲一区二区三区视频播放| 亚洲成色www8888| 欧美一区二区在线看| a91a精品视频在线观看| 黄色免费成人| 国产欧美1区2区3区| 欧美日韩黄色大片| 久久久久久久久久久成人| 在线视频一区二区| 亚洲激情视频在线播放| 久久综合狠狠综合久久激情| 亚洲欧美三级在线| 亚洲美女精品一区| 亚洲二区视频| 黑人一区二区三区四区五区| 国产精品拍天天在线| 欧美日韩黄色大片| 欧美成人精品高清在线播放| 久久久精品五月天| 亚洲综合日韩在线| 中文亚洲欧美| 亚洲麻豆一区| 亚洲日本久久| 亚洲黄色尤物视频| 亚洲第一网站| 欧美二区乱c少妇| 欧美成人午夜免费视在线看片| 久久夜色精品| 麻豆免费精品视频| 久久一区激情| 麻豆91精品91久久久的内涵| 久久亚洲视频| 乱中年女人伦av一区二区| 久久男人资源视频| 久久免费高清视频| 久久婷婷丁香| 农村妇女精品| 欧美激情网站在线观看| 亚洲东热激情| 亚洲激情网站| 亚洲最黄网站| 亚洲字幕一区二区| 午夜精品区一区二区三| 欧美一级视频| 久久性天堂网| 欧美另类videos死尸| 国产精品久久久久久久9999| 国产乱人伦精品一区二区| 国产色综合网| 亚洲成在线观看| 99国产精品私拍| 亚洲一区二区欧美日韩| 欧美在线综合| 欧美福利视频在线| 日韩视频亚洲视频| 亚洲欧美国产视频| 久久久人成影片一区二区三区观看 | 国产日韩一区二区三区在线播放| 国产女主播一区二区| 精品成人在线| 在线一区亚洲| 久久精品亚洲| 亚洲欧洲日夜超级视频| 亚洲男人的天堂在线观看| 久久久久久久久久久久久9999| 欧美激情一二区| 国产亚洲欧美一区二区| 91久久精品美女高潮| 亚洲欧美视频在线观看视频| 毛片一区二区| 一区二区三区国产盗摄| 久久久美女艺术照精彩视频福利播放| 欧美成人免费在线观看| 国产欧美日韩激情| 亚洲伦伦在线| 久久一区精品| 亚洲亚洲精品三区日韩精品在线视频 | 欧美一区二区成人| 欧美精品一区二区三区久久久竹菊 | 国产美女扒开尿口久久久| 亚洲精品精选| 久久全国免费视频| 一区二区三区精品久久久| 久久婷婷国产综合精品青草| 国产精品久久久久久久免费软件| 91久久精品日日躁夜夜躁国产| 欧美在线高清| 国产精品99久久久久久www| 美女久久一区| 精品91在线| 久久精品女人天堂| 亚洲影视在线播放|