From patchwork Thu Jun 2 12:52:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 9149935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D566B60221 for ; Thu, 2 Jun 2016 12:54:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C668226907 for ; Thu, 2 Jun 2016 12:54:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB06E2824A; Thu, 2 Jun 2016 12:54:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5171526907 for ; Thu, 2 Jun 2016 12:54:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8S7s-0004XB-6S; Thu, 02 Jun 2016 12:53:28 +0000 Received: from mx2.mailbox.org ([80.241.60.215]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b8S7o-0004Oi-GG for linux-arm-kernel@lists.infradead.org; Thu, 02 Jun 2016 12:53:25 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id EACDF4352B; Thu, 2 Jun 2016 14:52:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id ml9OnDDmbrUg; Thu, 2 Jun 2016 14:52:48 +0200 (CEST) From: Stefan Roese To: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org Subject: [PATCH] PCI: mvebu: Don't try to add an MBus window that already exists Date: Thu, 2 Jun 2016 14:52:47 +0200 Message-Id: <20160602125247.17566-1-sr@denx.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160602_055324_743447_B9859F72 X-CRM114-Status: GOOD ( 12.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Petazzoni , Russell King , Bjorn Helgaas , Jason Cooper , Jisheng Zhang MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a check to mvebu_pcie_add_windows() to detect, if an MBus window is already configured. If this is the case (base address, size, target and attribute are identical), then this window is not created. This fixes a problem I'm currently seeing on a custom Armada XP based board, which generates this error upon PCI rescanning (in this case via sysfs): $ echo 1 > /sys/bus/pci/rescan mvebu_mbus: cannot add window '4:e8', conflicts with another window mvebu-pcie soc:pcie-controller: Could not create MBus window at [mem 0x9e000000-0x9e0fffff]: -22 Signed-off-by: Stefan Roese Cc: Thomas Petazzoni Cc: Russell King Cc: Jisheng Zhang Cc: Jason Cooper Cc: Bjorn Helgaas --- drivers/pci/host/pci-mvebu.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c index 6b451df..a85b2b4 100644 --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c @@ -355,18 +355,31 @@ static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port, while (size) { size_t sz = 1 << (fls(size) - 1); int ret; + u32 wsize; + u8 wtarget, wattr; - ret = mvebu_mbus_add_window_remap_by_id(target, attribute, base, - sz, remap); - if (ret) { - phys_addr_t end = base + sz - 1; - - dev_err(&port->pcie->pdev->dev, - "Could not create MBus window at [mem %pa-%pa]: %d\n", - &base, &end, ret); - mvebu_pcie_del_windows(port, base - size_mapped, - size_mapped); - return; + /* + * Only add this MBus window when it does not yet exist. + * Otherwise an error may occur upon PCI rescanning (e.g. + * via sysfs). + */ + ret = mvebu_mbus_get_io_win_info(base, &wsize, &wtarget, + &wattr); + if (ret < 0 || wsize != sz || wtarget != target || + wattr != attribute) { + ret = mvebu_mbus_add_window_remap_by_id(target, + attribute, base, + sz, remap); + if (ret) { + phys_addr_t end = base + sz - 1; + + dev_err(&port->pcie->pdev->dev, + "Could not create MBus window at [mem %pa-%pa]: %d\n", + &base, &end, ret); + mvebu_pcie_del_windows(port, base - size_mapped, + size_mapped); + return; + } } size -= sz;