Urgent: Allocating 64bit aligned address memory in a 32bit kernel
Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.
Last edited by sundialsvcs; 04-27-2012 at 09:41 AM.