Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1782460pxy; Thu, 6 May 2021 16:09:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZjnK+x9/hl7oIB7mEaMGJR2mgFOrwmVyDPCpi5sAG1mMGVFzWnTqsmwuUiCcnzQkTCUX0 X-Received: by 2002:a17:902:b18f:b029:ec:7ac0:fd1a with SMTP id s15-20020a170902b18fb02900ec7ac0fd1amr6807683plr.84.1620342545274; Thu, 06 May 2021 16:09:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620342545; cv=none; d=google.com; s=arc-20160816; b=HqRKPlTKMWBfs/pj9MFCFIpEEgmjCYeX0bykQAG1xxtFLGFMFROvACh6jN10IWSSZY OSqvYgSnjcYRzY1/6BFzwnKSevn+qrNlVvD/KKbjN89Guz1np8i/Tqhwn7lZlUeVljgG Tr/sNP2QfIrR+eGGsqHKzZdPZpCL8h1e9yA95dRGOARMsZie/NUO8Cj8vKCXtJRCGOOR McLU+Q7g5bzZ2NDCMlRO6M5sU/bTCMBlzEfZY+IVmnlgZbA9UJLwOlB7z0igq2elnmy6 KJkZmibMcWMhlVf1DU9gClrg9ygre8dE7lU9KDpBG6hHshOKxEzDqXY+sQ6XGXVilqb4 Q0wA== 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=hmxApFxt2mEPrdELGx0l7tBeLA4UXfRPKXuVbw+E29g=; b=R5ELZwT7eft7wqlSRcKaemFt5iFr+mKm/wAsOlqG1kkX/oBVhAYsTQZD0kRfgf7lLG +vs897E0+YyL6QB6JX4T2Axy8pEg7hZ9mYilVZmi3KYu2fvaDSERElhuqu8v88GuFMU0 qKt1G11N/scIkN879MiW8v6c4xkXiE24/GSZXYYB3x+Ku0sjvSLOY72LC+RQq4gn0MXX 9bGzZuJUFH9WzjwstZ2Ek1M0zlAZSVm5U6vy6e98h1s0kTWG/+jdudz7KHmSraOKP/2A QNsQySCKWqboLomDI2AEn/CfpErUczFYNJ8Z4w75sdnUJo8d2L6UWk6e1OQE8Y7Qib1J fEmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SO4Lkojz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si5586398plb.191.2021.05.06.16.08.52; Thu, 06 May 2021 16:09:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@kernel.org header.s=k20201202 header.b=SO4Lkojz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236040AbhEFPhT (ORCPT + 99 others); Thu, 6 May 2021 11:37:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:46282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235538AbhEFPdv (ORCPT ); Thu, 6 May 2021 11:33:51 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 76E81613C8; Thu, 6 May 2021 15:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620315172; bh=/zvV+LVq+BiEj5EQTG+PoYjWSGUTXma5kYGSqhsmE2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SO4Lkojzvq1tCkR9lzFTQufbRmYayxaQGTdisCbUsxZ0Z3kWr1XkuhWm+fPrHfxHG DX2++QMrlApeHy3cGTI3+Gsmr+CKws/TMblvtyr1bqQSpLFLdMjj9zFSADPqgdZIx0 DA5eQMjWt4tSv73F4F03zuw2HhYHACD1AbZ37q4od1/d+8aTKC9emiwng6Qxbeghda aHACbdDsFgesmZzRt1FxvperRklvPAtnyS5ZSzddI9XYFEZNtYCdiBrxFv/292PLgK MaljOZpHcz2yyQ7rb31uZsxQbgvVBnJCE2tX2Yovxpb/NK2e+er7ylKnkrrAzzAgTN YV5e48uXIdK0Q== Received: by pali.im (Postfix) id 2E51B89A; Thu, 6 May 2021 17:32:52 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Lorenzo Pieralisi , Thomas Petazzoni , Rob Herring , Bjorn Helgaas Cc: Russell King , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Remi Pommarel , Xogium , Tomasz Maciej Nowak , Marc Zyngier , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 27/42] PCI: aardvark: Disable bus mastering and mask all interrupts when unbinding driver Date: Thu, 6 May 2021 17:31:38 +0200 Message-Id: <20210506153153.30454-28-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210506153153.30454-1-pali@kernel.org> References: <20210506153153.30454-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ensure that after unbinding aardvark driver, PCIe cards are not be able to forward memory and I/O requests in the upstream direction and also that no interrupt can be triggered. Signed-off-by: Pali Rohár Reviewed-by: Marek Behún Fixes: 526a76991b7b ("PCI: aardvark: Implement driver 'remove' function and allow to build it as module") --- drivers/pci/controller/pci-aardvark.c | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 92f93ec48d6b..28ddffce1bec 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -1453,12 +1453,41 @@ static int advk_pcie_remove(struct platform_device *pdev) { struct advk_pcie *pcie = platform_get_drvdata(pdev); struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); + u32 val; + /* Remove PCI bus with all devices */ pci_lock_rescan_remove(); pci_stop_root_bus(bridge->bus); pci_remove_root_bus(bridge->bus); pci_unlock_rescan_remove(); + /* Disable Root Bridge I/O space, memory space and bus mastering */ + val = advk_readl(pcie, PCIE_CORE_CMD_STATUS_REG); + val &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); + advk_writel(pcie, val, PCIE_CORE_CMD_STATUS_REG); + + /* Disable MSI */ + val = advk_readl(pcie, PCIE_CORE_CTRL2_REG); + val &= ~PCIE_CORE_CTRL2_MSI_ENABLE; + advk_writel(pcie, val, PCIE_CORE_CTRL2_REG); + + /* Clear MSI address */ + advk_writel(pcie, 0, PCIE_MSI_ADDR_LOW_REG); + advk_writel(pcie, 0, PCIE_MSI_ADDR_HIGH_REG); + + /* Mask all interrupts */ + advk_writel(pcie, PCIE_MSI_ALL_MASK, PCIE_MSI_MASK_REG); + advk_writel(pcie, PCIE_ISR0_ALL_MASK, PCIE_ISR0_MASK_REG); + advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_MASK_REG); + advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_MASK_REG); + + /* Clear all interrupts */ + advk_writel(pcie, PCIE_MSI_ALL_MASK, PCIE_MSI_STATUS_REG); + advk_writel(pcie, PCIE_ISR0_ALL_MASK, PCIE_ISR0_REG); + advk_writel(pcie, PCIE_ISR1_ALL_MASK, PCIE_ISR1_REG); + advk_writel(pcie, PCIE_IRQ_ALL_MASK, HOST_CTRL_INT_STATUS_REG); + + /* Remove IRQ domains */ advk_pcie_remove_msi_irq_domain(pcie); advk_pcie_remove_irq_domain(pcie); -- 2.20.1