Date: Mon, 27 Aug 2001 10:21:40 -0400 (EDT) From: Zhihui Zhang <zzhang@cs.binghamton.edu> To: Julian Elischer <julian@elischer.org> Cc: freebsd-hackers@freebsd.org Subject: Re: ata0-master: non aligned DMA transfer attempted Message-ID: <Pine.SOL.4.21.0108271015520.14303-100000@onyx> In-Reply-To: <3B8942DB.A242B58C@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SOL.4.21.0108271015520.14303-100000>