LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 04-26-2012, 08:36 AM   #1
vissu
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
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
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-26-2012, 09:49 AM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,583

Rep: Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558Reputation: 2558
Quote:
Originally Posted by vissu View Post
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.
 
Old 04-27-2012, 08:26 AM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,377

Rep: Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108
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 08:41 AM.
 
2 members found this post helpful.
  


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
[SOLVED] Problems allocating memory in kernel module yaplej Linux - Kernel 1 10-27-2009 11:11 PM
[SOLVED] Kernel Module Allocating memory? yaplej Linux - Kernel 4 10-01-2009 06:19 PM
possible to compile a 32bit kernel on a 64bit os? Shadowmeph Linux - General 5 10-02-2008 06:07 AM
Allocating Memory in the kernel arunachalam Linux - Software 4 10-12-2005 08:51 AM
Allocating memory for user program variable from kernel module appas Programming 2 08-12-2004 10:52 PM


All times are GMT -5. The time now is 03:07 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration