From owner-freebsd-hackers Mon Aug 27 7:22:57 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from bingnet2.cc.binghamton.edu (bingnet2.cc.binghamton.edu [128.226.1.18]) by hub.freebsd.org (Postfix) with ESMTP id 06CAD37B405 for ; Mon, 27 Aug 2001 07:22:46 -0700 (PDT) (envelope-from zzhang@cs.binghamton.edu) Received: from onyx (onyx.cs.binghamton.edu [128.226.140.171]) by bingnet2.cc.binghamton.edu (8.11.4/8.11.4) with ESMTP id f7REMho28881; Mon, 27 Aug 2001 10:22:43 -0400 (EDT) Date: Mon, 27 Aug 2001 10:21:40 -0400 (EDT) From: Zhihui Zhang X-Sender: zzhang@onyx To: Julian Elischer Cc: freebsd-hackers@freebsd.org Subject: Re: ata0-master: non aligned DMA transfer attempted In-Reply-To: <3B8942DB.A242B58C@elischer.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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