From owner-freebsd-hackers@FreeBSD.ORG Wed Oct 26 15:46:49 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 0B4CC16A41F for ; Wed, 26 Oct 2005 15:46:49 +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 928A443D45 for ; Wed, 26 Oct 2005 15:46:48 +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 ; Wed, 26 Oct 2005 12:03:33 -0400 From: John Baldwin To: freebsd-hackers@freebsd.org Date: Wed, 26 Oct 2005 11:30:44 -0400 User-Agent: KMail/1.8.2 References: <435EEC56.9080708@samsco.org> <435F428E.50609@alphaque.com> In-Reply-To: <435F428E.50609@alphaque.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510261130.45506.jhb@freebsd.org> Cc: Scott Long Subject: Re: [Fwd: Re: 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: Wed, 26 Oct 2005 15:46:49 -0000 On Wednesday 26 October 2005 04:47 am, Dinesh Nair wrote: > On 10/26/05 10:39 Scott Long said the following: > > Apparently the original poster sent his question to me in private, then > > sent it again to the mailing list right as I was responding in private. > > apologies on that, scott. an initial search only turned up your message in > the archives, but spreading it wider (not confining the google to > lists.freebsd.org) brought up more hits, and that made me post it into > -hackers. > > do bear with me as i try to understand this. > > > Below is my response. Note that I edited it slightly to fix an error > > that I found > > > > bus_dmamap_sync(tag, map, BUS_DMASYNC_PREREAD); > > Ask hardware for data > > bus_dmamap_sync(tag, map, BUS_DMASYNC_POSTREAD); > > > >> read from readbuf (i'm assuming that device has put data in > >> readbuf) > >> POSITION B > >> } > > in other words, the PREREAD/POSTREAD wrap around the device's access to > memory, and not the CPU's ? Yes, scott's notes are more correct than mine here. > > bus_dmamap_sync(tag, map, BUS_DMASYNC_PREWRITE); > > notify hardware of the write > > bus_dmamap_sync(tag, map, BUS_DMASYNC_POSTWRITE); > > > > The point of the syncs is to do the proper memory barrier and cache > > coherency magic between the CPU and the bus as well as do the memory > > copies for bounce buffers. If you are dealing with statically mapped > > buffers, i.e. for an rx/tx descriptor ring, then you'll want code > > however, reading thru the syscall code, bus_dmamem_alloc() sets the dmamap > to NULL, and if it's null, bus_dmamap_sync() is not called at all. would > this mean that if memory is allocated by bus_dmamem_alloc(), it does not > need to be synced with bus_dmamap_sync() ? Perhaps on i386. Each arch implements sync(). Argh, it does look like the memory barriers needed on e.g., Alpha aren't used with static buffers because of the map != NULL check in sys/busdma.h. *sigh* I guess archs that need membars even without bounce buffers need to always allocate and setup a bus_dmamap. None of that matters for i386 though. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org