系统相关
首页 > 系统相关> > 在Linux中将kmalloc与GFP_DMA一起使用时,为什么获得高地址?

在Linux中将kmalloc与GFP_DMA一起使用时,为什么获得高地址?

作者:互联网

我正在为Linux中的DMA设备编写设备驱动程序.在Linux Device Drivers, Chapter 15中,它表示:

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的指针?

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

我在OpenSuse 12中工作.

解决方法:

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

感谢Alex Brown提供了答案here.

标签:dma,opensuse,kmalloc,linux
来源: https://codeday.me/bug/20191127/2075993.html