Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Feb 2007 21:08:54 -0700
From:      Scott Long <scottl@samsco.org>
To:        Luigi Rizzo <rizzo@icir.org>
Cc:        current@freebsd.org
Subject:   Re: can a valid bus_dma_tag_t be NULL ?
Message-ID:  <45DE68D6.80705@samsco.org>
In-Reply-To: <20070219020725.A56400@xorpc.icir.org>
References:  <20070219020725.A56400@xorpc.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45DE68D6.80705>