From nobody Sun Feb 8 15:30:53 2026 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 670151AC44F for ; Thu, 29 Aug 2024 13:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938618; cv=none; b=VgL13zthqQ0FVhIqlW/WQvkjQXTyFAXpja0Jz9XfuRWaKSApEIlcDTe63WLBtFwUY1zR3EqUFHJZh1fY5WL8KNmWEcggTE2TKf1H2v/za/jvNMblGyRWeP3V4e/bATG+eGD1ovYpoQYV1g9um516fpgCqxpAKvFuZhkKFD41+7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724938618; c=relaxed/simple; bh=6mXsk6zG0mrAlCuZc3Y2pMCCXNNUGbUQQm730gsxblk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=TkVgLX4P2ChdLsyJPd/fWt0tb8pPsHhMIpaqBcM8geHNRNM1YZPxpQ6uoBjob5AX/Ep760jZ6US40GHkd40EHEp8bArDaADfRceIM9aKIR/cQ53pDXRq7cZddCBfdWiG1PicDqyaH4210KBQtOTKBN8pW57JuARX7SO1O37qMrA= 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=eKW7cP/b; arc=none smtp.client-ip=217.70.183.196 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="eKW7cP/b" Received: by mail.gandi.net (Postfix) with ESMTPSA id E81EBE000A; Thu, 29 Aug 2024 13:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1724938613; 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; bh=Y3RUvk6cKd1fBGlB64LeY6TLDxIiY15/3lHHLtlnvw4=; b=eKW7cP/bMblS78ZQD7HNe4sZCcT17bOF02Oef28YKIXpqDgcSzraYtRE37ZyTS+gf5BHjH f9KfOi2NuwU1q6czgxRwXJVhfhrXF+KYLUfCKz1X6Gc+WaDl8QVkMPqRXhDe1yp82VU/L1 reX7H1OJocBQrpdTrYxVeMYfiwv9IXAqaFz6PYgnkRXktXA4lhvC9RWzRqYXqI6B4evI8c VLV1GkGeeZjDuPYZ4VUFM+qLL3h3dFFNxAHmLjrMimIJDYb3D9LUyLJAX9mqQj9JnV18hs ++aapIdkcIJbCJg4/6ogJlzXONKWO3eW+zAhTU9Q13riHIVwgHhmFyXSuFJv2g== From: Louis Chauvet Date: Thu, 29 Aug 2024 15:36:51 +0200 Subject: [PATCH v3] drm/vkms: Add documentation 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: <20240829-google-clarifications-v3-1-f6604e2f6297@bootlin.com> X-B4-Tracking: v=1; b=H4sIAHJ50GYC/3WOS47CMBBErxJ5TYPtfGHFPRALf5rQUhKDbSIQy t0xRkgzC3ZdLb1X9WQBPWFgu+LJPM4UyE0plKuCmbOaegSyKTPJZcVryaF3rh8QzKA8nciomIA AFi121mgsO8USe/F4onv2Ho6f7PF6S/r4eTKtQrK4caS4K6wfYaRgNt8DJrxH9ibPFKLzjzxwF hnNWzpR/dgyC+BQIraNbS03sttr5+JA0zrVZecs/3hk88sjQYCs26qpa831Vvz3LMvyAompq88 +AQAA To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, 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 X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=15769; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=6mXsk6zG0mrAlCuZc3Y2pMCCXNNUGbUQQm730gsxblk=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBm0Hl0gQKQmnXN1x7gQxO9Trqa522OKtRPJNwAx DMhqiNUFO+JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZtB5dAAKCRAgrS7GWxAs 4jd3EADPWC3G0x3ihdIIvyx4jE3MwAboMQmtpItYg3+XeYhDZPssz/P5ZbouagwOmuHK0j/6B0M /7TGWxirwEMqySNaA0rND1t/ER/aAKSfTZ2C3U7x6SkebkobthlI7+AJBozvL/PFxPDWPW89wzC 4cepJPhVwYFaRLKuGx/FnxFHphwQgagAnGLLCMtCfYvnbDr/qiw6UofFJMK/UpK22TfZOoi9vt0 evIeg125kGrG4vP9nbUC2Z21GAc+vkBvWXj43XL9Ybcz8AzxRhUJjteR9pYkx9PUF7oEtH7bRu2 N/maF9An4LbDtrs5Csl8csMsWhIpH+rBv+QqEWSu9N5jQJWV4+7UOmMJWwMTsE6Zs1qPkSf9qy7 x38XVOEoPrXIp32GjeCJ4Z67C3E6879Hk+9VBLrBWh898gHcrXqufMuHn7YBuroIIQN3kPQFkpB fxXg3Otgt5jyI00bOlWvc7I/HDxqtlw4qv3+67Di4iLURxU46Qr7StVf1m9WjAjvCdSfr/o7GT1 2vPx+VjjAmIbVYaaRP9ox0p+nCi7ePoNbJlmH/1ocdC9IIvtLuxPdlH9L7+mDac0i+UsbI8EnUB n4O1nhayaOPjZtyvnGNnZ/qQ09m89gTtDjCH3mKd7YJRuZCZNS0xEnoj78OWl6hb8/MNxKMPRGf ufHD3Z7wsJ+PF+A== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Add documentation around vkms_output and its initialization. Add some documentation on pixel conversion functions. Update of outdated comments for pixel_write functions. Signed-off-by: Louis Chauvet Reviewed-by: Jos=C3=A9 Exp=C3=B3sito --- This series does not introduce functionnal changes, only some documentation and renaming to clarify the code. --- Changes in v3: - Merged https://lore.kernel.org/all/20240802-yuv-v9-3-08a706669e16@bootlin= .com/ as it also add documentation - Apply Jos=C3=A9's comments, sorry - Replace =3D1 by =3DBIT(0) for possible_crtc value - Link to v2: https://lore.kernel.org/r/20240826-google-clarifications-v2-1= -2574655b0b91@bootlin.com Changes in v2: - Dropped already applied patches - Dropped useless patch as its content is deleted later - Remove dependency on previous series - Apply Ma=C3=ADra's comments - Link to v1: https://lore.kernel.org/r/20240814-google-clarifications-v1-0= -3ee76d7d0c28@bootlin.com --- drivers/gpu/drm/vkms/vkms_composer.c | 7 +++ drivers/gpu/drm/vkms/vkms_drv.h | 101 ++++++++++++++++++++++++++++++-= ---- drivers/gpu/drm/vkms/vkms_formats.c | 62 +++++++++++++++++---- drivers/gpu/drm/vkms/vkms_output.c | 14 ++++- 4 files changed, 161 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vk= ms_composer.c index e7441b227b3c..57a5769fc994 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -189,6 +189,13 @@ static void blend(struct vkms_writeback_job *wb, =20 size_t crtc_y_limit =3D crtc_state->base.crtc->mode.vdisplay; =20 + /* + * The planes are composed line-by-line to avoid heavy memory usage. It i= s a necessary + * complexity to avoid poor blending performance. + * + * The function vkms_compose_row() is used to read a line, pixel-by-pixel= , into the staging + * buffer. + */ for (size_t y =3D 0; y < crtc_y_limit; y++) { fill_background(&background_color, output_buffer); =20 diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_dr= v.h index 5e46ea5b96dc..12a11976f2fc 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -25,6 +25,17 @@ =20 #define VKMS_LUT_SIZE 256 =20 +/** + * struct vkms_frame_info - Structure to store the state of a frame + * + * @fb: backing drm framebuffer + * @src: source rectangle of this frame in the source framebuffer, stored = in 16.16 fixed-point form + * @dst: destination rectangle in the crtc buffer, stored in whole pixel u= nits + * @map: see drm_shadow_plane_state@data + * @rotation: rotation applied to the source. + * + * @src and @dst should have the same size modulo the rotation. + */ struct vkms_frame_info { struct drm_framebuffer *fb; struct drm_rect src, dst; @@ -52,9 +63,11 @@ struct vkms_writeback_job { }; =20 /** - * vkms_plane_state - Driver specific plane state + * struct vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation + * @pixel_read: function to read a pixel in this plane. The creator of a s= truct vkms_plane_state + * must ensure that this pointer is valid */ struct vkms_plane_state { struct drm_shadow_plane_state base; @@ -73,29 +86,56 @@ struct vkms_color_lut { }; =20 /** - * vkms_crtc_state - Driver specific CRTC state + * struct vkms_crtc_state - Driver specific CRTC state + * * @base: base CRTC state * @composer_work: work struct to compose and add CRC entries - * @n_frame_start: start frame number for computed CRC - * @n_frame_end: end frame number for computed CRC + * + * @num_active_planes: Number of active planes + * @active_planes: List containing all the active planes (counted by + * @num_active_planes). They should be stored in z-order. + * @active_writeback: Current active writeback job + * @gamma_lut: Look up table for gamma used in this CRTC + * @crc_pending: Protected by @vkms_output.composer_lock, true when the fr= ame CRC is not computed + * yet. Used by vblank to detect if the composer is too slow. + * @wb_pending: Protected by @vkms_output.composer_lock, true when a write= back frame is requested. + * @frame_start: Protected by @vkms_output.composer_lock, saves the frame = number before the start + * of the composition process. + * @frame_end: Protected by @vkms_output.composer_lock, saves the last req= uested frame number. + * This is used to generate enough CRC entries when the composition= worker is too slow. */ struct vkms_crtc_state { struct drm_crtc_state base; struct work_struct composer_work; =20 int num_active_planes; - /* stack of active planes for crc computation, should be in z order */ struct vkms_plane_state **active_planes; struct vkms_writeback_job *active_writeback; struct vkms_color_lut gamma_lut; =20 - /* below four are protected by vkms_output.composer_lock */ bool crc_pending; bool wb_pending; u64 frame_start; u64 frame_end; }; =20 +/** + * struct vkms_output - Internal representation of all output components i= n VKMS + * + * @crtc: Base CRTC in DRM + * @encoder: DRM encoder used for this output + * @connector: DRM connector used for this output + * @wb_connecter: DRM writeback connector used for this output + * @vblank_hrtimer: Timer used to trigger the vblank + * @period_ns: vblank period, in nanoseconds, used to configure @vblank_hr= timer and to compute + * vblank timestamps + * @composer_workq: Ordered workqueue for @composer_state.composer_work. + * @lock: Lock used to protect concurrent access to the composer + * @composer_enabled: Protected by @lock, true when the VKMS composer is a= ctive (crc needed or + * writeback) + * @composer_state: Protected by @lock, current state of this VKMS output + * @composer_lock: Lock used internally to protect @composer_state members + */ struct vkms_output { struct drm_crtc crtc; struct drm_encoder encoder; @@ -103,28 +143,38 @@ struct vkms_output { struct drm_writeback_connector wb_connector; struct hrtimer vblank_hrtimer; ktime_t period_ns; - /* ordered wq for composer_work */ struct workqueue_struct *composer_workq; - /* protects concurrent access to composer */ spinlock_t lock; =20 - /* protected by @lock */ bool composer_enabled; struct vkms_crtc_state *composer_state; =20 spinlock_t composer_lock; }; =20 -struct vkms_device; - +/** + * struct vkms_config - General configuration for VKMS driver + * + * @writeback: If true, a writeback buffer can be attached to the CRTC + * @cursor: If true, a cursor plane is created in the VKMS device + * @overlay: If true, NUM_OVERLAY_PLANES will be created for the VKMS devi= ce + * @dev: Used to store the current VKMS device. Only set when the device i= s instantiated. + */ struct vkms_config { bool writeback; bool cursor; bool overlay; - /* only set when instantiated */ struct vkms_device *dev; }; =20 +/** + * struct vkms_device - Description of a VKMS device + * + * @drm - Base device in DRM + * @platform - Associated platform device + * @output - Configuration and sub-components of the VKMS device + * @config: Configuration used in this VKMS device + */ struct vkms_device { struct drm_device drm; struct platform_device *platform; @@ -132,6 +182,10 @@ struct vkms_device { const struct vkms_config *config; }; =20 +/* + * The following helpers are used to convert a member of a struct into its= parent. + */ + #define drm_crtc_to_vkms_output(target) \ container_of(target, struct vkms_output, crtc) =20 @@ -144,12 +198,33 @@ struct vkms_device { #define to_vkms_plane_state(target)\ container_of(target, struct vkms_plane_state, base.base) =20 -/* CRTC */ +/** + * vkms_crtc_init() - Initialize a CRTC for VKMS + * @dev: DRM device associated with the VKMS buffer + * @crtc: uninitialized CRTC device + * @primary: primary plane to attach to the CRTC + * @cursor plane to attach to the CRTC + */ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, struct drm_plane *primary, struct drm_plane *cursor); =20 +/** + * vkms_output_init() - Initialize all sub-components needed for a VKMS de= vice. + * + * @vkmsdev: VKMS device to initialize + * @index: CRTC which can be attached to the planes. The caller must ensur= e that + * @index is positive and less or equals to 31. + */ int vkms_output_init(struct vkms_device *vkmsdev, int index); =20 +/** + * vkms_plane_init() - Initialize a plane + * + * @vkmsdev: VKMS device containing the plane + * @type: type of plane to initialize + * @possible_crtc_index: CRTC which can be attached to the plane. The call= er must ensure that + * possible_crtc_index is positive and less or equals to 31. + */ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, enum drm_plane_type type, int index); =20 diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 040b7f113a3b..e8a5cc235ebb 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -9,24 +9,40 @@ =20 #include "vkms_formats.h" =20 +/** + * pixel_offset() - Get the offset of the pixel at coordinates x/y in the = first plane + * + * @frame_info: Buffer metadata + * @x: The x coordinate of the wanted pixel in the buffer + * @y: The y coordinate of the wanted pixel in the buffer + * + * The caller must ensure that the framebuffer associated with this reques= t uses a pixel format + * where block_h =3D=3D block_w =3D=3D 1. + * If this requirement is not fulfilled, the resulting offset can point to= an other pixel or + * outside of the buffer. + */ static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x= , int y) { return frame_info->offset + (y * frame_info->pitch) + (x * frame_info->cpp); } =20 -/* - * packed_pixels_addr - Get the pointer to pixel of a given pair of coordi= nates +/** + * packed_pixels_addr() - Get the pointer to the block containing the pixe= l at the given + * coordinates * * @frame_info: Buffer metadata - * @x: The x(width) coordinate of the 2D buffer - * @y: The y(Heigth) coordinate of the 2D buffer + * @x: The x (width) coordinate inside the plane + * @y: The y (height) coordinate inside the plane * * Takes the information stored in the frame_info, 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 ch= annel * comes immediately after another in the memory. And therefore, this func= tion * doesn't work for YUV with chroma subsampling (e.g. YUV420 and NV21). + * + * The caller must ensure that the framebuffer associated with this reques= t uses a pixel format + * where block_h =3D=3D block_w =3D=3D 1, otherwise the returned pointer c= an be outside the buffer. */ static void *packed_pixels_addr(const struct vkms_frame_info *frame_info, int x, int y) @@ -51,6 +67,13 @@ static int get_x_position(const struct vkms_frame_info *= frame_info, int limit, i return x; } =20 +/* + * The following functions take pixel data from the buffer and convert the= m to the format + * ARGB16161616 in @out_pixel. + * + * They are used in the vkms_compose_row() function to handle multiple for= mats. + */ + static void ARGB8888_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *ou= t_pixel) { /* @@ -143,12 +166,11 @@ void vkms_compose_row(struct line_buffer *stage_buffe= r, struct vkms_plane_state } =20 /* - * The following functions take an line of argb_u16 pixels from the - * src_buffer, convert them to a specific format, and store them in the - * destination. + * The following functions take one &struct pixel_argb_u16 and convert it = to a specific format. + * The result is stored in @dst_pixels. * - * They are used in the `compose_active_planes` to convert and store a line - * from the src_buffer to the writeback buffer. + * They are used in vkms_writeback_row() to convert and store a pixel from= the src_buffer to + * the writeback buffer. */ static void argb_u16_to_ARGB8888(u8 *dst_pixels, struct pixel_argb_u16 *in= _pixel) { @@ -214,6 +236,14 @@ static void argb_u16_to_RGB565(u8 *dst_pixels, struct = pixel_argb_u16 *in_pixel) *pixels =3D cpu_to_le16(r << 11 | g << 5 | b); } =20 +/** + * vkms_writeback_row() - Generic loop for all supported writeback format.= It is executed just + * after the blending to write a line in the writeback buffer. + * + * @wb: Job where to insert the final image + * @src_buffer: Line to write + * @y: Row to write in the writeback buffer + */ void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y) { @@ -227,6 +257,13 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, wb->pixel_write(dst_pixels, &in_pixels[x]); } =20 +/** + * get_pixel_conversion_function() - Retrieve the correct read_pixel funct= ion for a specific + * format. The returned pointer is NULL for unsupported pixel formats. The= caller must ensure that + * the pointer is valid before using it in a vkms_plane_state. + * + * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) + */ void *get_pixel_conversion_function(u32 format) { switch (format) { @@ -245,6 +282,13 @@ void *get_pixel_conversion_function(u32 format) } } =20 +/** + * get_pixel_write_function() - Retrieve the correct write_pixel function = for a specific format. + * The returned pointer is NULL for unsupported pixel formats. The caller = must ensure that the + * pointer is valid before using it in a vkms_writeback_job. + * + * @format: DRM_FORMAT_* value for which to obtain a conversion function (= see [drm_fourcc.h]) + */ void *get_pixel_write_function(u32 format) { switch (format) { diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms= _output.c index 5ce70dd946aa..56801e914208 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -21,6 +21,7 @@ static int vkms_conn_get_modes(struct drm_connector *conn= ector) { int count; =20 + /* Use the default modes list from DRM */ count =3D drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX); drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF); =20 @@ -58,6 +59,12 @@ int vkms_output_init(struct vkms_device *vkmsdev, int in= dex) int writeback; unsigned int n; =20 + /* + * Initialize used plane. One primary plane is required to perform the co= mposition. + * + * The overlay and cursor planes are not mandatory, but can be used to pe= rform complex + * composition. + */ primary =3D vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index); if (IS_ERR(primary)) return PTR_ERR(primary); @@ -76,6 +83,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int ind= ex) return PTR_ERR(cursor); } =20 + /* [1]: Allocation of a CRTC, its index will be 1 */ ret =3D vkms_crtc_init(dev, crtc, &primary->base, &cursor->base); if (ret) return ret; @@ -95,7 +103,11 @@ int vkms_output_init(struct vkms_device *vkmsdev, int i= ndex) DRM_ERROR("Failed to init encoder\n"); goto err_encoder; } - encoder->possible_crtcs =3D 1; + /* + * This is a hardcoded value to select crtc for the encoder. + * 1 here designate the first registered CRTC, the one allocated in [1] + */ + encoder->possible_crtcs =3D BIT(0); =20 ret =3D drm_connector_attach_encoder(connector, encoder); if (ret) { --- base-commit: 84addde447fd9d713e101437db0d4924855eff4f change-id: 20240520-google-clarifications-dede8dcbe38a Best regards, --=20 Louis Chauvet