Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2200905rdb; Fri, 8 Dec 2023 00:49:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuImQgXi0/xwo/eInYm1hhTt+ndZeIVWb337QnrID2Qrx1+yAmOSwaMtb6vbe9GtmEhtoM X-Received: by 2002:a17:90b:3ec4:b0:286:bc9c:327c with SMTP id rm4-20020a17090b3ec400b00286bc9c327cmr3118559pjb.22.1702025361976; Fri, 08 Dec 2023 00:49:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702025361; cv=none; d=google.com; s=arc-20160816; b=pR6NmiJ42cUENEB3ee95j+Veft19+G1S4LCcr992j+3kBhGpAKpyH4WcMSwxMzrbFi LNTZ7sy6U3ZefGUXTapUJGOiP/S0iqgyHle1xYMUsCXEFbH2X5RDceQomtq7O0Kezz83 fR+C1Gzrh5TtLSe8na32U7VxLmnOEhTamQkMczLMabznWBtP9725hw+PjYbsNOXIJnEs R1gC6JOVeSL39VKieC0XSPwILdn83Eu6PbM0tWXst0OoXxpHc0Urmy0lN/qc1/S7TYye RI+0Lz1/Yh8kioC4uvTky5LALgdWW7Hhb0EnFPa5Ad6BwPJf0XnSg9fmbvvX26q2Pfex NQpA== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=BI/a9kd3lyurB+jcttNXOa/XaS8zgyXI4PkPmj1fYQc=; fh=2oHfka1RMTQTF84mb7T46ycwVNzrlTi9XMjBcTPHQ7o=; b=fd5p5Az2+rJp/byVEG/GGgi7g64un9WA1GYL4fm8D/7/XKdbAaJ8W/Q5UAZgfrnEyo 8k5dR7VUU923smVcsdciEHp80Rg7fB7+GyVqMYC+2m203kngnPeAq2c6VrrX7ckBVlq5 Bzco2jYfOHlbKyGryyBH9ovKrgA63VoOhQOlju3pnQrtDvRypZY50Sy2li+zuYFdPXE9 hytnLJUfdHvVX0A3vYIqv6SU8saRMZ8LntzW6CZHem72ET8KlgZcnKk6w7W5U+YPFtYW E1WgncrH9fCmP7m4GVVCi2msSJWbc1J6Q5kxGSYsz9bB+OiZlNRpG8KsJ/8KKi8RM53e lIVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OtKH0ven; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id nn8-20020a17090b38c800b00274df6d4c38si1294527pjb.89.2023.12.08.00.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 00:49:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=OtKH0ven; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BAD4C823D9F7; Fri, 8 Dec 2023 00:49:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573372AbjLHIs5 (ORCPT + 99 others); Fri, 8 Dec 2023 03:48:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235815AbjLHIsp (ORCPT ); Fri, 8 Dec 2023 03:48:45 -0500 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DAF9172C; Fri, 8 Dec 2023 00:48:45 -0800 (PST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 4C12FC0002; Fri, 8 Dec 2023 08:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1702025322; 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: in-reply-to:in-reply-to:references:references; bh=BI/a9kd3lyurB+jcttNXOa/XaS8zgyXI4PkPmj1fYQc=; b=OtKH0venALl7A2QhgJRFyZltpGLlG6YDjqcRcLP4+ioDu0kWHpTJr7n3+Wa5f/AVb52L7v sQ7xGzfKdbCtD08vVBb51WHnzOL3YHE5LkOkDckyEQ0+BAvqF3DTjaKc1lBvl+zfLKH/DQ OcfO7uJKt7/KrgNwd3r0ixqzVUurngPx1s2jzs6NkdLdw1oBqerOmYZXzmL+xaZgp5fCbN bWmUIPLxW8MTcTgGkR20ktTBrCtFZmKap1/tA4jJ55F+BiAB686jtCitOt3Gflw8Lt9u++ UNBmL9m61OycftBOiWT2nG9x+ph228aFBSQ58iwT084dfGCt8Iihheplhhdsxw== Date: Fri, 8 Dec 2023 09:48:40 +0100 From: Herve Codina To: Rob Herring Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Bjorn Helgaas , Lizhi Hou , Max Zhen , Sonal Santan , Stefano Stabellini , Jonathan Cameron , "linux-kernel@vger.kernel.org" , PCI , Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni Subject: Re: [PATCH v2 0/2] Attach DT nodes to existing PCI devices Message-ID: <20231208094840.01d74fec@bootlin.com> In-Reply-To: References: <20231130165700.685764-1-herve.codina@bootlin.com> <20231204134335.3ded3d46@bootlin.com> <20231204163014.4da383f2@bootlin.com> <20231205090452.7c601eb5@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 00:49:16 -0800 (PST) Hi Rob, On Thu, 7 Dec 2023 16:51:56 -0600 Rob Herring wrote: > On Tue, Dec 5, 2023 at 2:05 AM Herve Codina wrote: > > > > On Mon, 4 Dec 2023 17:03:21 -0600 > > Rob Herring wrote: > > > > > On Mon, Dec 4, 2023 at 9:30 AM Herve Codina wrote: > > > > > > > > Hi Rob, > > > > > > > > On Mon, 4 Dec 2023 07:59:09 -0600 > > > > Rob Herring wrote: > > > > > > > > [...] > > > > > > > > > > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > > > > > > > index 9c2137dae429..46b252bbe500 100644 > > > > > > > --- a/drivers/pci/bus.c > > > > > > > +++ b/drivers/pci/bus.c > > > > > > > @@ -342,8 +342,6 @@ void pci_bus_add_device(struct pci_dev *dev) > > > > > > > */ > > > > > > > pcibios_bus_add_device(dev); > > > > > > > pci_fixup_device(pci_fixup_final, dev); > > > > > > > - if (pci_is_bridge(dev)) > > > > > > > - of_pci_make_dev_node(dev); > > > > > > > pci_create_sysfs_dev_files(dev); > > > > > > > pci_proc_attach_device(dev); > > > > > > > pci_bridge_d3_update(dev); > > > > > > > diff --git a/drivers/pci/of.c b/drivers/pci/of.c > > > > > > > index 51e3dd0ea5ab..e15eaf0127fc 100644 > > > > > > > --- a/drivers/pci/of.c > > > > > > > +++ b/drivers/pci/of.c > > > > > > > @@ -31,6 +31,8 @@ int pci_set_of_node(struct pci_dev *dev) > > > > > > > return 0; > > > > > > > > > > > > > > node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); > > > > > > > + if (!node && pci_is_bridge(dev)) > > > > > > > + of_pci_make_dev_node(dev); > > > > > > > if (!node) > > > > > > > return 0; > > > > > > > > > > > > Maybe it is too early. > > > > > > of_pci_make_dev_node() creates a node and fills some properties based on > > > > > > some already set values available in the PCI device such as its struct resource > > > > > > values. > > > > > > We need to have some values set by the PCI infra in order to create our DT node > > > > > > with correct values. > > > > > > > > > > Indeed, that's probably the issue I'm having. In that case, > > > > > DECLARE_PCI_FIXUP_HEADER should work. That's later, but still before > > > > > device_add(). > > > > > > > > > > I think modifying sysfs after device_add() is going to race with > > > > > userspace. Userspace is notified of a new device, and then the of_node > > > > > link may or may not be there when it reads sysfs. Also, not sure if > > > > > we'll need DT modaliases with PCI devices, but they won't work if the > > > > > DT node is not set before device_add(). > > > > > > > > Ok, we can try using DECLARE_PCI_FIXUP_HEADER. > > > > On your side, is moving from DECLARE_PCI_FIXUP_EARLY to DECLARE_PCI_FIXUP_HEADER > > > > fix your QEMU unittest ? > > > > > > No... > > I think the problem is we aren't setting the fwnode, just the of_node > ptr, but I haven't had a chance to verify that. > > > > And testing the bridge part crashes. That's because there's a > > > dependency on the bridge->subordinate to write out bus-range and > > > interrupt-map. I think the fix there is we should just not write those > > > properties. The bus range isn't needed because the kernel does its own > > > assignments. For interrupt-map, it is only needed if "interrupts" is > > > present in the child devices. If not present, then the standard PCI > > > swizzling is used. Alternatively, I think the interrupt mapping could > > > be simplified to just implement the standard swizzling at each level > > > which isn't dependent on any of the devices on the bus. I gave that a > > > go where each interrupt-map just points to the parent bridge, but ran > > > into an issue that the bridge nodes don't have a phandle. That should > > > be fixable, but I'd rather go with the first option. I suppose that > > > depends on how the interrupts downstream of the PCI device need to get > > > resolved. It could be that the PCI device serves as the interrupt > > > controller and can resolve the parent interrupt on its own (which may > > > be needed for ACPI host anyways). > > > > About interrupt, I am a bit stuck on my side. > > My dtso (applied at PCI device level) contains the following: > > fragment@0 { > > target-path=""; > > __overlay__ { > > pci-ep-bus@0 { > > compatible = "simple-bus"; > > #address-cells = <1>; > > #size-cells = <1>; > > > > /* > > * map @0xe2000000 (32MB) to BAR0 (CPU) > > * map @0xe0000000 (16MB) to BAR1 (AMBA) > > */ > > ranges = <0xe2000000 0x00 0x00 0x00 0x2000000 > > 0xe0000000 0x01 0x00 0x00 0x1000000>; > > > > itc: itc { > > compatible = "microchip,lan966x-itc"; > > #interrupt-cells = <1>; > > interrupt-controller; > > reg = <0xe00c0120 0x190>; > > }; > > > > ... > > }; > > }; > > }; > > > > I have a 'simple-bus' with a 'ranges' property to translate the BAR addresses > > then several devices. Among them a interrupt controller (itc). Its parent > > interrupt is the one used by the PCI device (INTA). > > I cannot describe this parent interrupt in the dtso because to that I need the > > parent interrupt phandle which will be know only at runtime. > > But you don't. The logic to find the interrupt parent is walk up the > parent nodes until you find 'interrupt-parent' or > '#interrupt-controller' (and interrupt-map always has > #interrupt-controller). So your overlay just needs 'interrupts = <1>' > for INTA and it should all just work. Yes, I tried some stuffs in that way... > > That of course implies that we need interrupt properties in all the > bridges which I was hoping to avoid. In the ACPI case, for DT > interrupt parsing to work, we're going to need to end up in an > 'interrupt-controller' node somewhere. I think the options are either ... and I went up to that point. Further more with that way, we need to update the addr value retrieved from the device requesting the interrupt. https://elixir.bootlin.com/linux/latest/source/drivers/of/irq.c#L343 Indeed, with the current 'interrupt-map' at bridges level, a addr value update is needed at the PCI device level if the interrupt is requested from some PCI device children. This is were my (not so good) interrupt-ranges property could play a role. > we walk interrupt-map properties up to the host bridge which then > points to something or the PCI device is the interrupt controller. I > think the PCI device is the right place. How the downstream interrupts Agree, the PCI device seems to be the best candidate. > are routed to PCI interrupts are defined by the device. That would > work the same way for both DT and ACPI. If you are concerned about > implementing in each driver needing this, some library functions can > mitigate that. > > I'm trying to play around with the IRQ domains and get this to work, > but not having any luck yet. May I help you on some points? Got a system with a real hardware (Lan966x) and a setup using an ARM platform (full DT) and an other one using an x86 platform (ACPI). Also, I have some piece of code to create the PCI host bridge node. Of course, this need to be first working on a full DT system but I can do some test to be sure that can be still ok on a ACPI system. > > > Of course, I can modified the overlay applied to tweak the 'interrupt' and > > 'interrupt-parent' in the itc node from my PCI device driver at runtime but I > > would like to avoid this kind of tweak in the PCI device driver. > > This kind of tweak is overlay dependent and needs to be done by each PCI > > device driver that need to work with interrupts. > > > > For BAR addresses translation, we use the 'ranges' property at the PCI device > > node to translate 0 0 0 to BAR0, 1 0 0 to BAR1, ... > > What do you think about a new 'irq-ranges' property to translate the irq number > > and get the irq parent controller base. > > > > irq-ranges = ; > > Seems fragile as you have to know something about the parent (the # of > cells), but you don't have the phandle. If you needed multiple > entries, you couldn't parse this. > Right. With the PCI device seen as an interrupt controller, there is no more need of this interrup-ranges property. Best regards, Hervé