本文介绍了在Linux中将kmalloc与GFP_DMA一起使用时,为什么得到高地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Linux中的DMA设备编写设备驱动程序.在Linux设备驱动程序,第15章,它说:

I am writing a device driver for a DMA device in Linux. In Linux Device Drivers, Chapter 15, it says:

我这样呼叫 kmalloc :

physical_pointer0 = kmalloc(number_of_bytes, GFP_DMA);

并打印如下结果:

  printk(KERN_INFO "pinmem:pinmen_write kmalloc succeeded.  pointer is %p, buffer size is %d\n", physical_pointer0, (unsigned)number_of_bytes);

这就是我所看到的:

Sep  9 00:29:45 nfellman_lnx kernel: [  112.161744] pinmem:pinmen_write kmalloc succeeded.  pointer is ffff880000180000, buffer size is 320800

如果我使用的是GFP_DMA,如何获取不适合24位的 0xffff880000180000 的指针?

How can I be getting a pointer to 0xffff880000180000, which doesn't fit in 24 bits, if I used GFP_DMA?

这可能不是我的内存块的物理地址吗?如果没有(那意味着我完全误解了 kmalloc ),如何获取其物理地址?

Could it be that this is not the physical address of my block of memory? If not (which would mean I'm completely misunderstanding kmalloc), how can I get its physical address?

我正在OpenSuse 12中工作.

I am working in OpenSuse 12.

推荐答案

答案似乎是 kmalloc 实际上并不返回物理指针,而是线性指针,我必须使用 virt_to_phys 转换为物理.

The answer to this appears to be that kmalloc doesn't in fact return a physical pointer, but rather a linear pointer, that I must convert to physical with virt_to_phys.

感谢 Alex Brown 提供了答案此处.

这篇关于在Linux中将kmalloc与GFP_DMA一起使用时,为什么得到高地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 08:35