linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Clément Léger" <clement.leger@bootlin.com>
To: Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Pantelis Antoniou <pantelis.antoniou@konsulko.com>,
	Bjorn Helgaas <bhelgaas@google.com>
Cc: "Clément Léger" <clement.leger@bootlin.com>,
	"Allan Nielsen" <allan.nielsen@microchip.com>,
	"Horatiu Vultur" <horatiu.vultur@microchip.com>,
	"Steen Hegelund" <steen.hegelund@microchip.com>,
	"Thomas Petazzoni" <thomas.petazonni@bootlin.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Hans de Goede" <hdegoede@redhat.com>,
	"Andrew Lunn" <andrew@lunn.ch>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org
Subject: [PATCH 0/3] add dynamic PCI device of_node creation for overlay
Date: Wed, 27 Apr 2022 11:44:59 +0200	[thread overview]
Message-ID: <20220427094502.456111-1-clement.leger@bootlin.com> (raw)

This series adds foundation work to support the lan9662 PCIe card. This
card is meant to be used an ethernet switch with 2 x RJ45 ports and
2 x 2.5G SFPs. The lan966x SoCs can be used in two different ways:

 - It can run Linux by itself, on ARM64 cores included in the SoC. This
   use-case of the lan966x is currently being upstreamed, using a
   traditional Device Tree representation of the lan996x HW blocks [1]
   A number of drivers for the different IPs of the SoC have already
   been merged in upstream Linux.

 - It can be used as a PCIe endpoint, connected to a separate platform
   that acts as the PCIe root complex. In this case, all the devices
   that are embedded on this SoC are exposed through PCIe BARs and the
   ARM64 cores of the SoC are not used. Since this is a PCIe card, it
   can be plugged on any platform, of any architecture supporting PCIe.

The problem that arose is that we want to reuse all the existing OF
compatible drivers that are used when in SoC mode to instantiate the
PCI device when in PCIe endpoint mode.

A previous attempt to tackle this problem was made using fwnode [1].
However, this proved being way too invasive and it required
modifications in both subsystems and drivers to support fwnode. First
series did not lead to a consensus and multiple ideas to support this
use-case were mentioned (ACPI overlay, fwnode, device-tree overlay).
Since it only seemed that fwnode was not a totally silly idea, we
continued on this way.

However, on the series that added fwnode support to the reset subsystem,
Rob Herring mentioned the fact that OF overlay might actually be the
best way to probe PCI devices and populate platform drivers using this
overlay. He also provided a branch containing some commits that helped
to implement this idea on a x86 setup. Due to the dynamic nature of PCI
bus enumeration, some other modifications needs to be applied on the
overlay to apply it correctly. Indeed, it is necessary to modify the
target node of the fragments to apply them correctly on the PCI device
that was probed. Moreover, the 'ranges' must be set according to the
BAR addresses in order to remap devices to the correct PCI addresses.
These modifications are the located into the driver since the remapping
is something that is specific to each driver.

After modifications, this proves to be successful and a full support of
the aforementioned lan966x PCI card was added. The modifications to
support that (apply an overlay on a dynamically created PCI of_node) are
actually minimal and only touches a few places (pci/of.c). This series
contains the 3 commits that are necessary to do that:

- First commit creates the root node if not present on a x86 setup
  without a firmware provided device-tree.
- Second one dynamically creates the PCI bus/device device-tree node
  hierarchy using changeset API.
- Finally a last commit allows to apply an overlay by targeting a
  specific device-tree node.

Other problems that might be considered with this series is the fact
that CONFIG_OF is not enabled by default on x86 configuration and thus
the driver can't be used without rebuilding a complete kernel with
CONFIG_OF=y. In order to fully support this PCIe card and allow lambda
user to use this driver, it would be almost mandatory to enable
CONFIG_OF by default on such setup.

A driver using this support was added and can be seen at [3]. This
driver embeds a builtin overlay and applies it to the live tree using
of_overlay_fdt_apply_to_node(). An interrupt driver is also included and
associated to a node that is added by the overlay. The driver also
insert a specific "ranges" property based on the BAR values which allows
to remap the device-tree node to BAR addresses dynamically. This is
needed to allow applying the overlay without depending on specific
enumeration BAR addresses.

This series was tested on a x86 kernel using CONFIG_OF under a virtual
machine using PCI passthrough.

Link: [1] https://lore.kernel.org/lkml/YhQHqDJvahgriDZK@lunn.ch/t/
Link: [2] https://lore.kernel.org/lkml/20220408174841.34458529@fixe.home/T/
Link: [3] https://github.com/clementleger/linux/tree/lan966x/of_support

Clément Léger (3):
  of: always populate a root node
  PCI: of: create DT nodes for PCI devices if they do not exists
  of: overlay: add of_overlay_fdt_apply_to_node()

 drivers/of/base.c    |  16 +++-
 drivers/of/overlay.c |  21 +++--
 drivers/pci/of.c     | 184 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/of.h   |  17 +++-
 4 files changed, 224 insertions(+), 14 deletions(-)

-- 
2.34.1


             reply	other threads:[~2022-04-27 11:02 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27  9:44 Clément Léger [this message]
2022-04-27  9:45 ` [PATCH 1/3] of: always populate a root node Clément Léger
2022-05-03 13:45   ` Rob Herring
2022-05-03 15:38     ` Clément Léger
2022-05-03 17:22     ` Frank Rowand
2022-05-17  3:11     ` Frank Rowand
2022-05-17  7:37       ` Clément Léger
2022-05-17 15:03         ` Frank Rowand
2022-05-18 10:03           ` Clément Léger
2022-04-27  9:45 ` [PATCH 2/3] PCI: of: create DT nodes for PCI devices if they do not exists Clément Léger
2022-04-27 17:37   ` kernel test robot
2022-04-27 17:47   ` kernel test robot
2022-05-03 14:12   ` Rob Herring
2022-05-03 16:05     ` Clément Léger
2022-05-03 22:53   ` Bjorn Helgaas
2022-05-04 13:43     ` Clément Léger
2022-05-18 19:22       ` Lizhi Hou
2022-04-27  9:45 ` [PATCH 3/3] of: overlay: add of_overlay_fdt_apply_to_node() Clément Léger
2022-05-06 18:33 ` [PATCH 0/3] add dynamic PCI device of_node creation for overlay Frank Rowand
2022-05-09 12:16   ` Clément Léger
2022-05-09 15:56     ` Frank Rowand
2022-05-09 16:09       ` Clément Léger
2022-05-09 17:00         ` Andy Shevchenko
2022-05-09 20:11           ` Frank Rowand
2022-05-09 20:40             ` Andy Shevchenko
2022-05-10  7:22               ` Christoph Hellwig
2022-05-09 20:07         ` Frank Rowand
2022-05-10  7:20           ` Clément Léger
2022-05-09 18:36       ` Rob Herring
2022-05-09 20:35         ` Frank Rowand
2022-05-10 14:43           ` Rob Herring

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=20220427094502.456111-1-clement.leger@bootlin.com \
    --to=clement.leger@bootlin.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=allan.nielsen@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=horatiu.vultur@microchip.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=pantelis.antoniou@konsulko.com \
    --cc=robh+dt@kernel.org \
    --cc=steen.hegelund@microchip.com \
    --cc=thomas.petazonni@bootlin.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).