从linux内核访问物理内存 [英] accessing physical memory from linux kernel

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

问题描述

我们可以通过某些内核代码访问任何物理内存吗?因为,我写了一个只有init_module和exit_module的设备驱动程序.代码如下.

Can we access any physical memory via some kernel code.? Because, i wrote a device driver which only had init_module and exit_module.. the code is following.

int init_module(void) {
    unsigned char *p = (unsigned char*)(0x10);
    printk( KERN_INFO  "I got %u \n", *p);
    return 0;
}

和一个虚拟的exit_module ..问题是当我执行lsmod时计算机被挂起. 怎么了?我应该获得某种访问内存位置的许可吗?

and a dummy exit_module.. the problem is the computer gets hung when i do lsmod.. What happens? Should i get some kinda permission to access the mem location?

请解释一下..我是初学者!

kindly explain.. I'm a beginner!

推荐答案

要访问实际的物理内存,应使用phys_to_virt函数.如果是io内存(例如PCI内存),则应仔细查看ioremap.

To access real physical memory you should use phys_to_virt function. In case it is io memory (e.g. PCI memory) you should have a closer look at ioremap.

整个主题非常复杂,如果您是初学者,我会建议一些内核/驱动程序开发书籍/文档.

This whole topic is very complex, if you are a beginner I would suggest some kernel/driver development books/doc.

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

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