linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Problems with dma_alloc_coherent()
@ 2004-04-01 15:59 John Whitney
  2004-04-01 16:30 ` John Whitney
                   ` (3 more replies)
  0 siblings, 4 replies; 36+ messages in thread
From: John Whitney @ 2004-04-01 15:59 UTC (permalink / raw)
  To: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 1465 bytes --]

In the process of reworking my Generic DMA core for the 2.6 kernel, I
noticed that dma_alloc_coherent() returns NULL in all cases on a
cache-coherent platform.  Instead, I think it would be better if this
routine returned a block of contiguous memory (not cache-inhibited), as
pci_alloc_consistent() does.

To that end, I am submitting the attached patch which modifies
dma_alloc_coherent() and dma_free_coherent() to do just this for
cache-coherent platforms.
I was going to add a check for dev->dma_mask in dma_alloc_coherent()
(to add GFP_DMA to the flags), but the dma_supported() macro always
returns 1, which would indicate that this is superfluous.

John


--- dma-mapping.h.orig	2004-04-01 10:38:33.000000000 -0500
+++ dma-mapping.h	2004-04-01 10:49:32.000000000 -0500
@@ -35,7 +35,18 @@
  		return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
  #endif

-	return consistent_alloc(flag, size, dma_handle);
+#ifdef CONFIG_NOT_COHERENT_CACHE
+    return consistent_alloc(flag, size, dma_handle);
+#else
+	void *ret;
+
+	ret = (void *)__get_free_pages(flag, get_order(size));
+	if (ret != NULL) {
+		*dma_handle = virt_to_bus(ret);
+	}
+
+    return ret;
+#endif /* CONFIG_NOT_COHERENT_CACHE */
  }

  static inline void
@@ -49,7 +60,11 @@
  	}
  #endif

-	consistent_free(vaddr);
+#ifdef CONFIG_NOT_COHERENT_CACHE
+	consistent_free(vaddr, size);
+#else
+	free_pages((unsigned long)vaddr, get_order(size));
+#endif
  }

  static inline dma_addr_t



[-- Attachment #2: dma-mapping.h.patch --]
[-- Type: application/octet-stream, Size: 791 bytes --]

--- dma-mapping.h.orig	2004-04-01 10:38:33.000000000 -0500
+++ dma-mapping.h	2004-04-01 10:49:32.000000000 -0500
@@ -35,7 +35,18 @@
 		return pci_alloc_consistent(to_pci_dev(dev), size, dma_handle);
 #endif

-	return consistent_alloc(flag, size, dma_handle);
+#ifdef CONFIG_NOT_COHERENT_CACHE
+    return consistent_alloc(flag, size, dma_handle);
+#else
+	void *ret;
+
+	ret = (void *)__get_free_pages(flag, get_order(size));
+	if (ret != NULL) {
+		*dma_handle = virt_to_bus(ret);
+	}
+
+    return ret;
+#endif /* CONFIG_NOT_COHERENT_CACHE */
 }

 static inline void
@@ -49,7 +60,11 @@
 	}
 #endif

-	consistent_free(vaddr);
+#ifdef CONFIG_NOT_COHERENT_CACHE
+	consistent_free(vaddr, size);
+#else
+	free_pages((unsigned long)vaddr, get_order(size));
+#endif
 }

 static inline dma_addr_t

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2004-04-05  9:05 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-01 15:59 Problems with dma_alloc_coherent() John Whitney
2004-04-01 16:30 ` John Whitney
2004-04-01 16:51 ` Dan Malek
2004-04-01 17:01 ` Tom Rini
2004-04-01 17:05 ` Matt Porter
2004-04-01 17:51   ` John Whitney
2004-04-01 18:16     ` Matt Porter
2004-04-01 18:19     ` Eugene Surovegin
2004-04-01 18:33       ` Eugene Surovegin
2004-04-01 18:33       ` John Whitney
2004-04-01 18:40         ` Eugene Surovegin
2004-04-01 18:48           ` John Whitney
2004-04-01 18:55       ` Dan Malek
2004-04-01 18:59         ` Eugene Surovegin
2004-04-01 19:10           ` John Whitney
2004-04-01 19:17             ` Eugene Surovegin
2004-04-01 19:35               ` John Whitney
2004-04-01 20:52               ` Michael R. Zucca
2004-04-01 22:00                 ` Eugene Surovegin
2004-04-01 22:39                   ` Michael R. Zucca
2004-04-02 16:50                   ` John Whitney
2004-04-02 18:50                     ` Michael R. Zucca
2004-04-02 19:27                       ` John Whitney
2004-04-02 20:20                         ` Michael R. Zucca
2004-04-02 21:01                           ` John Whitney
2004-04-03  7:54                             ` Adrian Cox
2004-04-03 12:43                               ` John Whitney
2004-04-05  9:05                                 ` Adrian Cox
2004-04-03 17:33                               ` Brad Boyer
2004-04-03 23:17                                 ` Paul Mackerras
2004-04-04  8:15                                 ` Adrian Cox
2004-04-02 22:54                     ` Paul Mackerras
2004-04-03  7:33                       ` Adrian Cox
2004-04-04 22:56                         ` Benjamin Herrenschmidt
2004-04-02  5:45             ` Christoph Hellwig
2004-04-01 20:49           ` Matt Porter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).