Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>,
	Nicolas Pitre <nico@fluxnic.net>,
	linux-mmc@vger.kernel.org, Russell King <linux@armlinux.org.uk>,
	linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
	Ben Dooks <ben-linux@fluff.org>,
	linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [PATCH 01/14] scatterlist: add sg_kmap_atomic / sg_kunmap_atomic helpers
Date: Tue, 12 Feb 2019 08:25:15 +0100
Message-ID: <20190212072528.13167-2-hch@lst.de> (raw)
In-Reply-To: <20190212072528.13167-1-hch@lst.de>

This avoids bug prone open coding of the sg offset handling and
also helps to document the limitations of mapping scatterlist
entries.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/scatterlist.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index b96f0d0b5b8f..524cd8448a48 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -2,6 +2,7 @@
 #ifndef _LINUX_SCATTERLIST_H
 #define _LINUX_SCATTERLIST_H
 
+#include <linux/highmem.h>
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/bug.h>
@@ -239,6 +240,31 @@ static inline void *sg_virt(struct scatterlist *sg)
 	return page_address(sg_page(sg)) + sg->offset;
 }
 
+/**
+ * sg_kmap_atomic - map a S/G list entry to a kernel address
+ * @sg:		scatterlist entry
+ *
+ * Return a kernel address for scatterlist entry by kmapping it.  Note that
+ * this function must only be called on scatterlist entries that do not span
+ * multiple pages.
+ */
+static inline void *sg_kmap_atomic(struct scatterlist *sg)
+{
+	if (WARN_ON_ONCE(sg->offset + sg->length > PAGE_SIZE))
+		return NULL;
+	return kmap_atomic(sg_page(sg)) + sg->offset;
+}
+
+/**
+ * sg_kunmap_atomic - unmap a S/G list entry to a kernel address
+ * @sg:		scatterlist entry
+ * @ptr:	address returned from sg_kmap_atomic
+ */
+static inline void sg_kunmap_atomic(struct scatterlist *sg, void *ptr)
+{
+	kunmap_atomic(ptr - sg->offset);
+}
+
 /**
  * sg_init_marker - Initialize markers in sg table
  * @sgl:	   The SG table
-- 
2.20.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply index

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12  7:25 remove block layer bounce buffering for MMC v2 Christoph Hellwig
2019-02-12  7:25 ` Christoph Hellwig [this message]
2019-02-12  7:25 ` [PATCH 02/14] mmc: remove the unused use_blk_mq field from struct mmc_host Christoph Hellwig
2019-02-12  7:25 ` [PATCH 03/14] mmc: add a need_kmap flag to " Christoph Hellwig
2019-02-12  7:25 ` [PATCH 04/14] mmc: davinci: handle highmem pages Christoph Hellwig
2019-02-12  7:25 ` [PATCH 05/14] mmc: moxart: " Christoph Hellwig
2019-02-12  7:25 ` [PATCH 06/14] mmc: omap: " Christoph Hellwig
2019-02-12 18:39   ` Tony Lindgren
2019-02-12  7:25 ` [PATCH 07/14] mmc: omap: handle chained sglists Christoph Hellwig
2019-02-12  7:25 ` [PATCH 08/14] mmc: s3cmci: handle highmem pages Christoph Hellwig
2019-02-12  7:25 ` [PATCH 09/14] mmc: s3cmci: handle chained sglists Christoph Hellwig
2019-02-12  7:25 ` [PATCH 10/14] mmc: mvsdio: handle highmem pages Christoph Hellwig
2019-02-12  7:25 ` [PATCH 11/14] mmc: sh_mmcif: " Christoph Hellwig
2019-02-12  7:25 ` [PATCH 12/14] mmc: sh_mmcif: handle chained sglists Christoph Hellwig
2019-02-12  7:25 ` [PATCH 13/14] mmc: core: don't use block layer bounce buffers Christoph Hellwig
2019-02-12  7:25 ` [PATCH 14/14] dma-mapping: remove dma_max_pfn Christoph Hellwig
2019-02-25 13:54 ` remove block layer bounce buffering for MMC v2 Ulf Hansson
2019-03-08  9:18   ` Christoph Hellwig
2019-03-08  9:43     ` Ulf Hansson

Reply instructions:

You may reply publically 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=20190212072528.13167-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=aaro.koskinen@iki.fi \
    --cc=ben-linux@fluff.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nico@fluxnic.net \
    --cc=ulf.hansson@linaro.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

Linux-ARM-Kernel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/0 linux-arm-kernel/git/0.git
	git clone --mirror https://lore.kernel.org/linux-arm-kernel/1 linux-arm-kernel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-arm-kernel linux-arm-kernel/ https://lore.kernel.org/linux-arm-kernel \
		linux-arm-kernel@lists.infradead.org infradead-linux-arm-kernel@archiver.kernel.org
	public-inbox-index linux-arm-kernel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-arm-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox