From: Will Deacon <will.deacon@arm.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
Liviu Dudau <Liviu.Dudau@arm.com>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"bhelgaas@google.com" <bhelgaas@google.com>,
"mohit.kumar@st.com" <mohit.kumar@st.com>
Subject: Re: [PATCH 2/3] PCI: ARM: add support for virtual PCI host controller
Date: Wed, 5 Feb 2014 19:09:47 +0000 [thread overview]
Message-ID: <20140205190947.GA22297@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <3460536.Sh23gjDa6X@wuerfel>
Hi Arnd,
Thanks for having a look.
On Tue, Feb 04, 2014 at 07:13:49PM +0000, Arnd Bergmann wrote:
> On Tuesday 04 February 2014 16:53:03 Will Deacon wrote:
> > +
> > +- ranges : As described in IEEE Std 1275-1994, but must provide
> > + at least a definition of the Configuration Space plus
> > + one or both of IO and Memory Space.
> > +
>
> I might need to reread the spec, but I think the config space is not
> actually supposed to be in the 'ranges' of the host bridge at all,
> and it should just be listed in the 'reg'.
This wasn't at all clear to me (I listed it in the cover-letter as being
something to sort out).
> IIRC the reason why the config space is part of the three-cell address
> is so that you can have funky ways to say "memory space of the device
> with bus/dev/fn is actually translated to address X rather then Y".
>
> It's too late to change that for the other drivers now, after the
> binding is established.
The spec is based on the idea that open-firmware enumerates your entire PCI
bus topology, then provides the Conriguation Space address for each device
using a reg property.
Since:
(a) This doesn't match what we're planning to support
(b) Runs the risk of making the "reg" encoding something specific to this
driver
(c) Doesn't match how we describe Memory and IO Spaces
(d) There is already precendence in mainline
I chose to use "ranges" instead.
Now, if "reg" is definitely the correct thing to do, is it simply a matter
of putting the Configuration Space base address in there, or do we also need
to do the rest of what ePAPR says (expansion ROM details, ...)? I don't like
the idea of enumerating the entire bus in the DT when we don't need to.
> > +Configuration Space is assumed to be memory-mapped (as opposed to being
> > +accessed via an ioport) and laid out with a direct correspondence to the
> > +geography of a PCI bus address, by concatenating the various components
> > +to form a 24-bit offset:
> > +
> > + cfg_offset(bus, device, function, register) =
> > + bus << 16 | device << 11 | function << 8 | register
>
> This won't allow extended config space. Why not just do the
> regular mmconfig layout and make this:
>
> cfg_offset(bus, device, function, register) =
> bus << 20 | device << 15 | function << 12 | register;
Is it worth adding a DT property to support both, or is ECAM the only thing
to care about? I'm happy either way, although I'll need to hack kvmtool to
use the new scheme.
> > +static int virt_pci_setup(int nr, struct pci_sys_data *sys)
> > +{
> > + struct virt_pci *pci = sys->private_data;
> > +
> > + if (resource_type(&pci->io)) {
> > + pci_add_resource(&sys->resources, &pci->io);
> > + pci_ioremap_io(nr * resource_size(&pci->io), pci->io.start);
> > + }
>
> This should really compute an io_offset.
>
> > + if (resource_type(&pci->mem))
> > + pci_add_resource(&sys->resources, &pci->mem);
>
> and also a mem_offset, which is something different.
As somebody new to PCI, I'm afraid you've lost me here. Are you referring to
using pci_add_resource_offset instead, then removing my restriction on
having a single resource from the parsing code?
> > + pci->cfg_base = devm_ioremap_resource(pci->dev, &pci->cfg);
> > + return !IS_ERR(pci->cfg_base);
> > +}
> > +
> > +static const struct of_device_id virt_pci_of_match[] = {
> > + { .compatible = "linux,pci-virt" },
> > + { },
> > +};
> > +MODULE_DEVICE_TABLE(of, virt_pci_of_match);
>
> I don't think we even want "virt" in the compatible string. The
> binding should be generic enough that it can actually work with
> real hardware.
Sure. How about "arm,pci-generic" ? Alternatives are
"arm,pcie-generic" or "linux,pci-generic".
> > + for_each_of_pci_range(&parser, &range) {
> > + u32 restype = range.flags & IORESOURCE_TYPE_BITS;
> > +
> > + switch (restype) {
> > + case IORESOURCE_IO:
> > + if (resource_type(&pci->io))
> > + dev_warn(dev,
> > + "ignoring additional io resource\n");
> > + else
> > + of_pci_range_to_resource(&range, np, &pci->io);
> > + break;
> > + case IORESOURCE_MEM:
> > + if (resource_type(&pci->mem))
> > + dev_warn(dev,
> > + "ignoring additional mem resource\n");
> > + else
> > + of_pci_range_to_resource(&range, np, &pci->mem);
> > + break;
>
> This shows once more that the range parser code is suboptimal. So far
> every single driver got the I/O space wrong here, because the obvious
> way to write this function is also completely wrong.
I see you mentioned to Liviu that you should register a logical resource,
rather than physical resource returned from the parser. It seems odd that
I/O space appears to work with this code as-is (I've tested it on arm using
kvmtool by removing the memory bars).
> What you get out of "of_pci_range_to_resource(&range, np, &pci->io)"
> is not the resource you want to pass into pci_add_resource()
> later.
Do I need to open-code the resource translation from phys -> logical?
>
> > + memset(&hw, 0, sizeof(hw));
> > + hw.nr_controllers = 1;
> > + hw.private_data = (void **)&pci;
> > + hw.setup = virt_pci_setup;
> > + hw.map_irq = of_irq_parse_and_map_pci;
> > + hw.ops = &virt_pci_ops;
> > + pci_common_init_dev(dev, &hw);
>
> Since most fields here are constant, I'd just write this as
>
> struct hw_pci hw = {
> .nr_controllers = 1,
> .setup = virt_pci_setup,
> ...
> };
Can do.
Thanks,
Will
next prev parent reply other threads:[~2014-02-05 19:10 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-04 16:53 [PATCH 0/3] ARM: PCI: implement virtual PCI host controller Will Deacon
2014-02-04 16:53 ` [PATCH 1/3] ARM: bios32: use pci_enable_resource to enable PCI resources Will Deacon
2014-02-12 1:06 ` Bjorn Helgaas
2014-02-12 16:18 ` Will Deacon
2014-02-04 16:53 ` [PATCH 2/3] PCI: ARM: add support for virtual PCI host controller Will Deacon
2014-02-04 19:13 ` Arnd Bergmann
2014-02-05 19:09 ` Will Deacon [this message]
2014-02-05 19:27 ` Jason Gunthorpe
2014-02-05 19:41 ` Peter Maydell
2014-02-05 20:26 ` Arnd Bergmann
2014-02-05 20:53 ` Jason Gunthorpe
2014-02-06 8:28 ` Arnd Bergmann
2014-02-06 20:31 ` Russell King - ARM Linux
2014-02-09 20:18 ` Arnd Bergmann
2014-02-09 20:34 ` Russell King - ARM Linux
2014-02-11 19:15 ` Arnd Bergmann
2014-02-07 11:46 ` Will Deacon
2014-02-07 17:54 ` Jason Gunthorpe
2014-02-12 18:10 ` Will Deacon
2014-02-12 18:19 ` Jason Gunthorpe
2014-02-12 18:21 ` Will Deacon
2014-02-09 20:30 ` Arnd Bergmann
2014-02-10 17:34 ` Jason Gunthorpe
2014-02-11 10:42 ` Arnd Bergmann
2014-02-12 19:43 ` Jason Gunthorpe
2014-02-12 20:07 ` Arnd Bergmann
2014-02-12 20:33 ` Bjorn Helgaas
2014-02-12 21:15 ` Thomas Petazzoni
2014-02-12 22:24 ` Jason Gunthorpe
2014-02-12 19:49 ` Will Deacon
2014-02-06 8:54 ` Anup Patel
2014-02-06 10:26 ` Arnd Bergmann
2014-02-06 10:52 ` Anup Patel
2014-02-06 10:54 ` Liviu Dudau
2014-02-06 11:00 ` Will Deacon
2014-02-06 11:28 ` Arnd Bergmann
2014-02-04 16:53 ` [PATCH 3/3] ARM: mach-virt: allow PCI support to be selected Will Deacon
2014-04-03 22:07 ` [PATCH 0/3] ARM: PCI: implement virtual PCI host controller Bjorn Helgaas
2014-04-14 17:13 ` Will Deacon
2014-04-14 18:48 ` Arnd Bergmann
2014-04-15 14:47 ` Will Deacon
2014-04-15 15:26 ` Arnd Bergmann
2014-04-16 13:58 ` Will Deacon
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=20140205190947.GA22297@mudshark.cambridge.arm.com \
--to=will.deacon@arm.com \
--cc=Liviu.Dudau@arm.com \
--cc=arnd@arndb.de \
--cc=bhelgaas@google.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=mohit.kumar@st.com \
/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).