如何从 linux 内核空间访问物理地址? [英] How to acess the physical address from linux kernel space?

查看:55
本文介绍了如何从 linux 内核空间访问物理地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 rasberry pi 板.是否可以直接访问GPIO物理地址从 linux 内核空间使用 inb(), outb()... ?.如果是怎么办?

I am working on rasberry pi board. Is it possible to directly access the GPIO physical address from linux kernel space using inb(), outb()... ?. If yes how ?.

GPIO寄存器地址链接第 90 页http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

GPIO register address link Page 90 http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

谢谢

推荐答案

是的.

  1. 使用 ioremap
  2. 获取相关寄存器的虚拟地址映射设置
  3. 使用readl/writel来操作物理内存.
  1. Get a virtual address mapping setup to the registers in question using ioremap
  2. Use readl/writel to manipulate the physical memory.

请注意 ARM 处理器会在未对齐访问时出错.Linux 可以优雅地处理这个问题,但会降低性能.

Beware that ARM processors will fault on unaligned accesses. Linux handles this gracefully, but with a performance penalty.

小例子:

void __iomem *regs = ioremap(0xdead0000, 4);

pr_info("0xdead0000: %#x
", readl(regs));

iounmap(regs);

这篇关于如何从 linux 内核空间访问物理地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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