resource_size_t dma_tx_chan;
struct resource *r;
dma_cap_mask_t mask;
struct dma_chan *dma_tx;
int ret;
struct scatterlist sg_tx;
//struct dma_async_tx_descriptor *txdesc;
struct device *tx_dev;
u32 tx_vir, tx_phy;
char *sour;
//char *dest;
dma_addr_t dma_dest,dma_src;
int i;
struct completion cmp;
u32 test_size = 1024*1024*4u;
int rc = 0;
/**************************************************/
printk("step 1\n");
r = platform_get_resource(ofdev, IORESOURCE_DMA, 0);
printk("step 2\n");
if (r)
dma_tx_chan = r->start;
else
printk("get dma resource faild\n");
dma_cap_zero(mask);
dma_cap_set(DMA_SLAVE, mask);
dma_tx = dma_request_channel(mask, NULL, NULL);
//dma_tx = dma_request_channel(mask, edma_filter_fn, dma_tx_chan);
printk("step 3\n");
if (!dma_tx) {
printk("request DMA channel failed\n");
ret = -ENODEV;
return ret;
}
//allocate a DMA buffer for the transfer
tx_dev = dma_tx->device->dev;
tx_vir = kzalloc(8, GFP_KERNEL);
sour = kzalloc(sizeof(u8) * test_size, GFP_KERNEL);
if (!sour)
return -ENOMEM;
dest = kzalloc(sizeof(u8) * test_size, GFP_KERNEL);
if (!dest)
return -ENOMEM;
for (i = 0; i < test_size; i++)
sour[i] = (u8)i;
dma_src = dma_map_single(tx_dev,sour,test_size,DMA_TO_DEVICE);
dma_dest = dma_map_single(tx_dev,dest,test_size,DMA_FROM_DEVICE);
struct dma_slave_config dma_tx_conf = {
.direction = DMA_MEM_TO_MEM,
.src_addr = dma_src,
.dst_addr = dma_dest,
.dst_addr_width = 1,
.src_addr_width = 1,
.dst_maxburst = 1,
.src_maxburst = 1,
};
struct dma_async_tx_descriptor *txdesc;
dmaengine_slave_config(dma_tx, &dma_tx_conf);
sg_init_table(&sg_tx, 1);
sg_dma_address(&sg_tx) = dma_src;
sg_dma_address(&sg_tx) = dma_dest;
sg_dma_len(&sg_tx) = test_size;
txdesc = dmaengine_prep_slave_sg(dma_tx, &sg_tx, 1, DMA_MEM_TO_MEM,
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
init_completion(&cmp);
txdesc->callback = dma_tx_callback;
txdesc->callback_param = &cmp;
dmaengine_submit(txdesc);
dma_async_issue_pending(dma_tx);
按照我的思路,应该是从0,1,2.。。。。。。,但实际传的是一些随机数据
在这里往源地址里赋的值
最终通过DMA传到目的地址,如果对的话,数据应该是一样的,但现在是一些随机数据
【村长】北京-某人
你用的什么DMA
【村长】北京-jianwenchang
PS的
【村长】北京-某人
这个我记得xilinx有例程,你可以照着做,就在wiki上
【村长】北京-jianwenchang
wiki上那个不能用,内核太老了,很多头文件都没有了,我还特意问了问写那驱动的外国人
他说不能用了
求大神高见....