aes.c求改错
#include <linux/module.h> #include <linux/kernel.h> #include <linux/fs.h> #include <linux/device.h> #include <asm/io.h> static struct class* aes_driver_class = NULL; static struct device* aes_driver_device = NULL; unsigned long aes_slave_reg0_addr = 0; //aes moulde's frequency visual address unsigned long aes_slave_reg1_addr = 0; unsigned long aes_slave_reg2_addr = 0; unsigned long aes_slave_reg3_addr = 0; //aes moulde's duty visual address unsigned long aes_slave_reg4_addr = 0; //aes moulde's frequency visual address unsigned long aes_slave_reg5_addr = 0; unsigned long aes_slave_reg6_addr = 0; unsigned long aes_slave_reg7_addr = 0; unsigned long aes_slave_reg8_addr = 0; #define DEVICE_NAME "AES_MOUDLE" #define AES__PHY_ADDR 0x40000000 //This Address is based XPS static aes_driver_major; static int my_open(struct inode * inode , struct file * filp) { return 0; } static int my_release(struct inode * inode, struct file *filp) { return 0; } static int my_ioctl(struct file *filp, unsigned int reg_num, unsigned long arg){ if(reg_num>=0&®_num<=8) {iowrite32(arg,aes_slave_reg0_addr+reg_num*4); prink("write0x% xto0x% x!\n",arg,aes_slave_reg0_addr+reg_num*4);} else prink("wrong reg num"); return 0; } static ssize_t my_write(struct file* filp, const char *data,size_t count,loff_t *offp){ return ioread(aes_slave_reg0_addr+count*4); } static ssize_t myread(struct file*file,char *data,size_t count,loff_t *offp){ if(filp->f_flags &O_NONBLOCK) return -EAGAIN; int tmp[4]; tmp[0] =ioread32(aes_slave_reg5_addr) ;//AXI_AES_IP_mReadSlaveReg5(X_BASE,0); tmp[1] =ioread32(aes_slave_reg6_addr) ;//AAXI_AES_IP_mReadSlaveReg6(X_BASE,0); tmp[2] =ioread32(aes_slave_reg7_addr) ;//AAXI_AES_IP_mReadSlaveReg7(X_BASE,0); tmp[3] =ioread32(aes_slave_reg8_addr) ;//AAXI_AES_IP_mReadSlaveReg8(X_BASE,0); //xil_printf("%08x %08x %08x %08x\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); data[3] = tmp[0] >> 24; data[2] = tmp[0] >> 16; data[1] = tmp[0] >> 8; data[0] = tmp[0]; data[7] = tmp[1] >> 24; data[6] = tmp[1] >> 16; data[5] = tmp[1] >> 8; data[4] = tmp[1]; data[11] = tmp[2] >> 24; data[10] = tmp[2] >> 16; data[9] = tmp[2] >> 8; data[8] = tmp[2]; data[15] = tmp[3] >> 24; data[14] = tmp[3] >> 16; data[13] = tmp[3] >> 8; data[12] = tmp[3]; return 0; } static struct file_operations aes_driver_fops = { .owner = THIS_MODULE, .read = my_read, .write = my_write, .open = my_open, .release = my_release, .unlock_ioctl = my_ioctl, }; static int __init aes_driver_module_init(void) { /************申请设备号************/ aes_driver_major=register_chrdev(0, DEVICE_NAME, &aes_driver_fops); if (aes_driver_major < 0){ printk("failed to register device.\n"); return -1; } //内核注册设备驱动 aes_driver_class = class_create(THIS_MODULE, "aes_driver"); if (IS_ERR(aes_driver_class)){ printk("failed to create aes moudle class.\n"); unregister_chrdev(aes_driver_major, DEVICE_NAME); return -1; } //创建p——driver设备类 aes_driver_device = device_create(aes_driver_class, NULL, MKDEV(aes_driver_major, 0), NULL, "aes_device"); if (IS_ERR(aes_driver_device)){ printk("failed to create device .\n"); unregister_chrdev(aes_driver_major, DEVICE_NAME); return -1; } //chuang jian设备】 /***************设备地址映射************/ aes_slave_reg0_addr = (unsigned long)ioremap(AES_PHY_ADDR, sizeof(u32));//To get Custom IP--aes moudle's virtual address aes_slave_reg1_addr = aes_slave_reg0_addr+4; aes_slave_reg2_addr = aes_slave_reg0_addr+8; aes_slave_reg3_addr = aes_slave_reg0_addr+12; aes_slave_reg4_addr = aes_slave_reg0_addr+16; aes_slave_reg5_addr = aes_slave_reg0_addr+20; aes_slave_reg6_addr = aes_slave_reg0_addr+24; aes_slave_reg7_addr = aes_slave_reg0_addr+28; aes_slave_reg8_addr = aes_slave_reg0_addr+32; printk(" aes driver initial successfully!\n"); return 0; } static void __exit aes_driver_module_exit(void) { device_destroy(aes_driver_class, MKDEV(aes_driver_major, 0)); class_unregister(aes_driver_class); class_destroy(aes_driver_class); unregister_chrdev(aes_driver_major, DEVICE_NAME); printk("aes module exit.\n"); } module_init(aes_driver_module_init); module_exit(aes_driver_module_exit); MODULE_AUTHOR("puck"); MODULE_ALIAS("aes"); MODULE_LICENSE("GPL");
static struct file_operations aes_driver_fops = { .owner = THIS_MODULE, .read = my_read, .write = my_write, .open = my_open, .release = my_release, .unlock_ioctl = my_ioctl, }; static int __init aes_driver_module_init(void) { /************申请设备号************/ aes_driver_major=register_chrdev(0, DEVICE_NAME, &aes_driver_fops); if (aes_driver_major < 0){ printk("failed to register device.\n"); return -1; } //内核注册设备驱动 aes_driver_class = class_create(THIS_MODULE, "aes_driver"); if (IS_ERR(aes_driver_class)){ printk("failed to create aes moudle class.\n"); unregister_chrdev(aes_driver_major, DEVICE_NAME); return -1; } //创建p——driver设备类 aes_driver_device = device_create(aes_driver_class, NULL, MKDEV(aes_driver_major, 0), NULL, "aes_device"); if (IS_ERR(aes_driver_device)){ printk("failed to create device .\n"); unregister_chrdev(aes_driver_major, DEVICE_NAME); return -1; } //chuang jian设备】 /***************设备地址映射************/ aes_slave_reg0_addr = (unsigned long)ioremap(AES_MOUDLE_PHY_ADDR, sizeof(u32));//To get Custom IP--aes moudle's virtual address aes_slave_reg1_addr = aes_slave_reg0_addr+4; aes_slave_reg2_addr = aes_slave_reg0_addr+8; aes_slave_reg3_addr = aes_slave_reg0_addr+12; aes_slave_reg4_addr = aes_slave_reg0_addr+16; aes_slave_reg5_addr = aes_slave_reg0_addr+20; aes_slave_reg6_addr = aes_slave_reg0_addr+24; aes_slave_reg7_addr = aes_slave_reg0_addr+28; aes_slave_reg8_addr = aes_slave_reg0_addr+32; printk(" aes driver initial successfully!\n"); return 0;
static void __exit aes_driver_module_exit(void) { device_destroy(aes_driver_class, MKDEV(aes_driver_major, 0)); class_unregister(aes_driver_class); class_destroy(aes_driver_class); unregister_chrdev(aes_driver_major, DEVICE_NAME); printk("aes module exit.\n"); } module_init(aes_driver_module_init); module_exit(aes_driver_module_exit); MODULE_AUTHOR("puck"); MODULE_ALIAS("aes"); MODULE_DESCRIPTION("zedboard aes module"); MODULE_LICENSE("GPL");
static int my_open(struct inode * inode , struct file * filp) { return 0; } static int my_release(struct inode * inode, struct file *filp) { return 0; }