From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 25 17:31:24 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CA0C416A41F for ; Tue, 25 Oct 2005 17:31:24 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id B227D43D67 for ; Tue, 25 Oct 2005 17:31:22 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from [10.50.41.234] (Not Verified[10.50.41.234]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Tue, 25 Oct 2005 13:48:05 -0400 From: John Baldwin To: freebsd-hackers@freebsd.org Date: Tue, 25 Oct 2005 13:27:59 -0400 User-Agent: KMail/1.8.2 References: <435E3003.4050609@alphaque.com> In-Reply-To: <435E3003.4050609@alphaque.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510251327.59965.jhb@freebsd.org> Cc: Subject: Re: correct use of bus_dmamap_sync X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Oct 2005 17:31:24 -0000 On Tuesday 25 October 2005 09:15 am, Dinesh Nair wrote: > i came across this message > http://lists.freebsd.org/pipermail/freebsd-current/2004-December/044395.htm >l > > and while it explains the use of bus_dmamap_sync, i'm still a little > confused on it's usage. i'm trying to port over a driver from freebsd 5.x > to freebsd 4.x, and it uses dma mapped addresses extensively. > > i've been trying to figure out the best places to use bus_dmamap_sync when > reading/writing to a dma mapped address space. however, i cant seem to get > the gist of this, either from the mailing list discussions or the man page. > > i've got two buffers, one for read, and one for write. both have been set > up with calls to bus_dma_tag_create, bus_dmamem_alloc and bus_dmamap_load. > > the buffers, which are used in the calls to bus_dmamem_alloc and > bus_dmamap_load are, > > int *readbuf; > int *writebuf; > > (must i malloc space for them before passing them into those functions, or > will the call to bus_dmamem_alloc do it for me ?) bus_dmamem_alloc() will do it for you. > also, i'm on FreeBSD 4.11 right now, and i notice the definitions of > BUS_DMASYNC_* has changed from an enum (0-3) in 4.x to a typedef in 5.x in > machine/bus_dma.h > > the pseudo code for the read and write, called during an interrupt cycle, > are: > > rx_func() > { > POSITION A bus_dmamap_sync(PREREAD); > while(there_is_some_data) { > memcpy(somebuf, readbuf) > } > POSITION B bus_dmamap_sync(POSTREAD); > } > > tx_func() > { > POSITION C bus_dmamap_sync(PREWRITE); > while(there_is_some_data) { > memcpy(writebuf, somebuf) > } > POSITION D bus_dmamap_sync(POSTWRITE); > } > > the question is, what op should i use for bus_dmamap_sync in positions A, > B, C and D ? > > any assistance would be gladly appreciated, as i'm seeing some really weird > symptoms on this device, where data written out is being immediately read > in. i'm guessing this has to do with my wrong usage of bus_dmamap_sync(). Probably not as the sync()'s don't really do anything with memory allocated via bus_dmamem_alloc(). The operations are named from the CPU's perspective, thus when you send data to your device, that is a WRITE operation (even though your device is doing a DMA to read data), and when you get data back from your device, that is a READ operation (even though your device is doing a DMA to write the data into the buffer). -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org