什么request_mem_region()实际上做的,当需要它? [英] What does request_mem_region() actually do and when it is needed?

查看:166
本文介绍了什么request_mem_region()实际上做的,当需要它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在学习上编写嵌入式Linux驱动程序,并决定开除几个GPIO来确保我理解这本书的(LDD3,chap9.4.1)正确。

I'm studying on writing embedded linux driver, and decided to fire a few GPIOs to make sure I understand the book (LDD3, chap9.4.1) correctly.

我能够控制正确的GPIO引脚按预期(使它成为高与低,我用万用表进行探测);不过,我测试了2件code,其中一个的 request_mem_region(),一个没有。我期待没有将失败的人,但都被工作得很好。

I am able to control the correct GPIO pins as intended (making it high and low, I probed with a multimeter); however, I tested 2 pieces of code, one with request_mem_region(), and one without. I'm expecting the one without will fail, but both is working just fine.

code与 request_mem_region

if( request_mem_region( PIN3_CONF_PHYS, MAPPED_SIZE_GPIO_CONF,DEVICE_NAME ) == NULL )
  {
    printk( KERN_ALERT
            "GPIO_140_141_conf_phys error:%s: unable to obtain I/O memory address 0x%08llX\n",
            DEVICE_NAME, PIN3_CONF_PHYS );

    return -EBUSY;
  }

pin3_conf = (u32)ioremap( PIN3_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
pin4_conf = (u32)ioremap( PIN4_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
pin5_conf = (u32)ioremap( PIN5_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
pin6_conf = (u32)ioremap( PIN6_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
//-----------------------------------------------------------------
if( request_mem_region( GPIO_BANK5_PHYS, MAPPED_SIZE_GPIO_5,DEVICE_NAME ) == NULL )
  {
    printk( KERN_ALERT
            "error:%s: unable to obtain I/O memory address 0x%08llX\n",
            DEVICE_NAME, GPIO_BANK5_PHYS );

    return -EBUSY;
  }

gpio_virt = (u32)ioremap( GPIO_BANK5_PHYS, MAPPED_SIZE_GPIO_5 );

//some iowrite32() functions continue...

code,而不 request_mem_region()

pin3_conf = (u32)ioremap( PIN3_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
pin4_conf = (u32)ioremap( PIN4_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
pin5_conf = (u32)ioremap( PIN5_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
pin6_conf = (u32)ioremap( PIN6_CONF_PHYS, MAPPED_SIZE_GPIO_CONF);
gpio_virt = (u32)ioremap( GPIO_BANK5_PHYS, MAPPED_SIZE_GPIO_5 );
//some iowrite32() functions continue...

我可以从两种情况下观察到的唯一的区别是这样做的结果执行cat / proc / iomem中,一个与 request_mem_region()将显示出额外的行 49056000-49056097。GPIO3

The only difference I can observe from both cases is the result of doing a cat /proc/iomem, the one with request_mem_region() will display an additional line showing 49056000-49056097 : GPIO3.

我的问题是,为什么 request_mem_region(),因为我仍然可以与硬件地址进行通信,只需要的ioremap()?所以,当我们真正需要使用 request_mem_region()

My question is why request_mem_region() is needed since I can still communicate with the hardware address with only ioremap()? So when do we actually need to use request_mem_region()?

感谢您的任何答复!

推荐答案

request_mem_region 告诉你的驱动程序将使用此范围内的I / O地址的内核,将prevent其他司机通过 request_mem_region 作任何重叠调用同一区域。这种机制没有做任何类型的映射,这是一个纯粹的保留机制,它依赖于一个事实,即所有的内核设备驱动程序必须是好的,他们必须调用 request_mem_region ,检查返回值,并适当地表现在出现错误时。

request_mem_region tells the kernel that your driver is going to use this range of I/O addresses, which will prevent other drivers to make any overlapping call to the same region through request_mem_region. This mechanism does not do any kind of mapping, it's a pure reservation mechanism, which relies on the fact that all kernel device drivers must be nice, and they must call request_mem_region, check the return value, and behave properly in case of error.

所以这是完全合乎逻辑的,你的code作品,未经 request_mem_region ,它只是它不符合内核编码规则。

So it is completely logical that your code works without request_mem_region, it's just that it doesn't comply with the kernel coding rules.

不过,您的code不符合内核编码风格。和additionnally,有一个现有的基础设施来处理的GPIO,名为gpiolib,您应该改用手动重新映射你的GPIO银行寄存器。哪个平台是你的工作吗?

However, your code doesn't comply with the kernel coding style. And additionnally, there is an existing infrastructure to handle GPIOs, named gpiolib, which you should use instead of manually remapping your GPIO bank registers. Which platform are you working on ?

这篇关于什么request_mem_region()实际上做的,当需要它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆