xiaolu192
驱动牛犊
驱动牛犊
  • 注册日期2009-04-24
  • 最后登录2009-06-12
  • 粉丝0
  • 关注0
  • 积分3分
  • 威望21点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2230回复:0

IO内存的申请与释放问题。

楼主#
更多 发布于:2009-06-02 15:52
大家好,最近写了个小小的测试程序,在测试程序中用到了request_mem_region()与release_mem_region()两个函数申请和释放IO内存。但交叉编译后insmod测试模块后再rmmod,出现错误。开发板为S3C2410,代码如下:
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/ioport.h>

int dev_major=200;

MODULE_LICENSE ("Dual BSD/GPL");

static struct file_operations dev_fops;

static ssize_t dev_init(void)
{
  printk(KERN_ALERT "Hello,device initialing!\n");
  request_mem_region(0xfff00000,10,"chdev");
  register_chrdev(dev_major,"chr_dev",&dev_fops);
  return 0;
}

static void dev_exit(void)
{
  printk(KERN_ALERT "Now leaving....\n");
  release_mem_region(0xfff00000,10);
  unregister_chrdev(dev_major,"chr_dev");
}

static ssize_t dev_open(struct inode *inode,struct file *filp)
{
  printk(KERN_ALERT "Device opened...\n");
  return 0;
}

static ssize_t dev_release(struct inode *inode,struct file *filp)
{
  printk(KERN_ALERT "Device closed...\n");
  return 0;
}

static ssize_t dev_write(struct file *filp,char __user *buff,
        size_t count,loff_t *offp)
{
  printk(KERN_ALERT "Device writting!\n");
  return 0;
}

static ssize_t dev_read(struct file *filp,char __user *buff,
        size_t count,loff_t *offp)
{
  printk(KERN_ALERT "Device reading!\n");
  return 0;
}

static struct file_operations dev_fops = {
    owner       :  THIS_MODULE,
    open       :  dev_open,
    release    :  dev_release,
    read       :  dev_read,
    write       :  dev_write
};

module_init(dev_init);
module_exit(dev_exit);

下面是ARM的出错信息:
/home # rmmod test
Unable to handle kernel paging request at virtual address 68104a00
pgd = c3950000
[68104a00] *pgd=00000000
Internal error: Oops: 0 [#1]
Modules linked in: test
CPU: 0
PC is at 0x68104a00
LR is at sys_delete_module+0x240/0x2a4
pc : [<68104a00>]    lr : [<c0066e78>]    Not tainted
sp : c3e79f3c  ip : 20000013  fp : c3e79fa4
r10: beb86ed4  r9 : c3e78000  r8 : c0036064
r7 : 00000000  r6 : c3e78000  r5 : bf000954  r4 : c02188a4
r3 : 68104a02  r2 : bf000954  r1 : c3e79f51  r0 : 00000000
Flags: nzcv  IRQs on  FIQs on  Mode SVC_32  Segment user
Control: C000717F  Table: 33950000  DAC: 00000015
Process rmmod (pid: 718, stack limit = 0xc3e78194)
Stack: (0xc3e79f3c to 0xc3e7a000)
9f20:                                                                00000000
9f40: bf000954 00000880 c3e79f3c 74736574 00000800 beb86ed4 00000000 c3e79fb0
9f60: 000c3bdc beb86ed4 c3e79f9c c3e79f78 c003d5ac c003d380 c3c0042c ffffffff
9f80: 00000880 00b86ed4 0009d5e4 beb86ed4 00000002 00000081 00000000 c3e79fa8
9fa0: c0035ee0 c0066c48 beb86ed4 00000002 00900081 000c3fb4 00000880 00000000
9fc0: 0009d5e4 beb86ed4 00000002 00000000 00000002 000c3bdc beb86ed4 00000002
9fe0: beb86ce4 beb86cd8 00051290 401b29f0 60000010 00900081 00000000 00000000
Backtrace:
[<c0066c38>] (sys_delete_module+0x0/0x2a4) from [<c0035ee0>] (ret_fast_syscall+0
x0/0x2c)
 r7 = 00000081  r6 = 00000002  r5 = BEB86ED4  r4 = 0009D5E4
Code: bad PC value.
 Segmentation fault
/home #

请问下这个错误是因为什么原因 ?LDD3 上说ARM是可以支持上述函数的,可以申请到指定的IO内存,为什么释放失败?请各位大虾指教指教!!
游客

返回顶部