From owner-freebsd-current@FreeBSD.ORG Wed May 27 18:22:32 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 28177106570C for ; Wed, 27 May 2009 18:22:32 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id EEDF68FC1D for ; Wed, 27 May 2009 18:22:31 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id A399746B03; Wed, 27 May 2009 14:22:31 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 9C4438A028; Wed, 27 May 2009 14:22:30 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org Date: Wed, 27 May 2009 13:55:26 -0400 User-Agent: KMail/1.9.7 References: <200905271253.06693.kosmo@semihalf.com> In-Reply-To: <200905271253.06693.kosmo@semihalf.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200905271355.28791.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Wed, 27 May 2009 14:22:30 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Piotr =?utf-8?q?Zi=C4=99cik?= 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 18:22:32 -0000 On Wednesday 27 May 2009 6:53:06 am Piotr Zi=C4=99cik wrote: > While working on bring-up SATA on ARM SoC I had issues with DMA memory=20 > coherency. After tracing, I have found problem in generic ATA code=20 behaviour. >=20 > The ATA generic driver allocates 64k DMA workspace memory which can be=20 > optionally used by ATA chipset drivers. Currently only ata-ahci,=20 ata-marvell,=20 > ata-promise and ata-siliconimage relies on this feature. In general, the= =20 > drivers use preallocated DMA workspace to hold small request descriptors,= =20 > consumed by hardware. >=20 > All of these drivers do not synchronize workspace with bus_dmamap_sync().= =20 They=20 > assumes that DMA workspace is coherent. However ATA driver neither enforc= es=20 > coherency by using BUS_DMA_COHERENT flag nor synchronizes the workspace w= ith=20 > bus_dmamap_sync(). >=20 > I have fixed my problem by adding BUS_DMA_COHERENT flag to workspace=20 > allocation code: >=20 > 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; >=20 > - 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; >=20 > if (bus_dmamap_load(ch->dma.work_tag, ch->dma.work_map, ch->dma.work, >=20 > The question is about multiplatform impact of this change. Especially I a= m=20 > curious how everything works without any problems on i386. The flag has no effect on x86. =2D-=20 John Baldwin