Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1886484lqo; Mon, 13 May 2024 01:01:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRbeiqdK9gPxRr7Ffr72+JL37zbr+AuWMy7Fz0lhpOVqK1XYWOhdsmn0r/bwil+EAd3kLBnazXzXIgpQTEd8l0W89Fljs9RgH5IxMagw== X-Google-Smtp-Source: AGHT+IG3Mfrlce+3/PHnVTZotuWHjkLjpA+zHtgdw1gp8bP59vqRj2cbWBaLqSKsVlEj97sIIpCV X-Received: by 2002:a05:6a00:4fc6:b0:6ec:ed90:65ea with SMTP id d2e1a72fcca58-6f4e0385c30mr10488171b3a.32.1715587261118; Mon, 13 May 2024 01:01:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715587261; cv=pass; d=google.com; s=arc-20160816; b=AW4Im9P/jAs5QI6k9LahWh/zjIool2RuS4wqhgghE+9IZfwP/vpomX+mtBb2IrUuLZ xQ1PNlEyMaLfJjX9yneXsEhOaykvKtyA4jKMRGCpVS5FlEQFgI5eugjT/uqQBbL+HEHR /EDXr48AB9qumpL82W4TqhEe1MXkfU9bSFQEuBFlr/UMXSQgrJUK3Cela6KhxEVJ3YZ6 UH1IjoSClsgm3nXcv5MPug17YBEwpGTDgnCQgYgMZUC6+mbvjrBh0XMHWSxIUwj9MlzN GRcn5w8jZXX/YfZ/ljL8HlMrvsas3LZnXKNeALhL9/zLN2Y1UKd8trdXGe/vtEaa4SRt y9lQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=qT71XLpmbf/fxDrbHr4V9B2UyQtLztqhPSk+Ws/EJcU=; fh=Qobrj7Y+D9wgq6uDoMzPfrxFbhCTKChuimkMa0d8zso=; b=OvFxwDHq55Iwx8MTbgKBA3XYqG14iwTcmQB7GKDr+LAcm67vESZVHgbmdHoD1xJbFE 174DLTeH3lwNDMRB4P7emKA3R2oxv3h7rIxJBM17COgPgOQ2UifCwZvIM+R99++RYACr KEfVdNAbgQmUqGj/TiB8kQbV3UeoWHUFVv6sQ7WbAMonSQNDGvsjkCGsbvCDshdpWW3V sIC4M/3JeCo2BJ06Ov5kIkKtUTx0ADOvww6BdL1e0VfaJ0vFyVmMMHJX5hfb+TDsMhN/ DZ5St3n/rCt33JsA/zvc7AaDMxcbAof/R1iBEPMVrUiDoVJdy7Y7//hsIKuOLonkr/td svgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=AfgYHzo8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-177304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177304-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-634103f5bd3si9460907a12.416.2024.05.13.01.01.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:01:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=AfgYHzo8; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-177304-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177304-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 906D12857EC for ; Mon, 13 May 2024 07:53:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAA0F14D29E; Mon, 13 May 2024 07:51:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="AfgYHzo8" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD31D14BFBF for ; Mon, 13 May 2024 07:51:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715586666; cv=none; b=JqLhw10yB7P2C5QAE15/fzR7UxPILD+7IhGBSgh39eLObfDwCZcpaaBGtA02Gvw6i7Fs16Cl9RmNuLgajBqlFFiIluEBek9oXhzpxpOPLY8Onj/T1+GVGX+M6vu4auJRiCYtSwp6UYvxrtMGFCYEPZ9DLHl0NIVwadGxgPLhxpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715586666; c=relaxed/simple; bh=HKmaIS+6cYtD2p4i1RftWm6LbG08lRAd2lgdmzQX0n4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XsBXQQodySm0qD96V0DzeS9Ay6i6FDe5vZhFHS4XiiVY+Cia1xcfKb6qWKlaLgTaqN4hl6NhfwNMBdfG61W61uqDZbIMEbuMLgjtynFJpC92lobrBmrrPKPWQA797qVtfCpW2+lwzUKQ8XIpcGBn49GsDKvFnpJnjILrc32Cpsg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=AfgYHzo8; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 6340E2000C; Mon, 13 May 2024 07:51:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715586663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qT71XLpmbf/fxDrbHr4V9B2UyQtLztqhPSk+Ws/EJcU=; b=AfgYHzo8ZUZtUR5adqLCq+NXOAxz8MnGWLVJ2MuoAvtq34NIBxOPRyP9YgWKMcQttbY6Wp hZKTw6wD//q/MDgeV9uQv9AyrVIjI7CwfWhoSnwpH9ZUgG89M/KaCsSyj7TwSEvESWQPCI vubIIaQgOqBREnX6RTet9Tgg5EQtstTLaU0VwK8I4xTL5PBEYC5kBazs570phP3U1DHtSB JorRD9PGPnjJhwpy2wG4BMJEcS36n+FJ/YYMnPHRvIPEs3QqIl4l27oBj78KkEkxfQjRV/ +x0i0ehtPsg1vlvqig7ziVr/rcF8lUwfiE/NlhrzjTAQHJsi8pyPpIjCItI2Jg== From: Louis Chauvet Date: Mon, 13 May 2024 09:50:38 +0200 Subject: [PATCH v7 17/17] drm/vkms: Add support for DRM_FORMAT_R* Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240513-yuv-v7-17-380e9ffec502@bootlin.com> References: <20240513-yuv-v7-0-380e9ffec502@bootlin.com> In-Reply-To: <20240513-yuv-v7-0-380e9ffec502@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet , Pekka Paalanen X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=6193; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=HKmaIS+6cYtD2p4i1RftWm6LbG08lRAd2lgdmzQX0n4=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmQcZF793QsIm7JQ9yQoJpE55VqpEyJbbJ+aORY BgpwbgIuY6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZkHGRQAKCRAgrS7GWxAs 4kZLEACGp32sHNeBQ+3qSUhYSNx9l5PRmBNs56jSdECAyUrQ2EHaBhzD5mEAtzns16PJwwCtDxn I+FXTJjnywtu4ONuGQAZWPiNJcMA5Dj1seGtBJRXwbP8VeH79nZ7QebI2xumdXbvr0S8h2V6f9Q WwYyJ6uJpsI2a+mCWlvvoWSfPMqfWniBGdrWnOTNGNIgNWiNHWQn+U1KKCRZ5DH39Br70LgDL8X u5rD2vIQs5I7DY++DBOnF1BIHqVpfkJdpzVquv5ie4BWh+MRA0yfujVIjYkI+N9F3FpLUnKuuB/ mhuTusSJHG879Ka9ojYM+gGdnxN4F25KjxkH6fdVoA2YuCzF4pPuxV5wuXuQb9rkYrSXRpwJ/QS xu8l0d4LGQVqi/e638HctijqC88jzsHm0308zGsYqTeuFGd+irRU5GcbBEDfqZEHRhsBk9uXYMd eIMBdCPmLfMXm1g9fY7zMMIzi0wNnoOlZ3Q7VEe5mkCnyy0KNA+JyARmWw3fOb9MT/wNWEyHYuh EWwHNR0HK26A0mx7YT5rClf8i01xm9zSuhXwNTqXjjadfxKIg9vqc7rrCx8EoK6+K98unClPIZA RsoIhyGLtgwfSO7Vh7ahSuPTVZwdEXlva4A88ftdzIKBvHbCFnbSUohSvIGDgGPUVpOBN/msUqL 16RB2k8UXSQ3bFw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com This add the support for: - R1/R2/R4/R8 R1 format was tested with [1] and [2]. [1]: https://lore.kernel.org/r/20240313-new_rotation-v2-0-6230fd5cae59@bootlin.com [2]: https://lore.kernel.org/igt-dev/20240306-b4-kms_tests-v1-0-8fe451efd2ac@bootlin.com/ Reviewed-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 105 +++++++++++++++++++++++++++++++++++- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++ 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c index 58c7192ce37d..06d74e39f756 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -237,6 +237,11 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(const u16 *pixel) return out_pixel; } +static struct pixel_argb_u16 argb_u16_from_gray16(u16 gray) +{ + return argb_u16_from_u16161616(255, gray, gray, gray); +} + VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, u8 channel_2, const struct conversion_matrix *matrix) { @@ -274,7 +279,7 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); * The following functions are read_line function for each pixel format supported by VKMS. * * They read a line starting at the point @x_start,@y_start following the @direction. The result - * is stored in @out_pixel and in the format ARGB16161616. + * is stored in @out_pixel and in a 64 bits format, see struct pixel_argb_u16. * * These functions are very repetitive, but the innermost pixel loops must be kept inside these * functions for performance reasons. Some benchmarking was done in [1] where having the innermost @@ -302,6 +307,96 @@ static void magenta_to_argb_u16(const struct vkms_plane_state *plane, int x_star } } +static void Rx_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end = out_pixel + count; + int bits_per_pixel = drm_format_info_bpp(plane->frame_info->fb->format, 0); + u8 *src_pixels; + int rem_x, rem_y; + + WARN_ONCE(drm_format_info_block_height(plane->frame_info->fb->format, 0) != 1, + "%s() only support formats with block_h == 1", __func__); + + packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, &rem_x, &rem_y); + int bit_offset = (8 - bits_per_pixel) - rem_x * bits_per_pixel; + int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); + int mask = (0x1 << bits_per_pixel) - 1; + int lum_per_level = 0xFFFF / mask; + + if (direction == READ_LEFT_TO_RIGHT || direction == READ_RIGHT_TO_LEFT) { + int restart_bit_offset; + int step_bit_offset; + + if (direction == READ_LEFT_TO_RIGHT) { + restart_bit_offset = 8 - bits_per_pixel; + step_bit_offset = -bits_per_pixel; + } else { + restart_bit_offset = 0; + step_bit_offset = bits_per_pixel; + } + + while (out_pixel < end) { + u8 val = ((*src_pixels) >> bit_offset) & mask; + + *out_pixel = argb_u16_from_gray16((int)val * lum_per_level); + + bit_offset += step_bit_offset; + if (bit_offset < 0 || 8 <= bit_offset) { + bit_offset = restart_bit_offset; + src_pixels += step; + } + out_pixel += 1; + } + } else if (direction == READ_TOP_TO_BOTTOM || direction == READ_BOTTOM_TO_TOP) { + while (out_pixel < end) { + u8 val = (*src_pixels >> bit_offset) & mask; + *out_pixel = argb_u16_from_gray16((int)val * lum_per_level); + src_pixels += step; + out_pixel += 1; + } + } +} + +static void R1_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R2_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R4_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); +} + +static void R8_read_line(const struct vkms_plane_state *plane, int x_start, + int y_start, enum pixel_read_direction direction, int count, + struct pixel_argb_u16 out_pixel[]) +{ + struct pixel_argb_u16 *end = out_pixel + count; + u8 *src_pixels; + int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); + + while (out_pixel < end) { + *out_pixel = argb_u16_from_gray16(*src_pixels); + src_pixels += step; + out_pixel += 1; + } +} + static void ARGB8888_read_line(const struct vkms_plane_state *plane, int x_start, int y_start, enum pixel_read_direction direction, int count, struct pixel_argb_u16 out_pixel[]) @@ -624,6 +719,14 @@ pixel_read_line_t get_pixel_read_line_function(u32 format) case DRM_FORMAT_YVU422: case DRM_FORMAT_YVU444: return &planar_yuv_read_line; + case DRM_FORMAT_R1: + return &R1_read_line; + case DRM_FORMAT_R2: + return &R2_read_line; + case DRM_FORMAT_R4: + return &R4_read_line; + case DRM_FORMAT_R8: + return &R8_read_line; default: /* * This is a bug in vkms_plane_atomic_check(). All the supported diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 8f764a108b00..67f891e7ac58 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -30,6 +30,10 @@ static const u32 vkms_formats[] = { DRM_FORMAT_YVU420, DRM_FORMAT_YVU422, DRM_FORMAT_YVU444, + DRM_FORMAT_R1, + DRM_FORMAT_R2, + DRM_FORMAT_R4, + DRM_FORMAT_R8, }; static struct drm_plane_state * -- 2.43.2