From owner-freebsd-current@FreeBSD.ORG Fri Feb 23 04:09:28 2007 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 04F7E16A402 for ; Fri, 23 Feb 2007 04:09:28 +0000 (UTC) (envelope-from scottl@samsco.org) Received: from pooker.samsco.org (pooker.samsco.org [168.103.85.57]) by mx1.freebsd.org (Postfix) with ESMTP id A2E1E13C4B2 for ; Fri, 23 Feb 2007 04:09:27 +0000 (UTC) (envelope-from scottl@samsco.org) Received: from phobos.samsco.home (phobos.samsco.home [192.168.254.11]) (authenticated bits=0) by pooker.samsco.org (8.13.4/8.13.4) with ESMTP id l1N49Gv5089006; Thu, 22 Feb 2007 21:09:21 -0700 (MST) (envelope-from scottl@samsco.org) Message-ID: <45DE68D6.80705@samsco.org> Date: Thu, 22 Feb 2007 21:08:54 -0700 From: Scott Long User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.2pre) Gecko/20070111 SeaMonkey/1.1 MIME-Version: 1.0 To: Luigi Rizzo References: <20070219020725.A56400@xorpc.icir.org> In-Reply-To: <20070219020725.A56400@xorpc.icir.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (pooker.samsco.org [168.103.85.57]); Thu, 22 Feb 2007 21:09:21 -0700 (MST) X-Spam-Status: No, score=-1.4 required=3.8 tests=ALL_TRUSTED autolearn=failed version=3.1.1 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on pooker.samsco.org Cc: current@freebsd.org Subject: Re: can a valid bus_dma_tag_t be NULL ? 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: Fri, 23 Feb 2007 04:09:28 -0000 Luigi Rizzo wrote: > I am trying to cleanup some code that allocates dma-able > regions and has to release it in case some of the step > goes wrong. > > The original code (if_iwi.c, but the pattern is repeated in other > drivers too) is the one below. Now, rather than using multiple > labels, is there a value for the various fields (bus_dma_tag_t, > bus_dmamap_t, fw_virtaddr, fw_physaddr) that tells me > that the resource has not been allocated, or i should keep > track of the success/failure of the various calls separately ? > > E.g. i imagine that a NULL fw_virtaddr means failure, however > bus_dmamap_load() worries me because the callback may happen later, > and also i seem to remember that one should not make assumptions > on bus_dma_tag_t == NULL ... > > comments anyone ? And, is -stable different from -current ? > cheers > luigi > There have been a couple of long answers here, so let me give you the short answer as the busdma maintainer. If you call bus_dma_tag_create(), the tag you get back will not be NULL. You can pass a NULL tag as the first parameter to bus_dma_tag_create(), but that only means that the tag you are creating won't inherit any properties and will be created on the face value of the parameters that you give it. The difference between 7-CURRENT and 6-STABLE and prior is that there is now a method to get the busdma tag from the parent bus of the device. This was always the intent of busdma, but it wasn't implemented until recently. You should think of tags as being in a hierarchy that mirrors the bus topology of the system. Certain buses have restrictions that must be communicated down to the device (16MB address limit for ISA, for example), and until now the driver had to guess at what those restrictions are. So, it's OK to pass NULL as the first argument to bus_dma_tag_create, it's just not wise to do anymore and it creates more work and debugging headaches. However, you'll never get back a tag from busdma that evaluates to NULL. busdma maps are a different matter, and can evaluate to NULL on some platforms. However, that is only for SOME PLATFORMS UNDER SOME CIRCUMSTANCES. Drivers should never assume that the map will always be NULL. If you want more info on how maps work, let me know. Scott