Linux中是否有用于从虚拟地址确定物理地址的API? [英] Is there any API for determining the physical address from virtual address in Linux?

查看:39
本文介绍了Linux中是否有用于从虚拟地址确定物理地址的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux 操作系统中是否有用于从虚拟地址确定物理地址的 API?

Is there any API for determining the physical address from virtual address in Linux operating system?

推荐答案

内核和用户空间使用由内存管理硬件映射到物理地址的虚拟地址(也称为线性地址).此映射由页表定义,由操作系统设置.

Kernel and user space work with virtual addresses (also called linear addresses) that are mapped to physical addresses by the memory management hardware. This mapping is defined by page tables, set up by the operating system.

DMA 设备使用总线地址.在 i386 PC 上,总线地址与物理地址相同,但其他体系结构可能具有特殊的地址映射硬件来将总线地址转换为物理地址.

DMA devices use bus addresses. On an i386 PC, bus addresses are the same as physical addresses, but other architectures may have special address mapping hardware to convert bus addresses to physical addresses.

在 Linux 中,您可以使用 asm/io.h 中的这些函数:

In Linux, you can use these functions from asm/io.h:

  • virt_to_phys(virt_addr);
  • phys_to_virt(phys_addr);
  • virt_to_bus(virt_addr);
  • bus_to_virt(bus_addr);

所有这些都是关于访问普通内存.PCI 或ISA 总线上还有共享内存".可以使用 ioremap() 将其映射到 32 位地址空间内,然后通过 readb()、writeb()(等)函数使用.

All this is about accessing ordinary memory. There is also "shared memory" on the PCI or ISA bus. It can be mapped inside a 32-bit address space using ioremap(), and then used via the readb(), writeb() (etc.) functions.

由于周围有各种缓存,因此访问同一物理地址的不同方式不一定会产生相同的结果.

Life is complicated by the fact that there are various caches around, so that different ways to access the same physical address need not give the same result.

另外,虚拟地址背后的真实物理地址是可以改变的.更重要的是 - 在您访问该内存之前,不可能有与虚拟地址相关联的地址.

Also, the real physical address behind virtual address can change. Even more than that - there could be no address associated with a virtual address until you access that memory.

至于用户端 API,我不知道.

As for the user-land API, there are none that I am aware of.

这篇关于Linux中是否有用于从虚拟地址确定物理地址的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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