From patchwork Thu Feb 23 10:52:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 60903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp247676wrd; Thu, 23 Feb 2023 02:57:52 -0800 (PST) X-Google-Smtp-Source: AK7set/6r77IGL5VmUAZgM9tjswCBzhgWeUL+SCzfa8i/ndGnyO/47gErsXYOzcnuQ8vsTEJNzQx X-Received: by 2002:a17:906:739d:b0:8aa:f573:4ff8 with SMTP id f29-20020a170906739d00b008aaf5734ff8mr16626541ejl.4.1677149872153; Thu, 23 Feb 2023 02:57:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677149872; cv=none; d=google.com; s=arc-20160816; b=K0YocP9rn3qNIZ4Fea2UiTJYctlq5rJQ10skH+CjkMPb5Cm1qXo5JJ7CqWMP4/8Z/O mnUVL0wuWONOKx0VrNjO08HCroTIOrSdwOIJ27ShVin3x/RLouuufh3+23DZ8YpKlr9c iU0tGfoyYY3G3yuooBps6B7bdN8h9A+OjAdtQTT2qaCEgbDhCiTRFPu3af3TFA323OOv hSSP9VZa4MbFsoQx5MQs5NLAUaE7FgbypkesPWJBZ3lESmBhcQjs7wMvEHQOkOBjl8sv wTbPzgH9ATcxL4fn0E8BJa6jCnZ13HfgL/fh6SEBSksbXtykd5Wh5VR+ZcN8FDSBRyKx 3rmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=c856FNZ6Lhd5u8jT462zPqnplUQDu/X42aKd4/VDH9g=; b=uGJFEtjI3QD/SILfuWQVk3sDu1rttH0dTEuWFw3rlS3K2GrqYlWQFf+KPrHJ5jsHxk lHXBLlD851GMNBbVgvPPyK8S5fCBKdIqCMqIXOy8C+qoGDsa57iUSH14p17dOJzfWZ8M eZ4i6auhZVzwPdybKU6FzgCT/scH0O4i6c0sMEsbVC/LRN7nAIyleiqs/fjyrdGH3Kfm gExoJ5B+qFUTztXOy39zE/HkVc1GNSqv5ohaUocWG4r60pZHg8/ObdvUXDFwMDMt/zlJ 2+hjIUfDuhf3wR5yLNtm3WBBLMARF5yFUButuWVkplVIH/KtoeGFHn/uSOrfguKdLrSe 2h+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i+SHoYDu; 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=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a17090791c600b008c2c9a6fb38si15395834ejz.266.2023.02.23.02.57.28; Thu, 23 Feb 2023 02:57:52 -0800 (PST) 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=@linaro.org header.s=google header.b=i+SHoYDu; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233351AbjBWKw1 (ORCPT + 99 others); Thu, 23 Feb 2023 05:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233851AbjBWKwL (ORCPT ); Thu, 23 Feb 2023 05:52:11 -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 8A1E15A3AE for ; Thu, 23 Feb 2023 02:52:10 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id s20so12983979lfb.11 for ; Thu, 23 Feb 2023 02:52:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=c856FNZ6Lhd5u8jT462zPqnplUQDu/X42aKd4/VDH9g=; b=i+SHoYDu2CxmzFsvpNyj8FuuX25oBODVO7YQBk4ALkNydlbwUNuiWSn2f2CSEkMM20 GYCDhYxFm4yDObXLeDN+CcKB9KjYhBpH+xjEp6XznKwW4U27HjLX/pBjjn1nzxBktyQi 8IDlkKcRwCSXCCFY6KgyEdg/VjEiof8Z57j5fM4Lgpd64qOljDmAfxGWFGBJWnvEBOCd nHds+xKzZaZ+Mjcdiqq8R/4HwuI692uDlbrLrTvC8/XXusCjda9ZvNhgWFj/Di3PUJkX hSIQD1VQMQgsa8z8Gtwddtgfd3JGanEvWAzeqgdjycAY9zP7YFslnhCzjOZp6R22alQ9 JCxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c856FNZ6Lhd5u8jT462zPqnplUQDu/X42aKd4/VDH9g=; b=l3s/KAzRZstlndbBBDd/iwMBxkae/zpwQXTOEXr+Vc5iNF4jYI1Q+aZhkZIc6gB7lA hDPsWP7r03YD8dxsUoAxWpSrytZX1TdvLDbEreNo2vr/ETuz0XXY22aavDVZJ9Yrm02I kPuh7ydfy154PrvfwCXJrYeBT9oO2hQ+s/M/SF13DFzVNjAp5R/lE8NVDqMARzwfH8c2 gCuow09ymEeDSqD+CvhHNU+s+7D+OA3b2wakL7h9u1pB4euygqtCl1TEANQKeccM89jx CZUUxMWCxm5rpehrP+1Zo5vt3p7sfseAMSqaSnZQJQkE82nfw691AWFniwDRooGGIp38 6DQg== X-Gm-Message-State: AO0yUKXV+gqFTLg/tRD557kBsuyyvD3BUyB2MTzdpomXExegPAYlp7ip V5dzdn8jgdS0F6PkTr+BzUuHSg== X-Received: by 2002:ac2:43b4:0:b0:4d4:d7fb:d13 with SMTP id t20-20020ac243b4000000b004d4d7fb0d13mr3426578lfl.35.1677149528877; Thu, 23 Feb 2023 02:52:08 -0800 (PST) Received: from [192.168.1.101] (abxi151.neoplus.adsl.tpnet.pl. [83.9.2.151]) by smtp.gmail.com with ESMTPSA id m25-20020ac24ad9000000b004cf07a0051csm262304lfp.228.2023.02.23.02.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 02:52:08 -0800 (PST) From: Konrad Dybcio Date: Thu, 23 Feb 2023 11:52:00 +0100 Subject: [PATCH v3 4/7] drm/msm/a2xx: Implement .gpu_busy MIME-Version: 1.0 Message-Id: <20230223-topic-opp-v3-4-5f22163cd1df@linaro.org> References: <20230223-topic-opp-v3-0-5f22163cd1df@linaro.org> In-Reply-To: <20230223-topic-opp-v3-0-5f22163cd1df@linaro.org> To: Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , David Airlie , Daniel Vetter Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1677149522; l=2182; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=M4GtniFH7Z74oP+C1wfVcdO+1YLmUE+S93nPkBb/ZUE=; b=A2D3TmwvTtxWv0uaGt4JkpWCn10VLe5vtr+8DwgiZJRVaOxktLKqoQFk0HZPITd+ExjXUz1QU95S 18RI7cwQD1ckEytf8zZPcel2UNNBKTsg0CC4mdBmGnGNEy0o5Nak X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1758619104146646663?= X-GMAIL-MSGID: =?utf-8?q?1758619104146646663?= Implement gpu_busy based on the downstream msm-3.4 code [1]. This allows us to use devfreq on this old old old hardware! [1] https://github.com/LineageOS/android_kernel_sony_apq8064/blob/lineage-16.0/drivers/gpu/msm/adreno_a2xx.c#L1975 Reviewed-by: Dmitry Baryshkov Signed-off-by: Konrad Dybcio --- drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/gpu/drm/msm/adreno/a2xx_gpu.c b/drivers/gpu/drm/msm/adreno/a2xx_gpu.c index c67089a7ebc1..104bdf28cdaf 100644 --- a/drivers/gpu/drm/msm/adreno/a2xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a2xx_gpu.c @@ -481,6 +481,31 @@ a2xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev) return aspace; } +/* While the precise size of this field is unknown, it holds at least these three values.. */ +static u64 a2xx_gpu_busy(struct msm_gpu *gpu, unsigned long *out_sample_rate) +{ + u64 busy_cycles; + + /* Freeze the counter */ + gpu_write(gpu, REG_A2XX_CP_PERFMON_CNTL, PERF_STATE_FREEZE); + + busy_cycles = gpu_read64(gpu, REG_A2XX_RBBM_PERFCOUNTER1_LO); + + /* Reset the counter */ + gpu_write(gpu, REG_A2XX_CP_PERFMON_CNTL, PERF_STATE_RESET); + + /* Re-enable the performance monitors */ + gpu_rmw(gpu, REG_A2XX_RBBM_PM_OVERRIDE2, + A2XX_RBBM_PM_OVERRIDE2_DEBUG_PERF_SCLK_PM_OVERRIDE, + A2XX_RBBM_PM_OVERRIDE2_DEBUG_PERF_SCLK_PM_OVERRIDE); + gpu_write(gpu, REG_A2XX_RBBM_PERFCOUNTER1_SELECT, 1); + gpu_write(gpu, REG_A2XX_CP_PERFMON_CNTL, PERF_STATE_ENABLE); + + *out_sample_rate = clk_get_rate(gpu->core_clk); + + return busy_cycles; +} + static u32 a2xx_get_rptr(struct msm_gpu *gpu, struct msm_ringbuffer *ring) { ring->memptrs->rptr = gpu_read(gpu, REG_AXXX_CP_RB_RPTR); @@ -502,6 +527,7 @@ static const struct adreno_gpu_funcs funcs = { #if defined(CONFIG_DEBUG_FS) || defined(CONFIG_DEV_COREDUMP) .show = adreno_show, #endif + .gpu_busy = a2xx_gpu_busy, .gpu_state_get = a2xx_gpu_state_get, .gpu_state_put = adreno_gpu_state_put, .create_address_space = a2xx_create_address_space,