Linux 设备驱动程序——内存映射 I/O 示例讨论 [英] Linux device driver - memory mapped I/O example discussion

查看:103
本文介绍了Linux 设备驱动程序——内存映射 I/O 示例讨论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了以下主题,但仍有一些问题.

ioread32 后跟 iowrite32 没有给出相同的值

  1. 在链接中,我在哪里可以得到我的 base,它被定义为 0xfed00000在帖子里?
  2. 我应该为第二个参数输入什么

    void request_mem_region(unsigned long start, unsigned long len,char *name);

  3. 我应该为第二个参数输入什么

    void *ioremap_nocache(unsigned long phys_addr, unsigned long size);

  4. 通过使用 Makefile 并生成内核模块,我应该使用 insmod 然后使用 dmesg 来检查代码是否按预期工作,是这样吗?正确吗?

  5. 在这种情况下,我应该在源代码中的 return 0; 之前添加 iounmap(virtual_base); 吗?

谢谢

解决方案

  1. 在链接中,我在哪里可以获得我在帖子中定义为 0xfed00000 的基数?

它是外设寄存器的基(物理)地址.
如果外围设备是板上的分立芯片,请查阅电路板文档.
如果外设嵌入在 SoC 中,请参阅 SoC 数据表中的存储器映射.

<块引用>

  1. 我应该为第二个参数输入什么

void request_mem_region(unsigned long start, unsigned long len,char *name);

<块引用>

  1. 我应该为第二个参数输入什么

void *ioremap_nocache(unsigned long phys_addr, unsigned long size);

应该使用相同的第一个和第二个参数调用这两个例程.
长度/大小是外设的寄存器集占用的字节数.
有时指定下一个外设的整个内存区域.

<块引用>

  1. 通过使用 Makefile 并生成内核模块,我应该使用 insmod 和 dmesg 来检查代码是否按预期工作,这是正确的吗?

明智地添加 printk() 语句是经过验证的 &测试 Linux 内核驱动程序/模块的真正方法.
Unix 有 kdb.

<块引用>

  1. 在这种情况下,我应该添加 iounmap(virtual_base);在返回0之前;在源代码中?

不要复制那个写得不好的初始化代码示例.
如果 ioremap() 在驱动程序的 probe()(或其他初始化)例程中执行,则 iounmap() 应该在探测器的驱动程序的 remove()(或 init 的补充)例程中的错误退出序列.
Linux 内核源代码中有许多示例可供研究.使用在线 Linux 交叉参考,例如 http://lxr.free-electrons.com/source/
请注意,几乎所有 Linux 驱动程序都使用 iounmap() 两次或更多次.

I have gone through the following topic and I still have some questions.

ioread32 followed by iowrite32 not giving same value

  1. In the link, where can I get my base which is defined as 0xfed00000 in the post ?
  2. what should I put for the second parameter in

    void request_mem_region(unsigned long start, unsigned long len,char *name);

  3. what should I put for the second parameter in

    void *ioremap_nocache(unsigned long phys_addr, unsigned long size);

  4. By having the Makefile and generating the kernel module, I should use the insmod and then dmesg to check if the code works as I expect, is this correct ?

  5. In the case, should I add iounmap(virtual_base); before return 0; in the source ?

Thanks

解决方案

  1. In the link, where can I get my base which is defined as 0xfed00000 in the post ?

It's the base (physical) address of the peripheral's registers.
If the peripheral is a discrete chip on the board, then consult the board documentation.
If the peripheral is embedded in a SoC, then consult the memory map in the SoC datasheet.

  1. what should I put for the second parameter in

void request_mem_region(unsigned long start, unsigned long len,char *name);

  1. what should I put for the second parameter in

void *ioremap_nocache(unsigned long phys_addr, unsigned long size);

These two routines should be called with the same first and second parameters.
The length/size is the number of bytes the peripheral's register set occupies.
Sometimes the entire memory region to the next peripheral is specified.

  1. By having the Makefile and generating the kernel module, I should use the insmod and then dmesg to check if the code works as I expect, is this correct ?

A judicious sprinkling of printk() statements is the tried & true method of testing a Linux kernel driver/module.
Unix has kdb.

  1. In the case, should I add iounmap(virtual_base); before return 0; in the source ?

Do not copy that poorly written example of init code.
If ioremap() is performed in a driver's probe() (or other initialization) routine, then the iounmap() should be in the probe's error exit sequence and in the driver's remove() (or the complementary to init) routine.
There are numerous examples to study in the Linux kernel source. Use an online Linux cross reference such as http://lxr.free-electrons.com/source/
Note that almost all Linux drivers use iounmap() two or more times.

这篇关于Linux 设备驱动程序——内存映射 I/O 示例讨论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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