#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);