All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Steven Newbury <steve@snewbury.org.uk>
Cc: "Barnes, Jesse" <jesse.barnes@intel.com>,
	Dave Airlie <airlied@linux.ie>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org,
	DRI mailing list <dri-devel@lists.freedesktop.org>
Subject: Re: PCI resources above 4GB
Date: Sun, 15 Apr 2012 23:54:56 -0700	[thread overview]
Message-ID: <CAE9FiQX7iVYZSoEJVVHJTx1gUSKh6RP+iJRGJqMZmDgkFDnPQQ@mail.gmail.com> (raw)
In-Reply-To: <CAE9FiQVzC2YCkXtFDPkCMVMcMqt9c0t8hKVvpgFpwjRdBen0Uw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

On Sun, Apr 15, 2012 at 1:06 PM, Yinghai Lu <yinghai@kernel.org> wrote:
>> 3. use pci_bus_allocate_resource in drm/radeon driver ... ===> but
>> that could fail.
>>   so could hack it like a. disable bar 0x10 and steal BAR address,
>> then set 0x30 to that address then copy ROM to ram.
>>   after that, disable rom again and set back address to 0x10.
>>   You try to update radeon_get_bios() to achieve that.

patches for solution 3:
map_rom.patch will try to borrow mem or mem pref bar for ROM copying

and You still need to use pci=norom

Yinghai

[-- Attachment #2: rom_option.patch --]
[-- Type: application/octet-stream, Size: 1673 bytes --]

Subject: [PATCH] PCI: Add is_pci_iov_resource_idx()

So we can remove one ifdef in setup-bus.c. and will share the code in that
ifdef block.

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

---
 drivers/pci/setup-bus.c |    7 +++----
 include/linux/pci.h     |    8 ++++++++
 2 files changed, 11 insertions(+), 4 deletions(-)

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
@@ -813,16 +813,15 @@ static int pbus_size_mem(struct pci_bus
 			if (r->parent || (r->flags & mask) != type)
 				continue;
 			r_size = resource_size(r);
-#ifdef CONFIG_PCI_IOV
+
 			/* put SRIOV requested res to the optional list */
-			if (realloc_head && i >= PCI_IOV_RESOURCES &&
-					i <= PCI_IOV_RESOURCE_END) {
+			if (realloc_head && is_pci_iov_resource_idx(i)) {
 				r->end = r->start - 1;
 				add_to_list(realloc_head, dev, r, r_size, 0/* dont' care */);
 				children_add_size += r_size;
 				continue;
 			}
-#endif
+
 			/* For bridges size != alignment */
 			align = pci_resource_alignment(dev, r);
 			order = __ffs(align) - 20;
Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -114,6 +114,14 @@ enum {
 	DEVICE_COUNT_RESOURCE = PCI_NUM_RESOURCES,
 };
 
+static inline bool is_pci_iov_resource_idx(int i)
+{
+#ifdef CONFIG_PCI_IOV
+	return i >= PCI_IOV_RESOURCES && i <= PCI_IOV_RESOURCE_END;
+#endif
+	return false;
+}
+
 typedef int __bitwise pci_power_t;
 
 #define PCI_D0		((pci_power_t __force) 0)

[-- Attachment #3: rom_option_1.patch --]
[-- Type: application/octet-stream, Size: 2254 bytes --]

Subject: [PATCH] PCI: Treat ROM resource as optional during assigning.

So will try to allocate them together with requested ones, if can not assign
them, could go with requested one only, and just skip ROM resource.

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

---
 drivers/pci/setup-bus.c |   21 +++++++--------------
 include/linux/pci.h     |    5 +++++
 2 files changed, 12 insertions(+), 14 deletions(-)

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
@@ -286,18 +286,10 @@ static void assign_requested_resources_s
 		idx = res - &dev_res->dev->resource[0];
 		if (resource_size(res) &&
 		    pci_assign_resource_fit(dev_res->dev, idx, fit)) {
-			if (fail_head) {
-				/*
-				 * if the failed res is for ROM BAR, and it will
-				 * be enabled later, don't add it to the list
-				 */
-				if (!((idx == PCI_ROM_RESOURCE) &&
-				      (!(res->flags & IORESOURCE_ROM_ENABLE))))
-					add_to_list(fail_head,
-						    dev_res->dev, res,
-						    0 /* dont care */,
-						    0 /* dont care */);
-			}
+			if (fail_head)
+				add_to_list(fail_head, dev_res->dev, res,
+					    0 /* dont care */,
+					    0 /* dont care */);
 			reset_resource(res);
 		}
 	}
@@ -814,8 +806,9 @@ static int pbus_size_mem(struct pci_bus
 				continue;
 			r_size = resource_size(r);
 
-			/* put SRIOV requested res to the optional list */
-			if (realloc_head && is_pci_iov_resource_idx(i)) {
+			/* put SRIOV/ROM requested res to the optional list */
+			if (realloc_head && (is_pci_iov_resource_idx(i) ||
+					     is_pci_rom_resource_idx(i))) {
 				r->end = r->start - 1;
 				add_to_list(realloc_head, dev, r, r_size, 0/* dont' care */);
 				children_add_size += r_size;
Index: linux-2.6/include/linux/pci.h
===================================================================
--- linux-2.6.orig/include/linux/pci.h
+++ linux-2.6/include/linux/pci.h
@@ -122,6 +122,11 @@ static inline bool is_pci_iov_resource_i
 	return false;
 }
 
+static inline bool is_pci_rom_resource_idx(int i)
+{
+	return i == PCI_ROM_RESOURCE;
+}
+
 typedef int __bitwise pci_power_t;
 
 #define PCI_D0		((pci_power_t __force) 0)

[-- Attachment #4: map_rom.patch --]
[-- Type: application/octet-stream, Size: 4307 bytes --]

Subject: [PATCH] PCI: Borrow dev mem windows to copy ROM

If the mem bar is not used yet and size is bigger enough.

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

---
 arch/x86/pci/common.c   |    3 +
 drivers/pci/rom.c       |   73 ++++++++++++++++++++++++++++++++++++++++++++++--
 drivers/pci/setup-bus.c |    8 ++++-
 3 files changed, 79 insertions(+), 5 deletions(-)

Index: linux-2.6/drivers/pci/rom.c
===================================================================
--- linux-2.6.orig/drivers/pci/rom.c
+++ linux-2.6/drivers/pci/rom.c
@@ -116,6 +116,10 @@ void __iomem *pci_map_rom(struct pci_dev
 	struct resource *res = &pdev->resource[PCI_ROM_RESOURCE];
 	loff_t start;
 	void __iomem *rom;
+	int i = -1;
+	struct resource *mem_r = NULL;
+	resource_size_t mem_r_start = 0;
+	resource_size_t mem_r_size = 0;
 
 	/*
 	 * IORESOURCE_ROM_SHADOW set on x86, x86_64 and IA64 supports legacy
@@ -135,8 +139,45 @@ void __iomem *pci_map_rom(struct pci_dev
 		} else {
 			/* assign the ROM an address if it doesn't have one */
 			if (res->parent == NULL &&
-			    pci_assign_resource(pdev,PCI_ROM_RESOURCE))
-				return NULL;
+			    pci_assign_resource(pdev,PCI_ROM_RESOURCE)) {
+				struct resource *r;
+
+				if (res->flags || !res->end ||
+				    !resource_size(res))
+					return NULL;
+
+				/* borrow MEM resource windows */
+				for (i = 0; i < PCI_ROM_RESOURCE; i++) {
+					r = &pdev->resource[i];
+					if (!r->parent ||
+					    (r->flags & IORESOURCE_MEM) ||
+					    r->child ||
+					    resource_size(r) < resource_size(res) ||
+					    r->start >= (1ULL<<32))
+						continue;
+					/* found one */
+					mem_r = r;
+					break;
+				}
+				if (!mem_r) {
+					i = -1;
+					return NULL;
+				}
+				/* disable mem_r temperily */
+				mem_r_start = mem_r->start;
+				mem_r_size = resource_size(mem_r);
+				mem_r->start = 0xffff0000;
+				mem_r->end = 0;
+				pci_update_resource(pdev, i);
+				/* restore flags */
+				res->flags = IORESOURCE_MEM |
+					     IORESOURCE_PREFETCH |
+					     IORESOURCE_READONLY |
+					     IORESOURCE_CACHEABLE |
+					     IORESOURCE_SIZEALIGN;
+				res->end = resource_size(res) + mem_r_start - 1;
+				res->start = mem_r_start;
+			}
 			start = pci_resource_start(pdev, PCI_ROM_RESOURCE);
 			*size = pci_resource_len(pdev, PCI_ROM_RESOURCE);
 			if (*size == 0)
@@ -155,7 +196,7 @@ void __iomem *pci_map_rom(struct pci_dev
 				    IORESOURCE_ROM_SHADOW |
 				    IORESOURCE_ROM_COPY)))
 			pci_disable_rom(pdev);
-		return NULL;
+		goto restore_mem_r;
 	}
 
 	/*
@@ -164,6 +205,32 @@ void __iomem *pci_map_rom(struct pci_dev
 	 * True size is important if the ROM is going to be copied.
 	 */
 	*size = pci_get_rom_size(pdev, rom, *size);
+
+	/* copy rom and restore borrow mem io */
+	if (i >= 0) {
+		void __iomem *new_rom;
+
+		new_rom = kmalloc(*size, GFP_KERNEL);
+		if (new_rom)
+			memcpy_fromio(new_rom, rom, *size);
+		pci_unmap_rom(pdev, rom);
+		if (new_rom) {
+			res->start = (unsigned long long)new_rom;
+			res->end = res->start + *size;
+			res->flags |= IORESOURCE_ROM_COPY;
+		} else {
+			res->start = res->end = res->flags = 0;
+		}
+		rom = new_rom;
+	}
+
+restore_mem_r:
+	if (i >= 0) {
+		mem_r->start = mem_r_start;
+		mem_r->end = mem_r_size + mem_r->start - 1;
+		pci_update_resource(pdev, i);
+	}
+
 	return rom;
 }
 
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
@@ -290,7 +290,13 @@ static void assign_requested_resources_s
 				add_to_list(fail_head, dev_res->dev, res,
 					    0 /* dont care */,
 					    0 /* dont care */);
-			reset_resource(res);
+			/* need to save the size */
+			if (idx == PCI_ROM_RESOURCE) {
+				res->flags = 0;
+				res->end -= res->start;
+				res->start = 0;
+			} else
+				reset_resource(res);
 		}
 	}
 }
Index: linux-2.6/arch/x86/pci/common.c
===================================================================
--- linux-2.6.orig/arch/x86/pci/common.c
+++ linux-2.6/arch/x86/pci/common.c
@@ -151,7 +151,8 @@ static void __devinit pcibios_fixup_devi
 			/* we deal with BIOS assigned ROM later */
 			return;
 		}
-		rom_r->start = rom_r->end = rom_r->flags = 0;
+		/* need to save the size */
+		rom_r->flags = 0;
 	}
 }
 

  reply	other threads:[~2012-04-16  6:54 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-09 10:49 PCI resources above 4GB Steven Newbury
2012-04-10  0:51 ` Bjorn Helgaas
2012-04-10 10:53   ` Steven Newbury
2012-04-10 15:16     ` Yinghai Lu
     [not found]       ` <4F8467AA.90305@snewbury.org.uk>
2012-04-10 17:29         ` Steven Newbury
2012-04-10 18:40         ` Yinghai Lu
2012-04-10 18:44           ` Steven Newbury
2012-04-10 19:00           ` Steven Newbury
2012-04-10 19:04             ` Steven Newbury
2012-04-10 19:16             ` Yinghai Lu
2012-04-10 19:46               ` Steven Newbury
2012-04-10 20:07                 ` Yinghai Lu
2012-04-10 20:26                   ` Steven Newbury
2012-04-10 20:45                     ` Yinghai Lu
2012-04-10 21:19                       ` Steven Newbury
2012-04-11  3:37                         ` Bjorn Helgaas
2012-04-11  5:33                           ` Steven Newbury
2012-04-11  9:03                             ` Steven Newbury
2012-04-11 14:33                           ` Steven Newbury
2012-04-11 23:59                             ` Bjorn Helgaas
2012-04-12 11:39                               ` Steven Newbury
2012-04-12  0:57                         ` Yinghai Lu
2012-04-12 11:22                           ` Steven Newbury
2012-04-12 16:07                             ` Yinghai Lu
2012-04-12 16:40                               ` Steven Newbury
2012-04-13  8:26                                 ` Yinghai Lu
2012-04-13  8:34                                   ` Steven Newbury
2012-04-13 11:45                                   ` Steven Newbury
2012-04-13 11:58                                     ` Steven Newbury
2012-04-13 11:58                                       ` Steven Newbury
2012-04-13 12:49                                       ` Steven Newbury
2012-04-13 12:49                                         ` Steven Newbury
2012-04-13 13:26                                         ` Steven Newbury
2012-04-13 13:26                                           ` Steven Newbury
2012-04-13 13:52                                           ` drm-next i915 regression? ( was: Re: PCI resources above 4GB) Steven Newbury
2012-04-13 14:08                                             ` Steven Newbury
2012-04-13 14:08                                               ` Steven Newbury
2012-04-13 14:13                                               ` Daniel Vetter
2012-04-13 14:19                                                 ` Steven Newbury
2012-04-13 15:23                                                   ` Steven Newbury
2012-04-13 15:23                                                     ` Steven Newbury
2012-04-13 15:49                                                     ` Steven Newbury
2012-04-13 16:17                                                       ` Yinghai Lu
2012-04-13 17:12                                                         ` btrfs oops [was Re: drm-next i915 regression? ( was: Re: PCI resources above 4GB)] Steven Newbury
2012-04-13 17:38                                                         ` drm-next i915 regression? ( was: Re: PCI resources above 4GB) Steven Newbury
2012-04-13 18:12                                                           ` Steven Newbury
2012-04-13 21:51                                                             ` Btrfs corruption Oops " Steven Newbury
2012-04-14 17:37                                 ` PCI resources above 4GB Steven Newbury
2012-04-14 17:37                                   ` Steven Newbury
2012-04-14 18:05                                   ` Steven Newbury
2012-04-14 18:05                                     ` Steven Newbury
2012-04-14 18:42                                     ` Steven Newbury
2012-04-14 18:42                                       ` Steven Newbury
2012-04-14 19:08                                       ` Steven Newbury
2012-04-14 19:08                                         ` Steven Newbury
2012-04-14 19:21                                         ` Steven Newbury
2012-04-14 19:21                                           ` Steven Newbury
2012-04-14 20:48                                           ` Yinghai Lu
2012-04-15 10:19                                             ` Steven Newbury
2012-04-15 10:19                                               ` Steven Newbury
2012-04-15 10:20                                             ` Steven Newbury
2012-04-15 10:20                                               ` Steven Newbury
2012-04-15 11:37                                               ` Steven Newbury
2012-04-15 11:37                                                 ` Steven Newbury
2012-04-15 17:25                                                 ` Steven Newbury
2012-04-15 17:25                                                   ` Steven Newbury
2012-04-15 17:31                                                   ` Steven Newbury
2012-04-15 17:31                                                     ` Steven Newbury
2012-04-15 20:05                                                     ` Yinghai Lu
2012-04-15 20:06                                                       ` Yinghai Lu
2012-04-16  6:54                                                         ` Yinghai Lu [this message]
2012-04-16  7:01                                                           ` Steven Newbury
2012-04-16  7:01                                                             ` Steven Newbury
2012-04-16 17:29                                                           ` Yinghai Lu
2012-04-18  7:21                                                             ` Steven Newbury
2012-04-18  7:21                                                               ` Steven Newbury
2012-04-24  9:49                                                             ` Steven Newbury
2012-04-24  9:49                                                               ` Steven Newbury
     [not found]                                                               ` <4FB227D3.7090002@snewbury.org.uk>
     [not found]                                                                 ` <CAE9FiQX48eCS85eWMFxm6fCWgu2zwxvSywtQhsf-35WEvBfJVQ@mail.gmail.com>
2012-05-17 12:27                                                                   ` Steven Newbury
2012-05-17 12:34                                                                     ` Steven Newbury
2012-05-17 16:36                                                                       ` Yinghai Lu
2012-05-18  7:45                                                                         ` Yinghai Lu
2012-05-18  9:08                                                                           ` Yinghai Lu
2012-05-21 17:27                                                                             ` Steven Newbury
2012-05-21 17:27                                                                               ` Steven Newbury
2012-05-29 23:19                                                                               ` Bjorn Helgaas
2012-06-01 23:06                                                                                 ` Bjorn Helgaas
2012-04-15  3:21                                   ` Yinghai Lu
2012-04-15 10:18                                     ` Steven Newbury
2012-04-15 10:18                                       ` Steven Newbury
2012-04-15 11:31                                     ` Steven Newbury
2012-04-15 11:31                                       ` Steven Newbury
2012-04-12 16:29                             ` Steven Newbury
2012-04-11 11:43                       ` Steven Newbury

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=CAE9FiQX7iVYZSoEJVVHJTx1gUSKh6RP+iJRGJqMZmDgkFDnPQQ@mail.gmail.com \
    --to=yinghai@kernel.org \
    --cc=airlied@linux.ie \
    --cc=bhelgaas@google.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jesse.barnes@intel.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=steve@snewbury.org.uk \
    /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.