From nobody Fri Oct 3 03:15:49 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7F202EB868 for ; Mon, 8 Sep 2025 08:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757320076; cv=none; b=Omn7jpAcTR3anfnoPI0WtR0qPZIaGcUyRD2odeo3L6KGCT5kwdfvx7ktdJ3w2oqCVf2ClptC7oHlwMbiPYoptcHKHhcAE31AUfZhIdW2fOAOD3bem/zXSMYJ1E4oaNLXa45DeCxur9V1q3kFNOD8HRwjPmJERQeRQthwUfSdZV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757320076; c=relaxed/simple; bh=gCVnHvNqEFHEXeSZVUKwjtK61YZKpfeHrmYf0fEaxvU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rwfVYWo8BvJQbz2BjUdT95btF7r+SBb+n44dMtNwmxY8zXLk9/0y+2PEhCrllDo/ypJmdNskhBfk/KtAj7y/MPaeCxJJ/TnYsIQ/dAIcNeBaKxfMwawcpSmgDYzWmi+byvGMUexfWxn9w2B4go3vcV4psP9YbufIYPsVTxkGDY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=aIRXbtpG; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="aIRXbtpG" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5880K3BK018961 for ; Mon, 8 Sep 2025 08:27:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= jjYclTunnZKXJ32H+XLcYEQN4yrHDXTjo7er5qBOfnY=; b=aIRXbtpGW4XvPsDJ dJ5x9qfdn5dwVNcafQpsl1yGbhxRhdvK5kUkDqyFNmFTkZ4xnJktk8dKn/7esj9w 9SJZN3HX+rHQU+/D+VIh00addNvpMV5X3byqw6SWZkX7uaeEUZdjedLaicFcSjPo p24pviherZ5oP6edHc8LNx1Ns7NgloXdtvBPfNP9Qc7SIWOa/mnuRXujThTQTxTs 29SIUYeustbSzDkqF0hQoKoZshXVPhMBAC4+YIXY54oOm1cggoEQNWrEgA/BlbGI 9Bbb+pC1U3K/yZFmX8UAqPZsmrBA4r7cDV9EomWFRNeedAPJPyPoQxolVeACUXOq 3v1o1Q== Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 490e8a3q25-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 08 Sep 2025 08:27:53 +0000 (GMT) Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-77278d3789cso9199007b3a.1 for ; Mon, 08 Sep 2025 01:27:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757320073; x=1757924873; 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=jjYclTunnZKXJ32H+XLcYEQN4yrHDXTjo7er5qBOfnY=; b=ePlUin4o7n0+qAypZVslXzMLyODOjO4GITEEJ04rWzjdQvV4sp1JGzakNqPw/XB+IM hY5iRVX505PmZS/nGuHbh55wj6M+SYIAjQ5z73FKevQlYKxvNle5XWr3UWr58/Ve847k 5hjB7OOMmGal58lzdB4MNILJX9GZTZUy+fBL75f4g8PZPIxF/T7HngD2ByPWrNrVCOyc yUzj0hLLFuQBEJsF+8thi8lzpiN2CFODgPrYCCA0O26Emn7GZoJPvla5yZze5908Y5xt eKyiaF41nIN3HmL2s+VHG5PFGmBaDQCz72/PgwIekxGMK+VILGUSyBs5h7enuz2acsB5 oWKw== X-Forwarded-Encrypted: i=1; AJvYcCWhgB3T1+oxMZsL5y7pb+zB4Z8DeoLYw/3IO0MYiOVI2k5SmhWvCQ2kOMdI3Oyhl4iSJu+LDXGvJgbxE38=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2p7YuLEqEFdpq3lTllsDBxg4CUaJIy1CAJwemaQDtWmSI6pPe ieHAz6mIwBqwaLfvoTTGMZ+VAtXGHGx5ffJBBDeA6TV0bgxDCBQJO1zMix2ixjosf6dx6iu/MT8 TddJOg9+z0pQc9Mn8fdyA2R7C0LO97HMdWz3dCCGOZlp/EHo87kGIcqTlbQoq0Pjru7M= X-Gm-Gg: ASbGncsiZVeZ5mNethoasBEWsNul+bSMIZqmrZ1hi0TDLB4I5KlGQQpYr7KYBjicjJm SiQcQWalFi4NHS1EkI2Ja8g74no7oG+YeAFDv2DhxxD7YThX5H+6jYuWT/sUcKIvVFH9tpJR94F h5LvQYVn7aqtLd7IqVRFkKqHoxmcI8a65EcY+hKO55w/IF6NkUS2WAEhrvJhbChjUkc9cWyyPqT tHq62EAVibi2jFPcUyCMM5mkvnOwJ4t88Rhe0OPWQmq7wtp+oi9MnvsjMA3lG0P/F6OpjM2Hovu 5cp68hNfN5Fj+dhl4sUPOSwTFQqGXGtAV/8nFK8amvApd/u7vcivk5SP26snqPxT X-Received: by 2002:a05:6a00:1789:b0:772:48c5:c758 with SMTP id d2e1a72fcca58-7742dde288bmr10351117b3a.8.1757320072827; Mon, 08 Sep 2025 01:27:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFoeOm+Hk8wiYTptE53Toghc/9oJAHArmq3zNncrkwsrIFJw9O6pu1iKlKXuhALo7nzpDuBvg== X-Received: by 2002:a05:6a00:1789:b0:772:48c5:c758 with SMTP id d2e1a72fcca58-7742dde288bmr10351074b3a.8.1757320072269; Mon, 08 Sep 2025 01:27:52 -0700 (PDT) Received: from hu-akhilpo-hyd.qualcomm.com ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7722a26bc9csm29157523b3a.18.2025.09.08.01.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Sep 2025 01:27:51 -0700 (PDT) From: Akhil P Oommen Date: Mon, 08 Sep 2025 13:57:00 +0530 Subject: [PATCH v2 07/16] drm/msm/adreno: Add fenced regwrite support 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: quoted-printable Message-Id: <20250908-ifpc-support-v2-7-631b1080bf91@oss.qualcomm.com> References: <20250908-ifpc-support-v2-0-631b1080bf91@oss.qualcomm.com> In-Reply-To: <20250908-ifpc-support-v2-0-631b1080bf91@oss.qualcomm.com> To: Rob Clark , Sean Paul , Konrad Dybcio , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Marijn Suijten , David Airlie , Simona Vetter , Antonino Maniscalco , Neil Armstrong Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, Akhil P Oommen X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1757320036; l=6919; i=akhilpo@oss.qualcomm.com; s=20240726; h=from:subject:message-id; bh=gCVnHvNqEFHEXeSZVUKwjtK61YZKpfeHrmYf0fEaxvU=; b=6ZHRUDeA8ijXXKJL/1600PFk0POlc17dUEsZ7EHSLWucCjIqgHyYg4k91yZdJnKkXCUlbxpRG vkz9VG/iKKGA9n8yX/E/7sJcGMOhrRtvJz2q0/CjZcFRS1sR1PfhnRW X-Developer-Key: i=akhilpo@oss.qualcomm.com; a=ed25519; pk=lmVtttSHmAUYFnJsQHX80IIRmYmXA4+CzpGcWOOsfKA= X-Authority-Analysis: v=2.4 cv=H7Dbw/Yi c=1 sm=1 tr=0 ts=68be938a cx=c_pps a=m5Vt/hrsBiPMCU0y4gIsQw==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=yJojWOMRYYMA:10 a=EUspDBNiAAAA:8 a=YYoBuv6U7x1zitwOiNcA:9 a=QEXdDO2ut3YA:10 a=IoOABgeZipijB_acs4fv:22 X-Proofpoint-GUID: 6wByWo2XEnsNs64O2Cc3tOG2AjGI3cIi X-Proofpoint-ORIG-GUID: 6wByWo2XEnsNs64O2Cc3tOG2AjGI3cIi X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwOTA2MDAzOSBTYWx0ZWRfX0RjDyCghbesb Bu5BeFOl9EWwk0Q2/gc/Rf5kE7lbhJjfNm0Ypxuo6+xOlzJq4MOXzI8Dcp9KwAV7mtL250nha/b J2lJbnl8IvypE9L0hJVDqE048fiX2hUyRAfF8DNAxZZ1gS0cye8gwmL4oTvGnkaO45GXFp7YAGu e/OqkcirGUocf6zGnLh4Skj0BvXlggirKEpc+Ts/1JcSAnyWwD2f3fCtYAXnA2n6y3wVdBXYB+p +bfdGc2E1m4QZ+sX3GX2r1zfl4Lnr7mtzmU8rH5sp9U7XEEvNPDdZ9V8KDZRXeN2d1u9leHbUMn tuIt8RmDlZTudf20eVg82K3nZTFDops/ib+uZTG0NFUizSVrpKkJyJ0oHpRYQqmKv44NddaCLD5 130TEMuA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-08_02,2025-09-08_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 impostorscore=0 adultscore=0 phishscore=0 clxscore=1015 suspectscore=0 priorityscore=1501 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2509060039 There are some special registers which are accessible even when GX power domain is collapsed during an IFPC sleep. Accessing these registers wakes up GPU from power collapse and allow programming these registers without additional handshake with GMU. This patch adds support for this special register write sequence. Signed-off-by: Akhil P Oommen --- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 80 +++++++++++++++++++++++++++= +++- drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 1 + drivers/gpu/drm/msm/adreno/a6xx_preempt.c | 20 ++++---- 3 files changed, 90 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c b/drivers/gpu/drm/msm/ad= reno/a6xx_gpu.c index 45dd5fd1c2bfcb0a01b71a326c7d95b0f9496d99..a63dad80ef461da45d5c41a042e= d4f19d8282ef5 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c @@ -16,6 +16,84 @@ =20 #define GPU_PAS_ID 13 =20 +static bool fence_status_check(struct msm_gpu *gpu, u32 offset, u32 value,= u32 status, u32 mask) +{ + /* Success if !writedropped0/1 */ + if (!(status & mask)) + return true; + + udelay(10); + + /* Try to update fenced register again */ + gpu_write(gpu, offset, value); + + /* We can't do a posted write here because the power domain could be + * in collapse state. So use the heaviest barrier instead + */ + mb(); + return false; +} + +static int fenced_write(struct a6xx_gpu *a6xx_gpu, u32 offset, u32 value, = u32 mask) +{ + struct adreno_gpu *adreno_gpu =3D &a6xx_gpu->base; + struct msm_gpu *gpu =3D &adreno_gpu->base; + struct a6xx_gmu *gmu =3D &a6xx_gpu->gmu; + u32 status; + + gpu_write(gpu, offset, value); + + /* Nothing else to be done in the case of no-GMU */ + if (adreno_has_gmu_wrapper(adreno_gpu)) + return 0; + + /* We can't do a posted write here because the power domain could be + * in collapse state. So use the heaviest barrier instead + */ + mb(); + + if (!gmu_poll_timeout(gmu, REG_A6XX_GMU_AHB_FENCE_STATUS, status, + fence_status_check(gpu, offset, value, status, mask), 0, 1000)) + return 0; + + /* Try again for another 1ms before failing */ + gpu_write(gpu, offset, value); + mb(); + + if (!gmu_poll_timeout(gmu, REG_A6XX_GMU_AHB_FENCE_STATUS, status, + fence_status_check(gpu, offset, value, status, mask), 0, 1000)) { + /* + * The 'delay' warning is here because the pause to print this + * warning will allow gpu to move to power collapse which + * defeats the purpose of continuous polling for 2 ms + */ + dev_err_ratelimited(gmu->dev, "delay in fenced register write (0x%x)\n", + offset); + return 0; + } + + dev_err_ratelimited(gmu->dev, "fenced register write (0x%x) fail\n", + offset); + + return -ETIMEDOUT; +} + +int a6xx_fenced_write(struct a6xx_gpu *a6xx_gpu, u32 offset, u64 value, u3= 2 mask, bool is_64b) +{ + int ret; + + ret =3D fenced_write(a6xx_gpu, offset, lower_32_bits(value), mask); + if (ret) + return ret; + + if (!is_64b) + return 0; + + ret =3D fenced_write(a6xx_gpu, offset + 1, upper_32_bits(value), mask); + + return ret; +} + static inline bool _a6xx_check_idle(struct msm_gpu *gpu) { struct adreno_gpu *adreno_gpu =3D to_adreno_gpu(gpu); @@ -86,7 +164,7 @@ static void a6xx_flush(struct msm_gpu *gpu, struct msm_r= ingbuffer *ring) /* Update HW if this is the current ring and we are not in preempt*/ if (!a6xx_in_preempt(a6xx_gpu)) { if (a6xx_gpu->cur_ring =3D=3D ring) - gpu_write(gpu, REG_A6XX_CP_RB_WPTR, wptr); + a6xx_fenced_write(a6xx_gpu, REG_A6XX_CP_RB_WPTR, wptr, BIT(0), false); else ring->restore_wptr =3D true; } else { diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.h b/drivers/gpu/drm/msm/ad= reno/a6xx_gpu.h index 6e71f617fc3d0d564e51650dfed63a18f31042ac..e736c59d566b3fcf8c62a212494= e3b110c09caa9 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.h +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.h @@ -295,5 +295,6 @@ int a6xx_gpu_state_put(struct msm_gpu_state *state); =20 void a6xx_bus_clear_pending_transactions(struct adreno_gpu *adreno_gpu, bo= ol gx_off); void a6xx_gpu_sw_reset(struct msm_gpu *gpu, bool assert); +int a6xx_fenced_write(struct a6xx_gpu *gpu, u32 offset, u64 value, u32 mas= k, bool is_64b); =20 #endif /* __A6XX_GPU_H__ */ diff --git a/drivers/gpu/drm/msm/adreno/a6xx_preempt.c b/drivers/gpu/drm/ms= m/adreno/a6xx_preempt.c index 6a12a35dabff1e64aae8440c2a8c88f5feb4803e..10625ffbc4cfc26edc36efcf11d= bb4efd55ab3e0 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_preempt.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_preempt.c @@ -41,7 +41,7 @@ static inline void set_preempt_state(struct a6xx_gpu *gpu, } =20 /* Write the most recent wptr for the given ring into the hardware */ -static inline void update_wptr(struct msm_gpu *gpu, struct msm_ringbuffer = *ring) +static inline void update_wptr(struct a6xx_gpu *a6xx_gpu, struct msm_ringb= uffer *ring) { unsigned long flags; uint32_t wptr; @@ -51,7 +51,7 @@ static inline void update_wptr(struct msm_gpu *gpu, struc= t msm_ringbuffer *ring) if (ring->restore_wptr) { wptr =3D get_wptr(ring); =20 - gpu_write(gpu, REG_A6XX_CP_RB_WPTR, wptr); + a6xx_fenced_write(a6xx_gpu, REG_A6XX_CP_RB_WPTR, wptr, BIT(0), false); =20 ring->restore_wptr =3D false; } @@ -172,7 +172,7 @@ void a6xx_preempt_irq(struct msm_gpu *gpu) =20 set_preempt_state(a6xx_gpu, PREEMPT_FINISH); =20 - update_wptr(gpu, a6xx_gpu->cur_ring); + update_wptr(a6xx_gpu, a6xx_gpu->cur_ring); =20 set_preempt_state(a6xx_gpu, PREEMPT_NONE); =20 @@ -268,7 +268,7 @@ void a6xx_preempt_trigger(struct msm_gpu *gpu) */ if (!ring || (a6xx_gpu->cur_ring =3D=3D ring)) { set_preempt_state(a6xx_gpu, PREEMPT_FINISH); - update_wptr(gpu, a6xx_gpu->cur_ring); + update_wptr(a6xx_gpu, a6xx_gpu->cur_ring); set_preempt_state(a6xx_gpu, PREEMPT_NONE); spin_unlock_irqrestore(&a6xx_gpu->eval_lock, flags); return; @@ -302,13 +302,13 @@ void a6xx_preempt_trigger(struct msm_gpu *gpu) =20 spin_unlock_irqrestore(&ring->preempt_lock, flags); =20 - gpu_write64(gpu, - REG_A6XX_CP_CONTEXT_SWITCH_SMMU_INFO, - a6xx_gpu->preempt_smmu_iova[ring->id]); + a6xx_fenced_write(a6xx_gpu, + REG_A6XX_CP_CONTEXT_SWITCH_SMMU_INFO, a6xx_gpu->preempt_smmu_iova[ring->= id], + BIT(1), true); =20 - gpu_write64(gpu, + a6xx_fenced_write(a6xx_gpu, REG_A6XX_CP_CONTEXT_SWITCH_PRIV_NON_SECURE_RESTORE_ADDR, - a6xx_gpu->preempt_iova[ring->id]); + a6xx_gpu->preempt_iova[ring->id], BIT(1), true); =20 a6xx_gpu->next_ring =3D ring; =20 @@ -328,7 +328,7 @@ void a6xx_preempt_trigger(struct msm_gpu *gpu) set_preempt_state(a6xx_gpu, PREEMPT_TRIGGERED); =20 /* Trigger the preemption */ - gpu_write(gpu, REG_A6XX_CP_CONTEXT_SWITCH_CNTL, cntl); + a6xx_fenced_write(a6xx_gpu, REG_A6XX_CP_CONTEXT_SWITCH_CNTL, cntl, BIT(1)= , false); } =20 static int preempt_init_ring(struct a6xx_gpu *a6xx_gpu, --=20 2.50.1