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

查看:190
本文介绍了在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天全站免登陆