All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: bugzilla-daemon@bugzilla.kernel.org,
	Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linux-pci@vger.kernel.org, yannick.roehlly@free.fr
Subject: Re: [Bug 11103] Can't use framebuffer or vesa Xorg with two memory modules
Date: Fri, 10 Apr 2009 20:29:35 -0700	[thread overview]
Message-ID: <49E00E9F.8030605@kernel.org> (raw)
In-Reply-To: <49DFABCC.3070001@kernel.org>

please check

[PATCH] pci: don't assume pref mem io are 64bit

Impact: fix bug with some devices

one system with 4g installed ( there is 1g hole)

when 4G installed.
BIOS put ACPI etc need the hole
[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: 0000000000000000 - 000000000009bc00 (usable)
[    0.000000]  BIOS-e820: 000000000009bc00 - 00000000000a0000 (reserved)
[    0.000000]  BIOS-e820: 00000000000e3000 - 0000000000100000 (reserved)
[    0.000000]  BIOS-e820: 0000000000100000 - 00000000bffa0000 (usable)
[    0.000000]  BIOS-e820: 00000000bffa0000 - 00000000bffae000 (ACPI data)
[    0.000000]  BIOS-e820: 00000000bffae000 - 00000000bfff0000 (ACPI NVS)
[    0.000000]  BIOS-e820: 00000000bfff0000 - 00000000c0000000 (reserved)
[    0.000000]  BIOS-e820: 00000000fee00000 - 00000000fee01000 (reserved)
[    0.000000]  BIOS-e820: 00000000ffb00000 - 0000000100000000 (reserved)
[    0.000000]  BIOS-e820: 0000000100000000 - 0000000140000000 (usable)
so in kernel resource will be reserved for 0xbffa0000 - 0xbfff0000 for ACPI
0x100000 -  0xbffa0000 for RAM...

and BIOS set
[    0.240007] pci 0000:00:01.0: bridge 64bit mmio pref: [0xbdf00000-0xddefffff]
[    0.237102] pci 0000:01:00.0: reg 10 32bit mmio: [0xc0000000-0xcfffffff]
that is conflict with reserved res. so it can not be reserved Kernel.

then Kernel try to get range from 0x140000000 ( above the RAM, 5G and above 4g)
and set let the bridge to use it, and ATI cards to use it.

but the problem is that ATI only support 32bit ...

we should not assign 64bit range to pci device that only take 32bit pref

try to set PCI_PREF_RANGE_TYPE_64 in 64bit resource of pci_device (besides in pci_bridge),
and make the bus resource only have that bit set when all device under that do support
64bit pref mem
then use that flag to decide the max limit for find/request.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 drivers/pci/bus.c       |    8 +++++++-
 drivers/pci/probe.c     |    8 ++++++--
 drivers/pci/setup-bus.c |   38 ++++++++++++++++++++++++++++----------
 3 files changed, 41 insertions(+), 13 deletions(-)

Index: linux-2.6/drivers/pci/bus.c
===================================================================
--- linux-2.6.orig/drivers/pci/bus.c
+++ linux-2.6/drivers/pci/bus.c
@@ -41,9 +41,15 @@ pci_bus_alloc_resource(struct pci_bus *b
 		void *alignf_data)
 {
 	int i, ret = -ENOMEM;
+	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_PREFETCH | PCI_PREF_RANGE_TYPE_64)) ==
+	    IORESOURCE_PREFETCH)
+		max = 0xffffffff;
+
 	for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
 		struct resource *r = bus->resource[i];
 		if (!r)
@@ -62,7 +68,7 @@ pci_bus_alloc_resource(struct pci_bus *b
 		/* Ok, try it out.. */
 		ret = allocate_resource(r, res, size,
 					r->start ? : min,
-					-1, align,
+					max, align,
 					alignf, alignf_data);
 		if (ret == 0)
 			break;
Index: linux-2.6/drivers/pci/probe.c
===================================================================
--- linux-2.6.orig/drivers/pci/probe.c
+++ linux-2.6/drivers/pci/probe.c
@@ -193,7 +193,7 @@ int __pci_read_base(struct pci_dev *dev,
 		res->flags |= pci_calc_resource_flags(l) | IORESOURCE_SIZEALIGN;
 		if (type == pci_bar_io) {
 			l &= PCI_BASE_ADDRESS_IO_MASK;
-			mask = PCI_BASE_ADDRESS_IO_MASK & 0xffff;
+			mask = PCI_BASE_ADDRESS_IO_MASK & IO_SPACE_LIMIT;
 		} else {
 			l &= PCI_BASE_ADDRESS_MEM_MASK;
 			mask = (u32)PCI_BASE_ADDRESS_MEM_MASK;
@@ -237,6 +237,9 @@ int __pci_read_base(struct pci_dev *dev,
 			dev_printk(KERN_DEBUG, &dev->dev,
 				"reg %x 64bit mmio: %pR\n", pos, res);
 		}
+
+		if (res->flags & IORESOURCE_PREFETCH)
+			res->flags |= PCI_PREF_RANGE_TYPE_64;
 	} else {
 		sz = pci_size(l, sz, mask);
 
@@ -362,7 +365,8 @@ void __devinit pci_read_bridge_bases(str
 		}
 	}
 	if (base <= limit) {
-		res->flags = (mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | IORESOURCE_MEM | IORESOURCE_PREFETCH;
+		res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) |
+					 IORESOURCE_MEM | IORESOURCE_PREFETCH;
 		res->start = base;
 		res->end = limit + 0xfffff;
 		dev_printk(KERN_DEBUG, &dev->dev, "bridge %sbit mmio pref: %pR\n",
Index: linux-2.6/drivers/pci/setup-bus.c
===================================================================
--- linux-2.6.orig/drivers/pci/setup-bus.c
+++ linux-2.6/drivers/pci/setup-bus.c
@@ -143,6 +143,7 @@ static void pci_setup_bridge(struct pci_
 	struct pci_dev *bridge = bus->self;
 	struct pci_bus_region region;
 	u32 l, bu, lu, io_upper16;
+	int pref_mem64;
 
 	if (pci_is_enabled(bridge))
 		return;
@@ -198,16 +199,22 @@ static void pci_setup_bridge(struct pci_
 	pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, 0);
 
 	/* Set up PREF base/limit. */
+	pref_mem64 = 0;
 	bu = lu = 0;
 	pcibios_resource_to_bus(bridge, &region, bus->resource[2]);
 	if (bus->resource[2]->flags & IORESOURCE_PREFETCH) {
+		int width = 8;
 		l = (region.start >> 16) & 0xfff0;
 		l |= region.end & 0xfff00000;
-		bu = upper_32_bits(region.start);
-		lu = upper_32_bits(region.end);
-		dev_info(&bridge->dev, "  PREFETCH window: %#016llx-%#016llx\n",
-		    (unsigned long long)region.start,
-		    (unsigned long long)region.end);
+		if (bus->resource[2]->flags & PCI_PREF_RANGE_TYPE_64) {
+			pref_mem64 = 1;
+			bu = upper_32_bits(region.start);
+			lu = upper_32_bits(region.end);
+			width = 16;
+		}
+		dev_info(&bridge->dev, "  PREFETCH window: %#0*llx-%#0*llx\n",
+				width, (unsigned long long)region.start,
+				width, (unsigned long long)region.end);
 	}
 	else {
 		l = 0x0000fff0;
@@ -215,9 +222,11 @@ static void pci_setup_bridge(struct pci_
 	}
 	pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, l);
 
-	/* Set the upper 32 bits of PREF base & limit. */
-	pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu);
-	pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu);
+	if (pref_mem64) {
+		/* Set the upper 32 bits of PREF base & limit. */
+		pci_write_config_dword(bridge, PCI_PREF_BASE_UPPER32, bu);
+		pci_write_config_dword(bridge, PCI_PREF_LIMIT_UPPER32, lu);
+	}
 
 	pci_write_config_word(bridge, PCI_BRIDGE_CONTROL, bus->bridge_ctl);
 }
@@ -255,8 +264,11 @@ static void pci_bridge_check_ranges(stru
 		pci_read_config_dword(bridge, PCI_PREF_MEMORY_BASE, &pmem);
 		pci_write_config_dword(bridge, PCI_PREF_MEMORY_BASE, 0x0);
 	}
-	if (pmem)
+	if (pmem) {
 		b_res[2].flags |= IORESOURCE_MEM | IORESOURCE_PREFETCH;
+		if ((pmem & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64)
+			b_res[2].flags |= PCI_PREF_RANGE_TYPE_64;
+	}
 }
 
 /* Helper function for sizing routines: find first available
@@ -336,6 +348,7 @@ static int pbus_size_mem(struct pci_bus
 	resource_size_t aligns[12];	/* Alignments from 1Mb to 2Gb */
 	int order, max_order;
 	struct resource *b_res = find_free_bus_resource(bus, type);
+	unsigned int mem64_mask = 0;
 
 	if (!b_res)
 		return 0;
@@ -344,6 +357,9 @@ static int pbus_size_mem(struct pci_bus
 	max_order = 0;
 	size = 0;
 
+	if (type & IORESOURCE_PREFETCH)
+		mem64_mask = PCI_PREF_RANGE_TYPE_64;
+
 	list_for_each_entry(dev, &bus->devices, bus_list) {
 		int i;
 		
@@ -372,6 +388,8 @@ static int pbus_size_mem(struct pci_bus
 				aligns[order] += align;
 			if (order > max_order)
 				max_order = order;
+			if (r->flags & IORESOURCE_PREFETCH)
+				mem64_mask &= r->flags & PCI_PREF_RANGE_TYPE_64;
 		}
 	}
 
@@ -395,7 +413,7 @@ static int pbus_size_mem(struct pci_bus
 	}
 	b_res->start = min_align;
 	b_res->end = size + min_align - 1;
-	b_res->flags |= IORESOURCE_STARTALIGN;
+	b_res->flags |= IORESOURCE_STARTALIGN | mem64_mask;
 	return 1;
 }
 

  reply	other threads:[~2009-04-11  3:31 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 [this message]
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
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=49E00E9F.8030605@kernel.org \
    --to=yinghai@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=bugzilla-daemon@bugzilla.kernel.org \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    --cc=yannick.roehlly@free.fr \
    /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.