문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top