Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2637925rdb; Wed, 4 Oct 2023 07:16:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcT++JWsFWNxRGLicrZzNeZHdtKZUaH4X2/X7aN7oKjx3++ZdCzMbTEH1HjecjY//kvTQD X-Received: by 2002:a05:6a20:324d:b0:14d:7511:1c2 with SMTP id hm13-20020a056a20324d00b0014d751101c2mr2091107pzc.55.1696428977504; Wed, 04 Oct 2023 07:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696428977; cv=none; d=google.com; s=arc-20160816; b=UU1q7q/V6/mRa9uIkS37dRWRq7uBfsqr1pXAsvlw4EYqvDdjCzro8/ZLwEiib6xCN2 /aV9y/WYnrNpoLYGocsF/P4M4j3lGq179sOsb0DKguhvuqhZBIP5euJWZSiivgGRimB3 JEx+6e91hEbxMJQUszrxmreToRJ88ErVoNOHiFkOBqq03SE42rl3Ohl77j7iD/j0dJgd n8NyzRm4vRNyKP+9jYzEUlR4SL6AFHNXfIUnGzUfXGYp82hPU2W+DFEs3ZH9HCK5SWdv FMlRDr4NKbwuTdMswkBmA5SgBuRimmX+pO/gNAr021pl1Zfn7PCPGgATLkPCAYMf2bvS gBFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wyLd9QM57jfBoCpRc+iAiWmkfmow9ld4/Z8yIIhOqS8=; fh=DKu7SzTWoXnkxbvZvkALvIXsoagB0ZyDgsBMxJGs/PM=; b=BZ0t4kLrerhFNyoyiHYbC0womC4w1DPGHHXZjFDS5jjRvCTTuMOA1NwjhRs62xMyD4 vgMP8DoyrHlqMIIX7DaQHJONwCLtzGXHhStBCk9ANFiWjFmOgxTraACkdLeZLRwIuib+ mcAz4tVZEXHdDOTdqdN9K1NLvTzhpXODtSiMNJ8D47UvLgkJ+GmA100cPZhpMjq9lJzI PKU+CmGoKQZIOdpyvweweZvZv+/POXjhsgEjpldGLC7GSHFNtUVgmkhNxCBgfRnA9Hbk e6SybGquUWVtSCjaV6QETR407a7mIvObjThN9vM4rWE5xyM80eOHnKx0kLHpAbIwp5Qa XRSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uZz1Ace7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c6-20020a633506000000b00577f6b56757si3997735pga.495.2023.10.04.07.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 07:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uZz1Ace7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id E3EF881ADD4D; Wed, 4 Oct 2023 07:16:13 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242866AbjJDOQA (ORCPT + 99 others); Wed, 4 Oct 2023 10:16:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242770AbjJDOP6 (ORCPT ); Wed, 4 Oct 2023 10:15:58 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65E81BF for ; Wed, 4 Oct 2023 07:15:52 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21FC7C433C7; Wed, 4 Oct 2023 14:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696428952; bh=YMXqF2086IHwMBRj5Tp+vck/KJO+L/Ns77eunTZpu38=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uZz1Ace7zromvNOtNZ4hnSiqZPOUIaULVa4vxoBbHhvOuGOMTIOuIzV/RPeRnVWSz ciCvK8IxHezXNuDNVQfeTMV9cjOCh57h59zDgjLyBfpXnCttUtH0Qpzp04DbhIG5c2 Tl2EQHyN9vyR4pWZEwlSL1LIPToxRkouQnigK3O6R1OUgRfR8bULuWJcZFenCNIKQu RaKjttfSLv1YS7L8yaDpVgYSE5HmDgAE6h6SPbdIaPKCJcbLKCYaqBgXCA/rT1zqZH QLrhs5eIEqqUf0A9OXNHbSfl62diFVdPccWV5hLZQlKyKvtE7I9oOdFxapi8AoZna0 bL4v/mRfteS1g== Received: (nullmailer pid 2947266 invoked by uid 1000); Wed, 04 Oct 2023 14:15:49 -0000 Date: Wed, 4 Oct 2023 09:15:49 -0500 From: Rob Herring To: Herve Codina Cc: Lizhi Hou , Frank Rowand , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni Subject: Re: [PATCH 1/1] of: address: Fix address translation when address-size is greater than 2 Message-ID: <20231004141549.GA2793277-robh@kernel.org> References: <20231003065236.121987-1-herve.codina@bootlin.com> <20231004110701.0c9aa467@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231004110701.0c9aa467@bootlin.com> 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,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 04 Oct 2023 07:16:14 -0700 (PDT) On Wed, Oct 04, 2023 at 11:07:01AM +0200, Herve Codina wrote: > On Tue, 3 Oct 2023 16:12:25 -0500 > Rob Herring wrote: > > > On Tue, Oct 3, 2023 at 1:53 AM Herve Codina wrote: > > > > > > With the recent addition of of_pci_prop_ranges() in commit 407d1a51921e > > > ("PCI: Create device tree node for bridge"), the ranges property can > > > have a 3 cells child address, a 3 cells parent address and a 2 cells > > > child size. > > > > Sigh. I'm starting to regret applying this for 6.6... You failed to Cc > > the AMD folks too. Lizhi now added. > > > > What's different here from the test cases? The having 3 cells in > > parent and child? > > Are you talking about of_unittest_pci_node()? That and there's a non-PCI one. > I so, only BAR0 is used and the DT overlay is > fragment@0 { > target-path=""; > __overlay__ { > #address-cells = <3>; > #size-cells = <2>; > pci-ep-bus@0 { > compatible = "simple-bus"; > #address-cells = <1>; > #size-cells = <1>; > ranges = <0x0 0x0 0x0 0x0 0x1000>; > reg = <0 0 0 0 0>; > unittest-pci@100 { > compatible = "unittest-pci"; > reg = <0x100 0x200>; > }; > }; > }; > }; > > > > > > > > > A range item property for a PCI device is filled as follow: > > > 0 0 > > > <-- Child --> <-- Parent (PCI definition) --> <- BAR size (64bit) --> > > > > > > This allow to translate BAR addresses from the DT. For instance: > > > pci@0,0 { > > > #address-cells = <0x03>; > > > #size-cells = <0x02>; > > > device_type = "pci"; > > > compatible = "pci11ab,100\0pciclass,060400\0pciclass,0604"; > > > ranges = <0x82000000 0x00 0xe8000000 > > > 0x82000000 0x00 0xe8000000 > > > 0x00 0x4400000>; > > > ... > > > dev@0,0 { > > > #address-cells = <0x03>; > > > #size-cells = <0x02>; > > > compatible = "pci1055,9660\0pciclass,020000\0pciclass,0200"; > > > /* Translations for BAR0 to BAR5 */ > > > ranges = <0x00 0x00 0x00 0x82010000 0x00 0xe8000000 0x00 0x2000000 > > > 0x01 0x00 0x00 0x82010000 0x00 0xea000000 0x00 0x1000000 > > > 0x02 0x00 0x00 0x82010000 0x00 0xeb000000 0x00 0x800000 > > > 0x03 0x00 0x00 0x82010000 0x00 0xeb800000 0x00 0x800000 > > > 0x04 0x00 0x00 0x82010000 0x00 0xec000000 0x00 0x20000 > > > 0x05 0x00 0x00 0x82010000 0x00 0xec020000 0x00 0x2000>; > > > ... > > > pci-ep-bus@0 { > > > #address-cells = <0x01>; > > > #size-cells = <0x01>; > > > compatible = "simple-bus"; > > > /* Translate 0xe2000000 to BAR0 and 0xe0000000 to BAR1 */ > > > ranges = <0xe2000000 0x00 0x00 0x00 0x20000000 > > > 0xe0000000 0x01 0x00 0x00 0x1000000>; > > > > Why are you reusing a PCI bus address value for the child bus? I'm > > wondering if this is some hackery because the child devices need PCI > > addresses to work. What address does a device need for DMA for > > example? > > I don't think I re-use a PCI bus address. Okay, I guess they happen to be similar. It depends on the host bridge, but often the PCI addresses are arbitrary. Often platforms just reuse the CPU address, but really they are independent. > In my device datasheet, 0xe2000000 to 0xe3ffffff are mapped to BAR0 and > 0xe0000000 to 0xe0FFFFFF are mapped to BAR1. > And so, all devices use this kind of addresses in their 'reg' property. Okay, your size is off. For 0xe2000000, you have 0x2000_0000 rather than 0x0200_0000. (It would be good if this mistake triggered a warning) > > > > > Also, I think each BAR should be a separate child. We need to > > formalize this BAR addressing in a schema. > > I am not sure that we should describe the hardware with a tree based on > BAR. On my system, some devices use two BARs. > For instance, I have a 'microchip,lan966x-switch' > https://elixir.bootlin.com/linux/v6.5/source/Documentation/devicetree/bindings/net/microchip,lan966x-switch.yaml > > This devices use two values (two reg set) for its reg property. > On my system, this device is accessed through the PCI bus and one reg set > should be accessed using BAR0 and the other set using BAR1. Okay, if the h/w is like that, then I agree. > > Having a tree based on BARs will break this kind of devices. > > > > > > ... > > > }; > > > }; > > > }; > > > > > > During the translation process, the "default-flags" map() function is > > > used to select the matching item in the ranges table and determine the > > > address offset from this matching item. > > > This map() function simply calls of_read_number() and when address-size > > > is greater than 2, the map() function skips the extra high address part > > > (ie part over 64bit). This lead to a wrong matching item and a wrong > > > offset computation. > > > Also during the translation itself, the extra high part related to the > > > parent address is not present in the translated address. > > > > > > Fix the "default-flags" map() and translate() in order to take into > > > account the child extra high address part in map() and the parent extra > > > high address part in translate() and so having a correct address > > > translation for ranges patterns such as the one given in the example > > > above. > > > > Please add a test case for this. > > Should I add it in the of_unittest_pci_node() or create a new unittest > dedicated to this translation test? Extending the existing tests is fine. If you can make the non-PCI one fail, that would be better as it doesn't depend on the QEMU PCI test device. Rob