Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2241230pxt; Sun, 8 Aug 2021 16:50:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+4HBk0mMglRukzG7BZQfxrDG/kKiajoLkm2JlWIEn/cWWGw4PaV0O3VhqvXKkBg/YACcp X-Received: by 2002:a05:6638:214d:: with SMTP id z13mr19943466jaj.113.1628466615567; Sun, 08 Aug 2021 16:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628466615; cv=none; d=google.com; s=arc-20160816; b=wpr69MYFa+iGv1h/C3BAK7ey2Q3YlxdQEuA8SKFRcr4cZ2aoCq/hlgSnLIxBNn+tnN RroRKOFYWCCQ6HYQ7ix+LkX1JOFy+E8ISC3UACB7zQKltDO0i6P0L81XbebTb6pCwHnK BTxAzFxj3W3/putHXhFydMemERXfoMnksvLLVgEupe9uT4MRdOHVJYB11YPq3hWUND5r orjN3i99uygJ552JB1cF1iHt7+FK9BRapNLxfclDDXylMkIm+wMBhduV2soV+z3LEZE5 FS5ngV7wzZP4j8HGYgd/JoB1aOCs0u0Kw3VYQCAZIsMO+ux599m9UYX6nYljhK3xQl96 JX9Q== 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:from :dkim-signature; bh=aKsA2BNTRqZMoBshMmKxXuZ09zv720j/AL0ofIWeqJw=; b=DAUSOZZbLTncBAnA/HTGCL6dtVx09APMvj/78syV100UHKGYrxtKSA3nXL4kaU/+IB Epbylw2acptzK/CRDCy6hGrr4q5owr9LuNdIm6ya+lssIJpjitDU9XvneGp1K7Pzoi8A gSaL3AUNQkagbRHoYCdhO4lNMTTACBGx3ehxceSCKMeiNIASU3dLz4/tGiFnM3gfpu41 VywalGNbmnUl8LRtksSbdQ74DQh2Yn1zGBajLiswwl1Wtg1seZ9OlaXT7g1lFGjn8/dX kxbhc6F1IXpb13j/sWbenCcG3f99ZcyHlyOTY3B2x5bVYHzorT3XhCy9BAHetfGgZIub hDSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="gDVzD/Pc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l15si15882221jak.4.2021.08.08.16.50.04; Sun, 08 Aug 2021 16:50:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="gDVzD/Pc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231764AbhHHXsN (ORCPT + 99 others); Sun, 8 Aug 2021 19:48:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:37904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231675AbhHHXsL (ORCPT ); Sun, 8 Aug 2021 19:48:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD6CC60E53; Sun, 8 Aug 2021 23:47:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1628466472; bh=xmyb+69TZrKaCU1pp1cXsTuGGJovIt+pixp1i4wic7k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gDVzD/Pcsv2dmdMtCE5HS0QjztT/vqE2n0KBD6oSPMut6B5EDQLdphtlaihR1hG7r WZLHRmzKXzwp30Gc4gSbCjsWx47SZciHBRz8faLdfWbqR+E1AWv+rNLcU812fy3iCA fRIEHhkNmmouv6LEWt9yGVCGcMy2yse78l7ugmXl1Ku/zEiriqOc1xzjlNcAUcV6mS qCLhHxludV7vyolyD2I0QAIk4bFUyOpdTxv4Dz5OO702sZLAC7hZQlx9Rn84j1VlWr NWJGPLHy/duXTKsij/06L7OIWKgnME1jKs7lP1KC9imcbD9mWAQV25WeuP/Mi241sp PmkJig+HPQ3mQ== From: Chun-Kuang Hu To: Philipp Zabel , David Airlie , Daniel Vetter Cc: Yongqiang Niu , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, Chun-Kuang Hu Subject: [PATCH v2 2/4] drm/mediatek: Remove struct cmdq_client Date: Mon, 9 Aug 2021 07:47:31 +0800 Message-Id: <20210808234733.14782-3-chunkuang.hu@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210808234733.14782-1-chunkuang.hu@kernel.org> References: <20210808234733.14782-1-chunkuang.hu@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In mailbox rx_callback, it pass struct mbox_client to callback function, but it could not map back to mtk_drm_crtc instance because struct cmdq_client use a pointer to struct mbox_client: struct cmdq_client { struct mbox_client client; struct mbox_chan *chan; }; struct mtk_drm_crtc { /* client instance data */ struct cmdq_client *cmdq_client; }; so remove struct cmdq_client and let mtk_drm_crtc instance define mbox_client as: struct mtk_drm_crtc { /* client instance data */ struct mbox_client cl; }; and in rx_callback function, use struct mbox_client to get struct mtk_drm_crtc. Signed-off-by: Chun-Kuang Hu --- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 80 +++++++++++++++++++------ 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c index cac8fe219c95..da92a3fedd0a 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c @@ -52,7 +52,8 @@ struct mtk_drm_crtc { bool pending_async_planes; #if IS_REACHABLE(CONFIG_MTK_CMDQ) - struct cmdq_client *cmdq_client; + struct mbox_client cmdq_cl; + struct mbox_chan *cmdq_chan; u32 cmdq_event; #endif @@ -224,11 +225,51 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc, } #if IS_REACHABLE(CONFIG_MTK_CMDQ) +static struct cmdq_pkt *mtk_drm_cmdq_pkt_create(struct mbox_chan *chan, size_t size) +{ + struct cmdq_pkt *pkt; + struct device *dev; + dma_addr_t dma_addr; + + pkt = kzalloc(sizeof(*pkt), GFP_KERNEL); + if (!pkt) + return ERR_PTR(-ENOMEM); + pkt->va_base = kzalloc(size, GFP_KERNEL); + if (!pkt->va_base) { + kfree(pkt); + return ERR_PTR(-ENOMEM); + } + pkt->buf_size = size; + + dev = chan->mbox->dev; + dma_addr = dma_map_single(dev, pkt->va_base, pkt->buf_size, + DMA_TO_DEVICE); + if (dma_mapping_error(dev, dma_addr)) { + dev_err(dev, "dma map failed, size=%u\n", (u32)(u64)size); + kfree(pkt->va_base); + kfree(pkt); + return ERR_PTR(-ENOMEM); + } + + pkt->pa_base = dma_addr; + + return pkt; +} + +static void mtk_drm_cmdq_pkt_destroy(struct mbox_chan *chan, struct cmdq_pkt *pkt) +{ + dma_unmap_single(chan->mbox->dev, pkt->pa_base, pkt->buf_size, + DMA_TO_DEVICE); + kfree(pkt->va_base); + kfree(pkt); +} + static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg) { + struct mtk_drm_crtc *mtk_crtc = container_of(cl, struct mtk_drm_crtc, cmdq_cl); struct cmdq_cb_data *data = mssg; - cmdq_pkt_destroy(data->pkt); + mtk_drm_cmdq_pkt_destroy(mtk_crtc->cmdq_chan, data->pkt); } #endif @@ -472,19 +513,19 @@ static void mtk_drm_crtc_update_config(struct mtk_drm_crtc *mtk_crtc, mtk_mutex_release(mtk_crtc->mutex); } #if IS_REACHABLE(CONFIG_MTK_CMDQ) - if (mtk_crtc->cmdq_client) { - mbox_flush(mtk_crtc->cmdq_client->chan, 2000); - cmdq_handle = cmdq_pkt_create(mtk_crtc->cmdq_client, PAGE_SIZE); + if (mtk_crtc->cmdq_chan) { + mbox_flush(mtk_crtc->cmdq_chan, 2000); + cmdq_handle = mtk_drm_cmdq_pkt_create(mtk_crtc->cmdq_chan, PAGE_SIZE); cmdq_pkt_clear_event(cmdq_handle, mtk_crtc->cmdq_event); cmdq_pkt_wfe(cmdq_handle, mtk_crtc->cmdq_event, false); mtk_crtc_ddp_config(crtc, cmdq_handle); cmdq_pkt_finalize(cmdq_handle); - dma_sync_single_for_device(mtk_crtc->cmdq_client->chan->mbox->dev, + dma_sync_single_for_device(mtk_crtc->cmdq_chan->mbox->dev, cmdq_handle->pa_base, cmdq_handle->cmd_buf_size, DMA_TO_DEVICE); - mbox_send_message(mtk_crtc->cmdq_client->chan, cmdq_handle); - mbox_client_txdone(mtk_crtc->cmdq_client->chan, 0); + mbox_send_message(mtk_crtc->cmdq_chan, cmdq_handle); + mbox_client_txdone(mtk_crtc->cmdq_chan, 0); } #endif mtk_crtc->config_updating = false; @@ -498,7 +539,7 @@ static void mtk_crtc_ddp_irq(void *data) struct mtk_drm_private *priv = crtc->dev->dev_private; #if IS_REACHABLE(CONFIG_MTK_CMDQ) - if (!priv->data->shadow_register && !mtk_crtc->cmdq_client) + if (!priv->data->shadow_register && !mtk_crtc->cmdq_chan) #else if (!priv->data->shadow_register) #endif @@ -841,17 +882,20 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, mutex_init(&mtk_crtc->hw_lock); #if IS_REACHABLE(CONFIG_MTK_CMDQ) - mtk_crtc->cmdq_client = - cmdq_mbox_create(mtk_crtc->mmsys_dev, - drm_crtc_index(&mtk_crtc->base)); - if (IS_ERR(mtk_crtc->cmdq_client)) { + mtk_crtc->cmdq_cl.dev = mtk_crtc->mmsys_dev; + mtk_crtc->cmdq_cl.tx_block = false; + mtk_crtc->cmdq_cl.knows_txdone = true; + mtk_crtc->cmdq_cl.rx_callback = ddp_cmdq_cb; + mtk_crtc->cmdq_chan = + mbox_request_channel(&mtk_crtc->cmdq_cl, + drm_crtc_index(&mtk_crtc->base)); + if (IS_ERR(mtk_crtc->cmdq_chan)) { dev_dbg(dev, "mtk_crtc %d failed to create mailbox client, writing register by CPU now\n", drm_crtc_index(&mtk_crtc->base)); - mtk_crtc->cmdq_client = NULL; + mtk_crtc->cmdq_chan = NULL; } - if (mtk_crtc->cmdq_client) { - mtk_crtc->cmdq_client->client.rx_callback = ddp_cmdq_cb; + if (mtk_crtc->cmdq_chan) { ret = of_property_read_u32_index(priv->mutex_node, "mediatek,gce-events", drm_crtc_index(&mtk_crtc->base), @@ -859,8 +903,8 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, if (ret) { dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n", drm_crtc_index(&mtk_crtc->base)); - cmdq_mbox_destroy(mtk_crtc->cmdq_client); - mtk_crtc->cmdq_client = NULL; + mbox_free_channel(mtk_crtc->cmdq_chan); + mtk_crtc->cmdq_chan = NULL; } } #endif -- 2.25.1