我现在在做dma+eim与fpga通信,我参考飞思卡尔提供的mem to mem的程序,然后对其修改,将wbuf改成eimbase虚拟地址后,一运行就死机,不知道该如何解决,以下是我的read的一段程序,抱大神大腿。
ssize_t sdma_read (struct file *filp, char __user * buf, size_t count,
loff_t * offset)
{
u8 *index1;
int i, ret;
struct dma_slave_config dma_m2m_config;
struct dma_async_tx_descriptor *dma_m2m_desc;
index1 = wbuf;
for (i=0; i<SDMA_BUF_SIZE/4; i++) {
*(index1 + i) = i;
}
dma_m2m_config.direction = DMA_MEM_TO_MEM;
dma_m2m_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
dmaengine_slave_config(dma_m2m_chan, &dma_m2m_config);
sg_init_table(sg, 1);
sg_set_buf(&sg[0], eimbase, SDMA_BUF_SIZE/4);
ret = dma_map_sg(NULL, sg, 1, dma_m2m_config.direction);
printk("eimbase page_link=%ld\n", sg->page_link);
printk("eimbase offset=%d\n", sg->offset);
printk("eimbase dma_address=%x\n", sg->dma_address);
printk("eimbase length=%d\n", sg->length);
dma_m2m_desc = dma_m2m_chan->device->device_prep_slave_sg(dma_m2m_chan,sg, 1, dma_m2m_config.direction, 1);
sg_init_table(sg2, 1);
sg_set_buf(&sg2[0], rbuf, SDMA_BUF_SIZE);
ret = dma_map_sg(NULL, sg2, 1, dma_m2m_config.direction);
printk("rbuf page_link=%ld\n", sg2->page_link);
printk("rbuf offset=%d\n", sg2->offset);
printk("rbuf dma_address=%x\n", sg2->dma_address);
printk("rbuf length=%d\n", sg2->length);
dma_m2m_desc = dma_m2m_chan->device->device_prep_slave_sg(dma_m2m_chan,sg2, 1, dma_m2m_config.direction, 0);
dma_m2m_desc->callback = dma_m2m_callback;
dmaengine_submit(dma_m2m_desc);
wait_for_completion(&dma_m2m_ok);
dma_unmap_sg(NULL, sg, 1, dma_m2m_config.direction);
dma_unmap_sg(NULL, sg2, 1, dma_m2m_config.direction);
for (i=0; i<SDMA_BUF_SIZE/4; i++) {
if (*(rbuf+i) != *(wbuf+i)) {
printk("buffer 1 copy falled!\n");
return 0;
}
}
printk("buffer 1 copy passed!\n");
i = copy_to_user(buf, rbuf, count);
return 0;
} |