From owner-freebsd-current@FreeBSD.ORG Wed May 27 21:33:15 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 09CD71065675 for ; Wed, 27 May 2009 21:33:15 +0000 (UTC) (envelope-from marius@alchemy.franken.de) Received: from alchemy.franken.de (alchemy.franken.de [194.94.249.214]) by mx1.freebsd.org (Postfix) with ESMTP id 7796B8FC1E for ; Wed, 27 May 2009 21:33:14 +0000 (UTC) (envelope-from marius@alchemy.franken.de) Received: from alchemy.franken.de (localhost [127.0.0.1]) by alchemy.franken.de (8.14.3/8.14.3/ALCHEMY.FRANKEN.DE) with ESMTP id n4RLCXCi093754; Wed, 27 May 2009 23:12:35 +0200 (CEST) (envelope-from marius@alchemy.franken.de) Received: (from marius@localhost) by alchemy.franken.de (8.14.3/8.14.3/Submit) id n4RLCXuL093753; Wed, 27 May 2009 23:12:33 +0200 (CEST) (envelope-from marius) Date: Wed, 27 May 2009 23:12:33 +0200 From: Marius Strobl To: Piotr =?unknown-8bit?Q?Zi=EAcik?= Message-ID: <20090527211233.GA93503@alchemy.franken.de> References: <200905271253.06693.kosmo@semihalf.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200905271253.06693.kosmo@semihalf.com> User-Agent: Mutt/1.4.2.3i Cc: freebsd-current@freebsd.org Subject: Re: Generic ATA driver DMA coherency issues X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 May 2009 21:33:15 -0000 On Wed, May 27, 2009 at 12:53:06PM +0200, Piotr Zicik wrote: > While working on bring-up SATA on ARM SoC I had issues with DMA memory > coherency. After tracing, I have found problem in generic ATA code behaviour. > > The ATA generic driver allocates 64k DMA workspace memory which can be > optionally used by ATA chipset drivers. Currently only ata-ahci, ata-marvell, > ata-promise and ata-siliconimage relies on this feature. In general, the > drivers use preallocated DMA workspace to hold small request descriptors, > consumed by hardware. > > All of these drivers do not synchronize workspace with bus_dmamap_sync(). They > assumes that DMA workspace is coherent. However ATA driver neither enforces > coherency by using BUS_DMA_COHERENT flag nor synchronizes the workspace with > bus_dmamap_sync(). > > I have fixed my problem by adding BUS_DMA_COHERENT flag to workspace > allocation code: > > diff --git a/sys/dev/ata/ata-dma.c b/sys/dev/ata/ata-dma.c > index ab4c3c8..71ee41b 100644 > --- a/sys/dev/ata/ata-dma.c > +++ b/sys/dev/ata/ata-dma.c > @@ -95,8 +95,8 @@ ata_dmainit(device_t dev) > 0, NULL, NULL, &ch->dma.work_tag)) > goto error; > > - if (bus_dmamem_alloc(ch->dma.work_tag, (void **)&ch->dma.work, 0, > - &ch->dma.work_map)) > + if (bus_dmamem_alloc(ch->dma.work_tag, (void **)&ch->dma.work, > + BUS_DMA_COHERENT, &ch->dma.work_map)) > goto error; > > if (bus_dmamap_load(ch->dma.work_tag, ch->dma.work_map, ch->dma.work, > > The question is about multiplatform impact of this change. Especially I am > curious how everything works without any problems on i386. > Well, bus_dma.9 documents BUS_DMA_COHERENT to not remove the requirement of using bus_dmamap_sync(), so this would only be a quick hack. The NetBSD version of the man page states the intent of that flag even more clearly. Marius