Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Jan 2015 20:35:09 +0000
From:      =?utf-8?Q?SalvageDrive.com?= <info@salvagedrive.com>
To:        =?utf-8?Q??= <arch@freebsd.org>
Subject:   =?utf-8?Q?Cars=20Cars=20Cars?=
Message-ID:  <38668d8a390eaafe346aac8d5c538f13530.20150129203500@mail54.atl51.rsgsv.net>

index | next in thread | raw e-mail

https://www.salvagedrive.com


** Special Deals from Salvage Drive
------------------------------------------------------------

TOP 5 REASONS TO BUY FROM
SALVAGE DRIVE:

1. Free and Easy Registration
2. Best Customer Service in the industry
3. Lowest fees on the market
4. We Ship Worldwide
5. Free Storage for International Shipping

NO AUCTION FEE DEALS!!! (https://www.salvagedrive.com)


** 2004 LEXUS RX 330
------------------------------------------------------------
Clean Title
170,451 miles
$7,400
https://www.salvagedrive.com/Cars/Category?SysId=901024315
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901024315)


** 2005 TOYOTA COROLLA
------------------------------------------------------------
Clean Title
131,459 miles
$3,800
https://www.salvagedrive.com/Cars/Category?SysId=900002667
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=900002667)


** 2005 TOYOTA CAMRY
------------------------------------------------------------
Clean Title
184,864 miles
$4,255
https://www.salvagedrive.com/Cars/Category?SysId=901020825
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901020825)


** 2012 Honda Accord
------------------------------------------------------------
Rebuilt Title
25,500 miles
$9,900
https://www.salvagedrive.com/Cars/Category?SysId=901024320
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901024320)


** 2005 LEXUS RX 330
------------------------------------------------------------
Clean Title
98,145 miles
$8,700
https://www.salvagedrive.com/Cars/Category?SysId=901024316
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901024316)


** 2006 TOYOTA COROLLA
------------------------------------------------------------
Clean Title
93,752 miles
$4,150
https://www.salvagedrive.com/Cars/Category?SysId=900002690
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=900002690)


** 2006 TOYOTA CAMRY
------------------------------------------------------------
Clean Title
237,267 miles
$3,795
https://www.salvagedrive.com/Cars/Category?SysId=901020293
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901020293)


** 2006 NISSAN MURANO
------------------------------------------------------------
Clean Title
122,700 miles
$4,999
https://www.salvagedrive.com/Cars/Category?SysId=901024319
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901024319)


** 2006 LEXUS RX 330
------------------------------------------------------------
Clean Title
184,841 miles
$9,800
https://www.salvagedrive.com/Cars/Category?SysId=901024317
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901024317)


** 2007 TOYOTA COROLLA
------------------------------------------------------------
Clean Title
107,474 miles
$6,380
https://www.salvagedrive.com/Cars/Category?SysId=901019125
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901019125)


** 2007 TOYOTA CAMRY
------------------------------------------------------------
Clean Title
124,800 miles
$7,800
https://www.salvagedrive.com/Cars/Category?SysId=900002666
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=900002666)


** 2008 TOYOTA TACOMA
------------------------------------------------------------
Clean Title
189,341 miles
$7,950
https://www.salvagedrive.com/Cars/Category?SysId=901024318
CLICK FOR MORE INFO (https://www.salvagedrive.com/Cars/Category?SysId=901024318)

============================================================
** LET US SEARCH FOR YOU! TELL US WHAT YOU ARE LOOKING FOR AND OUR EXPERTS WILL SEARCH FOR YOU BASED ON YOUR SPECIFIC BUDGET AND REQUIREMENTS. (https://www.salvagedrive.com)
** (https://www.salvagedrive.com)

** SalvageDrive.com (https://www.salvagedrive.com)
1-844-227-7411 Toll Free

1-347-492-1727 Tel.

Skype: salvagedrive

** info@SalvageDrive.com (mailto:info@SalvageDrive.com)

Don't forget to add info@salvagedrive.com to your Address Book to keep it from skipping your inbox or getting caught in spam filters.

We want your experience with the Salvage Drive to be as smooth and reassuring as possible. Accordingly, we diligently safeguard your privacy. If you wish to review our Privacy Policy at any time, please click on the link below, or copy and paste it into your web browser's location window
** Salvage Drive Privacy Policy (http://sdimages.salvagedrive.com/salvagedrive/PrivacyPolicy.pdf)
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

You can choose to unsubscribe from our Email Newsletters service by replying to this email with the word "STOP" and we will remove you from any future mailings.
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

© 2014 SalvageDrive, Inc.   |   All rights reserved
Salvage Drive, Inc. | 217 Broadway | Suite 505 | New York | NY | 10007

This email was sent to arch@freebsd.org (mailto:arch@freebsd.org)
why did I get this? (http://salvagedrive.us8.list-manage.com/about?u=38668d8a390eaafe346aac8d5&id=b173b821c7&e=c538f13530&c=b20b661509)     unsubscribe from this list (http://salvagedrive.us8.list-manage.com/unsubscribe?u=38668d8a390eaafe346aac8d5&id=b173b821c7&e=c538f13530&c=b20b661509)     update subscription preferences (http://salvagedrive.us8.list-manage.com/profile?u=38668d8a390eaafe346aac8d5&id=b173b821c7&e=c538f13530)
Salvage Drive, Inc. · 217 Broadway · Suite 505 · New York, NY 10007 · USA
From owner-freebsd-arch@FreeBSD.ORG  Thu Jan 29 21:04:23 2015
Return-Path: <owner-freebsd-arch@FreeBSD.ORG>
Delivered-To: freebsd-arch@freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by hub.freebsd.org (Postfix) with ESMTPS id 2480B514
 for <freebsd-arch@freebsd.org>; Thu, 29 Jan 2015 21:04:23 +0000 (UTC)
Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1])
 (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id D69869C8
 for <freebsd-arch@freebsd.org>; Thu, 29 Jan 2015 21:04:22 +0000 (UTC)
Received: from ralph.baldwin.cx (pool-173-70-85-31.nwrknj.fios.verizon.net
 [173.70.85.31])
 by bigwig.baldwin.cx (Postfix) with ESMTPSA id AD060B96C
 for <freebsd-arch@freebsd.org>; Thu, 29 Jan 2015 16:04:21 -0500 (EST)
From: John Baldwin <jhb@freebsd.org>
To: 'freebsd-arch' <freebsd-arch@freebsd.org>
Subject: Wrapper API for static bus_dma allocations
Date: Thu, 29 Jan 2015 15:37:19 -0500
Message-ID: <2800970.jY4xzTy9Hz@ralph.baldwin.cx>
User-Agent: KMail/4.14.2 (FreeBSD/10.1-STABLE; KDE/4.14.2; amd64; ; )
MIME-Version: 1.0
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="us-ascii"
X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7
 (bigwig.baldwin.cx); Thu, 29 Jan 2015 16:04:21 -0500 (EST)
X-BeenThere: freebsd-arch@freebsd.org
X-Mailman-Version: 2.1.18-1
Precedence: list
List-Id: Discussion related to FreeBSD architecture <freebsd-arch.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/options/freebsd-arch>,
 <mailto:freebsd-arch-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-arch/>;
List-Post: <mailto:freebsd-arch@freebsd.org>
List-Help: <mailto:freebsd-arch-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-arch>,
 <mailto:freebsd-arch-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 29 Jan 2015 21:04:23 -0000

The bus_dma API to allocate a chunk of static DMA'able memory (e.g. for
descriptor rings) can be a bit obtuse to use in that it require a bit of
boilerplate to create a tag, allocate memory for the tag, then load it to get
the bus address.  Similarly, freeing it also requires several steps.  In
addition, some of the steps are a bit subtle (e.g. the need to check for an
error in the bus_dma callback instead of from bus_dmamap_load()) and not all
drivers get those correct.

To try to make this simpler I've written a little wrapper API that tries to
provide a single call to allocate a buffer and a single call to free a buffer.
Each buffer is described by a structure defined by the API, and if the call to
allocate a buffer succeeds, the structure contains both a pointer to the
buffer in the kernel's address space as well as a bus address of the buffer.

In the interests of simplicity, this API does not allow the buffer to be quite
as fully configured as the underlying bus_dma API, instead it aims to handle
the most common cases that are used in most drivers.  As such, it assumes that
the buffer must be one contiguous range of DMA address space, and the only
parameters that can be specified are the parent tag, the alignment of the
buffer, the lowaddr parameter, the size of the buffer to allocate, and the
flags parameter that is normally passed to bus_dmamem_alloc().  I believe that
this should be sufficient to cover the vast majority of the drivers in our
tree.

I've included below a patch that contains the wrapper API along with a sample
conversion of the ndis driver (chosen at random).  If folks like this idea I
will update the patch to include manpage changes as well.

--- //depot/vendor/freebsd/src/sys/compat/ndis/subr_ndis.c
+++ //depot/user/jhb/cleanup/sys/compat/ndis/subr_ndis.c
@@ -186,7 +186,6 @@
 static ndis_status NdisMAllocateMapRegisters(ndis_handle,
 	uint32_t, uint8_t, uint32_t, uint32_t);
 static void NdisMFreeMapRegisters(ndis_handle);
-static void ndis_mapshared_cb(void *, bus_dma_segment_t *, int, int);
 static void NdisMAllocateSharedMemory(ndis_handle, uint32_t,
 	uint8_t, void **, ndis_physaddr *);
 static void ndis_asyncmem_complete(device_object *, void *);
@@ -1387,23 +1386,6 @@
 	bus_dma_tag_destroy(sc->ndis_mtag);
 }

-static void
-ndis_mapshared_cb(arg, segs, nseg, error)
-	void			*arg;
-	bus_dma_segment_t	*segs;
-	int			nseg;
-	int			error;
-{
-	ndis_physaddr		*p;
-
-	if (error || nseg > 1)
-		return;
-
-	p = arg;
-
-	p->np_quad = segs[0].ds_addr;
-}
-
 /*
  * This maps to bus_dmamem_alloc().
  */
@@ -1443,35 +1425,17 @@
 	 * than 1GB of physical memory.
 	 */

-	error = bus_dma_tag_create(sc->ndis_parent_tag, 64,
-	    0, NDIS_BUS_SPACE_SHARED_MAXADDR, BUS_SPACE_MAXADDR, NULL,
-	    NULL, len, 1, len, BUS_DMA_ALLOCNOW, NULL, NULL,
-	    &sh->ndis_stag);
+	error = bus_dma_mem_create(&sh->ndis_mem, sc->ndis_parent_tag, 64,
+	    NDIS_BUS_SPACE_SHARED_MAXADDR, len, BUS_DMA_NOWAIT | BUS_DMA_ZERO);

 	if (error) {
 		free(sh, M_DEVBUF);
 		return;
 	}

-	error = bus_dmamem_alloc(sh->ndis_stag, vaddr,
-	    BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sh->ndis_smap);
-
-	if (error) {
-		bus_dma_tag_destroy(sh->ndis_stag);
-		free(sh, M_DEVBUF);
-		return;
-	}
+	*vaddr = sh->ndis_mem.dma_vaddr;
+	paddr->np_quad = sh->ndis_mem.dma_baddr;

-	error = bus_dmamap_load(sh->ndis_stag, sh->ndis_smap, *vaddr,
-	    len, ndis_mapshared_cb, (void *)paddr, BUS_DMA_NOWAIT);
-
-	if (error) {
-		bus_dmamem_free(sh->ndis_stag, *vaddr, sh->ndis_smap);
-		bus_dma_tag_destroy(sh->ndis_stag);
-		free(sh, M_DEVBUF);
-		return;
-	}
-
 	/*
 	 * Save the physical address along with the source address.
 	 * The AirGo MIMO driver will call NdisMFreeSharedMemory()
@@ -1482,8 +1446,6 @@
 	 */

 	NDIS_LOCK(sc);
-	sh->ndis_paddr.np_quad = paddr->np_quad;
-	sh->ndis_saddr = *vaddr;
 	InsertHeadList((&sc->ndis_shlist), (&sh->ndis_list));
 	NDIS_UNLOCK(sc);
 }
@@ -1581,13 +1543,13 @@
 	l = sc->ndis_shlist.nle_flink;
 	while (l != &sc->ndis_shlist) {
 		sh = CONTAINING_RECORD(l, struct ndis_shmem, ndis_list);
-		if (sh->ndis_saddr == vaddr)
+		if (sh->ndis_mem.dma_vaddr == vaddr)
 			break;
 		/*
 		 * Check the physaddr too, just in case the driver lied
 		 * about the virtual address.
 		 */
-		if (sh->ndis_paddr.np_quad == paddr.np_quad)
+		if (sh->ndis_mem.dma_baddr == paddr.np_quad)
 			break;
 		l = l->nle_flink;
 	}
@@ -1604,9 +1566,7 @@

 	NDIS_UNLOCK(sc);

-	bus_dmamap_unload(sh->ndis_stag, sh->ndis_smap);
-	bus_dmamem_free(sh->ndis_stag, sh->ndis_saddr, sh->ndis_smap);
-	bus_dma_tag_destroy(sh->ndis_stag);
+	bus_dma_mem_free(&sh->ndis_mem);

 	free(sh, M_DEVBUF);
 }
--- //depot/vendor/freebsd/src/sys/dev/if_ndis/if_ndisvar.h
+++ //depot/user/jhb/cleanup/sys/dev/if_ndis/if_ndisvar.h
@@ -66,10 +66,7 @@

 struct ndis_shmem {
 	list_entry		ndis_list;
-	bus_dma_tag_t		ndis_stag;
-	bus_dmamap_t		ndis_smap;
-	void			*ndis_saddr;
-	ndis_physaddr		ndis_paddr;
+	struct bus_dmamem	ndis_mem;
 };

 struct ndis_cfglist {
--- //depot/vendor/freebsd/src/sys/kern/subr_bus_dma.c
+++ //depot/user/jhb/cleanup/sys/kern/subr_bus_dma.c
@@ -540,3 +540,66 @@

 	return (0);
 }
+
+struct bus_dma_mem_cb_data {
+	struct bus_dmamem *mem;
+	int	error;
+};
+
+static void
+bus_dma_mem_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
+{
+	struct bus_dma_mem_cb_data *d;
+
+	d = arg;
+	d->error = error;
+	if (error)
+		return;
+	d->mem->dma_baddr = segs[0].ds_addr;
+}
+
+int
+bus_dma_mem_create(struct bus_dmamem *mem, bus_dma_tag_t parent,
+    bus_size_t alignment, bus_addr_t lowaddr, bus_size_t len, int flags)
+{
+	struct bus_dma_mem_cb_data d;
+	int error;
+
+	bzero(mem, sizeof(*mem));
+	error = bus_dma_tag_create(parent, alignment, 0, lowaddr,
+	    BUS_SPACE_MAXADDR, NULL, NULL, len, 1, len, 0, NULL, NULL,
+	    &mem->dma_tag);
+	if (error) {
+		bus_dma_mem_free(mem);
+		return (error);
+	}
+	error = bus_dmamem_alloc(mem->dma_tag, &mem->dma_vaddr, flags,
+	    &mem->dma_map);
+	if (error) {
+		bus_dma_mem_free(mem);
+		return (error);
+	}
+	d.mem = mem;
+	error = bus_dmamap_load(mem->dma_tag, mem->dma_map, mem->dma_vaddr, len,
+	    bus_dma_mem_cb, &d, BUS_DMA_NOWAIT);
+	if (error == 0)
+		error = d.error;
+	if (error) {
+		bus_dma_mem_free(mem);
+		return (error);
+	}
+	return (0);
+}
+
+void
+bus_dma_mem_free(struct bus_dmamem *mem)
+{
+
+	if (mem->dma_baddr != 0)
+		bus_dmamap_unload(mem->dma_tag, mem->dma_map);
+	if (mem->dma_vaddr != NULL)
+		bus_dmamem_free(mem->dma_tag, mem->dma_vaddr, mem->dma_map);
+	if (mem->dma_tag != NULL)
+		bus_dma_tag_destroy(mem->dma_tag);
+	bzero(mem, sizeof(*mem));
+}
--- //depot/vendor/freebsd/src/sys/sys/bus_dma.h
+++ //depot/user/jhb/cleanup/sys/sys/bus_dma.h
@@ -337,4 +337,29 @@

 #endif /* __sparc64__ */

+/*
+ * A wrapper API to simplify management of static mappings.
+ */
+
+struct bus_dmamem {
+	bus_dma_tag_t	dma_tag;
+	bus_dmamap_t	dma_map;
+	void		*dma_vaddr;
+	bus_addr_t	dma_baddr;
+};
+
+/*
+ * Allocate a mapping.  On success, zero is returned and the 'dma_vaddr'
+ * and 'dma_baddr' fields are populated with the virtual and bus addresses,
+ * respectively, of the mapping.
+ */
+int bus_dma_mem_create(struct bus_dmamem *mem, bus_dma_tag_t parent,
+		       bus_size_t alignment, bus_addr_t lowaddr,
+		       bus_size_t len, int flags);
+
+/*
+ * Release a mapping created by bus_dma_mem_create().
+ */
+void bus_dma_mem_free(struct bus_dmamem *mem);
+
 #endif /* _BUS_DMA_H_ */


--
John Baldwin


help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?38668d8a390eaafe346aac8d5c538f13530.20150129203500>