From patchwork Wed Oct 19 13:23:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Povi=C5=A1er?= X-Patchwork-Id: 5481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp333287wrs; Wed, 19 Oct 2022 06:40:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5O7E3QZK5Qf4pG9+t36X+sGYumTbBumCDWADuMO2oj6obzQnbkk9Xq28vtDLtb5ERo04HD X-Received: by 2002:a05:6402:278c:b0:45c:da8e:837d with SMTP id b12-20020a056402278c00b0045cda8e837dmr7678850ede.18.1666186825769; Wed, 19 Oct 2022 06:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666186825; cv=none; d=google.com; s=arc-20160816; b=wKGXLXRAYytSQ/GWO3qwmhrOlg/vbfjkbsbgTNNGb58/FO55NJnifUAJeSItvscl5w QBgrMQjD2S9i/GRg8L/lpiR8xuXsnGHdtgTGD6W9YpON2qu6tQCs70IzDFiMKowj8/nm MwsV3FnFSIUJPQgPLFAS9w2RSO3QtaGY9hX5KoRxmUtdwrFdBUAQtBkEmoawYxFgEab4 nASWlsz4toPoofXSyNcfz73dwLHJzDX5Ot4g6iYV6CvPATJLWYwgScVxrbPLOorNopLo zt8FHROmtwgUaOOCyzU+NOYdPtyX11I2Q24PXDgT5r2N2PxyZv2AZyGrd2QMQO02FW5j I4PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:dkim-signature:from; bh=00XpFFUQMJvRxGis99g6ozE8OJO2nXC2MC4LveWM/4k=; b=Id8GiZVz0w52GMMcHcbvAMF2EM+N5AXKoEcKwVoAAxeqS5gin1b7Y7wMUy1/B17wmV 1+WycEktgKojFeHsgCFJEFljAJsmUvl5t7gOMq/ThQtN1d/2lSyahlmh0JwHYDWAfGR1 NywNFtBVC6D1JgyTb7N9TtRukXg6XEMZQsnLkBpuUM6rzJmjIz/P5DtWUXVD/aAC9IY1 GqLaXQn3KxkXVGlQw66sQImCgATnL4EIOV4q50zsRovqGcA01r5QEr85fyCfJXa8/Epf iG1G3PFKgM3uKRIV7vtl0aM/8eApi3PmOxmfGwXK3ujsDWiQRIzQVhjHhGYEvuNTvFYT lSzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b=qgn+em+f; 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=cutebit.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xg14-20020a170907320e00b00780805b99ccsi15964752ejb.648.2022.10.19.06.39.58; Wed, 19 Oct 2022 06:40:25 -0700 (PDT) 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=@cutebit.org header.s=mail header.b=qgn+em+f; 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=cutebit.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbiJSNgo (ORCPT + 99 others); Wed, 19 Oct 2022 09:36:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbiJSNgG (ORCPT ); Wed, 19 Oct 2022 09:36:06 -0400 Received: from hutie.ust.cz (hutie.ust.cz [185.8.165.127]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E708D11E47E; Wed, 19 Oct 2022 06:24:53 -0700 (PDT) From: =?utf-8?q?Martin_Povi=C5=A1er?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cutebit.org; s=mail; t=1666185808; bh=00XpFFUQMJvRxGis99g6ozE8OJO2nXC2MC4LveWM/4k=; h=From:To:Cc:Subject:Date; b=qgn+em+fUXd9c0OqunKrr0HB3TkgnoqpJfVxHZFO6AbzjzhRilDuwHSOmsTGrMKB8 ogODkpAq9wKcMnmPLRGOEqhmsf4aQVj72qARmqJ25hsLxLDdBgJ2QpQ8x36gbgRa1c x1beH56jVvPOmCxtHvIwJh9YqCbaXOSc7c4TIHis= To: Vinod Koul Cc: =?utf-8?q?Martin_Povi=C5=A1er?= , asahi@lists.linux.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] dmaengine: apple-admac: Fix grabbing of channels in of_xlate Date: Wed, 19 Oct 2022 15:23:23 +0200 Message-Id: <20221019132324.8585-1-povik+lin@cutebit.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747123517098281928?= X-GMAIL-MSGID: =?utf-8?q?1747123517098281928?= The of_xlate callback is supposed to return the channel after already having 'grabbed' it for private use, so fill that in. Fixes: b127315d9a78 ("dmaengine: apple-admac: Add Apple ADMAC driver") Signed-off-by: Martin Povišer --- drivers/dma/apple-admac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index 317ca76ccafd..a2cc520225d3 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -493,7 +493,7 @@ static struct dma_chan *admac_dma_of_xlate(struct of_phandle_args *dma_spec, return NULL; } - return &ad->channels[index].chan; + return dma_get_slave_channel(&ad->channels[index].chan); } static int admac_drain_reports(struct admac_data *ad, int channo) From patchwork Wed Oct 19 13:23:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Povi=C5=A1er?= X-Patchwork-Id: 5537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp345773wrs; Wed, 19 Oct 2022 07:05:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7h2URIdd09XgLrF0CMj/z4teCK0En8/r3yfj0EvStMdXiqdpv0ITbCiziH7XQ33zFgQvof X-Received: by 2002:a17:906:dc89:b0:78d:5616:4c24 with SMTP id cs9-20020a170906dc8900b0078d56164c24mr6897796ejc.118.1666188351615; Wed, 19 Oct 2022 07:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188351; cv=none; d=google.com; s=arc-20160816; b=L/qrZmtjTUS8cfjlazTy1EpzERAVvmGRineXfOhxQ4jmRjFUWe3b+lfG10rwLYvXoK 2T9mdxMKlzzLegeJM3muDhi4h/MkYOf8wk0S6nH+1hfMtRNxKN9qrgjPGiNatBl8cvok tyg1RjhyNFrT1K6jMWXzYLFGmEw1ZKPlC3C0Gi/CuzoswFk10kvgomx3KRWHGW3Sl6t8 ibxsb4MPHTO9SOTdzmoAKIu4O7xQzAZAS2qaBxhMWr1HRUa5I9etOmZMKTuDVpwpOg7b 9oY8FaCT1e6wE+GIHeyEaIFHrJTTvf43D/zf5JA/KyJf4L+c+MB0eFW3UF6emYaLz0MV iEjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :from; bh=MzctQr9qZv9WWpuIx6Po0Lx1bRPSxyuGpqrsSw2Aa2g=; b=xNYbWq5j9mud7BL7UVQeVAgbo+6flvhi3jzzq8F1HVxtsVXrcYdR8Gy+CeMigCnX9l S1hr9Nye6RUlae1b06HlU+LGrwerMGG0MXuy1qu1+Lw4rnoM4YNvUWXtqC73fcN+VK1J EEgx0cEO/SoKRo3hkWeS0e/Ej7oOKpUncLwtF23lIhsvpb/YDgX8VfAKpBIfOamZ3E33 LHlimJmew84BM8C4+ra8c/SAUsrK09qEaMe6V42xMUsA1o8LK/U8tKWthoXCMF4kFOQo npsYvZy80hqyK2tozpdL3Eql84tNNg7mzR1vmLK1ouWe+75Q/HC1A3ysAiUbIqhhYxBq Fg7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cutebit.org header.s=mail header.b=T0rg3eYT; 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=cutebit.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a170906b10c00b00787abcb1ce0si13629575ejy.679.2022.10.19.07.05.14; Wed, 19 Oct 2022 07:05:51 -0700 (PDT) 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=@cutebit.org header.s=mail header.b=T0rg3eYT; 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=cutebit.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233592AbiJSNuy (ORCPT + 99 others); Wed, 19 Oct 2022 09:50:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233575AbiJSNt6 (ORCPT ); Wed, 19 Oct 2022 09:49:58 -0400 Received: from hutie.ust.cz (unknown [IPv6:2a03:3b40:fe:f0::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D57EE1D4DC3; Wed, 19 Oct 2022 06:34:07 -0700 (PDT) From: =?utf-8?q?Martin_Povi=C5=A1er?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cutebit.org; s=mail; t=1666185808; bh=MzctQr9qZv9WWpuIx6Po0Lx1bRPSxyuGpqrsSw2Aa2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T0rg3eYTePFllJTlCl7xRrk8Ov5UVjgswieO3K5pxTrtjLl0bJe0diwD/d3LP3Dhl TOfFPysneaHVI61NwKb92OjItsWOJi08NlvZ0bcLDW0vNPDOJj0xqkwVKze6/lqLdZ bWi/9bZBa70dbEUpSNvKbByInX0Z5j/l7vo7apwI= To: Vinod Koul Cc: =?utf-8?q?Martin_Povi=C5=A1er?= , asahi@lists.linux.dev, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] dmaengine: apple-admac: Allocate cache SRAM to channels Date: Wed, 19 Oct 2022 15:23:24 +0200 Message-Id: <20221019132324.8585-2-povik+lin@cutebit.org> In-Reply-To: <20221019132324.8585-1-povik+lin@cutebit.org> References: <20221019132324.8585-1-povik+lin@cutebit.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_FAIL,SPF_HELO_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747125117340485763?= X-GMAIL-MSGID: =?utf-8?q?1747125117340485763?= There's a previously unknown part of the controller interface: We have to assign SRAM carveouts to channels to store their in-flight samples in. So, obtain the size of the SRAM from a read-only register and divide it into 2K blocks for allocation to channels. The FIFO depths we configure will always fit into 2K. (This fixes audio artifacts during simultaneous playback/capture on multiple channels -- which looking back is fully accounted for by having had the caches in the DMA controller overlap in memory.) Fixes: b127315d9a78 ("dmaengine: apple-admac: Add Apple ADMAC driver") Signed-off-by: Martin Povišer --- drivers/dma/apple-admac.c | 102 +++++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index a2cc520225d3..90f28bda29c8 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -21,6 +21,12 @@ #define NCHANNELS_MAX 64 #define IRQ_NOUTPUTS 4 +/* + * For allocation purposes we split the cache + * memory into blocks of fixed size (given in bytes). + */ +#define SRAM_BLOCK 2048 + #define RING_WRITE_SLOT GENMASK(1, 0) #define RING_READ_SLOT GENMASK(5, 4) #define RING_FULL BIT(9) @@ -36,6 +42,9 @@ #define REG_TX_STOP 0x0004 #define REG_RX_START 0x0008 #define REG_RX_STOP 0x000c +#define REG_IMPRINT 0x0090 +#define REG_TX_SRAM_SIZE 0x0094 +#define REG_RX_SRAM_SIZE 0x0098 #define REG_CHAN_CTL(ch) (0x8000 + (ch) * 0x200) #define REG_CHAN_CTL_RST_RINGS BIT(0) @@ -53,7 +62,9 @@ #define BUS_WIDTH_FRAME_2_WORDS 0x10 #define BUS_WIDTH_FRAME_4_WORDS 0x20 -#define CHAN_BUFSIZE 0x8000 +#define REG_CHAN_SRAM_CARVEOUT(ch) (0x8050 + (ch) * 0x200) +#define CHAN_SRAM_CARVEOUT_SIZE GENMASK(31, 16) +#define CHAN_SRAM_CARVEOUT_BASE GENMASK(15, 0) #define REG_CHAN_FIFOCTL(ch) (0x8054 + (ch) * 0x200) #define CHAN_FIFOCTL_LIMIT GENMASK(31, 16) @@ -76,6 +87,8 @@ struct admac_chan { struct dma_chan chan; struct tasklet_struct tasklet; + u32 carveout; + spinlock_t lock; struct admac_tx *current_tx; int nperiod_acks; @@ -92,12 +105,24 @@ struct admac_chan { struct list_head to_free; }; +struct admac_sram { + u32 size; + /* + * SRAM_CARVEOUT has 16-bit fields, so the SRAM cannot be larger than + * 64K and a 32-bit bitfield over 2K blocks covers it. + */ + u32 allocated; +}; + struct admac_data { struct dma_device dma; struct device *dev; __iomem void *base; struct reset_control *rstc; + struct mutex cache_alloc_lock; + struct admac_sram txcache, rxcache; + int irq; int irq_index; int nchannels; @@ -118,6 +143,60 @@ struct admac_tx { struct list_head node; }; +static int admac_alloc_sram_carveout(struct admac_data *ad, + enum dma_transfer_direction dir, + u32 *out) +{ + struct admac_sram *sram; + int i, ret = 0, nblocks; + + if (dir == DMA_MEM_TO_DEV) + sram = &ad->txcache; + else + sram = &ad->rxcache; + + mutex_lock(&ad->cache_alloc_lock); + + nblocks = sram->size / SRAM_BLOCK; + for (i = 0; i < nblocks; i++) + if (!(sram->allocated & BIT(i))) + break; + + if (i < nblocks) { + *out = FIELD_PREP(CHAN_SRAM_CARVEOUT_BASE, i * SRAM_BLOCK) | + FIELD_PREP(CHAN_SRAM_CARVEOUT_SIZE, SRAM_BLOCK); + sram->allocated |= BIT(i); + } else { + ret = -EBUSY; + } + + mutex_unlock(&ad->cache_alloc_lock); + + return ret; +} + +static void admac_free_sram_carveout(struct admac_data *ad, + enum dma_transfer_direction dir, + u32 carveout) +{ + struct admac_sram *sram; + u32 base = FIELD_GET(CHAN_SRAM_CARVEOUT_BASE, carveout); + int i; + + if (dir == DMA_MEM_TO_DEV) + sram = &ad->txcache; + else + sram = &ad->rxcache; + + if (WARN_ON(base >= sram->size)) + return; + + mutex_lock(&ad->cache_alloc_lock); + i = base / SRAM_BLOCK; + sram->allocated &= ~BIT(i); + mutex_unlock(&ad->cache_alloc_lock); +} + static void admac_modify(struct admac_data *ad, int reg, u32 mask, u32 val) { void __iomem *addr = ad->base + reg; @@ -466,15 +545,28 @@ static void admac_synchronize(struct dma_chan *chan) static int admac_alloc_chan_resources(struct dma_chan *chan) { struct admac_chan *adchan = to_admac_chan(chan); + struct admac_data *ad = adchan->host; + int ret; dma_cookie_init(&adchan->chan); + ret = admac_alloc_sram_carveout(ad, admac_chan_direction(adchan->no), + &adchan->carveout); + if (ret < 0) + return ret; + + writel_relaxed(adchan->carveout, + ad->base + REG_CHAN_SRAM_CARVEOUT(adchan->no)); return 0; } static void admac_free_chan_resources(struct dma_chan *chan) { + struct admac_chan *adchan = to_admac_chan(chan); + admac_terminate_all(chan); admac_synchronize(chan); + admac_free_sram_carveout(adchan->host, admac_chan_direction(adchan->no), + adchan->carveout); } static struct dma_chan *admac_dma_of_xlate(struct of_phandle_args *dma_spec, @@ -712,6 +804,7 @@ static int admac_probe(struct platform_device *pdev) platform_set_drvdata(pdev, ad); ad->dev = &pdev->dev; ad->nchannels = nchannels; + mutex_init(&ad->cache_alloc_lock); /* * The controller has 4 IRQ outputs. Try them all until @@ -801,6 +894,13 @@ static int admac_probe(struct platform_device *pdev) goto free_irq; } + ad->txcache.size = readl_relaxed(ad->base + REG_TX_SRAM_SIZE); + ad->rxcache.size = readl_relaxed(ad->base + REG_RX_SRAM_SIZE); + + dev_info(&pdev->dev, "Audio DMA Controller\n"); + dev_info(&pdev->dev, "imprint %x TX cache %u RX cache %u\n", + readl_relaxed(ad->base + REG_IMPRINT), ad->txcache.size, ad->rxcache.size); + return 0; free_irq: