From owner-freebsd-current@FreeBSD.ORG Wed May 27 11:31:04 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 BEA881065676 for ; Wed, 27 May 2009 11:31:04 +0000 (UTC) (envelope-from kosmo@semihalf.com) Received: from semihalf.com (semihalf.com [206.130.101.55]) by mx1.freebsd.org (Postfix) with ESMTP id 85AC48FC18 for ; Wed, 27 May 2009 11:31:04 +0000 (UTC) (envelope-from kosmo@semihalf.com) Received: from mail.semihalf.com (mail.semihalf.com [83.15.139.206]) by semihalf.com (8.13.1/8.13.1) with ESMTP id n4RAr7ar009389 for ; Wed, 27 May 2009 04:53:08 -0600 From: Piotr =?iso-8859-2?q?Zi=EAcik?= Organization: Semihalf To: freebsd-current@freebsd.org Date: Wed, 27 May 2009 12:53:06 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200905271253.06693.kosmo@semihalf.com> Subject: 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 11:31:05 -0000 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. -- Best Regards. Piotr Ziecik.