From: "Krzysztof Wilczyński" <kw@linux.com>
To: Rob Herring <robh@kernel.org>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Heiko Stuebner <heiko@sntech.de>, PCI <linux-pci@vger.kernel.org>,
Shawn Lin <shawn.lin@rock-chips.com>,
Jonathan Chocron <jonnyc@amazon.com>,
Michal Simek <michal.simek@xilinx.com>,
"open list:ARM/Rockchip SoC..."
<linux-rockchip@lists.infradead.org>,
Zhou Wang <wangzhou1@hisilicon.com>,
Robert Richter <rrichter@marvell.com>,
Bjorn Helgaas <helgaas@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Will Deacon <will@kernel.org>,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH] PCI: Unify ECAM constants in native PCI Express drivers
Date: Thu, 24 Sep 2020 22:57:56 +0200 [thread overview]
Message-ID: <20200924205756.GA56768@rocinante> (raw)
In-Reply-To: <CAL_JsqKs2m_echD97C+Q_NFS=yJif0LcgLMdDLnywjz35mboKQ@mail.gmail.com>
Hi Bjorn and Rob,
[...]
> > > #define PCIE_ECAM_BUS(x) (((x) & 0xff) << 20)
> > > #define PCIE_ECAM_DEV(x) (((x) & 0x1f) << 15)
> > > #define PCIE_ECAM_FUNC(x) (((x) & 0x7) << 12)
> > >
> > > drivers/pci/controller/dwc/pcie-al.c:
> > >
> > > #define PCIE_ECAM_DEVFN(x) (((x) & 0xff) << 12)
> > >
> > > I can move PCIE_ECAM_BUS, PCIE_ECAM_DEV and PCIE_ECAM_FUNC (as
> > > PCIE_ECAM_FUN) to the linux/pci-ecam.h file, as these seem useful, but
> > > without the masks, and then update other files to use these. We could
> > > then leverage these, for example:
> > >
> > > pci_base_addr = (void __iomem *)((uintptr_t)pp->va_cfg0_base +
> > > - (busnr_ecam << 20) +
> > > - PCIE_ECAM_DEVFN(devfn));
> > > + PCIE_ECAM_BUS(busnr_ecam) +
> > > + PCIE_ECAM_FUN(devfn));
> > >
> > > What do you think? Bjorn, would that be acceptable?
> >
> > It would be nice to use the same style and same macros for all of
> > the following, which are all really doing the same thing:
> >
> > al_pcie_conf_addr_map()
> > pci_base_addr = (void __iomem *)((uintptr_t)pp->va_cfg0_base +
> > (busnr_ecam << 20) +
> > PCIE_ECAM_DEVFN(devfn));
> >
> > rockchip_pcie_rd_other_conf()
> > busdev = PCIE_ECAM_ADDR(bus->number, PCI_SLOT(devfn),
> > PCI_FUNC(devfn), where);
> >
> > nwl_pcie_map_bus()
> > relbus = (bus->number << ECAM_BUS_LOC_SHIFT) |
> > (devfn << ECAM_DEV_LOC_SHIFT);
> >
> > return pcie->ecam_base + relbus + where;
> >
> > xilinx_pcie_map_bus()
> > relbus = (bus->number << ECAM_BUS_NUM_SHIFT) |
> > (devfn << ECAM_DEV_NUM_SHIFT);
> >
> > return port->reg_base + relbus + where;
> >
> > Maybe that's something like using PCIE_ECAM_ADDR() everywhere? I'm
> > not sure there's value in having the caller do the PCI_SLOT() and
> > PCI_FUNC() decomposition, though, i.e., maybe it's something like
> > this?
> >
> > #define PCIE_ECAM_REG(x) ((x) & 0xfff)
> >
> > #define PCI_ECAM_OFFSET(bus, devfn, where) \
> > PCIE_ECAM_BUS(bus->number) | \
> > PCIE_ECAM_DEVFN(devfn) | \
> > PCIE_ECAM_REG(where)
[...]
> LGTM. This was on my radar, but not something I've looked at.
>
> There's also aardvark which isn't ECAM, but does the same calculation.
> Call it indirect ECAM:
>
> drivers/pci/controller/pci-aardvark.c:#define PCIE_CONF_BUS(bus)
> (((bus) & 0xff) << 20)
> drivers/pci/controller/pci-aardvark.c-#define PCIE_CONF_DEV(dev)
> (((dev) & 0x1f) << 15)
> drivers/pci/controller/pci-aardvark.c-#define PCIE_CONF_FUNC(fun)
> (((fun) & 0x7) << 12)
> drivers/pci/controller/pci-aardvark.c-#define PCIE_CONF_REG(reg)
> ((reg) & 0xffc)
> drivers/pci/controller/pci-aardvark.c-#define PCIE_CONF_ADDR(bus,
> devfn, where) \
> drivers/pci/controller/pci-aardvark.c- (PCIE_CONF_BUS(bus) |
> PCIE_CONF_DEV(PCI_SLOT(devfn)) | \
> drivers/pci/controller/pci-aardvark.c-
> PCIE_CONF_FUNC(PCI_FUNC(devfn)) | PCIE_CONF_REG(where))
>
> And VMD:
> drivers/pci/controller/vmd.c- char __iomem *addr = vmd->cfgbar +
> drivers/pci/controller/vmd.c: ((bus->number -
> vmd->busn_start) << 20) +
> drivers/pci/controller/vmd.c- (devfn << 12) + reg;
> drivers/pci/controller/vmd.c-
>
>
> And brcm_pcie_cfg_index().
Thank you both for good feedback!
I will send a v2 later incorporating the feedback and suggestions.
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
prev parent reply other threads:[~2020-09-24 20:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-27 22:49 [PATCH] PCI: Unify ECAM constants in native PCI Express drivers Krzysztof Wilczyński
2020-08-28 9:08 ` Jonathan Cameron
2020-09-05 20:44 ` Krzysztof Wilczyński
2020-09-22 23:27 ` Bjorn Helgaas
2020-09-23 17:23 ` Rob Herring
2020-09-24 20:57 ` Krzysztof Wilczyński [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200924205756.GA56768@rocinante \
--to=kw@linux.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=bhelgaas@google.com \
--cc=heiko@sntech.de \
--cc=helgaas@kernel.org \
--cc=jonnyc@amazon.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=michal.simek@xilinx.com \
--cc=robh@kernel.org \
--cc=rrichter@marvell.com \
--cc=shawn.lin@rock-chips.com \
--cc=wangzhou1@hisilicon.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).