Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp311167rdg; Thu, 12 Oct 2023 06:30:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKdRtMSv+HY9qY9qlGV9ntPi2bWHFu0gpMuPNO0d5yK2gqquwIOhZs08qnmr/cDxk9j7MO X-Received: by 2002:a05:6a20:3d85:b0:16b:e89b:fb11 with SMTP id s5-20020a056a203d8500b0016be89bfb11mr17107017pzi.56.1697117425626; Thu, 12 Oct 2023 06:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697117425; cv=none; d=google.com; s=arc-20160816; b=vpjt48dRN73bHVOdw1T83Y3w22dtoaSzBiKRjW86yPCfp+n1sHalYyy93APaGZCdq4 Rylnlg+8dzUamUjT+pFJtehrRCNyF9QZAHIGRG4GNoylrEUlMZ4t8aTaiA3kpQ+Vueg4 IFQ6OsVYKIRthjwyc5maYB4MNwahgdIxL/JfFbboGmEMqmxHlCPgfhBbJHr/UA77AaWF 5XDc46PlHW+audfM6HB8a7Jx4Flu7UOyWrBlciOUzMZYJdOPGuDcwV74tBTNTu2PqY3y DjQRQixxvQS4Mree8X0DobmTYsyoMLD7vTxpv0mvSQz25lSpWAriqkR/MA6EobhoWPia AZcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=4EwAhxT4YGeUjPFFndZrOLQbhs4tGDZqtUU/Z9A6IQ4=; fh=jXY1BHJeUC/xrG0irHYalycYDOoZqSU/DXMb4qu7YFY=; b=oUbq0eZGWrQtPdLlJys3a33P7d4JCpuCYS7RdGFyl2FIOaeRA0OkPQRcQMGixyhHM9 xdA0LiKRi1dP/lRMFSTyKHSGIpu/Sx5bPJNgsSf9zaKKJ/omsdGcF7UVK6Dxy1FQmGvm gWkxO8T+ZlfWLWGACzTWkcBpcti7mm9l5CJUp17CD41NTS7EJPvj//yqwDuVJpryQB63 4UJTYtocGZClCDS0O4DXKXa/BXw15Z3bUFQo4I7KH1bVKsmOmYjYH3taAKFspHC/DxVR KwscD66sDgjZlxQSkyeoBGvZCnUsHld8x9Ukj3QfuG2VGk6aetvw00jp6dEdZlFsEQ9f 9k8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=Jt+KZkIY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c23-20020a170902b69700b001c73738781dsi2113547pls.609.2023.10.12.06.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 06:30:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=Jt+KZkIY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9B5D1822D02E; Thu, 12 Oct 2023 06:30:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378843AbjJLNaU (ORCPT + 99 others); Thu, 12 Oct 2023 09:30:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378868AbjJLNaS (ORCPT ); Thu, 12 Oct 2023 09:30:18 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A5CAC9 for ; Thu, 12 Oct 2023 06:30:15 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-32d9552d765so311998f8f.2 for ; Thu, 12 Oct 2023 06:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1697117414; x=1697722214; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4EwAhxT4YGeUjPFFndZrOLQbhs4tGDZqtUU/Z9A6IQ4=; b=Jt+KZkIY8yhUNOXY74CorUnyQjb49kmt6FgiomNv9rN+tMQdFQPrFyrD4NWsV9qcji 6gmUwZ533V7xfvZzaCRLJMQE0PimiX4LuY1lje7El17E8tuUsmqOjTKX4bOBsgciFx7p w8L9lagT46UbRENdfTkWHkpQxkL26innJS//8KXBlwUbC9dK34/1GkhO+HiW5hiA0gsg PDltZMivO9gVsEBXkGJ1G8Kbz0Jc8j3xiv9IBf2LthtGFWIa7Mm/U6+4iDN/fLX+K04o a8veYGynYpP5D/4Jyx7Q+LWzuZ2MmkTj1td0PZbbyxdinmVOiemadbygATlMClwo4qt1 8xIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697117414; x=1697722214; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4EwAhxT4YGeUjPFFndZrOLQbhs4tGDZqtUU/Z9A6IQ4=; b=O/jPcth2e8TbMyUebhNwd1xYZIPu8rruWuk//JTkqNdxeFpGYYgKSMFPaC/CCCQqoq 8QgNg5EgxIRskq1fnYOIaSKJNl06pTMJRWCzQsVY+gCovCBsFT33wGkAH3fLJg+VCCkt 4RkSjetc1cFT77I4tYYP06q0Jeu/myutfrTWpCIZ/kjpsIV5hvY1hyeL+B4DBotJFhaA 3rpkatGNh3IrCZtPd+gd9+GclsvdV2an4rnDC1nPvNqGcAl0haSZmRZtt12sBCwytj4O ddQCgGKs2qA9AOJVqnurZ1ZZBZHXKVE+goftFzwcqsxJa3b90hqAG+LDA2mjAmxbp7PW SsPg== X-Gm-Message-State: AOJu0Yz9/Gr21utRPGv3aQYLJGuTsmqyBgiR4n2DgN7omKzItnCjsb1U GIIps/OK6njc8/Et/IH0Es9C7g== X-Received: by 2002:adf:f7c4:0:b0:32d:9740:5a27 with SMTP id a4-20020adff7c4000000b0032d97405a27mr295406wrq.9.1697117413894; Thu, 12 Oct 2023 06:30:13 -0700 (PDT) Received: from [192.168.1.172] ([93.5.22.158]) by smtp.gmail.com with ESMTPSA id hn32-20020a05600ca3a000b004053e9276easm21902592wmb.32.2023.10.12.06.30.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 06:30:13 -0700 (PDT) Message-ID: <2e9766db-da12-42e6-80a8-b9ef6f2de724@baylibre.com> Date: Thu, 12 Oct 2023 15:30:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] PCI: mediatek-gen3: Fix translation window Content-Language: en-US To: AngeloGioacchino Del Regno , =?UTF-8?B?Smlhbmp1biBXYW5nICjnjovlu7rlhpsp?= , "robh@kernel.org" , "kw@linux.com" , "lpieralisi@kernel.org" , "bhelgaas@google.com" , "matthias.bgg@gmail.com" Cc: "linux-kernel@vger.kernel.org" , "linux-mediatek@lists.infradead.org" , =?UTF-8?B?SmlleXkgWWFuZyAo5p2o5rSBKQ==?= , =?UTF-8?B?Q2h1YW5qaWEgTGl1ICjmn7PkvKDlmIkp?= , =?UTF-8?B?SmlhbiBZYW5nICjmnajmiKwp?= , =?UTF-8?B?UWl6aG9uZyBDaGVuZyAo56iL5ZWf5b+gKQ==?= , "linux-arm-kernel@lists.infradead.org" , "linux-pci@vger.kernel.org" , Ryder Lee References: <20231011122633.31559-1-jianjun.wang@mediatek.com> <899c7275-ccca-43bb-b1ae-a3403dd18622@baylibre.com> <088559162e5ec4e2d6d38d8a5707c6e0e12f5ac6.camel@mediatek.com> <54ed1269-8699-4531-abc6-09b602adece9@baylibre.com> <930f6df4-3267-59df-ad75-244f5b9cee84@collabora.com> From: Alexandre Mergnat In-Reply-To: <930f6df4-3267-59df-ad75-244f5b9cee84@collabora.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 12 Oct 2023 06:30:24 -0700 (PDT) On 12/10/2023 14:52, AngeloGioacchino Del Regno wrote: > Il 12/10/23 12:27, Alexandre Mergnat ha scritto: >> >> >> On 12/10/2023 08:17, Jianjun Wang (王建军) wrote: >>> On Wed, 2023-10-11 at 17:38 +0200, Alexandre Mergnat wrote: >>>> External email : Please do not click links or open attachments until >>>> you have verified the sender or the content. >>>> >>>> >>>> On 11/10/2023 14:26, Jianjun Wang wrote: >>>> > The size of translation table should be a power of 2, using fls() >>>> cannot > get the proper value when the size is not a power of 2. For >>>> example, > fls(0x3e00000) - 1 = 25, hence the PCIe translation >>>> window size >>>> will be > set to 0x2000000 instead of the expected size 0x3e00000. Fix >>>> translation > window by splitting the MMIO space to multiple tables >>>> if its size >>>> is not > a power of 2. >>>> >>>> Hi Jianjun, >>>> >>>> I've no knowledge in PCIE, so maybe what my suggestion is stupid: >>>> >>>> Is it mandatory to fit the translation table size with 0x3e00000 (in >>>> this example) ? >>>> I'm asking because you can have an issue by reaching the maximum >>>> translation table number. >>>> >>>> Is it possible to just use only one table with the power of 2 size >>>> above 0x3e00000 => 0x4000000 ( fls(0x3e00000) = 26 = 0x4000000). The >>>> downside of this method is wasting allocation space. AFAIK I already >>>> see this kind of method for memory protection/allocation in embedded >>>> systems, >>>> so I'm wondering if this method is safer than using multiple table for >>>> only one size which isn't a power of 2. >>> >>> Hi Alexandre, >>> >>> It's not mandatory to fit the translation table size with 0x3e00000, >>> and yes we can use only one table with the power of 2 size to prevent >>> this. >>> >>> For MediaTek's SoCs, the MMIO space range for each PCIe port is fixed, >>> and it will always be a power of 2, most of them will be 64MB. The >>> reason we have the size which isn't a power of 2 is that we reserve an >>> IO space for compatible purpose, some older devices may still use IO >>> space. >>> >>> Take MT8195 as an example, its MMIO size is 64MB, and the declaration >>> in the DT is like: >>> ranges = <0x81000000 0 0x20000000 0x0 0x20000000 0 0x200000>, >>>           <0x82000000 0 0x20200000 0x0 0x20200000 0 0x3e00000>; >>> >>> The MMIO space is splited to 2MB IO space and 62MB MEM space, that's >>> cause the current risk of the MEM space range, its actual available MEM >>> space is 32MB. But it still works for now because most of the devices >>> only require a very small amount of MEM space and will not reach ranges >>> higher than 32MB. >>> >>> So for the concern of reaching the maximum translation table number, I >>> think maybe we can just print the warning message instead of return >>> error code, since it still works but have some limitations(MEM space >>> not set as DT expected). >>> >> >> Ok understood, thanks for your explanation. >> Then, IMHO, you should use only one table with the power of 2 size >> above to make the code simpler, efficient, robust, more readable and >> avoid confusion about the warning. >> >> This is what is done for pci-mvebu.c AFAII. >> >> If you prefer waiting another reviewer with a better PCIE expertise >> than me, it's ok for me. With the information I have currently, I >> prefer to not approve the current implementation because, from my PoV, >> it introduce unnecessary complexity. >> > > From what I understand, using only one table with a size that is a > power of two > won't let us use the entire MMIO space, hence the only solution to allow > using > the entire range is to split to more than one table. You can take the power of 2 above, which is directly returned by fls(). That let us use the entire MMIO space. In this example, if your size is 0x3e00000, the you will allow 0x4000000. -- Regards, Alexandre