From patchwork Tue Nov 8 04:26:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1701106 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=dE9Px+bU; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5w6S45qtz23lT for ; Tue, 8 Nov 2022 15:26:55 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1osGCD-00033e-Kc; Tue, 08 Nov 2022 04:26:45 +0000 Received: from mail-pl1-f182.google.com ([209.85.214.182]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1osGC8-00030b-Sv for kernel-team@lists.ubuntu.com; Tue, 08 Nov 2022 04:26:41 +0000 Received: by mail-pl1-f182.google.com with SMTP id io19so13107771plb.8 for ; Mon, 07 Nov 2022 20:26:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=2FPoScrubb2DpcBHLHfCSq8dJRywubicMKcm4OKEOBs=; b=dE9Px+bUJjopWnOBU4fexz3/23MCSAik8clYn2d6LoBWsuv6au1GaXP6g6YqbRpVQy C5lEjlMGpeEF2i/bNk0TopNn021XDP0gTzQmJHn7VIpj/Lhl4OyKWB5mVm8OtKDzSEkh YgGgX8HrJ7koZUl5v6aEHxdh+prV83bRRO8RFlFy9OPUBMxP0s1nuvrMkuYcAbk0HAHM MiUpeMuABxi221QdV5rEoJGvJxRAEH2Wi/gUTxzYXcKfg0DgIEVF3kj+Uc2SGOHZtLwB Xo1MPQTGT8hgWFXooK6/nEfDTc+se9ZAzrYs/sS5fSzzs/A7LrcBpvO1ApAhUgGdeBjl 32rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=2FPoScrubb2DpcBHLHfCSq8dJRywubicMKcm4OKEOBs=; b=I6nCvUH+hFn+i5ZjuKjDWJUJufVPMpv+n0crJ6H+ieoHZ1wo7hgwqnhphIT+T7VFM2 huGwNqwV9LBPrz5lfNLPU0UQ4VSq5L9OtuOc2VNURXTum0rJ+H3ov11f29G7oiECt6I/ Jl2kT+XadTjUN0JdZzFk6hvkFoT+RrD0e68eaR50JAV2LFbX5i8K0gdXXVwERe4kGQgd OczZR4iYF6lXMZu4O/6Wo3ak33E4JPx+hdHdiD9kyCHkIp9gV/oZvfwW0lKzXmZfBobN u+I/AU5I0WSJb1nc+X3ufB4r4BHo9n+FRKTyoIQjKjuL4md16pbpWDX691olmBW462g5 ZBVg== X-Gm-Message-State: ACrzQf2iY75xupXgiZL0kZS5iEm2nNhGUL3V8CnfKrRewpcOl/1lU3kd lAf/y7ckRj53rZ7AE0R1E8UWtl0c3w8= X-Google-Smtp-Source: AMsMyM7ebRW/J5bJkoqZk2kjLytfEVd2wawVWtmh1U6Z0Ds9/bnu4F8G7jXcyqoTzKEXiLNubo1zNA== X-Received: by 2002:a17:90b:38c3:b0:213:5ccc:9736 with SMTP id nn3-20020a17090b38c300b002135ccc9736mr54341443pjb.196.1667881598935; Mon, 07 Nov 2022 20:26:38 -0800 (PST) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id e13-20020a17090301cd00b0018855a22ccfsm5822541plh.91.2022.11.07.20.26.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 20:26:38 -0800 (PST) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/6][SRU][OEM-5.17] drm: Add DRM-managed mutex_init() Date: Tue, 8 Nov 2022 12:26:26 +0800 Message-Id: <20221108042634.24176-2-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221108042634.24176-1-acelan.kao@canonical.com> References: <20221108042634.24176-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.182; envelope-from=acelan@gmail.com; helo=mail-pl1-f182.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Thomas Zimmermann BugLink: https://launchpad.net/bugs/1995573 Add drmm_mutex_init(), a helper that provides managed mutex cleanup. The mutex will be destroyed with the final reference of the DRM device. Signed-off-by: Thomas Zimmermann Reviewed-by: Jocelyn Falempe Reviewed-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20220502142514.2174-2-tzimmermann@suse.de (cherry picked from commit e13f13e039dc8f31168b5569120a7658035c80ee) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/gpu/drm/drm_managed.c | 27 +++++++++++++++++++++++++++ include/drm/drm_managed.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/drivers/gpu/drm/drm_managed.c b/drivers/gpu/drm/drm_managed.c index 37d7db6223be..4cf214de50c4 100644 --- a/drivers/gpu/drm/drm_managed.c +++ b/drivers/gpu/drm/drm_managed.c @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -262,3 +263,29 @@ void drmm_kfree(struct drm_device *dev, void *data) free_dr(dr_match); } EXPORT_SYMBOL(drmm_kfree); + +static void drmm_mutex_release(struct drm_device *dev, void *res) +{ + struct mutex *lock = res; + + mutex_destroy(lock); +} + +/** + * drmm_mutex_init - &drm_device-managed mutex_init() + * @dev: DRM device + * @lock: lock to be initialized + * + * Returns: + * 0 on success, or a negative errno code otherwise. + * + * This is a &drm_device-managed version of mutex_init(). The initialized + * lock is automatically destroyed on the final drm_dev_put(). + */ +int drmm_mutex_init(struct drm_device *dev, struct mutex *lock) +{ + mutex_init(lock); + + return drmm_add_action_or_reset(dev, drmm_mutex_release, lock); +} +EXPORT_SYMBOL(drmm_mutex_init); diff --git a/include/drm/drm_managed.h b/include/drm/drm_managed.h index b45c6fbf53ac..359883942612 100644 --- a/include/drm/drm_managed.h +++ b/include/drm/drm_managed.h @@ -8,6 +8,7 @@ #include struct drm_device; +struct mutex; typedef void (*drmres_release_t)(struct drm_device *dev, void *res); @@ -104,4 +105,6 @@ char *drmm_kstrdup(struct drm_device *dev, const char *s, gfp_t gfp); void drmm_kfree(struct drm_device *dev, void *data); +int drmm_mutex_init(struct drm_device *dev, struct mutex *lock); + #endif From patchwork Tue Nov 8 04:26:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1701109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=TGINZ8dY; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5w6S3rM9z1yqS for ; Tue, 8 Nov 2022 15:26:55 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1osGCC-00032i-En; Tue, 08 Nov 2022 04:26:44 +0000 Received: from mail-pj1-f42.google.com ([209.85.216.42]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1osGCA-00031K-Vm for kernel-team@lists.ubuntu.com; Tue, 08 Nov 2022 04:26:43 +0000 Received: by mail-pj1-f42.google.com with SMTP id c15-20020a17090a1d0f00b0021365864446so12295470pjd.4 for ; Mon, 07 Nov 2022 20:26:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=2UjJga3iG09x2dzbTJsrse6yF+FiRqjU/pxKP0DXtjQ=; b=TGINZ8dYgQ/6DRe53h7dHqQc0gxSl2o3EYGTTOAnL4i98kx77XL2ybxrTcc01CB7mH 6iG0fmZPQzW2aHYR0/za64pEG6kxRP4OlRrZoJfBHGYhtejjBmIxqzsTD0/jfYmUEtMb 4Zc5iyMGOtfVB6wKTas8R5eDCmxPZu2Y74f7Fzk95YxC2MeL0qU4BY/mtllrt+OG4L9j pRVmWsSsJKS8tYivrvLPWvXMIB+41hS2VT/vQVsKEujhG3ZKUPKUczGqDCcW2II16gBJ bIZnxnbem0RZyxp21TgJPnoILVxSGp1wmDtXVuTGxFBhbRWws4tVByoCwbFZeyS7o9yp 9uuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=2UjJga3iG09x2dzbTJsrse6yF+FiRqjU/pxKP0DXtjQ=; b=CaL38GfYxQiKRVvzXihpbUng6T9lx+xub+mUbbPHAAPYeUTlzCb/el181u2uXm+83W UCYbM3S5ZHHAHnpi1djzFZB4XVnUiCkMJXj0mTYFGq6i0PoTWNTrWXrIocKzTrNw9n7r PZjRM3DvA4JI3ainZIPdNbKfLyPxYTQ9FPPDb/iwabwok/hpMMSPMlOpeVGuejH3KBp9 bCQfoHPxBCUQYtFzJzyAQX6Ze3bYVqmaQmob1oLMKUeSKlMKFM0MJbNeTqlyAGEmnINq mXdEO0/cG6N1n8NIjUSPjt7vGpgCYksMP/GyRHxa60tY2lSXcs0o5XXuZM/S/tfUgkMq lq5w== X-Gm-Message-State: ACrzQf27m+93IbbJw2AGxrM+ly8k03lUG859kKUdPdEuLUxAE421mH6j FIrs80oDcN9dQHTetK2Km+xSXT1nhDg= X-Google-Smtp-Source: AMsMyM4nzSjfd3pD060/7SZbbQ0+3dfBffSEx0OF7KBGgC6zeWCw5wsiMUkC6ba8RtJmIKj3De3x9g== X-Received: by 2002:a17:903:2442:b0:186:ef89:7b41 with SMTP id l2-20020a170903244200b00186ef897b41mr53192933pls.164.1667881600972; Mon, 07 Nov 2022 20:26:40 -0800 (PST) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id b4-20020a170903228400b00178b77b7e71sm5810853plh.188.2022.11.07.20.26.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 20:26:40 -0800 (PST) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/6][SRU][OEM-5.17] drm/mgag200: Protect concurrent access to I/O registers with lock Date: Tue, 8 Nov 2022 12:26:27 +0800 Message-Id: <20221108042634.24176-3-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221108042634.24176-1-acelan.kao@canonical.com> References: <20221108042634.24176-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.216.42; envelope-from=acelan@gmail.com; helo=mail-pj1-f42.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Thomas Zimmermann BugLink: https://launchpad.net/bugs/1995573 Add a mutex lock to protect concurrent access to I/O registers against each other. This happens between invocation of commit- tail functions and get-mode operations. Both with use the CRTC index registers MGA1064_GEN_IO_DATA and MGA1064_GEN_IO_CTL. Concurrent access can lead to failed mode-setting operations. v2: * fix typo in commit description (Jocelyn) * add comment to explain rmmio_lock Signed-off-by: Thomas Zimmermann Reviewed-by: Jocelyn Falempe Acked-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20220502142514.2174-4-tzimmermann@suse.de (backported from commit 931e3f3a0e997c41eafbc88e4fc07ba9fef28f29) (Fix the cherry pick failure due to header files conflict) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/gpu/drm/mgag200/mgag200_drv.c | 6 ++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_mode.c | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c index 740108a006ba..c463d27562c3 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.c +++ b/drivers/gpu/drm/mgag200/mgag200_drv.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "mgag200_drv.h" @@ -64,6 +65,11 @@ static int mgag200_regs_init(struct mga_device *mdev) struct pci_dev *pdev = to_pci_dev(dev->dev); u32 option, option2; u8 crtcext3; + int ret; + + ret = drmm_mutex_init(dev, &mdev->rmmio_lock); + if (ret) + return ret; switch (mdev->type) { case G200_PCI: diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.h b/drivers/gpu/drm/mgag200/mgag200_drv.h index 4368112023f7..a18384c41fc4 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.h +++ b/drivers/gpu/drm/mgag200/mgag200_drv.h @@ -213,6 +213,7 @@ struct mga_device { struct drm_device base; unsigned long flags; + struct mutex rmmio_lock; /* Protects access to rmmio */ resource_size_t rmmio_base; resource_size_t rmmio_size; void __iomem *rmmio; diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index cd9ba13ad5fc..92d37bb125ab 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -881,6 +881,14 @@ mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, .y2 = fb->height, }; + /* + * Concurrent operations could possibly trigger a call to + * drm_connector_helper_funcs.get_modes by trying to read the + * display modes. Protect access to I/O registers by acquiring + * the I/O-register lock. + */ + mutex_lock(&mdev->rmmio_lock); + if (mdev->type == G200_WB || mdev->type == G200_EW3) mgag200_g200wb_hold_bmc(mdev); @@ -904,6 +912,8 @@ mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, mgag200_enable_display(mdev); mgag200_handle_damage(mdev, fb, &fullscreen, &shadow_plane_state->data[0]); + + mutex_unlock(&mdev->rmmio_lock); } static void @@ -963,8 +973,12 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, if (!fb) return; + mutex_lock(&mdev->rmmio_lock); + if (drm_atomic_helper_damage_merged(old_state, state, &damage)) mgag200_handle_damage(mdev, fb, &damage, &shadow_plane_state->data[0]); + + mutex_unlock(&mdev->rmmio_lock); } static struct drm_crtc_state * From patchwork Tue Nov 8 04:26:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1701108 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=KjuVOKCy; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5w6S4P56z23mJ for ; Tue, 8 Nov 2022 15:26:54 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1osGCE-00034S-Pm; Tue, 08 Nov 2022 04:26:46 +0000 Received: from mail-pl1-f182.google.com ([209.85.214.182]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1osGCC-0002zC-ON for kernel-team@lists.ubuntu.com; Tue, 08 Nov 2022 04:26:44 +0000 Received: by mail-pl1-f182.google.com with SMTP id v17so13135303plo.1 for ; Mon, 07 Nov 2022 20:26:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=p9aTvhGQ7NKcyKetcfpiLMyi2WUNhAxo0OM2ZO6NihY=; b=KjuVOKCyrFcHwmmcmXyCtsCkRfzFGt7Mykxm4T4Kd3/dfQ27iPOra7nqrDpHCjY15E pKSc8hrAMDRsZpUcEHZtDiewgjc9MDW7vz2mu9vXY14wzyr4VT0A04kVkOfMYikFwGO5 vs4ILjGBwlGdBSVodAzbSzrAt/ra7Gflp4mUqApWkSIgIbUDcX3WNOfr7oHfRmLsl3KT xVDbUcLiv7JgNv/gyEFiyvFaInhsTjEosfEFysHTUXNsYRa3PMpW4/JNj96PUkzETMOg AoFHF/av3oz1Tmt6e4drOefQquJ4O8Em8w87nZ4OGWCGHg89GNrRV/sx+bcnTpKm//IJ X97w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=p9aTvhGQ7NKcyKetcfpiLMyi2WUNhAxo0OM2ZO6NihY=; b=WkDF4ScHWrQWVe6GtRSciF7Cu36+WWCcmlzJ3s+TJFlRCno/Jttk2w7vXOULsfP3g7 8HIdtdMbkeWUpdJeCwRRjrw3CcUPM6n4k7k/uyy8xiTsHoMMiILSYgTWAaproi060F/g b+gUneE+b0TJT24TCI+Z6BuOmZr3mlJYp/phW1mUuLvUWjSPgrm154F0Vtuw5gdhpS6D xt+wyLw0Uq2Wzm5yYQiSXocSgk0JV3UcWqe9r1PZCURph0jCe7b2LNHWkIN3Muz5u0qJ qp5HnUc7BwirJ3+HGJT55jHAkkALj/VD/fPGRKfBY3qiV4r0W8iGNlRBegX+nv0neSqB wlVg== X-Gm-Message-State: ACrzQf1DbZSHJ79y0kLcLM5vTg/j+pngt+XealyHPy8Mjd54gUtIo1mV FaNm4rsF8BITdf4189oIllt1kkwUl/0= X-Google-Smtp-Source: AMsMyM5kxsMX6QVAAqAgfPrFkGd8In429fJOj3RwlHps62cDCi1rjbO4E4ZMk5JLwMXopHZG2SUTNQ== X-Received: by 2002:a17:902:b94c:b0:178:336f:13d6 with SMTP id h12-20020a170902b94c00b00178336f13d6mr55232758pls.64.1667881603593; Mon, 07 Nov 2022 20:26:43 -0800 (PST) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id u15-20020a170903124f00b0016d72804664sm5786763plh.205.2022.11.07.20.26.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 20:26:43 -0800 (PST) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/6][SRU][OEM-5.17] drm/mgag200: Acquire I/O lock while reading EDID Date: Tue, 8 Nov 2022 12:26:28 +0800 Message-Id: <20221108042634.24176-4-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221108042634.24176-1-acelan.kao@canonical.com> References: <20221108042634.24176-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.182; envelope-from=acelan@gmail.com; helo=mail-pl1-f182.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Thomas Zimmermann BugLink: https://launchpad.net/bugs/1995573 DDC operation conflicts with concurrent mode setting. Acquire the driver's I/O lock in get_modes to prevent this. This change should have been part of commit 931e3f3a0e99 ("drm/mgag200: Protect concurrent access to I/O registers with lock"), but apparently got lost somewhere. v3: * fix commit message to say 'drm/mgag200' (Jocelyn) Signed-off-by: Thomas Zimmermann Fixes: 931e3f3a0e99 ("drm/mgag200: Protect concurrent access to I/O registers with lock") Reviewed-by: Jocelyn Falempe Tested-by: Jocelyn Falempe Cc: Thomas Zimmermann Cc: Jocelyn Falempe Cc: Daniel Vetter Cc: Dave Airlie Cc: dri-devel@lists.freedesktop.org Link: https://patchwork.freedesktop.org/patch/msgid/20220516134343.6085-2-tzimmermann@suse.de (cherry picked from commit 5913ab941d6ea782e841234c76958c6872ea752d) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/gpu/drm/mgag200/mgag200_mode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index 92d37bb125ab..4bdc1fc388a9 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -667,16 +667,26 @@ static void mgag200_disable_display(struct mga_device *mdev) static int mga_vga_get_modes(struct drm_connector *connector) { + struct mga_device *mdev = to_mga_device(connector->dev); struct mga_connector *mga_connector = to_mga_connector(connector); struct edid *edid; int ret = 0; + /* + * Protect access to I/O registers from concurrent modesetting + * by acquiring the I/O-register lock. + */ + mutex_lock(&mdev->rmmio_lock); + edid = drm_get_edid(connector, &mga_connector->i2c->adapter); if (edid) { drm_connector_update_edid_property(connector, edid); ret = drm_add_edid_modes(connector, edid); kfree(edid); } + + mutex_unlock(&mdev->rmmio_lock); + return ret; } From patchwork Tue Nov 8 04:26:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1701110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=OLr11d1U; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5w6W0BpPz1yqS for ; Tue, 8 Nov 2022 15:26:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1osGCJ-00039N-2A; Tue, 08 Nov 2022 04:26:51 +0000 Received: from mail-pg1-f173.google.com ([209.85.215.173]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1osGCG-00034V-Ai for kernel-team@lists.ubuntu.com; Tue, 08 Nov 2022 04:26:48 +0000 Received: by mail-pg1-f173.google.com with SMTP id o13so3064334pgu.7 for ; Mon, 07 Nov 2022 20:26:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=eGzCMS6R4Dr+CfIU2e0VuZVQqoUS8od2pa/KcRcmtTY=; b=OLr11d1U2YSnlRUISGliUGD5Z2WPzO/aJg6b7Qp4pwZVKKB7zDL6to1FRrwTIRBwZU UnY3LkqeyznutFA/++f7FErGzZneCsTZMJE1xMb5UrfhG1NibSXWR9Lzsbb/+scwNTpj sKTySL86mKltMkV+J5NwB0p+2xQrCclX0q0MrLzmRdhAc0DJdEDeDJrnNp0M+ihDl2JB t3kRUaJOJjXoDnI7oJEbZO6mJCXzbELQgoyQ+dFOmEi/IJsMW119VjoXCA5VAJDlH47j UCHZ+WGmOuS4lTLiy7in/oi3CFaQ4VGlafPln6wTO5NerWlM6USq6GJDQu6/f3DUV/Ft WPkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=eGzCMS6R4Dr+CfIU2e0VuZVQqoUS8od2pa/KcRcmtTY=; b=JEiGL0EaZ6oWgvf6QyuvJUnIySuHuNFzJGVigEOumJgt9ucI0S+TTjC2mXZz43G55E psCHvgVowM/jWMQDWY8BDxKtKnmuxzwWnJewo7Tkdh+EiBxTWoszhAtGiN9iOWMdrwT/ edGjHmKOqg0yEQg+OjY2E0I++Udlhlbo6bn5OItkw04LJB96tAcO619+jLfF2CXYZlwt 8VyXTDqFKuU4+LsbQVnusicwhHYg4Q8XdBrfp3nUZqfjlPkf908+2rr49rSeQ8jZBfBp rbN+bU9BxE8Z3vAf/ky46mmWQI+qwEDzkUvoCytUZEzxbW476WV2fMzOkARGPkJAs4ch RNTw== X-Gm-Message-State: ACrzQf0bJN1K6G69AfWwGtm3rIY8m+eR0uc5yAIR7BejRqb0G95qy0+F aSBStgbt7U8cf1bUa/qETjJjcanqjCA= X-Google-Smtp-Source: AMsMyM4YtvSilqLe1PP9EYNtfeWB/LWa6/4fFlIj90PoAiw/IsiNuhxMT6xRgo/SHhvIfS9ktiObrA== X-Received: by 2002:a63:5761:0:b0:43c:5940:9176 with SMTP id h33-20020a635761000000b0043c59409176mr45172001pgm.65.1667881605682; Mon, 07 Nov 2022 20:26:45 -0800 (PST) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id x10-20020a1709027c0a00b00186b8752a78sm5862419pll.80.2022.11.07.20.26.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 20:26:45 -0800 (PST) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/6][SRU][OEM-5.17] drm/mgag200: Optimize damage clips Date: Tue, 8 Nov 2022 12:26:29 +0800 Message-Id: <20221108042634.24176-5-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221108042634.24176-1-acelan.kao@canonical.com> References: <20221108042634.24176-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.173; envelope-from=acelan@gmail.com; helo=mail-pg1-f173.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jocelyn Falempe BugLink: https://launchpad.net/bugs/1995573 When there are multiple damage clips, previous code merged them into one big rectangle. As the Matrox memory is very slow, it's faster to copy each damage clip. Signed-off-by: Jocelyn Falempe Reviewed-by: Lyude Paul Reviewed-by: Thomas Zimmermann Link: https://patchwork.freedesktop.org/patch/msgid/20220504134026.283417-2-jfalempe@redhat.com (cherry picked from commit c48a363016349352dac7e66cd1e823f73bff1fc4) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/gpu/drm/mgag200/mgag200_mode.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index 4bdc1fc388a9..4c09485d3ef8 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -865,10 +865,6 @@ mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb, dst += drm_fb_clip_offset(fb->pitches[0], fb->format, clip); drm_fb_memcpy_toio(dst, fb->pitches[0], vmap, fb, clip); - - /* Always scanout image at VRAM offset 0 */ - mgag200_set_startadd(mdev, (u32)0); - mgag200_set_offset(mdev, fb); } static void @@ -923,6 +919,10 @@ mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, mgag200_handle_damage(mdev, fb, &fullscreen, &shadow_plane_state->data[0]); + /* Always scanout image at VRAM offset 0 */ + mgag200_set_startadd(mdev, (u32)0); + mgag200_set_offset(mdev, fb); + mutex_unlock(&mdev->rmmio_lock); } @@ -979,14 +979,20 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, struct drm_shadow_plane_state *shadow_plane_state = to_drm_shadow_plane_state(state); struct drm_framebuffer *fb = state->fb; struct drm_rect damage; + struct drm_atomic_helper_damage_iter iter; if (!fb) return; mutex_lock(&mdev->rmmio_lock); - if (drm_atomic_helper_damage_merged(old_state, state, &damage)) + drm_atomic_helper_damage_iter_init(&iter, old_state, state); + drm_atomic_for_each_plane_damage(&iter, &damage) { mgag200_handle_damage(mdev, fb, &damage, &shadow_plane_state->data[0]); + } + /* Always scanout image at VRAM offset 0 */ + mgag200_set_startadd(mdev, (u32)0); + mgag200_set_offset(mdev, fb); mutex_unlock(&mdev->rmmio_lock); } From patchwork Tue Nov 8 04:26:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1701111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VoQfeu4F; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5w6X0BqDz1yqS for ; Tue, 8 Nov 2022 15:27:00 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1osGCK-0003Bj-GZ; Tue, 08 Nov 2022 04:26:52 +0000 Received: from mail-pj1-f42.google.com ([209.85.216.42]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1osGCH-00031K-9p for kernel-team@lists.ubuntu.com; Tue, 08 Nov 2022 04:26:49 +0000 Received: by mail-pj1-f42.google.com with SMTP id c15-20020a17090a1d0f00b0021365864446so12295693pjd.4 for ; Mon, 07 Nov 2022 20:26:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=aogRgXCIOydMC1Fm0NBp5xCq71lsc2EmisS0+7Sk890=; b=VoQfeu4FACyRZtGpvbkIGZTRtDCoDTKzU4+yJbh3z3arroxbXqV/ewZW4S3kZR4ZB7 rKXeJSIa+Unwpj6AU011Cin80JiJyI9VjeSxRMMJmn4pC7ziIo9ekJaifXuSwdwdmY1Y vS6UzmbGqOOzV3lS9OhlYxLtxHwSgnU+hzhDVZOlWGqgV2pgSuSFqsf93biYtuPD1qEm EwkagPZCqlEMKVKaZi3awsNF10v1/ZiRmMIwYhHcLI1ipcjJMyQtLELwdkgOnVovkPLJ Ri2vdHH4vL2FsvCZxgOwvG0qmOwCapWch7AoJvGX1zpI+vqS9OW1m/rHD56INgFEhsS3 elzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=aogRgXCIOydMC1Fm0NBp5xCq71lsc2EmisS0+7Sk890=; b=yOWl/oUi3a7UA7D7Cyi/EFDgeJjT+DUNfVZ/Iu9dSI9X2E7ehwrBvJMbv7bnZiYg1D Dlt5Lcc5ZQufj1/FIX7NoPb75DBe19ZinvwumHstexbfHS8ml2400FQ/exYvjxedaNXN y/7LYdPtBhcWe3+MVBhVzMXQqVqIDs6Gf9w1nZQhCkxeLHA6kH/qlIO9uXmBJTZsBjR8 TgY7jxAWP38DrTNTwZhh0KUQ3qbvwIx9Ii3QV5XqO6rZsvPiz3TjM1XsKkaI1ddjXa57 p0GsgguzSKYTfOB/PamjJNJ6C6nKN6wgz5wDI2pzUZjmqLJp2EbAGS15H6hRDNLRTLqD mQRQ== X-Gm-Message-State: ACrzQf3To75R4Ayi2zSK47jyjgyiKY4aI7PHMoPSzod8ntcFisKVjsH4 N4sk9dtcLWiLGDPf0WplkUxLVgG+0SE= X-Google-Smtp-Source: AMsMyM7QSKkTkbGfOAPOdL0pL3g3dn2Re24KH/yP3LIX65Z8qzzw7bUCuUEmSV+6veXn2sH9GwtR4Q== X-Received: by 2002:a17:903:41c8:b0:187:480b:ead5 with SMTP id u8-20020a17090341c800b00187480bead5mr32723410ple.22.1667881608278; Mon, 07 Nov 2022 20:26:48 -0800 (PST) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id c188-20020a624ec5000000b0056c0d129edfsm5304778pfb.121.2022.11.07.20.26.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 20:26:47 -0800 (PST) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 5/6][SRU][OEM-5.17] drm/mgag200: Add FB_DAMAGE_CLIPS support Date: Tue, 8 Nov 2022 12:26:30 +0800 Message-Id: <20221108042634.24176-6-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221108042634.24176-1-acelan.kao@canonical.com> References: <20221108042634.24176-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.216.42; envelope-from=acelan@gmail.com; helo=mail-pj1-f42.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jocelyn Falempe BugLink: https://launchpad.net/bugs/1995573 The driver does support damage clips, but doesn't advertise it. So when running gnome/wayland on Matrox hardware, the full frame is copied to the slow Matrox memory, which leads to very poor performances. Add drm_plane_enable_fb_damage_clips() to advertise this capability to userspace. With this patch, gnome/wayland becomes usable on Matrox GPU. Suggested-by: Jonas Ã…dahl Signed-off-by: Jocelyn Falempe Reviewed-by: Lyude Paul Reviewed-by: Thomas Zimmermann Link: https://patchwork.freedesktop.org/patch/msgid/20220504134026.283417-2-jfalempe@redhat.com (cherry picked from commit 3064debaf55e1bc8f191871ca5f82697ef4c0951) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/gpu/drm/mgag200/mgag200_mode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index 4c09485d3ef8..825b4f6964e4 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -1137,6 +1137,8 @@ int mgag200_modeset_init(struct mga_device *mdev) return ret; } + drm_plane_enable_fb_damage_clips(&pipe->plane); + /* FIXME: legacy gamma tables; convert to CRTC state */ drm_mode_crtc_set_gamma_size(&pipe->crtc, MGAG200_LUT_SIZE); From patchwork Tue Nov 8 04:26:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1701112 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=UTbrRNmq; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N5w6g3jMhz1yqS for ; Tue, 8 Nov 2022 15:27:07 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1osGCQ-0003MN-0z; Tue, 08 Nov 2022 04:26:58 +0000 Received: from mail-pl1-f170.google.com ([209.85.214.170]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1osGCM-0003AY-2l for kernel-team@lists.ubuntu.com; Tue, 08 Nov 2022 04:26:54 +0000 Received: by mail-pl1-f170.google.com with SMTP id j12so13113848plj.5 for ; Mon, 07 Nov 2022 20:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=A0bVFP4gGz8XAcdDArSSKHAy4nKJjt0fLZ+xnMaKfaI=; b=UTbrRNmqVc3Jxp/Fa4Ha4WPgAZvJelQS+Dk70zlgIJyYllqJim1ICDa4/uhpxsupzY RGEDEYxYHJqhkXIDSwMcD/R7YDnGZe4IqmAzxtMOZfqTxFeddIJ6tR8y9SkLrtmyGCuy OLrxkqkBYN1LVFhCdojo7Ar0xMtuhfMGSCsdevbZW2a5KsDidshrCkE9jN5qLXW+xdm1 hSlEP4hB9QCGsELnXOJQnPhr2xwQQpuqwEKOQV2OYTx3FQcR05xvDM4PIaRLILMMzH2J PKFSlfrbjM/yjxK2+aUPN9gQbL4wmJD91fiQTVfvpy+yjp3oyyhSRGiZk86ZFkNKUCz2 zZlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=A0bVFP4gGz8XAcdDArSSKHAy4nKJjt0fLZ+xnMaKfaI=; b=nDQfqzPjLv06AbZ4CG9eGV7iDDdl6eO50w38T6z3ID/7xGihJOjDt3uRBkRB1nsMmG cyjq+4Lg3PecJYh0m6TS+rSZBlNFsUEO7hTAMZjlknN3RIIHIvWvhMguRdtDylYTAICg JfFg2nzUmCPR53npD1LkzbT+rbux4RpF0PT87RgrhZ0XtFZW6Tgw6VPslUDcxI0s2VLj 00G4FQ0gYwp/zLJw0VvOL4wsr1c/K+RdJ0nYALs69yNdr6zgTd8CrNJGrgfinGeoUzAE aAo8Vnht5hcPTCEpVSyExLqYX9ChDxRhhSBSDHDRsSzVFYiQ6SzZYR9mx0tf8YIXk5xO rfPw== X-Gm-Message-State: ACrzQf3PNYCvqCtC78Q+Ctc0sF1EF/i6yFOPhawrZTVbo6yNLK1k5Epx Xba4mA3g3B99oZeyzxJ9FPOnXpzqXb8= X-Google-Smtp-Source: AMsMyM6atEV8cY336ceKvxPkwbzK6nzmGolVbB0jeXmGQgaVSbiUL2aSdixls8Kv//vsgTtALL00Gg== X-Received: by 2002:a17:90b:e86:b0:213:8092:e19a with SMTP id fv6-20020a17090b0e8600b002138092e19amr62782214pjb.56.1667881610783; Mon, 07 Nov 2022 20:26:50 -0800 (PST) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id k12-20020a6555cc000000b0043c22e926f8sm4944844pgs.84.2022.11.07.20.26.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 20:26:50 -0800 (PST) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 6/6][SRU][OEM-5.17] drm/mgag200: Enable atomic gamma lut update Date: Tue, 8 Nov 2022 12:26:31 +0800 Message-Id: <20221108042634.24176-7-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221108042634.24176-1-acelan.kao@canonical.com> References: <20221108042634.24176-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.170; envelope-from=acelan@gmail.com; helo=mail-pl1-f170.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jocelyn Falempe BugLink: https://launchpad.net/bugs/1995573 Add support for atomic update of gamma lut. With this patch the "Night light" feature of gnome3 is working properly on mgag200. v2: - Add a default linear gamma function - renamed functions with mgag200 prefix - use format's 4cc code instead of bit depth - use better interpolation for 16bits gamma - remove legacy function mga_crtc_load_lut() - can't remove the call to drm_mode_crtc_set_gamma_size() because it doesn't work with userspace. - other small refactors v3: - change mgag200_crtc_set_gamma*() argument to struct drm_format_info *format - fix printk format to %p4cc for 4cc and %zu for size_t - rebased to drm-misc-next. Signed-off-by: Jocelyn Falempe Tested-by: Thomas Zimmermann Reviewed-by: Thomas Zimmermann Link: https://patchwork.freedesktop.org/patch/msgid/20220513084900.1832381-1-jfalempe@redhat.com (cherry picked from commit c577b2f43e80d707870a74de0fd726c51b206956) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/gpu/drm/mgag200/mgag200_mode.c | 127 ++++++++++++++++--------- 1 file changed, 83 insertions(+), 44 deletions(-) diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c index 825b4f6964e4..1ed43bac4339 100644 --- a/drivers/gpu/drm/mgag200/mgag200_mode.c +++ b/drivers/gpu/drm/mgag200/mgag200_mode.c @@ -32,57 +32,78 @@ * This file contains setup code for the CRTC. */ -static void mga_crtc_load_lut(struct drm_crtc *crtc) +static void mgag200_crtc_set_gamma_linear(struct mga_device *mdev, + const struct drm_format_info *format) { - struct drm_device *dev = crtc->dev; - struct mga_device *mdev = to_mga_device(dev); - struct drm_framebuffer *fb; - u16 *r_ptr, *g_ptr, *b_ptr; int i; - if (!crtc->enabled) - return; - - if (!mdev->display_pipe.plane.state) - return; + WREG8(DAC_INDEX + MGA1064_INDEX, 0); - fb = mdev->display_pipe.plane.state->fb; + switch (format->format) { + case DRM_FORMAT_RGB565: + /* Use better interpolation, to take 32 values from 0 to 255 */ + for (i = 0; i < MGAG200_LUT_SIZE / 8; i++) { + WREG8(DAC_INDEX + MGA1064_COL_PAL, i * 8 + i / 4); + WREG8(DAC_INDEX + MGA1064_COL_PAL, i * 4 + i / 16); + WREG8(DAC_INDEX + MGA1064_COL_PAL, i * 8 + i / 4); + } + /* Green has one more bit, so add padding with 0 for red and blue. */ + for (i = MGAG200_LUT_SIZE / 8; i < MGAG200_LUT_SIZE / 4; i++) { + WREG8(DAC_INDEX + MGA1064_COL_PAL, 0); + WREG8(DAC_INDEX + MGA1064_COL_PAL, i * 4 + i / 16); + WREG8(DAC_INDEX + MGA1064_COL_PAL, 0); + } + break; + case DRM_FORMAT_RGB888: + case DRM_FORMAT_XRGB8888: + for (i = 0; i < MGAG200_LUT_SIZE; i++) { + WREG8(DAC_INDEX + MGA1064_COL_PAL, i); + WREG8(DAC_INDEX + MGA1064_COL_PAL, i); + WREG8(DAC_INDEX + MGA1064_COL_PAL, i); + } + break; + default: + drm_warn_once(&mdev->base, "Unsupported format %p4cc for gamma correction\n", + &format->format); + break; + } +} - r_ptr = crtc->gamma_store; - g_ptr = r_ptr + crtc->gamma_size; - b_ptr = g_ptr + crtc->gamma_size; +static void mgag200_crtc_set_gamma(struct mga_device *mdev, + const struct drm_format_info *format, + struct drm_color_lut *lut) +{ + int i; WREG8(DAC_INDEX + MGA1064_INDEX, 0); - if (fb && fb->format->cpp[0] * 8 == 16) { - int inc = (fb->format->depth == 15) ? 8 : 4; - u8 r, b; - for (i = 0; i < MGAG200_LUT_SIZE; i += inc) { - if (fb->format->depth == 16) { - if (i > (MGAG200_LUT_SIZE >> 1)) { - r = b = 0; - } else { - r = *r_ptr++ >> 8; - b = *b_ptr++ >> 8; - r_ptr++; - b_ptr++; - } - } else { - r = *r_ptr++ >> 8; - b = *b_ptr++ >> 8; - } - /* VGA registers */ - WREG8(DAC_INDEX + MGA1064_COL_PAL, r); - WREG8(DAC_INDEX + MGA1064_COL_PAL, *g_ptr++ >> 8); - WREG8(DAC_INDEX + MGA1064_COL_PAL, b); + switch (format->format) { + case DRM_FORMAT_RGB565: + /* Use better interpolation, to take 32 values from lut[0] to lut[255] */ + for (i = 0; i < MGAG200_LUT_SIZE / 8; i++) { + WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i * 8 + i / 4].red >> 8); + WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i * 4 + i / 16].green >> 8); + WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i * 8 + i / 4].blue >> 8); } - return; - } - for (i = 0; i < MGAG200_LUT_SIZE; i++) { - /* VGA registers */ - WREG8(DAC_INDEX + MGA1064_COL_PAL, *r_ptr++ >> 8); - WREG8(DAC_INDEX + MGA1064_COL_PAL, *g_ptr++ >> 8); - WREG8(DAC_INDEX + MGA1064_COL_PAL, *b_ptr++ >> 8); + /* Green has one more bit, so add padding with 0 for red and blue. */ + for (i = MGAG200_LUT_SIZE / 8; i < MGAG200_LUT_SIZE / 4; i++) { + WREG8(DAC_INDEX + MGA1064_COL_PAL, 0); + WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i * 4 + i / 16].green >> 8); + WREG8(DAC_INDEX + MGA1064_COL_PAL, 0); + } + break; + case DRM_FORMAT_RGB888: + case DRM_FORMAT_XRGB8888: + for (i = 0; i < MGAG200_LUT_SIZE; i++) { + WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].red >> 8); + WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].green >> 8); + WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].blue >> 8); + } + break; + default: + drm_warn_once(&mdev->base, "Unsupported format %p4cc for gamma correction\n", + &format->format); + break; } } @@ -914,7 +935,11 @@ mgag200_simple_display_pipe_enable(struct drm_simple_display_pipe *pipe, if (mdev->type == G200_WB || mdev->type == G200_EW3) mgag200_g200wb_release_bmc(mdev); - mga_crtc_load_lut(crtc); + if (crtc_state->gamma_lut) + mgag200_crtc_set_gamma(mdev, fb->format, crtc_state->gamma_lut->data); + else + mgag200_crtc_set_gamma_linear(mdev, fb->format); + mgag200_enable_display(mdev); mgag200_handle_damage(mdev, fb, &fullscreen, &shadow_plane_state->data[0]); @@ -965,6 +990,14 @@ mgag200_simple_display_pipe_check(struct drm_simple_display_pipe *pipe, return ret; } + if (crtc_state->color_mgmt_changed && crtc_state->gamma_lut) { + if (crtc_state->gamma_lut->length != + MGAG200_LUT_SIZE * sizeof(struct drm_color_lut)) { + drm_err(dev, "Wrong size for gamma_lut %zu\n", + crtc_state->gamma_lut->length); + return -EINVAL; + } + } return 0; } @@ -973,6 +1006,7 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, struct drm_plane_state *old_state) { struct drm_plane *plane = &pipe->plane; + struct drm_crtc *crtc = &pipe->crtc; struct drm_device *dev = plane->dev; struct mga_device *mdev = to_mga_device(dev); struct drm_plane_state *state = plane->state; @@ -986,6 +1020,9 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe, mutex_lock(&mdev->rmmio_lock); + if (crtc->state->color_mgmt_changed && crtc->state->gamma_lut) + mgag200_crtc_set_gamma(mdev, fb->format, crtc->state->gamma_lut->data); + drm_atomic_helper_damage_iter_init(&iter, old_state, state); drm_atomic_for_each_plane_damage(&iter, &damage) { mgag200_handle_damage(mdev, fb, &damage, &shadow_plane_state->data[0]); @@ -1139,9 +1176,11 @@ int mgag200_modeset_init(struct mga_device *mdev) drm_plane_enable_fb_damage_clips(&pipe->plane); - /* FIXME: legacy gamma tables; convert to CRTC state */ + /* FIXME: legacy gamma tables, but atomic gamma doesn't work without */ drm_mode_crtc_set_gamma_size(&pipe->crtc, MGAG200_LUT_SIZE); + drm_crtc_enable_color_mgmt(&pipe->crtc, 0, false, MGAG200_LUT_SIZE); + drm_mode_config_reset(dev); return 0;