All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com,
	linux-pci@vger.kernel.org
Cc: bhelgaas@google.com, mark.brown@linaro.org,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH] PCI: generic: map config window in one go
Date: Fri, 29 Jan 2016 15:17:15 +0100	[thread overview]
Message-ID: <1454077035-23872-1-git-send-email-ard.biesheuvel@linaro.org> (raw)

Instead of iterating over the PCI config window and performing individual
ioremap() calls on all the adjacent slices, perform a single ioremap() to
map the entire region, and divvy it up later. This not only prevents
leaving some of it mapped if we fail half way through, it also ensures that
archs that support huge-vmap can use section mappings to perform the
mapping.

On my Seattle A0 box, this transforms 128 separate 1 MB mappings that are
mapped down to 4 KB pages into a single 128 MB mapping using 2 MB sections,
saving 512 KB worth of page tables.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---

huge-vmap for arm64 proposed here:
http://article.gmane.org/gmane.linux.kernel.hardened.devel/1661
 
 drivers/pci/host/pci-host-generic.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
index 1652bc70b145..3251cd779278 100644
--- a/drivers/pci/host/pci-host-generic.c
+++ b/drivers/pci/host/pci-host-generic.c
@@ -161,6 +161,7 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
 	struct device *dev = pci->host.dev.parent;
 	struct device_node *np = dev->of_node;
 	u32 sz = 1 << pci->cfg.ops->bus_shift;
+	void *window;
 
 	err = of_address_to_resource(np, 0, &pci->cfg.res);
 	if (err) {
@@ -186,14 +187,15 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
 		return -ENOMEM;
 
 	bus_range = pci->cfg.bus_range;
+	window = devm_ioremap(dev, pci->cfg.res.start,
+			      (bus_range->end - bus_range->start + 1) * sz);
+	if (!window)
+		return -ENOMEM;
+
 	for (busn = bus_range->start; busn <= bus_range->end; ++busn) {
 		u32 idx = busn - bus_range->start;
 
-		pci->cfg.win[idx] = devm_ioremap(dev,
-						 pci->cfg.res.start + idx * sz,
-						 sz);
-		if (!pci->cfg.win[idx])
-			return -ENOMEM;
+		pci->cfg.win[idx] = window + idx * sz;
 	}
 
 	return 0;
-- 
2.5.0


WARNING: multiple messages have this Message-ID (diff)
From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] PCI: generic: map config window in one go
Date: Fri, 29 Jan 2016 15:17:15 +0100	[thread overview]
Message-ID: <1454077035-23872-1-git-send-email-ard.biesheuvel@linaro.org> (raw)

Instead of iterating over the PCI config window and performing individual
ioremap() calls on all the adjacent slices, perform a single ioremap() to
map the entire region, and divvy it up later. This not only prevents
leaving some of it mapped if we fail half way through, it also ensures that
archs that support huge-vmap can use section mappings to perform the
mapping.

On my Seattle A0 box, this transforms 128 separate 1 MB mappings that are
mapped down to 4 KB pages into a single 128 MB mapping using 2 MB sections,
saving 512 KB worth of page tables.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---

huge-vmap for arm64 proposed here:
http://article.gmane.org/gmane.linux.kernel.hardened.devel/1661
 
 drivers/pci/host/pci-host-generic.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/host/pci-host-generic.c b/drivers/pci/host/pci-host-generic.c
index 1652bc70b145..3251cd779278 100644
--- a/drivers/pci/host/pci-host-generic.c
+++ b/drivers/pci/host/pci-host-generic.c
@@ -161,6 +161,7 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
 	struct device *dev = pci->host.dev.parent;
 	struct device_node *np = dev->of_node;
 	u32 sz = 1 << pci->cfg.ops->bus_shift;
+	void *window;
 
 	err = of_address_to_resource(np, 0, &pci->cfg.res);
 	if (err) {
@@ -186,14 +187,15 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
 		return -ENOMEM;
 
 	bus_range = pci->cfg.bus_range;
+	window = devm_ioremap(dev, pci->cfg.res.start,
+			      (bus_range->end - bus_range->start + 1) * sz);
+	if (!window)
+		return -ENOMEM;
+
 	for (busn = bus_range->start; busn <= bus_range->end; ++busn) {
 		u32 idx = busn - bus_range->start;
 
-		pci->cfg.win[idx] = devm_ioremap(dev,
-						 pci->cfg.res.start + idx * sz,
-						 sz);
-		if (!pci->cfg.win[idx])
-			return -ENOMEM;
+		pci->cfg.win[idx] = window + idx * sz;
 	}
 
 	return 0;
-- 
2.5.0

             reply	other threads:[~2016-01-29 14:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-29 14:17 Ard Biesheuvel [this message]
2016-01-29 14:17 ` [PATCH] PCI: generic: map config window in one go Ard Biesheuvel
2016-01-29 14:19 ` Ard Biesheuvel
2016-01-29 14:19   ` Ard Biesheuvel
2016-01-29 14:22   ` Ard Biesheuvel
2016-01-29 14:22     ` Ard Biesheuvel
2016-01-29 14:28 ` Will Deacon
2016-01-29 14:28   ` Will Deacon
2016-01-29 14:32   ` Ard Biesheuvel
2016-01-29 14:32     ` Ard Biesheuvel
2016-01-29 14:52     ` Arnd Bergmann
2016-01-29 14:52       ` Arnd Bergmann
2016-02-05 10:48       ` Ard Biesheuvel
2016-02-05 10:48         ` Ard Biesheuvel
2016-02-05 13:37         ` Arnd Bergmann
2016-02-05 13:37           ` Arnd Bergmann
2016-02-05 14:09           ` Ard Biesheuvel
2016-02-05 14:09             ` Ard Biesheuvel

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=1454077035-23872-1-git-send-email-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=bhelgaas@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mark.brown@linaro.org \
    --cc=will.deacon@arm.com \
    /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 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.