From patchwork Tue Oct 17 09:28:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 154004 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4008221vqb; Tue, 17 Oct 2023 02:30:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8H/Ir/JQeLqlQJwN5qmbyg1ZUpk8OkqVXRrO/ZH5B5GeGlk7zyCy1q56qIX205QxfA5rH X-Received: by 2002:a05:6a20:c182:b0:13d:fff1:c672 with SMTP id bg2-20020a056a20c18200b0013dfff1c672mr1695855pzb.4.1697535051949; Tue, 17 Oct 2023 02:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697535051; cv=none; d=google.com; s=arc-20160816; b=bS6NvIzuPx5Ks9EbKkdraKd0bpMq59bPkjtQL9TXqqxP5WcAWaL8OpGyMyqQG8OBmK lqjnO1KvmJ4fXxhleBzzITKoRsNExhaSm78QyTVxSlwQCQzswwi34+kDvAWtPrV7ovta r28mfiHZKBDROER3hgG55PvhfrB95wcFGHErOb2OSUV3VUA7A10OGUirBvptdTunBRVG stzxAUMeLQnqcLyevOJuwK+SvWBWpFUnGUHTR3FoaXYtNBnt6Fj3ACpDNKRzN2yj7uGp uR2GVdrHsJIcMF4DgQuNN2b3jX5sLbcHr1v6FbZ5MXTvbVdLmTpgoS7IU2JIz909g2X0 uQyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=M0OhnC9PF7mmN9DYZd8NiL3IgQoyU0UGHjNLFnu9l9M=; fh=SJQ48KwEv1Wk78SyBTKjV1EcFj2vZ5p6XYIidAE2t8E=; b=YEljb/D4mPs40W98KEBmNn8KdmWG4Vo1LBkb2j+tOuym7IF/eODFYTOWkmhLKKzafu nMppoNU+2E7t+pq/gHAisC3Dxw5EJxRP41UiQDtp02xeJDcPazvkVeCxVG+ye5+M8J7C yWQCy3N8BPXUrad+mvcy2kgHcEe068uoS2giOqoHlAMl/BsitJzsGjsLMBWO3f1IWnJM CVrE6dsAhsRPRjAtBVHz3Q4RZ56/kBz1NWSG8+WX+AXQSi3L6G+qzC5afW1atNzG18ML 1yHmmFELuBXbJuQd9qs68sxIoKcCidsyVgNolqVNXERRaG6LQL2B5kGstyMBDWhcQ8u1 i3CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=sJ3DFzHx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bw32-20020a056a0204a000b005aa6b242005si1591348pgb.24.2023.10.17.02.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:30:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=sJ3DFzHx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id BECB88067F4F; Tue, 17 Oct 2023 02:30:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343552AbjJQJ37 (ORCPT + 19 others); Tue, 17 Oct 2023 05:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234974AbjJQJ3f (ORCPT ); Tue, 17 Oct 2023 05:29:35 -0400 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCE4819A0 for ; Tue, 17 Oct 2023 02:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=M0OhnC9PF7mmN9DYZd8NiL3IgQoyU0UGHjNLFnu9l9M=; b=sJ3DFzHxiczoUhJfKkJeBA7h6K 5Jnaw6qrt0Z/y3EIp9gfLHExSFw5sOOy2tLkOiTo7eJeYNIqPtcjqGBuFaEeM96sQhhKuACClA5H4 8gw01zMH2Z1T0XU11+XK5974jiTVsMf4x0tPxaDJIWSxdv5/ZSnNsP6NbYHzp/5QuVBDYNngagYb2 zqGzoWw7uBNDTLUfWocH7p0QpI1csmrGblgu2C+uNXEL9/Rw+Y2QN9QKS1E4euaiAdLyxi4B+czxq pDJktObFE3Lsb/6740B6jp1ZV4z9L/DvzNl8h7iPGjuvpKmY4d5tjtephXwH3/Uv7eiiT1nPGcPyL 8gU+vyqw==; Received: from 167.red-81-39-185.dynamicip.rima-tde.net ([81.39.185.167] helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1qsgNc-001ODF-3b; Tue, 17 Oct 2023 11:28:48 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: pierre-eric.pelloux-prayer@amd.com, =?utf-8?b?J01hcmVrIE9sxaHDoWsn?= , =?utf-8?q?Michel_D?= =?utf-8?q?=C3=A4nzer?= , "Randy Dunlap" , "Pekka Paalanen" , hwentlan@amd.com, kernel-dev@igalia.com, alexander.deucher@amd.com, christian.koenig@amd.com, joshua@froggi.es, Simon Ser , =?utf-8?q?Andr=C3=A9_Alm?= =?utf-8?q?eida?= Subject: [PATCH v7 1/6] drm: allow DRM_MODE_PAGE_FLIP_ASYNC for atomic commits Date: Tue, 17 Oct 2023 11:28:32 +0200 Message-ID: <20231017092837.32428-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231017092837.32428-1-andrealmeid@igalia.com> References: <20231017092837.32428-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 17 Oct 2023 02:30:41 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779994514885912708 X-GMAIL-MSGID: 1779994514885912708 From: Simon Ser If the driver supports it, allow user-space to supply the DRM_MODE_PAGE_FLIP_ASYNC flag to request an async page-flip. Set drm_crtc_state.async_flip accordingly. Document that drivers will reject atomic commits if an async flip isn't possible. This allows user-space to fall back to something else. For instance, Xorg falls back to a blit. Another option is to wait as close to the next vblank as possible before performing the page-flip to reduce latency. Signed-off-by: Simon Ser Reviewed-by: Alex Deucher Co-developed-by: André Almeida Signed-off-by: André Almeida --- drivers/gpu/drm/drm_atomic_uapi.c | 28 +++++++++++++++++++++++++--- include/uapi/drm/drm_mode.h | 9 +++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 98d3b10c08ae..a15121e75a0a 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -1323,6 +1323,18 @@ static void complete_signaling(struct drm_device *dev, kfree(fence_state); } +static void +set_async_flip(struct drm_atomic_state *state) +{ + struct drm_crtc *crtc; + struct drm_crtc_state *crtc_state; + int i; + + for_each_new_crtc_in_state(state, crtc, crtc_state, i) { + crtc_state->async_flip = true; + } +} + int drm_mode_atomic_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { @@ -1363,9 +1375,16 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, } if (arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) { - drm_dbg_atomic(dev, - "commit failed: invalid flag DRM_MODE_PAGE_FLIP_ASYNC\n"); - return -EINVAL; + if (!dev->mode_config.async_page_flip) { + drm_dbg_atomic(dev, + "commit failed: DRM_MODE_PAGE_FLIP_ASYNC not supported\n"); + return -EINVAL; + } + if (dev->mode_config.atomic_async_page_flip_not_supported) { + drm_dbg_atomic(dev, + "commit failed: DRM_MODE_PAGE_FLIP_ASYNC not supported with atomic\n"); + return -EINVAL; + } } /* can't test and expect an event at the same time. */ @@ -1468,6 +1487,9 @@ int drm_mode_atomic_ioctl(struct drm_device *dev, if (ret) goto out; + if (arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) + set_async_flip(state); + if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) { ret = drm_atomic_check_only(state); } else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) { diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index ea1b639bcb28..04e6a3caa675 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -957,6 +957,15 @@ struct hdr_output_metadata { * Request that the page-flip is performed as soon as possible, ie. with no * delay due to waiting for vblank. This may cause tearing to be visible on * the screen. + * + * When used with atomic uAPI, the driver will return an error if the hardware + * doesn't support performing an asynchronous page-flip for this update. + * User-space should handle this, e.g. by falling back to a regular page-flip. + * + * Note, some hardware might need to perform one last synchronous page-flip + * before being able to switch to asynchronous page-flips. As an exception, + * the driver will return success even though that first page-flip is not + * asynchronous. */ #define DRM_MODE_PAGE_FLIP_ASYNC 0x02 #define DRM_MODE_PAGE_FLIP_TARGET_ABSOLUTE 0x4