[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: qword aligned address



1. The most straight-forward would be to use vmalloc()/kmalloc() with some
extra "head room":

char
	*ptr,
	*ptr0;

ptr0 = ptr = kmalloc( nsize + 4*4, GFP_KERNEL | __GFP_DMA );

if( ptr % 4*4 )
{
	ptr /= 4*4;
	ptr *= 4*4;
}

Now ptr is qword (16 byte) aligned.  Remember that you'll need to call
kfree()/vfree() on ptr0, not ptr!

2. If you are performing a large quantity of DMA then you might look into
using the functions:

__get_free_page(), __get_free_pages(), __get_dma_pages()

Once again, Runbini's book "Linux Device Drivers", published by O'Reilly has
several chapters on the subject of  memory and DMA.

Nat

-----Original Message-----
From: Oliver Ryan [mailto:oryan@physics.nuigalway.ie]
Sent: Wednesday, July 18, 2001 11:08 AM
To: 'kernelnewbies@nl.linux.org'
Subject: qword aligned address


Hi,
I hope this is the right place for this question -- if not sorry, and 
please forget about it.

I'm setting up scatter/gather dma for a PCI device.  The device requires to 
be passed a  descriptor (which will be of type struct containing 4 
integers), the address of which needs to be q-word aligned.  How do I 
declare the descriptor to make sure its address is qword aligned?

Thanks in advance.

Oliver.

Dept. of Physics,
National University of Ireland, Galway,
Galway,
Ireland.

Tel: +353 (0)91 524411 ext. 2716
Fax: +353 (0)91 750584
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/