Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp3967437imb; Wed, 6 Mar 2019 01:52:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxbU+h1XXaCVwg8QRqT1lxwsi675TQKQCE8DPgq4zSnVtsCfiyACF/6GlG8hmrd9WILONaC X-Received: by 2002:a63:6949:: with SMTP id e70mr5461964pgc.89.1551865977720; Wed, 06 Mar 2019 01:52:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551865977; cv=none; d=google.com; s=arc-20160816; b=RIivvf0MF5L2X3ib9FUXIPT8V4qiwKAXVPwKI5/BmT33Dk4RdcV7z0pu8hTItTK3gp +5ILm/8Qp7LwXkjO6S/NToXnfz63MkjXDtuZV8G4Ukl/S5JVTYZ+6J3m7+9vJRoMdlVn +K4lvfMX+CcFoCIgAKitTm/kcEPKwede90+PQSsNoNkbrhaOFrw9UjaWzCJKVafkkukj 194NNStV2bxPRs6slEhpvxmvNNVzSRX7jig843VvjEdaqr1QHILRWm+9o77rYhDQyhTr oyy/6uFZVvILKlzzj+hinaVA5V7uLMaSv2/GHjRicJraHCULkFUUvrA3KfjRBqzf32lP SM1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=lheTzTT5nMDIkOMLo8Te4kgeQn2zeyxeg/LP3uZ8gIU=; b=VXk/Arh7Y20WIIoNMJcUKqg4nzGUkJhDh930HrZxFSCx+p4wJNVEnyakRQkWtJlz6l Osc26ElKIV6bO2rjOcOfHwu+x8YiqbGDpBugE8QqaL3vJhrDOZ719TACTvZJr7lRE00I cT6xnKoDA68+A3o/jauKUHdaSNyNYBNE9KYNltJOBtwSy6zAUZ2adcx7PbyQXfuxZ9re 4pJUyN3u0BQRhDn8zBv2qsLOR6PkoiAy5l1ADy++NYxhhJWjaLR+JpFCnppCLNs0iPUY iK9EoAS/IQY7u0nbSS447RGfGx04h+VzQfeLpEQj1n6OsWrROK0jP9Y2tcma1vP04R5T FZhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si1012433plr.388.2019.03.06.01.52.42; Wed, 06 Mar 2019 01:52:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729897AbfCFJut (ORCPT + 99 others); Wed, 6 Mar 2019 04:50:49 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:53739 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729863AbfCFJur (ORCPT ); Wed, 6 Mar 2019 04:50:47 -0500 X-UUID: afb0b3fcc279453d89e086e561b416e5-20190306 X-UUID: afb0b3fcc279453d89e086e561b416e5-20190306 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 605550775; Wed, 06 Mar 2019 17:50:39 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 6 Mar 2019 17:50:38 +0800 Received: from mtkslt302.mediatek.inc (10.21.14.115) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 6 Mar 2019 17:50:38 +0800 From: Bibby Hsieh To: Jassi Brar , Matthias Brugger , Rob Herring , CK HU CC: Daniel Kurtz , Sascha Hauer , , , , , , "Sascha Hauer" , Philipp Zabel , Nicolas Boichat , Bibby Hsieh , YT Shen , Daoyuan Huang , Jiaguang Zhang , Dennis-YC Hsieh , Houlong Wei , , , Frederic Chen Subject: [PATCH v2 07/10] soc: mediatek: cmdq: add packet encoder function Date: Wed, 6 Mar 2019 17:50:32 +0800 Message-ID: <1551865835-50974-8-git-send-email-bibby.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1551865835-50974-1-git-send-email-bibby.hsieh@mediatek.com> References: <1551865835-50974-1-git-send-email-bibby.hsieh@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement a function can encode the GCE instructions Signed-off-by: Bibby Hsieh --- drivers/soc/mediatek/mtk-cmdq-helper.c | 125 ++++++++++++++++++++++--------- include/linux/mailbox/mtk-cmdq-mailbox.h | 2 + include/linux/soc/mediatek/mtk-cmdq.h | 14 ++-- 3 files changed, 99 insertions(+), 42 deletions(-) diff --git a/drivers/soc/mediatek/mtk-cmdq-helper.c b/drivers/soc/mediatek/mtk-cmdq-helper.c index ff9fef5..d3873ab 100644 --- a/drivers/soc/mediatek/mtk-cmdq-helper.c +++ b/drivers/soc/mediatek/mtk-cmdq-helper.c @@ -9,11 +9,43 @@ #include #include -#define CMDQ_ARG_A_WRITE_MASK 0xffff +#define CMDQ_GET_ARG_B(arg) (((arg) & GENMASK(31, 16)) >> 16) +#define CMDQ_GET_ARG_C(arg) ((arg) & GENMASK(15, 0)) #define CMDQ_WRITE_ENABLE_MASK BIT(0) #define CMDQ_EOC_IRQ_EN BIT(0) #define CMDQ_EOC_CMD ((u64)((CMDQ_CODE_EOC << CMDQ_OP_CODE_SHIFT)) \ << 32 | CMDQ_EOC_IRQ_EN) +#define CMDQ_IMMEDIATE_VALUE 0 +#define CMDQ_REG_TYPE 1 + +struct cmdq_instruction { + s16 arg_c:16; + s16 arg_b:16; + s16 arg_a:16; + u8 s_op:5; + u8 arg_c_type:1; + u8 arg_b_type:1; + u8 arg_a_type:1; + u8 op:8; +}; + +static void cmdq_pkt_instr_encoder(struct cmdq_pkt *pkt, s16 arg_c, s16 arg_b, + s16 arg_a, u8 s_op, u8 arg_c_type, + u8 arg_b_type, u8 arg_a_type, u8 op) +{ + struct cmdq_instruction *cmdq_inst; + + cmdq_inst = pkt->va_base + pkt->cmd_buf_size; + cmdq_inst->op = op; + cmdq_inst->arg_a_type = arg_a_type; + cmdq_inst->arg_b_type = arg_b_type; + cmdq_inst->arg_c_type = arg_c_type; + cmdq_inst->s_op = s_op; + cmdq_inst->arg_a = arg_a; + cmdq_inst->arg_b = arg_b; + cmdq_inst->arg_c = arg_c; + pkt->cmd_buf_size += CMDQ_INST_SIZE; +} static void cmdq_client_timeout(struct timer_list *t) { @@ -110,10 +142,11 @@ void cmdq_pkt_destroy(struct cmdq_pkt *pkt) } EXPORT_SYMBOL(cmdq_pkt_destroy); -static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code, - u32 arg_a, u32 arg_b) +static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, s16 arg_c, s16 arg_b, + s16 arg_a, u8 s_op, u8 arg_c_type, + u8 arg_b_type, u8 arg_a_type, + enum cmdq_code code) { - u64 *cmd_ptr; if (unlikely(pkt->cmd_buf_size + CMDQ_INST_SIZE > pkt->buf_size)) { /* @@ -129,65 +162,72 @@ static int cmdq_pkt_append_command(struct cmdq_pkt *pkt, enum cmdq_code code, __func__, (u32)pkt->buf_size); return -ENOMEM; } - cmd_ptr = pkt->va_base + pkt->cmd_buf_size; - (*cmd_ptr) = (u64)((code << CMDQ_OP_CODE_SHIFT) | arg_a) << 32 | arg_b; - pkt->cmd_buf_size += CMDQ_INST_SIZE; + cmdq_pkt_instr_encoder(pkt, arg_c, arg_b, arg_a, s_op, arg_c_type, + arg_b_type, arg_a_type, code); return 0; } -int cmdq_pkt_write(struct cmdq_pkt *pkt, u32 value, u32 subsys, u32 offset) +int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value) { - u32 arg_a = (offset & CMDQ_ARG_A_WRITE_MASK) | - (subsys << CMDQ_SUBSYS_SHIFT); - - return cmdq_pkt_append_command(pkt, CMDQ_CODE_WRITE, arg_a, value); + return cmdq_pkt_append_command(pkt, CMDQ_GET_ARG_C(value), + CMDQ_GET_ARG_B(value), offset, subsys, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, CMDQ_CODE_WRITE); } EXPORT_SYMBOL(cmdq_pkt_write); -int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, - u32 subsys, u32 offset, u32 mask) +int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys, u16 offset, + u32 value, u32 mask) { u32 offset_mask = offset; int err = 0; if (mask != 0xffffffff) { - err = cmdq_pkt_append_command(pkt, CMDQ_CODE_MASK, 0, ~mask); + err = cmdq_pkt_append_command(pkt, CMDQ_GET_ARG_C(~mask), + CMDQ_GET_ARG_B(~mask), + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_CODE_MASK); offset_mask |= CMDQ_WRITE_ENABLE_MASK; } - err |= cmdq_pkt_write(pkt, value, subsys, offset_mask); + err |= cmdq_pkt_write(pkt, subsys, offset_mask, value); return err; } EXPORT_SYMBOL(cmdq_pkt_write_mask); -int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u32 event) +int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event) { - u32 arg_b; - if (event >= CMDQ_MAX_EVENT) return -EINVAL; - /* - * WFE arg_b - * bit 0-11: wait value - * bit 15: 1 - wait, 0 - no wait - * bit 16-27: update value - * bit 31: 1 - update, 0 - no update - */ - arg_b = CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | CMDQ_WFE_WAIT_VALUE; - - return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, arg_b); + return cmdq_pkt_append_command(pkt, CMDQ_GET_ARG_C(CMDQ_WFE_OPTION), + CMDQ_GET_ARG_B(CMDQ_WFE_OPTION), event, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_CODE_WFE); } EXPORT_SYMBOL(cmdq_pkt_wfe); -int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u32 event) +int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event) { if (event >= CMDQ_MAX_EVENT) return -EINVAL; - return cmdq_pkt_append_command(pkt, CMDQ_CODE_WFE, event, - CMDQ_WFE_UPDATE); + return cmdq_pkt_append_command(pkt, CMDQ_GET_ARG_C(CMDQ_WFE_UPDATE), + CMDQ_GET_ARG_B(CMDQ_WFE_UPDATE), event, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_CODE_WFE); } EXPORT_SYMBOL(cmdq_pkt_clear_event); @@ -196,10 +236,25 @@ static int cmdq_pkt_finalize(struct cmdq_pkt *pkt) int err; /* insert EOC and generate IRQ for each command iteration */ - err = cmdq_pkt_append_command(pkt, CMDQ_CODE_EOC, 0, CMDQ_EOC_IRQ_EN); - + err = cmdq_pkt_append_command(pkt, CMDQ_GET_ARG_C(CMDQ_EOC_IRQ_EN), + CMDQ_GET_ARG_B(CMDQ_EOC_IRQ_EN), + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_CODE_EOC); + if (err < 0) + return err; /* JUMP to end */ - err |= cmdq_pkt_append_command(pkt, CMDQ_CODE_JUMP, 0, CMDQ_JUMP_PASS); + err = cmdq_pkt_append_command(pkt, CMDQ_GET_ARG_C(CMDQ_JUMP_PASS), + CMDQ_GET_ARG_B(CMDQ_JUMP_PASS), + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_IMMEDIATE_VALUE, + CMDQ_CODE_JUMP); return err; } diff --git a/include/linux/mailbox/mtk-cmdq-mailbox.h b/include/linux/mailbox/mtk-cmdq-mailbox.h index 911475da..f21801d 100644 --- a/include/linux/mailbox/mtk-cmdq-mailbox.h +++ b/include/linux/mailbox/mtk-cmdq-mailbox.h @@ -19,6 +19,8 @@ #define CMDQ_WFE_UPDATE BIT(31) #define CMDQ_WFE_WAIT BIT(15) #define CMDQ_WFE_WAIT_VALUE 0x1 +#define CMDQ_WFE_OPTION (CMDQ_WFE_UPDATE | CMDQ_WFE_WAIT | \ + CMDQ_WFE_WAIT_VALUE) /** cmdq event maximum */ #define CMDQ_MAX_EVENT 0x3ff diff --git a/include/linux/soc/mediatek/mtk-cmdq.h b/include/linux/soc/mediatek/mtk-cmdq.h index 4e88999..52f69c8 100644 --- a/include/linux/soc/mediatek/mtk-cmdq.h +++ b/include/linux/soc/mediatek/mtk-cmdq.h @@ -60,26 +60,26 @@ struct cmdq_client *cmdq_mbox_create(struct device *dev, int index, /** * cmdq_pkt_write() - append write command to the CMDQ packet * @pkt: the CMDQ packet - * @value: the specified target register value * @subsys: the CMDQ sub system code * @offset: register offset from CMDQ sub system + * @value: the specified target register value * * Return: 0 for success; else the error code is returned */ -int cmdq_pkt_write(struct cmdq_pkt *pkt, u32 value, u32 subsys, u32 offset); +int cmdq_pkt_write(struct cmdq_pkt *pkt, u8 subsys, u16 offset, u32 value); /** * cmdq_pkt_write_mask() - append write command with mask to the CMDQ packet * @pkt: the CMDQ packet - * @value: the specified target register value * @subsys: the CMDQ sub system code * @offset: register offset from CMDQ sub system + * @value: the specified target register value * @mask: the specified target register mask * * Return: 0 for success; else the error code is returned */ -int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, - u32 subsys, u32 offset, u32 mask); +int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u8 subsys, u16 offset, + u32 value, u32 mask); /** * cmdq_pkt_wfe() - append wait for event command to the CMDQ packet @@ -88,7 +88,7 @@ int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, * * Return: 0 for success; else the error code is returned */ -int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u32 event); +int cmdq_pkt_wfe(struct cmdq_pkt *pkt, u16 event); /** * cmdq_pkt_clear_event() - append clear event command to the CMDQ packet @@ -97,7 +97,7 @@ int cmdq_pkt_write_mask(struct cmdq_pkt *pkt, u32 value, * * Return: 0 for success; else the error code is returned */ -int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u32 event); +int cmdq_pkt_clear_event(struct cmdq_pkt *pkt, u16 event); /** * cmdq_pkt_flush_async() - trigger CMDQ to asynchronously execute the CMDQ -- 1.9.1