All of lore.kernel.org
 help / color / mirror / Atom feed
* + firmware-consolidate-kmap-read-write-logic.patch added to -mm tree
@ 2016-06-07 20:26 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2016-06-07 20:26 UTC (permalink / raw)
  To: stephen.boyd, broonie, gregkh, markivx, ming.lei, zohar, mm-commits


The patch titled
     Subject: firmware: consolidate kmap/read/write logic
has been added to the -mm tree.  Its filename is
     firmware-consolidate-kmap-read-write-logic.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/firmware-consolidate-kmap-read-write-logic.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/firmware-consolidate-kmap-read-write-logic.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Stephen Boyd <stephen.boyd@linaro.org>
Subject: firmware: consolidate kmap/read/write logic

Some systems are memory constrained but they need to load very large
firmwares.  The firmware subsystem allows drivers to request this firmware
be loaded from the filesystem, but this requires that the entire firmware
be loaded into kernel memory first before it's provided to the driver. 
This can lead to a situation where we map the firmware twice, once to load
the firmware into kernel memory and once to copy the firmware into the
final resting place.

This design creates needless memory pressure and delays loading because we
have to copy from kernel memory to somewhere else.  This patch sets adds
support to the request firmware API to load the firmware directly into a
pre-allocated buffer, skipping the intermediate copying step and
alleviating memory pressure during firmware loading.  The drawback is that
we can't use the firmware caching feature because the memory for the
firmware cache is not managed by the firmware layer.


This patch (of 3):

We use similar structured code to read and write the kmapped firmware
pages.  The only difference is read copies from the kmap region and write
copies to it.  Consolidate this into one function to reduce duplication.

Link: http://lkml.kernel.org/r/20160607164741.31849-2-stephen.boyd@linaro.org
Signed-off-by: Stephen Boyd <stephen.boyd@linaro.org>
Cc: Vikram Mulukutla <markivx@codeaurora.org>
Cc: Mimi Zohar <zohar@linux.vnet.ibm.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Ming Lei <ming.lei@canonical.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/base/firmware_class.c |   57 ++++++++++++++------------------
 1 file changed, 26 insertions(+), 31 deletions(-)

diff -puN drivers/base/firmware_class.c~firmware-consolidate-kmap-read-write-logic drivers/base/firmware_class.c
--- a/drivers/base/firmware_class.c~firmware-consolidate-kmap-read-write-logic
+++ a/drivers/base/firmware_class.c
@@ -691,6 +691,29 @@ out:
 
 static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store);
 
+static void firmware_rw(struct firmware_buf *buf, char *buffer,
+			loff_t offset, size_t count, bool read)
+{
+	while (count) {
+		void *page_data;
+		int page_nr = offset >> PAGE_SHIFT;
+		int page_ofs = offset & (PAGE_SIZE-1);
+		int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
+
+		page_data = kmap(buf->pages[page_nr]);
+
+		if (read)
+			memcpy(buffer, page_data + page_ofs, page_cnt);
+		else
+			memcpy(page_data + page_ofs, buffer, page_cnt);
+
+		kunmap(buf->pages[page_nr]);
+		buffer += page_cnt;
+		offset += page_cnt;
+		count -= page_cnt;
+	}
+}
+
 static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj,
 				  struct bin_attribute *bin_attr,
 				  char *buffer, loff_t offset, size_t count)
@@ -715,21 +738,8 @@ static ssize_t firmware_data_read(struct
 
 	ret_count = count;
 
-	while (count) {
-		void *page_data;
-		int page_nr = offset >> PAGE_SHIFT;
-		int page_ofs = offset & (PAGE_SIZE-1);
-		int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
-
-		page_data = kmap(buf->pages[page_nr]);
-
-		memcpy(buffer, page_data + page_ofs, page_cnt);
+	firmware_rw(buf, buffer, offset, count, true);
 
-		kunmap(buf->pages[page_nr]);
-		buffer += page_cnt;
-		offset += page_cnt;
-		count -= page_cnt;
-	}
 out:
 	mutex_unlock(&fw_lock);
 	return ret_count;
@@ -809,24 +819,9 @@ static ssize_t firmware_data_write(struc
 		goto out;
 
 	retval = count;
+	firmware_rw(buf, buffer, offset, count, false);
 
-	while (count) {
-		void *page_data;
-		int page_nr = offset >> PAGE_SHIFT;
-		int page_ofs = offset & (PAGE_SIZE - 1);
-		int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count);
-
-		page_data = kmap(buf->pages[page_nr]);
-
-		memcpy(page_data + page_ofs, buffer, page_cnt);
-
-		kunmap(buf->pages[page_nr]);
-		buffer += page_cnt;
-		offset += page_cnt;
-		count -= page_cnt;
-	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-06-07 20:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-07 20:26 + firmware-consolidate-kmap-read-write-logic.patch added to -mm tree akpm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.