linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	Lior Amsalem <alior@marvell.com>, Andrew Lunn <andrew@lunn.ch>,
	"Russell King - ARM Linux" <linux@arm.linux.org.uk>,
	Jason Cooper <jason@lakedaemon.net>,
	Stephen Warren <swarren@wwwdotorg.org>,
	Thierry Reding <thierry.reding@avionic-design.de>,
	"Eran Ben-Avi" <benavi@marvell.com>,
	Nadav Haklai <nadavh@marvell.com>,
	Maen Suleiman <maen@marvell.com>,
	Shadi Ammouri <shadi@marvell.com>,
	Gregory Clement <gregory.clement@free-electrons.com>,
	Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
	Tawfik Bayouk <tawfik@marvell.com>
Subject: Re: [PATCH 24/32] pci: PCIe driver for Marvell Armada 370/XP systems
Date: Tue, 12 Feb 2013 20:22:52 +0100	[thread overview]
Message-ID: <20130212202252.3a9ee3d0@skate> (raw)
In-Reply-To: <201302121830.11375.arnd@arndb.de>

Dear Arnd Bergmann,

On Tue, 12 Feb 2013 18:30:11 +0000, Arnd Bergmann wrote:
> On Tuesday 12 February 2013, Thomas Petazzoni wrote:
> > diff --git a/drivers/pci/host/Makefile b/drivers/pci/host/Makefile
> > new file mode 100644
> > index 0000000..3ad563f
> > --- /dev/null
> > +++ b/drivers/pci/host/Makefile
> > @@ -0,0 +1,4 @@
> > +obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
> > +CFLAGS_pci-mvebu.o += \
> > +	-I$(srctree)/arch/arm/plat-orion/include \
> > +	-I$(srctree)/arch/arm/mach-mvebu/include
> 
> This does not seem like a good idea to me. We should not include
> architecture specific directories from a driver directory.
> 
> What are the header files you need here? 

>From the patch itself:

+#include <plat/pcie.h>
+#include <mach/addr-map.h>

<plat/pcie.h> is needed for a few PCIe functions shared with earlier
families of Marvell SoC. My plan is that once this PCI driver gets
accepted, I work on migrating the earlier Marvell SoC families to using
this PCI driver, and therefore those functions would ultimately move in
the driver in drivers/pci/host/, which would remove the <plat/pcie.h>.

The <mach/addr-map.h> is here to access the address decoding windows
allocation/free API. And for this, there is no other long term plan
than having an API provided by the platform code in arch/arm/, and used
by drivers. Some other drivers may have to use this API as well in the
future.

I think that completely preventing <mach/> and <plat/> includes from
drivers is not possible. Some sub-architectures will also have some
bizarre mechanism to handle (in our case the address decoding windows),
for which there is no kernel-wide API and kernel-wide subsystem to
handle it. In such cases, a sub-architecture specific solution is
really the only reasonable way, and in this case, we have to include
the sub-architecture headers.

Note that I have been careful to use CFLAGS_pci-mvebu.o, so that those
include paths only apply to *this* driver. I added a separate dummy
driver in drivers/pci/host/, and verified that those include paths are
not used when building this other driver. So those special CFLAGS are
still compatible with the multiplatform kernel.

> > +/*
> > + * This product ID is registered by Marvell, and used when the
> > Marvell
> > + * SoC is not the root complex, but an endpoint on the PCIe bus.
> > It is
> > + * therefore safe to re-use this PCI ID for our emulated PCI-to-PCI
> > + * bridge.
> > + */
> > +#define MARVELL_EMULATED_PCI_PCI_BRIDGE_ID 0x7846
> 
> Just a side note: What happens if you have two of these systems and
> connect them over PCIe, putting one of them into host mode and the
> other into endpoint mode?

I am not a PCI expert, but I don't think it would cause issues. Maybe
Jason Gunthorpe can comment on this, as he originally suggested to
re-use this PCI ID.

> > +static void mvebu_pcie_setup_io_window(struct mvebu_pcie_port
> > *port,
> > +				       int enable)
> > +{
> > +	unsigned long iobase, iolimit;
> > +
> > +	if (port->bridge.iolimit < port->bridge.iobase)
> > +		return;
> > +
> > +	iolimit = 0xFFF | ((port->bridge.iolimit & 0xF0) << 8) |
> > +		(port->bridge.iolimitupper << 16);
> > +	iobase = ((port->bridge.iobase & 0xF0) << 8) |
> > +		(port->bridge.iobaseupper << 16);
> 
> I don't understand this code with the masks and shifts. Could you
> add a comment here for readers like me?

Sure, will do.

It basically comes from the PCI-to-PCI bridge specification, which
explains how the I/O address and I/O limit is split into two 16 bits
registers, with those bizarre shifts and hardcoded values. I'll put a
reference to the relevant section of the PCI-to-PCI bridge
specification here.

> > +
> > +/*
> > + * Initialize the configuration space of the PCI-to-PCI bridge
> > + * associated with the given PCIe interface.
> > + */
> > +static void mvebu_sw_pci_bridge_init(struct mvebu_pcie_port *port)
> > +{
> 
> As mentioned, I'm still skeptical of the sw_pci_bridge approach,
> so I'm not commenting on the details of your implementations
> (they seem fine on a first look though)

Yes, I understood your were still skeptical. But as I've mentioned in
other e-mails, I still haven't seen any other serious alternate
proposal that takes into account the need for dynamic assignment of
addresses.

> > +	/* Get the I/O and memory ranges from DT */
> > +	while ((range = of_pci_process_ranges(np, &res, range)) !=
> > NULL) {
> > +		if (resource_type(&res) == IORESOURCE_IO) {
> > +			memcpy(&pcie->io, &res, sizeof(res));
> > +			memcpy(&pcie->realio, &res, sizeof(res));
> > +			pcie->io.name = "I/O";
> > +			pcie->realio.start &= 0xFFFFF;
> > +			pcie->realio.end   &= 0xFFFFF;
> > +		}
> 
> The bit masking seems fishy here. What exactly are you doing,
> does this just assume you have a 1MB window at most?

Basically, I have two resources for the I/O:

 * One described in the DT, from 0xC0000000 to 0xC00FFFFF which will be
   used to create the address decoding windows for the I/O regions of
   the different PCIe interfaces. The PCI I/O virtual address 0xffe00000
   will be mapped to those physical addresses. Those address decoding
   windows are configured with the special "remap" mechanism that
   ensures that if an access is made at 0xC0000000 + offset, it will
   appear on the PCI bus as an I/O access at address "offset".

 * One covering the low addresses 0x0 -> 0xFFFFF (pcie->realio), which
   is used to tell the Linux PCI subsystem from which address range it
   should assign I/O addresses.

> Maybe something like
> 
> 	pcie->realio.start = 0;
> 	pcie->realio.end = pcie->io.end - pcie->io.start;

Indeed, that would result in the same values. If you find it clearer,
I'm fine with it.

> I suppose you also need to fix up pcie->io to be in IORESOURCE_MEM
> space instead of IORESOURCE_IO, or fix the of_pci_process_ranges
> function to return it in a different way.

Ok.

> > +static int mvebu_pcie_init(void)
> > +{
> > +	return platform_driver_probe(&mvebu_pcie_driver,
> > +				     mvebu_pcie_probe);
> > +}
> > +
> > +subsys_initcall(mvebu_pcie_init);
> 
> You don't have to do it, but I wonder if this could be a module
> with unload support instead.

This has already been discussed in the review of PATCHv2. Please see
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-January/145580.html.

Basically, doing a module_init() initialization fails, because the XHCI
USB quirks are executed before we have the chance to create the address
decoding windows, which crashes the kernel at boot time (and we have
one platform where an USB 3.0 XHCI controller sits on the PCIe bus).
Bjorn Helgaas has acknowledged the problem in
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-February/148292.html:

"""
This is not really a problem in your code; it's a generic PCI core
problem.  pci_scan_root_bus() does everything including creating the
root bus, scanning it, and adding the devices we find.  At the point
where we add a device (pci_bus_add_device()), it should be ready for a
driver to claim it -- all resource assignment should already be done.

I don't think it's completely trivial to fix this in the PCI core yet
(but we're moving in that direction) because we have some boot-time
ordering issues, e.g., x86 scans the root buses before we know about
the address space consumed by ACPI devices, so we can't just assign
the resources when we scan the bus.
"""

Best regards,

Thomas
-- 
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

  reply	other threads:[~2013-02-12 19:23 UTC|newest]

Thread overview: 135+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-12 16:28 [PATCH v3] PCIe support for the Armada 370 and Armada XP SoCs Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 01/32] of/pci: Provide support for parsing PCI DT ranges property Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 02/32] of/pci: Add of_pci_get_devfn() function Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 03/32] of/pci: Add of_pci_parse_bus_range() function Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 04/32] ARM: pci: Allow passing per-controller private data Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 05/32] lib: devres: don't enclose pcim_*() functions in CONFIG_HAS_IOPORT Thomas Petazzoni
2013-02-12 18:00   ` Arnd Bergmann
2013-02-12 18:58     ` Thomas Petazzoni
2013-02-12 22:36       ` Arnd Bergmann
2013-03-04 16:28         ` Thomas Petazzoni
2013-03-04 20:30           ` Arnd Bergmann
2013-02-12 16:28 ` [PATCH 06/32] arm: pci: add a align_resource hook Thomas Petazzoni
2013-02-12 18:03   ` Arnd Bergmann
2013-02-12 19:01     ` Thomas Petazzoni
2013-02-12 19:49       ` Russell King - ARM Linux
2013-02-12 16:28 ` [PATCH 07/32] arm: mvebu: fix address-cells in mpic DT node Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 08/32] clk: mvebu: create parent-child relation for PCIe clocks on Armada 370 Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 09/32] clk: mvebu: add more PCIe clocks for Armada XP Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 10/32] arm: plat-orion: introduce WIN_CTRL_ENABLE in address mapping code Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 11/32] arm: plat-orion: refactor the orion_disable_wins() function Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 12/32] plat-orion: introduce ORION_ADDR_MAP_NO_REMAP Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 13/32] arm: mach-dove: use ORION_ADDR_MAP_NO_REMAP Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 14/32] arm: mach-kirkwood: " Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 15/32] arm: mach-mvebu: " Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 16/32] arm: mach-orion5x: " Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 17/32] arm: plat-orion: convert 'int remap' to 'u32 remap' Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 18/32] arm: plat-orion: remove __init from addr-map functions needed after boot time Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 19/32] arm: plat-orion: introduce orion_{alloc,free}_cpu_win() functions Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 20/32] arm: plat-orion: remove __init from PCIe functions needed after boot time Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 21/32] arm: mvebu: add functions to alloc/free PCIe decoding windows Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 22/32] arm: plat-orion: make common PCIe code usable on mvebu Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 23/32] pci: infrastructure to add drivers in drivers/pci/host Thomas Petazzoni
2013-02-12 16:28 ` [PATCH 24/32] pci: PCIe driver for Marvell Armada 370/XP systems Thomas Petazzoni
2013-02-12 18:30   ` Arnd Bergmann
2013-02-12 19:22     ` Thomas Petazzoni [this message]
2013-02-12 19:49       ` Jason Gunthorpe
2013-02-12 22:59       ` Arnd Bergmann
2013-02-13  0:41         ` Jason Gunthorpe
2013-02-13  9:18           ` Arnd Bergmann
2013-02-13  9:31             ` Thomas Petazzoni
2013-02-13 10:23               ` Arnd Bergmann
2013-02-13  8:23         ` Thomas Petazzoni
2013-02-13  9:29           ` Arnd Bergmann
2013-02-13  9:40             ` Thomas Petazzoni
2013-02-13 10:37               ` Arnd Bergmann
2013-03-06  9:50                 ` Thomas Petazzoni
2013-03-06 10:43                   ` Arnd Bergmann
2013-02-12 22:35   ` Jason Gunthorpe
2013-02-13  8:57     ` Thomas Petazzoni
2013-02-13 18:04       ` Jason Gunthorpe
2013-02-13 19:33         ` Arnd Bergmann
2013-03-06  9:54     ` Thomas Petazzoni
2013-03-06 12:11       ` Thierry Reding
2013-03-06 18:09         ` Jason Gunthorpe
2013-03-07  8:08           ` Thierry Reding
2013-03-07 17:49             ` Jason Gunthorpe
2013-03-07 19:48               ` Thierry Reding
2013-03-07 20:02                 ` Jason Gunthorpe
2013-03-07 20:47                   ` Thierry Reding
2013-03-08  0:05                     ` Rob Herring
2013-03-08  7:14                       ` Thierry Reding
2013-03-08 16:52                         ` Jason Gunthorpe
2013-03-08 19:12                           ` Thierry Reding
2013-03-08 19:43                             ` Mitch Bradley
2013-03-08 20:02                               ` Jason Gunthorpe
2013-03-08 20:13                                 ` Thierry Reding
2013-03-10 15:09                                   ` Thomas Petazzoni
2013-03-11  8:08                                     ` Thierry Reding
2013-03-08 23:46                                 ` Mitch Bradley
2013-03-09  1:31                                   ` Jason Gunthorpe
2013-03-10  4:52                                     ` Mitch Bradley
2013-03-10  6:55                                       ` Jason Gunthorpe
2013-03-11  5:46                                         ` Mitch Bradley
2013-03-11  7:46                                           ` Thierry Reding
2013-03-11 18:04                                             ` Mitch Bradley
2013-03-11 18:23                                               ` Jason Gunthorpe
2013-03-11 19:49                                                 ` Mitch Bradley
2013-03-11 18:15                                           ` Jason Gunthorpe
2013-03-11 21:50                                             ` Mitch Bradley
2013-03-11 23:25                                               ` Jason Gunthorpe
2013-03-11 23:38                                                 ` Mitch Bradley
2013-03-12  7:08                                                   ` Thierry Reding
2013-03-12 15:57                                                     ` Jason Gunthorpe
2013-03-12 20:38                                                       ` Thierry Reding
2013-03-12 21:03                                                         ` Jason Gunthorpe
2013-03-12 21:30                                                           ` Thierry Reding
2013-03-12 22:08                                                             ` Jason Gunthorpe
2013-03-12 23:25                                                               ` Mitch Bradley
2013-03-13  8:18                                                               ` Thierry Reding
2013-03-13 17:02                                                                 ` Jason Gunthorpe
2013-03-13 19:26                                                                   ` Thierry Reding
2013-03-13 19:59                                                                     ` Jason Gunthorpe
2013-03-13 20:54                                                                       ` Thierry Reding
2013-03-13 20:58                                                                     ` Mitch Bradley
2013-03-13 21:33                                                                       ` Thierry Reding
2013-03-13 22:48                                                                         ` Mitch Bradley
2013-03-14  0:43                                                                           ` Rob Herring
2013-03-14  1:20                                                                             ` Mitch Bradley
2013-03-14  7:11                                                                           ` Thierry Reding
2013-03-14  4:56                                                                         ` Stephen Warren
2013-03-13 22:02                                                                       ` Thierry Reding
2013-03-13 22:21                                                                         ` Jason Gunthorpe
2013-03-14  9:01                                                                           ` Thierry Reding
2013-03-14 17:25                                                                             ` Jason Gunthorpe
2013-03-14 20:38                                                                               ` Thierry Reding
2013-03-14 21:05                                                                                 ` Jason Gunthorpe
2013-03-14 21:10                                                                                 ` Mitch Bradley
2013-03-14 21:09                                                                               ` Thierry Reding
2013-03-14 21:29                                                                                 ` Jason Gunthorpe
2013-03-14 21:37                                                                                   ` Thierry Reding
2013-03-13 22:22                                                                       ` Jason Gunthorpe
2013-03-09  8:58                             ` Thomas Petazzoni
2013-03-08 23:12                         ` Rob Herring
2013-03-09 11:10                           ` Thierry Reding
2013-03-10  5:04                           ` Mitch Bradley
2013-03-10 15:06                             ` Thomas Petazzoni
2013-03-10 18:33                               ` Mitch Bradley
2013-02-15  0:36   ` Bjorn Helgaas
2013-02-15  5:06     ` Thomas Petazzoni
2013-02-15 16:26       ` Bjorn Helgaas
2013-02-15 16:44         ` Jason Gunthorpe
2013-02-12 16:28 ` [PATCH 25/32] arm: mvebu: PCIe support is now available on mvebu Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 26/32] arm: mvebu: add PCIe Device Tree informations for Armada 370 Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 27/32] arm: mvebu: add PCIe Device Tree informations for Armada XP Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 28/32] arm: mvebu: PCIe Device Tree informations for OpenBlocks AX3-4 Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 29/32] arm: mvebu: PCIe Device Tree informations for Armada XP DB Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 30/32] arm: mvebu: PCIe Device Tree informations for Armada 370 Mirabox Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 31/32] arm: mvebu: PCIe Device Tree informations for Armada 370 DB Thomas Petazzoni
2013-02-12 16:29 ` [PATCH 32/32] arm: mvebu: update defconfig with PCI and USB support Thomas Petazzoni
2013-02-12 18:12 ` [PATCH v3] PCIe support for the Armada 370 and Armada XP SoCs Arnd Bergmann
2013-02-12 19:04   ` Thomas Petazzoni
2013-02-13  8:50   ` Thomas Petazzoni
2013-02-13  9:37     ` Arnd Bergmann
2013-02-13 15:27 ` Christophe Vu-Brugier
2013-02-13 15:30   ` Thomas Petazzoni

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=20130212202252.3a9ee3d0@skate \
    --to=thomas.petazzoni@free-electrons.com \
    --cc=alior@marvell.com \
    --cc=andrew@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=benavi@marvell.com \
    --cc=bhelgaas@google.com \
    --cc=gregory.clement@free-electrons.com \
    --cc=jason@lakedaemon.net \
    --cc=jgunthorpe@obsidianresearch.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=maen@marvell.com \
    --cc=nadavh@marvell.com \
    --cc=shadi@marvell.com \
    --cc=swarren@wwwdotorg.org \
    --cc=tawfik@marvell.com \
    --cc=thierry.reding@avionic-design.de \
    /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).