From: Yinghai Lu <yinghai@kernel.org>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Gu Zheng <guz.fnst@cn.fujitsu.com>,
Guo Chao <yan@linux.vnet.ibm.com>,
linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Yinghai Lu <yinghai@kernel.org>
Subject: [PATCH v2 07/10] PCI: Try to allocate mem64 above 4G at first
Date: Mon, 25 Nov 2013 17:28:07 -0800 [thread overview]
Message-ID: <1385429290-25397-8-git-send-email-yinghai@kernel.org> (raw)
In-Reply-To: <1385429290-25397-1-git-send-email-yinghai@kernel.org>
Will fall back to below 4g if it can not find any above 4g.
x86 32bit without X86_PAE support will have bottom set to 0, because
resource_size_t is 32bit.
Also for 32bit with resource_size_t 64bit kernel on machine with pae support
we are safe because iomem_resource is limited to 32bit according to
x86_phys_bits.
-v2: update bottom assigning to make it clear for non-pae support machine.
-v3: Bjorn's change:
use MAX_RESOURCE instead of -1
use start/end instead of bottom/max
for all arch instead of just x86_64
-v4: updated after PCI_MAX_RESOURCE_32 change.
-v5: restore io handling to use PCI_MAX_RESOURCE_32 as limit.
-v6: checking pcibios_resource_to_bus return for every bus res, to decide it
if we need to try high at first.
It supports all arches instead of just x86_64.
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
arch/x86/include/asm/pci.h | 1 -
drivers/pci/bus.c | 42 ++++++++++++++++++++++++++++++++++--------
drivers/pci/pci.h | 2 ++
include/linux/pci.h | 4 ----
4 files changed, 36 insertions(+), 13 deletions(-)
diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h
index 947b5c4..122c299 100644
--- a/arch/x86/include/asm/pci.h
+++ b/arch/x86/include/asm/pci.h
@@ -125,7 +125,6 @@ int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc,
/* generic pci stuff */
#include <asm-generic/pci.h>
-#define PCIBIOS_MAX_MEM_32 0xffffffff
#ifdef CONFIG_NUMA
/* Returns the node based on pci bus */
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 1ffd95b..f801f6a 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -125,15 +125,13 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
{
int i, ret = -ENOMEM;
struct resource *r;
- resource_size_t max = -1;
type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
- /* don't allocate too high if the pref mem doesn't support 64bit*/
- if (!(res->flags & IORESOURCE_MEM_64))
- max = PCIBIOS_MAX_MEM_32;
-
pci_bus_for_each_resource(bus, r, i) {
+ resource_size_t start, end, middle;
+ struct pci_bus_region region;
+
if (!r)
continue;
@@ -147,14 +145,42 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
!(res->flags & IORESOURCE_PREFETCH))
continue;
+ start = 0;
+ end = MAX_RESOURCE;
+ /*
+ * don't allocate too high if the pref mem doesn't
+ * support 64bit, also if this is a 64-bit mem
+ * resource, try above 4GB first
+ */
+ __pcibios_resource_to_bus(bus, ®ion, r);
+ if (region.start <= PCI_MAX_ADDR_32 &&
+ region.end > PCI_MAX_ADDR_32) {
+ middle = pcibios_bus_addr_to_res(bus, res->flags,
+ PCI_MAX_ADDR_32);
+ if (res->flags & IORESOURCE_MEM_64)
+ start = middle + 1;
+ else
+ end = middle;
+ } else if (region.start > PCI_MAX_ADDR_32 &&
+ !(res->flags & IORESOURCE_MEM_64))
+ continue;
+
+again:
/* Ok, try it out.. */
ret = allocate_resource(r, res, size,
- r->start ? : min,
- max, align,
+ max(start, r->start ? : min),
+ end, align,
alignf, alignf_data);
if (ret == 0)
- break;
+ return 0;
+
+ if (start != 0) {
+ start = 0;
+ goto again;
+ }
}
+
+
return ret;
}
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 9c91ecc..aea4efb 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -198,6 +198,8 @@ enum pci_bar_type {
pci_bar_mem64, /* A 64-bit memory BAR */
};
+#define PCI_MAX_ADDR_32 ((resource_size_t)0xffffffff)
+
bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
int crs_timeout);
int pci_setup_device(struct pci_dev *dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 3c6e399..1c69789 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1491,10 +1491,6 @@ static inline struct pci_dev *pci_dev_get(struct pci_dev *dev)
#include <asm/pci.h>
-#ifndef PCIBIOS_MAX_MEM_32
-#define PCIBIOS_MAX_MEM_32 (-1)
-#endif
-
/* these helpers provide future and backwards compatibility
* for accessing popular PCI BAR info */
#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
--
1.8.1.4
next prev parent reply other threads:[~2013-11-26 1:29 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-26 1:28 [PATCH v2 00/10] PCI: Double removing fix and allocate 64bit mmio pref Yinghai Lu
2013-11-26 1:28 ` [PATCH v2 01/10] PCI: Use device_release_driver in pci_stop_root_bus Yinghai Lu
2013-11-27 1:09 ` Rafael J. Wysocki
2013-11-26 1:28 ` [PATCH v2 02/10] PCI: Move back pci_proc_attach_devices calling Yinghai Lu
2013-11-26 1:28 ` [PATCH v2 03/10] PCI: Move resources and bus_list releasing to pci_release_dev Yinghai Lu
2013-11-27 1:15 ` Rafael J. Wysocki
2013-11-27 2:15 ` Yinghai Lu
2013-11-26 1:28 ` [PATCH v2 04/10] PCI: Destroy pci dev only once Yinghai Lu
2013-11-26 3:38 ` Bjorn Helgaas
2013-11-26 19:34 ` Yinghai Lu
2013-11-26 20:13 ` Yinghai Lu
2013-11-27 1:24 ` Rafael J. Wysocki
2013-11-27 2:26 ` Yinghai Lu
2013-11-29 23:38 ` Rafael J. Wysocki
2013-11-29 23:45 ` Rafael J. Wysocki
2013-11-30 0:31 ` Rafael J. Wysocki
2013-11-30 21:37 ` Rafael J. Wysocki
2013-11-30 22:27 ` Yinghai Lu
2013-12-01 1:24 ` Rafael J. Wysocki
2013-12-02 1:29 ` Rafael J. Wysocki
2013-12-02 14:49 ` Rafael J. Wysocki
2013-12-05 22:40 ` Bjorn Helgaas
2013-12-06 1:21 ` Rafael J. Wysocki
2013-12-06 6:29 ` Yinghai Lu
2014-01-10 14:20 ` [PATCH 0/9] PCI: Eliminate race conditions between hotplug and sysfs rescan/remove (Was: Re: [PATCH v2 04/10] PCI: Destroy pci dev only once) Rafael J. Wysocki
2014-01-10 14:22 ` [PATCH 1/9] PCI: Global rescan-remove lock Rafael J. Wysocki
2014-01-10 14:23 ` [PATCH 2/9] ACPI / PCI: Use global PCI rescan-remove locking in PCI root hotplug Rafael J. Wysocki
2014-01-10 14:24 ` [PATCH 3/9] ACPI / hotplug / PCI: Use global PCI rescan-remove locking Rafael J. Wysocki
2014-01-10 14:25 ` [PATCH 4/9] PCMCIA / cardbus: " Rafael J. Wysocki
2014-01-10 14:26 ` [PATCH 5/9] PCI / hotplug: " Rafael J. Wysocki
2014-01-10 14:27 ` [PATCH 6/9] platform / x86: " Rafael J. Wysocki
2014-01-10 14:27 ` [PATCH 7/9] MPT / PCI: Use pci_stop_and_remove_bus_device_locked() Rafael J. Wysocki
2014-01-10 14:28 ` [PATCH 8/9] powerpc / eeh_driver: Use global PCI rescan-remove locking Rafael J. Wysocki
2014-01-15 13:36 ` [Update][PATCH " Rafael J. Wysocki
2014-01-15 17:38 ` Bjorn Helgaas
2014-01-10 14:29 ` [PATCH 9/9] Xen / PCI: " Rafael J. Wysocki
2014-01-15 18:02 ` [PATCH 0/9] PCI: Eliminate race conditions between hotplug and sysfs rescan/remove (Was: Re: [PATCH v2 04/10] PCI: Destroy pci dev only once) Bjorn Helgaas
2013-12-06 6:52 ` [PATCH v2 04/10] PCI: Destroy pci dev only once Yinghai Lu
2013-12-07 1:27 ` Rafael J. Wysocki
2013-12-08 3:31 ` Yinghai Lu
2013-12-08 3:50 ` Greg Kroah-Hartman
2013-12-09 15:24 ` Ethan Zhao
2013-12-09 19:08 ` Greg Kroah-Hartman
2013-12-10 7:43 ` Ethan Zhao
2014-01-13 1:03 ` [PATCH] PCI / remove: Check parent kobject in pci_destroy_dev() (was: Re: [PATCH v2 04/10] PCI: Destroy pci dev only once) Rafael J. Wysocki
2013-11-27 1:17 ` [PATCH v2 04/10] PCI: Destroy pci dev only once Rafael J. Wysocki
2013-11-26 1:28 ` [PATCH v2 05/10] PCI: pcibus address to resource converting take bus directly Yinghai Lu
2013-11-26 1:28 ` [PATCH v2 06/10] PCI: Add pcibios_bus_addr_to_res() Yinghai Lu
2013-11-26 1:28 ` Yinghai Lu [this message]
2013-11-26 4:15 ` [PATCH v2 07/10] PCI: Try to allocate mem64 above 4G at first Bjorn Helgaas
2013-11-26 20:14 ` Yinghai Lu
2013-11-26 1:28 ` [PATCH v2 08/10] PCI: Try best to allocate pref mmio 64bit above 4g Yinghai Lu
2013-11-26 4:17 ` Bjorn Helgaas
2013-11-26 6:59 ` Guo Chao
2013-11-26 17:53 ` Bjorn Helgaas
2013-11-26 22:00 ` Yinghai Lu
2013-11-26 22:01 ` Bjorn Helgaas
2013-11-27 0:33 ` Yinghai Lu
2013-11-26 1:28 ` [PATCH v2 09/10] PCI: Sort pci root bus resources list Yinghai Lu
2013-11-26 4:18 ` Bjorn Helgaas
2013-11-26 1:28 ` [PATCH v2 10/10] intel-gtt: Read 64bit for gmar_bus_addr Yinghai Lu
2013-11-26 3:46 ` Bjorn Helgaas
2013-11-26 19:35 ` Yinghai Lu
2013-12-11 18:48 ` Bjorn Helgaas
2013-12-11 19:58 ` Yinghai Lu
2013-12-21 0:27 ` Bjorn Helgaas
2013-12-21 1:19 ` Yinghai Lu
2013-12-21 18:50 ` Bjorn Helgaas
2013-12-23 22:33 ` Bjorn Helgaas
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=1385429290-25397-8-git-send-email-yinghai@kernel.org \
--to=yinghai@kernel.org \
--cc=bhelgaas@google.com \
--cc=guz.fnst@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=yan@linux.vnet.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).