DMA Engine

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pagemap.h>
#include <linux/completion.h>
#include <linux/async_tx.h>
#include <linux/slab.h>
//#include <asm-generic/page.h>
#define PAGE_SIZE 1 << 12
#define SIZE 10

MODULE_LICENSE("GPL");

void callback(void *param)
{
    struct completion *cmp = param;
    complete(cmp);
    printk("call back\n");
}

void my_copy(void *src, void *dst, size_t len)
{
    struct dma_async_tx_descriptor *tx ;
    addr_conv_t addr_conv[SIZE];
    struct async_submit_ctl submit;
    struct completion cmp;
    struct page *copy_src = virt_to_page(src);
    struct page *copy_dst = virt_to_page(dst);
    //init_async_submit(&submit, ASYNC_TX_XOR_DROP_DST, NULL, NULL, NULL, addr_conv);
    //tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len, &submit);
    init_completion(&cmp);
    init_async_submit(&submit, ASYNC_TX_XOR_DROP_DST , NULL, callback, &cmp, addr_conv);
    //submit.depend_tx = tx;
    tx = async_memcpy(copy_dst, copy_src, ((unsigned int)src)&(PAGE_SIZE - 1), ((unsigned int)dst)&(PAGE_SIZE - 1), len, &submit);
    if(tx == NULL)
      printk("memcpy failed!\n");
    //tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len, &submit);

    async_tx_issue_pending_all();

    wait_for_completion(&cmp);
    printk("Finished!\n");
}


static int hello_init(void)
{
    int size = SIZE * sizeof(char);
    char *src = kzalloc(size, GFP_KERNEL);
    char *dst = kzalloc(size, GFP_KERNEL);
    printk("Begin test\n");
    if(NULL == src || NULL == dst)
        printk("kmalloc failed!\n");
    memcpy(src, "xhj", 4);
    my_copy(src, dst, size);
    printk("src = %s, dst = %s\n", src, dst);
    kfree(src);
    kfree(dst);
    return 0;
}

static void hello_exit(void)
{
        printk("End test\n");
}

module_init(hello_init);
module_exit(hello_exit);

 

 

ifneq ($(KERNELRELEASE),)

    obj-m :=hello.o

else
    PWD := $(shell pwd)
    KDIR :=/lib/modules/$(shell uname -r)/build

all:

    make -C $(KDIR) M=$(PWD) modules

clean:

    rm -f *.ko *.o *.mod.o *.mod.c *.symvers
endif

 

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/pagemap.h>
#include <linux/completion.h>
#include <linux/async_tx.h>


MODULE_LICENSE("GPL");

void callback(void *param)
{
    struct completion *cmp = param;
    complete(cmp);
    printk("call back\n");
}

void run_xor_copy_xor(struct page **xor_srcs,
                    int xor_src_cnt,
                    struct page *xor_dest,
                    size_t xor_len,
                    struct page *copy_src,
                    struct page *copy_dest,
                    size_t copy_len)
{
    struct dma_async_tx_descriptor *tx ;
    addr_conv_t addr_conv[xor_src_cnt];
    struct async_submit_ctl submit;
    struct completion cmp;
    //init_async_submit(&submit, ASYNC_TX_XOR_DROP_DST, NULL, NULL, NULL, addr_conv);
    //tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len, &submit);
    init_completion(&cmp);
    init_async_submit(&submit, ASYNC_TX_XOR_DROP_DST , NULL, callback, &cmp, addr_conv);
    //submit.depend_tx = tx;
    tx = async_memcpy(copy_dest, copy_src, 0, 0, copy_len, &submit);
    if(tx == NULL)
      printk("memcpy failed!\n");
    //tx = async_xor(xor_dest, xor_srcs, 0, xor_src_cnt, xor_len, &submit);

    async_tx_issue_pending_all();

    wait_for_completion(&cmp);
    printk("Finished!\n");
}


static int hello_init(void)
{
    struct page * xor_src = alloc_page(GFP_KERNEL);
    struct page * xor_dst = alloc_page(GFP_KERNEL);
    struct page * copy_src = alloc_page(GFP_KERNEL);
    struct page * copy_dst = alloc_page(GFP_KERNEL);
    printk("Begin test\n");
    run_xor_copy_xor(&xor_src, sizeof(struct page), xor_dst, sizeof(struct page), copy_src, copy_dst, sizeof(struct page));
    __free_page(xor_src);
    __free_page(xor_dst);
    __free_page(copy_src);
    __free_page(copy_dst);
    return 0;
}

static void hello_exit(void)
{
        printk("End test\n");
}

module_init(hello_init);
module_exit(hello_exit);

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值