Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6798880rwb; Mon, 12 Dec 2022 06:36:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf4x2PDbnUG/6K7gYKNTIiuv7G1f5BbjUy4pA3NBCMfUlFnOiKqXV+20nbfP/wBBj3lUxme7 X-Received: by 2002:a17:902:7609:b0:185:441e:6ef3 with SMTP id k9-20020a170902760900b00185441e6ef3mr17130487pll.61.1670855765750; Mon, 12 Dec 2022 06:36:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670855765; cv=none; d=google.com; s=arc-20160816; b=MgO9d94AKiXcSECkqHycOrKEmyod9Dmuoe0gyZhtFmAoCD/n931ww3PGg0ToWzCPQl XmI0ZvnDFG/j4kyS3A38xTIjqkT7wV1/6ZAQgqRScqKiMyiQISqHmPKu/5i8KjotU92h xO5BxVsRo5KbRgq0xwXKrSmxLzAPsVHhtVATH3J2cc2NAsQGY29yR0pVWnFJn8Aib8+a k6iiz+Nm8GCWmNgfu7PMF6UWaJOt/sFGemANFZrPA1QTJq3tC2Gm7AYQ+5DFH6olqzG1 +hc2UZonlr6exjoA0y0copzXjRk+8T3vB/oeVMRhKD3cozD2Htr/1Ik1bYjUeCfxAeVG tcJA== 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 :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=G9iYd6kqtFhmq3Tad5O9hQBa+pcM/uERX8qMkaMKSWY=; b=Qp+d0jHAHuw4Bs64yxLIKlxq5PVMwX2veJLudwKJ1BA+uUk4aKxp4SY8clAZqhkjJ9 hg+3z2FDarGkQd04MWmnDe0lYyWr1szVJSw/mEs61yW778dPkDnDVLcynTt4HdNH6eZ/ hDL2iimh98uE8HgQ7Bf4cRTSBL6YHG9vuu/AP9lEDucCQkIgMdD8THai/009okjhHMBU Q7hhfawUiB4nmmIMdmQyQNvKfGCQnyNg4/mnpSCLOgm9nvTXW8BTPOGBGUXuB63+5SJx 0AqdFPyQ9oqhLFe6JY22cUhERHKBQMUOGBQM+OenFwXZX0KeRI2ziPZxQodSDLew7GJr MZKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OTGeF+dY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p21-20020a170902f09500b001869e6efb8asi8788714pla.59.2022.12.12.06.35.55; Mon, 12 Dec 2022 06:36:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OTGeF+dY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232445AbiLLNOt (ORCPT + 75 others); Mon, 12 Dec 2022 08:14:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232414AbiLLNO2 (ORCPT ); Mon, 12 Dec 2022 08:14:28 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A79D1032; Mon, 12 Dec 2022 05:14:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670850867; x=1702386867; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=9Mk/c1UnbOZ1TXK8FvpaAfqNr18tZtlpEe7k7RdUxSU=; b=OTGeF+dYTagj/aeud/pLnvGOm5xcqyxBGZlm/3lwNiiQb6W/r1SUh2+O nZbCubzBG6WQuRJTmY1gSi/9xo9KZKwimxUHmlVS09Ro4osffD8tDlRL5 wEou3Jt4FLVia0kPNLMQkX0TWXoua0xXQ0cboOga/NjxPtgBQP+8fQZKe lkNQLodH9SC5IIKTtoR6ggXIgl4MTf5n0RbJFaFw6iqjkhvq4XESCohJA xqUH6OkH4YhvzrrQqmAw5kYZv/jDt0ls99X7jpbvQrLBrixtNC03/NRWa wicuGOE8KMVQ/M0iCANk10qHptqqEuELPc3gFoDtAU+GqPn1SY0pCAOsv g==; X-IronPort-AV: E=McAfee;i="6500,9779,10558"; a="305490537" X-IronPort-AV: E=Sophos;i="5.96,238,1665471600"; d="scan'208";a="305490537" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2022 05:14:26 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10558"; a="680671043" X-IronPort-AV: E=Sophos;i="5.96,238,1665471600"; d="scan'208";a="680671043" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.57.252]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2022 05:14:23 -0800 Message-ID: <9c84dbf7-e80a-5281-1070-6aeb65cfe958@intel.com> Date: Mon, 12 Dec 2022 15:13:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.5.1 Subject: Re: [PATCH v3 3/3] mmc: xenon: Fix 2G limitation on AC5 SoC Content-Language: en-US To: Vadym Kochan , Hu Ziji , Ulf Hansson , Rob Herring , Krzysztof Kozlowski , linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Elad Nachman , Chris Packham References: <20221205105931.410686-1-vadym.kochan@plvision.eu> <20221205105931.410686-4-vadym.kochan@plvision.eu> <18cf4197-adce-3e47-7802-80b0d078368b@intel.com> <69dd8714-4be1-6b1b-fa07-04c790a6c6fc@intel.com> <44f642bc-8810-80d9-368a-15994de7f50d@intel.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE 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 On 12/12/22 13:34, Vadym Kochan wrote: > Hi Adrian, > > On Mon, 12 Dec 2022 10:42:36 +0200, Adrian Hunter wrote: >> On 9/12/22 15:27, Vadym Kochan wrote: >>> On Fri, 9 Dec 2022 14:13:06 +0200, Adrian Hunter wrote: >>>> On 9/12/22 14:10, Vadym Kochan wrote: >>>>> Hi Adrian, >>>>> >>>>> On Fri, 9 Dec 2022 13:53:58 +0200, Adrian Hunter wrote: >>>>>> On 9/12/22 13:39, Vadym Kochan wrote: >>>>>>> Hi Adrian, >>>>>>> >>>>>>> On Fri, 9 Dec 2022 09:23:05 +0200, Adrian Hunter wrote: >>>>>>>> On 5/12/22 12:59, Vadym Kochan wrote: >>>>>>>>> There is a limitation on AC5 SoC that mmc controller >>>>>>>>> can't have DMA access over 2G memory, so use SDMA with >>>>>>>>> a bounce buffer. Swiotlb can't help because on arm64 arch >>>>>>>>> it reserves memblock's at the end of the memory. >>>>>>>>> >>>>>>>>> Additionally set mask to 34 bit since on AC5 SoC RAM starts >>>>>>>>> at 0x2_00000000. >>>>>>>> >>>>>>>> Can you explain more about how a 34-bit DMA mask works when >>>>>>>> SDMA only supports 32-bit addresses? >>>>>>>> >>>>>>> >>>>>>> So, after I set >>>>>>> >>>>>>>>> + host->flags &= ~SDHCI_USE_64_BIT_DMA; >>>>>>> >>>>>>> then sdhc core sets mask to 32 bit, but then dma_map fails to map >>>>>>> bounce buffer because the base address is higher than 32bit - 0x2_00000000, >>>>>>> and 34bit mask fixed it. >>>>>> >>>>>> What happens if the bounce buffer gets mapped in the range >>>>>> 0x1_00000000 to 0x1_ffffffff ? >>>>>> >>>>> >>>>> From my understanding, on the AC5 SoC RAM starts at 0x2_00000000 so the bounce >>>>> buffer can be mapped in the range 0x2_00000000..0x2_ffffffff >>>> >>>> Right but I guess I meant what about 0x3_00000000..0x3_ffffffff ? >>>> Isn't that also in DMA_BIT_MASK(34) >>> >>> Yes, you are right. >> >> So it would fail in that case? Is it possible to use devicetree >> reserved memory or some such, to set aside 64k for the bounce >> buffer DMA mapping? >> > > The main restriction is that only lower 2GB can be used for DMA. > > I already did send solution based on reserved memory, I can send it again in context of this series. > Also what about the solution which Linus suggested ? > > [cut] > > Let's just create a new quirk: > > SDHCI_QUIRK_31BIT_DMA_ROOF > > Define the semantics such that this will allow DMA for buffers that are below > the 31st bit, but does not have the semantics to limit scatter-gather buffers to > be 32-bit aligned. > > [/cut] Wouldn't that need to be done after DMA mapping? In the SDMA case, the bounce buffer would need to be checked only once and if wrong then it would be PIO-only for all requests. You probably don't need need a quirk for that since the check could be done at probe time. In the ADMA case the ADMA table would have to be checked also. And then after every dma_map_sg(). Seems a bit messy? > > Thanks, > >>> >>>> >>>>> >>>>>>> >>>>>>>>> >>>>>>>>> Co-developed-by: Elad Nachman >>>>>>>>> Signed-off-by: Elad Nachman >>>>>>>>> Signed-off-by: Vadym Kochan >>>>>>>>> --- >>>>>>>>> drivers/mmc/host/sdhci-xenon.c | 38 ++++++++++++++++++++++++++++++++++ >>>>>>>>> drivers/mmc/host/sdhci-xenon.h | 3 ++- >>>>>>>>> 2 files changed, 40 insertions(+), 1 deletion(-) >>>>>>>>> >>>>>>>>> diff --git a/drivers/mmc/host/sdhci-xenon.c b/drivers/mmc/host/sdhci-xenon.c >>>>>>>>> index 08e838400b52..5f3db0425674 100644 >>>>>>>>> --- a/drivers/mmc/host/sdhci-xenon.c >>>>>>>>> +++ b/drivers/mmc/host/sdhci-xenon.c >>>>>>>>> @@ -13,7 +13,9 @@ >>>>>>>>> >>>>>>>>> #include >>>>>>>>> #include >>>>>>>>> +#include >>>>>>>>> #include >>>>>>>>> +#include >>>>>>>>> #include >>>>>>>>> #include >>>>>>>>> #include >>>>>>>>> @@ -253,6 +255,22 @@ static unsigned int xenon_get_max_clock(struct sdhci_host *host) >>>>>>>>> return pltfm_host->clock; >>>>>>>>> } >>>>>>>>> >>>>>>>>> +static int xenon_set_dma_mask(struct sdhci_host *host) >>>>>>>>> +{ >>>>>>>>> + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); >>>>>>>>> + struct xenon_priv *priv = sdhci_pltfm_priv(pltfm_host); >>>>>>>>> + struct mmc_host *mmc = host->mmc; >>>>>>>>> + struct device *dev = mmc_dev(mmc); >>>>>>>>> + >>>>>>>>> + if (priv->hw_version == XENON_AC5) { >>>>>>>>> + host->flags &= ~SDHCI_USE_64_BIT_DMA; >>>>>>>>> + >>>>>>>>> + return dma_set_mask_and_coherent(dev, DMA_BIT_MASK(34)); >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> + return sdhci_set_dma_mask(host); >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> static const struct sdhci_ops sdhci_xenon_ops = { >>>>>>>>> .voltage_switch = xenon_voltage_switch, >>>>>>>>> .set_clock = sdhci_set_clock, >>>>>>>>> @@ -261,6 +279,7 @@ static const struct sdhci_ops sdhci_xenon_ops = { >>>>>>>>> .reset = xenon_reset, >>>>>>>>> .set_uhs_signaling = xenon_set_uhs_signaling, >>>>>>>>> .get_max_clock = xenon_get_max_clock, >>>>>>>>> + .set_dma_mask = xenon_set_dma_mask, >>>>>>>>> }; >>>>>>>>> >>>>>>>>> static const struct sdhci_pltfm_data sdhci_xenon_pdata = { >>>>>>>>> @@ -486,6 +505,18 @@ static void xenon_sdhc_unprepare(struct sdhci_host *host) >>>>>>>>> xenon_disable_sdhc(host, sdhc_id); >>>>>>>>> } >>>>>>>>> >>>>>>>>> +static int xenon_ac5_probe(struct sdhci_host *host) >>>>>>>>> +{ >>>>>>>>> + struct sysinfo si; >>>>>>>>> + >>>>>>>>> + si_meminfo(&si); >>>>>>>>> + >>>>>>>>> + if ((si.totalram * si.mem_unit) > SZ_2G) >>>>>>>>> + host->quirks |= SDHCI_QUIRK_BROKEN_ADMA; >>>>>>>>> + >>>>>>>>> + return 0; >>>>>>>>> +} >>>>>>>>> + >>>>>>>>> static int xenon_probe(struct platform_device *pdev) >>>>>>>>> { >>>>>>>>> struct sdhci_pltfm_host *pltfm_host; >>>>>>>>> @@ -533,6 +564,12 @@ static int xenon_probe(struct platform_device *pdev) >>>>>>>>> } >>>>>>>>> } >>>>>>>>> >>>>>>>>> + if (priv->hw_version == XENON_AC5) { >>>>>>>>> + err = xenon_ac5_probe(host); >>>>>>>>> + if (err) >>>>>>>>> + goto err_clk_axi; >>>>>>>>> + } >>>>>>>>> + >>>>>>>>> err = mmc_of_parse(host->mmc); >>>>>>>>> if (err) >>>>>>>>> goto err_clk_axi; >>>>>>>>> @@ -682,6 +719,7 @@ static const struct of_device_id sdhci_xenon_dt_ids[] = { >>>>>>>>> { .compatible = "marvell,armada-ap807-sdhci", .data = (void *)XENON_AP807}, >>>>>>>>> { .compatible = "marvell,armada-cp110-sdhci", .data = (void *)XENON_CP110}, >>>>>>>>> { .compatible = "marvell,armada-3700-sdhci", .data = (void *)XENON_A3700}, >>>>>>>>> + { .compatible = "marvell,ac5-sdhci", .data = (void *)XENON_AC5}, >>>>>>>>> {} >>>>>>>>> }; >>>>>>>>> MODULE_DEVICE_TABLE(of, sdhci_xenon_dt_ids); >>>>>>>>> diff --git a/drivers/mmc/host/sdhci-xenon.h b/drivers/mmc/host/sdhci-xenon.h >>>>>>>>> index 3e9c6c908a79..0460d97aad26 100644 >>>>>>>>> --- a/drivers/mmc/host/sdhci-xenon.h >>>>>>>>> +++ b/drivers/mmc/host/sdhci-xenon.h >>>>>>>>> @@ -57,7 +57,8 @@ enum xenon_variant { >>>>>>>>> XENON_A3700, >>>>>>>>> XENON_AP806, >>>>>>>>> XENON_AP807, >>>>>>>>> - XENON_CP110 >>>>>>>>> + XENON_CP110, >>>>>>>>> + XENON_AC5 >>>>>>>>> }; >>>>>>>>> >>>>>>>>> struct xenon_priv { >>>>>>>> >>>>>>> >>>>>>> Regards, >>>>>> >>>> >>