From patchwork Tue Oct 26 11:34:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44739C433EF for ; Tue, 26 Oct 2021 11:34:39 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 140A8604E9 for ; Tue, 26 Oct 2021 11:34:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 140A8604E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6661289CFA; Tue, 26 Oct 2021 11:34:34 +0000 (UTC) Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by gabe.freedesktop.org (Postfix) with ESMTPS id A489E89CC4 for ; Tue, 26 Oct 2021 11:34:29 +0000 (UTC) Received: by mail-qt1-x836.google.com with SMTP id y11so13092316qtn.13 for ; Tue, 26 Oct 2021 04:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g8AjUosguFFwtSTTUN5QcdLFCu3iDK1fKV4GOcMHHcY=; b=pIvdM+bPSllROd9J58XWZfllhzU8vWSjbRvnbm5a04KeMQq6iA8iRwvZOJEMuOmcoH CAH8/fCIERo6Mu+xvk5ItQiBgD96zTa5dhGSlTr0lr+0hLWO+Rj/MHRryB2fEa01O2R1 HTiHYXXAhmpFrIt7BZGQBN5VnC4VVuttXWHhB2/PBh+3fs4NElCZmSHGX2OFqyIHy4Fu sNxuMnBxLEJvrw5sLKzSnVwa98U3Gd0DKAsr9Ra1F9qq+wEs4GnySvJ71SogcHgL/zIR hAThQ+uQPDSeDR9XT/PFo4RP7ybZO7XgwfLDPQlRJejQ+GWsUjprxFwcWJRn3te6OWsK Pl/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g8AjUosguFFwtSTTUN5QcdLFCu3iDK1fKV4GOcMHHcY=; b=xzmN0m4hpcVa+b0sOXyO9okd8YIAlDY4JWzWarPSZ2DdBK9AfiW93pVygPZ52ZWxba lFPc+7TcYgGJ0DiN/X2dw9MxjksdbbeeJwvMKGWX7fyY+Ucb6WXUROUmtIj4PUbvTSP+ Zypz50gEw3hLJ/xXQjUpA8psfB356iPdJHrdsYHIjOjlRdm94lvd4mSvjfpXBTXLgW2g niLusm0TVmqsrQN9ABRxwjqxczO8W5Tl2EeYkyNYmUX9td/M178NUUjfKFdvfw9m5ynJ qvZEbFY/UeUSbBByh7EzwmC2EWLEgmwd3u+80jyAGKyLfnyQEkEIoNAURZBzxcCWsP7w 7y1Q== X-Gm-Message-State: AOAM532HeYDTytcV3tJukHw6Prc5yhZQVzSveRwBoeryM8ZBrVUjlxI0 Gmge2CTe6+PU5U38MGMsn1c= X-Google-Smtp-Source: ABdhPJwNCqGvoofJDphLJuI8ugs3EZ27U14tagTGxGaPD5Pu0+v5MIh7QJPEAY6vC6d5cZvEebvc4A== X-Received: by 2002:ac8:610b:: with SMTP id a11mr23622405qtm.182.1635248068893; Tue, 26 Oct 2021 04:34:28 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:28 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/8] drm: vkms: Replace the deprecated drm_mode_config_init Date: Tue, 26 Oct 2021 08:34:01 -0300 Message-Id: <20211026113409.7242-2-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The `drm_mode_config_init` was deprecated since c3b790e commit, and it's being replaced by the `drmm_mode_config_init`. Signed-off-by: Igor Torrente --- V2: Change the code style(Thomas Zimmermann). --- drivers/gpu/drm/vkms/vkms_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 0ffe5f0e33f7..ee4d96dabe19 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -140,8 +140,12 @@ static const struct drm_mode_config_helper_funcs vkms_mode_config_helpers = { static int vkms_modeset_init(struct vkms_device *vkmsdev) { struct drm_device *dev = &vkmsdev->drm; + int ret; + + ret = drmm_mode_config_init(dev); + if (ret < 0) + return ret; - drm_mode_config_init(dev); dev->mode_config.funcs = &vkms_mode_funcs; dev->mode_config.min_width = XRES_MIN; dev->mode_config.min_height = YRES_MIN; From patchwork Tue Oct 26 11:34:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3F2CC433F5 for ; Tue, 26 Oct 2021 11:34:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7BFC8604E9 for ; Tue, 26 Oct 2021 11:34:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7BFC8604E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0632C89CC4; Tue, 26 Oct 2021 11:34:34 +0000 (UTC) Received: from mail-qt1-x831.google.com (mail-qt1-x831.google.com [IPv6:2607:f8b0:4864:20::831]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5B41A89CC4 for ; Tue, 26 Oct 2021 11:34:32 +0000 (UTC) Received: by mail-qt1-x831.google.com with SMTP id v17so13154521qtp.1 for ; Tue, 26 Oct 2021 04:34:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wqMc7i1j40Y6DJkM28XSTOEIlGNuQurfBNScJR7ESu8=; b=Goj4gTT4O5t+YUsAYs5tnCbkO/VEDkjlieeYIWOKIAEPRUn/SkOfJbSxy04aq1WzEK PF8mUm23zlMbaFjYu5D1j8qebNn+BaxC31yvDgRFwx6kVoCdvjpN561AzgAzYu/nRM+P GaS2F4dDeA4YyjSiXx2KNPtfoxenaP/Qk949evKwoiVBB1IWw++j1oA9MR/NEc8fux24 USLGTNYtVy6MWPEd1dLprhmyGvt1+2iKE1g2PCkfN0wZS8cgsmwlODFibQmzHu2OKsum nERzYk7X8uGpyUoQz9+rmxA6GDyjTLx+IxQCYF/AFJbgh7+8+guT6ZfnikszvbCVQz4J KCYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wqMc7i1j40Y6DJkM28XSTOEIlGNuQurfBNScJR7ESu8=; b=bvU3dyZXF78ciIqMH+f1KKzFOIZmRp1ifBQ4TRvkIB4Szkc9u8Erd7t4WA5JdMcUQH V0PztouWZITKtY31+MK/jomFParzkLeiZgwZXOQHww4nVIZ7I0ZQ7sihNktacV+HYenY SvvTOIQA9QZIby07Bnh+ncWVA7b0ua/Nml5Aet8Num2obmHLz8oVA+N+8jxleNtE3s60 RA2kLE4/nCl/bly3rmHZoWrW+sF0dao5QIEzFmpMZufzAtqzy6dMdtssqEsdJmyDUQsT EH+zIHhxLMWYTcp5l9YotkIgm+Me8PhmrURVxpVcvC2lZ7mLUMU07/Z50TjfdPh7Ncoj dBDQ== X-Gm-Message-State: AOAM533WFMiQAbLI9aCH9V/oc3Q1sISoKHhyJKqkdHzRpSYvBbeCdRCY XE5BF6unrdLNeCrO5rwduyA= X-Google-Smtp-Source: ABdhPJy58bgE5ig1WKtumIXsNvAjAio5QYt9toq4UiCMJEzyf6moIAN9g91DGOK5SQKnlR/OC0ovyg== X-Received: by 2002:a05:622a:1a2a:: with SMTP id f42mr24307335qtb.381.1635248071550; Tue, 26 Oct 2021 04:34:31 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:31 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/8] drm: vkms: Alloc the compose frame using vzalloc Date: Tue, 26 Oct 2021 08:34:02 -0300 Message-Id: <20211026113409.7242-3-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently, the memory to the composition frame is being allocated using the kzmalloc. This comes with the limitation of maximum size of one page size(which in the x86_64 is 4Kb and 4MB for default and hugepage respectively). Somes test of igt (e.g. kms_plane@pixel-format) uses more than 4MB when testing some pixel formats like ARGB16161616. This problem is addessed by allocating the memory using kvzalloc that circunvents this limitation. Signed-off-by: Igor Torrente --- drivers/gpu/drm/vkms/vkms_composer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 9e8204be9a14..82f79e508f81 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -180,7 +180,7 @@ static int compose_active_planes(void **vaddr_out, int i; if (!*vaddr_out) { - *vaddr_out = kzalloc(gem_obj->size, GFP_KERNEL); + *vaddr_out = kvzalloc(gem_obj->size, GFP_KERNEL); if (!*vaddr_out) { DRM_ERROR("Cannot allocate memory for output frame."); return -ENOMEM; @@ -263,7 +263,7 @@ void vkms_composer_worker(struct work_struct *work) crtc_state); if (ret) { if (ret == -EINVAL && !wb_pending) - kfree(vaddr_out); + kvfree(vaddr_out); return; } @@ -275,7 +275,7 @@ void vkms_composer_worker(struct work_struct *work) crtc_state->wb_pending = false; spin_unlock_irq(&out->composer_lock); } else { - kfree(vaddr_out); + kvfree(vaddr_out); } /* From patchwork Tue Oct 26 11:34:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E564C433F5 for ; Tue, 26 Oct 2021 11:34:52 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F1A776008E for ; Tue, 26 Oct 2021 11:34:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F1A776008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D06CC6E42C; Tue, 26 Oct 2021 11:34:49 +0000 (UTC) Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6BEA76E425 for ; Tue, 26 Oct 2021 11:34:35 +0000 (UTC) Received: by mail-qv1-xf35.google.com with SMTP id o20so9280034qvk.7 for ; Tue, 26 Oct 2021 04:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4h5zssoprQVwUD/a+0iu7NgShrwtvdhuvMV0VoWpIVI=; b=Z0+Vmb9SA3GDGHWzGshFG2cbmaX3YObyMVExUokXNje/LEUkMcLV4WYwbCeyU/Y6ji QEwLhNVikeMQavW4bF9VzdUH9v2cJ7MVLDXDdxBHkgIZtUHMei8q27YEzLdUU5nvTqLD 5fpKEtd+sBTsiOrPHi4Q6X++ytudP1inXfQQ8CWy1gAgJ46NpoSXB8QAkBlxKFQA4aS7 vLKuQ9z2SOq9stYZ5qBF/aApjJO8CIoZQAPa0TcuUA00HyJmReax1/Vm+BelMYBQ0TcO rkbYXBVfI88M3iYmgkgWeYFCcpY2mYwkN0+Uiyr3W4i7tkqKtmObiBwdP39Tw7kRZfGG 6Gdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4h5zssoprQVwUD/a+0iu7NgShrwtvdhuvMV0VoWpIVI=; b=oprp+JaWbPpo3i38+krQpwASqw0355NhpOaf6kK7R15vB0qulk1Ri7lvewi9myMYpc Mn6FaUFSD1WtY00ZRdN8NJpSTQ2MdZPgyFISEFZ7ogpGASgx4GX9UoJdgGECIg2XwNVp XNadaHbfdvrP6oYRdl06u35sWAdMAeYROWc8eKSwHkAIBqEG67U/jtnFQb6GnvsMYSsK VoQV+EfuhaqJDAbxNpnLDM55EOpy1d1jsmHrYXF90N6guvvgW5d6+zmod6G7v/x5FqXV arupxE8LEb7ODNrYwtiX2vClRtv3fWAFCxIcaLomao6iixqoT9j3ujgDU7gI0/ddqql7 GBdg== X-Gm-Message-State: AOAM531fTdPia3+drH9TuWA9/R5uTFDIxlTXnis5s9f17y+lYiS98Euu Rd4UlvMxYnkMa8Ln7sXg0Zo= X-Google-Smtp-Source: ABdhPJyFYSzLutIYA+4K2QxblxTKk5KJU3m/tlDZRfeVO2Ghg5lVIxoqYInFjfQtSHYnFT6xkxuyRQ== X-Received: by 2002:a0c:ec52:: with SMTP id n18mr12604617qvq.6.1635248074307; Tue, 26 Oct 2021 04:34:34 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:34 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org Subject: [PATCH v2 3/8] drm: vkms: Replace hardcoded value of `vkms_composer.map` to DRM_FORMAT_MAX_PLANES Date: Tue, 26 Oct 2021 08:34:03 -0300 Message-Id: <20211026113409.7242-4-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The `map` vector at `vkms_composer` uses a hardcoded value to define its size. If someday the maximum number of planes increases, this hardcoded value can be a problem. This value is being replaced with the DRM_FORMAT_MAX_PLANES macro. Signed-off-by: Igor Torrente Acked-by: Thomas Zimmermann --- drivers/gpu/drm/vkms/vkms_drv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index d48c23d40ce5..64e62993b06f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -28,7 +28,7 @@ struct vkms_writeback_job { struct vkms_composer { struct drm_framebuffer fb; struct drm_rect src, dst; - struct dma_buf_map map[4]; + struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]; unsigned int offset; unsigned int pitch; unsigned int cpp; From patchwork Tue Oct 26 11:34:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DCF0C433EF for ; Tue, 26 Oct 2021 11:34:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 476AB6008E for ; Tue, 26 Oct 2021 11:34:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 476AB6008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5165E6E425; Tue, 26 Oct 2021 11:34:43 +0000 (UTC) Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by gabe.freedesktop.org (Postfix) with ESMTPS id D1E4F6E3EC for ; Tue, 26 Oct 2021 11:34:37 +0000 (UTC) Received: by mail-qt1-x82f.google.com with SMTP id y11so13092627qtn.13 for ; Tue, 26 Oct 2021 04:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qtCE7jonGK+7NebnXrOPLBttVq28Cf6oUZgL1KGrk/M=; b=ZC9LYvGxv9FOqQMVsliBmhIvRoEsCuS55GUwwR3ywalLi5KL36jUQ2p9GFdGQz7UrP W5LqbiVjLnNV0VP1V2IaSDk+YdG7+phUqxrfh6/Zmc90tnPHLPCs30n/e58QKxzScRyP lp+xs42JmgGFAEPFbNfSrD10WbjZq/ZLLjeyDPSepnvJ2vXeC6z6uRtRCZ85vSWsA+Qu xSj1vysMYlMZUY7dSfIyVWRhACC27hMKFGeCEZ6+pf1xhiS6SJOXochx/3LTXk190aQ0 L3ZiwAuYzbu4PcatIVogyAANYdqZHQKwkYQ1Xg6EDgu8ftwrqnzV7j3IkNCHpt6CZbK4 nXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qtCE7jonGK+7NebnXrOPLBttVq28Cf6oUZgL1KGrk/M=; b=HYRBOgcShRdvbegYjM1XDIB5PNtaay964hpQ52+krEeOAa9MKnk7JRYBS32GqwQjm4 R8APxx3k7OxuGxW6qpCZ9xI1QtzoITMaxHF+WwQbO0/EjhH2sgIYNeyYwdBgYrZR8Jcm mphD/pamviGnFmzoy2l2PNokWvOt8Lwt9Rz+TiIq+M8OwUYEXIf4qwU3XvyCr1iTLm3E RqLboCjfi1fi6eAE8sSZrXXAU280bHErPe5k1YlwVXA6aKtf8eizLT3/qdQtGuc4x/vi Ig1pitfiotF+NG5RlgOXjpcZJDsWaa5PVBcLDIZ+4dL91EAOBjSFTU1t47K0mtfKExZI R5KA== X-Gm-Message-State: AOAM531yC0JOIbKRaGBQUuMAxB5YZawRD/JSpkhbEsPTjBddRsVSLOBm zoMgm3urvdEIWE6GR9GHm8Y= X-Google-Smtp-Source: ABdhPJxPO6dQX2xPy5zHAQLRFlT46jR0wnx3KgNLEvUGrqdlQxY3gqyX5EQiNXBlouZusogy5qC+9w== X-Received: by 2002:ac8:58d6:: with SMTP id u22mr23618085qta.7.1635248076975; Tue, 26 Oct 2021 04:34:36 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:36 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/8] drm: vkms: Add fb information to `vkms_writeback_job` Date: Tue, 26 Oct 2021 08:34:04 -0300 Message-Id: <20211026113409.7242-5-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This commit is the groundwork to introduce new formats to the planes and writeback buffer. As part of it, a new buffer metadata field is added to `vkms_writeback_job`, this metadata is represented by the `vkms_composer` struct. This will allow us, in the future, to have different compositing and wb format types. Signed-off-by: Igor Torrente --- V2: Change the code to get the drm_framebuffer reference and not copy its contents(Thomas Zimmermann). --- drivers/gpu/drm/vkms/vkms_composer.c | 4 ++-- drivers/gpu/drm/vkms/vkms_drv.h | 12 ++++++------ drivers/gpu/drm/vkms/vkms_plane.c | 10 +++++----- drivers/gpu/drm/vkms/vkms_writeback.c | 21 ++++++++++++++++++--- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 82f79e508f81..383ca657ddf7 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -153,7 +153,7 @@ static void compose_plane(struct vkms_composer *primary_composer, struct vkms_composer *plane_composer, void *vaddr_out) { - struct drm_framebuffer *fb = &plane_composer->fb; + struct drm_framebuffer *fb = plane_composer->fb; void *vaddr; void (*pixel_blend)(const u8 *p_src, u8 *p_dst); @@ -174,7 +174,7 @@ static int compose_active_planes(void **vaddr_out, struct vkms_composer *primary_composer, struct vkms_crtc_state *crtc_state) { - struct drm_framebuffer *fb = &primary_composer->fb; + struct drm_framebuffer *fb = primary_composer->fb; struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0); const void *vaddr; int i; diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 64e62993b06f..9e4c1e95bbb1 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -20,13 +20,8 @@ #define XRES_MAX 8192 #define YRES_MAX 8192 -struct vkms_writeback_job { - struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]; - struct dma_buf_map data[DRM_FORMAT_MAX_PLANES]; -}; - struct vkms_composer { - struct drm_framebuffer fb; + struct drm_framebuffer *fb; struct drm_rect src, dst; struct dma_buf_map map[DRM_FORMAT_MAX_PLANES]; unsigned int offset; @@ -34,6 +29,11 @@ struct vkms_composer { unsigned int cpp; }; +struct vkms_writeback_job { + struct dma_buf_map data[DRM_FORMAT_MAX_PLANES]; + struct vkms_composer composer; +}; + /** * vkms_plane_state - Driver specific plane state * @base: base plane state diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 32409e15244b..0a28cb7a85e2 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -50,12 +50,12 @@ static void vkms_plane_destroy_state(struct drm_plane *plane, struct vkms_plane_state *vkms_state = to_vkms_plane_state(old_state); struct drm_crtc *crtc = vkms_state->base.base.crtc; - if (crtc) { + if (crtc && vkms_state->composer->fb) { /* dropping the reference we acquired in * vkms_primary_plane_update() */ - if (drm_framebuffer_read_refcount(&vkms_state->composer->fb)) - drm_framebuffer_put(&vkms_state->composer->fb); + if (drm_framebuffer_read_refcount(vkms_state->composer->fb)) + drm_framebuffer_put(vkms_state->composer->fb); } kfree(vkms_state->composer); @@ -110,9 +110,9 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, composer = vkms_plane_state->composer; memcpy(&composer->src, &new_state->src, sizeof(struct drm_rect)); memcpy(&composer->dst, &new_state->dst, sizeof(struct drm_rect)); - memcpy(&composer->fb, fb, sizeof(struct drm_framebuffer)); + composer->fb = fb; memcpy(&composer->map, &shadow_plane_state->data, sizeof(composer->map)); - drm_framebuffer_get(&composer->fb); + drm_framebuffer_get(composer->fb); composer->offset = fb->offsets[0]; composer->pitch = fb->pitches[0]; composer->cpp = fb->format->cpp[0]; diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c index 8694227f555f..32734cdbf6c2 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -75,12 +75,15 @@ static int vkms_wb_prepare_job(struct drm_writeback_connector *wb_connector, if (!vkmsjob) return -ENOMEM; - ret = drm_gem_fb_vmap(job->fb, vkmsjob->map, vkmsjob->data); + ret = drm_gem_fb_vmap(job->fb, vkmsjob->composer.map, vkmsjob->data); if (ret) { DRM_ERROR("vmap failed: %d\n", ret); goto err_kfree; } + vkmsjob->composer.fb = job->fb; + drm_framebuffer_get(vkmsjob->composer.fb); + job->priv = vkmsjob; return 0; @@ -99,7 +102,10 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector, if (!job->fb) return; - drm_gem_fb_vunmap(job->fb, vkmsjob->map); + drm_gem_fb_vunmap(job->fb, vkmsjob->composer.map); + + if (drm_framebuffer_read_refcount(vkmsjob->composer.fb)) + drm_framebuffer_put(vkmsjob->composer.fb); vkmsdev = drm_device_to_vkms_device(job->fb->dev); vkms_set_composer(&vkmsdev->output, false); @@ -116,14 +122,23 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn, struct drm_writeback_connector *wb_conn = &output->wb_connector; struct drm_connector_state *conn_state = wb_conn->base.state; struct vkms_crtc_state *crtc_state = output->composer_state; + struct drm_framebuffer *fb = connector_state->writeback_job->fb; + struct vkms_writeback_job *active_wb; + struct vkms_composer *wb_composer; if (!conn_state) return; vkms_set_composer(&vkmsdev->output, true); + active_wb = conn_state->writeback_job->priv; + wb_composer = &active_wb->composer; + spin_lock_irq(&output->composer_lock); - crtc_state->active_writeback = conn_state->writeback_job->priv; + crtc_state->active_writeback = active_wb; + wb_composer->offset = fb->offsets[0]; + wb_composer->pitch = fb->pitches[0]; + wb_composer->cpp = fb->format->cpp[0]; crtc_state->wb_pending = true; spin_unlock_irq(&output->composer_lock); drm_writeback_queue_job(wb_conn, connector_state); From patchwork Tue Oct 26 11:34:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7ABD1C433F5 for ; Tue, 26 Oct 2021 11:34:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4B67E604E9 for ; Tue, 26 Oct 2021 11:34:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4B67E604E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 427B76E3EC; Tue, 26 Oct 2021 11:34:43 +0000 (UTC) Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A6A96E3EC for ; Tue, 26 Oct 2021 11:34:40 +0000 (UTC) Received: by mail-qt1-x836.google.com with SMTP id z24so13124446qtv.9 for ; Tue, 26 Oct 2021 04:34:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aY3LH0lI65RLzOt7MIGcFNyCUGeK9Gvq4WungNdLgNg=; b=XKzjMo1lRCpEbEAI/KcFfbLC90MtgRsqNs7LbvSavjixBVTII6kKU/mxlTun+CqYo6 rBIg2GL1sGR+rZ2HUrAfZlR1rrCRIpgtubnB3K34wxGfByM0lguULHxCNiswQdmY49xS 0HfXX9N1hFdUkLryuJimQwOVOcC+waWrD2Upx+HV9w6Fafo21CyRV/fHdqUX5MChRrwx b2jrkDopZEiy7h2x7TMWGzBOOsunPZjHBSM7gIdhNAxTW7wxrPtWTGyQVno1MGH4wK2f DIF1FAcCXDYaxbOCMCmZLgIgAWrDZk3Tha8XaW/h40F+iWXlmD+GFn5PWS6QthdCvwQL j6Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aY3LH0lI65RLzOt7MIGcFNyCUGeK9Gvq4WungNdLgNg=; b=ZbHTR2cC+g3edtRH/Xwv24Xg/S14t3T5V6+/z4MoWuaRDlUkQrYeZX6alxf4pL5sIl jKzLPVfcKb2CduCZJz7Xb5HmAG16dwDjcpgR4Cv6iW1JaoqJmyTw0z7Fn2Nw/Bea/cjL tChJ1HGLFX2F3H/kMejgjTrymcAMPcYIuhvjMmlEKB3tFr504LnBt6OBS9RU2quWvUAc QG5qiE42ASIzOF96pTqIXJlTM2Y5jujSpJtQ7P3Ka9JP+JxREUDrm1zr/NP2GS/uBCct xIUOpCNAEdxhEQiQtB2+q3ryOBh6RDYdd+Yb6VyYUhc9T7agr7tsRWYLQqZlp21BRSwG J70Q== X-Gm-Message-State: AOAM530ITGvCZMMVHbbZgZd6EmMCl50c35nFNVCMt+zFS/E5Q0Hvg+0V x6uaGZGZtjT8a16DLYNhkjs= X-Google-Smtp-Source: ABdhPJwDOFoWZjWZ3H1bzviKxHxAUcxuRxi+sdvFTGLdrUSEoA7e/RhfHR9Rt65avdQIX9uxAErB3g== X-Received: by 2002:a05:622a:449:: with SMTP id o9mr24009362qtx.141.1635248079645; Tue, 26 Oct 2021 04:34:39 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:39 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org Subject: [PATCH v2 5/8] drm: drm_atomic_helper: Add a new helper to deal with the writeback connector validation Date: Tue, 26 Oct 2021 08:34:05 -0300 Message-Id: <20211026113409.7242-6-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a helper function to validate the connector configuration receive in the encoder atomic_check by the drivers. So the drivers don't need do these common validations themselves. Signed-off-by: Igor Torrente --- V2: Move the format verification to a new helper at the drm_atomic_helper.c (Thomas Zimmermann). --- drivers/gpu/drm/drm_atomic_helper.c | 47 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_writeback.c | 9 +++-- include/drm/drm_atomic_helper.h | 3 ++ 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 2c0c6ec92820..c2653b9824b5 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -766,6 +766,53 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, } EXPORT_SYMBOL(drm_atomic_helper_check_modeset); +/** + * drm_atomic_helper_check_wb_connector_state() - Check writeback encoder state + * @encoder: encoder state to check + * @conn_state: connector state to check + * + * Checks if the wriback connector state is valid, and returns a erros if it + * isn't. + * + * RETURNS: + * Zero for success or -errno + */ +int +drm_atomic_helper_check_wb_encoder_state(struct drm_encoder *encoder, + struct drm_connector_state *conn_state) +{ + struct drm_writeback_job *wb_job = conn_state->writeback_job; + struct drm_property_blob *pixel_format_blob; + bool format_supported = false; + struct drm_framebuffer *fb; + int i, n_formats; + u32 *formats; + + if (!wb_job || !wb_job->fb) + return 0; + + pixel_format_blob = wb_job->connector->pixel_formats_blob_ptr; + n_formats = pixel_format_blob->length / sizeof(u32); + formats = pixel_format_blob->data; + fb = wb_job->fb; + + for (i = 0; i < n_formats; i++) { + if (fb->format->format == formats[i]) { + format_supported = true; + break; + } + } + + if (!format_supported) { + DRM_DEBUG_KMS("Invalid pixel format %p4cc\n", + &fb->format->format); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL(drm_atomic_helper_check_wb_encoder_state); + /** * drm_atomic_helper_check_plane_state() - Check plane state for validity * @plane_state: plane state to check diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c index 32734cdbf6c2..42f3396c523a 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -30,6 +30,7 @@ static int vkms_wb_encoder_atomic_check(struct drm_encoder *encoder, { struct drm_framebuffer *fb; const struct drm_display_mode *mode = &crtc_state->mode; + int ret; if (!conn_state->writeback_job || !conn_state->writeback_job->fb) return 0; @@ -41,11 +42,9 @@ static int vkms_wb_encoder_atomic_check(struct drm_encoder *encoder, return -EINVAL; } - if (fb->format->format != vkms_wb_formats[0]) { - DRM_DEBUG_KMS("Invalid pixel format %p4cc\n", - &fb->format->format); - return -EINVAL; - } + ret = drm_atomic_helper_check_wb_encoder_state(encoder, conn_state); + if (ret < 0) + return ret; return 0; } diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h index 4045e2507e11..3fbf695da60f 100644 --- a/include/drm/drm_atomic_helper.h +++ b/include/drm/drm_atomic_helper.h @@ -40,6 +40,9 @@ struct drm_private_state; int drm_atomic_helper_check_modeset(struct drm_device *dev, struct drm_atomic_state *state); +int +drm_atomic_helper_check_wb_encoder_state(struct drm_encoder *encoder, + struct drm_connector_state *conn_state); int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, const struct drm_crtc_state *crtc_state, int min_scale, From patchwork Tue Oct 26 11:34:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D788BC433EF for ; Tue, 26 Oct 2021 11:34:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB60C6008E for ; Tue, 26 Oct 2021 11:34:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AB60C6008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 451E36E42A; Tue, 26 Oct 2021 11:34:50 +0000 (UTC) Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by gabe.freedesktop.org (Postfix) with ESMTPS id CFEA96E427 for ; Tue, 26 Oct 2021 11:34:43 +0000 (UTC) Received: by mail-qk1-x731.google.com with SMTP id bk35so453323qkb.6 for ; Tue, 26 Oct 2021 04:34:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nFtKShrzA3NR3s2awMHDZ0WFl/JygTDUV5EP5Xutpkc=; b=qlscrwlc9HxHyth+6cp7K2GoS91Ii+A1CaEwvCs2H3qU4nCmEWznd3sHOi2STNi50P m4enipn1Y5968Tep5GA5h/VWPQTMtgoIfbbTGj4gdwzH0swtLpg/zEHmhEVotqqn3RKh uhjIYhn04z2/+sRK9VaxUGTmlaCh0hFjvNI9wfQY4+e3boqG3kbS6DwI6E0VRZKJGMoR ZvUDKwRnQeUktRB+KlkLFDYoJdBYuFISnvrenEoFmzB7j/waPn/9XOKGM8kNOlFKCAkl rThdTWJw05kVYpioM/PgerNVacuUEDW60E8gh0Sv09CL2h0NRMb/96/kShb+cnEmwW1D v3UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nFtKShrzA3NR3s2awMHDZ0WFl/JygTDUV5EP5Xutpkc=; b=X5l5yTy1lnTRKokC3UN1Mo75o/YQN6yxp+cvRHBOcrGKISaP9Lh+UXiQkzjllVOW/M T6Ie/lzrLIyw2D7IhSxiDHU+5NlJueqCRR3zj95WCEtQeCndEj7pZSroPQwayHRio4oA bClCKb0J9G4W8JXEJXgg9EJpjTX+bBId+JhwDB8yUaU/jawykKtiCz2Z+1KRQCVkThUp kgMPT125PsLgTmunXKjeWhDYp6xk8NXXBCLJinECfCvJX6hmSUDHF0RMxxiLOjMHsLP+ xBqE84u3RZO0xhCWPaXuhOFmfqlp9RU10Ual5jL1Ccp1z5/AP+ubeBt0A2+pv2wIDcMi WrZQ== X-Gm-Message-State: AOAM530L9jT21fR7a/VDf1a2z81cHjPzjIB3JHAYhevpQ/tr5FEg2rDg E3W55r42uivbEDhNLzX+y8A= X-Google-Smtp-Source: ABdhPJzN13FIKlfjkPGC28nF3L6KEE9BdHFCA+xmc1JeynkV0EC4t1XG+TVdsiYeQh3OFGcrGsqkoA== X-Received: by 2002:a37:a304:: with SMTP id m4mr18953025qke.111.1635248082755; Tue, 26 Oct 2021 04:34:42 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:42 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org, kernel test robot Subject: [PATCH v2 6/8] drm: vkms: Refactor the plane composer to accept new formats Date: Tue, 26 Oct 2021 08:34:06 -0300 Message-Id: <20211026113409.7242-7-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently the blend function only accepts XRGB_8888 and ARGB_8888 as a color input. This patch refactors all the functions related to the plane composition to overcome this limitation. Now the blend function receives a struct `vkms_pixel_composition_functions` containing two handlers. One will generate a buffer of each line of the frame with the pixels converted to ARGB16161616. And the other will take this line buffer, do some computation on it, and store the pixels in the destination. Both the handlers have the same signature. They receive a pointer to the pixels that will be processed(`pixels_addr`), the number of pixels that will be treated(`length`), and the intermediate buffer of the size of a frame line (`line_buffer`). The first function has been totally described previously. The second is more interesting, as it has to perform two roles depending on where it is called in the code. The first is to convert(if necessary) the data received in the `line_buffer` and write in the memory pointed by `pixels_addr`. The second role is to perform the `alpha_blend`. So, it takes the pixels in the `line_buffer` and `pixels_addr`, executes the blend, and stores the result back to the `pixels_addr`. The per-line implementation was chosen for performance reasons. The per-pixel functions were having performance issues due to indirect function call overhead. The per-line code trades off memory for execution time. The `line_buffer` allows us to diminish the number of function calls. Results in the IGT test `kms_cursor_crc`: | Frametime | |:---------------:|:---------:|:----------:|:--------:| | implmentation | Current | Per-pixel | Per-line | | frametime range | 8~22 ms | 32~56 ms | 6~19 ms | | Average | 10.0 ms | 35.8 ms | 8.6 ms | Reported-by: kernel test robot Signed-off-by: Igor Torrente --- V2: Improves the performance drastically, by perfoming the operations per-line and not per-pixel(Pekka Paalanen). Minor improvements(Pekka Paalanen). --- drivers/gpu/drm/vkms/vkms_composer.c | 321 ++++++++++++++++----------- drivers/gpu/drm/vkms/vkms_formats.h | 155 +++++++++++++ 2 files changed, 342 insertions(+), 134 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_formats.h diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 383ca657ddf7..69fe3a89bdc9 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -9,18 +9,26 @@ #include #include "vkms_drv.h" - -static u32 get_pixel_from_buffer(int x, int y, const u8 *buffer, - const struct vkms_composer *composer) -{ - u32 pixel; - int src_offset = composer->offset + (y * composer->pitch) - + (x * composer->cpp); - - pixel = *(u32 *)&buffer[src_offset]; - - return pixel; -} +#include "vkms_formats.h" + +#define get_output_vkms_composer(buffer_pointer, composer) \ + ((struct vkms_composer) { \ + .fb = &(struct drm_framebuffer) { \ + .format = &(struct drm_format_info) { \ + .format = DRM_FORMAT_ARGB16161616, \ + }, \ + }, \ + .map[0].vaddr = (buffer_pointer), \ + .src = (composer)->src, \ + .dst = (composer)->dst, \ + .cpp = sizeof(u64), \ + .pitch = drm_rect_width(&(composer)->dst) * sizeof(u64) \ + }) + +struct vkms_pixel_composition_functions { + void (*get_src_line)(void *pixels_addr, int length, u64 *line_buffer); + void (*set_output_line)(void *pixels_addr, int length, u64 *line_buffer); +}; /** * compute_crc - Compute CRC value on output frame @@ -31,179 +39,222 @@ static u32 get_pixel_from_buffer(int x, int y, const u8 *buffer, * returns CRC value computed using crc32 on the visible portion of * the final framebuffer at vaddr_out */ -static uint32_t compute_crc(const u8 *vaddr, +static uint32_t compute_crc(const __le64 *vaddr, const struct vkms_composer *composer) { - int x, y; - u32 crc = 0, pixel = 0; - int x_src = composer->src.x1 >> 16; - int y_src = composer->src.y1 >> 16; - int h_src = drm_rect_height(&composer->src) >> 16; - int w_src = drm_rect_width(&composer->src) >> 16; - - for (y = y_src; y < y_src + h_src; ++y) { - for (x = x_src; x < x_src + w_src; ++x) { - pixel = get_pixel_from_buffer(x, y, vaddr, composer); - crc = crc32_le(crc, (void *)&pixel, sizeof(u32)); - } - } + int h = drm_rect_height(&composer->dst); + int w = drm_rect_width(&composer->dst); - return crc; + return crc32_le(0, (void *)vaddr, w * h * sizeof(u64)); } -static u8 blend_channel(u8 src, u8 dst, u8 alpha) +static __le16 blend_channel(u16 src, u16 dst, u16 alpha) { - u32 pre_blend; - u8 new_color; + u64 pre_blend; + u16 new_color; - pre_blend = (src * 255 + dst * (255 - alpha)); + pre_blend = (src * 0xffff + dst * (0xffff - alpha)); - /* Faster div by 255 */ - new_color = ((pre_blend + ((pre_blend + 257) >> 8)) >> 8); + new_color = DIV_ROUND_UP(pre_blend, 0xffff); - return new_color; + return cpu_to_le16(new_color); } /** * alpha_blend - alpha blending equation - * @argb_src: src pixel on premultiplied alpha mode - * @argb_dst: dst pixel completely opaque + * @src_composer: source framebuffer's metadata + * @dst_composer: destination framebuffer's metadata + * @y: The y coodinate(heigth) of the line that will be processed + * @line_buffer: The line with the pixels from src_compositor * * blend pixels using premultiplied blend formula. The current DRM assumption * is that pixel color values have been already pre-multiplied with the alpha * channel values. See more drm_plane_create_blend_mode_property(). Also, this * formula assumes a completely opaque background. + * + * For performance reasons this function also fetches the pixels from the + * destination of the frame line y. + * We use the information that one of the source pixels are in the output + * buffer to fetch it here instead of separate function. And because the + * output format is ARGB16161616, we know that they don't need to be + * converted. + * This save us a indirect function call for each line. */ -static void alpha_blend(const u8 *argb_src, u8 *argb_dst) +static void alpha_blend(void *pixels_addr, int length, u64 *line_buffer) { - u8 alpha; + __le16 *output_pixel = pixels_addr; + int i; - alpha = argb_src[3]; - argb_dst[0] = blend_channel(argb_src[0], argb_dst[0], alpha); - argb_dst[1] = blend_channel(argb_src[1], argb_dst[1], alpha); - argb_dst[2] = blend_channel(argb_src[2], argb_dst[2], alpha); -} + for (i = 0; i < length; i++) { + u16 src1_a = line_buffer[i] >> 48; + u16 src1_r = (line_buffer[i] >> 32) & 0xffff; + u16 src1_g = (line_buffer[i] >> 16) & 0xffff; + u16 src1_b = line_buffer[i] & 0xffff; -/** - * x_blend - blending equation that ignores the pixel alpha - * - * overwrites RGB color value from src pixel to dst pixel. - */ -static void x_blend(const u8 *xrgb_src, u8 *xrgb_dst) -{ - memcpy(xrgb_dst, xrgb_src, sizeof(u8) * 3); + u16 src2_r = le16_to_cpu(output_pixel[2]); + u16 src2_g = le16_to_cpu(output_pixel[1]); + u16 src2_b = le16_to_cpu(output_pixel[0]); + + output_pixel[0] = blend_channel(src1_b, src2_b, src1_a); + output_pixel[1] = blend_channel(src1_g, src2_g, src1_a); + output_pixel[2] = blend_channel(src1_r, src2_r, src1_a); + output_pixel[3] = 0xffff; + + output_pixel += 4; + } } /** - * blend - blend value at vaddr_src with value at vaddr_dst - * @vaddr_dst: destination address - * @vaddr_src: source address - * @dst_composer: destination framebuffer's metadata * @src_composer: source framebuffer's metadata - * @pixel_blend: blending equation based on plane format + * @dst_composer: destiny framebuffer's metadata + * @funcs: A struct containing all the composition functions(get_src_line, + * and set_output_pixel) + * @line_buffer: The line with the pixels from src_compositor * - * Blend the vaddr_src value with the vaddr_dst value using a pixel blend - * equation according to the supported plane formats DRM_FORMAT_(A/XRGB8888) - * and clearing alpha channel to an completely opaque background. This function - * uses buffer's metadata to locate the new composite values at vaddr_dst. + * Using the pixel_blend function passed as parameter, this function blends + * all pixels from src plane into a output buffer (with a blend function + * passed as parameter). + * Information of the output buffer is in the dst_composer parameter + * and the source plane in the src_composer. + * The get_src_line will use the src_composer to get the respective line, + * convert, and return it as ARGB_16161616. + * And finally, the blend function will receive the dst_composer, dst_composer, + * the line y coodinate, and the line buffer. Blend all pixels, and store the + * result in the output. * * TODO: completely clear the primary plane (a = 0xff) before starting to blend * pixel color values */ -static void blend(void *vaddr_dst, void *vaddr_src, +static void blend(struct vkms_composer *src_composer, struct vkms_composer *dst_composer, - struct vkms_composer *src_composer, - void (*pixel_blend)(const u8 *, u8 *)) + struct vkms_pixel_composition_functions *funcs, + u64 *line_buffer) { - int i, j, j_dst, i_dst; - int offset_src, offset_dst; - u8 *pixel_dst, *pixel_src; + int i, i_dst; int x_src = src_composer->src.x1 >> 16; int y_src = src_composer->src.y1 >> 16; int x_dst = src_composer->dst.x1; int y_dst = src_composer->dst.y1; + int h_dst = drm_rect_height(&src_composer->dst); - int w_dst = drm_rect_width(&src_composer->dst); + int length = drm_rect_width(&src_composer->dst); int y_limit = y_src + h_dst; - int x_limit = x_src + w_dst; - - for (i = y_src, i_dst = y_dst; i < y_limit; ++i) { - for (j = x_src, j_dst = x_dst; j < x_limit; ++j) { - offset_dst = dst_composer->offset - + (i_dst * dst_composer->pitch) - + (j_dst++ * dst_composer->cpp); - offset_src = src_composer->offset - + (i * src_composer->pitch) - + (j * src_composer->cpp); - - pixel_src = (u8 *)(vaddr_src + offset_src); - pixel_dst = (u8 *)(vaddr_dst + offset_dst); - pixel_blend(pixel_src, pixel_dst); - /* clearing alpha channel (0xff)*/ - pixel_dst[3] = 0xff; - } - i_dst++; + + u8 *src_pixels = packed_pixels_addr(src_composer, x_src, y_src); + u8 *dst_pixels = packed_pixels_addr(dst_composer, x_dst, y_dst); + + int src_next_line_offset = src_composer->pitch; + int dst_next_line_offset = dst_composer->pitch; + + for (i = y_src, i_dst = y_dst; i < y_limit; ++i, i_dst++) { + funcs->get_src_line(src_pixels, length, line_buffer); + funcs->set_output_line(dst_pixels, length, line_buffer); + src_pixels += src_next_line_offset; + dst_pixels += dst_next_line_offset; } } -static void compose_plane(struct vkms_composer *primary_composer, - struct vkms_composer *plane_composer, - void *vaddr_out) +static void ((*get_line_fmt_transform_function(u32 format)) + (void *pixels_addr, int length, u64 *line_buffer)) { - struct drm_framebuffer *fb = plane_composer->fb; - void *vaddr; - void (*pixel_blend)(const u8 *p_src, u8 *p_dst); + if (format == DRM_FORMAT_ARGB8888) + return &ARGB8888_to_ARGB16161616; + else if (format == DRM_FORMAT_ARGB16161616) + return &get_ARGB16161616; + else + return &XRGB8888_to_ARGB16161616; +} - if (WARN_ON(dma_buf_map_is_null(&primary_composer->map[0]))) - return; +static void ((*get_output_line_function(u32 format)) + (void *pixels_addr, int length, u64 *line_buffer)) +{ + if (format == DRM_FORMAT_ARGB8888) + return &convert_to_ARGB8888; + else if (format == DRM_FORMAT_ARGB16161616) + return &convert_to_ARGB16161616; + else + return &convert_to_XRGB8888; +} - vaddr = plane_composer->map[0].vaddr; +static void compose_plane(struct vkms_composer *src_composer, + struct vkms_composer *dst_composer, + struct vkms_pixel_composition_functions *funcs, + u64 *line_buffer) +{ + u32 src_format = src_composer->fb->format->format; - if (fb->format->format == DRM_FORMAT_ARGB8888) - pixel_blend = &alpha_blend; - else - pixel_blend = &x_blend; + funcs->get_src_line = get_line_fmt_transform_function(src_format); - blend(vaddr_out, vaddr, primary_composer, plane_composer, pixel_blend); + blend(src_composer, dst_composer, funcs, line_buffer); } -static int compose_active_planes(void **vaddr_out, - struct vkms_composer *primary_composer, - struct vkms_crtc_state *crtc_state) +static __le64 *compose_active_planes(struct vkms_composer *primary_composer, + struct vkms_crtc_state *crtc_state, + u64 *line_buffer) { - struct drm_framebuffer *fb = primary_composer->fb; - struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0); - const void *vaddr; + struct vkms_plane_state **active_planes = crtc_state->active_planes; + int h = drm_rect_height(&primary_composer->dst); + int w = drm_rect_width(&primary_composer->dst); + struct vkms_pixel_composition_functions funcs; + struct vkms_composer dst_composer; + __le64 *vaddr_out; int i; - if (!*vaddr_out) { - *vaddr_out = kvzalloc(gem_obj->size, GFP_KERNEL); - if (!*vaddr_out) { - DRM_ERROR("Cannot allocate memory for output frame."); - return -ENOMEM; - } - } - if (WARN_ON(dma_buf_map_is_null(&primary_composer->map[0]))) - return -EINVAL; + return NULL; - vaddr = primary_composer->map[0].vaddr; + vaddr_out = kvzalloc(w * h * sizeof(__le64), GFP_KERNEL); + if (!vaddr_out) { + DRM_ERROR("Cannot allocate memory for output frame."); + return NULL; + } - memcpy(*vaddr_out, vaddr, gem_obj->size); + dst_composer = get_output_vkms_composer(vaddr_out, primary_composer); + funcs.set_output_line = get_output_line_function(DRM_FORMAT_ARGB16161616); + compose_plane(active_planes[0]->composer, &dst_composer, + &funcs, line_buffer); /* If there are other planes besides primary, we consider the active * planes should be in z-order and compose them associatively: * ((primary <- overlay) <- cursor) */ + funcs.set_output_line = alpha_blend; for (i = 1; i < crtc_state->num_active_planes; i++) - compose_plane(primary_composer, - crtc_state->active_planes[i]->composer, - *vaddr_out); + compose_plane(active_planes[i]->composer, &dst_composer, + &funcs, line_buffer); - return 0; + return vaddr_out; +} + +static void write_wb_buffer(struct vkms_writeback_job *active_wb, + struct vkms_composer *primary_composer, + __le64 *vaddr_out, u64 *line_buffer) +{ + u32 dst_fb_format = active_wb->composer.fb->format->format; + struct vkms_pixel_composition_functions funcs; + struct vkms_composer src_composer; + + src_composer = get_output_vkms_composer(vaddr_out, primary_composer); + funcs.set_output_line = get_output_line_function(dst_fb_format); + active_wb->composer.src = primary_composer->src; + active_wb->composer.dst = primary_composer->dst; + + compose_plane(&src_composer, &active_wb->composer, &funcs, line_buffer); +} + +u64 *alloc_line_buffer(struct vkms_composer *primary_composer) +{ + int line_width = drm_rect_width(&primary_composer->dst); + u64 *line_buffer; + + line_buffer = kvmalloc(line_width * sizeof(u64), GFP_KERNEL); + if (!line_buffer) + DRM_ERROR("Cannot allocate memory for intermediate line buffer"); + + return line_buffer; } /** @@ -221,14 +272,14 @@ void vkms_composer_worker(struct work_struct *work) struct vkms_crtc_state, composer_work); struct drm_crtc *crtc = crtc_state->base.crtc; + struct vkms_writeback_job *active_wb = crtc_state->active_writeback; struct vkms_output *out = drm_crtc_to_vkms_output(crtc); struct vkms_composer *primary_composer = NULL; struct vkms_plane_state *act_plane = NULL; + u64 frame_start, frame_end, *line_buffer; bool crc_pending, wb_pending; - void *vaddr_out = NULL; + __le64 *vaddr_out = NULL; u32 crc32 = 0; - u64 frame_start, frame_end; - int ret; spin_lock_irq(&out->composer_lock); frame_start = crtc_state->frame_start; @@ -256,28 +307,30 @@ void vkms_composer_worker(struct work_struct *work) if (!primary_composer) return; - if (wb_pending) - vaddr_out = crtc_state->active_writeback->data[0].vaddr; + line_buffer = alloc_line_buffer(primary_composer); + if (!line_buffer) + return; - ret = compose_active_planes(&vaddr_out, primary_composer, - crtc_state); - if (ret) { - if (ret == -EINVAL && !wb_pending) - kvfree(vaddr_out); + vaddr_out = compose_active_planes(primary_composer, crtc_state, + line_buffer); + if (!vaddr_out) { + kvfree(line_buffer); return; } - crc32 = compute_crc(vaddr_out, primary_composer); - if (wb_pending) { + write_wb_buffer(active_wb, primary_composer, + vaddr_out, line_buffer); drm_writeback_signal_completion(&out->wb_connector, 0); spin_lock_irq(&out->composer_lock); crtc_state->wb_pending = false; spin_unlock_irq(&out->composer_lock); - } else { - kvfree(vaddr_out); } + kvfree(line_buffer); + crc32 = compute_crc(vaddr_out, primary_composer); + kvfree(vaddr_out); + /* * The worker can fall behind the vblank hrtimer, make sure we catch up. */ diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkms_formats.h new file mode 100644 index 000000000000..5b850fce69f3 --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -0,0 +1,155 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _VKMS_FORMATS_H_ +#define _VKMS_FORMATS_H_ + +#include + +#define pixel_offset(composer, x, y) \ + ((composer)->offset + ((y) * (composer)->pitch) + ((x) * (composer)->cpp)) + +/* + * packed_pixels_addr - Get the pointer to pixel of a given pair of coordinates + * + * @composer: Buffer metadata + * @x: The x(width) coordinate of the 2D buffer + * @y: The y(Heigth) coordinate of the 2D buffer + * + * Takes the information stored in the composer, a pair of coordinates, and + * returns the address of the first color channel. + * This function assumes the channels are packed together, i.e. a color channel + * comes immediately after another. And therefore, this function doesn't work + * for YUV with chroma subsampling (e.g. YUV420 and NV21). + */ +static void *packed_pixels_addr(struct vkms_composer *composer, int x, int y) +{ + int offset = pixel_offset(composer, x, y); + + return (u8 *)composer->map[0].vaddr + offset; +} + +static void ARGB8888_to_ARGB16161616(void *pixels_addr, int length, + u64 *line_buffer) +{ + u8 *src_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + /* + * Organizes the channels in their respective positions and converts + * the 8 bits channel to 16. + * The 257 is the "conversion ratio". This number is obtained by the + * (2^16 - 1) / (2^8 - 1) division. Which, in this case, tries to get + * the best color value in a pixel format with more possibilities. + * And a similar idea applies to others RGB color conversions. + */ + line_buffer[i] = ((u64)src_pixels[3] * 257) << 48 | + ((u64)src_pixels[2] * 257) << 32 | + ((u64)src_pixels[1] * 257) << 16 | + ((u64)src_pixels[0] * 257); + + src_pixels += 4; + } +} + +static void XRGB8888_to_ARGB16161616(void *pixels_addr, int length, + u64 *line_buffer) +{ + u8 *src_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + /* + * The same as the ARGB8888 but with the alpha channel as the + * maximum value as possible. + */ + line_buffer[i] = 0xffffllu << 48 | + ((u64)src_pixels[2] * 257) << 32 | + ((u64)src_pixels[1] * 257) << 16 | + ((u64)src_pixels[0] * 257); + + src_pixels += 4; + } +} + +static void get_ARGB16161616(void *pixels_addr, int length, u64 *line_buffer) +{ + __le64 *src_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + /* + * Because the format byte order is in little-endian and this code + * needs to run on big-endian machines too, we need modify + * the byte order from little-endian to the CPU native byte order. + */ + line_buffer[i] = le64_to_cpu(*src_pixels); + + src_pixels++; + } +} + +/* + * The following functions are used as blend operations. But unlike the + * `alpha_blend`, these functions take an ARGB16161616 pixel from the + * source, convert it to a specific format, and store it in the destination. + * + * They are used in the `compose_active_planes` and `write_wb_buffer` to + * copy and convert one line of the frame from/to the output buffer to/from + * another buffer (e.g. writeback buffer, primary plane buffer). + */ + +static void convert_to_ARGB8888(void *pixels_addr, int length, u64 *line_buffer) +{ + u8 *dst_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + /* + * This sequence below is important because the format's byte order is + * in little-endian. In the case of the ARGB8888 the memory is + * organized this way: + * + * | Addr | = blue channel + * | Addr + 1 | = green channel + * | Addr + 2 | = Red channel + * | Addr + 3 | = Alpha channel + */ + dst_pixels[0] = DIV_ROUND_UP(line_buffer[i] & 0xffff, 257); + dst_pixels[1] = DIV_ROUND_UP((line_buffer[i] >> 16) & 0xffff, 257); + dst_pixels[2] = DIV_ROUND_UP((line_buffer[i] >> 32) & 0xffff, 257); + dst_pixels[3] = DIV_ROUND_UP(line_buffer[i] >> 48, 257); + + dst_pixels += 4; + } +} + +static void convert_to_XRGB8888(void *pixels_addr, int length, u64 *line_buffer) +{ + u8 *dst_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + dst_pixels[0] = DIV_ROUND_UP(line_buffer[i] & 0xffff, 257); + dst_pixels[1] = DIV_ROUND_UP((line_buffer[i] >> 16) & 0xffff, 257); + dst_pixels[2] = DIV_ROUND_UP((line_buffer[i] >> 32) & 0xffff, 257); + dst_pixels[3] = 0xff; + + dst_pixels += 4; + } +} + +static void convert_to_ARGB16161616(void *pixels_addr, int length, + u64 *line_buffer) +{ + __le64 *dst_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + + *dst_pixels = cpu_to_le64(line_buffer[i]); + dst_pixels++; + } +} + +#endif /* _VKMS_FORMATS_H_ */ From patchwork Tue Oct 26 11:34:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBDEAC433EF for ; Tue, 26 Oct 2021 11:34:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B82756008E for ; Tue, 26 Oct 2021 11:34:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B82756008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0B6A96E427; Tue, 26 Oct 2021 11:34:49 +0000 (UTC) Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by gabe.freedesktop.org (Postfix) with ESMTPS id 71B596E427 for ; Tue, 26 Oct 2021 11:34:46 +0000 (UTC) Received: by mail-qk1-x735.google.com with SMTP id y10so14696903qkp.9 for ; Tue, 26 Oct 2021 04:34:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vTJgeD6lPy222typZ3Q5onBN26bymP3kzPrhRNt/7Mo=; b=KDe0MfD2koim2vHX+9GOptZ2LW7K5thZqu3549FLJTOjnzbu2Q1Cwj0Cjmk1qqVuSC xIlaPU55tXWX/eHlPOwt73DSm88Bw5LMDCOQMjQmDBGPKHIO0Lge8HhhTsHUGJCYAVlC lFaL4vu1MhcA+Jeh1LuuGmKvxFlqvmO/vhkYr2fZJbnhl7jo+SJYRImV7k5TKxSS8T51 BIxfAOBMF7caU7heVDzr+0Xqh2Q3Rv4NNa2PsMC33D+G12py3utArogJrceI0SuKPOET 4o6zE1dVqHW5S82MqvKbOPXnNfEUhoHbOgQeC+cFG239/8Wucgo1MgwN5rxikAItY8hU yMqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vTJgeD6lPy222typZ3Q5onBN26bymP3kzPrhRNt/7Mo=; b=XvRQjNfgDzI+CnQippA+izKnp3uSmv0ZveS2oUVru3k4Ke+luh626rP8gI6CTJ9Jty 06lNw82sSL2jN9GYy0K5ahyMjYY9weIo09/r0TwiCimJyXMgSZwkvioVUPC07LvaEyvO WBe518wUtEgRsjik/t96tsuWrho00Pj4moC2vfGhl5vzidOL+vIKE2VJp/xP6Z/8DXy8 oH+W8cLWIuuR9sCS4m7QNZfzwq8B7BKcZfXM9LqFZEpebFjtM1oFiYtyhj33aoa0wSgE IK9o1pXShh/mJ/us2uvk+bwDOxaS0ch2k7W7xEKpnuZ7sQWaV4lAbedUVNMfEvdEkp3H 5mbA== X-Gm-Message-State: AOAM533es9EuqDc79ijf2lv1cFloYTRkrYKXRQTKGPtDzZPG/HFQmB+j rw66lENfR7n/PMXXgJr6/QWEYPi6HGA= X-Google-Smtp-Source: ABdhPJxQdIeynOqG+nQtjuB9AzqwIdpqxvw8lfJDMHez3M/aMJPUvXmHDeieTSQJA2/6KBhyDUOeAg== X-Received: by 2002:a05:620a:244a:: with SMTP id h10mr13171982qkn.403.1635248085617; Tue, 26 Oct 2021 04:34:45 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:45 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org Subject: [PATCH v2 7/8] drm: vkms: Exposes ARGB_1616161616 and adds XRGB_16161616 formats Date: Tue, 26 Oct 2021 08:34:07 -0300 Message-Id: <20211026113409.7242-8-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This will be useful to write tests that depends on these formats. ARGB format is already used as the universal format for internal uses. Here we are just exposing it to the user space. XRGB follows the a similar implementation of the former format. Just overwriting the alpha channel. Signed-off-by: Igor Torrente --- drivers/gpu/drm/vkms/vkms_composer.c | 4 ++++ drivers/gpu/drm/vkms/vkms_formats.h | 25 +++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 5 ++++- drivers/gpu/drm/vkms/vkms_writeback.c | 2 ++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 69fe3a89bdc9..f16fcfc88cea 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -164,6 +164,8 @@ static void ((*get_line_fmt_transform_function(u32 format)) return &ARGB8888_to_ARGB16161616; else if (format == DRM_FORMAT_ARGB16161616) return &get_ARGB16161616; + else if (format == DRM_FORMAT_XRGB16161616) + return &XRGB16161616_to_ARGB16161616; else return &XRGB8888_to_ARGB16161616; } @@ -175,6 +177,8 @@ static void ((*get_output_line_function(u32 format)) return &convert_to_ARGB8888; else if (format == DRM_FORMAT_ARGB16161616) return &convert_to_ARGB16161616; + else if (format == DRM_FORMAT_XRGB16161616) + return &convert_to_XRGB16161616; else return &convert_to_XRGB8888; } diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkms_formats.h index 5b850fce69f3..aa433edd00bd 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -89,6 +89,19 @@ static void get_ARGB16161616(void *pixels_addr, int length, u64 *line_buffer) } } +static void XRGB16161616_to_ARGB16161616(void *pixels_addr, int length, + u64 *line_buffer) +{ + __le64 *src_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + line_buffer[i] = le64_to_cpu(*src_pixels) | (0xffffllu << 48); + + src_pixels++; + } +} + /* * The following functions are used as blend operations. But unlike the * `alpha_blend`, these functions take an ARGB16161616 pixel from the @@ -152,4 +165,16 @@ static void convert_to_ARGB16161616(void *pixels_addr, int length, } } +static void convert_to_XRGB16161616(void *pixels_addr, int length, + u64 *line_buffer) +{ + __le64 *dst_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + *dst_pixels = cpu_to_le64(line_buffer[i] | (0xffffllu << 48)); + dst_pixels++; + } +} + #endif /* _VKMS_FORMATS_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 0a28cb7a85e2..516e48b38806 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -13,11 +13,14 @@ static const u32 vkms_formats[] = { DRM_FORMAT_XRGB8888, + DRM_FORMAT_XRGB16161616 }; static const u32 vkms_plane_formats[] = { DRM_FORMAT_ARGB8888, - DRM_FORMAT_XRGB8888 + DRM_FORMAT_XRGB8888, + DRM_FORMAT_XRGB16161616, + DRM_FORMAT_ARGB16161616 }; static struct drm_plane_state * diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c index 42f3396c523a..0f7bb77f981e 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -14,6 +14,8 @@ static const u32 vkms_wb_formats[] = { DRM_FORMAT_XRGB8888, + DRM_FORMAT_XRGB16161616, + DRM_FORMAT_ARGB16161616 }; static const struct drm_connector_funcs vkms_wb_connector_funcs = { From patchwork Tue Oct 26 11:34:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Matheus Andrade Torrente X-Patchwork-Id: 12584649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2786C433FE for ; Tue, 26 Oct 2021 11:34:55 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 83DDE6008E for ; Tue, 26 Oct 2021 11:34:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 83DDE6008E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B19226E42F; Tue, 26 Oct 2021 11:34:50 +0000 (UTC) Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4108C6E42A for ; Tue, 26 Oct 2021 11:34:49 +0000 (UTC) Received: by mail-qk1-x72c.google.com with SMTP id bj31so14878942qkb.2 for ; Tue, 26 Oct 2021 04:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BpzB9psURBvhNvmXpPEQXb13hz7OsGQ74tdDzFCqOD4=; b=GXDL8pf6VLTBwZRBxzMJfKTsTcr0Netp0zWt3lU2zsSyJFqLVkkS2/NAaVI+yYrdbJ nv2qglrowxZnYGS7l7gmLxSwlVIe3WdOOIHtiSjBwqcw/IeWLmr94/Ot/8OeNNB+Ywcf lzwyhnEEz7C4uQCG8RRUrIh4hc8c7GK2ooTTzzy5Ll8u23wD1pGQZgaCb9SU9+HPCuRc A8e8mZSxU3im4WO6EC0dTPimgFWPCBOnPEMbZGj1PNEwbg0THpcr8vYM7ls53yX5xvXG AmJMrM4xbLevIc6Yq8/DlDJy29R2YY8w/i8kLBqCaQV0aPeA32DxBwU8KyN/jBnlcI2A Elzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BpzB9psURBvhNvmXpPEQXb13hz7OsGQ74tdDzFCqOD4=; b=fxbjv2u43MF+BY/kl2YTOR1//y+BhRVcAOrHGNI5LYhsMsIyTmdwWPF3R2A1/yzTQf UjI+LxgSwwmQOVCy2G/eRipIprsGI3/+l5zTajNINSIRoAuK+AeqepEt+X9E5M+b0pJ+ fk6GZS5PXOCXgfg6tC9nQ+BR/uTewlpE8AKvF3Y+ha7BB78A/RbTsuR+GZtlgN3YKvcU 8CU5kTc/VQX1altYV5MZ9JewsG/J4Yak98sNEX0KhZiCzschHMEmPkBU1Dn17VQr4Plc g12k0K29/CAoIcXWMroNJO+Dm3VCUz1jdx/u07onGdKKn+y7Wnv0O9X5P+KevRkvXy57 QmSw== X-Gm-Message-State: AOAM530OXgqJG5M/kIjmBCx2YqGqOERRaBG2CDMTf71Q9DVoPb/9Gt6l KswKm2N14ZljML04VCaHXE4= X-Google-Smtp-Source: ABdhPJwTt1Btc3rYbvaHDdJEFrwttZSfHy5RAuJQKD6wxekYKq3IlBd2Q50hxF6KarbzOl9TAqKCew== X-Received: by 2002:a37:9606:: with SMTP id y6mr18046734qkd.13.1635248088339; Tue, 26 Oct 2021 04:34:48 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f4:5469:b11e:67b8:49d2:1744]) by smtp.googlemail.com with ESMTPSA id f3sm11117691qko.32.2021.10.26.04.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 04:34:48 -0700 (PDT) From: Igor Torrente To: rodrigosiqueiramelo@gmail.com, melissa.srw@gmail.com, ppaalanen@gmail.com, tzimmermann@suse.de Cc: Igor Torrente , hamohammed.sa@gmail.com, daniel@ffwll.ch, airlied@linux.ie, contact@emersion.fr, leandro.ribeiro@collabora.com, dri-devel@lists.freedesktop.org Subject: [PATCH v2 8/8] drm: vkms: Add support the RGB565 format Date: Tue, 26 Oct 2021 08:34:08 -0300 Message-Id: <20211026113409.7242-9-igormtorrente@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211026113409.7242-1-igormtorrente@gmail.com> References: <20211026113409.7242-1-igormtorrente@gmail.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Adds this common format to vkms. This commit also adds new helper macros to deal with fixed-point arithmetic. It was done to improve the precision of the conversion to ARGB16161616 since the "conversion ratio" is not an integer. Signed-off-by: Igor Torrente --- drivers/gpu/drm/vkms/vkms_composer.c | 4 ++ drivers/gpu/drm/vkms/vkms_formats.h | 72 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 6 ++- drivers/gpu/drm/vkms/vkms_writeback.c | 3 +- 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index f16fcfc88cea..57ec82839a89 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -166,6 +166,8 @@ static void ((*get_line_fmt_transform_function(u32 format)) return &get_ARGB16161616; else if (format == DRM_FORMAT_XRGB16161616) return &XRGB16161616_to_ARGB16161616; + else if (format == DRM_FORMAT_RGB565) + return &RGB565_to_ARGB16161616; else return &XRGB8888_to_ARGB16161616; } @@ -179,6 +181,8 @@ static void ((*get_output_line_function(u32 format)) return &convert_to_ARGB16161616; else if (format == DRM_FORMAT_XRGB16161616) return &convert_to_XRGB16161616; + else if (format == DRM_FORMAT_RGB565) + return &convert_to_RGB565; else return &convert_to_XRGB8888; } diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkms_formats.h index aa433edd00bd..1e2db1a844aa 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -8,6 +8,26 @@ #define pixel_offset(composer, x, y) \ ((composer)->offset + ((y) * (composer)->pitch) + ((x) * (composer)->cpp)) +/* + * FP stands for _Fixed Point_ and **not** _Float Point_ + * LF stands for Long Float (i.e. double) + * The following macros help doing fixed point arithmetic. + */ +/* + * With FP scale 15 we have 17 and 15 bits of integer and fractional parts + * respectively. + * | 0000 0000 0000 0000 0.000 0000 0000 0000 | + * 31 0 + */ +#define FP_SCALE 15 + +#define LF_TO_FP(a) ((a) * (u64)(1 << FP_SCALE)) +#define INT_TO_FP(a) ((a) << FP_SCALE) +#define FP_MUL(a, b) ((s32)(((s64)(a) * (b)) >> FP_SCALE)) +#define FP_DIV(a, b) ((s32)(((s64)(a) << FP_SCALE) / (b))) +/* This macro converts a fixed point number to int, and round half up it */ +#define FP_TO_INT_ROUND_UP(a) (((a) + (1 << (FP_SCALE - 1))) >> FP_SCALE) + /* * packed_pixels_addr - Get the pointer to pixel of a given pair of coordinates * @@ -102,6 +122,35 @@ static void XRGB16161616_to_ARGB16161616(void *pixels_addr, int length, } } +static void RGB565_to_ARGB16161616(void *pixels_addr, int length, + u64 *line_buffer) +{ + __le16 *src_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + u16 rgb_565 = le16_to_cpu(*src_pixels); + int fp_r = INT_TO_FP((rgb_565 >> 11) & 0x1f); + int fp_g = INT_TO_FP((rgb_565 >> 5) & 0x3f); + int fp_b = INT_TO_FP(rgb_565 & 0x1f); + + /* + * The magic constants is the "conversion ratio" and is calculated + * dividing 65535(2^16 - 1) by 31(2^5 -1) and 63(2^6 - 1) respectively. + */ + int fp_rb_ratio = LF_TO_FP(2114.032258065); + int fp_g_ratio = LF_TO_FP(1040.238095238); + + u64 r = FP_TO_INT_ROUND_UP(FP_MUL(fp_r, fp_rb_ratio)); + u64 g = FP_TO_INT_ROUND_UP(FP_MUL(fp_g, fp_g_ratio)); + u64 b = FP_TO_INT_ROUND_UP(FP_MUL(fp_b, fp_rb_ratio)); + + line_buffer[i] = 0xffffllu << 48 | r << 32 | g << 16 | b; + + src_pixels++; + } +} + /* * The following functions are used as blend operations. But unlike the * `alpha_blend`, these functions take an ARGB16161616 pixel from the @@ -177,4 +226,27 @@ static void convert_to_XRGB16161616(void *pixels_addr, int length, } } +static void convert_to_RGB565(void *pixels_addr, int length, + u64 *line_buffer) +{ + __le16 *dst_pixels = pixels_addr; + int i; + + for (i = 0; i < length; i++) { + int fp_r = INT_TO_FP((line_buffer[i] >> 32) & 0xffff); + int fp_g = INT_TO_FP((line_buffer[i] >> 16) & 0xffff); + int fp_b = INT_TO_FP(line_buffer[i] & 0xffffllu); + + int fp_rb_ratio = LF_TO_FP(2114.032258065); + int fp_g_ratio = LF_TO_FP(1040.238095238); + + u16 r = FP_TO_INT_ROUND_UP(FP_DIV(fp_r, fp_rb_ratio)); + u16 g = FP_TO_INT_ROUND_UP(FP_DIV(fp_g, fp_g_ratio)); + u16 b = FP_TO_INT_ROUND_UP(FP_DIV(fp_b, fp_rb_ratio)); + + *dst_pixels = cpu_to_le16(r << 11 | g << 5 | b); + dst_pixels++; + } +} + #endif /* _VKMS_FORMATS_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 516e48b38806..de250808aa39 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -13,14 +13,16 @@ static const u32 vkms_formats[] = { DRM_FORMAT_XRGB8888, - DRM_FORMAT_XRGB16161616 + DRM_FORMAT_XRGB16161616, + DRM_FORMAT_RGB565 }; static const u32 vkms_plane_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB16161616, - DRM_FORMAT_ARGB16161616 + DRM_FORMAT_ARGB16161616, + DRM_FORMAT_RGB565 }; static struct drm_plane_state * diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c index 0f7bb77f981e..11eb1be5a0fc 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -15,7 +15,8 @@ static const u32 vkms_wb_formats[] = { DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB16161616, - DRM_FORMAT_ARGB16161616 + DRM_FORMAT_ARGB16161616, + DRM_FORMAT_RGB565 }; static const struct drm_connector_funcs vkms_wb_connector_funcs = {