From patchwork Thu Jul 30 03:59:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 501910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9B4EB1409BB for ; Thu, 30 Jul 2015 13:59:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=jKZuccqF; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753105AbbG3D7R (ORCPT ); Wed, 29 Jul 2015 23:59:17 -0400 Received: from mail-ig0-f174.google.com ([209.85.213.174]:35512 "EHLO mail-ig0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752727AbbG3D7Q (ORCPT ); Wed, 29 Jul 2015 23:59:16 -0400 Received: by igr7 with SMTP id 7so159443316igr.0 for ; Wed, 29 Jul 2015 20:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=iMc+OdwrFIOgBwkEfqz88fZfQQtCg4ISFbVeYPe/BJQ=; b=jKZuccqFcxSIIZoqzYtahgNIV6hZTN2MdwNK+iNTHVtUpwVQUz3U7rRuGQZpojs+4E uyMIx4cA+ZXwaWKBNHNs0PqnZ9g2NkCem5ueUO5cKWWy8JkGowxlq646uvl/OxEamUjG ryo5cSd7dCS91yK9DK2NS9yg4XnwX76lpbAUm4WsY5MsBBRX2NZolPRVZLQ+JaPlnc+z yhOsmnPr8fH4wzYdWCW+bBQoh0wZt8uHup/JL+z/1CZte6Zt6SVR/uW/n48IWKLWS8iF aS9XqX3S+iXbRp+JDMDKyEOKHR5N36gUtdcRGHAY7p0yibt80nTQA1bbCvuzzu1cyk4K cL4g== MIME-Version: 1.0 X-Received: by 10.50.29.17 with SMTP id f17mr1737933igh.54.1438228756313; Wed, 29 Jul 2015 20:59:16 -0700 (PDT) Received: by 10.64.120.101 with HTTP; Wed, 29 Jul 2015 20:59:16 -0700 (PDT) In-Reply-To: <20150729202639.GA13239@google.com> References: <1436292680-25111-1-git-send-email-linux@roeck-us.net> <20150729160903.GD31170@google.com> <55B92DA5.4030409@roeck-us.net> <55B93151.8040608@roeck-us.net> <20150729202639.GA13239@google.com> Date: Wed, 29 Jul 2015 20:59:16 -0700 X-Google-Sender-Auth: fJz5RyGIt4ysWMmILFzTh9E6ieg Message-ID: Subject: Re: [RFC PATCH v2] PCI: Only enable IO window if supported From: Yinghai Lu To: Bjorn Helgaas Cc: Guenter Roeck , "linux-pci@vger.kernel.org" , Lorenzo Pieralisi Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org On Wed, Jul 29, 2015 at 1:26 PM, Bjorn Helgaas wrote: > On Wed, Jul 29, 2015 at 01:02:25PM -0700, Guenter Roeck wrote: >> Bjorn, how do you want to handle the flag problem ? >> Do you have an idea on how to make it work with >> the reversed definition ? > > I'll wait for the revised patch. Sorry for screwing this up. Please check attached updated version. Yinghai commit 4b59da521f7e0aedff75c2aa90b6a653727cdf7f Author: Guenter Roeck Date: Tue Jul 7 11:11:20 2015 -0700 The PCI subsystem always assumes that I/O is supported on PCIe bridges and tries to assign an I/O window to each child bus even if that is not the case. This may result in messages such as: pcieport 0000:02:00.0: res[7]=[io 0x1000-0x0fff] get_res_add_size add_size 1000 pcieport 0000:02:00.0: BAR 7: no space for [io size 0x1000] pcieport 0000:02:00.0: BAR 7: failed to assign [io size 0x1000] for each bridge port, even if a bus or its parent does not support I/O in the first place. To avoid this message, check if a bus supports I/O before trying to enable it. Also check if the root bus has an IO window assigned; if not, it does not make sense to try to assign one to any of its child busses. [bhelgaas: reverse sense of new pci_bus_flags_t value] [yinghai: simplify root bus flag check, fix flags initial setting, change to bool] Signed-off-by: Guenter Roeck Signed-off-by: Bjorn Helgaas CC: Lorenzo Pieralisi --- drivers/pci/probe.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/pci/setup-bus.c | 11 ++-------- include/linux/pci.h | 1 3 files changed, 55 insertions(+), 8 deletions(-) Index: linux-2.6/drivers/pci/probe.c =================================================================== --- linux-2.6.orig/drivers/pci/probe.c +++ linux-2.6/drivers/pci/probe.c @@ -332,6 +332,32 @@ static void pci_read_bases(struct pci_de } } +static bool pci_bridge_supports_io(struct pci_dev *bridge) +{ + u16 io; + + pci_read_config_word(bridge, PCI_IO_BASE, &io); + if (io) + return true; + + /* IO_BASE/LIMIT is either hard-wired to zero or programmed to zero */ + pci_write_config_word(bridge, PCI_IO_BASE, 0xe0f0); + pci_read_config_word(bridge, PCI_IO_BASE, &io); + pci_write_config_word(bridge, PCI_IO_BASE, 0x0); + if (io) + return true; + + return false; +} + +static bool pci_root_has_io_resource(struct pci_bus *bus) +{ + while (bus->parent) + bus = bus->parent; + + return !!(bus->bus_flags & PCI_BUS_FLAGS_SUPPORTS_IO); +} + static void pci_read_bridge_io(struct pci_bus *child) { struct pci_dev *dev = child->self; @@ -340,6 +366,21 @@ static void pci_read_bridge_io(struct pc struct pci_bus_region region; struct resource *res; + if (!(child->bus_flags & PCI_BUS_FLAGS_SUPPORTS_IO)) + return; + + if (!pci_bridge_supports_io(dev)) { + dev_printk(KERN_DEBUG, &dev->dev, " no I/O window\n"); + child->bus_flags &= ~PCI_BUS_FLAGS_SUPPORTS_IO; + return; + } + + if (!pci_root_has_io_resource(child)) { + dev_printk(KERN_DEBUG, &dev->dev, " no I/O resource on root bus\n"); + child->bus_flags &= ~PCI_BUS_FLAGS_SUPPORTS_IO; + return; + } + io_mask = PCI_IO_RANGE_MASK; io_granularity = 0x1000; if (dev->io_window_1k) { @@ -496,6 +537,7 @@ static struct pci_bus *pci_alloc_bus(str INIT_LIST_HEAD(&b->resources); b->max_bus_speed = PCI_SPEED_UNKNOWN; b->cur_bus_speed = PCI_SPEED_UNKNOWN; + b->bus_flags |= PCI_BUS_FLAGS_SUPPORTS_IO; #ifdef CONFIG_PCI_DOMAINS_GENERIC if (parent) b->domain_nr = parent->domain_nr; @@ -2058,6 +2100,15 @@ int pci_bus_insert_busn_res(struct pci_b res->flags |= IORESOURCE_PCI_FIXED; } + b->bus_flags &= ~PCI_BUS_FLAGS_SUPPORTS_IO; + resource_list_for_each_entry(window, &bridge->windows) { + res = window->res; + if (resource_type(res) == IORESOURCE_IO) { + b->bus_flags |= PCI_BUS_FLAGS_SUPPORTS_IO; + break; + } + } + conflict = request_resource_conflict(parent_res, res); if (conflict) 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 @@ -744,7 +744,6 @@ int pci_claim_bridge_resource(struct pci base/limit registers must be read-only and read as 0. */ static void pci_bridge_check_ranges(struct pci_bus *bus) { - u16 io; u32 pmem; struct pci_dev *bridge = bus->self; struct resource *b_res; @@ -752,14 +751,10 @@ static void pci_bridge_check_ranges(stru b_res = &bridge->resource[PCI_BRIDGE_RESOURCES]; b_res[1].flags |= IORESOURCE_MEM; - pci_read_config_word(bridge, PCI_IO_BASE, &io); - if (!io) { - pci_write_config_word(bridge, PCI_IO_BASE, 0xe0f0); - pci_read_config_word(bridge, PCI_IO_BASE, &io); - pci_write_config_word(bridge, PCI_IO_BASE, 0x0); - } - if (io) + if (bus->bus_flags & PCI_BUS_FLAGS_SUPPORTS_IO) b_res[0].flags |= IORESOURCE_IO; + else + b_res[0].flags &= ~IORESOURCE_IO; /* DECchip 21050 pass 2 errata: the bridge may miss an address disconnect boundary by one PCI data phase. Index: linux-2.6/include/linux/pci.h =================================================================== --- linux-2.6.orig/include/linux/pci.h +++ linux-2.6/include/linux/pci.h @@ -193,6 +193,7 @@ typedef unsigned short __bitwise pci_bus enum pci_bus_flags { PCI_BUS_FLAGS_NO_MSI = (__force pci_bus_flags_t) 1, PCI_BUS_FLAGS_NO_MMRBC = (__force pci_bus_flags_t) 2, + PCI_BUS_FLAGS_SUPPORTS_IO = (__force pci_bus_flags_t) 4, }; /* These values come from the PCI Express Spec */