Why am I getting a high address when I use kmalloc with GFP_DMA in Linux?

二次信任 提交于 2019-12-07 15:37:40

问题


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

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

I am calling kmalloc like this:

physical_pointer0 = kmalloc(number_of_bytes, GFP_DMA);

and printing the result like this:

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

And this is what I see:

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

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

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?


I am working in OpenSuse 12.


回答1:


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.

Thanks to Alex Brown for providing the answer here.



来源:https://stackoverflow.com/questions/12337914/why-am-i-getting-a-high-address-when-i-use-kmalloc-with-gfp-dma-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!