Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp3037372rdb; Mon, 4 Dec 2023 15:04:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFgCP8Js3HeJ4BYfji6Eyvd83IjIkfjzOqa8edEe693wgWYEnr+GrnqWlDopcnNHqvhL52 X-Received: by 2002:a05:6a21:32a1:b0:18b:4fa:a877 with SMTP id yt33-20020a056a2132a100b0018b04faa877mr2079114pzb.14.1701731043692; Mon, 04 Dec 2023 15:04:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701731043; cv=none; d=google.com; s=arc-20160816; b=hZxnoH4s3tTKdk+hhLrYat15lkPbX/6StNJEgrky5mMR/1cdoiNdTWkpR1adc6mGug NWT7ZqnRg0M4FcvJNjzh9ItzOQ0vQKZN9ivveXo6lJZTBhRCMhNW2vTPNbP9Ae+cE45p EHFAKxoxOVwyJ2z4D2MadULaEU0Vz+hPlrvdl1Be+3Rru3Or9vYQClQ9+SHznx+Fkzk6 i2XPWROgrOz/Bm//BtrN7CQoIO5Pn63jy5ABKd21iqpYDuR/3nJQUmP1vKWM1WFyZf85 8+JQItRprzJmk6zQpmU47JfR2TQe0iBDyJgdl+fhuOMkdYyZB7QHVQl8Dc3QmBdEI+Qe dSFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=asCzNr+gHJzcbteFbEhDeRyF01BpNNLpeHqCW3qY27s=; fh=dKD0V+qARsvbtedAJivV5fCwUL1NkvPJzUfFW07lA2k=; b=ursHrWjlmit0EoGmKd1+Xy7C8yJTi9ZdCsLjPXvLQ57rQmxwKOIDAYbfqATsesJqX/ MCmbfkzK/e+9VxTNd48AgAZTN7SSabBkd5bogqB8aPIVjM8LEtJuvFqsRjWMOsQbtqpS 3oOxzBMO66xL385AE3XGjwggnocpT12n9BdJ1Rkw27itv0gZWqKDrNADsupupTywv6Rd ZE4cYONmZZBqUIEUythXqVapFcZcLOrzOp8GcLbNOF77lVM54z6iOIedv9dqiD2ou7aq rSzWiNlvNNuboBsrPcrsOgBoLMaKxjIRfdR3LSi6ughHSGkUx2AqBQtm+11atHmEU5xd N+pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jjZ23m4b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id j34-20020a63fc22000000b005c179c00758si8599680pgi.891.2023.12.04.15.04.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 15:04:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jjZ23m4b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id EB2608042D01; Mon, 4 Dec 2023 15:04:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234908AbjLDXDq (ORCPT + 99 others); Mon, 4 Dec 2023 18:03:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234814AbjLDXDl (ORCPT ); Mon, 4 Dec 2023 18:03:41 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65611111 for ; Mon, 4 Dec 2023 15:03:36 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC6F9C433CA; Mon, 4 Dec 2023 23:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701731016; bh=tXDxkojyxkL25p9KkCy1ONmXm0F3Hq4hBfCV6xY7ulc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=jjZ23m4bGHUCkel/wk+iwxFLkCbsg8aQehe6yjfAVRzAhDwtCB86d/QAZ8CPye/+g PDmNtQYWag+HBhLxEu/lbbd2cm6Wpw9Nl1soPFiWQ82X8sx1JwtMyZezdQX5YuWZ7t ZKVzLrMHnyY44Vcd5muBROIzT8erf1cIkW2ktCmvSFsWfR+XlhCNia2ZK0mkSaqrTU 1/kuuXz7gu6jTuF75u5gyGdWp5gWBzFZL+XJDpKle/YEJo0JGmxxJb9s68un8REvFN 2sBCincUk89Z4HW6/Ujq77JCdtru4OQfnyXP71excZQpAq9Vqd0l4gVR993+XywZan YqHF0Xn+xkjIw== Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2ca0715f0faso18105371fa.0; Mon, 04 Dec 2023 15:03:35 -0800 (PST) X-Gm-Message-State: AOJu0Ywhie+kfAhRb7bnEj+ZXc7d8Dr6NhITXkKio3niJxOlJMghOULK d1fj8cElb7nBLIKA49xv9/bG35+b5UfcqOfMXA== X-Received: by 2002:a05:6512:40c:b0:50c:180:2163 with SMTP id u12-20020a056512040c00b0050c01802163mr222632lfk.26.1701731014049; Mon, 04 Dec 2023 15:03:34 -0800 (PST) MIME-Version: 1.0 References: <20231130165700.685764-1-herve.codina@bootlin.com> <20231204134335.3ded3d46@bootlin.com> <20231204163014.4da383f2@bootlin.com> In-Reply-To: <20231204163014.4da383f2@bootlin.com> From: Rob Herring Date: Mon, 4 Dec 2023 17:03:21 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 0/2] Attach DT nodes to existing PCI devices To: Herve Codina 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 04 Dec 2023 15:04:01 -0800 (PST) On Mon, Dec 4, 2023 at 9:30=E2=80=AFAM 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 =3D of_pci_find_child_device(dev->bus->dev.of_node, de= v->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 struc= t resource > > > values. > > > We need to have some values set by the PCI infra in order to create o= ur 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... 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). > We have to note that between the pci_fixup_device(pci_fixup_header, dev) = call > and the device_add() call, the call to pci_set_msi_domain() is present. > MSIs are not supported currently but in the future ... MSI's aren't ever described in PCI nodes. Only the host bridge. So I don't think we should have problems there. > Related to DT modaliases, I don't think they are needed. > All drivers related to PCI device should be declared as pci_driver. > Correct me if I am wrong but I think that the core PCI will load the corr= ect > module without any DT modalias. Yes, you are probably right. Rob