From nobody Sun Dec 14 21:37:47 2025 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 C7C89217F4E; Tue, 4 Feb 2025 17:06:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738688805; cv=none; b=aGTDF6x0CVydqoUPzILfzkbGwforubXK81PXLYIN4A+T8i5SDQ71kBvL9a3Ne8DEeV8Yn2fJFRSWv/bFfxts8zqrITUixEwTTh+dlfmcu5pWEI+w4FsGNmo1HqKLR74FT9NdLA/GvKZvI5JnpRO4vY/+8cWGwU7cc2jX2ezj53I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738688805; c=relaxed/simple; bh=PNS6jE8+jTWry2DjZN6o63/wHFqvUOxYr4mRZNl69fs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WwQdnpC1i5DK53nOQjHEOvwKEGnhk8UYprUE5Sq5RT2nP4MbeZXaSxKaz2WAmDQmpp33tzcoVkmEEl3x4CPsmejnuPG1Yj7LGpMXTEP4E4MiEO0neO8QErcVYtiYlyYqEXTsGH9+0nrVxkGvVuNMdnehvkuplFcLzlnkg/I8Y+A= 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=VmTBBXKU; arc=none smtp.client-ip=217.70.183.195 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="VmTBBXKU" Received: by mail.gandi.net (Postfix) with ESMTPSA id E8981204B7; Tue, 4 Feb 2025 17:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1738688801; 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=xEKfLiMa4LQvObfDXDJHazbN8jNm0C/l0epdXaXnwAo=; b=VmTBBXKUIb8nTMEYepM3HEhRCn6LOOXV4Kq6t/Cble7157foKvbVWjc+qgU3akKATMJVDs YRCIz0ssWjmu0irYpkzSdXTV19SCXTuTaCc7lcmlA9i354m2qD6q4yWB9LB7EFSP/pOJZj kXAGIR7mLIGEYJuK0H8Q33ZvUTdjeaKy4KarlyZJBWVTkHeU3vpi0S/AzIkxzOT5j6OztH r6yu2KOOG6jz5AL5Q/I8QAsvLjOOi2bMrxi1sxP9DzfCjnojqGvQ1DrNyHMERtCM00+O3W lEOKNWTLbc/74MJdOxfE0/k7T9LG5iDhdOleaN5+nOXH+HqFSXUtGrPbkm5Tiw== From: Louis Chauvet Date: Tue, 04 Feb 2025 18:06:18 +0100 Subject: [PATCH v17 7/7] 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: quoted-printable Message-Id: <20250204-yuv-v17-7-9c623880d0ac@bootlin.com> References: <20250204-yuv-v17-0-9c623880d0ac@bootlin.com> In-Reply-To: <20250204-yuv-v17-0-9c623880d0ac@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , rdunlap@infradead.org, arthurgrillo@riseup.net, Jonathan Corbet , pekka.paalanen@haloniitty.fi, Simona Vetter , Simona Vetter 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, linux-doc@vger.kernel.org, Louis Chauvet , Pekka Paalanen X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=6494; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=PNS6jE8+jTWry2DjZN6o63/wHFqvUOxYr4mRZNl69fs=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnokkVmhLUAbH64CAWYo+cBTKCeeAT/8lN9wz27 dprIZiPcD+JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ6JJFQAKCRAgrS7GWxAs 4nzND/9AnddKyZecL67kwIDFFOi9SQaWe7A/fM5UGwZDT4q1ALeWT8zs7ztpvjO7RL447Z0Vvd+ BIpzCK1liYBETU8AeGu3+3lt8mE76gq0zbMaQAhbOfyp1j3CezOisXK/kDUHVDLlf6MaabExDpB 351sa7V22QNZOROlP2VDkTdvUUrU2lZmODgYn3jJBUTUjT12rk0KXeh1n1QF9bjeIRymtwVp7ce RQcBAlyoOwjpO9iyZHKkh/IwBaZ7vI2QDxmUMkRr3jouDaOEEbFDh3gj/BwaXTPVY2ZMeCNFU4d PYDLAelv6DXXq+9wE447qNo6kwNhOd/bNUO2punRmSOT8SJa+MY/Ym/F1FImuJHVHVx2k1+C62D E/OcMgQ5kWwBqw+e17oiJGwvtkrOyWrylGj6obBXI/I4tE4t7lDoW1P+M+aJgQ5HBa0xm8PUgAc YDE9yuuKxpAxv12Z4Z5YJCuKp7/8axnpPLYbJthx/KPudrlXYPFNCP3GXTgDiymCyMwKgdmURC4 3biSv9jaGYicPfgxft6iSTw77J+o89+JsVMmVHwvSpfKJKUOK5zZ8ABQaB9mD6YzqJVvmHxb5V5 n/gjxNJxRdNjwTcwCdLWRgn8al1j1zQfc7Pa/wct7qirRhPc+AgboSYhP8M6sxB0ZCF5LkfrAhB RnmHzzhY4OlaqGA== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvuddtkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpefnohhuihhsucevhhgruhhvvghtuceolhhouhhishdrtghhrghuvhgvthessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepvdfgfefgheetgffhffetfffgheefteeltddvudeuieefvddtledtueehjeelfedtnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgdujedvrddukedrtddrudgnpdhmrghilhhfrhhomheplhhouhhishdrtghhrghuvhgvthessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdehpdhrtghpthhtoheprhhoughrihhgohhsihhquhgvihhrrghmvghlohesghhmrghilhdrtghomhdprhgtphhtthhopehlihhnuhigqdguohgtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghorhgsvghtsehlfihnrdhnvghtpdhrtghpthhtohepnhhitgholhgvjhgruggvhigvvgesghhoohhglhgvrdgtohhmpdhrtghpt hhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepmhhiqhhuvghlrdhrrgihnhgrlhessghoohhtlhhinhdrtghomhdprhgtphhtthhopehtiihimhhmvghrmhgrnhhnsehsuhhsvgdruggvpdhrtghpthhtohepphgvkhhkrgdrphgrrghlrghnvghnsegtohhllhgrsghorhgrrdgtohhm 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@boot= lin.com [2]: https://lore.kernel.org/igt-dev/20240306-b4-kms_tests-v1-0-8fe451efd2a= c@bootlin.com/ Reviewed-by: Pekka Paalanen Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 110 ++++++++++++++++++++++++++++++++= +++- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 9972780f3fa975ad8f5bcb71fa5c616071a8cf08..6d0227c6635adbedf28301672fb= 4b0a411c9e6df 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -249,6 +249,16 @@ static struct pixel_argb_u16 argb_u16_from_RGB565(cons= t __le16 *pixel) return out_pixel; } =20 +static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray) +{ + return argb_u16_from_u8888(255, gray, gray, gray); +} + +static struct pixel_argb_u16 argb_u16_from_grayu16(u16 gray) +{ + return argb_u16_from_u16161616(0xFFFF, gray, gray, gray); +} + VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 chann= el_1, u8 channel_2, const struct conversion_matrix *matrix) { @@ -286,7 +296,7 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); * The following functions are read_line function for each pixel format su= pported 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] wh= ere having the innermost @@ -295,6 +305,96 @@ EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); * [1]: https://lore.kernel.org/dri-devel/d258c8dc-78e9-4509-9037-a98f7f33= b3a3@riseup.net/ */ =20 +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 =3D out_pixel + count; + int bits_per_pixel =3D 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) = !=3D 1, + "%s() only support formats with block_h =3D=3D 1", __func__); + + packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, &= rem_x, &rem_y); + int bit_offset =3D (8 - bits_per_pixel) - rem_x * bits_per_pixel; + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + int mask =3D (0x1 << bits_per_pixel) - 1; + int lum_per_level =3D 0xFFFF / mask; + + if (direction =3D=3D READ_LEFT_TO_RIGHT || direction =3D=3D READ_RIGHT_TO= _LEFT) { + int restart_bit_offset; + int step_bit_offset; + + if (direction =3D=3D READ_LEFT_TO_RIGHT) { + restart_bit_offset =3D 8 - bits_per_pixel; + step_bit_offset =3D -bits_per_pixel; + } else { + restart_bit_offset =3D 0; + step_bit_offset =3D bits_per_pixel; + } + + while (out_pixel < end) { + u8 val =3D ((*src_pixels) >> bit_offset) & mask; + + *out_pixel =3D argb_u16_from_grayu16((int)val * lum_per_level); + + bit_offset +=3D step_bit_offset; + if (bit_offset < 0 || 8 <=3D bit_offset) { + bit_offset =3D restart_bit_offset; + src_pixels +=3D step; + } + out_pixel +=3D 1; + } + } else if (direction =3D=3D READ_TOP_TO_BOTTOM || direction =3D=3D READ_B= OTTOM_TO_TOP) { + while (out_pixel < end) { + u8 val =3D (*src_pixels >> bit_offset) & mask; + *out_pixel =3D argb_u16_from_grayu16((int)val * lum_per_level); + src_pixels +=3D step; + out_pixel +=3D 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 =3D out_pixel + count; + u8 *src_pixels; + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); + + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); + + while (out_pixel < end) { + *out_pixel =3D argb_u16_from_gray8(*src_pixels); + src_pixels +=3D step; + out_pixel +=3D 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[]) @@ -636,6 +736,14 @@ pixel_read_line_t get_pixel_read_line_function(u32 for= mat) 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 fbfbe424e558d781759c25a46e3b2b4ab082558c..e3fdd161d0f0a1d20c14a79dbe5= 1c08c8486d12f 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -31,6 +31,10 @@ static const u32 vkms_formats[] =3D { DRM_FORMAT_YVU420, DRM_FORMAT_YVU422, DRM_FORMAT_YVU444, + DRM_FORMAT_R1, + DRM_FORMAT_R2, + DRM_FORMAT_R4, + DRM_FORMAT_R8, }; =20 static struct drm_plane_state * --=20 2.48.1