Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp374998rwb; Mon, 26 Sep 2022 21:05:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4DNvc+aq/WKhF4Dt5XAWPrI2O23Ya0lCFZRhyOBgZh7mDq6GE/DZo8W9XMEHu6iD+0MkEE X-Received: by 2002:a05:6402:5243:b0:451:6d52:5928 with SMTP id t3-20020a056402524300b004516d525928mr25694772edd.328.1664251557838; Mon, 26 Sep 2022 21:05:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664251557; cv=none; d=google.com; s=arc-20160816; b=XXxd3eyzIxoh+cLR2qd0ns0For+D6Lr4BVEIIIZvUMkSYBlq/Bs8LJI5rt4o0jt8Hk RIXIOc3Pba8fvTUbnvVY7N2xIcoP8dIZMA6gaLg7l+mLmrSXSDsYOfgaT3q/OZpxjxXt 6y337sqMzpOULft//yqekOUf7Q2pE3dDrqvinwOlTvG8/yXJhB81yjzrRf9n+AcDf0GO 7pY2PcpS0uFxSLQxJMExzVg7rRZaUrjBdtaPa2b6m/2umOBhxNBecKXqAsKXnWG/IZsw fPmRGT9FHEIQNDtIQp1o/fUTDJgF/FDlFa+915yn/GMmixJjWIL7jUEJvnt5RFPYziPX 1Ndw== 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:from:dkim-signature; bh=SzXqMwnMUYUrvjoSVir0fP8kScyKsUlvqWallfPjjWE=; b=alhAhGVf3LFQKlknuDfD8Z8R30Te356mV/k7VlemJsIzRVIVQdAXGlsSqRGn3KwxRp 5tFpshlZNL4SjWKeMzOoqQExzg3byiftVQ0ns5gQPjdiLWLhSyk1hAYOisYCRYsgIyya aXCsA0ai2zx2aEMGZ1/mAI9yJpOAgi4FRdQrC7F6+jnvH+dd8v9wzkTjUKf5jzd7zxih qPJsqU3cgBBVob8LZmGdo3oYnFI0Xa9gS5476rzMd1Vx+A5HiWcumEnVSpaciyDrfmx9 zAKgqeN6kILTmiH5K3CImtzowMTav6inZh9faqX7uH1XSDFr8ktq1KuKPkn7vUcHraq8 38CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=PtGfUx2Y; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i20-20020a05640242d400b00457a0fced64si643342edc.552.2022.09.26.21.05.31; Mon, 26 Sep 2022 21:05:57 -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=@mediatek.com header.s=dk header.b=PtGfUx2Y; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229572AbiI0EB3 (ORCPT + 99 others); Tue, 27 Sep 2022 00:01:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbiI0EBU (ORCPT ); Tue, 27 Sep 2022 00:01:20 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57EF75A148 for ; Mon, 26 Sep 2022 21:01:16 -0700 (PDT) X-UUID: a42d3377a78b475f81c0fce5315a1c7e-20220927 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=SzXqMwnMUYUrvjoSVir0fP8kScyKsUlvqWallfPjjWE=; b=PtGfUx2Y/hPnfD4BhubB6uUjJq/2LO68yI5v5cGIvkW6xNbNlFaxms2S/D0dSj9CPvUay3MxF2kvVt4gmTUc4Ugi+5kSET4Zw7fsx/rxUWpNcA4UgPwjlF+kLtBiuXRemvcdMmzTYX6saH+Ox4bz7MLtV7rWplWhUwCIKKYmAog=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:cad49a7e-1611-41ef-88d1-6efeff3eb82e,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:100 X-CID-INFO: VERSION:1.1.11,REQID:cad49a7e-1611-41ef-88d1-6efeff3eb82e,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTIO N:quarantine,TS:100 X-CID-META: VersionHash:39a5ff1,CLOUDID:f0ce1f07-1cee-4c38-b21b-a45f9682fdc0,B ulkID:2209271201119CD1CMNL,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48|823| 824,TC:nil,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:nil,QS:nil,BEC:n il,COL:0 X-UUID: a42d3377a78b475f81c0fce5315a1c7e-20220927 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 429035312; Tue, 27 Sep 2022 12:01:09 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Tue, 27 Sep 2022 12:01:07 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 27 Sep 2022 12:01:06 +0800 From: Yongqiang Niu To: CK Hu , Chun-Kuang Hu CC: Jassi Brar , Matthias Brugger , , , , , Hsin-Yi Wang , Yongqiang Niu Subject: [PATCH v4] mailbox: mtk-cmdq: fix gce timeout issue Date: Tue, 27 Sep 2022 12:01:05 +0800 Message-ID: <20220927040105.21494-1-yongqiang.niu@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY,URIBL_CSS 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 1. enable gce ddr enable(gce reigster offset 0x48, bit 16 to 18) when gce work, and disable gce ddr enable when gce work job done 2. add cmdq ddr enable/disable api, and control gce ddr enable/disable to make sure it could protect when cmdq is multiple used by display and mdp this is only for some SOC which has flag "gce_ddr_en". for this kind of gce, there is a handshake flow between gce and ddr hardware, if not set ddr enable flag of gce, ddr will fall into idle mode, then gce instructions will not process done. we need set this flag of gce to tell ddr when gce is idle or busy controlled by software flow. ddr problem is a special case. when test suspend/resume case, gce sometimes will pull ddr, and ddr can not go to suspend. if we set gce register 0x48 to 0x7, will fix this gce pull ddr issue, as you have referred [1] and [2] (8192 and 8195) but for mt8186, the gce is more special, except setting of [1] and [2], we need add more setting set gce register 0x48 to (0x7 << 16 | 0x7) when gce working to make sure gce could process all instructions ok. this case just need normal bootup, if we not set this, display cmdq task will timeout, and chrome homescreen will always black screen. and with this patch, we have done these test on mt8186: 1.suspend/resume 2.boot up to home screen 3.playback video with youtube. suspend issue is special gce hardware issue, gce client driver command already process done, but gce still pull ddr. Signed-off-by: Yongqiang Niu --- change since v3: split cmdq_sw_ddr_enable/cmdq_sw_ddr_disable into single api to control mt8186 gce ddr enable flow --- --- drivers/mailbox/mtk-cmdq-mailbox.c | 61 ++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c index 9465f9081515..650a1ed1a579 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -38,6 +38,8 @@ #define CMDQ_THR_PRIORITY 0x40 #define GCE_GCTL_VALUE 0x48 +#define GCE_CTRL_BY_SW GENMASK(18, 16) +#define GCE_DDR_EN GENMASK(2, 0) #define CMDQ_THR_ACTIVE_SLOT_CYCLES 0x3200 #define CMDQ_THR_ENABLED 0x1 @@ -80,16 +82,51 @@ struct cmdq { bool suspended; u8 shift_pa; bool control_by_sw; + bool sw_ddr_en; u32 gce_num; + atomic_t usage; + spinlock_t lock; }; struct gce_plat { u32 thread_nr; u8 shift; bool control_by_sw; + bool sw_ddr_en; u32 gce_num; }; +static void cmdq_sw_ddr_enable(struct cmdq *cmdq) +{ + s32 usage; + unsigned long flags; + + spin_lock_irqsave(&cmdq->lock, flags); + + usage = atomic_inc_return(&cmdq->usage); + + if (usage <= 0) + dev_err(cmdq->mbox.dev, "ref count %d suspend %d\n", + usage, cmdq->suspended); + else if (usage == 1) + writel(GCE_DDR_EN + GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE); + + spin_unlock_irqrestore(&cmdq->lock, flags); +} + +static void cmdq_sw_ddr_disable(struct cmdq *cmdq) +{ + s32 usage; + + usage = atomic_dec_return(&cmdq->usage); + + if (usage < 0) + dev_err(cmdq->mbox.dev, "ref count %d suspend %d\n", + usage, cmdq->suspended); + else if (usage == 0) + writel(GCE_CTRL_BY_SW, cmdq->base + GCE_GCTL_VALUE); +} + u8 cmdq_get_shift_pa(struct mbox_chan *chan) { struct cmdq *cmdq = container_of(chan->mbox, struct cmdq, mbox); @@ -266,6 +303,10 @@ static void cmdq_thread_irq_handler(struct cmdq *cmdq, if (list_empty(&thread->task_busy_list)) { cmdq_thread_disable(cmdq, thread); + + if (cmdq->sw_ddr_en) + cmdq_sw_ddr_disable(cmdq); + clk_bulk_disable(cmdq->gce_num, cmdq->clocks); } } @@ -357,6 +398,8 @@ static int cmdq_mbox_send_data(struct mbox_chan *chan, void *data) if (list_empty(&thread->task_busy_list)) { WARN_ON(clk_bulk_enable(cmdq->gce_num, cmdq->clocks)); + if (cmdq->sw_ddr_en) + cmdq_sw_ddr_enable(cmdq); /* * The thread reset will clear thread related register to 0, * including pc, end, priority, irq, suspend and enable. Thus @@ -427,6 +470,9 @@ static void cmdq_mbox_shutdown(struct mbox_chan *chan) kfree(task); } + if (cmdq->sw_ddr_en) + cmdq_sw_ddr_disable(cmdq); + cmdq_thread_disable(cmdq, thread); clk_bulk_disable(cmdq->gce_num, cmdq->clocks); @@ -468,6 +514,10 @@ static int cmdq_mbox_flush(struct mbox_chan *chan, unsigned long timeout) cmdq_thread_resume(thread); cmdq_thread_disable(cmdq, thread); + + if (cmdq->sw_ddr_en) + cmdq_sw_ddr_disable(cmdq); + clk_bulk_disable(cmdq->gce_num, cmdq->clocks); out: @@ -543,6 +593,7 @@ static int cmdq_probe(struct platform_device *pdev) cmdq->thread_nr = plat_data->thread_nr; cmdq->shift_pa = plat_data->shift; cmdq->control_by_sw = plat_data->control_by_sw; + cmdq->sw_ddr_en = plat_data->sw_ddr_en; cmdq->gce_num = plat_data->gce_num; cmdq->irq_mask = GENMASK(cmdq->thread_nr - 1, 0); err = devm_request_irq(dev, cmdq->irq, cmdq_irq_handler, IRQF_SHARED, @@ -615,6 +666,7 @@ static int cmdq_probe(struct platform_device *pdev) WARN_ON(clk_bulk_prepare(cmdq->gce_num, cmdq->clocks)); + spin_lock_init(&cmdq->lock); cmdq_init(cmdq); return 0; @@ -660,9 +712,18 @@ static const struct gce_plat gce_plat_v6 = { .gce_num = 2 }; +static const struct gce_plat gce_plat_v7 = { + .thread_nr = 24, + .shift = 3, + .control_by_sw = true, + .sw_ddr_en = true, + .gce_num = 1 +}; + static const struct of_device_id cmdq_of_ids[] = { {.compatible = "mediatek,mt8173-gce", .data = (void *)&gce_plat_v2}, {.compatible = "mediatek,mt8183-gce", .data = (void *)&gce_plat_v3}, + {.compatible = "mediatek,mt8186-gce", .data = (void *)&gce_plat_v7}, {.compatible = "mediatek,mt6779-gce", .data = (void *)&gce_plat_v4}, {.compatible = "mediatek,mt8192-gce", .data = (void *)&gce_plat_v5}, {.compatible = "mediatek,mt8195-gce", .data = (void *)&gce_plat_v6}, -- 2.25.1