public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@steeleye.com>
To: linux-arch@vger.kernel.org
Subject: [PATCH] dma_get_required_mask()
Date: 25 Jun 2004 10:27:29 -0500	[thread overview]
Message-ID: <1088177249.2217.29.camel@mulgrave> (raw)

[copy of email sent to linux-kernel and linux-scsi for notice only,
please discuss on the public thread]

Following the discussion, this is a patch implementing
dma_get_required_mask().  The default implementation simply works out
the largest mask covering all of memory and returns the and of that with
the current dma_mask.  If this looks OK, I'll send out another patch
including the documentation updates as well.

I've put the implementation in linux/dma-mapping.h with a
ARCH_HAS_DMA_GET_REQUIRED_MASK override for those architectures that
would like to do something different.

Any opinions on whether I should also make linux/dma-mapping.h include
linux/bitops.h now since it requires fls() from there?

James

===== include/linux/dma-mapping.h 1.3 vs edited =====
--- 1.3/include/linux/dma-mapping.h	2004-03-30 20:53:54 -05:00
+++ edited/include/linux/dma-mapping.h	2004-06-25 11:12:30 -04:00
@@ -19,6 +19,29 @@
 #define dma_sync_single		dma_sync_single_for_cpu
 #define dma_sync_sg		dma_sync_sg_for_cpu
 
+#ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
+static inline u64 dma_get_required_mask(struct device *dev)
+{
+	extern unsigned long max_pfn; /* defined in bootmem.h but may
+					 not be included */
+	u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
+	u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT));
+	u64 mask;
+
+	if (!high_totalram) {
+		/* convert to mask just covering totalram */
+		low_totalram = (1 << (fls(low_totalram) - 1));
+		low_totalram += low_totalram - 1;
+		mask = low_totalram;
+	} else {
+		high_totalram = (1 << (fls(high_totalram) - 1));
+		high_totalram += high_totalram - 1;
+		mask = (((u64)high_totalram) << 32) + 0xffffffff;
+	}
+	return mask & *dev->dma_mask;
+}
+#endif
+		
 #endif
 

                 reply	other threads:[~2004-06-25 15:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1088177249.2217.29.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=linux-arch@vger.kernel.org \
    /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