LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Urgent: Allocating 64bit aligned address memory in a 32bit kernel (https://www.linuxquestions.org/questions/linux-kernel-70/urgent-allocating-64bit-aligned-address-memory-in-a-32bit-kernel-941850/)

vissu 04-26-2012 08:36 AM

Urgent: Allocating 64bit aligned address memory in a 32bit kernel
 
Hi,

I got a Linux 32bit Machine with ubuntu 10.04, 2.6-32.33 kernel.

I got a device connected to PCIe bus. I need to allocate memory and fill in the HW registers, but the device expects 64-bit alligned address.

I used dma_allo_coherent, it gives 32bit aligned address but cannot assure about 64-bit alignment.

Can anyone help on this.

Thanx

TB0ne 04-26-2012 09:49 AM

Quote:

Originally Posted by vissu (Post 4663539)
Hi,
I got a Linux 32bit Machine with ubuntu 10.04, 2.6-32.33 kernel. I got a device connected to PCIe bus. I need to allocate memory and fill in the HW registers, but the device expects 64-bit alligned address. I used dma_allo_coherent, it gives 32bit aligned address but cannot assure about 64-bit alignment.

First, this is NOT URGENT for ANYONE here. If you want "urgent" help, pay for tech support from Red Hat or SuSE. We volunteer our time here, so don't expect everyone to hurry and help you, because you mark threads *urgent*.

Second, did you read what you posted? You've got a 32 bit machine, with a 32 bit kernel...but you're expecting it to do 64 bits? Also, it would help if you told us WHAT device you're plugging in, and show us your code. We can't guess.

sundialsvcs 04-27-2012 08:26 AM

It's actually relatively easy to get aligned-addresses: it can be done with a simple #define macro, or tiny function, that is applied to the address that you obtain from calloc().

Request, say, 128 bytes more than you need. Take the address you've received, add 64, then mask-off the lower bits.

What you've done is located an aligned area of memory within a larger area that you obtained, which is large enough to contain it.

(I suggest using a memory-allocation function that always returns memory that is known-zero, just as a matter of course. And for what it's worth, when allocating a buffer for use by anyone, I always allocate "a little more than I need," because not-quite tested algorithms often munge a few bytes beyond the end, and scribbling on the pointer structures used by the memory-allocator never fails to come to grief.)

You'll need to remember what the original address is, and release that address. But that's not hard to do if you've got a define-macro to use to send the desired address from it.

This principle applies equally to kernel and to non-kernel programming.


All times are GMT -5. The time now is 08:01 PM.