From patchwork Fri Mar 10 04:08:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 67214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp679753wrd; Thu, 9 Mar 2023 20:26:14 -0800 (PST) X-Google-Smtp-Source: AK7set/emfYe3QM29/VDGP04xzyNyzNukUXW5x2loHETyYJpeb12OPwXpsIfa3FgA2RKuH44lSzQ X-Received: by 2002:a17:903:2349:b0:19c:e046:d906 with SMTP id c9-20020a170903234900b0019ce046d906mr983661plh.24.1678422373856; Thu, 09 Mar 2023 20:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678422373; cv=none; d=google.com; s=arc-20160816; b=YN7ejkl+ixtfaug7toNmvABt9SWdYoPgChDMTo5ckMdEM8A9MKJJCRIf2Sx4lEvht8 WZnMAhclkvuaVgGqTw0oLM/1cOXJA6LZB5pneXjThOTOVoukfT7+rBubgdjLSU0LV0Cs D1mwD1Ocu2RocW88ubHuHfxFEIGYUX8X6Z1N7epuSJlKipr8uAjmgBYv61fLZ9xUhNVj qWWa4woL3gpdHyj1cv880s848Pwy8/yGymlG/wxg5FrPLET3Re1fx9npi4htDlwhYRua 7HFytu3BxGc5PGllUiGAclaYj7lLs2RVdTqpeFyL1mGCv75UWwCdnaJHMAKFiOQFG5pM mZwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TwnOfx0fvyN0EVTsIZtRO7GfnRR3nR2D8SXkkwhJ4Fg=; b=GsjYiHt7hj33ExDqNi6GPuMWnxpuplLszxjQAcaBNPyPdCoOmpLbZSmuD2VwQdJrRu CMm9cu16o/f9nosx2/6kqbXW70oJ8bpCJXbcDCDJPVrDr/dCOgNDOwUwfrP7qWgOueQk Jki80sLzIIW9Tf2uoe/JmLoal7zH0fXuCHNJVEcLRSuBsGlnbv3zhRiB5yjQaEoLC2F0 okqtG40sM+1w77EBHXjqmnqzV7nnNM75nrUXdDGLCUKea68hOZt/7jZxU/3C2wkxEFdG FuNf84cp/m4+qFnBm4yC2fpJGHWNrokZjTFKl4DJx6wOcR/sVD9nWx7QjW1ssJZulnV8 bh4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o5wWWCRw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a170902c1d300b0019ad7bad651si1082622plc.4.2023.03.09.20.26.01; Thu, 09 Mar 2023 20:26:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o5wWWCRw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230501AbjCJELe (ORCPT + 99 others); Thu, 9 Mar 2023 23:11:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbjCJEK3 (ORCPT ); Thu, 9 Mar 2023 23:10:29 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8345D102B79 for ; Thu, 9 Mar 2023 20:09:35 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id x20-20020a17090a8a9400b00233ba727724so7067173pjn.1 for ; Thu, 09 Mar 2023 20:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1678421367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TwnOfx0fvyN0EVTsIZtRO7GfnRR3nR2D8SXkkwhJ4Fg=; b=o5wWWCRwfCXHSDaJxzI5Mf0pLfNmuyFz7riyLzkoGymmZQfSSsmTjU+/5Mlp9ssne7 Ep95fbLjk6WW5RtwHDocEkWwpq0QL/sl0s+Nagd/8gKTsbf2G1h8Jn+RAqLWb1izc3uj NdVKgXjonyb+mTtpUY8PqCTMqgqcIX9/evmnxS1uoECVYoutQOT1Vfd9X1atz3pF6sny OjoTlHqIEY2s5Huxk/GYz8kgINIs0s6bbbzxw4A/QFa3Yq/MFcNHyQQmWalZcVXxVW5O mwADWZN5YQyi6s807g6yhpnxeCCYtSbmlwiuPbCIUxqSDqQfoPCxrWmyvOWy4MROTLnm OJ3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678421367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TwnOfx0fvyN0EVTsIZtRO7GfnRR3nR2D8SXkkwhJ4Fg=; b=Vm9UlFWPI3je+WweFiFkJf9ysLUQA4LA4IWaTUY4QRoWcoc8O9C0sP4SQHpiRhVfQi D78Ov/Af6tOEETXVSb/NKkzqJPg/fH3j+PkB6SN5G3RlXRL/XYIyaoMtENIpaspIazh6 I+wX8FA6fLygX9tTMF338/kFknIso/VDQ2ouFvyCeotUMnBIBjZ6C//yldSDu270Bwcm U7ZTz8YIAgQcvFw3nR2I+fBVGUT5iOrBYkSmDk6vqnrbnEw3Pf/fIsIVvZE67jRkHKK7 Jimf+8/RZWHjvDr5Bkcl/lq0WQdpsd7Zrh9KgkKDtyQVIU5AfMe7pdlauR/GxqgNWhL8 NcGg== X-Gm-Message-State: AO0yUKWSHtkaA06KUJxSZ/llORh9Dqnfe+dbJvDsSx5hzrrs4UDHRp5E 5wM2Cy79c1QssltOuR3oGsQd X-Received: by 2002:a05:6a21:338f:b0:cb:b92c:b46e with SMTP id yy15-20020a056a21338f00b000cbb92cb46emr1056989pzb.9.1678421367512; Thu, 09 Mar 2023 20:09:27 -0800 (PST) Received: from localhost.localdomain ([27.111.75.67]) by smtp.gmail.com with ESMTPSA id y26-20020aa7855a000000b0058d92d6e4ddsm361846pfn.5.2023.03.09.20.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 20:09:26 -0800 (PST) From: Manivannan Sadhasivam To: andersson@kernel.org, lpieralisi@kernel.org, kw@linux.com, krzysztof.kozlowski+dt@linaro.org, robh@kernel.org Cc: konrad.dybcio@linaro.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, quic_srichara@quicinc.com, Manivannan Sadhasivam Subject: [PATCH v3 13/19] PCI: qcom: Rename qcom_pcie_config_sid_sm8250() to reflect IP version Date: Fri, 10 Mar 2023 09:38:10 +0530 Message-Id: <20230310040816.22094-14-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230310040816.22094-1-manivannan.sadhasivam@linaro.org> References: <20230310040816.22094-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759953418847609152?= X-GMAIL-MSGID: =?utf-8?q?1759953418847609152?= qcom_pcie_config_sid_sm8250() function no longer applies only to SM8250. So let's rename it to reflect the actual IP version and also move its definition to keep it sorted as per IP revisions. Signed-off-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pcie-qcom.c | 144 ++++++++++++------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index e1180c84f0fa..52f09ee8dd48 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -963,6 +963,77 @@ static void qcom_pcie_deinit_2_7_0(struct qcom_pcie *pcie) regulator_bulk_disable(ARRAY_SIZE(res->supplies), res->supplies); } +static int qcom_pcie_config_sid_1_9_0(struct qcom_pcie *pcie) +{ + /* iommu map structure */ + struct { + u32 bdf; + u32 phandle; + u32 smmu_sid; + u32 smmu_sid_len; + } *map; + void __iomem *bdf_to_sid_base = pcie->parf + PARF_BDF_TO_SID_TABLE_N; + struct device *dev = pcie->pci->dev; + u8 qcom_pcie_crc8_table[CRC8_TABLE_SIZE]; + int i, nr_map, size = 0; + u32 smmu_sid_base; + + of_get_property(dev->of_node, "iommu-map", &size); + if (!size) + return 0; + + map = kzalloc(size, GFP_KERNEL); + if (!map) + return -ENOMEM; + + of_property_read_u32_array(dev->of_node, + "iommu-map", (u32 *)map, size / sizeof(u32)); + + nr_map = size / (sizeof(*map)); + + crc8_populate_msb(qcom_pcie_crc8_table, QCOM_PCIE_CRC8_POLYNOMIAL); + + /* Registers need to be zero out first */ + memset_io(bdf_to_sid_base, 0, CRC8_TABLE_SIZE * sizeof(u32)); + + /* Extract the SMMU SID base from the first entry of iommu-map */ + smmu_sid_base = map[0].smmu_sid; + + /* Look for an available entry to hold the mapping */ + for (i = 0; i < nr_map; i++) { + __be16 bdf_be = cpu_to_be16(map[i].bdf); + u32 val; + u8 hash; + + hash = crc8(qcom_pcie_crc8_table, (u8 *)&bdf_be, sizeof(bdf_be), + 0); + + val = readl(bdf_to_sid_base + hash * sizeof(u32)); + + /* If the register is already populated, look for next available entry */ + while (val) { + u8 current_hash = hash++; + u8 next_mask = 0xff; + + /* If NEXT field is NULL then update it with next hash */ + if (!(val & next_mask)) { + val |= (u32)hash; + writel(val, bdf_to_sid_base + current_hash * sizeof(u32)); + } + + val = readl(bdf_to_sid_base + hash * sizeof(u32)); + } + + /* BDF [31:16] | SID [15:8] | NEXT [7:0] */ + val = map[i].bdf << 16 | (map[i].smmu_sid - smmu_sid_base) << 8 | 0; + writel(val, bdf_to_sid_base + hash * sizeof(u32)); + } + + kfree(map); + + return 0; +} + static int qcom_pcie_get_resources_2_9_0(struct qcom_pcie *pcie) { struct qcom_pcie_resources_2_9_0 *res = &pcie->res.v2_9_0; @@ -1077,77 +1148,6 @@ static int qcom_pcie_link_up(struct dw_pcie *pci) return !!(val & PCI_EXP_LNKSTA_DLLLA); } -static int qcom_pcie_config_sid_sm8250(struct qcom_pcie *pcie) -{ - /* iommu map structure */ - struct { - u32 bdf; - u32 phandle; - u32 smmu_sid; - u32 smmu_sid_len; - } *map; - void __iomem *bdf_to_sid_base = pcie->parf + PARF_BDF_TO_SID_TABLE_N; - struct device *dev = pcie->pci->dev; - u8 qcom_pcie_crc8_table[CRC8_TABLE_SIZE]; - int i, nr_map, size = 0; - u32 smmu_sid_base; - - of_get_property(dev->of_node, "iommu-map", &size); - if (!size) - return 0; - - map = kzalloc(size, GFP_KERNEL); - if (!map) - return -ENOMEM; - - of_property_read_u32_array(dev->of_node, - "iommu-map", (u32 *)map, size / sizeof(u32)); - - nr_map = size / (sizeof(*map)); - - crc8_populate_msb(qcom_pcie_crc8_table, QCOM_PCIE_CRC8_POLYNOMIAL); - - /* Registers need to be zero out first */ - memset_io(bdf_to_sid_base, 0, CRC8_TABLE_SIZE * sizeof(u32)); - - /* Extract the SMMU SID base from the first entry of iommu-map */ - smmu_sid_base = map[0].smmu_sid; - - /* Look for an available entry to hold the mapping */ - for (i = 0; i < nr_map; i++) { - __be16 bdf_be = cpu_to_be16(map[i].bdf); - u32 val; - u8 hash; - - hash = crc8(qcom_pcie_crc8_table, (u8 *)&bdf_be, sizeof(bdf_be), - 0); - - val = readl(bdf_to_sid_base + hash * sizeof(u32)); - - /* If the register is already populated, look for next available entry */ - while (val) { - u8 current_hash = hash++; - u8 next_mask = 0xff; - - /* If NEXT field is NULL then update it with next hash */ - if (!(val & next_mask)) { - val |= (u32)hash; - writel(val, bdf_to_sid_base + current_hash * sizeof(u32)); - } - - val = readl(bdf_to_sid_base + hash * sizeof(u32)); - } - - /* BDF [31:16] | SID [15:8] | NEXT [7:0] */ - val = map[i].bdf << 16 | (map[i].smmu_sid - smmu_sid_base) << 8 | 0; - writel(val, bdf_to_sid_base + hash * sizeof(u32)); - } - - kfree(map); - - return 0; -} - static int qcom_pcie_host_init(struct dw_pcie_rp *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); @@ -1268,7 +1268,7 @@ static const struct qcom_pcie_ops ops_1_9_0 = { .init = qcom_pcie_init_2_7_0, .deinit = qcom_pcie_deinit_2_7_0, .ltssm_enable = qcom_pcie_2_3_2_ltssm_enable, - .config_sid = qcom_pcie_config_sid_sm8250, + .config_sid = qcom_pcie_config_sid_1_9_0, }; /* Qcom IP rev.: 2.9.0 Synopsys IP rev.: 5.00a */