Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4472288ioa; Wed, 27 Apr 2022 04:45:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaFR2TD8G1Ffu7XG0XOSuzttZyUxfvx57imKouAqsxCUF8KpNWhkNiuaeYmZbqwRSEatxQ X-Received: by 2002:a17:90a:a78f:b0:1bc:8042:9330 with SMTP id f15-20020a17090aa78f00b001bc80429330mr43343825pjq.229.1651059904200; Wed, 27 Apr 2022 04:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651059904; cv=none; d=google.com; s=arc-20160816; b=OWSw6NBIkrr/EcTzYBSfY6JzbFJMwj6tkPYyHfEbyU3aonhX1kJUZt0tsOXsc38nH8 AqFr1aXgi0AcM3oPMMGWQ7DZ7X2Wmr5qpIMa/ompWLcqfG7T83qdbBZh4OhQNvS5Ddt0 joz8V6HsPbMUouzX6lZzIIwU47ED/1cDzSXYQxZRNbCiyAUjZdjju5RdBAq13SFlLFnx jUMP9lDSpmpMaPHZicYm0b10F+GNJneELl7GNXZKQE2wC7yj6zHnBm0X4TK/yjXyVAtO 6E4/9NS9TRNntgg8SD1ejtb1EW4tQQykQgWhHraye3g6atJtQFb2Q1UFTdE2XdfAi0WZ +LRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QY22kkywdGz9ZZ9vDCj+AzFscs29dSCG+zCgFSuQoY4=; b=rYZqS6+KI3sy0GlIcY6kHJ10AUc2miMTN8LdGajQLyZCOIrLrvp980bcjM6IudzOr2 IWQuanKhdttKrox2uzm40ovAmV0gbbWmYMFkVSGnJOJ2uA3RBjnza3s8XuW3olGYalQw YhuNnnIEp3nQLbgV5r7LsC4EOH4RHhOCHbmMAlvcwnxNskRIPikdMUQ/j3UlPNXCpXzw rJo1hUg2ZsBovsNBQyXmUv46nuqlCyOnWr6Zr9lWwszGoXl9Vf6079BpX0iReSb6vW/y C8HWXqCyAcZjI6gCUxAfLldY4dzcgbqFBtZB2ljLz6pLVnIpqdPDEA7bgfzjmkzuwqmE D5Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=apqfwr3M; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t3-20020a635f03000000b00382192930cdsi1313985pgb.349.2022.04.27.04.45.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:45:04 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=apqfwr3M; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 45AC836F6EE; Wed, 27 Apr 2022 04:02:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232118AbiD0LFT (ORCPT + 99 others); Wed, 27 Apr 2022 07:05:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232541AbiD0LE6 (ORCPT ); Wed, 27 Apr 2022 07:04:58 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D079728CFD4; Wed, 27 Apr 2022 03:54:53 -0700 (PDT) Received: from relay1-d.mail.gandi.net (unknown [217.70.183.193]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 3702FC22B9; Wed, 27 Apr 2022 09:47:27 +0000 (UTC) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 46333240002; Wed, 27 Apr 2022 09:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1651052807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QY22kkywdGz9ZZ9vDCj+AzFscs29dSCG+zCgFSuQoY4=; b=apqfwr3MNvppcLIhApJyjfR8DLf0VDKvYPEk0C92Xc4dHd1/2IHZUeDZIN+BqgeVMXJBLe 68KVF6OQE4sfXdyFtdRcjCju9VnSchAPE2vaG57wMDB8Y2TuwQS7THMNdTUzmRwAs0jLak YjNtCTox/wSQMGVK5rdQN6aGsI4lOcys2zaTrjFZL/zCWgE3SGguVjAQcTpwRjXEQkqfTg kNPG7kMtaqyvcc2ugc858c+w903NRJHcsTBzfRnI2+S+DAqqQVSbjngj8a7GvA9JdNzFrB UblHKoUIpNsVXP6fz8DiqtTYu3KAWPwdxw44+I5KkC9u8NvmsUE/69ug+/isZw== From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Rob Herring , Frank Rowand , Pantelis Antoniou , Bjorn Helgaas Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni , Alexandre Belloni , Mark Brown , Andy Shevchenko , Jakub Kicinski , Hans de Goede , Andrew Lunn , 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 Message-Id: <20220427094502.456111-1-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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