From patchwork Mon Aug 28 15:25:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_L=C3=BCbbe?= X-Patchwork-Id: 9925815 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 B70D460329 for ; Mon, 28 Aug 2017 15:27:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A96DE28700 for ; Mon, 28 Aug 2017 15:27:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9DE0528703; Mon, 28 Aug 2017 15:27:35 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 375D528700 for ; Mon, 28 Aug 2017 15:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8LXDJp9X5YvJzuydWjZiKBrQBgdQpYIZecoLUkaCmWM=; b=jiaPKex8gt6AlLOAUuvIUVBY8C QVLZZ9W4uF47lnZ4hRxFzgMCL8Lop2ZhGwtH6ebpflrhGtF49XRXvhx6JMNvQiSFzFTSB8adtlBOd 5Dhyi7r/GAONBd1ZO1uioiNYM/xfmq40h73E2rfKdHOf8X9uqBpDVfsVrjVkhhkUIxM7WERQwe53l UdGCShX029yEsRML/guJjTdiV4WYq0PznylTbvXHNHgz5eg8tcvNpqOQKVFli8ju3Iq6ZNDsVv6fr Dro7+eJsnVnddBjQJTkmn7WaI/8D4OnhsKX7OeqDo7w94ysMqheF99QJwLjGpYXmXi6KWiTTwifVW /06i71YQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dmLwp-0004Vx-CZ; Mon, 28 Aug 2017 15:27:31 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dmLvH-0003jx-B1 for linux-arm-kernel@lists.infradead.org; Mon, 28 Aug 2017 15:26:10 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dmLus-00080v-Cb; Mon, 28 Aug 2017 17:25:30 +0200 Received: from jlu by dude.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1dmLur-0006O5-KI; Mon, 28 Aug 2017 17:25:29 +0200 From: Jan Luebbe To: Gregory Clement , Andrew Lunn , Thomas Petazzoni , Jason Cooper Subject: [PATCH 2/2] PCI: mvebu: Check DRAM window size Date: Mon, 28 Aug 2017 17:25:17 +0200 Message-Id: <20170828152517.24506-3-jlu@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170828152517.24506-1-jlu@pengutronix.de> References: <20170828152517.24506-1-jlu@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: jlu@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170828_082555_733847_738DB64D X-CRM114-Status: GOOD ( 12.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@pengutronix.de, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jan Luebbe 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 The sum of the DRAM windows may exceed 4GB (at least on Armada XP). Return an error in that case. Signed-off-by: Jan Luebbe --- drivers/pci/host/pci-mvebu.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c index f353a6eb2f01..5d74af81d104 100644 --- a/drivers/pci/host/pci-mvebu.c +++ b/drivers/pci/host/pci-mvebu.c @@ -206,10 +206,10 @@ static void mvebu_pcie_set_local_dev_nr(struct mvebu_pcie_port *port, int nr) * BAR[0,2] -> disabled, BAR[1] -> covers all DRAM banks * WIN[0-3] -> DRAM bank[0-3] */ -static void mvebu_pcie_setup_wins(struct mvebu_pcie_port *port) +static int mvebu_pcie_setup_wins(struct mvebu_pcie_port *port) { const struct mbus_dram_target_info *dram; - u32 size; + u64 size; int i; dram = mv_mbus_dram_info(); @@ -252,19 +252,32 @@ static void mvebu_pcie_setup_wins(struct mvebu_pcie_port *port) if ((size & (size - 1)) != 0) size = 1 << fls(size); + if (size > 0x100000000) { + dev_err(&port->pcie->pdev->dev, + "Could not configure DRAM window (too large): 0x%llx\n", + size); + + return -EINVAL; + } + /* Setup BAR[1] to all DRAM banks. */ mvebu_writel(port, dram->cs[0].base, PCIE_BAR_LO_OFF(1)); mvebu_writel(port, 0, PCIE_BAR_HI_OFF(1)); mvebu_writel(port, ((size - 1) & 0xffff0000) | 1, PCIE_BAR_CTRL_OFF(1)); + + return 0; } -static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) +static int mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) { u32 cmd, mask; + int ret; /* Point PCIe unit MBUS decode windows to DRAM space. */ - mvebu_pcie_setup_wins(port); + ret = mvebu_pcie_setup_wins(port); + if (ret) + return ret; /* Master + slave enable. */ cmd = mvebu_readl(port, PCIE_CMD_OFF); @@ -277,6 +290,8 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) mask = mvebu_readl(port, PCIE_MASK_OFF); mask |= PCIE_MASK_ENABLE_INTS; mvebu_writel(port, mask, PCIE_MASK_OFF); + + return 0; } static int mvebu_pcie_hw_rd_conf(struct mvebu_pcie_port *port, @@ -882,7 +897,9 @@ static int mvebu_pcie_setup(int nr, struct pci_sys_data *sys) if (!port->base) continue; - mvebu_pcie_setup_hw(port); + err = mvebu_pcie_setup_hw(port); + if (err) + return 0; } return 1;