Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp609766pxb; Tue, 15 Feb 2022 23:41:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDgw35kQV3n51/2OP6NA+2fXz6KQMsLM7imhMm0PRh4BpbnKFbq2VYbIC8pP2+DT4R+NLn X-Received: by 2002:a17:902:b597:b0:14f:3396:a7a5 with SMTP id a23-20020a170902b59700b0014f3396a7a5mr1381226pls.29.1644997293786; Tue, 15 Feb 2022 23:41:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644997293; cv=none; d=google.com; s=arc-20160816; b=OBOyvDLPehto3zrGn/7DE1ICq/IE8Cs6vNeGooSZZcgwH16Syf860ZQIRl6kUiBxcH qti1r4eUUNT6VRj2rphKtpVcU5rUWM2SRg4nliRthtpOcIv9nYMu70J832EOI/jAO7ec 5K2O7PDeG+KKbf9SoYHt1hoCHny7ykQ+5il6A6LZNpmMg+1ClrmW0TDcMUpFT8RfcJ24 Otor3KwTgpGsEkjdmx8NcoJ1isSeTVPrAIaGPhyyIWozC6fF/qyAtxqeuoYp3ITOxJ5x nTpg3B8VuHlfXg/RyTlajC77X6mENCBay0Lm15SpQ7B+IHnG4lgACs7jC8z7uqVmzwfc jAcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gjCi/HaXP+bc/Zw8WReu9bjIQ1k5GoBWpagMKd2Rfl0=; b=VyMl5NJcyAAQrpmZ1QrzVg/dzLtwz6uE4ZibnaCY78qAFR9eD2n8SJgmla9DIZD/br 4DsblYkdwmksIH1S5tLVA1zIr8hj9eJdq5HpxJxujBNpEJ13od0SGm0+eRqSPZtR5cgq ZnvM0gAs1s00DvByZ5kdT6P/KnOqJWnfmNWKV1wple5temoiDqL9SAIXZoWOcuNg4mp7 PWINTuBXa6kZOc6wMg3oRI6I+D11bjuUqSMs2yStyBx/xNqJEHjpirNTTHEuHwch/10B oJmEbWm5kFA+Bcxs3+FmTtlMJwp4eWZgNNIueM30ItQlMwPUiGAprkF2AneSDJ5WmX8C fRbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=IgeglsV3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x8si16997959pjq.137.2022.02.15.23.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 23:41:33 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=IgeglsV3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F44CC7E48; Tue, 15 Feb 2022 23:06:05 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229481AbiBPG6r (ORCPT + 99 others); Wed, 16 Feb 2022 01:58:47 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:39848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiBPG6l (ORCPT ); Wed, 16 Feb 2022 01:58:41 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B6A01DBFBB for ; Tue, 15 Feb 2022 22:57:42 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id g39so1991139lfv.10 for ; Tue, 15 Feb 2022 22:57:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gjCi/HaXP+bc/Zw8WReu9bjIQ1k5GoBWpagMKd2Rfl0=; b=IgeglsV3Ccf40cqfZi33wnyMePOTDBS1Gj63ZrI9pUvFILQtGV9unvSUw8faEfUy7K kKoVrK5Wxjt/WSSaJhjW/Xmo1AKosOR6Mcy0NWvmAT/Hh3D2Mw8FiDGRRv2Hbmt3gZiU ESS5BZClYqWMuKOWKgJa6lrxHAeFFMfhFxla5BFuviqkVZJwZVFXZRg/U69ZwP84G6we CUBGkFGlnnuLpDwVoMrSlArTHFSrAqrXvmy9yaUpWtSEffK54ZAe5/5m5XsXwMfXwty6 VIiAWTULGPYZmucLXgL8vYknVqPDEaHIT4bXnb6n5pwGkOEob4R6CV0OHLkXQcFv6QPC lDmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gjCi/HaXP+bc/Zw8WReu9bjIQ1k5GoBWpagMKd2Rfl0=; b=s/n7WrWOHEsRJFonI2Au4KV0uhAWx8cySBlA18Vd4008OQwzRhpGVXN9uYaOD9qABa b2cAMC/zVT67BIMoHAP8toXxKDXu6RyuiMaSkxueAjqrzLKerJLmCb8dWRj6KOkIpkbU 2NPWZnNdSjOJv/EIMicnvnHV0W8XypjkSrtUA9cQEeTd1/FvWAvFcM6LyGu/d08Owsng CY2bX7YC9UxX6DIXGaKOzuHCBjzYIMSBgQm9JVUxLWRZ/dlv3QMqGoYv8gADbmOK3qTc Bo9utqDrcNX/HBRHOQgpH+9KEWHENBRqPmbuoUesnGxZEUNeuwTbrg45rwY67gKBFZfB ejmA== X-Gm-Message-State: AOAM532WHRoasgo+itUOO7jgJXOz3X6jEX+mIEmYRg9FPuNHKmdWVC67 GsKGXlQGd9vN4uCRgMEwZivjhfezJvzXHzN0znv89w== X-Received: by 2002:ac2:4e4a:0:b0:430:5dc2:3877 with SMTP id f10-20020ac24e4a000000b004305dc23877mr1062162lfr.116.1644994346088; Tue, 15 Feb 2022 22:52:26 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Zong Li Date: Wed, 16 Feb 2022 14:52:14 +0800 Message-ID: Subject: Re: [PATCH v5 3/3] dmaengine: sf-pdma: Get number of channel by device tree To: Vinod Koul Cc: Rob Herring , Paul Walmsley , Palmer Dabbelt , Albert Ou , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Bin Meng , Green Wan , dmaengine , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , "linux-kernel@vger.kernel.org List" , linux-riscv Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Tue, Feb 15, 2022 at 8:06 PM Vinod Koul wrote: > > On 07-02-22, 14:30, Zong Li wrote: > > It currently assumes that there are always four channels, it would > > cause the error if there is actually less than four channels. Change > > that by getting number of channel from device tree. > > > > For backwards-compatibility, it uses the default value (i.e. 4) when > > there is no 'dma-channels' information in dts. > > > > Signed-off-by: Zong Li > > --- > > drivers/dma/sf-pdma/sf-pdma.c | 21 ++++++++++++++------- > > drivers/dma/sf-pdma/sf-pdma.h | 8 ++------ > > 2 files changed, 16 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/dma/sf-pdma/sf-pdma.c b/drivers/dma/sf-pdma/sf-pdma.c > > index f12606aeff87..2ae10b61dfa1 100644 > > --- a/drivers/dma/sf-pdma/sf-pdma.c > > +++ b/drivers/dma/sf-pdma/sf-pdma.c > > @@ -482,9 +482,7 @@ static void sf_pdma_setup_chans(struct sf_pdma *pdma) > > static int sf_pdma_probe(struct platform_device *pdev) > > { > > struct sf_pdma *pdma; > > - struct sf_pdma_chan *chan; > > struct resource *res; > > - int len, chans; > > int ret; > > const enum dma_slave_buswidth widths = > > DMA_SLAVE_BUSWIDTH_1_BYTE | DMA_SLAVE_BUSWIDTH_2_BYTES | > > @@ -492,13 +490,21 @@ static int sf_pdma_probe(struct platform_device *pdev) > > DMA_SLAVE_BUSWIDTH_16_BYTES | DMA_SLAVE_BUSWIDTH_32_BYTES | > > DMA_SLAVE_BUSWIDTH_64_BYTES; > > > > - chans = PDMA_NR_CH; > > - len = sizeof(*pdma) + sizeof(*chan) * chans; > > - pdma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); > > + pdma = devm_kzalloc(&pdev->dev, sizeof(*pdma), GFP_KERNEL); > > if (!pdma) > > return -ENOMEM; > > > > - pdma->n_chans = chans; > > + ret = of_property_read_u32(pdev->dev.of_node, "dma-channels", > > + &pdma->n_chans); > > + if (ret) { > > + dev_notice(&pdev->dev, "set number of channels to default value: 4\n"); > > This is useful for only debug i think, so dev_dbg perhaps > Thanks for your suggestion, let me change it in the next version. > > + pdma->n_chans = PDMA_MAX_NR_CH; > > + } > > + > > + if (pdma->n_chans > PDMA_MAX_NR_CH) { > > + dev_err(&pdev->dev, "the number of channels exceeds the maximum\n"); > > + return -EINVAL; > > + } > > > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > > pdma->membase = devm_ioremap_resource(&pdev->dev, res); > > @@ -556,7 +562,7 @@ static int sf_pdma_remove(struct platform_device *pdev) > > struct sf_pdma_chan *ch; > > int i; > > > > - for (i = 0; i < PDMA_NR_CH; i++) { > > + for (i = 0; i < pdma->n_chans; i++) { > > ch = &pdma->chans[i]; > > > > devm_free_irq(&pdev->dev, ch->txirq, ch); > > @@ -574,6 +580,7 @@ static int sf_pdma_remove(struct platform_device *pdev) > > > > static const struct of_device_id sf_pdma_dt_ids[] = { > > { .compatible = "sifive,fu540-c000-pdma" }, > > + { .compatible = "sifive,pdma0" }, > > {}, > > }; > > MODULE_DEVICE_TABLE(of, sf_pdma_dt_ids); > > diff --git a/drivers/dma/sf-pdma/sf-pdma.h b/drivers/dma/sf-pdma/sf-pdma.h > > index 0c20167b097d..8127d792f639 100644 > > --- a/drivers/dma/sf-pdma/sf-pdma.h > > +++ b/drivers/dma/sf-pdma/sf-pdma.h > > @@ -22,11 +22,7 @@ > > #include "../dmaengine.h" > > #include "../virt-dma.h" > > > > -#define PDMA_NR_CH 4 > > - > > -#if (PDMA_NR_CH != 4) > > -#error "Please define PDMA_NR_CH to 4" > > -#endif > > +#define PDMA_MAX_NR_CH 4 > > > > #define PDMA_BASE_ADDR 0x3000000 > > #define PDMA_CHAN_OFFSET 0x1000 > > @@ -118,7 +114,7 @@ struct sf_pdma { > > void __iomem *membase; > > void __iomem *mappedbase; > > u32 n_chans; > > - struct sf_pdma_chan chans[PDMA_NR_CH]; > > + struct sf_pdma_chan chans[PDMA_MAX_NR_CH]; > > why waste memory allocating max, we know number of channels in probe, > why not allocate runtime? > I kept it there because I'd like to do minimum change in this patch set. You're right, let me change it in the next version. > -- > ~Vinod