[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAL_Jsq+g=ntTQ5rs9V0pB9U=Jq3Rf0C0akmdJD60GTQTGPeAGQ@mail.gmail.com>
Date: Fri, 21 Feb 2025 09:47:00 -0600
From: Rob Herring <robh@...nel.org>
To: Marc Zyngier <maz@...nel.org>
Cc: Alyssa Rosenzweig <alyssa@...enzweig.io>, Hector Martin <marcan@...can.st>,
Sven Peter <sven@...npeter.dev>, Bjorn Helgaas <bhelgaas@...gle.com>,
Lorenzo Pieralisi <lpieralisi@...nel.org>, Krzysztof Wilczyński <kw@...ux.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Mark Kettenis <kettenis@...nbsd.org>,
Stan Skowronek <stan@...ellium.com>, asahi@...ts.linux.dev,
linux-arm-kernel@...ts.infradead.org, linux-pci@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 7/7] PCI: apple: Add T602x PCIe support
On Thu, Feb 13, 2025 at 12:01 PM Marc Zyngier <maz@...nel.org> wrote:
>
> On Thu, 13 Feb 2025 17:56:19 +0000,
> Rob Herring <robh@...nel.org> wrote:
> >
> > On Tue, Feb 11, 2025 at 1:54 PM Alyssa Rosenzweig <alyssa@...enzweig.io> wrote:
> > >
> > > From: Hector Martin <marcan@...can.st>
> > >
> > > This version of the hardware moved around a bunch of registers, so we
> > > drop the old compatible for these and introduce register offset
> > > structures to handle the differences.
> > >
> > > Signed-off-by: Hector Martin <marcan@...can.st>
> > > Signed-off-by: Alyssa Rosenzweig <alyssa@...enzweig.io>
> > > ---
> > > drivers/pci/controller/pcie-apple.c | 125 ++++++++++++++++++++++++++++++------
> > > 1 file changed, 105 insertions(+), 20 deletions(-)
> > >
> > > diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c
> > > index 7f4839fb0a5b15a9ca87337f53c14a1ce08301fc..7c598334427cb56ca066890ac61143ae1d3ed744 100644
> > > --- a/drivers/pci/controller/pcie-apple.c
> > > +++ b/drivers/pci/controller/pcie-apple.c
> > > @@ -26,6 +26,7 @@
> > > #include <linux/list.h>
> > > #include <linux/module.h>
> > > #include <linux/msi.h>
> > > +#include <linux/of_device.h>
> >
> > Drivers should not need this...
> >
> > > +const struct reg_info t602x_hw = {
> > > + .phy_lane_ctl = 0,
> > > + .port_msiaddr = PORT_T602X_MSIADDR,
> > > + .port_msiaddr_hi = PORT_T602X_MSIADDR_HI,
> > > + .port_refclk = 0,
> > > + .port_perst = PORT_T602X_PERST,
> > > + .port_rid2sid = PORT_T602X_RID2SID,
> > > + .port_msimap = PORT_T602X_MSIMAP,
> > > + .max_rid2sid = 512, /* 16 on t602x, guess for autodetect on future HW */
> > > + .max_msimap = 512, /* 96 on t602x, guess for autodetect on future HW */
> > > +};
> > > +
> > > +static const struct of_device_id apple_pcie_of_match_hw[] = {
> > > + { .compatible = "apple,t6020-pcie", .data = &t602x_hw },
> > > + { .compatible = "apple,pcie", .data = &t8103_hw },
> > > + { }
> > > +};
> >
> > You should not have 2 match tables.
> >
> > > @@ -750,13 +828,19 @@ static int apple_pcie_init(struct pci_config_window *cfg)
> > > struct platform_device *platform = to_platform_device(dev);
> > > struct device_node *of_port;
> > > struct apple_pcie *pcie;
> > > + const struct of_device_id *match;
> > > int ret;
> > >
> > > + match = of_match_device(apple_pcie_of_match_hw, dev);
> > > + if (!match)
> > > + return -ENODEV;
> > > +
> > > pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
> > > if (!pcie)
> > > return -ENOMEM;
> > >
> > > pcie->dev = dev;
> > > + pcie->hw = match->data;
> > >
> > > mutex_init(&pcie->lock);
> > >
> > > @@ -795,6 +879,7 @@ static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
> > > };
> > >
> > > static const struct of_device_id apple_pcie_of_match[] = {
> > > + { .compatible = "apple,t6020-pcie", .data = &apple_pcie_cfg_ecam_ops },
> > > { .compatible = "apple,pcie", .data = &apple_pcie_cfg_ecam_ops },
> > > { }
> >
> > You are going to need to merge the data to 1 struct.
> >
> > And then use (of_)?device_get_match_data() in probe().
>
> No, that will break the driver. This isn't a standalone driver, but
> only an ECAM shim (as you can tell from the actual probe function).
Yes, I'm aware of that issue. The self-contained solution is just:
struct apple_match_data {
const struct pci_ecam_ops ops;
const struct reg_info info;
};
That works for pci_host_common_probe and apple_pcie_init. You don't
actually have to match again, but just cast the ops pointer. Yeah, no
type checking, but that already happens with of_match_table data.
Another solution is you could have 2 .init() hooks.
The somewhat more invasive solution is to define a struct with
pci_ecam_ops and a void pointer for extra data for ECAM match data.
Last time I looked at this, I think I needed something like this to
share more of the ECAM code with host drivers needing more setup.
There's a few cases of host controllers that have an ECAM space, but
still need a full driver.
The bottom line is drivers shouldn't be including of_device.h because
it's for bus implementations. I've worked to remove a bunch, but
there's still a bunch left. Please don't add more.
Rob
Powered by blists - more mailing lists