Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp2716ima; Thu, 31 Jan 2019 21:36:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN73szX2E2QfcT2uJ2nxgYkjft0yRP303CImUPMHjUn/vSkCXXZcBFLAl+rWUg7ntNaMPqYi X-Received: by 2002:a17:902:29a7:: with SMTP id h36mr38497642plb.244.1548999410559; Thu, 31 Jan 2019 21:36:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548999410; cv=none; d=google.com; s=arc-20160816; b=y2DczNKB8Hdbca+M2lJ/e/N7NJZFJ5l5xKmuNbtTsEIHMDJ9kLWY8605IXzWiwsln5 OgAGUC/d3IZ2Y9nq4E4p6BYMakTBlhBlq5vDw2h3MpCk64HHc2GpOT9K1sel25tJ85cS gbLn4upW/qPlBIsrlCdo+JLOrlhqu6rIFeoWp2NpOblgqy6w22jGA/ILQ1sUSphiKx8E ZlZ3Zkj2X2V0SfYhKp5BkNYpz7jzNZMSQDGzV7gLBkG+4tbtdkRJgGccCeSPAmQ+UCuZ uYPLgeNet57leWGyPFIjRQ+SETQE1sR2Ys7yM1Jz3HjJRxqapjGahDTfmsNhJY7GmNoG 3QIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=HANhaGVy0kQR14G+SgtgydWXuQahsmnHb84rPRIVMsU=; b=wZfEtmdivathEGoygr/l/c+204mMbEbDHUhkpvWu9EEvKvMALax7bCB01ZotHG0WdI adry0MYJ97VdTQnYXp0WdZjVfyuQUR4csJHnmcdAlQ0YhwQ5bTMeBQKqnPxgbmc4MR0K s8t6gP4ACQMI9dl1MoYr2qdxdIDEEiRLXuuzFyxpGNPr0VWmrug5zHzuzXAsPeTdTITV 3oMTFTz7V/XWwMZxVU6H//Yv7tkzHrzH31D/MbQ7JRrUn/U9LSgpXqAUG495lZ/TcSkQ U1OHp0yXOcMwFMIFl6+S2O/rILfRuNRrnmK4DEsFwsC96QPJG3l4G7SdCaXqzqmsckR4 IvJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s129si1407279pgs.121.2019.01.31.21.36.34; Thu, 31 Jan 2019 21:36:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbfBAFg0 (ORCPT + 99 others); Fri, 1 Feb 2019 00:36:26 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:5434 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726570AbfBAFgX (ORCPT ); Fri, 1 Feb 2019 00:36:23 -0500 X-UUID: 131bf5fa71ef4237a3d8e23bedf72e10-20190201 X-UUID: 131bf5fa71ef4237a3d8e23bedf72e10-20190201 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1387363885; Fri, 01 Feb 2019 13:36:19 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 1 Feb 2019 13:36:10 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 1 Feb 2019 13:36:10 +0800 From: To: , , , , , , CC: , , , , , Honghui Zhang Subject: [PATCH v3 1/2] PCI: mediatek: Enable the whole memory mapped IO range Date: Fri, 1 Feb 2019 13:36:06 +0800 Message-ID: <1548999367-11733-2-git-send-email-honghui.zhang@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1548999367-11733-1-git-send-email-honghui.zhang@mediatek.com> References: <1548999367-11733-1-git-send-email-honghui.zhang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-TM-SNTS-SMTP: 18A9FA841BB559D2EFB2D7B455CE214262B6A26F60324E17095F577292C51CA82000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Honghui Zhang Mediatek's HW assigned a bus address range(typically start from 0x2000_0000 to 0x2fff_ffff for both mt2712 and mt7622) for PCIe usage. This bus address range is called memory mapped IO range, when CPU or other HW access those address, PCIe RC HW should response to this access. Normally the RC will translate those access request to TLPs and send to corresponding EP side. It's like the total memory address resource which could be allocated by EP and RC's BARs. Although those address range is available for allocated, but it should be enabled by the PCIE_AHB_TRANS_BASE register, what size will be enabled is determined by AHB2PCIE_SIZE bits in this register. In previous code we did not enable the full size of HW assigned address range, if the EP's BAR requested size is bigger than the size we enabled and smaller than the HW available size. The access request which target at these un-enabled address will be blocked by RC, and EP side will never get those TLPs. Previous code never run into a system error in production because even half of those range(128MB) is bigger enough for typical EP device's BAR request(4MB). But all those HW assigned bus range should be enabled. And it's Okay to do that. RC will never forward a request to EP when this request is not suitable for EP's BAR range. Using resource_size(mem) instead of mem->end - mem->start to fix this, since the MMIO window size for both MT2712 and MT7622 are all 0x1000_0000, this change will change the values of fls(size) from fls(0xfff_ffff) to fls(0x1000_0000) and calcalate the whole memory mapped IO range size. This change also eliminate the following complain generated by scripts/coccinelle/api/resource_size.cocci: pcie-mediatek.c:720:13-16: WARNING: Suspicious code. resource_size is maybe missing with mem Signed-off-by: Honghui Zhang --- drivers/pci/controller/pcie-mediatek.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 55e471c..c42fe5c 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -654,7 +654,6 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) struct resource *mem = &pcie->mem; const struct mtk_pcie_soc *soc = port->pcie->soc; u32 val; - size_t size; int err; /* MT7622 platforms need to enable LTSSM and ASPM from PCIe subsys */ @@ -706,8 +705,8 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) mtk_pcie_enable_msi(port); /* Set AHB to PCIe translation windows */ - size = mem->end - mem->start; - val = lower_32_bits(mem->start) | AHB2PCIE_SIZE(fls(size)); + val = lower_32_bits(mem->start) | + AHB2PCIE_SIZE(fls(resource_size(mem))); writel(val, port->base + PCIE_AHB_TRANS_BASE0_L); val = upper_32_bits(mem->start); -- 2.6.4