From nobody Thu Dec 18 09:44:15 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75D2120ADFE; Wed, 4 Dec 2024 15:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733324511; cv=none; b=tTWj42mx4nvw7+po1KQJf0BL9zwnWFRncMP3SAPAkmpRN2DFO4miiqhYgd0mQLGqV+xkXV/fr57SrSFh0yLAjfh+TUJkjydqi1yJ2XKgeeJznoE+rocLpilv99UkQeNor/Pq/CjwgMq5IrIW8rWklNvUSXtOtVi16xPxMFSYO8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733324511; c=relaxed/simple; bh=bGrthp6P6OjGXSuGAAT9PJ7U09h7+JZZ06Vtmr7nZv8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MpAI4X7l1IoTJbD44j7bfdOhwUkMSz/uaLYEUrpiK+YihDzLjoIH5TNxhcGuwgRFNaHC7ZsN259J4wNZKTK7+y+MVOEBD2YovfQoZCgrlHLS1CfJmoHBcOb8hXFcFQjjySpXIKAChPiVgi/n39td6E87/jGHPlj+iwI+2essb6Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O0ONyUa0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O0ONyUa0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FCA5C4CEDF; Wed, 4 Dec 2024 15:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733324511; bh=bGrthp6P6OjGXSuGAAT9PJ7U09h7+JZZ06Vtmr7nZv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0ONyUa0NIju4sT0cu7zhe0Q1Zo9jkyng1DWVpBdqZLqgUuK2IMVW8/iM+9uQ/yim Sy3wMVyXF0OM4fZiIKEUoFR5QVtfcKVtHcaiz4kgxNfw4AEda2sYch16JtEbhQPZgC uN1yH/2mjrL35RlGeL+7w+wvzb8BPLPXcoH29bLM+Rp6diKOhE41ehjSvRmk7knvBR bnp8KN+AanPUfepm0Az5oJkmXhTYb8sJ3hmg4qDHj+fyDQZkd0tmyu2cboIkO0uWtm 71krdOeC8i0jo2P6uVCvZIGQbpg7oUdr3Z4Yi9BHBdqI9wUXVRL9peU4pBNed/w3dh 6bkRRob4dP6fQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tIqsv-000TvG-1E; Wed, 04 Dec 2024 15:01:49 +0000 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Bjorn Helgaas , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Alyssa Rosenzweig , Frank Li Subject: [PATCH 1/2] PCI: host-generic: Allow {en,dis}able_device() to be provided via pci_ecam_ops Date: Wed, 4 Dec 2024 15:01:44 +0000 Message-Id: <20241204150145.800408-2-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204150145.800408-1-maz@kernel.org> References: <20241204150145.800408-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kw@linux.com, manivannan.sadhasivam@linaro.org, robh@kernel.org, alyssa@rosenzweig.io, Frank.Li@nxp.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" In order to let host controller drivers using the host-generic infrastructure use the {en,dis}able_device() callbacks that can be used to configure sideband RID mapping hardware, provide these two callbacks as part of the pci_ecap_ops structure. Signed-off-by: Marc Zyngier Reviewed-by: Frank Li Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/pci-host-common.c | 2 ++ include/linux/pci-ecam.h | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/control= ler/pci-host-common.c index cf5f59a745b37..f441bfd6f96a8 100644 --- a/drivers/pci/controller/pci-host-common.c +++ b/drivers/pci/controller/pci-host-common.c @@ -75,6 +75,8 @@ int pci_host_common_probe(struct platform_device *pdev) =20 bridge->sysdata =3D cfg; bridge->ops =3D (struct pci_ops *)&ops->pci_ops; + bridge->enable_device =3D ops->enable_device; + bridge->disable_device =3D ops->disable_device; bridge->msi_domain =3D true; =20 return pci_host_probe(bridge); diff --git a/include/linux/pci-ecam.h b/include/linux/pci-ecam.h index 3a4860bd27586..3a10f8cfc3ad5 100644 --- a/include/linux/pci-ecam.h +++ b/include/linux/pci-ecam.h @@ -45,6 +45,10 @@ struct pci_ecam_ops { unsigned int bus_shift; struct pci_ops pci_ops; int (*init)(struct pci_config_window *); + int (*enable_device)(struct pci_host_bridge *, + struct pci_dev *); + void (*disable_device)(struct pci_host_bridge *, + struct pci_dev *); }; =20 /* --=20 2.39.2 From nobody Thu Dec 18 09:44:15 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75D9320B1E0; Wed, 4 Dec 2024 15:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733324511; cv=none; b=BQRHR7mgNXi7ti68iSvGmqcvx/gPfTlQOFmr8urs0N/6Xz1L44AFZjTg9LmWect6QrpYos/Zo4qEeMCc5Vt60GnmKKqF15VWGcPPc4fA4SesuJR9VL/uh9IdZ45S37SuPZYK/N0fG2I2E9LdTbI+P4M9mAF/AzzAr84YwgtoWI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733324511; c=relaxed/simple; bh=QkFC1E8ORPu9Ne0GyjX1Po1qGhOZQ6JkT3lHao3IQsI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZwZBz/jPfSKy1jW6YtXnAwWRP88MDzkTuZgcA1cX7jI5BMxiWIesxGMg/233ANLSK26zXvOTlvCek9a04PEdnVVZ7F9DhCrR+SBj7koXIhB93v5vjeUtZUC5Qfos5k+6xjuJ79dqBuhvnP9Hltua0CCpIEawotbKVzCM7YdHPB0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OneFgRhu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OneFgRhu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E289C4CEE1; Wed, 4 Dec 2024 15:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733324511; bh=QkFC1E8ORPu9Ne0GyjX1Po1qGhOZQ6JkT3lHao3IQsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OneFgRhuMZcpMXvXGH2sNjjiLoVbivUuxMbDW3R/a50ggHowA7AfijKDDI5X7o7dj iO1FVN5v+iZQQkxWR00nZ6R3zGP1BqGtAx4Rs4QMlKvWdKLMsDUibKdPFYjDTrPRKW LZ9pDziKKT5K5X+JM3DaFdz/gv9VnVk8Qvp/8XFm0TYSzKW8+iRCbWVeaX/CSpBXoY iGsthjrLqxmPmYH27RDHNP3IAsIf8z7jC/g3Gzvot/q5UxNV6/aZ9npmIUsm+f5lu3 0ftY/dFdkkuJJVAUZsdCXrm/apPx8xVC+289embS0KGwxaz5YSssvCvj/UAiEukf1Y 82PjqvM9AHo2g== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tIqsv-000TvG-7v; Wed, 04 Dec 2024 15:01:49 +0000 From: Marc Zyngier To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Bjorn Helgaas , Lorenzo Pieralisi , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Manivannan Sadhasivam , Rob Herring , Alyssa Rosenzweig , Frank Li Subject: [PATCH 2/2] PCI: apple: Convert to {en,dis}able_device() callbacks Date: Wed, 4 Dec 2024 15:01:45 +0000 Message-Id: <20241204150145.800408-3-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20241204150145.800408-1-maz@kernel.org> References: <20241204150145.800408-1-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bhelgaas@google.com, lpieralisi@kernel.org, kw@linux.com, manivannan.sadhasivam@linaro.org, robh@kernel.org, alyssa@rosenzweig.io, Frank.Li@nxp.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Content-Type: text/plain; charset="utf-8" Now that the core host-bridge infrastructure is able to give us a callback on each device being added or removed, convert the bus-notifier hack to it. Signed-off-by: Marc Zyngier Reviewed-by: Frank Li Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/pcie-apple.c | 75 ++++++----------------------- 1 file changed, 15 insertions(+), 60 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/p= cie-apple.c index fefab2758a064..a7e51bc1c2fe8 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include =20 @@ -667,12 +666,16 @@ static struct apple_pcie_port *apple_pcie_get_port(st= ruct pci_dev *pdev) return NULL; } =20 -static int apple_pcie_add_device(struct apple_pcie_port *port, - struct pci_dev *pdev) +static int apple_pcie_enable_device(struct pci_host_bridge *bridge, struct= pci_dev *pdev) { u32 sid, rid =3D pci_dev_id(pdev); + struct apple_pcie_port *port; int idx, err; =20 + port =3D apple_pcie_get_port(pdev); + if (!port) + return 0; + dev_dbg(&pdev->dev, "added to bus %s, index %d\n", pci_name(pdev->bus->self), port->idx); =20 @@ -698,12 +701,16 @@ static int apple_pcie_add_device(struct apple_pcie_po= rt *port, return idx >=3D 0 ? 0 : -ENOSPC; } =20 -static void apple_pcie_release_device(struct apple_pcie_port *port, - struct pci_dev *pdev) +static void apple_pcie_disable_device(struct pci_host_bridge *bridge, stru= ct pci_dev *pdev) { + struct apple_pcie_port *port; u32 rid =3D pci_dev_id(pdev); int idx; =20 + port =3D apple_pcie_get_port(pdev); + if (!port) + return; + mutex_lock(&port->pcie->lock); =20 for_each_set_bit(idx, port->sid_map, port->sid_map_sz) { @@ -721,45 +728,6 @@ static void apple_pcie_release_device(struct apple_pci= e_port *port, mutex_unlock(&port->pcie->lock); } =20 -static int apple_pcie_bus_notifier(struct notifier_block *nb, - unsigned long action, - void *data) -{ - struct device *dev =3D data; - struct pci_dev *pdev =3D to_pci_dev(dev); - struct apple_pcie_port *port; - int err; - - /* - * This is a bit ugly. We assume that if we get notified for - * any PCI device, we must be in charge of it, and that there - * is no other PCI controller in the whole system. It probably - * holds for now, but who knows for how long? - */ - port =3D apple_pcie_get_port(pdev); - if (!port) - return NOTIFY_DONE; - - switch (action) { - case BUS_NOTIFY_ADD_DEVICE: - err =3D apple_pcie_add_device(port, pdev); - if (err) - return notifier_from_errno(err); - break; - case BUS_NOTIFY_DEL_DEVICE: - apple_pcie_release_device(port, pdev); - break; - default: - return NOTIFY_DONE; - } - - return NOTIFY_OK; -} - -static struct notifier_block apple_pcie_nb =3D { - .notifier_call =3D apple_pcie_bus_notifier, -}; - static int apple_pcie_init(struct pci_config_window *cfg) { struct device *dev =3D cfg->parent; @@ -799,23 +767,10 @@ static int apple_pcie_init(struct pci_config_window *= cfg) return 0; } =20 -static int apple_pcie_probe(struct platform_device *pdev) -{ - int ret; - - ret =3D bus_register_notifier(&pci_bus_type, &apple_pcie_nb); - if (ret) - return ret; - - ret =3D pci_host_common_probe(pdev); - if (ret) - bus_unregister_notifier(&pci_bus_type, &apple_pcie_nb); - - return ret; -} - static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops =3D { .init =3D apple_pcie_init, + .enable_device =3D apple_pcie_enable_device, + .disable_device =3D apple_pcie_disable_device, .pci_ops =3D { .map_bus =3D pci_ecam_map_bus, .read =3D pci_generic_config_read, @@ -830,7 +785,7 @@ static const struct of_device_id apple_pcie_of_match[] = =3D { MODULE_DEVICE_TABLE(of, apple_pcie_of_match); =20 static struct platform_driver apple_pcie_driver =3D { - .probe =3D apple_pcie_probe, + .probe =3D pci_host_common_probe, .driver =3D { .name =3D "pcie-apple", .of_match_table =3D apple_pcie_of_match, --=20 2.39.2