将物理地址映射到虚拟地址linux [英] Mapping physical addresses to virtual address linux

查看:412
本文介绍了将物理地址映射到虚拟地址linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型嵌入式系统.当我的Linux启动到用户空间时,我知道物理内存中的设备在哪里.我想将它们映射到用户空间虚拟地址.目前,我正在通过内核模块来实现.我使用vmalloc/kmalloc(取决于大小),然后在返回的虚拟地址上使用ioremap_page_range来映射我的物理地址.我不认为这是正确的方法.首先,我正在分配内存,然后要求内核将虚拟地址空间重新映射到一些不同的物理地址空间. (在vmcall/kmalloc中,最初映射的physical-> virtual有点用,因为我不在乎那些物理页面.这绝对不好.)

I am working on a small embedded system. When my linux boots up into user space, I know where are my devices in the physical memory. I want to map them into user space virtual addresses. Currently, I am doing it through a kernel module. I use vmalloc/kmalloc (depending on the size) and then I use ioremap_page_range on that returned virtual addresses to map my physical addresses. I dont think that is the correct way to go about. First of all I am allocating memory and then I am asking kernel to remap that virtual address space to some different physical address space. (Initially mapped physical->virtual in vmcall/kmalloc is kinda useless as I dont care about those physical pages. This is definitely not good.)

有一种更好的方法可以将已知的物理内存映射到用户空间进程中. (我知道除了我的用户空间流程外,没有人会触摸该内存.)

Instead of this is there a better way to map the known physical memory into user space process. (I know other than my user space process, no one gonna touch that memory.)

谢谢

推荐答案

您要尝试的操作是访问 IO内存.我只能鼓励您阅读 Linux设备驱动程序(LDD),尤其是第9章.

What you are trying to do is accessing what is called IO memory. I can only encourage you to read the Linux Device Drivers (LDD) book and more specifically the chapter 9.

要分配"此类区域,您需要致电

To "allocate" such an area, you need to call

struct resource *request_mem_region(unsigned long start, unsigned long len, char *name)

.在驱动程序可以访问它之前,您必须为其分配一个虚拟地址,这是通过调用

. Before your driver can access it, you have to assign it a virtual address, this is done with a call to

void *ioremap(unsigned long phys_addr, unsigned long size)

为确保驱动程序随后可在不同的体系结构/平台上运行,请确保对此类区域使用某些访问器功能(ioread8/16/32或iowrite8/16/32及其所有变体).

To ensure that your driver will then work on different architectures/platforms, be sure to use some accessor function to such areas ( ioread8/16/32 or iowrite8/16/32 and all of their variants).

这篇关于将物理地址映射到虚拟地址linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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