From patchwork Sun Jul 25 04:00:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 485650 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp2693874jao; Sat, 24 Jul 2021 21:02:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVYVXIh9U5ZW8vxl8Y922T20dUTUS9qu4X//4qh/+69+qXfdFw+3lA5gzG7YOPNzl6v9Sz X-Received: by 2002:a5d:8596:: with SMTP id f22mr9969287ioj.147.1627185768101; Sat, 24 Jul 2021 21:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627185768; cv=none; d=google.com; s=arc-20160816; b=K9xWTQC3avx/qCuIG8UBPxSrLW6eP1v3Y+mr7XBsEICbJmuYnfgS4uSmZHzLM6kXX4 HsT/WTa6smRLJUo1KR+F/qabytNuemknegZOMGyEXg0A9RdXb54KES7k7dWDbDsE+7n5 RGzLYjdR99Yx4s3wVu036W2A47I9WHG2ryiehmupoQ/LBQGytKS5RYzYlHlYegkil35i m0RHET/oY0S/1aJCUDTU5tnnyEm5F4saXQV037aUNUU2CZGXicHJssnHuYN0XTocbZFC pIV2NI4qTB4XOVU/zyzHTeqRH/Zj0NTSmm5Ib5RJ+3WUXu7hgBxqwpftgaVSzSHJikOq 6uMA== 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=fdmG3WG+Fl0BSnXJiqQEACHTkoffgPGp8XBicBQYpOo=; b=KyiaO3nbJ1kphScTZn4NxrNeCaY1xIEidik/jziIts1KxrDHQD/xP5OR8OpripMLza lA3vk6UjpmCu4Q3sAPwDKiJzRRy1p+eZd2YMFir6klZaLO+Dy8NtWMjKjAgWDgfBiYp9 dp0+TEbYkk8+ao/ZwNgX75+XQMc1p1fsx4TRT5uB8GzYEw91w+jCcwMZyQSyyl1/MBUD HLU6dEZ7JxB8B4/ShDPrQeooJPR8NEW3L1wcOGb0xecMiSPHcBrUw4nLy8PL7t6KQiLw yu274JM0SSfIQKPRZ3RbobD2Hpc7LC9W5ZK+2uiVxmiiXg/yY8t93pDAqLjkocDV1raU KIPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bUyKH/yL"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z24si38699427jap.49.2021.07.24.21.02.47; Sat, 24 Jul 2021 21:02:48 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="bUyKH/yL"; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-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 S230187AbhGYDWB (ORCPT + 7 others); Sat, 24 Jul 2021 23:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbhGYDV5 (ORCPT ); Sat, 24 Jul 2021 23:21:57 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDEF8C0613C1 for ; Sat, 24 Jul 2021 21:02:26 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id o185so6790896oih.13 for ; Sat, 24 Jul 2021 21:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fdmG3WG+Fl0BSnXJiqQEACHTkoffgPGp8XBicBQYpOo=; b=bUyKH/yL3uKMbRoFBycdV+AfDTE8ss1Qs1/Iw/icuLQwu0o4EOMDP7GIRMNwKcr9kW TI689VHRtv20TGBCCfe8QuPkiTDNYfaDpm4xbygf5xNYpF4L01c/QeVtBXhDpqxFeuiz dgvdUIOW6fmhDCjZSPqduzmtRWmExefdakj4p3o0RbSUhQu+mGrk+nggXMFUOeb481cQ JFPJdoh+CivVAFlrOF70psrME2PALWFTsqKG9GxYCzIGecNlisqhJvwRv7bTnnxyPael w+GNjKNDJbfaDWklYcEOAZw5MxZSL1sGyQy8sZgkCeqLL2mU8A1UkbZJWmCzwHMyjVUP 3a7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fdmG3WG+Fl0BSnXJiqQEACHTkoffgPGp8XBicBQYpOo=; b=NTmMOwo3pRBao50p1l7x4FreeclNi33hPRb/kexLKoCvkxHueNimIK6N2n6gqykHKy AH8xszSWekrjO31ka59laPmoDFCDq4KR1CtglfihnH/mCGET0xkndEKx3x9OP7hTSgPZ uLmwh1InuII2YlDqUshZGLxiU0jcryFTm2WNLPMBDog+eRqniFfmR67phuv5dHHyYsUP +uTqm7Ipv4zqen/2t64q+lMFqAxdXsHAWFYUaw2TUtByLpq6gVk5SmVcUJQbfbdUUc3O bPF9ngDF3ZG8syPZXg7Fufd8yjC7nWk8B8kkMMts76Yux0ABznPotoDjFm2E3D0ihB9D YyOw== X-Gm-Message-State: AOAM530frAcCLcAx2XluRdtlU1n0/W9qpUko9v21fQZz2ZdfkA8Phagl 1B7/W3REAqhUXnkjKxoaGMhoTQ== X-Received: by 2002:aca:4355:: with SMTP id q82mr13228367oia.165.1627185746154; Sat, 24 Jul 2021 21:02:26 -0700 (PDT) Received: from localhost.localdomain (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id q20sm872910otv.50.2021.07.24.21.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 21:02:25 -0700 (PDT) From: Bjorn Andersson To: Bjorn Helgaas , Rob Herring , Stanimir Varbanov , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wil?= =?utf-8?q?czy=C5=84ski?= Cc: linux-arm-msm@vger.kernel.org, linux-pci@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] PCI: qcom: Introduce enable/disable resource ops Date: Sat, 24 Jul 2021 21:00:36 -0700 Message-Id: <20210725040038.3966348-2-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210725040038.3966348-1-bjorn.andersson@linaro.org> References: <20210725040038.3966348-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The current model of doing resource enablement and controller initialization in a single "init" function invoked after dw_pcie_host_init() is invoked might result in clocks not being enabled at the time the "msi" interrupt fires. One such case happens reliably on the SC8180x (8cx) Snapdragon laptops, where it's seems like the bootloader touches PCIe and leaves things in a state that the "msi" interrupt will fire before we have a change to enable the clocks, resulting in an access of unclocked hardware. Introduce a two new callbacks, allowing the individual resource handling functions to be split between enable/init and deinit/disable. Helper functions for enable, disable and deinit are introduced to handle the fact that these functions may now be left without implementation. init is given a wrapper for symmetry. Signed-off-by: Bjorn Andersson --- drivers/pci/controller/dwc/pcie-qcom.c | 42 +++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) -- 2.29.2 diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index 8a7a300163e5..8a64a126de2b 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -181,9 +181,11 @@ struct qcom_pcie; struct qcom_pcie_ops { int (*get_resources)(struct qcom_pcie *pcie); + int (*enable_resources)(struct qcom_pcie *pcie); int (*init)(struct qcom_pcie *pcie); int (*post_init)(struct qcom_pcie *pcie); void (*deinit)(struct qcom_pcie *pcie); + void (*disable_resources)(struct qcom_pcie *pcie); void (*post_deinit)(struct qcom_pcie *pcie); void (*ltssm_enable)(struct qcom_pcie *pcie); int (*config_sid)(struct qcom_pcie *pcie); @@ -1345,6 +1347,31 @@ static int qcom_pcie_config_sid_sm8250(struct qcom_pcie *pcie) return 0; } +static int qcom_pcie_enable_resources(struct qcom_pcie *pcie) +{ + if (pcie->ops->enable_resources) + return pcie->ops->enable_resources(pcie); + + return 0; +} + +static int qcom_pcie_init(struct qcom_pcie *pcie) +{ + return pcie->ops->init(pcie); +} + +static void qcom_pcie_deinit(struct qcom_pcie *pcie) +{ + if (pcie->ops->deinit) + pcie->ops->deinit(pcie); +} + +static void qcom_pcie_disable_resources(struct qcom_pcie *pcie) +{ + if (pcie->ops->disable_resources) + pcie->ops->disable_resources(pcie); +} + static int qcom_pcie_host_init(struct pcie_port *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); @@ -1353,7 +1380,7 @@ static int qcom_pcie_host_init(struct pcie_port *pp) qcom_ep_reset_assert(pcie); - ret = pcie->ops->init(pcie); + ret = qcom_pcie_init(pcie); if (ret) return ret; @@ -1384,7 +1411,7 @@ static int qcom_pcie_host_init(struct pcie_port *pp) err_disable_phy: phy_power_off(pcie->phy); err_deinit: - pcie->ops->deinit(pcie); + qcom_pcie_deinit(pcie); return ret; } @@ -1520,10 +1547,14 @@ static int qcom_pcie_probe(struct platform_device *pdev) pp->ops = &qcom_pcie_dw_ops; + ret = qcom_pcie_enable_resources(pcie); + if (ret) + goto err_pm_runtime_put; + ret = phy_init(pcie->phy); if (ret) { pm_runtime_disable(&pdev->dev); - goto err_pm_runtime_put; + goto err_disable_resources; } platform_set_drvdata(pdev, pcie); @@ -1532,11 +1563,14 @@ static int qcom_pcie_probe(struct platform_device *pdev) if (ret) { dev_err(dev, "cannot initialize host\n"); pm_runtime_disable(&pdev->dev); - goto err_pm_runtime_put; + goto err_disable_resources; } return 0; +err_disable_resources: + qcom_pcie_disable_resources(pcie); + err_pm_runtime_put: pm_runtime_put(dev); pm_runtime_disable(dev);