From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0EA318991E for ; Sat, 2 Nov 2024 11:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730548485; cv=none; b=Wr471YCmVqgCvl6KRUsRvhBc0HKTZQiaHzqFQIC66qD6n1dIO4DRBT0etP01EQpbJ/hjVPkdLLZgHI6BhyLfVAu6/g9gdbvvAPoFg8g1KIBT3R8JW1Uc6MMpt5mhtGFtXJyVIjBGYxGYlNQ1XpDTBMDL8VaaSUGibPStl8TIk7Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730548485; c=relaxed/simple; bh=uenxxXG7WDG5CmlqwyqtlRiBDcCxllosDV07ROVKTgk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LGvnlnKlaJlMfWbbZLdXWPC0VJ9qb8M4V8ETuqsZuXJzAPXRCewwQrgcxaUjWqdJS8EYZiARjEon3BTjh5TcAvmqfVidnuWELvnlkKNFdeRMOGN0kvMhkp5a42Of2rIAIUoMp7r8AgVT/v0EMzcLzsgTrsgEgm0NQB0joji8wgI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=y85azVdq; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="y85azVdq" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-720d14c8dbfso1417344b3a.0 for ; Sat, 02 Nov 2024 04:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730548483; x=1731153283; darn=lists.linux.dev; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=Yf5PO0O/8GxH6YaffdPErJ0yX0DmIFh2NMk1EvLbRA8=; b=y85azVdqDON32bMUPpTO+oB58TSzjL2c36pHdQNwu3yz3mLJ3nrJhGBTcuCfZkxDSL ol+YCeKFztaU5RWKF+jnH1Tan5YjzQnrOL74x9g7hDX9WbIWp0JOQit1JkYFsj2qU5Gd i/Zk4bhdNgmETbkqXFzTz1t/dKYEsByfRozNmvs4jwICTrWc8f6A0NRPFlInN4m4L3OI 8ucYs6ImX1CKvH+90joe+/1D3e7ETFbOYWAHDshrsVAt+PNZXa9jVV/RcKDvoEykyclW ymSb/a1+Etwaf6rCgi69NunlqT8wVNFuKjSWM74za8tlvwfYm4k0f+I+Xxv7F7GdexlL Z6wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730548483; x=1731153283; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Yf5PO0O/8GxH6YaffdPErJ0yX0DmIFh2NMk1EvLbRA8=; b=n1MBnNLvbrO5E0vetTLbHTe+M+8GfzoSJmRbNhvKSxAkpND5ZbjGGy1pQ9zM1MDDdT VqKaR+FlgDum4Od5l3VRNtK4dLverPRDcLdrwepLr/ElfMb2ijFqb8Q+jD2GRr+9IRQ3 u+u5v3OlH/R7WPe0Oy6UbC+pK2Cl2KEJCAbeBq1X+c98qLyYSu4M9vrYO4MgYNTCZIa2 LgnO27Kyb5ThvUM3r9vb2GExIif+KwKj/hh/FPFpPgDbE8vixsZN6M5EheAwi0STZHtv RjJ38nLayH+HAkTdMGxQRgSBnXhegWVMr8GtvPWRle2cvPq8HE47c0oZ4Vn40Nl46iPa zs7g== X-Forwarded-Encrypted: i=1; AJvYcCXaMKjNeu7iLGbpDcZqEKSwnF0klG5FbvbyhQxg6DBVGdK66MKtJenByqc7a2Ib/zwIBiw=@lists.linux.dev X-Gm-Message-State: AOJu0Yw4vqt7RrPHwvNJjQD1PUsHykD3TpSe71Oungo21Mpplu7XDtXg OxP7EslbYOxJy+3H2YaTubZLQc+gBRU6Lo/nLXYOiccCiEOn5nmMFDmmmUfRVg== X-Google-Smtp-Source: AGHT+IFBSMlqCkyuHYgmkW0THyLKy0cIuZ+FHeVb4thr/BQ4WLID6ROgAM8u2xitC9jx8P6RXoMQtA== X-Received: by 2002:a05:6a00:1397:b0:714:15ff:a2a4 with SMTP id d2e1a72fcca58-720b9c96d0emr14158400b3a.13.1730548483312; Sat, 02 Nov 2024 04:54:43 -0700 (PDT) Received: from thinkpad ([220.158.156.192]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8cf3sm4023582b3a.20.2024.11.02.04.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Nov 2024 04:54:42 -0700 (PDT) Date: Sat, 2 Nov 2024 17:24:35 +0530 From: Manivannan Sadhasivam To: Marc Zyngier Cc: Frank Li , Bjorn Helgaas , Richard Zhu , Lucas Stach , Lorenzo Pieralisi , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Rob Herring , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev, alyssa@rosenzweig.io, bpf@vger.kernel.org, broonie@kernel.org, jgg@ziepe.ca, joro@8bytes.org, lgirdwood@gmail.com, p.zabel@pengutronix.de, robin.murphy@arm.com, will@kernel.org Subject: Re: [PATCH v3 1/2] PCI: Add enable_device() and disable_device() callbacks for bridges Message-ID: <20241102115435.s7oycrh2pjkfhpsu@thinkpad> References: <20241024-imx95_lut-v3-0-7509c9bbab86@nxp.com> <20241024-imx95_lut-v3-1-7509c9bbab86@nxp.com> <20241102111012.23zwz4et2qkafyca@thinkpad> <86jzdl27my.wl-maz@kernel.org> Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <86jzdl27my.wl-maz@kernel.org> On Sat, Nov 02, 2024 at 11:32:37AM +0000, Marc Zyngier wrote: > On Sat, 02 Nov 2024 11:10:12 +0000, > Manivannan Sadhasivam wrote: > > > > On Thu, Oct 24, 2024 at 06:34:44PM -0400, Frank Li wrote: > > > Some PCIe host bridges require special handling when enabling or disabling > > > PCIe Endpoints. For example, the i.MX95 platform has a lookup table to map > > > Requester IDs to StreamIDs, which are used by the SMMU and MSI controller > > > to identify the source of DMA accesses. > > > > > > Without this mapping, DMA accesses may target unintended memory, which > > > would corrupt memory or read the wrong data. > > > > > > Add a host bridge .enable_device() hook the imx6 driver can use to > > > configure the Requester ID to StreamID mapping. The hardware table isn't > > > big enough to map all possible Requester IDs, so this hook may fail if no > > > table space is available. In that case, return failure from > > > pci_enable_device(). > > > > > > It might make more sense to make pci_set_master() decline to enable bus > > > mastering and return failure, but it currently doesn't have a way to return > > > failure. > > > > > > Signed-off-by: Frank Li > > > --- > > > Change from v2 to v3 > > > - use Bjorn suggest's commit message. > > > - call disable_device() when error happen. > > > > > > Change from v1 to v2 > > > - move enable(disable)device ops to pci_host_bridge > > > --- > > > drivers/pci/pci.c | 23 ++++++++++++++++++++++- > > > include/linux/pci.h | 2 ++ > > > 2 files changed, 24 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > > index 7d85c04fbba2a..5e0cb9b6f4d4f 100644 > > > --- a/drivers/pci/pci.c > > > +++ b/drivers/pci/pci.c > > > @@ -2056,6 +2056,7 @@ int __weak pcibios_enable_device(struct pci_dev *dev, int bars) > > > static int do_pci_enable_device(struct pci_dev *dev, int bars) > > > { > > > int err; > > > + struct pci_host_bridge *host_bridge; > > > struct pci_dev *bridge; > > > u16 cmd; > > > u8 pin; > > > @@ -2068,9 +2069,16 @@ static int do_pci_enable_device(struct pci_dev *dev, int bars) > > > if (bridge) > > > pcie_aspm_powersave_config_link(bridge); > > > > > > + host_bridge = pci_find_host_bridge(dev->bus); > > > + if (host_bridge && host_bridge->enable_device) { > > > + err = host_bridge->enable_device(host_bridge, dev); > > > + if (err) > > > + return err; > > > + } > > > > How about wrapping the enable/disable part in a helper? > > > > int pci_host_bridge_enable_device(dev); > > void pci_host_bridge_disable_device(dev); > > > > The definition could be placed in drivers/pci/pci.h as an inline > > function. > > What does it bring? I would see the point if there was another user. > But this is very much core infrastructure which doesn't lend itself to > duplication. > > Unless you have something in mind? > IMO, it adds a nice encapsulation to help readers understand what this piece of code is all about and also keeps the callers short. Plus the disable helper is reused in both error and pci_disable_device() (if that matters). - Mani -- மணிவண்ணன் சதாசிவம்