LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 09-03-2015, 12:35 PM   #1
bluebit
LQ Newbie
 
Registered: Sep 2015
Posts: 1

Rep: Reputation: Disabled
Allocate physical memory buffer for ARM64 Linux Device Driver (without DMA support)


Hi,

I have to implement an ARM64 Linux driver for a device that needs to work with physical memory buffers and that doesn't support DMA (nor IOMMU).

My first attempt was to allocate the buffers with kmalloc, use the returned vaddr virtual address in the driver and send the paddr physical address obtained after a virt_to_phys(vaddr) translation to the device. I understand that (in general) this is not be the best approach, since the device might only know its bus-specific addresses. But my problem is that the paddr address returned by
virt_to_phys(vaddr) isn't the same as the one listed in the PageTable for vaddr, so the device couldn't use it either (the virt_to_phys value looks like a shifted version of the real physical
address).

What worked for me was using the DMA mapping API (e.g. dma_alloc_coherent), but I'm not sure if this is the best approach, since the device module doesn't support DMA. The same question for dma_map_single function for temporary allocations.

Another option would be to pre-allocate a memory range (e.g. using a reserved-memory node in the device tree file) and ioremap it in the driver, but I'm not sure if that's OK either. Some of the buffers are only needed temporary (while the device is processing a command) and their size is variable (could get quite large). So, in this case, a
dynamic allocation might be better.

Any idea what would be the best memory management approach (practice) for this case? Also, why would virt_to_phys called over a kmalloc address not return the correct physical address?

Any help is appreciated.
 
Old 09-04-2015, 10:49 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,179

Rep: Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272Reputation: 1272
If the device doesn't support DMA, then why does it need an address?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to allocate LARGE (more than 16M) DMA memory? leechaotang Linux - Kernel 3 10-05-2011 06:04 AM
Allocate and use DMA buffer orback Linux - Kernel 1 03-09-2010 03:01 AM
How to allocate DMA-eable memory from Userland nizamy Programming 2 10-14-2006 02:15 AM
NVidia: Failed to allocate frame buffer context DMA Sulu Linux - Hardware 0 11-29-2004 08:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 10:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration