ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2019-11-27 17:51:35  阅读:1662  来源: 互联网

标签:dma opensuse kmalloc linux


我正在为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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有