Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp918471lqt; Tue, 19 Mar 2024 07:42:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX7swClkM9BErpfe309pKF9Hf6SrJCe1yI1ntd182T4mYV/MYW0eaJR8mYxD9WIJ3VFqQVYpaUEr2MSmCJOIC3tNsNrCXT69ztvXK2zLg== X-Google-Smtp-Source: AGHT+IGiQpjDhpSFiDQlyUE/ypw5ENvdEZ6ubAVv9Wo+MsyQ2sWV50ilKGtGs7q1iWXKaIkUHRVh X-Received: by 2002:a05:6358:7523:b0:17e:cd08:8bc with SMTP id k35-20020a056358752300b0017ecd0808bcmr10899480rwg.20.1710859357925; Tue, 19 Mar 2024 07:42:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710859357; cv=pass; d=google.com; s=arc-20160816; b=GXEn55lSpMEp5vbqxJOfYPyFaQfnSITtGA03Fb4ua7MHnqAb+20Iida7HuxmocjEJe GBuKJEaj1ihSL27+Kf2PMNSPGJcJoazSYnYi5Xc8UEyMRoBjgTYRMEBOIP/PX8BhkRi+ tzujSElNxHwCmT2VRuye70aeK2GJidKj9071DKZJqVZIn8ihOuBIfcJ937VjSOL/xXnh 6sBWvvmMAaJ7lxEuNRP9c4ychd/WmPS8dzR5timrZ63odQFegk27jEhBRNtDn/P/eqBM NZE4ggUYUm4DH99Tk7924o0Jq6stc+A2kfrg61y7e7otVmKSA5U9BSKi5l25a6PAS8+6 tGQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=6pzJKG5CLK//p9ZCz9khgVEAQ5zvuh1yAWK/ALunBpk=; fh=2oHfka1RMTQTF84mb7T46ycwVNzrlTi9XMjBcTPHQ7o=; b=uiD1mPkCiWW7NIBZjEYFX4umqdxd8kb0DjG4xXnQjwaPebk8V88/9Y56ttfHx25+Zv MZH/3iHlbrkYV7oSQ8RqoMtFlclAdGeV46Io0oy0C7OXKliM5qke35gfQuEG9lRW0kC+ /t+b9NjyN02W1toeNP7GC4Ho8s6Cgdm3WSGRQdqAo1n0WQQvi1T44gqRQqf/57IzQG7V U8TxqGVGEhKHiAqxjdWuFl2XjbbW7EL8psrrPcnlI9oJPiEXdchK/Uvd9grEpfuZerz7 7bmizdBIki/eeFooEpLYSyCJrlSXpxeZ+845Khx8PFqmR1ROdw3nBpyc6OdZfSqIIfWr JIvQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dWo1Vcu7; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-107666-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107666-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id p12-20020a056a000a0c00b006e64cdf09edsi11552491pfh.378.2024.03.19.07.42.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 07:42:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107666-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=dWo1Vcu7; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-107666-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107666-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 68BB3B21E88 for ; Tue, 19 Mar 2024 14:42:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A2C653385; Tue, 19 Mar 2024 14:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="dWo1Vcu7" Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF2C0200BF; Tue, 19 Mar 2024 14:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710859313; cv=none; b=RpJLp+wxyavKxFBAAOlfJnw+ITCeSvXwzzoSLqzEkWF/b9pEARa900+Em8Fn6K2u3pFkS2/lY8Tt8k8NR4NEGG/I3OHQndEXjzgWLmRhbZp0QraUfvGnbySx6m+nvgg9HpzoQsFwngJkntbJf470OeF9JnWSqFsGzeH7y5hq490= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710859313; c=relaxed/simple; bh=H86jgSj39Vt5eZQa4Li5R+8zowtHYkyrFgx+9QNPBdg=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U4So/z6ahM1aKmsarLjk6xNSwMM22apsfNujRDzr4akcRU8QTRYJFt1DSNUs1nSlW7a5OYmP94IhQkjJ8TObvbcSodCM6zi4XpzUkUdIj3DpAYDBPlGhQfzNsH02xmPuSjn987TRi068D9GUV4Bg8Iah/2BdIzSJgQGLiomHwOk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=dWo1Vcu7; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id C43671BF207; Tue, 19 Mar 2024 14:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1710859301; 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=6pzJKG5CLK//p9ZCz9khgVEAQ5zvuh1yAWK/ALunBpk=; b=dWo1Vcu7aXPfdW4r+i1v7PMuMcPoEaDJJZ/kN2+CkLQf6f8e+pPsH+Q2UNnYZuxCK1SHoi Jv/bV9kuZmT6snZRjmg5zrYMOqEk8fWY38pHWT+DqjYD3qKCh8lAhW0yx8uV7RqT8XvVVz wce9oaumtggWtBp47/ahEDKKuU6+QUpQRyQQh13TwpIQyy0faEajFeTCZwRB0vNvbHsC1F w2eN4ZSy6BB9mrRXzA9IYNhof8chsicphGvpdAp2YQeTi0nwxG2Y2I7fA8wi+VwmZraaAB ETYSndIISoy/ePrtwbF9rNxNizZPK3GXBs3WlIE8G6b1LmCnZsuwC5ARwMUkPg== Date: Tue, 19 Mar 2024 15:41:39 +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: <20240319154139.03058bf3@bootlin.com> In-Reply-To: <20231214153122.07e99a5a@bootlin.com> References: <20231130165700.685764-1-herve.codina@bootlin.com> <20231204134335.3ded3d46@bootlin.com> <20231204163014.4da383f2@bootlin.com> <20231205090452.7c601eb5@bootlin.com> <20231208094840.01d74fec@bootlin.com> <20231214153122.07e99a5a@bootlin.com> Organization: Bootlin X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: herve.codina@bootlin.com Hi Rob, On Thu, 14 Dec 2023 15:31:22 +0100 Herve Codina wrote: > > > > > > 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. > > > > Got some piece of code creating an interrupt controller at PCI device level. > To have it working, '#interrupt-cell = <1>' and 'interrupt-controller' > properties need to be set in the PCI device DT node. > > I can set them when the PCI device DT node is created (add them in > of_pci_add_properties()) but as this interrupt controller is specific to the > PCI device driver (it needs to be created after the pci_enable_device() call > and will probably be device specific with MSI), it would make sense to have > these properties set by the PCI device driver itself or in the overlay it > applies. > > But these properties creation done by the device driver itself (or the > overlay) lead to memory leaks. > Indeed, we cannot add properties to an existing node without memory > leaks. When a property is removed, the property is not freed but moved > to the node->deadprops list (of_remove_property()). > The properties present in the list will be free once the node itself is > removed. > In our use-case, the node (PCI device node) is not removed when the driver > is removed and probe again (rmmod/insmod). > > Do you have any opinion about the '#interrupt-cell' and > 'interrupt-controller' properties creation: > > - Created by of_pci_add_properties(): > No mem leak but done outside the specific device driver itself and done for > all PCI devices. > Maybe the driver will not create the interrupt controller, maybe it will > prefer an other value for '#interrupt-cell', maybe it will handle MSI and > will need to set other properties, ... All of these are device specific. > > - Created by the device driver itself (or the overlay it applies): > The mem leak is present. Any idea about a way to fix that or at least having > a fix for some properties ? > I was thinking about avoiding to export properties (of_find_property()) and > so avoid references properties or introducing refcount on properties but > these modifications touch a lot of drivers and subsystems and are subject > to errors. > That's said, checking a property presence based on its name can be done without > exporting the property, as well as getting a single value. Iterating over array > values need some more complicated code. > I revive this quite old topic. The primary goal of this series was to avoid a struct device duplication due to the insertion of DT nodes related to PCI devices. The series added the sysfs of_node symlink once the device is visible from sysfs. You proposed to create the DT node earlier, DECLARE_PCI_FIXUP_EARLY() instead of DECLARE_PCI_FIXUP_FINAL() in order to have it set before the device_add() call. This raised some new issues because the DT node creation needs some information set by the PCI core. DECLARE_PCI_FIXUP_HEADER() was the new candidate. Issues were still present. The 'ranges' property is needed and information needed for its computation are set by the PCI core after the device_add() call. At this point the discussion continued also on interrupts with the idea to add the 'interrupt-controller' property in the PCI device node in order to bypass all the interrupt mapping done in DT nodes. Indeed, in order to have a working DT mapping, an 'interrupt-parent' phandle is needed at some points and will be problematic with ACPI. On my side I've got a piece of code to consider the PCI device as an interrup controller. This work with the 'interrupt-controller' property. The question raised: Which part of code set the interrupt-controller property ? - DT node creation: Common to all PCI devices even if the interrupt are not handled by the PCI device driver. Also '#interrupt-cells' is really device specific. - Added by the PCI device driver itself Seems the good place but we enter in overlay memleak issues What is your opinion related to the best candidate for the 'interrupt-controller' and '#interrupt-cells' property creation ? Back to the of_node link addition to sysfs. Is it really an issue to add it on an already present device ? If so, is it acceptable (not tested on my side) to create the of_node link to an empty node before the device_add() call and then fill this node later when needed information are set by the PCI core ? With your answers, I hope to move forward on these topics. Best regards, Hervé -- Hervé Codina, Bootlin Embedded Linux and Kernel engineering https://bootlin.com