如何确定设备存储器的页面帧号? [英] How does one determine the page frame number for device memory?

查看:144
本文介绍了如何确定设备存储器的页面帧号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自LDD3/Ch.在使用remap_pfn_range"和简单实现"的15/节中,pfn已等同于vm_pgoff字段.我对此感到困惑.怎么会这样呢?

请注意,vm_pgoff被描述为:

文件中区域的偏移量(以页为单位).当文件或设备是 映射,这是在此映射的第一页的文件位置 区域.

因此,如果映射的第一页也对应于文件的第一页(我认为这很常见),则vm_pgoff为0.正确吗?如果是这样,这似乎不是remap_pfn_range()的pfn参数的正确值.我在这里想念什么?正确的值是多少?为了便于参考,我在下面的LDD3(第426页)中复制了相关代码.

static int simple_remap_mmap(struct file *filp, struct vm_area_struct *vma)
{
if (remap_pfn_range(vma, vma->vm_start, vm->vm_pgoff,
                    vma->vm_end - vma->vm_start,
                    vma->vm_page_prot))
    return -EAGAIN;
...
}

解决方案

您提供的特定示例是实现一个字符设备文件,该文件允许一个人映射物理内存,这与/dev/mem非常相似.通过指定文件的偏移量,可以指定物理内存地址.因此,该计算将使用偏移量并除以页面大小以找到PFN.

对于真实"设备驱动程序,通常将具有设备内存映射的寄存器的物理地址或根据设备规范对RAM进行硬编码,然后使用它们来得出PFN(除以页面大小). /p>

From LDD3/ Ch. 15/ sections "Using remap_pfn_range" and "A Simple Implementation", pfn has been equated to the vm_pgoff field. I am confused by this. How can that be so?

Note that vm_pgoff is described as:

The offset of the area in the file, in pages. When a file or device is mapped, this is the file position of the first page mapped in this area.

Thus if the first page mapped corresponds to the first page of the file as well (which, I think would be quite common), vm_pgoff would be 0. correct? If so, this doesn't seem to be the correct value for the pfn parameter of remap_pfn_range( ). What am I missing here? What is the correct value? For ease of reference, I am reproducing the relevant code from LDD3 below (Page no. 426)

static int simple_remap_mmap(struct file *filp, struct vm_area_struct *vma)
{
if (remap_pfn_range(vma, vma->vm_start, vm->vm_pgoff,
                    vma->vm_end - vma->vm_start,
                    vma->vm_page_prot))
    return -EAGAIN;
...
}

解决方案

The specific example you've provided is implementing a character device file that allows one to map physical memory, very similar to /dev/mem. By specifying the offset of the file you specify the physical memory address. Hence the calculation that takes the offset and divide in the page size to find the PFN.

For a "real" device driver, you would normally have the physical address of the device memory mapped registers or RAM hard coded from the device specification, and use that to derive the PFN (by dividing by the page size).

这篇关于如何确定设备存储器的页面帧号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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