Linux下获取缓冲区的物理地址 [英] get the physical address of a buffer under Linux

查看:25
本文介绍了Linux下获取缓冲区的物理地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xilinx 的 Microblaze 上使用完整的 MMU 运行 Linux 内核 3.3.我正在执行的任务要求我了解以下内容:我需要创建一个文本文件(缓冲区)并定位该缓冲区的物理地址,并且我不希望内核将此文件写入内存的不连续区域.

I am running Linux kernel 3.3 on Xilinx's Microblaze with full MMU. the task that I am doing requires me to know the following: I need to create a text file (buffer) and locate the physical address of this buffer and I don't want the kernel to write this file into discontinuous regions of memory.

我需要这个的原因是因为我有一个 DMA 引擎,可以从预设的物理内存地址传输数据,所以我需要强制 Linux 在那个确切的内存位置创建缓冲区文件,这样当我将数据写入这个文件时它立即由 DMA 引擎传输到另一个硬件核心

the reason I need this because I have a DMA engine that streams data from a preset physical memory address, so I need to force Linux to create the buffer file at that exact memory location, so that when I write data into this file its immediately transmitted by the DMA Engine to another Hardware core

更多详情:

我的系统有一个 512 MB DDR3 RAM 通过Xilinx"多端口内存控制器(MPMC)连接到系统.这个内存控制器的基地址是 0x90000000,系统中的所有单元都通过这个控制器访问内存,包括 MicroBlaze, 我所拥有的 DMA 单元使用一种称为 Native Personality Interface (NPI) 的特殊接口在非常低的级别与内存进行通信,从而获得非常高的速度性能.

my system has a 512 MB DDR3 RAM connected to the system via "Xilinx' multi port memory controller (MPMC). the base address of this memory controller is 0x90000000, all units in the system access memory through this controller, including MicroBlaze, The DMA unit that I have uses a special interface called Native Personality Interface (NPI) to communicate with memory at a very low level, thus resulting a very high speed performance.

这个 NPI DMA 单元最初设计用于一个非常基本的嵌入式内核xilkernel"下,该内核不支持虚拟内存,MMU 都不是 MicroBlaze 的一部分,因此程序员可以看到操作系统代码驻留的位置并选择一个物理内存地址(例如 0x91800000)作为 DMA 的源地址,然后程序员可以在该确切地址中放置一个文件并运行系统

This NPI DMA unit was originally designed to be utilized under a very basic embedded kernel called "xilkernel" which did not support virtual memory, neither MMU was part of MicroBlaze, so the programmer could see where the OS code will reside and select a physical memory address such as 0x91800000 as the source address which DMA will stream from, then the programmer can place a file in that exact address and run the system

当我们需要迁移项目以使用 Linux 而不是 xilkernel 时,我们遇到了这个问题,我在外部存储设备上有文件,我可以作为块设备从 Linux 访问,我需要将每个文件移动到主内存(DDR3 RAM)并使 DMA 流成为文件.目前来自固定地址的 DMA 流,但如果需要,我可以使其通用.

when we needed to the migrate the project to use Linux instead of xilkernel we ran into this issue, I have files on an external storage device which I can access as block device from Linux and I need move each file to main memory (DDR3 RAM) and make the DMA stream the file. currently the DMA streams from a fixed address but I can make it generic if needed.

推荐答案

我需要强制 Linux 在那个确切的内存位置创建缓冲文件

I need to force Linux to create the buffer file at that exact memory location

这是不可能的.(实际上您已经创建了一个 XY 问题.)

This is not possible. (Actually you have created an XY question.)

由于您的硬件从预设的物理内存地址流式传输数据",那么您必须确保 Linux 内核不会将此内存区域用作其内存池的一部分.你需要通知内核启动时不要使用这个内存区域.一旦它成为内核控制的内存空间的一部分,您将无法在此特定物理内存区域中回收"或分配缓冲区.

Since you have hardware that "streams data from a preset physical memory address", then you have to ensure that the Linux kernel does not use this memory region as part of its memory pool. You need to inform the kernel when it boots to not use this memory region. You will not be able to "reclaim" or allocate buffers in this specific physical memory region once it becomes part of the memory space controlled by the kernel.

排除内存区域的最通用方法是在内核命令行上使用 memmap= 参数.

The most generic method to exclude a memory region is to use the memmap= parameter on the kernel command line.

memmap=nn[KMG]$ss[KMG]
        [KNL,ACPI] Mark specific memory as reserved.
        Region of memory to be used, from ss to ss+nn.
        Example: Exclude memory from 0x18690000-0x1869ffff
                 memmap=64K$0x18690000
                 or
                 memmap=0x10000$0x18690000

某些架构,例如带有 ATAG 的 ARM,还有其他不那么明显且更安全的方法来保留物理内存区域.

Some architectures, such as ARM with its ATAGs, have other less visible and more secure methods of reserving regions of physical memory.

然后您必须以某种方式向设备驱动程序提供此内存区域的地址和大小.这可以通过解析命令行获得,或者使用 #defines 硬编码.

Somehow you then have to provide the address and size of this memory region to the device driver. This could be obtained by parsing the command line, or (thumbs down) hardcoded using #defines.

驱动程序应通过调用 request_mem_region() 声明其对内存区域的使用.
驱动程序可以通过调用 ioreamp() 将该内存区域映射到虚拟地址空间.

The driver should declare its use of the memory region by calling request_mem_region().
The driver can map this memory region into virtual address space by calling ioreamp().

由于提供了驱动程序或已经知道物理地址,所以就完成了.由于分配了物理内存,因此内存是连续的.您必须配置 MMU 以禁用此内存区域的缓存.内存区域将是可DMA的".

Since the driver is provided or knows the physical address already, that's done. Since physical memory was allocated, the memory is therefore contiguous. You will have to configure the MMU to disable caching on this memory region. The memory region will then be "DMAable".

这篇关于Linux下获取缓冲区的物理地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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