From: Joerg Roedel <joerg.roedel@amd.com>
To: mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com
Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
muli@il.ibm.com, Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 4/8] x86: add alloc_coherent dma_ops callback to NOMMU driver
Date: Tue, 19 Aug 2008 16:32:42 +0200 [thread overview]
Message-ID: <1219156366-32498-5-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1219156366-32498-1-git-send-email-joerg.roedel@amd.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kernel/pci-nommu.c | 55 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu.c
index 3f91f71..b8ce83c 100644
--- a/arch/x86/kernel/pci-nommu.c
+++ b/arch/x86/kernel/pci-nommu.c
@@ -72,7 +72,62 @@ static int nommu_map_sg(struct device *hwdev, struct scatterlist *sg,
return nents;
}
+static void *
+nommu_alloc_coherent(struct device *hwdev, size_t size,
+ dma_addr_t *dma_addr, gfp_t gfp)
+{
+ unsigned long dma_mask;
+ int node;
+ struct page *page;
+
+ if (hwdev->dma_mask == NULL)
+ return NULL;
+
+ gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
+ gfp |= __GFP_ZERO;
+
+ dma_mask = hwdev->coherent_dma_mask;
+ if (!dma_mask)
+ dma_mask = *(hwdev->dma_mask);
+
+ if (dma_mask < DMA_24BIT_MASK)
+ return NULL;
+
+ node = dev_to_node(hwdev);
+
+#ifdef CONFIG_X86_64
+ if (dma_mask <= DMA_32BIT_MASK)
+ gfp |= GFP_DMA32;
+#endif
+
+ /* No alloc-free penalty for ISA devices */
+ if (dma_mask == DMA_24BIT_MASK)
+ gfp |= GFP_DMA;
+
+again:
+ page = alloc_pages_node(node, gfp, get_order(size));
+ if (!page)
+ return NULL;
+
+ if ((page_to_phys(page) + size > dma_mask) && !(gfp & GFP_DMA)) {
+ free_pages((unsigned long)page_address(page), get_order(size));
+ gfp |= GFP_DMA;
+ goto again;
+ }
+
+ *dma_addr = page_to_phys(page);
+ if (check_addr("alloc_coherent", hwdev, *dma_addr, size)) {
+ flush_write_buffers();
+ return page_address(page);
+ }
+
+ free_pages((unsigned long)page_address(page), get_order(size));
+
+ return NULL;
+}
+
struct dma_mapping_ops nommu_dma_ops = {
+ .alloc_coherent = nommu_alloc_coherent,
.map_single = nommu_map_single,
.map_sg = nommu_map_sg,
.is_phys = 1,
--
1.5.3.7
next prev parent reply other threads:[~2008-08-19 14:33 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-19 14:32 [PATCH 0/8] x86 dma_*_coherent rework patchset v2 Joerg Roedel
2008-08-19 14:32 ` [PATCH 1/8] x86: add alloc_coherent dma_ops callback to GART driver Joerg Roedel
2008-08-21 14:16 ` FUJITA Tomonori
2008-08-21 15:17 ` Joerg Roedel
2008-08-21 17:28 ` [PATCH] x86: make gart_alloc_coherent return zeroed memory Joerg Roedel
2008-08-21 23:19 ` FUJITA Tomonori
2008-08-22 6:35 ` Joerg Roedel
2008-08-22 6:41 ` Ingo Molnar
2008-08-22 6:55 ` Joerg Roedel
2008-08-22 6:36 ` Ingo Molnar
2008-08-19 14:32 ` [PATCH 2/8] x86: add free_coherent dma_ops callback to GART driver Joerg Roedel
2008-08-19 14:32 ` [PATCH 3/8] x86: add free_coherent dma_ops callback to Calgary IOMMU driver Joerg Roedel
2008-08-19 14:32 ` Joerg Roedel [this message]
2008-08-19 14:32 ` [PATCH 5/8] x86: add free_coherent dma_ops callback to NOMMU driver Joerg Roedel
2008-08-19 14:32 ` [PATCH 6/8] x86: cleanup dma_*_coherent functions Joerg Roedel
2008-08-19 14:32 ` [PATCH 7/8] x86: move dma_*_coherent functions to include file Joerg Roedel
2008-08-19 14:32 ` [PATCH 8/8] x86, AMD IOMMU: remove obsolete FIXME comment Joerg Roedel
2008-08-20 9:46 ` [PATCH 0/8] x86 dma_*_coherent rework patchset v2 Ingo Molnar
2008-08-20 10:18 ` [PATCH] dma-coherent: export dma_[alloc|release]_from_coherent methods Ingo Molnar
2008-08-20 11:28 ` Joerg Roedel
2008-08-20 17:39 ` [PATCH 0/8] x86 dma_*_coherent rework patchset v2 Jesse Barnes
2008-08-21 12:00 ` Ingo Molnar
2008-08-21 14:16 ` FUJITA Tomonori
2008-08-21 15:07 ` Jesse Barnes
2008-08-22 7:09 ` Ingo Molnar
2008-08-21 15:20 ` Joerg Roedel
2008-08-21 14:16 ` FUJITA Tomonori
2008-08-21 15:12 ` FUJITA Tomonori
2008-08-22 6:44 ` Ingo Molnar
2008-08-22 6:57 ` FUJITA Tomonori
2008-08-22 7:04 ` Ingo Molnar
2008-08-22 7:29 ` FUJITA Tomonori
2008-08-22 8:23 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1219156366-32498-5-git-send-email-joerg.roedel@amd.com \
--to=joerg.roedel@amd.com \
--cc=hpa@zytor.com \
--cc=iommu@lists.linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=muli@il.ibm.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome