From patchwork Fri Jan 29 14:17:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 8163881 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2D69ABEEE5 for ; Fri, 29 Jan 2016 14:17:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53E2920395 for ; Fri, 29 Jan 2016 14:17:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F49F20328 for ; Fri, 29 Jan 2016 14:17:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751670AbcA2ORX (ORCPT ); Fri, 29 Jan 2016 09:17:23 -0500 Received: from mail-wm0-f51.google.com ([74.125.82.51]:34688 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751516AbcA2ORX (ORCPT ); Fri, 29 Jan 2016 09:17:23 -0500 Received: by mail-wm0-f51.google.com with SMTP id 128so54759122wmz.1 for ; Fri, 29 Jan 2016 06:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=kzQ2FYEEs/9wzlcXKyn+eF4JWnq4/Anie0BH3pnRnD8=; b=eNPwcfuomstuCskLfsPO1aOXXtjnn0dpKMf6YpDZ/WDCWlQ8pjRUnmif04ScolIXPo atS6iyuA/a4m8uGwk/spuYhsicvauI09OgFtdPR00mkxGabkO1za79KJwyyFVez01hV6 tLxOQNf/OXljGXFkwhc3trzijcRpaxib4QPwQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kzQ2FYEEs/9wzlcXKyn+eF4JWnq4/Anie0BH3pnRnD8=; b=ZRkq3fJsGg4ONwcR0brEKfZIxY78bjOAGJyG7k5Hdv9VX3rIgYBiYOF0JRq/DrVdj+ 5CGaEsF3tg/Z7l/YNRbZim8H92RCJCZbAYCKMqorW0KltPW/x7g4ZdsZ2Ky4aQzWs6+P iPP7HQ2RsYG9nLv6I2+hsaf1S+/DjZu0up8LuSS1iSS1GH6Gu07b+6tDzpg6UUJyIs3C q/KniNoYxM7NNI+YkNubwucRQPTRS+dz7MOMqVOXiUcoaTDn5HMceW6ETj9ejkMPln50 BC6Yu7JUfiKQPxGTCywffCM5LK42MF2O/CFjimcVoygX4ycS6EsrkW0/3923apda1KZF +zog== X-Gm-Message-State: AG10YOR0fotXu+co2nvHylv48MbfECLN7GytRKrYm6HB8ri0+y9tQGBvg0+4RoARGY2MVGch X-Received: by 10.28.182.133 with SMTP id g127mr8937612wmf.61.1454077041900; Fri, 29 Jan 2016 06:17:21 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id ka4sm15861229wjc.47.2016.01.29.06.17.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jan 2016 06:17:20 -0800 (PST) From: Ard Biesheuvel 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 Subject: [PATCH] PCI: generic: map config window in one go Date: Fri, 29 Jan 2016 15:17:15 +0100 Message-Id: <1454077035-23872-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;