在Linux中将kmalloc与GFP_DMA一起使用时,为什么得到高地址? [英] Why am I getting a high address when I use kmalloc with GFP_DMA in Linux?
问题描述
我正在为Linux中的DMA设备编写设备驱动程序.在Linux设备驱动程序,第15章,它说:
I am writing a device driver for a DMA device in Linux. In Linux Device Drivers, Chapter 15, it says:
对于具有此类限制的设备,应分配内存通过将GFP_DMA标志添加到kmalloc来从DMA区域中删除get_free_pages调用.存在此标志时,只有可以被分配24位地址.或者,您可以使用通用DMA层(我们稍后将讨论)来分配缓冲区解决设备的限制
For devices with this kind of limitation, memory should be allocated from the DMA zone by adding the GFP_DMA flag to the kmalloc or get_free_pages call. When this flag is present, only memory that can be addressed with 24 bits is allocated. Alternatively, you can use the generic DMA layer (which we discuss shortly) to allocate buffers that work around your device’s limitations
我这样呼叫 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 提供了答案 查看全文