From: "Yinghai Lu" <yinghai.lu@amd.com>
To: "Andrew Morton" <akpm@osdl.org>
Cc: "Greg KH" <gregkh@suse.de>, "Andi Kleen" <ak@suse.de>,
linux-kernel <linux-kernel@vger.kernel.org>,
myles@mouselemur.cs.byu.edu
Subject: Re: [Patch] PCI: check szhi when sz is 0 for 64 bit pref mem
Date: Mon, 6 Nov 2006 20:35:04 -0800 [thread overview]
Message-ID: <86802c440611062035m7b530ct5e79174e4008f32b@mail.gmail.com> (raw)
In-Reply-To: <20061106160441.1a06bf76.akpm@osdl.org>
[-- Attachment #1: Type: text/plain, Size: 38 bytes --]
please check version with pci_size64.
[-- Attachment #2: pci_64bit_pref_4g_1106.patch --]
[-- Type: text/x-patch, Size: 3056 bytes --]
[PATCH] PCI: check szhi when sz is 0 when 64 bit iomem bigger than 4G
If the PCI device is 64-bit memory and has a size of 0xnnnnnnnn00000000 then
pci_read_bases() will incorrectly assume that it has a size of zero.
Cc: Myles Watson <myles@mouselemur.cs.byu.edu>
Signed-off-by: Yinghai Lu <yinghai.lu@amd.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index e159d66..0e2b10c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -144,6 +144,24 @@ static u32 pci_size(u32 base, u32 maxbas
return size;
}
+static u64 pci_size64(u64 base, u64 maxbase, u64 mask)
+{
+ u64 size = mask & maxbase; /* Find the significant bits */
+ if (!size)
+ return 0;
+
+ /* Get the lowest of them to find the decode size, and
+ from that the extent. */
+ size = (size & ~(size-1)) - 1;
+
+ /* base == maxbase can be valid only if the BAR has
+ already been programmed with all 1s. */
+ if (base == maxbase && ((base | size) & mask) != mask)
+ return 0;
+
+ return size;
+}
+
static void pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
{
unsigned int pos, reg, next;
@@ -151,6 +169,7 @@ static void pci_read_bases(struct pci_de
struct resource *res;
for(pos=0; pos<howmany; pos = next) {
+ u64 l64, sz64;
next = pos+1;
res = &dev->resource[pos];
res->name = pci_name(dev);
@@ -164,9 +183,15 @@ static void pci_read_bases(struct pci_de
if (l == 0xffffffff)
l = 0;
if ((l & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY) {
+ sz64 = sz;
sz = pci_size(l, sz, (u32)PCI_BASE_ADDRESS_MEM_MASK);
- if (!sz)
- continue;
+ /* for 64bit pref, sz could be 0, if the real size is bigger than 4G,
+ so need to check szhi for it
+ */
+ if ((l & (PCI_BASE_ADDRESS_SPACE | PCI_BASE_ADDRESS_MEM_TYPE_MASK))
+ != (PCI_BASE_ADDRESS_SPACE_MEMORY | PCI_BASE_ADDRESS_MEM_TYPE_64))
+ if (!sz)
+ continue;
res->start = l & PCI_BASE_ADDRESS_MEM_MASK;
res->flags |= l & ~PCI_BASE_ADDRESS_MEM_MASK;
} else {
@@ -185,17 +210,21 @@ static void pci_read_bases(struct pci_de
pci_write_config_dword(dev, reg+4, ~0);
pci_read_config_dword(dev, reg+4, &szhi);
pci_write_config_dword(dev, reg+4, lhi);
- szhi = pci_size(lhi, szhi, 0xffffffff);
+ sz64 |= ((unsigned long) szhi) << 32;
+ l64 = (((unsigned long) lhi) << 32) | l;
+ sz64 = pci_size64(l64, sz64, PCI_BASE_ADDRESS_MEM_MASK);
next++;
#if BITS_PER_LONG == 64
- res->start |= ((unsigned long) lhi) << 32;
- res->end = res->start + sz;
- if (szhi) {
- /* This BAR needs > 4GB? Wow. */
- res->end |= (unsigned long)szhi<<32;
+ if (!sz64) {
+ res->start = 0;
+ res->end = 0;
+ res->flags = 0;
+ continue;
}
+ res->start = l64 & PCI_BASE_ADDRESS_MEM_MASK;
+ res->end = res->start + sz64;
#else
- if (szhi) {
+ if (sz64>0x100000000ULL) {
printk(KERN_ERR "PCI: Unable to handle 64-bit BAR for device %s\n", pci_name(dev));
res->start = 0;
res->flags = 0;
next prev parent reply other threads:[~2006-11-07 4:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-06 22:15 Lu, Yinghai
2006-11-07 0:04 ` Andrew Morton
2006-11-07 4:35 ` Yinghai Lu [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-11-08 19:15 Lu, Yinghai
2006-11-10 0:50 ` Greg KH
2006-11-04 5:27 Yinghai Lu
2006-11-06 22:04 ` Andrew Morton
2006-11-08 18:19 ` Eric W. Biederman
2006-11-08 19:10 ` Andrew Morton
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=86802c440611062035m7b530ct5e79174e4008f32b@mail.gmail.com \
--to=yinghai.lu@amd.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=myles@mouselemur.cs.byu.edu \
/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
all inboxes | Powered by JetHome®