From patchwork Wed Jul 15 20:20:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barnes X-Patchwork-Id: 35747 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6FKKodY015067 for ; Wed, 15 Jul 2009 20:20:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932266AbZGOUUt (ORCPT ); Wed, 15 Jul 2009 16:20:49 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932269AbZGOUUt (ORCPT ); Wed, 15 Jul 2009 16:20:49 -0400 Received: from outbound-mail-309.bluehost.com ([67.222.54.2]:41514 "HELO outbound-mail-309.bluehost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S932266AbZGOUUs (ORCPT ); Wed, 15 Jul 2009 16:20:48 -0400 Received: (qmail 10636 invoked by uid 0); 15 Jul 2009 20:20:48 -0000 Received: from unknown (HELO box514.bluehost.com) (74.220.219.114) by outboundproxy6.bluehost.com with SMTP; 15 Jul 2009 20:20:48 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=virtuousgeek.org; h=Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type:Content-Transfer-Encoding:X-Identified-User; b=kxRIByqSCnc93u1YdnzEHI+IHZxNmxn2F5iICQctckOVC4tbRN/Ume/4nwZ33OzHBtbXRsCTgY4ARSqZ+RGIF5MaVbKyayjinq9W9DjCtfwyk0YtRjCIlc+4oNpHt/xb; Received: from [75.111.28.251] (helo=jbarnes-g45) by box514.bluehost.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1MRAy8-0002hS-18; Wed, 15 Jul 2009 14:20:48 -0600 Date: Wed, 15 Jul 2009 13:20:45 -0700 From: Jesse Barnes To: linux-pci@vger.kernel.org Cc: Matthew Wilcox , x86@kernel.org, jacob.jun.pan@intel.com Subject: [PATCH] x86/PCI: Moorestown PCI support Message-ID: <20090715132045.2bc669e0@jbarnes-g45> In-Reply-To: <20090715131939.37a4836a@jbarnes-g45> References: <20090715131939.37a4836a@jbarnes-g45> X-Mailer: Claws Mail 3.6.1 (GTK+ 2.16.1; i486-pc-linux-gnu) Mime-Version: 1.0 X-Identified-User: {10642:box514.bluehost.com:virtuous:virtuousgeek.org} {sentby:smtp auth 75.111.28.251 authed with jbarnes@virtuousgeek.org} Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The Moorestown platform only has a few devices that actually support PCI config cycles. The rest of the devices use an in-RAM MCFG space for the purposes of device enumeration and initialization. There are a few uglies in the fake support, like BAR sizes that aren't a power of two, sizing detection, and writes to the real devices, but other than that it's pretty straightforward. Another way to think of this is not really as PCI at all, but just a table in RAM describing which devices are present, their capabilities and their offsets in MMIO space. This could have been done with a special new firmware table on this platform, but given that we do have some real PCI devices too, simply describing things in an MCFG type space was pretty simple. Signed-off-by: Jesse Barnes Signed-off-by: Jacob Pan --- arch/x86/Kconfig | 4 + arch/x86/include/asm/pci_x86.h | 6 + arch/x86/pci/Makefile | 1 + arch/x86/pci/fixup.c | 10 ++ arch/x86/pci/init.c | 3 + arch/x86/pci/mmconfig-shared.c | 3 +- arch/x86/pci/mmconfig_32.c | 2 +- arch/x86/pci/mrst.c | 228 ++++++++++++++++++++++++++++++++++++++++ include/linux/pci_ids.h | 3 + include/linux/pci_regs.h | 1 + 10 files changed, 259 insertions(+), 2 deletions(-) create mode 100644 arch/x86/pci/mrst.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 738bdc6..9532d10 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -1884,6 +1884,10 @@ config PCI_OLPC def_bool y depends on PCI && OLPC && (PCI_GOOLPC || PCI_GOANY) +config PCI_MOORESTOWN + def_bool y + depends on PCI && PCI_MMCONFIG + config PCI_DOMAINS def_bool y depends on PCI diff --git a/arch/x86/include/asm/pci_x86.h b/arch/x86/include/asm/pci_x86.h index b399988..cc6dad4 100644 --- a/arch/x86/include/asm/pci_x86.h +++ b/arch/x86/include/asm/pci_x86.h @@ -99,6 +99,7 @@ extern struct pci_raw_ops *raw_pci_ops; extern struct pci_raw_ops *raw_pci_ext_ops; extern struct pci_raw_ops pci_direct_conf1; +extern struct pci_raw_ops pci_mmcfg; extern bool port_cf9_safe; /* arch_initcall level */ @@ -106,6 +107,11 @@ extern int pci_direct_probe(void); extern void pci_direct_init(int type); extern void pci_pcbios_init(void); extern int pci_olpc_init(void); +#ifdef CONFIG_PCI_MOORESTOWN +extern void pci_mrst_init(void); +#else +static inline void pci_mrst_init(void) { } +#endif extern void __init dmi_check_pciprobe(void); extern void __init dmi_check_skip_isa_align(void); diff --git a/arch/x86/pci/Makefile b/arch/x86/pci/Makefile index d49202e..7f7a655 100644 --- a/arch/x86/pci/Makefile +++ b/arch/x86/pci/Makefile @@ -4,6 +4,7 @@ obj-$(CONFIG_PCI_BIOS) += pcbios.o obj-$(CONFIG_PCI_MMCONFIG) += mmconfig_$(BITS).o direct.o mmconfig-shared.o obj-$(CONFIG_PCI_DIRECT) += direct.o obj-$(CONFIG_PCI_OLPC) += olpc.o +obj-$(CONFIG_PCI_MOORESTOWN) += mrst.o obj-y += fixup.o obj-$(CONFIG_ACPI) += acpi.o diff --git a/arch/x86/pci/fixup.c b/arch/x86/pci/fixup.c index 6dd8955..89674d5 100644 --- a/arch/x86/pci/fixup.c +++ b/arch/x86/pci/fixup.c @@ -521,3 +521,13 @@ static void sb600_disable_hpet_bar(struct pci_dev *dev) } } DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, 0x4385, sb600_disable_hpet_bar); + +/* Intel Moorestown graphics controller can use INTx but the platform + * doesn't support it, so zero it out. + */ +static void __devinit pci_mrst_gfx_intx_pin_bug(struct pci_dev *dev) +{ + dev->pin = 0; +} +DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRST_GFX, + pci_mrst_gfx_intx_pin_bug); diff --git a/arch/x86/pci/init.c b/arch/x86/pci/init.c index 25a1f8e..d3e5430 100644 --- a/arch/x86/pci/init.c +++ b/arch/x86/pci/init.c @@ -15,6 +15,9 @@ static __init int pci_arch_init(void) if (!(pci_probe & PCI_PROBE_NOEARLY)) pci_mmcfg_early_init(); + pci_mmcfg_late_init(); + pci_mrst_init(); + #ifdef CONFIG_PCI_OLPC if (!pci_olpc_init()) return 0; /* skip additional checks if it's an XO */ diff --git a/arch/x86/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c index 712443e..ff7250a 100644 --- a/arch/x86/pci/mmconfig-shared.c +++ b/arch/x86/pci/mmconfig-shared.c @@ -605,9 +605,10 @@ static void __init __pci_mmcfg_init(int early) known_bridge = 1; } + /* Need SFI/MRST work here */ if (!known_bridge) acpi_table_parse(ACPI_SIG_MCFG, pci_parse_mcfg); - + /* ... and here */ pci_mmcfg_reject_broken(early); if ((pci_mmcfg_config_num == 0) || diff --git a/arch/x86/pci/mmconfig_32.c b/arch/x86/pci/mmconfig_32.c index 8b2d561..608009c 100644 --- a/arch/x86/pci/mmconfig_32.c +++ b/arch/x86/pci/mmconfig_32.c @@ -125,7 +125,7 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus, return 0; } -static struct pci_raw_ops pci_mmcfg = { +struct pci_raw_ops pci_mmcfg = { .read = pci_mmcfg_read, .write = pci_mmcfg_write, }; diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c new file mode 100644 index 0000000..ebb97d2 --- /dev/null +++ b/arch/x86/pci/mrst.c @@ -0,0 +1,228 @@ +/* + * Moorestown PCI support + * Copyright (c) 2008 Intel Corporation + * Jesse Barnes + * + * Moorestown has an interesting PCI implementation: + * - configuration space is memory mapped (as defined by MCFG) + * - Lincroft devices also have a real, type 1 configuration space + * - Early Lincroft silicon has a type 1 access bug that will cause + * a hang if non-existent devices are accessed + * - some devices have the "fixed BAR" capability, which means + * they can't be relocated or modified; check for that during + * BAR sizing + * + * So, we use the MCFG space for all reads and writes, but also send + * Lincroft writes to type 1 space. But only read/write if the device + * actually exists, otherwise return all 1s for reads and bit bucket + * the writes. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* Fixed BAR fields */ +#define PCIE_VNDR_CAP_ID_FIXED_BAR 0x00 /* Fixed BAR (TBD) */ +#define PCI_FIXED_BAR_0_SIZE 0x04 +#define PCI_FIXED_BAR_1_SIZE 0x08 +#define PCI_FIXED_BAR_2_SIZE 0x0c +#define PCI_FIXED_BAR_3_SIZE 0x10 +#define PCI_FIXED_BAR_4_SIZE 0x14 +#define PCI_FIXED_BAR_5_SIZE 0x1c + +/** + * fixed_bar_cap - return the offset of the fixed BAR cap if found + * @bus: PCI bus + * @devfn: device in question + * + * Look for the fixed BAR cap on @bus and @devfn, returning its offset + * if found or 0 otherwise. + */ +static int fixed_bar_cap(struct pci_bus *bus, unsigned int devfn) +{ + int pos; + u32 cap_data; + + pos = pci_bus_find_ext_capability(bus, devfn, PCI_EXT_CAP_ID_VNDR); + if (!pos) + return 0; + + /* + * Assumes our fixed BAR cap is the first dword of the vendor cap. + * This is true for Moorestown. On future platforms we may have + * to walk the whole vendor cap (structure TBD) to find it. + */ + pci_bus_read_config_dword(bus, devfn, pos + 4, &cap_data); + if ((cap_data & 0xffff) == PCIE_VNDR_CAP_ID_FIXED_BAR) + return pos + 4; + + return 0; +} + +static int pci_device_update_fixed(struct pci_bus *bus, unsigned int devfn, + int reg, int len, u32 val, int offset) +{ + u32 size; + unsigned int domain, busnum; + int bar = (reg - PCI_BASE_ADDRESS_0) >> 2; + + domain = pci_domain_nr(bus); + busnum = bus->number; + + if (val == ~0 && len == 4) { + unsigned long decode; + + pci_mmcfg.read(domain, busnum, devfn, + offset + 4 + (bar * 4), 4, &size); + + /* Turn the size into a decode pattern for the sizing code */ + if (size) { + decode = size - 1; + decode |= decode >> 1; + decode |= decode >> 2; + decode |= decode >> 4; + decode |= decode >> 8; + decode |= decode >> 16; + decode++; + decode = ~(decode - 1); + } else { + decode = ~0; + } + + /* + * If val is all ones, the core code is trying to size the reg, + * so update the mmconfig space with the real size. + * + * Note: this assumes the fixed size we got is a power of two. + */ + return pci_mmcfg.write(domain, busnum, devfn, reg, 4, + decode); + } + + /* This is some other kind of BAR write, so just do it. */ + return pci_mmcfg.write(domain, busnum, devfn, reg, len, val); +} + +/** + * type1_access_ok - check whether to use type 1 + * @bus: bus number + * @devfn: device & function in question + * + * If the bus is on a Lincroft chip and it exists, or is not on a Lincroft at + * all, the we can go ahead with any reads & writes. If it's on a Lincroft, + * but doesn't exist, avoid the access altogether to keep the chip from + * hanging. + */ +static bool type1_access_ok(unsigned int bus, unsigned int devfn, int reg) +{ + /* This is a workaround for A0 LNC bug where PCI status register does + * not have new CAP bit set. can not be written by SW either. + * + * PCI header type in real LNC indicates a single function device, this + * will prevent probing other devices under the same function in PCI + * shim. Therefore, use the header type in shim instead. + */ + if (reg >= 0x100 || reg == PCI_STATUS || reg == PCI_HEADER_TYPE) + return 0; + if (bus == 0 && (devfn == PCI_DEVFN(2, 0) || devfn == PCI_DEVFN(0, 0))) + return 1; + return 0; /* langwell on others */ +} + +static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, + int size, u32 *value) +{ + if (type1_access_ok(bus->number, devfn, where)) + return pci_direct_conf1.read(pci_domain_nr(bus), bus->number, devfn, + where, size, value); + return pci_mmcfg.read(pci_domain_nr(bus), bus->number, + devfn, where, size, value); +} + +static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, + int size, u32 value) +{ + int offset; + + /* On MRST, there is no PCI ROM BAR, this will cause a subsequent read + * to ROM BAR return 0 then being ignored. + */ + if (where == PCI_ROM_ADDRESS) + return 0; + + /* + * Devices with fixed BARs need special handling: + * - BAR sizing code will save, write ~0, read size, restore + * - so writes to fixed BARs need special handling + * - other writes to fixed BAR devices should go through mmconfig + */ + offset = fixed_bar_cap(bus, devfn); + if (offset && + (where >= PCI_BASE_ADDRESS_0 && where <= PCI_BASE_ADDRESS_5)) { + return pci_device_update_fixed(bus, devfn, where, size, value, + offset); + } + + /* + * On Moorestown update both real & mmconfig space + * Note: early Lincroft silicon can't handle type 1 accesses to + * non-existent devices, so just eat the write in that case. + */ + if (type1_access_ok(bus->number, devfn, where)) + return pci_direct_conf1.write(pci_domain_nr(bus), bus->number, + devfn, where, size, value); + return pci_mmcfg.write(pci_domain_nr(bus), bus->number, devfn, + where, size, value); +} + +struct pci_ops pci_mrst_ops = { + .read = pci_read, + .write = pci_write, +}; + +/** + * pci_mrst_init - figure out if this platform should use pci_mrst_ops + * + * Moorestown has an interesting PCI implementation (see above). This + * function checks whether the current platform should use MRST-style PCI + * config space ops or not, and sets pci_root_ops accordingly. + */ +void pci_mrst_init(void) +{ + /* Use platform feature flags here to return early on !MRST */ + printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n"); + pci_root_ops = pci_mrst_ops; +} + +/* + * Langwell devices reside at fixed offsets, don't try to move them. + */ +static void __devinit pci_fixed_bar_fixup(struct pci_dev *dev) +{ + unsigned long offset; + u32 size; + int i; + + /* Fixup the BAR sizes for fixed BAR devices and make them unmoveable */ + offset = fixed_bar_cap(dev->bus, dev->devfn); + if (!offset || PCI_DEVFN(2, 0) == dev->devfn || + PCI_DEVFN(2, 2) == dev->devfn) + return; + + for (i = 0; i < PCI_ROM_RESOURCE; i++) { + pci_read_config_dword(dev, offset + 4 + (i * 4), &size); + dev->resource[i].end = dev->resource[i].start + size - 1; + dev->resource[i].flags |= IORESOURCE_PCI_FIXED; + } +} +DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_fixed_bar_fixup); + diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h index 73b46b6..0ac107f 100644 --- a/include/linux/pci_ids.h +++ b/include/linux/pci_ids.h @@ -2357,6 +2357,8 @@ #define PCI_DEVICE_ID_INTEL_82375 0x0482 #define PCI_DEVICE_ID_INTEL_82424 0x0483 #define PCI_DEVICE_ID_INTEL_82378 0x0484 +#define PCI_DEVICE_ID_INTEL_MRST_SD0 0x0807 +#define PCI_DEVICE_ID_INTEL_MRST_SD1 0x0808 #define PCI_DEVICE_ID_INTEL_I960 0x0960 #define PCI_DEVICE_ID_INTEL_I960RM 0x0962 #define PCI_DEVICE_ID_INTEL_8257X_SOL 0x1062 @@ -2525,6 +2527,7 @@ #define PCI_DEVICE_ID_INTEL_PCH_LPC_MAX 0x3b1f #define PCI_DEVICE_ID_INTEL_PCH_SMBUS 0x3b30 #define PCI_DEVICE_ID_INTEL_IOAT_SNB 0x402f +#define PCI_DEVICE_ID_INTEL_MRST_GFX 0x4102 #define PCI_DEVICE_ID_INTEL_5100_16 0x65f0 #define PCI_DEVICE_ID_INTEL_5100_21 0x65f5 #define PCI_DEVICE_ID_INTEL_5100_22 0x65f6 diff --git a/include/linux/pci_regs.h b/include/linux/pci_regs.h index fcaee42..fcad960 100644 --- a/include/linux/pci_regs.h +++ b/include/linux/pci_regs.h @@ -501,6 +501,7 @@ #define PCI_EXT_CAP_ID_VC 2 #define PCI_EXT_CAP_ID_DSN 3 #define PCI_EXT_CAP_ID_PWR 4 +#define PCI_EXT_CAP_ID_VNDR 11 #define PCI_EXT_CAP_ID_ARI 14 #define PCI_EXT_CAP_ID_ATS 15 #define PCI_EXT_CAP_ID_SRIOV 16