Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp536319lqr; Wed, 5 Jun 2024 13:12:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCP6KP3i1UGJzO/qd8noZPzHBLzGhNS0sgQPC/0PdCIWeG8E1IHOPLCM38VQDqmqlWyKPV+54Ri3ZLfRL1y5EzvwC1Wdk3B1HiYFH1pg== X-Google-Smtp-Source: AGHT+IEeRnAcYBhb2BU8Fn55U+gHEFk2dOZg2hJM0njtlydpeGh19g+lWmYlEsmfJKiqF4zQI+m0 X-Received: by 2002:a05:6e02:1a83:b0:373:8d65:5e6 with SMTP id e9e14a558f8ab-374b1ee28d4mr35600985ab.3.1717618346121; Wed, 05 Jun 2024 13:12:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717618346; cv=pass; d=google.com; s=arc-20160816; b=RxgfBIZvxq4nStlG7senOfisLFxULC/auKelTmaveG4T1Dnzfs2vdoaZuuKyLxuMXd u1ORcVS8XwJIHJUANAH7+XbKsrrTI52oZWlr03ACJ9aT1XHsVkmPL8uQJK8FZ4CNYuhU l+t89aurv2M2vSGGur7dl7idKOmAAWhIXhmAsKhx+lrl3lMuo+Fk8qfmFRwHYTKtRUrT dLcUkbOyfQcqxzQubOD7Rvve+Rhs4Gsibq+ZN5zGjaXwgU+rA1ONPf38DRqITXYEnBcz CAu3U9r+hqMFubmCWrm/3A48qyzcSuD6VNEX1bTTeRAly++sU042nBAm8jftbcYNrqPv se5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=oK9nE6TjsLWeKUxIQ1Zr5Vx3uwM6i2437SAG5zcYC9A=; fh=YlaVY0GOsbrM2E2m6aJpIYT/J4ZSV/wrAoOlGs55FH0=; b=r35YU9h0+mRuMVrB4TbKrUyqMRgZyLB6BWRWg1D/c68ATUo43cYZyzOLaxUE7qeJUV f/0TLiKyJh3nX/Hbi6bmYoKuB5F3DOfTtvVQgbbx4DkxM+/SHZi4KDEZuYv9W1sIgqWI 7rNG/wJjZqaD9AVTjxT9STdbvxpHoOXwuVp3l233xbKgwrx8QTuCJNG0jki40Ew8RUUA bju5IpdoWJMDolBhFAcX/kOOz+YshWcAQlRNe/hBNm37FUmcyyqxeoLT2+vx7kIip1KH GD2DUQm1bpdPjg33z9zCyqqrQlWAB6S2ShFWQRsTx3GZunU7E/QIpFBgt2TJqQtdqOtQ 0UTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nN4rA05P; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-203157-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203157-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c355157b95si10498338a12.190.2024.06.05.13.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 13:12:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203157-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nN4rA05P; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-203157-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203157-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B41DD281A15 for ; Wed, 5 Jun 2024 20:12:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4DFC15ECF5; Wed, 5 Jun 2024 20:10:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nN4rA05P" Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2013E15DBD3 for ; Wed, 5 Jun 2024 20:10:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717618236; cv=none; b=d8tAZrKwpVKJ+7EDc2lb1g0x9JczKfA84mwRnj337iR0pGBmuUGg4iycGAsygrR19xneMKJGMZ1y+ihVr7RdFFQHBBiQ4ynb2Q/jCMA0P94XZsgWfV5bIAdTevHgGySBu8P7Kr0cMK1xs5RvuMIRMKs9xZOpGVAdAOM638Ufmmk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717618236; c=relaxed/simple; bh=NKlOWZ3llYIHAucM7hXLsZOaIDZ9ii5c/xLWD63q7Vk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NEUYMKxiRisALGVODxmLrftJD9r3bicG56togFnqxSbrikBGx+LonFY6qO6ZWb+XGSyp7FSTrFx0pX7KDK3tx4MjnMZM1cjEWXrpGOWEM7gJizBN1xuNkKusJq1AMQ0KZMQA5KlVIj5WlKmtAMI1tM18kY7l63byV2lz7xbzsI0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=nN4rA05P; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2e72224c395so1980881fa.3 for ; Wed, 05 Jun 2024 13:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717618232; x=1718223032; darn=vger.kernel.org; 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=oK9nE6TjsLWeKUxIQ1Zr5Vx3uwM6i2437SAG5zcYC9A=; b=nN4rA05PHq50hzRuK8RUF7/MfjVDZlkaiFUDVT0nI+oYZRzBNMHjwMMzRHGcuXvrLd 9jZbAYSDAOlAPXJMnVMRI/0znZx7NxPOfDsPGk/pjZG4FtGgMAYrKxu4utKen9ijQnoC BXtqC6O7KPwhWrRs3hR+cPtrUKO/mhajqV3GcmrgAP0/7elOGc7mn7xgJWHbfas9w4eP dZmjvNTWx9yMomBP5mWzuhNMsxhTPZu7B7feFV5CHc4V67u1dNE5Zw1bifW8L/vztgEy RQg/+kiaeCHXKFjLyYJoYu08uaQhjhZizA7PXDCaWsZBCWkVXL23ta/Nt8l7+aVhkNeJ tKUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717618232; x=1718223032; 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=oK9nE6TjsLWeKUxIQ1Zr5Vx3uwM6i2437SAG5zcYC9A=; b=iaOIfOra76JO1H3v0DqEqMrqAXuf9PNMw26G1Whb6tXZ0MvmRnIEFSzgo9ay0dO6TU NCOfMCL4ghsc4RezpgeYgN0IjgfMlBQcsyTYyA87FcaN+ufx+Q2ykedClLo4WM8rTKT5 ENvVB3GZnYHf2Aw8LJIvIAlfUOTHS/Z3JsbITlTTmtf3ovT1E6+RZM1sGFPabuBdHjDv Diudcs8CXuAnZ6HjHP6wuLdj0GndVN9Uu6tu2t0HwhZDvjhuCY4mhoyTS8KJ6TxMxWrQ m54otcrUNfCw0PcrF+UNgyxSAILZGhbAFvqxB4pwIrwWAl3KdyC55CO+9zuVboXlQSjv iJKQ== X-Forwarded-Encrypted: i=1; AJvYcCXyzra984G7pksR2a7dXCo2RdLz58FqYdDuqDil5USZ3Zs2bxUNfQYkCM/19o20Q4pWORBqvC3aQGfqo1WP8GU5ptYZHqIY6SCFn13U X-Gm-Message-State: AOJu0YwX2TmH5gKUuU9XOBVYJ7xnN7mDKVUfxMAYyCtCTrk44MW4/tFE FSysvlNCNaGytJeAVPiZmtjso/lhmttJptbvhteXqEwuyCgf24ISb+zfOT09ay0= X-Received: by 2002:a2e:9305:0:b0:2e9:8497:46ce with SMTP id 38308e7fff4ca-2eac7a71477mr20870721fa.46.1717618232370; Wed, 05 Jun 2024 13:10:32 -0700 (PDT) Received: from [127.0.1.1] (078088045245.garwolin.vectranet.pl. [78.88.45.245]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a31be4e36sm9717473a12.53.2024.06.05.13.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 13:10:32 -0700 (PDT) From: Konrad Dybcio Date: Wed, 05 Jun 2024 22:10:19 +0200 Subject: [PATCH v2 6/7] drm/msm/adreno: Redo the speedbin assignment Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240605-topic-smem_speedbin-v2-6-8989d7e3d176@linaro.org> References: <20240605-topic-smem_speedbin-v2-0-8989d7e3d176@linaro.org> In-Reply-To: <20240605-topic-smem_speedbin-v2-0-8989d7e3d176@linaro.org> To: Bjorn Andersson , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , Marijn Suijten , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, devicetree@vger.kernel.org, Neil Armstrong , Konrad Dybcio X-Mailer: b4 0.14-dev There is no need to reinvent the wheel for simple read-match-set logic. Make speedbin discovery and assignment generation independent. This implicitly removes the bogus 0x80 / BIT(7) speed bin on A5xx, which has no representation in hardware whatshowever. Signed-off-by: Konrad Dybcio --- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 34 -------------------- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 56 --------------------------------- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 51 ++++++++++++++++++++++++++---- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 3 -- 4 files changed, 45 insertions(+), 99 deletions(-) diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c index c003f970189b..eed6a2eb1731 100644 --- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c @@ -1704,38 +1704,6 @@ static const struct adreno_gpu_funcs funcs = { .get_timestamp = a5xx_get_timestamp, }; -static void check_speed_bin(struct device *dev) -{ - struct nvmem_cell *cell; - u32 val; - - /* - * If the OPP table specifies a opp-supported-hw property then we have - * to set something with dev_pm_opp_set_supported_hw() or the table - * doesn't get populated so pick an arbitrary value that should - * ensure the default frequencies are selected but not conflict with any - * actual bins - */ - val = 0x80; - - cell = nvmem_cell_get(dev, "speed_bin"); - - if (!IS_ERR(cell)) { - void *buf = nvmem_cell_read(cell, NULL); - - if (!IS_ERR(buf)) { - u8 bin = *((u8 *) buf); - - val = (1 << bin); - kfree(buf); - } - - nvmem_cell_put(cell); - } - - devm_pm_opp_set_supported_hw(dev, &val, 1); -} - struct msm_gpu *a5xx_gpu_init(struct drm_device *dev) { struct msm_drm_private *priv = dev->dev_private; @@ -1763,8 +1731,6 @@ struct msm_gpu *a5xx_gpu_init(struct drm_device *dev) a5xx_gpu->lm_leakage = 0x4E001A; - check_speed_bin(&pdev->dev); - nr_rings = 4; if (config->info->revn == 510) diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c index 3f84417ff027..d256e27ee581 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c @@ -2882,55 +2882,6 @@ static bool a6xx_progress(struct msm_gpu *gpu, struct msm_ringbuffer *ring) return progress; } -static u32 fuse_to_supp_hw(const struct adreno_info *info, u32 fuse) -{ - if (!info->speedbins) - return UINT_MAX; - - for (int i = 0; info->speedbins[i].fuse != SHRT_MAX; i++) - if (info->speedbins[i].fuse == fuse) - return BIT(info->speedbins[i].speedbin); - - return UINT_MAX; -} - -static int a6xx_set_supported_hw(struct adreno_gpu *adreno_gpu, - struct device *dev, - const struct adreno_info *info) -{ - u32 supp_hw; - u32 speedbin; - int ret; - - ret = adreno_read_speedbin(adreno_gpu, dev, &speedbin); - /* - * -ENOENT means that the platform doesn't support speedbin which is - * fine - */ - if (ret == -ENOENT) { - return 0; - } else if (ret) { - dev_err_probe(dev, ret, - "failed to read speed-bin. Some OPPs may not be supported by hardware\n"); - return ret; - } - - supp_hw = fuse_to_supp_hw(info, speedbin); - - if (supp_hw == UINT_MAX) { - DRM_DEV_ERROR(dev, - "missing support for speed-bin: %u. Some OPPs may not be supported by hardware\n", - speedbin); - supp_hw = BIT(0); /* Default */ - } - - ret = devm_pm_opp_set_supported_hw(dev, &supp_hw, 1); - if (ret) - return ret; - - return 0; -} - static const struct adreno_gpu_funcs funcs = { .base = { .get_param = adreno_get_param, @@ -3062,13 +3013,6 @@ struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) a6xx_llc_slices_init(pdev, a6xx_gpu, is_a7xx); - ret = a6xx_set_supported_hw(adreno_gpu, &pdev->dev, config->info); - if (ret) { - a6xx_llc_slices_destroy(a6xx_gpu); - kfree(a6xx_gpu); - return ERR_PTR(ret); - } - if (is_a7xx) ret = adreno_gpu_init(dev, pdev, adreno_gpu, &funcs_a7xx, 1); else if (adreno_has_gmu_wrapper(adreno_gpu)) diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c index 055072260b3d..8b2bc5f147e8 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c @@ -1060,8 +1060,8 @@ void adreno_gpu_ocmem_cleanup(struct adreno_ocmem *adreno_ocmem) adreno_ocmem->hdl); } -int adreno_read_speedbin(struct adreno_gpu *adreno_gpu, - struct device *dev, u32 *fuse) +static int adreno_read_speedbin(struct adreno_gpu *adreno_gpu, + struct device *dev, u32 *fuse) { u32 fcode; int ret; @@ -1095,6 +1095,46 @@ int adreno_read_speedbin(struct adreno_gpu *adreno_gpu, return 0; } +#define ADRENO_SPEEDBIN_FUSE_NODATA 0xFFFF /* Made-up large value, expected by mesa */ +static int adreno_set_speedbin(struct adreno_gpu *adreno_gpu, struct device *dev) +{ + const struct adreno_info *info = adreno_gpu->info; + u32 fuse = ADRENO_SPEEDBIN_FUSE_NODATA; + u32 supp_hw = UINT_MAX; + int ret; + + /* No speedbins defined for this GPU SKU => allow all defined OPPs */ + if (!info->speedbins) { + adreno_gpu->speedbin = ADRENO_SPEEDBIN_FUSE_NODATA; + return devm_pm_opp_set_supported_hw(dev, &supp_hw, 1); + } + + /* + * If a real error (not counting older devicetrees having no nvmem references) + * occurs when trying to get the fuse value, bail out. + */ + ret = adreno_read_speedbin(adreno_gpu, dev, &fuse); + if (ret) { + return ret; + } else if (fuse == ADRENO_SPEEDBIN_FUSE_NODATA) { + /* The info struct has speedbin data, but the DT is too old => allow all OPPs */ + DRM_DEV_INFO(dev, "No GPU speed bin fuse, please update your device tree\n"); + return devm_pm_opp_set_supported_hw(dev, &supp_hw, 1); + } + + adreno_gpu->speedbin = fuse; + + /* Traverse the known speedbins */ + for (int i = 0; info->speedbins[i].fuse != SHRT_MAX; i++) { + if (info->speedbins[i].fuse == fuse) { + supp_hw = BIT(info->speedbins[i].speedbin); + return devm_pm_opp_set_supported_hw(dev, &supp_hw, 1); + } + } + + return dev_err_probe(dev, -EINVAL, "Unknown speed bin fuse value: 0x%x\n", fuse); +} + int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, struct adreno_gpu *adreno_gpu, const struct adreno_gpu_funcs *funcs, int nr_rings) @@ -1104,7 +1144,6 @@ int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, struct msm_gpu_config adreno_gpu_config = { 0 }; struct msm_gpu *gpu = &adreno_gpu->base; const char *gpu_name; - u32 speedbin; int ret; adreno_gpu->funcs = funcs; @@ -1131,9 +1170,9 @@ int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev, devm_pm_opp_set_clkname(dev, "core"); } - if (adreno_read_speedbin(adreno_gpu, dev, &speedbin) || !speedbin) - speedbin = 0xffff; - adreno_gpu->speedbin = speedbin; + ret = adreno_set_speedbin(adreno_gpu, dev); + if (ret) + return ret; gpu_name = devm_kasprintf(dev, GFP_KERNEL, "%"ADRENO_CHIPID_FMT, ADRENO_CHIPID_ARGS(config->chip_id)); diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.h b/drivers/gpu/drm/msm/adreno/adreno_gpu.h index 8f2b70eaf6ad..30e8b9919adb 100644 --- a/drivers/gpu/drm/msm/adreno/adreno_gpu.h +++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.h @@ -524,9 +524,6 @@ int adreno_fault_handler(struct msm_gpu *gpu, unsigned long iova, int flags, struct adreno_smmu_fault_info *info, const char *block, u32 scratch[4]); -int adreno_read_speedbin(struct adreno_gpu *adreno_gpu, - struct device *dev, u32 *speedbin); - /* * For a5xx and a6xx targets load the zap shader that is used to pull the GPU * out of secure mode -- 2.43.0