Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Jul 2009 23:29:59 +0000 (UTC)
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r195983 - projects/mips/sys/mips/mips
Message-ID:  <200907302329.n6UNTxCi049063@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gonzo
Date: Thu Jul 30 23:29:59 2009
New Revision: 195983
URL: http://svn.freebsd.org/changeset/base/195983

Log:
  - mark map as coherent if requested by flags
  - explicitly set memory allocation method in map flags instead
      of duplicating conditions for malloc/contigalloc

Modified:
  projects/mips/sys/mips/mips/busdma_machdep.c

Modified: projects/mips/sys/mips/mips/busdma_machdep.c
==============================================================================
--- projects/mips/sys/mips/mips/busdma_machdep.c	Thu Jul 30 21:51:07 2009	(r195982)
+++ projects/mips/sys/mips/mips/busdma_machdep.c	Thu Jul 30 23:29:59 2009	(r195983)
@@ -123,9 +123,11 @@ SYSCTL_INT(_hw_busdma, OID_AUTO, total_b
 #define DMAMAP_LINEAR		0x1
 #define DMAMAP_MBUF		0x2
 #define DMAMAP_UIO		0x4
-#define DMAMAP_ALLOCATED	0x10
 #define DMAMAP_TYPE_MASK	(DMAMAP_LINEAR|DMAMAP_MBUF|DMAMAP_UIO)
 #define DMAMAP_COHERENT		0x8
+#define DMAMAP_ALLOCATED	0x10
+#define DMAMAP_MALLOCUSED	0x20
+
 struct bus_dmamap {
 	struct bp_list	bpages;
 	int		pagesneeded;
@@ -514,6 +516,10 @@ bus_dmamap_create(bus_dma_tag_t dmat, in
 		}
 		bz->map_count++;
 	}
+
+	if (flags & BUS_DMA_COHERENT)
+	    newmap->flags |= DMAMAP_COHERENT;
+
 	CTR4(KTR_BUSDMA, "%s: tag %p tag flags 0x%x error %d",
 	    __func__, dmat, dmat->flags, error);
 
@@ -570,12 +576,16 @@ bus_dmamem_alloc(bus_dma_tag_t dmat, voi
 	dmat->map_count++;
 	*mapp = newmap;
 	newmap->dmat = dmat;
+
+	if (flags & BUS_DMA_COHERENT)
+	    newmap->flags |= DMAMAP_COHERENT;
 	
         if (dmat->maxsize <= PAGE_SIZE &&
 	   (dmat->alignment < dmat->maxsize) &&
 	   !_bus_dma_can_bounce(dmat->lowaddr, dmat->highaddr) && 
 	   !(flags & BUS_DMA_COHERENT)) {
                 *vaddr = malloc(dmat->maxsize, M_DEVBUF, mflags);
+		newmap->flags |= DMAMAP_MALLOCUSED;
         } else {
                 /*
                  * XXX Use Contigmalloc until it is merged into this facility
@@ -639,13 +649,12 @@ bus_dmamem_free(bus_dma_tag_t dmat, void
 		    ("Trying to freeing the wrong DMA buffer"));
 		vaddr = map->origbuffer;
 	}
-        if (dmat->maxsize <= PAGE_SIZE &&
-	   dmat->alignment < dmat->maxsize &&
-	    !_bus_dma_can_bounce(dmat->lowaddr, dmat->highaddr))
+
+        if (map->flags & DMAMAP_MALLOCUSED)
 		free(vaddr, M_DEVBUF);
-        else {
+        else
 		contigfree(vaddr, dmat->maxsize, M_DEVBUF);
-	}
+
 	dmat->map_count--;
 	_busdma_free_dmamap(map);
 	CTR3(KTR_BUSDMA, "%s: tag %p flags 0x%x", __func__, dmat, dmat->flags);



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