On Sun, 26 Aug 2001, Julian Elischer wrote:
> Zhihui Zhang wrote:
> >
> > Thanks for your replay. I use gdb to find out that the buffer address is
> > not 16-byte aligned. This leads to a question as to how to align a
> > statically allocated data structure properly. Using union seems to be able
> > to align you on a long boundary (or even long long?), but that is not 16
> > byte aligned.
> >
> > union {
> > my_data_structure_t xyz;
> > long pad;
> > }
> >
> > The natural alignment seems to work only on primitive data types. If you
> > define:
> >
> > unsigned char sector_buf[512];
> >
> > It will not always be aligned on a 512 byte boundary, even 16-byte
> > alignment is not guaranteed. Is there a way to achieve this?
>
> unfortunatly not, except to allocate N+16 bytes, and allign it yourself by
>
> using a 2nd variable..
>
> x = malloc(buffesize + 16)
> y = x + 15 & ~15
> ...
> write (fd, y, buffersize);
> ...
> free (x);
> exit();
>
>
> You may experiment to see what allignment your hardware needs...
> 2?, 4?, 6?, 16?
>
> when does the message happen?
I believe that message is from ata_dmasetup():
if (((uintptr_t)data & scp->alignment) || (count & scp->alignment)) {
ata_printf(scp, device, "non aligned DMA transfer attempted\n");
return -1;
}
The user address obtained by static allocation is not 16-byte aligned. The
kernel routine physio() grabs a physical buffer to do DMA, but it still
uses the user's address. The KVA associated with the buffer is not used.
-Zhihui
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message