All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
To: Ingo Molnar <mingo@elte.hu>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Yinghai Lu <yinghai@kernel.org>,
	Jesse Barnes <jbarnes@virtuousgeek.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-pci@vger.kernel.org, yannick.roehlly@free.fr
Subject: Re: [PATCH] x86/pci: make pci_mem_start to be aligned only -v4
Date: Tue, 21 Apr 2009 02:33:05 +0400	[thread overview]
Message-ID: <20090420223305.GA15340@jurassic.park.msu.ru> (raw)
In-Reply-To: <20090419090615.GA30631@elte.hu>

On Sun, Apr 19, 2009 at 11:06:15AM +0200, Ingo Molnar wrote:
> Hm, there's one patch in that lot that does:
> 
>  drivers/pci/bus.c	 |    8 +++++++-
>  drivers/pci/probe.c     |    8 ++++++--
>  drivers/pci/setup-bus.c |   40 +++++++++++++++++++++++++++++++---------
>  3 files changed, 44 insertions(+), 12 deletions(-)
> 
> Which should go via the PCI tree.

Here is a replacement for that patch which doesn't touch
the generic code.

Ivan.

---
x86 pci: first cut on 64-bit resource allocation

I believe that we should consider PCI memory above 4G as yet another
type of address space. This actually makes sense, as even accesses to that
memory are physically different - Dual Address Cycle (DAC) vs. 32-bit
Single Address Cycle (SAC).

So, platform that can deal with 64-bit allocations would set up an
additional root bus resource and mark it with IORESOURCE_MEM64 flag.

The main problem here is how the kernel would detect that hardware can
actually access a DAC memory (I know for a fact that a lot of Intel chipsets
cannot access MMIO >4G, even though subordinate p2p bridges are 64-bit
capable).
On the other hand, there are PCI devices with 64-bit BARs that do not
work properly being placed above 4G boundary. For example, some
radeon cards have 64-bit BAR for video RAM, but allocating that BAR in
the DAC area doesn't work for various reasons, like video-BIOS
limitations or drivers not taking into account that GPU is 32-bit.

So moving stuff into MEM64 area should be considered as generally unsafe
operation, and the best default policy is to not enable MEM64 resource
unless we find that BIOS has allocated something there.
At the same time, MEM64 can be easily enabled/disabled based on host
bridge PCI IDs, kernel command line options and so on.

Here is a basic implementation of the above for x86. I think it's
reasonably good starting point for PCI64 work - the next step would
be to teach pci_bus_alloc_resource() about IORESOURCE_MEM64: logic is
similar to prefetch vs non-prefetch case - MEM can hold MEM64 resource,
but not vice versa. And eventually bridge sizing code will be updated
for reasonable 64-bit allocations (it's a non-trivial task, though).

This patch alone should fix cardbus >4G allocations and similar
nonsense.

Signed-off-by: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
---
 arch/x86/include/asm/pci.h |    8 ++++++++
 arch/x86/pci/Makefile      |    2 ++
 arch/x86/pci/dac_64bit.c   |   44 ++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/pci/i386.c        |   10 ++++++++++
 include/linux/ioport.h     |    2 ++
 5 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h
index b51a1e8..5a9c54e 100644
--- a/arch/x86/include/asm/pci.h
+++ b/arch/x86/include/asm/pci.h
@@ -86,6 +86,14 @@ static inline void early_quirks(void) { }
 
 extern void pci_iommu_alloc(void);
 
+#ifdef CONFIG_ARCH_PHYS_ADDR_T_64BIT
+extern void pcibios_pci64_setup(void);
+extern void pcibios_pci64_verify(void);
+#else
+static inline void pcibios_pci64_setup(void) { }
+static inline void pcibios_pci64_verify(void) { }
+#endif
+
 /* MSI arch hook */
 #define arch_setup_msi_irqs arch_setup_msi_irqs
 
diff --git a/arch/x86/pci/Makefile b/arch/x86/pci/Makefile
index d49202e..1b6c576 100644
--- a/arch/x86/pci/Makefile
+++ b/arch/x86/pci/Makefile
@@ -13,5 +13,7 @@ obj-$(CONFIG_X86_VISWS)		+= visws.o
 
 obj-$(CONFIG_X86_NUMAQ)		+= numaq_32.o
 
+obj-$(CONFIG_ARCH_PHYS_ADDR_T_64BIT)	+= dac_64bit.o
+
 obj-y				+= common.o early.o
 obj-y				+= amd_bus.o
diff --git a/arch/x86/pci/dac_64bit.c b/arch/x86/pci/dac_64bit.c
new file mode 100644
index 0000000..ee03c4a
--- /dev/null
+++ b/arch/x86/pci/dac_64bit.c
@@ -0,0 +1,44 @@
+/*
+ * Set up the 64-bit bus resource for allocations > 4G if the hardware
+ * is capable of generating Dual Address Cycle (DAC).
+ */
+
+#include <linux/pci.h>
+
+static struct resource mem64 = {
+	.name	= "PCI mem64",
+	.start	= (resource_size_t)1 << 32,	/* 4Gb */
+	.end	= -1,
+	.flags	= IORESOURCE_MEM,
+};
+
+void pcibios_pci64_setup(void)
+{
+	struct resource *r64 = &mem64, *root = &iomem_resource;
+	struct pci_bus *b;
+
+	if (insert_resource(root, r64)) {
+		printk(KERN_WARNING "PCI: Failed to allocate PCI64 space\n");
+		return;
+	}
+
+	list_for_each_entry(b, &pci_root_buses, node) {
+		/* Is this a "standard" root bus created by pci_create_bus? */
+		if (b->resource[1] != root || b->resource[2])
+			continue;
+		b->resource[2] = r64;	/* create DAC resource */
+	}
+}
+
+void pcibios_pci64_verify(void)
+{
+	struct pci_bus *b;
+
+	if (mem64.flags & IORESOURCE_MEM64)
+		return;		/* presumably DAC works */
+	list_for_each_entry(b, &pci_root_buses, node) {
+		if (b->resource[2] == &mem64)
+			b->resource[2] = NULL;
+	}
+	printk(KERN_INFO "PCI: allocations above 4G disabled\n");
+}
diff --git a/arch/x86/pci/i386.c b/arch/x86/pci/i386.c
index f1817f7..bf8eb75 100644
--- a/arch/x86/pci/i386.c
+++ b/arch/x86/pci/i386.c
@@ -137,6 +137,10 @@ static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
 					 * range.
 					 */
 					r->flags = 0;
+				} else {
+					/* Successful allocation */
+					if (upper_32_bits(r->start))
+						pr->flags |= IORESOURCE_MEM64;
 				}
 			}
 		}
@@ -174,6 +178,10 @@ static void __init pcibios_allocate_resources(int pass)
 					/* We'll assign a new address later */
 					r->end -= r->start;
 					r->start = 0;
+				} else {
+					/* Successful allocation */
+					if (upper_32_bits(r->start))
+						pr->flags |= IORESOURCE_MEM64;
 				}
 			}
 		}
@@ -225,9 +233,11 @@ static int __init pcibios_assign_resources(void)
 void __init pcibios_resource_survey(void)
 {
 	DBG("PCI: Allocating resources\n");
+	pcibios_pci64_setup();
 	pcibios_allocate_bus_resources(&pci_root_buses);
 	pcibios_allocate_resources(0);
 	pcibios_allocate_resources(1);
+	pcibios_pci64_verify();
 
 	e820_reserve_resources_late();
 }
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 32e4b2f..30403b3 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -49,6 +49,8 @@ struct resource_list {
 #define IORESOURCE_SIZEALIGN	0x00020000	/* size indicates alignment */
 #define IORESOURCE_STARTALIGN	0x00040000	/* start field is alignment */
 
+#define IORESOURCE_MEM64	0x00080000	/* 64-bit addressing, >4G */
+
 #define IORESOURCE_EXCLUSIVE	0x08000000	/* Userland may not map this resource */
 #define IORESOURCE_DISABLED	0x10000000
 #define IORESOURCE_UNSET	0x20000000

  parent reply	other threads:[~2009-04-20 22:32 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-11103-13546@http.bugzilla.kernel.org/>
     [not found] ` <200904101913.n3AJDhMm018684@demeter.kernel.org>
2009-04-10 20:27   ` [Bug 11103] Can't use framebuffer or vesa Xorg with two memory modules Yinghai Lu
2009-04-11  3:29     ` Yinghai Lu
2009-04-14 20:49       ` [PATCH] pci: don't assume pref memio are 64bit -v2 Yinghai Lu
2009-04-14 20:50         ` [PATCH] x86/pci: make pci_mem_start to be aligned only Yinghai Lu
2009-04-14 21:10           ` Linus Torvalds
2009-04-14 21:27             ` H. Peter Anvin
2009-04-14 21:27             ` Yinghai Lu
2009-04-14 22:35             ` Yannick Roehlly
2009-04-15  0:29             ` [PATCH] x86/pci: make pci_mem_start to be aligned only -v2 Yinghai Lu
2009-04-15  0:41               ` [PATCH] x86/pci: make pci_mem_start to be aligned only -v3 Yinghai Lu
2009-04-15  0:42                 ` [PATCH] x86/pci: fix -1 calling to e820_all_mapped with mmconfig Yinghai Lu
2009-04-16 16:31                 ` [PATCH] x86/pci: make pci_mem_start to be aligned only -v3 Jesse Barnes
2009-04-16 16:44                   ` Linus Torvalds
2009-04-16 16:56                     ` Ingo Molnar
2009-04-16 17:18                       ` Yinghai Lu
2009-04-16 17:27                         ` H. Peter Anvin
2009-04-16 17:38                           ` Ingo Molnar
2009-04-16 17:28                         ` Ingo Molnar
2009-04-16 20:13                           ` [PATCH] x86/pci: make pci_mem_start to be aligned only -v4 Yinghai Lu
2009-04-16 23:18                             ` Linus Torvalds
2009-04-16 23:54                               ` Ingo Molnar
2009-04-17  0:24                                 ` Linus Torvalds
2009-04-17 13:16                                   ` Ingo Molnar
2009-04-17 21:59                                     ` Yinghai Lu
2009-04-17 22:04                                     ` H. Peter Anvin
2009-04-18  5:37                                       ` [PATCH] pci: keep pci device resource name pointer right Yinghai Lu
2009-04-18  7:51                                         ` Ingo Molnar
2009-04-18 16:05                                           ` Jesse Barnes
2009-04-18 18:42                                         ` Linus Torvalds
2009-04-18 19:19                                           ` Yinghai Lu
2009-04-18 19:23                                             ` Greg KH
2009-04-18 20:00                                               ` Kay Sievers
2009-04-18 20:27                                                 ` Kay Sievers
2009-04-18 20:37                                                   ` Ingo Molnar
2009-04-18 22:05                                                     ` [PATCH] driver: dont update dev_name via device_add path Yinghai Lu
2009-04-28  7:36                                                       ` [PATCH] driver: make dev_set_name(, NULL) work Yinghai Lu
2009-04-28  7:42                                                         ` [RFC PATCH] use dev_set_name(,NULL) to prevent leaking Yinghai Lu
2009-04-28  8:25                                                           ` Kay Sievers
2009-04-28 15:21                                                             ` Yinghai Lu
2009-04-28 15:34                                                               ` Yinghai Lu
2009-04-28 15:39                                                                 ` Greg KH
2009-04-28 15:51                                                                   ` Yinghai Lu
2009-04-28 15:56                                                                     ` Kay Sievers
2009-04-28 16:08                                                                       ` Yinghai Lu
2009-04-28 16:15                                                                         ` Kay Sievers
2009-04-28 19:04                                                                           ` Yinghai Lu
2009-04-28 16:36                                                                       ` Yinghai Lu
2009-04-28 16:50                                                                         ` Kay Sievers
2009-04-28 14:52                                                           ` Greg KH
2009-04-28 14:51                                                         ` [PATCH] driver: make dev_set_name(, NULL) work Greg KH
2009-04-28 15:14                                                           ` Yinghai Lu
2009-04-28 15:39                                                             ` Greg KH
2009-04-18 21:07                                                   ` [PATCH] pci: keep pci device resource name pointer right Yinghai Lu
2009-04-18 22:17                                                   ` Linus Torvalds
2009-04-18 20:00                                               ` [PATCH] driver: dont update dev_name if it is not changed Yinghai Lu
2009-04-18 20:11                                                 ` Ingo Molnar
2009-04-18 20:20                                                   ` Yinghai Lu
2009-04-18 20:27                                                     ` Ingo Molnar
2009-04-18  8:33                               ` [PATCH] x86/pci: make pci_mem_start to be aligned only -v4 Yinghai Lu
2009-04-18  9:22                                 ` Ingo Molnar
2009-04-18 17:07                                   ` Yinghai Lu
2009-04-18 18:57                                   ` Linus Torvalds
2009-04-18 19:14                                     ` Ingo Molnar
2009-04-18 19:26                                       ` Yinghai Lu
2009-04-18 22:20                                         ` Yinghai Lu
2009-04-18 22:31                                         ` Linus Torvalds
2009-04-18 20:13                                       ` Ivan Kokshaysky
2009-04-18 18:50                                 ` Linus Torvalds
2009-04-18 22:44                                   ` Yinghai Lu
2009-04-18 23:01                                     ` Yinghai Lu
2009-04-18 23:06                                       ` Linus Torvalds
2009-04-18 23:26                                         ` Yinghai Lu
2009-04-18 23:30                                           ` Yinghai Lu
2009-04-18 23:04                                     ` Linus Torvalds
2009-04-19  0:32                                       ` H. Peter Anvin
2009-04-19  4:50                                       ` Linus Torvalds
2009-04-19  5:26                                         ` Yinghai Lu
2009-04-19 19:35                                           ` Yannick Roehlly
2009-04-19 19:59                                             ` Yinghai Lu
2009-04-19 20:24                                               ` Yannick Roehlly
2009-04-19  9:02                                         ` Ingo Molnar
2009-04-19  9:06                                           ` Ingo Molnar
2009-04-19 17:52                                             ` Jesse Barnes
2009-04-20 22:33                                             ` Ivan Kokshaysky [this message]
2009-04-20 22:52                                               ` Yinghai Lu
2009-04-21 10:54                                                 ` Ivan Kokshaysky
2009-04-21  0:09                                               ` Yinghai Lu
2009-04-21 10:56                                                 ` Ivan Kokshaysky
2009-04-21 15:57                                                   ` Yinghai Lu
2009-04-22 22:37                                                   ` [RFC PATCH 1/2] pci: don't assume pref memio are 64bit -v3 Yinghai Lu
2009-04-22 22:38                                                     ` [RFC PATCH 2/2] pci: try to assign res for device under transparent bridges Yinghai Lu
2009-04-22 22:49                                                     ` [RFC PATCH 1/2] pci: don't assume pref memio are 64bit -v3 Jesse Barnes
2009-04-23  0:49                                                       ` Yinghai Lu
2009-04-23  1:05                                                         ` Jesse Barnes
2009-04-23  2:03                                                           ` Yinghai Lu
2009-04-23 12:58                                                             ` Ivan Kokshaysky
2009-04-23 15:30                                                               ` Yinghai Lu
2009-04-23  2:10                                                           ` Yinghai Lu
2009-04-23 13:22                                                             ` Ivan Kokshaysky
2009-04-23 15:13                                                               ` Yinghai Lu
2009-04-23 22:19                                                                 ` Ivan Kokshaysky
2009-04-24  3:48                                                                   ` [PATCH 1/4] pci/x86: don't assume pref memio are 64bit -v4 Yinghai Lu
2009-04-24  3:49                                                                     ` [PATCH 2/4] pci: try to assign res for device under transparent bridges -v2 Yinghai Lu
2009-04-24  3:50                                                                     ` [PATCH 3/4] x86: reserve range near the ram Yinghai Lu
2009-04-24  3:50                                                                     ` [PATCH 4/4] x86/pci: make pci_mem_start to be aligned only -v5 Yinghai Lu
2009-04-24 13:16                                                                     ` [PATCH 1/4] pci/x86: don't assume pref memio are 64bit -v4 Ivan Kokshaysky
2009-05-05 18:52                                                                     ` Jesse Barnes
2009-05-06 12:33                                                                       ` Ingo Molnar
2009-05-06 15:06                                                                         ` [PATCH 1/2] x86: reserve range near the ram Yinghai Lu
2009-05-11  9:51                                                                           ` [tip:x86/mm] x86, e820, pci: reserve extra free space near end of RAM tip-bot for Linus Torvalds
2009-05-06 15:07                                                                         ` [PATCH 1/2] x86/pci: make pci_mem_start to be aligned only -v5 Yinghai Lu
2009-05-11  9:51                                                                           ` [tip:x86/mm] x86/pci: remove rounding quirk from e820_setup_gap() tip-bot for Yinghai Lu
2009-04-23 12:36                                                     ` [RFC PATCH 1/2] pci: don't assume pref memio are 64bit -v3 Ivan Kokshaysky
2009-04-23 12:41                                                       ` Ingo Molnar
2009-04-23 13:09                                                         ` Ivan Kokshaysky
2009-04-23 15:05                                                       ` Yinghai Lu
2009-04-21 15:41                                               ` [PATCH] x86/pci: make pci_mem_start to be aligned only -v4 Jesse Barnes

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=20090420223305.GA15340@jurassic.park.msu.ru \
    --to=ink@jurassic.park.msu.ru \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=yannick.roehlly@free.fr \
    --cc=yinghai@kernel.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
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.