Linux在特定的物理地址分配内存 [英] Linux allocates memory at specific physical address

查看:483
本文介绍了Linux在特定的物理地址分配内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试PCI端点驱动程序,我想从PCI RootPort端到PCI端点端进行简单复制.在PCI端点方面,我们将地址从PCI地址转换为CPU物理地址.我们可以在转换中配置CPU物理地址,以便它映射到特定的DRAM区域.问题是我们如何才能在该特定的CPU物理地址上分配一个内存缓冲区,以确保从RootPort端进行的写操作确实有效?

I am testing a PCI Endpoint driver, I would like to do simple copy from the PCI RootPort side to the PCI Endpoint side. In PCI Endpoint side, we have address translation from PCI address to CPU physical address. We can configure the CPU physical address in the translation so that it maps to the specific DRAM region. The problem is how can we allocate a memory buffer at that specific CPU physical address to make sure the write from RootPort side really works?

任何建议都值得赞赏.非常感谢!

Any recommendations are appreciated. Thanks a lot!

推荐答案

如果您可以即时重新映射翻译,则您应该像使用DMA的任何驱动程序一样工作.您的基本参考是 LDD3第15章,以及 Linux DMA API .

If you can remap the translation on the fly, then you should work like any driver that uses DMA. Your basic reference for this is Chapter 15 of LDD3, plus the Linux DMA API.

您要分配的是通过dma_alloc_coherent的DMA相干缓冲区.在大多数平台上,您应该能够传递空的struct device指针并获取通用的DMA地址.这将为您提供一个内核虚拟地址来访问数据,以及一个dma地址,该地址是要在您的转换层中映射的CPU物理地址.

What you are allocating is a DMA coherent buffer, via dma_alloc_coherent. On most platforms you should be able to pass in a null struct device pointer and get a generic DMA address. This will give you both a kernel virtual address to access the data, and a dma address which is the CPU physical address to map through your translation layer.

如果地址转换不是很灵活,则可能需要修改端点的平台代码以尽早保留此缓冲区,以满足地址对齐要求.这有点复杂,但是有一个 bigphysarea更新补丁最新的内核可能会作为一个起点.

If your address translation is not very flexible, you may need to modify the platform code for your endpoint to reserve this buffer early on, in order to meet address alignment requirements. This is a bit more complicated, but there is an update of the bigphysarea patch to recent kernels that may help as a starting point.

这篇关于Linux在特定的物理地址分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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