Commit 8c30b1a7 authored by Andi Kleen's avatar Andi Kleen Committed by Linus Torvalds

[PATCH] i386/x86_64: Check if MCFG works for the first 16 busses

Previously only the first bus would be checked against Type 1.

Why 16? Checking all would need too much memory and we
can assume that systems with more than 16 busses have better than
average quality BIOS.

This is an additional defense against bad MCFG tables.
Signed-off-by: default avatarAndi Kleen <ak@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent e405d067
...@@ -17,12 +17,15 @@ ...@@ -17,12 +17,15 @@
#define MMCONFIG_APER_SIZE (256*1024*1024) #define MMCONFIG_APER_SIZE (256*1024*1024)
/* Assume systems with more busses have correct MCFG */
#define MAX_CHECK_BUS 16
#define mmcfg_virt_addr ((void __iomem *) fix_to_virt(FIX_PCIE_MCFG)) #define mmcfg_virt_addr ((void __iomem *) fix_to_virt(FIX_PCIE_MCFG))
/* The base address of the last MMCONFIG device accessed */ /* The base address of the last MMCONFIG device accessed */
static u32 mmcfg_last_accessed_device; static u32 mmcfg_last_accessed_device;
static DECLARE_BITMAP(fallback_slots, 32); static DECLARE_BITMAP(fallback_slots, MAX_CHECK_BUS*32);
/* /*
* Functions for accessing PCI configuration space with MMCONFIG accesses * Functions for accessing PCI configuration space with MMCONFIG accesses
...@@ -32,8 +35,8 @@ static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn) ...@@ -32,8 +35,8 @@ static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn)
int cfg_num = -1; int cfg_num = -1;
struct acpi_table_mcfg_config *cfg; struct acpi_table_mcfg_config *cfg;
if (seg == 0 && bus == 0 && if (seg == 0 && bus < MAX_CHECK_BUS &&
test_bit(PCI_SLOT(devfn), fallback_slots)) test_bit(PCI_SLOT(devfn) + 32*bus, fallback_slots))
return 0; return 0;
while (1) { while (1) {
...@@ -149,29 +152,34 @@ static struct pci_raw_ops pci_mmcfg = { ...@@ -149,29 +152,34 @@ static struct pci_raw_ops pci_mmcfg = {
Normally this can be expressed in the MCFG by not listing them Normally this can be expressed in the MCFG by not listing them
and assigning suitable _SEGs, but this isn't implemented in some BIOS. and assigning suitable _SEGs, but this isn't implemented in some BIOS.
Instead try to discover all devices on bus 0 that are unreachable using MM Instead try to discover all devices on bus 0 that are unreachable using MM
and fallback for them. and fallback for them. */
We only do this for bus 0/seg 0 */
static __init void unreachable_devices(void) static __init void unreachable_devices(void)
{ {
int i; int i, k;
unsigned long flags; unsigned long flags;
for (i = 0; i < 32; i++) { for (k = 0; k < MAX_CHECK_BUS; k++) {
u32 val1; for (i = 0; i < 32; i++) {
u32 addr; u32 val1;
u32 addr;
pci_conf1_read(0, 0, PCI_DEVFN(i, 0), 0, 4, &val1);
if (val1 == 0xffffffff) pci_conf1_read(0, k, PCI_DEVFN(i, 0), 0, 4, &val1);
continue; if (val1 == 0xffffffff)
continue;
/* Locking probably not needed, but safer */
spin_lock_irqsave(&pci_config_lock, flags); /* Locking probably not needed, but safer */
addr = get_base_addr(0, 0, PCI_DEVFN(i, 0)); spin_lock_irqsave(&pci_config_lock, flags);
if (addr != 0) addr = get_base_addr(0, k, PCI_DEVFN(i, 0));
pci_exp_set_dev_base(addr, 0, PCI_DEVFN(i, 0)); if (addr != 0)
if (addr == 0 || readl((u32 __iomem *)mmcfg_virt_addr) != val1) pci_exp_set_dev_base(addr, k, PCI_DEVFN(i, 0));
set_bit(i, fallback_slots); if (addr == 0 ||
spin_unlock_irqrestore(&pci_config_lock, flags); readl((u32 __iomem *)mmcfg_virt_addr) != val1) {
set_bit(i, fallback_slots);
printk(KERN_NOTICE
"PCI: No mmconfig possible on %x:%x\n", k, i);
}
spin_unlock_irqrestore(&pci_config_lock, flags);
}
} }
} }
......
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
#include "pci.h" #include "pci.h"
#define MMCONFIG_APER_SIZE (256*1024*1024) #define MMCONFIG_APER_SIZE (256*1024*1024)
/* Verify the first 16 busses. We assume that systems with more busses
get MCFG right. */
#define MAX_CHECK_BUS 16
static DECLARE_BITMAP(fallback_slots, 32); static DECLARE_BITMAP(fallback_slots, 32*MAX_CHECK_BUS);
/* Static virtual mapping of the MMCONFIG aperture */ /* Static virtual mapping of the MMCONFIG aperture */
struct mmcfg_virt { struct mmcfg_virt {
...@@ -57,7 +60,8 @@ static char __iomem *get_virt(unsigned int seg, unsigned bus) ...@@ -57,7 +60,8 @@ static char __iomem *get_virt(unsigned int seg, unsigned bus)
static char __iomem *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn) static char __iomem *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn)
{ {
char __iomem *addr; char __iomem *addr;
if (seg == 0 && bus == 0 && test_bit(PCI_SLOT(devfn), fallback_slots)) if (seg == 0 && bus < MAX_CHECK_BUS &&
test_bit(32*bus + PCI_SLOT(devfn), fallback_slots))
return NULL; return NULL;
addr = get_virt(seg, bus); addr = get_virt(seg, bus);
if (!addr) if (!addr)
...@@ -131,21 +135,26 @@ static struct pci_raw_ops pci_mmcfg = { ...@@ -131,21 +135,26 @@ static struct pci_raw_ops pci_mmcfg = {
Normally this can be expressed in the MCFG by not listing them Normally this can be expressed in the MCFG by not listing them
and assigning suitable _SEGs, but this isn't implemented in some BIOS. and assigning suitable _SEGs, but this isn't implemented in some BIOS.
Instead try to discover all devices on bus 0 that are unreachable using MM Instead try to discover all devices on bus 0 that are unreachable using MM
and fallback for them. and fallback for them. */
We only do this for bus 0/seg 0 */
static __init void unreachable_devices(void) static __init void unreachable_devices(void)
{ {
int i; int i, k;
for (i = 0; i < 32; i++) { /* Use the max bus number from ACPI here? */
u32 val1; for (k = 0; i < MAX_CHECK_BUS; k++) {
char __iomem *addr; for (i = 0; i < 32; i++) {
u32 val1;
pci_conf1_read(0, 0, PCI_DEVFN(i,0), 0, 4, &val1); char __iomem *addr;
if (val1 == 0xffffffff)
continue; pci_conf1_read(0, k, PCI_DEVFN(i,0), 0, 4, &val1);
addr = pci_dev_base(0, 0, PCI_DEVFN(i, 0)); if (val1 == 0xffffffff)
if (addr == NULL|| readl(addr) != val1) { continue;
set_bit(i, fallback_slots); addr = pci_dev_base(0, k, PCI_DEVFN(i, 0));
if (addr == NULL|| readl(addr) != val1) {
set_bit(i + 32*k, fallback_slots);
printk(KERN_NOTICE
"PCI: No mmconfig possible on device %x:%x\n",
k, i);
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment