drm/drm_colorop: add post-blend colorop support to AMD display driver
Subsystems (4)
v3 cover drm/drm_colorop: add post-blend colorop support to AMD display driver
This is an updated version of previous RFC series which adds post-blend colorop support to AMD display driver [RFC v2].
As I mentioned in the previous version, I worked on a proposal to migrate Gamescope, shifting from AMD driver-specific color properties to the KMS colorop API [1], and the AMD CRTC REGAMMA TF is the only driver-specific color property still missing upstream. I then implemented this 1D post-blend curve — which had been missing from the upstream kernel — based on Ariel&Nicolas’s proposal for post-blend colorop support [2]. Matthew is now continuing and extending this work on Gamescope.
Besides that, Robert is also using this support to offload the pre- and post-blend color pipeline in Weston:
https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/2157
This series doesn't depend on the inactive plane color pipeline series [3], but I already applied some of the plane rules:
1. AMD uses the committed state of colorops that aren't in the commit (as in "allow individual colorop changes").
2. "drm/atomic: duplicate CRTC colorop states" duplicates CRTC colorops for suspend/resume. If [3] lands first, the plane and CRTC duplication loops can be merged into one.
The rule that only colorops of an active (or (de)activating) pipeline can be changed is not applied to CRTC colorops yet. I plan to extend it once the plane approach in [3] is agreed.
Also, [3] adds a core check rejecting an enabled colorop without a DATA blob. Until then, AMD checks it for the post-blend CTM itself.
[RFC v2] https://lore.kernel.org/dri-devel/[email protected]/
Changes:
- Rebase on drm-misc-next.
- New patches:
- drm/atomic: handle CRTC colorops in drm_atomic_commit_set_colorop_state():
adapt the lock assert added by 259907fef771 to CRTC colorops.
- drm/atomic: duplicate CRTC colorop states: keep CRTC colorop values across suspend/resume.
- drm/atomic: track individual CRTC colorop updates: set color_mgmt_changed when COLOR_PIPELINE changes, as done for planes.
- drm/atomic: set hidden CRTC color mgmt model to default values.
- Dropped:
- "drm/crtc: Track crtc color pipeline client cap in drm_crtc_state" and "drm/atomic: Pass crtc_color_pipeline client cap to atomic check": Drivers now choose between colorop and the CRTC color properties from crtc_state->color_pipeline, as for planes.
- Dropped the CTM 3x4 and LUT32 extraction helpers: no users in this series.
- AMD:
- enable post-blend colorop properties since the beginning of the post-blend colorop support to avoid unused function.
- set colorop funcs on CRTC colorops (fixes a NULL dereference on destroy);
- based on [3], use the committed state of colorops that aren't in the commit, check colorop types, program bypass explicitly, reject an enabled CTM colorop without DATA blob;
- reset the CRTC degamma flags when in colorop mode;
- move "move CRTC CTM color mgmt prop to check helper" before the post-blend colorop enablement.
You can check the implementation for Gamescope [1], which fully migrates its color pipeline—shifting from AMD-specific color properties to planes/CRTC colorops; on the kernel side, this just needs a drm-misc-next kernel with this series applied.
[1] https://github.com/ValveSoftware/gamescope/pull/2113/commits
[2] https://lore.kernel.org/dri-devel/20251223-mtk-post-blend-color-pipeline-v3-0-7d969f9a37a0@collabora.com/
[3] https://lore.kernel.org/dri-devel/[email protected]/
===
This is one example of drm_info output on Steam Deck with SteamOS/gamescope implementation and this kernel work:
├───CRTCs
│ ├───CRTC 0
│ │ ├───Object ID: 399
[...]
│ │ └───"COLOR_PIPELINE" (atomic): enum {Bypass, Color Pipeline 400} = Color Pipeline 400
│ │ ├───Bypass
│ │ └───Color Pipeline 400
│ │ ├───Color Operation 400
│ │ │ └───Properties
│ │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 3x4 Matrix
│ │ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ │ ├───"NEXT" (atomic, immutable): object colorop = 405
│ │ │ └───"DATA" (atomic): blob = 0
│ │ ├───Color Operation 405
│ │ │ └───Properties
│ │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
│ │ │ ├───"BYPASS" (atomic): range [0, 1] = 0
│ │ │ ├───"NEXT" (atomic, immutable): object colorop = 410
│ │ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse EOTF, PQ 125 Inverse EOTF, BT.2020 OETF, Gamma 2.2 Inverse, Gamma 2.4 Inverse, Gamma 2.6 Inverse} = PQ 125 Inverse EOTF
│ │ └───Color Operation 410
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D LUT
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ ├───"NEXT" (atomic, immutable): object colorop = 0
│ │ ├───"SIZE" (atomic, immutable): range [0, UINT32_MAX] = 4096
│ │ ├───"LUT1D_INTERPOLATION": enum {Linear} = Linear
│ │ └───"DATA" (atomic): blob = 0[...]
├───Plane 3
│ ├───Object ID: 218
[...]
│ └───Properties
│ ├───"type" (immutable): enum {Overlay, Primary, Cursor} = Primary
│ ├───"FB_ID" (atomic): object framebuffer = 513
│ │ ├───Object ID: 513
[...]
│ └───"COLOR_PIPELINE" (atomic): enum {Bypass, Color Pipeline 224} = Color Pipeline 224
│ ├───Bypass
│ └───Color Pipeline 224
│ ├───Color Operation 224
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = Fixed Matrix
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ ├───"NEXT" (atomic, immutable): object colorop = 229
│ │ └───"FIXED_MATRIX_TYPE" (atomic): enum {YCbCr 601 Full to RGB, YCbCr 601 Limited to RGB, YCbCr 709 Full to RGB, YCbCr 709 Limited to RGB, YCbCr 2020 NC Full to RGB, YCbCr 2020 NC Limited to RGB} = YCbCr 601 Full to RGB
│ ├───Color Operation 229
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
│ │ ├───"BYPASS" (atomic): range [0, 1] = 0
│ │ ├───"NEXT" (atomic, immutable): object colorop = 234
│ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, PQ 125 EOTF, BT.2020 Inverse OETF, Gamma 2.2, Gamma 2.4, Gamma 2.6} = sRGB EOTF
│ ├───Color Operation 234
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = Multiplier
│ │ ├───"BYPASS" (atomic): range [0, 1] = 0
│ │ ├───"NEXT" (atomic, immutable): object colorop = 239
│ │ └───"MULTIPLIER" (atomic): range [0, UINT64_MAX] = 4294967296
│ ├───Color Operation 239
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 3x4 Matrix
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ ├───"NEXT" (atomic, immutable): object colorop = 244
│ │ └───"DATA" (atomic): blob = 0
│ ├───Color Operation 244
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
│ │ ├───"BYPASS" (atomic): range [0, 1] = 0
│ │ ├───"NEXT" (atomic, immutable): object colorop = 249
│ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse EOTF, PQ 125 Inverse EOTF, BT.2020 OETF, Gamma 2.2 Inverse, Gamma 2.4 Inverse, Gamma 2.6 Inverse} = sRGB Inverse EOTF
│ ├───Color Operation 249
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D LUT
│ │ ├───"BYPASS" (atomic): range [0, 1] = 0
│ │ ├───"NEXT" (atomic, immutable): object colorop = 256
│ │ ├───"SIZE" (atomic, immutable): range [0, UINT32_MAX] = 4096
│ │ ├───"LUT1D_INTERPOLATION": enum {Linear} = Linear
│ │ └───"DATA" (atomic): blob = 528
│ ├───Color Operation 256
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 3D LUT
│ │ ├───"BYPASS" (atomic): range [0, 1] = 0
│ │ ├───"NEXT" (atomic, immutable): object colorop = 263
│ │ ├───"SIZE" (atomic, immutable): range [0, UINT32_MAX] = 17
│ │ ├───"LUT3D_INTERPOLATION": enum {Tetrahedral} = Tetrahedral
│ │ └───"DATA" (atomic): blob = 529
│ ├───Color Operation 263
│ │ └───Properties
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D Curve
│ │ ├───"BYPASS" (atomic): range [0, 1] = 0
│ │ ├───"NEXT" (atomic, immutable): object colorop = 268
│ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, PQ 125 EOTF, BT.2020 Inverse OETF, Gamma 2.2, Gamma 2.4, Gamma 2.6} = PQ 125 EOTF
│ └───Color Operation 268
│ └───Properties
│ ├───"TYPE" (immutable): enum {1D Curve, 1D LUT, 3x4 Matrix, Multiplier, 3D LUT, Fixed Matrix} = 1D LUT
│ ├───"BYPASS" (atomic): range [0, 1] = 1
│ ├───"NEXT" (atomic, immutable): object colorop = 0
│ ├───"SIZE" (atomic, immutable): range [0, UINT32_MAX] = 4096
│ ├───"LUT1D_INTERPOLATION": enum {Linear} = Linear
│ └───"DATA" (atomic): blob = 0FWIW, here is the drm_info diff:
drm_info.h +1 -0
@@ -21,5 +21,6 @@ enum {/* Remove after updating libdrm */ #define DRM_MODE_OBJECT_COLOROP 0xfafafafa#define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE 7 +#define DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE 8#endif
json.c +1 -0
@@ -29,6 +29,7 @@ static const struct { { "WRITEBACK_CONNECTORS", DRM_CLIENT_CAP_WRITEBACK_CONNECTORS }, { "CURSOR_PLANE_HOTSPOT", DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT }, { "PLANE_COLOR_PIPELINE", DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE }, + { "CRTC_COLOR_PIPELINE", DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE }, };
===
Melissa Wen (11):
drm/atomic: handle CRTC colorops in drm_atomic_commit_set_colorop_state() drm/atomic: duplicate CRTC colorop states
drm/atomic: track individual CRTC colorop updates
drm/colorop: distinguish whether a colorop belongs to a plane or a CRTC drm/drm_mode_object: hide deprecated CRTC color mgmt props if colorop is set drm/atomic: set hidden CRTC color mgmt model to default values drm/drm_ioctl: guard DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE drm/amd/display: move CRTC CTM color mgmt prop to check helper drm/amd/display: enable post-blend CTM colorop
drm/amd/display: add support to post-blend 1D-Curve colorop drm/amd/display: add support to post-blend 1D-LUT colorop
Nícolas F. R. A. Prado (8):
drm/crtc: Add color pipeline to CRTC state
drm/colorop: Allow parenting colorop to CRTC
drm: Factor out common color_pipeline property initialization code drm/crtc: Add COLOR_PIPELINE property
drm: Introduce DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE drm/atomic: Print the color pipeline as part of the CRTC state print drm/colorop: Factor out common paths from colorops helpers drm/colorop: Introduce colorop helpers for crtc
.../amd/display/amdgpu_dm/amdgpu_dm_color.c | 254 +++++++++++++--- .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 76 +++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 42 +++ drivers/gpu/drm/drm_atomic.c | 17 +- drivers/gpu/drm/drm_atomic_helper.c | 18 ++ drivers/gpu/drm/drm_atomic_uapi.c | 132 +++++++- drivers/gpu/drm/drm_colorop.c | 282 ++++++++++++++---- drivers/gpu/drm/drm_connector.c | 1 + drivers/gpu/drm/drm_crtc.c | 31 ++ drivers/gpu/drm/drm_crtc_internal.h | 1 + drivers/gpu/drm/drm_ioctl.c | 20 ++ drivers/gpu/drm/drm_mode_object.c | 18 ++ drivers/gpu/drm/drm_plane.c | 34 +-- drivers/gpu/drm/drm_property.c | 44 +++ include/drm/drm_atomic_uapi.h | 2 + include/drm/drm_colorop.h | 32 +- include/drm/drm_crtc.h | 21 ++ include/drm/drm_file.h | 7 + include/drm/drm_property.h | 5 + include/uapi/drm/drm.h | 20 ++ 21 files changed, 912 insertions(+), 147 deletions(-)
Signature · 1 line
2.53.0
PATCH v3 1/19 drm/crtc: Add color pipeline to CRTC state
From: Nícolas F. R. A. Prado <[email protected]>
Add a color pipeline to the CRTC state to allow post-blend color pipelines.
---
v3:
- rebase on drm-misc-next, no other changes
--- include/drm/drm_crtc.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/drm/drm_crtc.h +8 -0
@@ -274,6 +274,14 @@ struct drm_crtc_state {*/ struct drm_property_blob *gamma_lut; +/** +* @color_pipeline: +* +* The first colorop of the active color pipeline, or NULL, if no +* color pipeline is active. +*/ +struct drm_colorop *color_pipeline; +/** * @background_color: *
Signature · 1 line
2.53.0
PATCH v3 2/19 drm/colorop: Allow parenting colorop to CRTC
In reply to Melissa WenFrom: Nícolas F. R. A. Prado <[email protected]>
In order to allow for post-blend color pipelines, colorops need to be assigned to a crtc rather than a plane. Add a crtc to the colorop struct to enable this. Either the plane or the crtc will be set for any given colorop depending on whether it is part of a pre- or post-blend color pipeline.
---
v3:
- minor fix of trailing whitespace <mwen>
- rebase on drm-misc-next
--- drivers/gpu/drm/drm_atomic.c | 6 +++--- drivers/gpu/drm/drm_colorop.c | 25 +++++++++++++++++++++++++ include/drm/drm_colorop.h | 18 ++++++++++++++++-- 3 files changed, 44 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_atomic.c +3 -3
@@ -748,7 +748,7 @@ drm_atomic_get_colorop_state(struct drm_atomic_commit *state,if (colorop_state)return colorop_state; - ret =drm_modeset_lock (&colorop->plane->mutex, state->acquire_ctx); + ret =drm_colorop_modeset_lock (colorop, state->acquire_ctx);if (ret)return ERR_PTR (ret);
@@ -2213,10 +2213,10 @@ static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p,list_for_each_entry (colorop, &config->colorop_list, head) {if (take_locks) -drm_modeset_lock (&colorop->plane->mutex,NULL ); +drm_colorop_modeset_lock (colorop,NULL );drm_atomic_colorop_print_state (p, colorop->state);if (take_locks) -drm_modeset_unlock (&colorop->plane->mutex); +drm_colorop_modeset_unlock (colorop); }list_for_each_entry (plane, &config->plane_list, head) {
drivers/gpu/drm/drm_colorop.c +25 -0
@@ -24,6 +24,7 @@* */ +#include <drm/drm_crtc.h> #include <drm/drm_colorop.h> #include <drm/drm_print.h> #include <drm/drm_drv.h>
@@ -774,3 +775,27 @@ void drm_colorop_set_next_property(struct drm_colorop *colorop, struct drm_color colorop->next = next; }EXPORT_SYMBOL (drm_colorop_set_next_property); + +int drm_colorop_modeset_lock (struct drm_colorop *colorop,struct drm_modeset_acquire_ctx *ctx) +{ +if (colorop->plane) +return drm_modeset_lock (&colorop->plane->mutex, ctx); + +if (colorop->crtc) +return drm_modeset_lock (&colorop->crtc->mutex, ctx); + +drm_err (colorop->dev,"Dangling colorop, it must be attached to a plane or a CRTC\n" ); +return -EINVAL ; +} +EXPORT_SYMBOL (drm_colorop_modeset_lock); + +void drm_colorop_modeset_unlock (struct drm_colorop *colorop) +{ +if (colorop->plane) +drm_modeset_unlock (&colorop->plane->mutex); +else if (colorop->crtc) +drm_modeset_unlock (&colorop->crtc->mutex); +else +drm_err (colorop->dev,"Dangling colorop, it must be attached to a plane or a CRTC\n" ); +} +EXPORT_SYMBOL (drm_colorop_modeset_unlock);
include/drm/drm_colorop.h +16 -2
@@ -29,6 +29,7 @@#include <drm/drm_mode_object.h> #include <drm/drm_mode.h> +#include <drm/drm_modeset_lock.h> #include <drm/drm_property.h> /* DRM colorop flags */
@@ -365,11 +366,21 @@ struct drm_colorop {/** * @plane: * -* The plane on which the colorop sits. A drm_colorop is always unique -* to a plane. +* The plane on which the colorop sits if it is a pre-blend colorop. +* In this case it is unique to the plane. +* NOTE: plane and crtc are mutually exclusive. */ struct drm_plane *plane; +/** +* @crtc: +* +* The CRTC on which the colorop sits if it is a post-blend colorop. +* In this case it is unique to the CRTC. +* NOTE: plane and crtc are mutually exclusive. +*/ +struct drm_crtc *crtc; +/** * @state: *
@@ -610,4 +621,7 @@ const char *drm_get_colorop_fixed_matrix_type_name(enum drm_colorop_fixed_matrixvoid drm_colorop_set_next_property (struct drm_colorop *colorop,struct drm_colorop *next); +int drm_colorop_modeset_lock (struct drm_colorop *colorop,struct drm_modeset_acquire_ctx *ctx); +void drm_colorop_modeset_unlock (struct drm_colorop *colorop); +#endif /* __DRM_COLOROP_H__ */
Signature · 1 line
2.53.0
PATCH v3 3/19 drm/atomic: handle CRTC colorops in drm_atomic_commit_set_colorop_state()
In reply to Melissa WenCommit 259907fef771 ("drm/atomic: Create function to insert colorop state into a commit") asserts if the lock of the plane colorop is held. Now that a colorop can be also parented by a CRTC, colorop->plane is NULL for a CRTC colorop and drm_atomic_commit_set_colorop_state() has to check the CRTC mutex instead of plane mutex. Update the helper to assert the lock of the object that owns the colorop.
---
v3:
- new patch: adapt the lock assert added by commit 259907fef771 to colorops parented to a CRTC
--- drivers/gpu/drm/drm_atomic.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic.c +6 -3
@@ -710,7 +710,10 @@ static void drm_atomic_commit_set_colorop_state(struct drm_atomic_commit *commit {int index =drm_colorop_index (colorop); -drm_modeset_lock_assert_held (&colorop->plane->mutex); +if (colorop->plane) +drm_modeset_lock_assert_held (&colorop->plane->mutex); +else if (colorop->crtc) +drm_modeset_lock_assert_held (&colorop->crtc->mutex); commit->colorops[index].state_to_destroy = colorop_state; commit->colorops[index].old_state = colorop->state;
@@ -725,8 +728,8 @@ static void drm_atomic_commit_set_colorop_state(struct drm_atomic_commit *commit* @colorop: colorop to get state object for * * This function returns the colorop state for the given colorop, allocating it -* if needed. It will also grab the relevant plane lock to make sure that the -* state is consistent. +* if needed. It will also grab the relevant plane or CRTC lock to make sure +* that the state is consistent. * * Returns: *
Signature · 1 line
2.53.0
PATCH v3 4/19 drm/atomic: duplicate CRTC colorop states
In reply to Melissa WenAdd the state of every CRTC colorop to the duplicated state, active or not, so their settings persist on a reset cycle.
---
v3:
- new patch
- Note: if "drm/atomic: duplicate state of all colorops" for colorop planes [1] lands first, the plane and CRTC loops can be merged into a single pass over all colorops.
[1] https://lore.kernel.org/dri-devel/[email protected]/
--- drivers/gpu/drm/drm_atomic_helper.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +18 -0
@@ -3730,6 +3730,7 @@ drm_atomic_helper_duplicate_state(struct drm_device *dev,struct drm_connector_list_iter conn_iter;struct drm_plane *plane;struct drm_crtc *crtc; +struct drm_colorop *colorop;int err =0 ; state =drm_atomic_commit_alloc (dev);
@@ -3749,6 +3750,23 @@ drm_atomic_helper_duplicate_state(struct drm_device *dev, } } +/* +* Add all CRTC colorops, active or not, so their settings survive the +* colorop reset done on resume. +*/ +drm_for_each_colorop (colorop, dev) { +struct drm_colorop_state *colorop_state; + +if (!colorop->crtc) +continue ; + + colorop_state =drm_atomic_get_colorop_state (state, colorop); +if (IS_ERR (colorop_state)) { + err =PTR_ERR (colorop_state); + goto free; + } + } +drm_for_each_plane (plane, dev) {struct drm_plane_state *plane_state;
Signature · 1 line
2.53.0
PATCH v3 5/19 drm: Factor out common color_pipeline property initialization code
In reply to Melissa WenFrom: Nícolas F. R. A. Prado <[email protected]>
In preparation for sharing the initialization code for the color pipeline property between pre-blend (plane) and post-blend (crtc) color pipelines, factor out the common initialization to a separate function.
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_plane.c | 34 ++++---------------------- drivers/gpu/drm/drm_property.c | 44 ++++++++++++++++++++++++++++++++++ include/drm/drm_property.h | 5 ++++ 3 files changed, 53 insertions(+), 30 deletions(-)
drivers/gpu/drm/drm_plane.c +4 -30
@@ -1837,41 +1837,15 @@ int drm_plane_create_color_pipeline_property(struct drm_plane *plane, const struct drm_prop_enum_list *pipelines, int num_pipelines) { -struct drm_prop_enum_list *all_pipelines;struct drm_property *prop; -int len =0 ; -int i; - all_pipelines =kzalloc_objs (*all_pipelines, num_pipelines +1 ); + prop =drm_property_create_color_pipeline (plane->dev, &plane->base, + pipelines, num_pipelines); +if (IS_ERR (prop)) +return PTR_ERR (prop); -if (!all_pipelines) { -drm_err (plane->dev,"failed to allocate color pipeline\n" ); -return -ENOMEM ; - } - -/* Create default Bypass color pipeline */ - all_pipelines[len].type =0 ; - all_pipelines[len].name ="Bypass" ; - len++; - -/* Add all other color pipelines */ -for (i =0 ; i < num_pipelines; i++, len++) { - all_pipelines[len].type = pipelines[i].type; - all_pipelines[len].name = pipelines[i].name; - } - - prop =drm_property_create_enum (plane->dev,DRM_MODE_PROP_ATOMIC , -"COLOR_PIPELINE" , - all_pipelines, len); -if (!prop) { -kfree (all_pipelines); -return -ENOMEM ; - } - -drm_object_attach_property (&plane->base, prop,0 ); plane->color_pipeline_property = prop; -kfree (all_pipelines);return 0 ; }EXPORT_SYMBOL (drm_plane_create_color_pipeline_property);
drivers/gpu/drm/drm_property.c +44 -0
47 lines not on this page · raw message
include/drm/drm_property.h +5 -0
@@ -297,6 +297,11 @@ bool drm_property_replace_blob(struct drm_property_blob **blob,struct drm_property_blob *drm_property_blob_get (struct drm_property_blob *blob);void drm_property_blob_put (struct drm_property_blob *blob); +struct drm_property * +drm_property_create_color_pipeline (struct drm_device *dev,struct drm_mode_object *obj, +const struct drm_prop_enum_list *pipelines, +int num_pipelines); +/** * drm_property_find - find property object * @dev: DRM device
Signature · 1 line
2.53.0
PATCH v3 6/19 drm/crtc: Add COLOR_PIPELINE property
In reply to Melissa WenFrom: Nícolas F. R. A. Prado <[email protected]>
Add a COLOR_PIPELINE property to the CRTC to allow userspace to set a post-blend color pipeline analogously to how pre-blend color pipelines are set on planes.
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_atomic_uapi.c | 50 ++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_crtc.c | 31 +++++++++++++++++++ include/drm/drm_atomic_uapi.h | 2 ++ include/drm/drm_crtc.h | 11 +++++++ 4 files changed, 90 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_atomic_uapi.c +46 -4
@@ -294,6 +294,34 @@ drm_atomic_set_colorop_for_plane(struct drm_plane_state *plane_state, }EXPORT_SYMBOL (drm_atomic_set_colorop_for_plane); +/** +* drm_atomic_set_colorop_for_crtc - set colorop for crtc +* @crtc_state: atomic state object for the crtc +* @colorop: colorop to use for the crtc +* +* Helper function to select the color pipeline on a crtc by setting +* it to the first drm_colorop element of the pipeline. +*/ +void +drm_atomic_set_colorop_for_crtc (struct drm_crtc_state *crtc_state, +struct drm_colorop *colorop) +{ +struct drm_crtc *crtc = crtc_state->crtc; + +if (colorop) +drm_dbg_atomic (crtc->dev, +"Set [COLOROP:%d] for [CRTC:%d:%s] state %p\n" , + colorop->base.id, crtc->base.id, crtc->name, + crtc_state); +else +drm_dbg_atomic (crtc->dev, +"Set [NOCOLOROP] for [CRTC:%d:%s] state %p\n" , + crtc->base.id, crtc->name, crtc_state); + + crtc_state->color_pipeline = colorop; +} +EXPORT_SYMBOL (drm_atomic_set_colorop_for_crtc); +/** * drm_atomic_set_crtc_for_connector - set CRTC for connector * @conn_state: atomic state object for the connector
@@ -402,8 +430,8 @@ static s32 __user *get_out_fence_for_connector(struct drm_atomic_commit *state, }static int drm_atomic_crtc_set_property (struct drm_crtc *crtc, -struct drm_crtc_state *state,struct drm_property *property, -uint64_t val) +struct drm_crtc_state *state,struct drm_file *file_priv, +struct drm_property *property,uint64_t val) {struct drm_device *dev = crtc->dev;struct drm_mode_config *config = &dev->mode_config;
@@ -412,7 +440,17 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,if (property == config->prop_active) state->active = val; -else if (property == config->prop_mode_id) { +else if (property == crtc->color_pipeline_property) { +/* find DRM colorop object */ +struct drm_colorop *colorop =NULL ; + + colorop =drm_colorop_find (dev, file_priv, val); + +if (val && !colorop) +return -EACCES ; + +drm_atomic_set_colorop_for_crtc (state, colorop); + }else if (property == config->prop_mode_id) {struct drm_property_blob *mode =drm_property_lookup_blob (dev, val); ret =drm_atomic_set_mode_prop_for_crtc (state, mode);
@@ -519,6 +557,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc, *val = state->scaling_filter; else if (property == crtc->sharpness_strength_property) *val = state->sharpness_strength; + else if (property == crtc->color_pipeline_property) + *val = (state->color_pipeline) ? state->color_pipeline->base.id : 0; else if (crtc->funcs->atomic_get_property) return crtc->funcs->atomic_get_property(crtc, state, property, val); else {
@@ -1106,6 +1146,8 @@ int drm_atomic_get_property(struct drm_mode_object *obj,if (colorop->plane)WARN_ON (!drm_modeset_is_locked (&colorop->plane->mutex)); +else if (colorop->crtc) +WARN_ON (!drm_modeset_is_locked (&colorop->crtc->mutex)); ret =drm_atomic_colorop_get_property (colorop, colorop->state, property, val);break ;
@@ -1262,7 +1304,7 @@ int drm_atomic_set_property(struct drm_atomic_commit *state, } ret =drm_atomic_crtc_set_property (crtc, - crtc_state, prop, prop_value); + crtc_state, file_priv, prop, prop_value);break ; }case DRM_MODE_OBJECT_PLANE : {
drivers/gpu/drm/drm_crtc.c +31 -0
@@ -997,3 +997,34 @@ bool drm_crtc_in_clone_mode(struct drm_crtc_state *crtc_state)return hweight32 (crtc_state->encoder_mask) >1 ; }EXPORT_SYMBOL (drm_crtc_in_clone_mode); + +/** +* drm_crtc_create_color_pipeline_property - create a new color pipeline +* property +* +* @crtc: drm CRTC +* @pipelines: list of pipelines +* @num_pipelines: number of pipelines +* +* Create the COLOR_PIPELINE CRTC property to specify color pipelines on +* the CRTC. +* +* RETURNS: +* Zero for success or -errno +*/ +int drm_crtc_create_color_pipeline_property (struct drm_crtc *crtc, +const struct drm_prop_enum_list *pipelines, +int num_pipelines) +{ +struct drm_property *prop; + + prop =drm_property_create_color_pipeline (crtc->dev, &crtc->base, + pipelines, num_pipelines); +if (IS_ERR (prop)) +return PTR_ERR (prop); + + crtc->color_pipeline_property = prop; + +return 0 ; +} +EXPORT_SYMBOL (drm_crtc_create_color_pipeline_property);
include/drm/drm_atomic_uapi.h +2 -0
@@ -54,6 +54,8 @@ void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state, struct drm_framebuffer *fb);bool drm_atomic_set_colorop_for_plane (struct drm_plane_state *plane_state,struct drm_colorop *colorop); +void drm_atomic_set_colorop_for_crtc (struct drm_crtc_state *crtc_state, +struct drm_colorop *colorop);int __must_check drm_atomic_set_crtc_for_connector (struct drm_connector_state *conn_state,struct drm_crtc *crtc);
include/drm/drm_crtc.h +11 -0
@@ -1129,6 +1129,14 @@ struct drm_crtc {*/ struct drm_property *sharpness_strength_property; +/** +* @color_pipeline_property: +* +* Optional "COLOR_PIPELINE" enum property for specifying +* a color pipeline to use on the CRTC. +*/ +struct drm_property *color_pipeline_property; +/** * @state: *
@@ -1364,6 +1372,9 @@ static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,int drm_crtc_create_scaling_filter_property (struct drm_crtc *crtc,unsigned int supported_filters); +int drm_crtc_create_color_pipeline_property (struct drm_crtc *crtc, +const struct drm_prop_enum_list *pipelines, +int num_pipelines);bool drm_crtc_in_clone_mode (struct drm_crtc_state *crtc_state);int drm_crtc_create_sharpness_strength_property (struct drm_crtc *crtc);#endif /* __DRM_CRTC_H__ */
Signature · 1 line
2.53.0
PATCH v3 7/19 drm/atomic: track individual CRTC colorop updates
In reply to Melissa WenAs done for plane colorops by commit 2e235e2a2784b ("drm/atomic: track individual colorop updates"), make drm_atomic_set_colorop_for_crtc() report whether the CRTC color pipeline changed and set
CRTC color_mgmt_changed flag accordingly.
---
v3:
- new patch: set color_mgmt_changed when the CRTC COLOR_PIPELINE value changes, as commit 2e235e2a2784 does for planes
--- drivers/gpu/drm/drm_atomic_uapi.c | 12 ++++++++++-- include/drm/drm_atomic_uapi.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_atomic_uapi.c +10 -2
@@ -301,13 +301,18 @@ EXPORT_SYMBOL(drm_atomic_set_colorop_for_plane);* * Helper function to select the color pipeline on a crtc by setting * it to the first drm_colorop element of the pipeline. +* +* Return: true if CRTC color pipeline value changed, false otherwise. */ -void +bool drm_atomic_set_colorop_for_crtc (struct drm_crtc_state *crtc_state,struct drm_colorop *colorop) {struct drm_crtc *crtc = crtc_state->crtc; +if (crtc_state->color_pipeline == colorop) +return false; +if (colorop) drm_dbg_atomic(crtc->dev, "Set [COLOROP:%d] for [CRTC:%d:%s] state %p\n",
@@ -319,6 +324,8 @@ drm_atomic_set_colorop_for_crtc(struct drm_crtc_state *crtc_state, crtc->base.id, crtc->name, crtc_state); crtc_state->color_pipeline = colorop; + +return true; }EXPORT_SYMBOL (drm_atomic_set_colorop_for_crtc);
@@ -449,7 +456,8 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,if (val && !colorop)return -EACCES ; -drm_atomic_set_colorop_for_crtc (state, colorop); + state->color_mgmt_changed |= +drm_atomic_set_colorop_for_crtc (state, colorop); }else if (property == config->prop_mode_id) {struct drm_property_blob *mode =drm_property_lookup_blob (dev, val);
include/drm/drm_atomic_uapi.h +1 -1
@@ -54,7 +54,7 @@ void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state, struct drm_framebuffer *fb);bool drm_atomic_set_colorop_for_plane (struct drm_plane_state *plane_state,struct drm_colorop *colorop); -void drm_atomic_set_colorop_for_crtc (struct drm_crtc_state *crtc_state, +bool drm_atomic_set_colorop_for_crtc (struct drm_crtc_state *crtc_state,struct drm_colorop *colorop); int __must_check drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
Signature · 1 line
2.53.0
PATCH v3 8/19 drm: Introduce DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE
In reply to Melissa WenFrom: Nícolas F. R. A. Prado <[email protected]>
Introduce DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE which a DRM client can set to enable the usage of CRTC (post-blend) color pipelines instead of the now deprecated CRTC color management properties: "GAMMA_LUT", "DEGAMMA_LUT" and "CTM".
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_atomic_uapi.c | 21 +++++++++++++++++++++ drivers/gpu/drm/drm_connector.c | 1 + drivers/gpu/drm/drm_crtc_internal.h | 1 + drivers/gpu/drm/drm_ioctl.c | 7 +++++++ drivers/gpu/drm/drm_mode_object.c | 9 +++++++++ include/drm/drm_file.h | 7 +++++++ include/uapi/drm/drm.h | 19 +++++++++++++++++++ 7 files changed, 65 insertions(+)
drivers/gpu/drm/drm_atomic_uapi.c +21 -0
@@ -448,6 +448,11 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,if (property == config->prop_active) state->active = val;else if (property == crtc->color_pipeline_property) { +if (!file_priv->crtc_color_pipeline) { +drm_dbg_atomic (dev, +"Setting COLOR_PIPELINE CRTC property not permitted without DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE client cap\n" ); +return -EINVAL ; + }/* find DRM colorop object */ struct drm_colorop *colorop =NULL ;
@@ -470,6 +475,11 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,const size_t elem_size =sizeof (struct drm_color_lut );u64 lut_size; +if (file_priv->crtc_color_pipeline) { +drm_dbg_atomic (dev, +"Setting DEGAMMA_LUT CRTC property not permitted with DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE client cap\n" ); +return -EINVAL ; + } ret =drm_object_immutable_property_get_value (&crtc->base, config->degamma_lut_size_property, &lut_size);
@@ -484,6 +494,11 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc, state->color_mgmt_changed |= replaced;return ret; }else if (property == config->ctm_property) { +if (file_priv->crtc_color_pipeline) { +drm_dbg_atomic (dev, +"Setting CTM CRTC property not permitted with DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE client cap\n" ); +return -EINVAL ; + } ret = drm_property_replace_blob_from_id(dev, &state->ctm, val,
@@ -495,6 +510,12 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,const size_t elem_size =sizeof (struct drm_color_lut );u64 lut_size; +if (file_priv->crtc_color_pipeline) { +drm_dbg_atomic (dev, +"Setting GAMMA_LUT CRTC property not permitted with DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE client cap\n" ); +return -EINVAL ; + } + ret =drm_object_immutable_property_get_value (&crtc->base, config->gamma_lut_size_property, &lut_size);
drivers/gpu/drm/drm_connector.c +1 -0
@@ -3767,6 +3767,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,*/ ret =drm_mode_object_get_properties (&connector->base, file_priv->atomic, file_priv->plane_color_pipeline, + file_priv->crtc_color_pipeline, (uint32_t __user *)(unsigned long )(out_resp->props_ptr), (uint64_t __user *)(unsigned long )(out_resp->prop_values_ptr), &out_resp->count_props);
drivers/gpu/drm/drm_crtc_internal.h +1 -0
@@ -164,6 +164,7 @@ void drm_mode_object_unregister(struct drm_device *dev, struct drm_mode_object *object);int drm_mode_object_get_properties (struct drm_mode_object *obj,bool atomic,bool plane_color_pipeline, +bool crtc_color_pipeline,uint32_t __user *prop_ptr,uint64_t __user *prop_values,uint32_t *arg_count_props);
drivers/gpu/drm/drm_ioctl.c +7 -0
@@ -392,6 +392,13 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv) file_priv->plane_color_pipeline = req->value;break ; } +case DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE : +if (!file_priv->atomic) +return -EINVAL ; +if (req->value >1 ) +return -EINVAL ; + file_priv->crtc_color_pipeline = req->value; +break ;default :return -EINVAL ; }
drivers/gpu/drm/drm_mode_object.c +9 -0
@@ -413,6 +413,7 @@ EXPORT_SYMBOL(drm_object_immutable_property_get_value);/* helper for getconnector and getproperties ioctls */ int drm_mode_object_get_properties (struct drm_mode_object *obj,bool atomic,bool plane_color_pipeline, +bool crtc_color_pipeline,uint32_t __user *prop_ptr,uint64_t __user *prop_values,uint32_t *arg_count_props)
@@ -441,6 +442,13 @@ int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,continue ; } +if (!crtc_color_pipeline && obj->type ==DRM_MODE_OBJECT_CRTC ) { +struct drm_crtc *crtc =obj_to_crtc (obj); + +if (prop == crtc->color_pipeline_property) +continue ; + } +if (*arg_count_props > count) { ret =__drm_object_property_get_value (obj, prop, &val);if (ret)
@@ -500,6 +508,7 @@ int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, ret =drm_mode_object_get_properties (obj, file_priv->atomic, file_priv->plane_color_pipeline, + file_priv->crtc_color_pipeline, (uint32_t __user *)(unsigned long )(arg->props_ptr), (uint64_t __user *)(unsigned long )(arg->prop_values_ptr), &arg->count_props);
include/drm/drm_file.h +7 -0
@@ -214,6 +214,13 @@ struct drm_file {*/ bool plane_color_pipeline; +/** +* @crtc_color_pipeline: +* +* True if client understands CRTC (post-blend) color pipelines +*/ +bool crtc_color_pipeline; +/** * @was_master: *
include/uapi/drm/drm.h +19 -0
@@ -903,6 +903,25 @@ struct drm_get_cap {*/ #define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE 7 +/** +* DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE +* +* If set to 1 the DRM core will allow setting the COLOR_PIPELINE +* property on a &drm_crtc, as well as drm_colorop properties. +* +* Setting of these crtc properties will be rejected when this client +* cap is set: +* - GAMMA_LUT +* - DEGAMMA_LUT +* - CTM +* +* The client must enable &DRM_CLIENT_CAP_ATOMIC first. +* +* This client cap can only be set if the driver sets the corresponding driver +* cap &DRM_CAP_CRTC_COLOR_PIPELINE. +*/ +#define DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE 8 +/* DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */ struct drm_set_client_cap {__u64 capability;
Signature · 1 line
2.53.0
PATCH v3 9/19 drm/atomic: Print the color pipeline as part of the CRTC state print
In reply to Melissa WenFrom: Nícolas F. R. A. Prado <[email protected]>
Print the value of the color pipeline in the CRTC state as part of the CRTC state print.
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_atomic.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/drm_atomic.c +2 -0
@@ -575,6 +575,8 @@ static void drm_atomic_crtc_print_state(struct drm_printer *p,drm_printf_indent (p,1 ,"plane_mask=%x\n" , state->plane_mask);drm_printf_indent (p,1 ,"connector_mask=%x\n" , state->connector_mask);drm_printf_indent (p,1 ,"encoder_mask=%x\n" , state->encoder_mask); +drm_printf_indent (p,1 ,"color-pipeline=%d\n" , + state->color_pipeline ? state->color_pipeline->base.id :0 );drm_printf_indent (p,1 ,"mode: " DRM_MODE_FMT "\n" ,DRM_MODE_ARG (&state->mode));drm_printf_indent (p,1 ,"background_color=%llx\n" , state->background_color);
Signature · 1 line
2.53.0
PATCH v3 10/19 drm/colorop: Factor out common paths from colorops helpers
In reply to Melissa WenFrom: Nícolas F. R. A. Prado <[email protected]>
Factor out the common code paths from the colorop helpers so they can be reused by the post-blend colorop helpers.
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_colorop.c | 180 +++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 66 deletions(-)
drivers/gpu/drm/drm_colorop.c +114 -66
@@ -103,10 +103,11 @@ static const char * const colorop_fixed_matrix_type_names[] = {/* Init Helpers */ -static int drm_plane_colorop_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane,const struct drm_colorop_funcs *funcs, -enum drm_colorop_type type, -uint32_t flags) +static int drm_common_colorop_init (struct drm_device *dev, +struct drm_colorop *colorop, +const struct drm_colorop_funcs *funcs, +enum drm_colorop_type type, +uint32_t flags) {struct drm_mode_config *config = &dev->mode_config;struct drm_property *prop;
@@ -119,7 +120,6 @@ static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *co colorop->base.properties = &colorop->properties; colorop->dev = dev; colorop->type = type; - colorop->plane = plane; colorop->next =NULL ; colorop->funcs = funcs;
@@ -169,6 +169,22 @@ static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *coreturn ret; } +static int drm_plane_colorop_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_plane *plane, +const struct drm_colorop_funcs *funcs, +enum drm_colorop_type type, +uint32_t flags) +{ +int ret; + + ret =drm_common_colorop_init (dev, colorop, funcs, type, flags); + + colorop->plane = plane; + +return ret; +} +/** * drm_colorop_cleanup - Cleanup a drm_colorop object in color_pipeline *
@@ -220,45 +236,14 @@ void drm_colorop_pipeline_destroy(struct drm_device *dev) }EXPORT_SYMBOL (drm_colorop_pipeline_destroy); -/** -* drm_plane_colorop_curve_1d_init - Initialize a DRM_COLOROP_1D_CURVE -* -* @dev: DRM device -* @colorop: The drm_colorop object to initialize -* @plane: The associated drm_plane -* @funcs: control functions for the new colorop -* @supported_tfs: A bitfield of supported drm_plane_colorop_curve_1d_init enum values, -* created using BIT(curve_type) and combined with the OR '|' -* operator. -* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines. -* @return zero on success, -E value on failure -*/ -int drm_plane_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane,const struct drm_colorop_funcs *funcs, -u64 supported_tfs,uint32_t flags) +static int drm_common_colorop_curve_1d_init (struct drm_device *dev, +struct drm_colorop *colorop, +u64 supported_tfs,uint32_t flags) {struct drm_prop_enum_list enum_list[DRM_COLOROP_1D_CURVE_COUNT ];int i, len;struct drm_property *prop; -int ret; - -if (!supported_tfs) { -drm_err (dev, -"No supported TFs for new 1D curve colorop on [PLANE:%d:%s]\n" , - plane->base.id, plane->name); -return -EINVAL ; - } - -if ((supported_tfs & -BIT (DRM_COLOROP_1D_CURVE_COUNT )) !=0 ) { -drm_err (dev,"Unknown TF provided on [PLANE:%d:%s]\n" , - plane->base.id, plane->name); -return -EINVAL ; - } - - ret =drm_plane_colorop_init (dev, colorop, plane, funcs,DRM_COLOROP_1D_CURVE , flags); -if (ret) -return ret; len =0 ;for (i =0 ; i <DRM_COLOROP_1D_CURVE_COUNT ; i++) {
@@ -287,6 +272,45 @@ int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *return 0 ; } + +static int drm_colorop_has_supported_tf (struct drm_device *dev,struct drm_mode_object *obj, +const char *name,u64 supported_tfs) +{ +if (!supported_tfs) { +drm_err (dev, +"No supported TFs for new 1D curve colorop on [PLANE:%d:%s]\n" , + obj->id, name); +return -EINVAL ; + } + +if ((supported_tfs & -BIT (DRM_COLOROP_1D_CURVE_COUNT )) !=0 ) { +drm_err (dev,"Unknown TF provided on [PLANE:%d:%s]\n" , + obj->id, name); +return -EINVAL ; + } + +return 0 ; +} + +int drm_plane_colorop_curve_1d_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_plane *plane, +const struct drm_colorop_funcs *funcs, +u64 supported_tfs, +uint32_t flags) +{ +int ret; + + ret =drm_colorop_has_supported_tf (dev, &plane->base, plane->name, supported_tfs); +if (ret) +return ret; + + ret =drm_plane_colorop_init (dev, colorop, plane, funcs,DRM_COLOROP_1D_CURVE , flags); +if (ret) +return ret; + +return drm_common_colorop_curve_1d_init (dev, colorop, supported_tfs, flags); +}EXPORT_SYMBOL (drm_plane_colorop_curve_1d_init);static int drm_colorop_create_data_prop (struct drm_device *dev,struct drm_colorop *colorop)
@@ -307,32 +331,15 @@ static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_colorreturn 0 ; } -/** -* drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT -* -* @dev: DRM device -* @colorop: The drm_colorop object to initialize -* @plane: The associated drm_plane -* @funcs: control functions for new colorop -* @lut_size: LUT size supported by driver -* @interpolation: 1D LUT interpolation type -* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines. -* @return zero on success, -E value on failure -*/ -int drm_plane_colorop_curve_1d_lut_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane, -const struct drm_colorop_funcs *funcs, -uint32_t lut_size, -enum drm_colorop_lut1d_interpolation_type interpolation, -uint32_t flags) +static int drm_common_colorop_curve_1d_lut_init (struct drm_device *dev, +struct drm_colorop *colorop, +uint32_t lut_size, +enum drm_colorop_lut1d_interpolation_type interpolation, +uint32_t flags) {struct drm_property *prop;int ret; - ret =drm_plane_colorop_init (dev, colorop, plane, funcs,DRM_COLOROP_1D_LUT , flags); -if (ret) -return ret; -/* initialize 1D LUT only attribute */ /* LUT size */ prop = drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ATOMIC,
@@ -363,18 +370,44 @@ int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorreturn 0 ; } -EXPORT_SYMBOL (drm_plane_colorop_curve_1d_lut_init); -int drm_plane_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane,const struct drm_colorop_funcs *funcs, -uint32_t flags) +/** +* drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT +* +* @dev: DRM device +* @colorop: The drm_colorop object to initialize +* @plane: The associated drm_plane +* @lut_size: LUT size supported by driver +* @lut1d_interpolation: 1D LUT interpolation type +* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines. +* @return zero on success, -E value on failure +*/ +int +drm_plane_colorop_curve_1d_lut_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_plane *plane, +const struct drm_colorop_funcs *funcs, +uint32_t lut_size, +enum drm_colorop_lut1d_interpolation_type lut1d_interpolation, +uint32_t flags) {int ret; - ret =drm_plane_colorop_init (dev, colorop, plane, funcs,DRM_COLOROP_CTM_3X4 , flags); + ret =drm_plane_colorop_init (dev, colorop, plane, funcs,DRM_COLOROP_1D_LUT , flags);if (ret)return ret; +return drm_common_colorop_curve_1d_lut_init (dev, colorop, lut_size, + lut1d_interpolation, flags); +} +EXPORT_SYMBOL (drm_plane_colorop_curve_1d_lut_init); + +static int drm_common_colorop_ctm_3x4_init (struct drm_device *dev, +struct drm_colorop *colorop, +uint32_t flags) +{ +int ret; + ret =drm_colorop_create_data_prop (dev, colorop);if (ret)return ret;
@@ -383,6 +416,21 @@ int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *creturn 0 ; } + +int drm_plane_colorop_ctm_3x4_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_plane *plane, +const struct drm_colorop_funcs *funcs, +uint32_t flags) +{ +int ret; + + ret =drm_plane_colorop_init (dev, colorop, plane, funcs,DRM_COLOROP_CTM_3X4 , flags); +if (ret) +return ret; + +return drm_common_colorop_ctm_3x4_init (dev, colorop, flags); +}EXPORT_SYMBOL (drm_plane_colorop_ctm_3x4_init);/**
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 10/19] drm/colorop: Factor out common paths from colorops helpers
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/colorop: missing @funcs kernel-doc and deleted curve_1d_init kernel-doc --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/colorop: missing @funcs kernel-doc and deleted curve_1d_init kernel-doc
--
commit de778a21ac78648776da670a0d86b55bc392e7de
Author: Nícolas F. R. A. Prado <[email protected]>
drm/colorop: Factor out common paths from colorops helpers
This commit factors out common initialization helpers from the plane colorop helpers so they can be shared with post-blend colorop helpers.
Quoted 4 lines
drivers/gpu/drm/drm_colorop.c +0
-0
[ ... ]
Quoted 23 lines
drivers/gpu/drm/drm_colorop.c +3
-16@@ -220,45 +236,14 @@ void drm_colorop_pipeline_destroy(struct drm_device *dev) }EXPORT_SYMBOL (drm_colorop_pipeline_destroy); -/** -* drm_plane_colorop_curve_1d_init - Initialize a DRM_COLOROP_1D_CURVE -* -* @dev: DRM device -* @colorop: The drm_colorop object to initialize -* @plane: The associated drm_plane -* @funcs: control functions for the new colorop -* @supported_tfs: A bitfield of supported drm_plane_colorop_curve_1d_init enum values, -* created using BIT(curve_type) and combined with the OR '|' -* operator. -* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines. -* @return zero on success, -E value on failure -*/ -int drm_plane_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane,const struct drm_colorop_funcs *funcs, -u64 supported_tfs,uint32_t flags) +static int drm_common_colorop_curve_1d_init (struct drm_device *dev, +struct drm_colorop *colorop, +u64 supported_tfs,uint32_t flags)
[ ... ]
Quoted 18 lines
drivers/gpu/drm/drm_colorop.c +9
-4@@ -363,18 +370,44 @@ int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorreturn 0 ; } -EXPORT_SYMBOL (drm_plane_colorop_curve_1d_lut_init); -int drm_plane_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane,const struct drm_colorop_funcs *funcs, -uint32_t flags) +/** +* drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT +* +* @dev: DRM device +* @colorop: The drm_colorop object to initialize +* @plane: The associated drm_plane +* @lut_size: LUT size supported by driver +* @lut1d_interpolation: 1D LUT interpolation type +* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines.
drivers/gpu/drm/drm_colorop.c int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_color · line 392
Quoted 10 lines
drivers/gpu/drm/drm_colorop.c +10
-0+* @return zero on success, -E value on failure +*/ +int +drm_plane_colorop_curve_1d_lut_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_plane *plane, +const struct drm_colorop_funcs *funcs, +uint32_t lut_size, +enum drm_colorop_lut1d_interpolation_type lut1d_interpolation, +uint32_t flags)
[Severity: Low]
The updated kernel-doc comment for drm_plane_colorop_curve_1d_lut_init() drops @funcs while the function still takes const struct drm_colorop_funcs *funcs, which triggers a scripts/kernel-doc warning on W=1 and htmldocs builds. Also, the kernel-doc comment for the exported drm_plane_colorop_curve_1d_init() function was removed above instead of being kept on drm_plane_colorop_curve_1d_init().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
PATCH v3 11/19 drm/colorop: Introduce colorop helpers for crtc
In reply to Melissa WenFrom: Nícolas F. R. A. Prado <[email protected]>
Introduce colorop helper counterparts for post-blend color pipelines that take a CRTC instead of a plane.
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_colorop.c | 81 +++++++++++++++++++++++++++++++++++ include/drm/drm_colorop.h | 14 ++++++ 2 files changed, 95 insertions(+)
drivers/gpu/drm/drm_colorop.c +81 -0
@@ -185,6 +185,21 @@ static int drm_plane_colorop_init(struct drm_device *dev,return ret; } +static int drm_crtc_colorop_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_crtc *crtc, +const struct drm_colorop_funcs *funcs, +enum drm_colorop_type type,uint32_t flags) +{ +int ret; + + ret =drm_common_colorop_init (dev, colorop, funcs, type, flags); + + colorop->crtc = crtc; + +return ret; +} +/** * drm_colorop_cleanup - Cleanup a drm_colorop object in color_pipeline *
@@ -313,6 +328,26 @@ int drm_plane_colorop_curve_1d_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_plane_colorop_curve_1d_init); +int drm_crtc_colorop_curve_1d_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_crtc *crtc, +const struct drm_colorop_funcs *funcs, +u64 supported_tfs,uint32_t flags) +{ +int ret; + + ret =drm_colorop_has_supported_tf (dev, &crtc->base, crtc->name, supported_tfs); +if (ret) +return ret; + + ret =drm_crtc_colorop_init (dev, colorop, crtc, funcs,DRM_COLOROP_1D_CURVE , flags); +if (ret) +return ret; + +return drm_common_colorop_curve_1d_init (dev, colorop, supported_tfs, flags); +} +EXPORT_SYMBOL (drm_crtc_colorop_curve_1d_init); +static int drm_colorop_create_data_prop (struct drm_device *dev,struct drm_colorop *colorop) {struct drm_property *prop;
@@ -402,6 +437,37 @@ drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_plane_colorop_curve_1d_lut_init); +/** +* drm_crtc_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT +* +* @dev: DRM device +* @colorop: The drm_colorop object to initialize +* @crtc: The associated drm_crtc +* @lut_size: LUT size supported by driver +* @interpolation: 1D LUT interpolation type +* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines. +* @return zero on success, -E value on failure +*/ +int +drm_crtc_colorop_curve_1d_lut_init (struct drm_device *dev, +struct drm_colorop *colorop, +struct drm_crtc *crtc, +const struct drm_colorop_funcs *funcs, +uint32_t lut_size, +enum drm_colorop_lut1d_interpolation_type interpolation, +uint32_t flags) +{ +int ret; + + ret =drm_crtc_colorop_init (dev, colorop, crtc, funcs,DRM_COLOROP_1D_LUT , flags); +if (ret) +return ret; + +return drm_common_colorop_curve_1d_lut_init (dev, colorop, lut_size, + interpolation, flags); +} +EXPORT_SYMBOL (drm_crtc_colorop_curve_1d_lut_init); +static int drm_common_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop,uint32_t flags)
@@ -433,6 +499,21 @@ int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_plane_colorop_ctm_3x4_init); +int drm_crtc_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_crtc *crtc, +const struct drm_colorop_funcs *funcs, +uint32_t flags) +{ +int ret; + + ret =drm_crtc_colorop_init (dev, colorop, crtc, funcs,DRM_COLOROP_CTM_3X4 , flags); +if (ret) +return ret; + +return drm_common_colorop_ctm_3x4_init (dev, colorop, flags); +} +EXPORT_SYMBOL (drm_crtc_colorop_ctm_3x4_init); +/** * drm_plane_colorop_mult_init - Initialize a DRM_COLOROP_MULTIPLIER *
include/drm/drm_colorop.h +14 -0
@@ -535,6 +535,13 @@ static inline struct drm_colorop *drm_colorop_find(struct drm_device *dev,void drm_colorop_pipeline_destroy (struct drm_device *dev);void drm_colorop_cleanup (struct drm_colorop *colorop); +int drm_crtc_colorop_curve_1d_lut_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_crtc *crtc, +const struct drm_colorop_funcs *funcs, +uint32_t lut_size, +enum drm_colorop_lut1d_interpolation_type interpolation, +uint32_t flags); +int drm_plane_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane,const struct drm_colorop_funcs *funcs,u64 supported_tfs,uint32_t flags);
@@ -544,9 +551,16 @@ int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_coloruint32_t lut_size, enum drm_colorop_lut1d_interpolation_type interpolation, uint32_t flags); +int drm_crtc_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_crtc *crtc, +const struct drm_colorop_funcs *funcs, +u64 supported_tfs,uint32_t flags); +int drm_plane_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane,const struct drm_colorop_funcs *funcs,uint32_t flags); +int drm_crtc_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_crtc *crtc,const struct drm_colorop_funcs *funcs,uint32_t flags);int drm_plane_colorop_mult_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane,const struct drm_colorop_funcs *funcs,uint32_t flags);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 11/19] drm/colorop: Introduce colorop helpers for crtc
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] drm/colorop: missing @funcs doc in drm_crtc_colorop_curve_1d_lut_init() - [Low] drm/colorop…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] drm/colorop: missing @funcs doc in drm_crtc_colorop_curve_1d_lut_init()
- [Low] drm/colorop: hardcoded PLANE log prefix in drm_colorop_has_supported_tf()
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] drm/colorop: missing error cleanup in drm_plane_colorop_init()
[1]
--
commit 31c092228a64133171c742733eb09f34d70d27f6
Author: Nícolas F. R. A. Prado <[email protected]>
drm/colorop: Introduce colorop helpers for crtc
This commit adds CRTC-based colorop initialization helpers for post-blend 1D curve, 1D LUT, and 3x4 CTM color pipelines.
Quoted 4 lines
drivers/gpu/drm/drm_colorop.c +0
-0
[ ... ]
Quoted 5 lines
drivers/gpu/drm/drm_colorop.c +1
-0@@ -313,6 +328,26 @@ int drm_plane_colorop_curve_1d_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_plane_colorop_curve_1d_init); +int drm_crtc_colorop_curve_1d_init(struct drm_device *dev,
drivers/gpu/drm/drm_colorop.c int drm_plane_colorop_curve_1d_init(struct drm_device *dev, · line 341
Quoted 10 lines
drivers/gpu/drm/drm_colorop.c +10
-0+struct drm_colorop *colorop, + struct drm_crtc *crtc, + const struct drm_colorop_funcs *funcs, + u64 supported_tfs, uint32_t flags) +{ + int ret; + + ret =drm_colorop_has_supported_tf (dev, &crtc->base, crtc->name, supported_tfs); +if (ret) +return ret;
[Severity: Low]
When drm_colorop_has_supported_tf() rejects supported_tfs here, does it log the CRTC with a [PLANE:%d:%s] prefix? Both drm_err() messages in drm_colorop_has_supported_tf() hardcode [PLANE:%d:%s].
drivers/gpu/drm/drm_colorop.c int drm_plane_colorop_curve_1d_init(struct drm_device *dev, · line 349
Quoted 8 lines
drivers/gpu/drm/drm_colorop.c +8
-0+ + ret =drm_crtc_colorop_init (dev, colorop, crtc, funcs,DRM_COLOROP_1D_CURVE , flags); +if (ret) +return ret; + +return drm_common_colorop_curve_1d_init (dev, colorop, supported_tfs, flags); +} +EXPORT_SYMBOL (drm_crtc_colorop_curve_1d_init);
[Severity: High]
This problem wasn't introduced by this patch, but if property creation fails in drm_common_colorop_init() or in a subtype helper such as drm_common_colorop_curve_1d_init() [1], does it leave colorop registered in dev->mode_config.object_idr and linked in config->colorop_list with colorop->state still NULL?
drm_common_colorop_init() calls drm_mode_object_add() and adds colorop->head to config->colorop_list before creating the base properties, while colorop->state is only allocated at the end of the subtype helper by drm_colorop_reset():
drivers/gpu/drm/drm_colorop.c:drm_common_colorop_init() {
ret = drm_mode_object_add(dev, &colorop->base, DRM_MODE_OBJECT_COLOROP);
if (ret)
return ret;
...
list_add_tail(&colorop->head, &config->colorop_list);
colorop->index = config->num_colorop++;
...
prop = drm_property_create_enum(dev,
DRM_MODE_PROP_IMMUTABLE,
"TYPE", drm_colorop_type_enum_list,
ARRAY_SIZE(drm_colorop_type_enum_list));
if (!prop)
return -ENOMEM;
}If any property allocation fails, neither drm_common_colorop_init() nor the subtype helpers unwind the registration, so querying the published mode object via DRM_IOCTL_MODE_OBJ_GETPROPERTIES will hit a NULL pointer dereference on colorop->state in drm_atomic_colorop_get_property().
Quoted 10 lines
drivers/gpu/drm/drm_colorop.c +6
-0@@ -402,6 +437,37 @@ drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, }EXPORT_SYMBOL (drm_plane_colorop_curve_1d_lut_init); +/** +* drm_crtc_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT +* +* @dev: DRM device +* @colorop: The drm_colorop object to initialize +* @crtc: The associated drm_crtc
drivers/gpu/drm/drm_colorop.c drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, · line 455
Quoted 10 lines
drivers/gpu/drm/drm_colorop.c +10
-0+* @lut_size: LUT size supported by driver +* @interpolation: 1D LUT interpolation type +* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines. +* @return zero on success, -E value on failure +*/ +int +drm_crtc_colorop_curve_1d_lut_init(struct drm_device *dev, + struct drm_colorop *colorop, + struct drm_crtc *crtc, + const struct drm_colorop_funcs *funcs,
[Severity: Low]
The kernel-doc comment for drm_crtc_colorop_curve_1d_lut_init() omits the @funcs parameter description (and uses @return instead of Return:), which triggers a scripts/kernel-doc warning when building documentation or with W=1.
[1] https://sashiko.dev/#/bug/linux-e4f43398-10d0-4ccc-944b-469733dc5b85
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
PATCH v3 12/19 drm/colorop: distinguish whether a colorop belongs to a plane or a CRTC
In reply to Melissa WenTo correctly track states and color management changes with the support of both pre-blend and post-blend colorop.
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_atomic_uapi.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_atomic_uapi.c +19 -6
@@ -1382,7 +1382,6 @@ int drm_atomic_set_property(struct drm_atomic_commit *state,break ; }case DRM_MODE_OBJECT_COLOROP : { -struct drm_plane_state *plane_state;struct drm_colorop *colorop =obj_to_colorop (obj);struct drm_colorop_state *colorop_state;bool replaced = false;
@@ -1407,12 +1406,26 @@ int drm_atomic_set_property(struct drm_atomic_commit *state,if (ret || !replaced)break ; - plane_state =drm_atomic_get_plane_state (state, colorop->plane); -if (IS_ERR (plane_state)) { - ret =PTR_ERR (plane_state); -break ; +if (colorop->plane) { +struct drm_plane_state *plane_state; + + plane_state =drm_atomic_get_plane_state (state, colorop->plane); +if (IS_ERR (plane_state)) { + ret =PTR_ERR (plane_state); +break ; + } + plane_state->color_mgmt_changed |= replaced; + }else if (colorop->crtc) { +struct drm_crtc_state *crtc_state; + + crtc_state =drm_atomic_get_crtc_state (state, colorop->crtc); +if (IS_ERR (crtc_state)) { + ret =PTR_ERR (crtc_state); +break ; + } + crtc_state->color_mgmt_changed |= replaced; + } - plane_state->color_mgmt_changed |= replaced;break ; }
Signature · 1 line
2.53.0
PATCH v3 13/19 drm/drm_mode_object: hide deprecated CRTC color mgmt props if colorop is set
In reply to Melissa WenStop advertising CRTC color mgmt properties if post-blend colorop is enabled. Follow the same approach done for plane COLOR_ENCODING and COLOR_RANGE when pre-blend colorop is enabled.
---
v3:
- rebase on drm-misc-next, no other changes
--- drivers/gpu/drm/drm_mode_object.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_mode_object.c +11 -2
@@ -442,10 +442,19 @@ int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,continue ; } -if (!crtc_color_pipeline && obj->type ==DRM_MODE_OBJECT_CRTC ) { +if (obj->type ==DRM_MODE_OBJECT_CRTC ) {struct drm_crtc *crtc =obj_to_crtc (obj); +struct drm_mode_config *config = &crtc->dev->mode_config; -if (prop == crtc->color_pipeline_property) +if (!crtc_color_pipeline && prop == crtc->color_pipeline_property) +continue ; + +if (crtc_color_pipeline && + (prop == config->degamma_lut_property || + prop == config->degamma_lut_size_property || + prop == config->ctm_property || + prop == config->gamma_lut_property || + prop == config->gamma_lut_size_property))continue ; }
Signature · 1 line
2.53.0
PATCH v3 14/19 drm/atomic: set hidden CRTC color mgmt model to default values
In reply to Melissa WenUserspace sees a single CRTC color management model: the colorop pipeline if DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE is set, or CRTC color properties otherwise. When the other model is hidden, CRTC still holds its previous property settings and, without visibility, the userspace cannot clear it anymore.
Reset the hidden model to its default value on every CRTC included in an atomic commit: clear blobs if colorop pipeline, and set COLOR_PIPELINE to Bypass if CRTC color properties are in place. Colorop values aren't touched, so re-selecting a pipeline later restores them. Only set color_mgmt_changed flag when something was actually reset.
---
v3:
- new patch, as for planes, drivers now decide from crtc_state->color_pipeline between colorop or CRTC color properties and the core sets the properties of the model hidden from the client to their defaults.
--- drivers/gpu/drm/drm_atomic_uapi.c | 28 ++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 6 ++++-- include/uapi/drm/drm.h | 4 ++++ 3 files changed, 36 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic_uapi.c +28 -0
@@ -1695,6 +1695,32 @@ static void complete_signaling(struct drm_device *dev,kfree (fence_state); } +static void +reset_crtc_color_mgmt_props (struct drm_atomic_commit *state, +struct drm_file *file_priv, +bool async_flip) +{ +struct drm_crtc_state *crtc_state; +struct drm_crtc *crtc; +bool changed; +int i; + +/* Async page flip doesn't change properties */ +if (async_flip) +return ; + +for_each_new_crtc_in_state (state, crtc, crtc_state, i) { +if (file_priv->crtc_color_pipeline) { + changed =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); + changed |=drm_property_replace_blob (&crtc_state->ctm,NULL ); + changed |=drm_property_replace_blob (&crtc_state->gamma_lut,NULL ); + }else { + changed =drm_atomic_set_colorop_for_crtc (crtc_state,NULL ); + } + crtc_state->color_mgmt_changed |= changed; + } +} +static void set_async_flip (struct drm_atomic_commit *state) {
@@ -1853,6 +1879,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,drm_mode_object_put (obj); } +reset_crtc_color_mgmt_props (state, file_priv, async_flip); + ret =prepare_signaling (dev, state, arg, file_priv, &fence_state, &num_fences);if (ret)
include/drm/drm_crtc.h +4 -2
@@ -277,8 +277,10 @@ struct drm_crtc_state {/** * @color_pipeline: * -* The first colorop of the active color pipeline, or NULL, if no -* color pipeline is active. +* The first colorop of the active color pipeline, or NULL, if no color +* pipeline is active. Drivers program CRTC color management from this +* pipeline when it is set, and from @degamma_lut, @ctm and @gamma_lut +* properties otherwise. */ struct drm_colorop *color_pipeline;
include/uapi/drm/drm.h +4 -0
@@ -915,6 +915,10 @@ struct drm_get_cap {* - DEGAMMA_LUT * - CTM * +* Userspace can only see one CRTC color management model. On every CRTC +* included in an atomic commit, the DRM core resets CRTC color properties of +* the hidden model to default values. +* * The client must enable &DRM_CLIENT_CAP_ATOMIC first. * * This client cap can only be set if the driver sets the corresponding driver
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 14/19] drm/atomic: set hidden CRTC color mgmt model to default values
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/atomic: hidden CRTC color model not reset outside drm_mode_atomic_ioctl() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/atomic: hidden CRTC color model not reset outside drm_mode_atomic_ioctl()
--
commit 988786e967d206ee7e346b8385770656e4c8ad9e
Author: Melissa Wen <[email protected]>
drm/atomic: set hidden CRTC color mgmt model to default values
This commit resets the hidden CRTC color management properties (either the legacy LUT/CTM blobs or the colorop pipeline) to default values on each CRTC included in an atomic ioctl commit.
Quoted 38 lines
drivers/gpu/drm/drm_atomic_uapi.c +26
-0@@ -1687,6 +1687,32 @@ static void complete_signaling(struct drm_device *dev,kfree (fence_state); } +static void +reset_crtc_color_mgmt_props (struct drm_atomic_commit *state, +struct drm_file *file_priv, +bool async_flip) +{ +struct drm_crtc_state *crtc_state; +struct drm_crtc *crtc; +bool changed; +int i; + +/* Async page flip doesn't change properties */ +if (async_flip) +return ; + +for_each_new_crtc_in_state (state, crtc, crtc_state, i) { +if (file_priv->crtc_color_pipeline) { + changed =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); + changed |=drm_property_replace_blob (&crtc_state->ctm,NULL ); + changed |=drm_property_replace_blob (&crtc_state->gamma_lut,NULL ); + }else { + changed =drm_atomic_set_colorop_for_crtc (crtc_state,NULL ); + } + crtc_state->color_mgmt_changed |= changed; + } +} +static void set_async_flip (struct drm_atomic_commit *state) {
drivers/gpu/drm/drm_atomic_uapi.c int drm_mode_atomic_ioctl(struct drm_device *dev, · line 1874
Quoted 4 lines
drivers/gpu/drm/drm_atomic_uapi.c +1
-0@@ -1845,6 +1871,8 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,drm_mode_object_put (obj); } +reset_crtc_color_mgmt_props (state, file_priv, async_flip);
[Severity: Medium]
Does calling reset_crtc_color_mgmt_props() only in drm_mode_atomic_ioctl() leave crtc_state->color_pipeline active when a later client updates CRTC color properties through other atomic commit paths?
For example, after a client with DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE sets a CRTC color pipeline, switching to a client or helper that updates gamma or CTM via drm_crtc_legacy_gamma_set() (DRM_IOCTL_MODE_SETGAMMA), set_property_atomic() (DRM_IOCTL_MODE_OBJ_SETPROPERTY), or fbdev's setcmap_atomic() commits the new LUT/CTM blobs without clearing crtc_state->color_pipeline. Because drivers program CRTC color management from color_pipeline whenever it is non-NULL and only fall back to degamma_lut, ctm, and gamma_lut otherwise, those updates are silently ignored while the previous client's color pipeline remains active.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
PATCH v3 15/19 drm/drm_ioctl: guard DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE
In reply to Melissa WenIf the driver doesn't support post-blend colorop, refuse attempts from userspace to set it. Same approach is taken for pre-blend colorop since commit ac7c6b4308c5 ("drm: Guard DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE").
---
v3:
- refuse the cap when no CRTC has a color pipeline as the plane guard does
- drop the stale DRM_CAP_CRTC_COLOR_PIPELINE requirement from the cap documentation
--- drivers/gpu/drm/drm_ioctl.c | 15 ++++++++++++++- include/uapi/drm/drm.h | 3 --- 2 files changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_ioctl.c +14 -1
@@ -392,13 +392,26 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv) file_priv->plane_color_pipeline = req->value;break ; } -case DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE : +case DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE : { +struct drm_crtc *crtc; +bool has_crtc_with_color_pipeline = false; +if (!file_priv->atomic)return -EINVAL ;if (req->value >1 )return -EINVAL ; +drm_for_each_crtc (crtc, dev) { +if (crtc->color_pipeline_property) { + has_crtc_with_color_pipeline = true; +break ; + } + } +if (!has_crtc_with_color_pipeline) +return -EOPNOTSUPP ; + file_priv->crtc_color_pipeline = req->value;break ; + }default :return -EINVAL ; }
include/uapi/drm/drm.h +0 -3
@@ -920,9 +920,6 @@ struct drm_get_cap {* the hidden model to default values. * * The client must enable &DRM_CLIENT_CAP_ATOMIC first. -* -* This client cap can only be set if the driver sets the corresponding driver -* cap &DRM_CAP_CRTC_COLOR_PIPELINE. */ #define DRM_CLIENT_CAP_CRTC_COLOR_PIPELINE 8
Signature · 1 line
2.53.0
PATCH v3 16/19 drm/amd/display: move CRTC CTM color mgmt prop to check helper
In reply to Melissa WenMove legacy CRTC CTM color mgmt handlers to AMD atomic check helper to centralize legacy properties in a single place, so that we can reuse the callers to these helpers for colorop setup.
---
v3:
- move before the post-blend colorop patches, so the previous CTM setup can't override the CTM colorop once the pipeline is enabled
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +32 -34
@@ -1265,6 +1265,7 @@ int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state *crtc,uint32_t degamma_size, regamma_size;bool has_regamma, has_degamma;enum dc_transfer_func_predefined tf =TRANSFER_FUNCTION_LINEAR ; +struct drm_color_ctm *ctm =NULL ;bool is_legacy;int r;
@@ -1334,10 +1335,38 @@ int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state *crtc,* have to place the CTM in the OCSC in that case. */ crtc->cm_has_degamma = has_degamma; -if (check_only) +if (check_only) {kvfree (out_tf); +return r; + } -return r; +if (r) +return r; + +/* Setup CRTC CTM. */ +if (crtc->base.ctm) { + ctm = (struct drm_color_ctm *)crtc->base.ctm->data; + +/* +* Gamut remapping must be used for gamma correction +* since it comes before the regamma correction. +* +* OCSC could be used for gamma correction, but we'd need to +* blend the adjustments together with the required output +* conversion matrix - so just use the gamut remap block +* for now. +*/ +__drm_ctm_to_dc_matrix (ctm, stream->gamut_remap_matrix.matrix); + + stream->gamut_remap_matrix.enable_remap = true; + stream->csc_color_matrix.enable_adjustment = false; + }else { +/* Bypass CTM. */ + stream->gamut_remap_matrix.enable_remap = false; + stream->csc_color_matrix.enable_adjustment = false; + } + +return 0 ; }EXPORT_IF_KUNIT (amdgpu_dm_check_crtc_color_mgmt);
@@ -1365,38 +1394,7 @@ EXPORT_IF_KUNIT(amdgpu_dm_check_crtc_color_mgmt);*/ int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc) { -struct dc_stream_state *stream = crtc->stream; -struct drm_color_ctm *ctm =NULL ; -int ret; - - ret =amdgpu_dm_check_crtc_color_mgmt (crtc, false); -if (ret) -return ret; - -/* Setup CRTC CTM. */ -if (crtc->base.ctm) { - ctm = (struct drm_color_ctm *)crtc->base.ctm->data; - -/* -* Gamut remapping must be used for gamma correction -* since it comes before the regamma correction. -* -* OCSC could be used for gamma correction, but we'd need to -* blend the adjustments together with the required output -* conversion matrix - so just use the gamut remap block -* for now. -*/ -__drm_ctm_to_dc_matrix (ctm, stream->gamut_remap_matrix.matrix); - - stream->gamut_remap_matrix.enable_remap = true; - stream->csc_color_matrix.enable_adjustment = false; - }else { -/* Bypass CTM. */ - stream->gamut_remap_matrix.enable_remap = false; - stream->csc_color_matrix.enable_adjustment = false; - } - -return 0 ; +return amdgpu_dm_check_crtc_color_mgmt (crtc, false); }EXPORT_IF_KUNIT (amdgpu_dm_update_crtc_color_mgmt);
Signature · 1 line
2.53.0
PATCH v3 17/19 drm/amd/display: enable post-blend CTM colorop
In reply to Melissa WenInitialize the AMD post-blend color pipeline with CTM as the first color operation in the AMD post-blend color pipeline. AMD post-blend color pipeline for DCN3 is described in DCN 3.0 family color caps and mapping of the kernel doc.
Only enable post-blend colorop properties if there is no AMD private color prop.
---
v3:
- merge "drm/amd/display: enable post-blend colorop properties" into this patch
- choose between the colorop and the CRTC color props from crtc_state->color_pipeline
- set colorop funcs on the CTM colorop (fixes a NULL pointer dereference on destroy)
- use the committed state of the CTM colorop when it isn't part of the commit
- reject a colorop of unexpected type and program bypass explicitly as in [1].
- reset the CRTC degamma flags when colorop is in use
- make amdgpu_dm_crtc_set_colorop_properties() static
- reject an enabled CTM colorop without a DATA blob. Note: becomes redundant if [1] is applied first.
[1] https://lore.kernel.org/dri-devel/[email protected]
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 97 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 38 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 42 ++++++++ 4 files changed, 179 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +97 -0
@@ -1233,6 +1233,96 @@ int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state) }EXPORT_IF_KUNIT (amdgpu_dm_verify_lut_sizes); +static int +__set_dm_crtc_colorop_3x4_matrix (struct drm_crtc_state *crtc_state, +struct dc_stream_state *dc_stream_state, +struct drm_colorop *colorop, +bool check_only) +{ +struct drm_colorop_state *colorop_state; +struct drm_atomic_commit *state = crtc_state->state; +const struct drm_property_blob *blob; +struct drm_color_ctm_3x4 *ctm =NULL ; + +if (colorop->type !=DRM_COLOROP_CTM_3X4 ) +return -EINVAL ; + +/* A colorop that isn't part of this commit keeps its committed state. +* It allows individual colorop changes. +*/ + colorop_state =drm_atomic_get_new_colorop_state (state, colorop); +if (!colorop_state) + colorop_state = colorop->state; + +if (colorop_state->bypass) { +if (!check_only) { + dc_stream_state->gamut_remap_matrix.enable_remap = false; + dc_stream_state->csc_color_matrix.enable_adjustment = false; + } +return 0 ; + } + +drm_dbg (state->dev,"3x4 matrix colorop with ID: %d\n" , colorop->base.id); + blob = colorop_state->data; +if (!blob) { +drm_dbg_atomic (state->dev, +"[COLOROP:%d] enabled without a DATA blob\n" , + colorop->base.id); +return -EINVAL ; + } + +if (blob->length !=sizeof (struct drm_color_ctm_3x4 )) { +drm_warn (state->dev,"blob->length (%zu) isn't equal to drm_color_ctm_3x4 (%zu)\n" , + blob->length,sizeof (struct drm_color_ctm_3x4 )); +return -EINVAL ; + } + +if (!check_only) { + ctm = (struct drm_color_ctm_3x4 *)blob->data; +__drm_ctm_3x4_to_dc_matrix (ctm, dc_stream_state->gamut_remap_matrix.matrix); + dc_stream_state->gamut_remap_matrix.enable_remap = true; + dc_stream_state->csc_color_matrix.enable_adjustment = false; + } + +return 0 ; +} + +/* +* amdgpu_dm_crtc_set_colorop_properties: Set colorop props if programmable by DC. +* @crtc_state: DRM crtc state +* @dc_stream_state: AMDGPU DC stream state +* @check_only: only check color state without update dc stream +* +* This function verifies post-blend CTM and LUT sizes: if there is enough space, and for +* output transfer function, if its parameters can be calculated by AMD +* color module. The main difference with CRTC color mgmt properties is that +* post-blend degamma is not part of the color pipeline since it's actually +* supported pre-blend only. +* +* If it's not an atomic check, DC resources are checked and updated +* accordingly. +* +* Returns: +* 0 on success. Error code if validation fails. +*/ +static int +amdgpu_dm_crtc_set_colorop_properties (struct drm_crtc_state *crtc_state, +struct dc_stream_state *dc_stream_state, +bool check_only) +{ +struct drm_colorop *colorop = crtc_state->color_pipeline; +struct drm_device *dev = crtc_state->crtc->dev; +int ret; + +if (drm_WARN_ON (dev, !colorop)) +return -EINVAL ; + +/* 3x4 matrix */ + ret =__set_dm_crtc_colorop_3x4_matrix (crtc_state, dc_stream_state, colorop, check_only); + +return ret; +} +/** * amdgpu_dm_check_crtc_color_mgmt: Check if DRM color props are programmable by DC. * @crtc: amdgpu_dm crtc state
@@ -1269,6 +1359,13 @@ int amdgpu_dm_check_crtc_color_mgmt(struct dm_crtc_state *crtc,bool is_legacy;int r; +if (crtc->base.color_pipeline) { + crtc->cm_has_degamma = false; + crtc->cm_is_degamma_srgb = false; + r =amdgpu_dm_crtc_set_colorop_properties (&crtc->base, stream, check_only); +return r; + } + tf =amdgpu_tf_to_dc_tf (crtc->regamma_tf); r =amdgpu_dm_verify_lut_sizes (&crtc->base);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +38 -0
@@ -301,3 +301,41 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_prreturn amdgpu_dm_build_default_pipeline (dev, plane, hw_3d_lut, list); }EXPORT_IF_KUNIT (amdgpu_dm_initialize_default_pipeline); + +int amdgpu_dm_initialize_crtc_default_pipeline (struct drm_crtc *crtc, +struct drm_prop_enum_list *list) +{ +struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS ]; +struct drm_device *dev = crtc->dev; +int ret; +int i =0 ; + +memset (ops,0 ,sizeof (ops)); + +/* 3x4 matrix */ + ops[i] = kzalloc_obj(struct drm_colorop); +if (!ops[i]) { + ret = -ENOMEM ; + goto cleanup; + } + + ret =drm_crtc_colorop_ctm_3x4_init (dev, ops[i], crtc, &dm_colorop_funcs, +DRM_COLOROP_FLAG_ALLOW_BYPASS ); +if (ret) + goto cleanup; + + list->type = ops[i]->base.id; + + i++; + + list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , ops[0 ]->base.id); + +return 0 ; +cleanup: +if (ret == -ENOMEM ) +drm_err (crtc->dev,"KMS: Failed to allocate colorop\n" ); + +drm_colorop_pipeline_destroy (dev); + +return ret; +}
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h +2 -0
@@ -34,6 +34,8 @@ extern const u64 amdgpu_dm_supported_fm;int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list); +int amdgpu_dm_initialize_crtc_default_pipeline (struct drm_crtc *crtc,struct drm_prop_enum_list *list); +#if IS_ENABLED (CONFIG_DRM_AMD_DC_KUNIT_TEST )#include <drm/drm_colorop.h>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +42 -0
60 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 17/19] drm/amd/display: enable post-blend CTM colorop
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/amd/display: NULL deref on kasprintf() failure in CRTC pipeline init - [Medium]…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/amd/display: NULL deref on kasprintf() failure in CRTC pipeline init
- [Medium] drm/amd/display: missing error unwind in amdgpu_dm_crtc_init()
--
commit a6af21490f0a9bf347d95f27bc66b20a42758591
Author: Melissa Wen <[email protected]>
drm/amd/display: enable post-blend CTM colorop
This commit initializes the AMD post-blend color pipeline on DCN 3.0 and newer with a 3x4 CTM colorop and programs it when a CRTC color pipeline is active.
Quoted 28 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +20
-0@@ -305,3 +305,41 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_prreturn amdgpu_dm_build_default_pipeline (dev, plane, hw_3d_lut, list); }EXPORT_IF_KUNIT (amdgpu_dm_initialize_default_pipeline); + +int amdgpu_dm_initialize_crtc_default_pipeline (struct drm_crtc *crtc, +struct drm_prop_enum_list *list) +{ +struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS ]; +struct drm_device *dev = crtc->dev; +int ret; +int i =0 ; + +memset (ops,0 ,sizeof (ops)); + +/* 3x4 matrix */ + ops[i] = kzalloc_obj(struct drm_colorop); +if (!ops[i]) { + ret = -ENOMEM ; + goto cleanup; + } + + ret =drm_crtc_colorop_ctm_3x4_init (dev, ops[i], crtc, &dm_colorop_funcs, +DRM_COLOROP_FLAG_ALLOW_BYPASS );
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_pr · line 337
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +10
-0+if (ret) + goto cleanup; + + list->type = ops[i]->base.id; + + i++; + + list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , ops[0 ]->base.id); + +return 0 ;
[Severity: Medium]
What happens if kasprintf() returns NULL here? Unlike amdgpu_dm_build_default_pipeline(), this returns 0 with list->name set to NULL, so dm_crtc_init_colorops() passes pipelines[0].name to drm_crtc_create_color_pipeline_property() -> drm_property_add_enum(), causing a NULL pointer dereference in strlen(name) and skipping cleanup of the initialized colorop.
[ ... ]
Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +0
-0
[ ... ]
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm, · line 886
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +4
-0@@ -840,6 +878,10 @@ int amdgpu_dm_crtc_init(struct amdgpu_display_manager *dm,#ifdef AMD_PRIVATE_COLOR dm_crtc_additional_color_mgmt (&acrtc->base); +#else + res =dm_crtc_init_colorops (&acrtc->base); +if (res) +return res;#endif return 0 ;
[Severity: Medium]
Should a failure in dm_crtc_init_colorops() clear dm->adev->mode_info.crtcs[crtc_index] and jump to error_ism_fini instead of returning directly? Returning early skips amdgpu_dm_ism_flush(), drm_crtc_cleanup(), drm_plane_cleanup(), and freeing acrtc and cursor_plane, leaving the partially initialized CRTC registered in mode_config and stored in mode_info.crtcs[crtc_index].
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
PATCH v3 18/19 drm/amd/display: add support to post-blend 1D-Curve colorop
In reply to Melissa WenAdd Regamma TF operation as 1D Curve colorop to the AMD post-blend color pipeline. Allow individual changes on colorop properties by using the committed state of colorops that aren't in the commit.
---
v3:
- use the committed state of the curve colorop when it isn't part of the commit
- reject a colorop of unexpected type
- drop the NULL colorop path since it's now only called with a colorop set
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 58 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 20 +++++++ 2 files changed, 78 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +58 -0
@@ -1287,6 +1287,41 @@ __set_dm_crtc_colorop_3x4_matrix(struct drm_crtc_state *crtc_state,return 0 ; } +static int +__set_dm_crtc_colorop_regamma (struct drm_crtc_state *crtc_state, +struct dc_stream_state *dc_stream_state, +struct drm_colorop *colorop, +struct dc_transfer_func *tf) +{ +struct drm_colorop_state *colorop_state =NULL ; +struct drm_atomic_commit *state = crtc_state->state; +enum dc_transfer_func_predefined default_tf =TRANSFER_FUNCTION_LINEAR ; +struct drm_device *dev = crtc_state->state->dev; +int ret =0 ; + + tf->type =TF_TYPE_BYPASS ; + +/* 1D Curve - Regamma TF */ +if (colorop->type !=DRM_COLOROP_1D_CURVE ) +return -EINVAL ; + + colorop_state =drm_atomic_get_new_colorop_state (state, colorop); +if (!colorop_state) + colorop_state = colorop->state; + +if (!colorop_state->bypass) { +drm_dbg (dev,"Regamma TF colorop with ID: %d\n" , colorop->base.id); + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf = default_tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; + ret =__set_output_tf (tf,0 ,0 , false); +if (ret) +return ret; + } + +return 0 ; +} +/* * amdgpu_dm_crtc_set_colorop_properties: Set colorop props if programmable by DC. * @crtc_state: DRM crtc state
@@ -1312,6 +1347,7 @@ amdgpu_dm_crtc_set_colorop_properties(struct drm_crtc_state *crtc_state, {struct drm_colorop *colorop = crtc_state->color_pipeline;struct drm_device *dev = crtc_state->crtc->dev; +struct dc_transfer_func *out_tf;int ret;if (drm_WARN_ON (dev, !colorop))
@@ -1319,6 +1355,28 @@ amdgpu_dm_crtc_set_colorop_properties(struct drm_crtc_state *crtc_state,/* 3x4 matrix */ ret =__set_dm_crtc_colorop_3x4_matrix (crtc_state, dc_stream_state, colorop, check_only); +if (ret) +return ret; + +/* 1D Curve - REGAMMA TF */ + colorop = colorop->next; +if (!colorop) { +drm_dbg (dev,"no regamma TF colorop found\n" ); +return -EINVAL ; + } + +if (check_only) { + out_tf =kvzalloc_obj (*out_tf); +if (!out_tf) +return -ENOMEM ; + }else { + out_tf = &dc_stream_state->out_transfer_func; + } + + ret =__set_dm_crtc_colorop_regamma (crtc_state, dc_stream_state, colorop, out_tf); + +if (check_only) +kvfree (out_tf);return ret; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +20 -0
@@ -307,6 +307,7 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, {struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS ];struct drm_device *dev = crtc->dev; +struct amdgpu_device *adev =drm_to_adev (dev);int ret;int i =0 ;
@@ -328,6 +329,25 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, i++; +if (adev->dm.dc->caps.color.mpc.ogam_ram) { +/* 1D Curve - REGAMMA TF */ + ops[i] =kzalloc_obj (*ops[0 ]); +if (!ops[i]) { + ret = -ENOMEM ; + goto cleanup; + } + + ret =drm_crtc_colorop_curve_1d_init (dev, ops[i], crtc, &dm_colorop_funcs, + amdgpu_dm_supported_shaper_tfs, +DRM_COLOROP_FLAG_ALLOW_BYPASS ); +if (ret) + goto cleanup; + +drm_colorop_set_next_property (ops[i-1 ], ops[i]); + + i++; + } + list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , ops[0 ]->base.id);return 0 ;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 18/19] drm/amd/display: add support to post-blend 1D-Curve colorop
Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] drm/amd/display: missing ogam_ram check when applying CRTC regamma colorop - [Medium]…
Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [Medium] drm/amd/display: missing ogam_ram check when applying CRTC regamma colorop
- [Medium] drm/amd/display: stale out_transfer_func.tf in __set_dm_crtc_colorop_regamma()
- [Medium] drm/amd/display: colorop leak in amdgpu_dm_initialize_crtc_default_pipeline()
- [Medium] drm/amd/display: unchecked kasprintf() in CRTC default pipeline init
- [Low] drm/amd/display: unused param and variable in __set_dm_crtc_colorop_regamma()
--
commit a10135e3487a34c61aa5df0ce12f0d6b9ae37b7c
Author: Melissa Wen <[email protected]>
drm/amd/display: add support to post-blend 1D-Curve colorop
This commit adds a 1D curve regamma transfer function colorop to the AMD CRTC post-blend color pipeline and applies its state during atomic check and commit.
Quoted 15 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +7
-0@@ -1287,6 +1287,41 @@ __set_dm_crtc_colorop_3x4_matrix(struct drm_crtc_state *crtc_state,return 0 ; } +static int +__set_dm_crtc_colorop_regamma (struct drm_crtc_state *crtc_state, +struct dc_stream_state *dc_stream_state, +struct drm_colorop *colorop, +struct dc_transfer_func *tf) +{ +struct drm_colorop_state *colorop_state =NULL ;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c __set_dm_crtc_colorop_3x4_matrix(struct drm_crtc_state *crtc_state, · line 1306
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +10
-0+struct drm_atomic_commit *state = crtc_state->state; +enum dc_transfer_func_predefined default_tf =TRANSFER_FUNCTION_LINEAR ; +struct drm_device *dev = crtc_state->state->dev; +int ret =0 ; + + tf->type =TF_TYPE_BYPASS ; + +/* 1D Curve - Regamma TF */ +if (colorop->type !=DRM_COLOROP_1D_CURVE ) +return -EINVAL ;
[Severity: Medium]
Does setting only tf->type = TF_TYPE_BYPASS leave a stale transfer function in dc_stream_state->out_transfer_func.tf when this colorop is bypassed? Other transfer function helpers use __set_tf_bypass(), which also resets tf->tf to TRANSFER_FUNCTION_LINEAR. Downstream DC paths such as set_avi_info_frame() and get_hdr_visual_confirm_color() check stream->out_transfer_func.tf without checking whether out_transfer_func.type is TF_TYPE_BYPASS, so a prior TRANSFER_FUNCTION_GAMMA22 or TRANSFER_FUNCTION_PQ value stays active for AVI InfoFrame colorimetry and HDR visual confirm even after regamma is bypassed.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c __set_dm_crtc_colorop_3x4_matrix(struct drm_crtc_state *crtc_state, · line 1315
Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +9
-0+ + colorop_state =drm_atomic_get_new_colorop_state (state, colorop); +if (!colorop_state) + colorop_state = colorop->state; + +if (!colorop_state->bypass) { +drm_dbg (dev,"Regamma TF colorop with ID: %d\n" , colorop->base.id); + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf = default_tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type);
[Severity: Low]dc_stream_state is unused in __set_dm_crtc_colorop_regamma(), and default_tf is assigned here without being read in this patch, which triggers -Wunused-but-set-variable under W=1 builds until commit "drm/amd/display: add support to post-blend 1D-LUT colorop" uses it.
Quoted 23 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +10
-0+ tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; + ret =__set_output_tf (tf,0 ,0 , false); +if (ret) +return ret; + } + +return 0 ; +} +/* * amdgpu_dm_crtc_set_colorop_properties: Set colorop props if programmable by DC. * @crtc_state: DRM crtc state @@ -1312,6 +1347,7 @@ amdgpu_dm_crtc_set_colorop_properties(struct drm_crtc_state *crtc_state, {struct drm_colorop *colorop = crtc_state->color_pipeline;struct drm_device *dev = crtc_state->crtc->dev; +struct dc_transfer_func *out_tf;int ret;if (drm_WARN_ON (dev, !colorop))@@ -1319,6 +1355,28 @@ amdgpu_dm_crtc_set_colorop_properties(struct drm_crtc_state *crtc_state,/* 3x4 matrix */
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c amdgpu_dm_crtc_set_colorop_properties(struct drm_crtc_state *crtc_state, · line 1366
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +9
-0ret =__set_dm_crtc_colorop_3x4_matrix (crtc_state, dc_stream_state, colorop, check_only); +if (ret) +return ret; + +/* 1D Curve - REGAMMA TF */ + colorop = colorop->next; +if (!colorop) { +drm_dbg (dev,"no regamma TF colorop found\n" ); +return -EINVAL ; + }
[Severity: Medium]
Should this check adev->dm.dc->caps.color.mpc.ogam_ram before requiring the regamma colorop? amdgpu_dm_initialize_crtc_default_pipeline() only appends the 1D curve colorop when mpc.ogam_ram is set, so when it is false the pipeline still registers with just the 3x4 CTM (ops[0]->next == NULL) and every atomic check or commit using that pipeline will fail here with -EINVAL.
[ ... ]
Quoted 19 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +4
-0@@ -311,6 +311,7 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, {struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS ];struct drm_device *dev = crtc->dev; +struct amdgpu_device *adev =drm_to_adev (dev);int ret;int i =0 ;@@ -332,6 +333,25 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, i++; +if (adev->dm.dc->caps.color.mpc.ogam_ram) { +/* 1D Curve - REGAMMA TF */ + ops[i] =kzalloc_obj (*ops[0 ]);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, · line 348
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +10
-0+if (!ops[i]) { + ret = -ENOMEM ; + goto cleanup; + } + + ret =drm_crtc_colorop_curve_1d_init (dev, ops[i], crtc, &dm_colorop_funcs, + amdgpu_dm_supported_shaper_tfs, +DRM_COLOROP_FLAG_ALLOW_BYPASS ); +if (ret) + goto cleanup;
[Severity: Medium]
Does jumping to cleanup leak ops[i] if drm_crtc_colorop_curve_1d_init() fails before linking it into dev->mode_config.colorop_list? drm_common_colorop_init() returns early if drm_mode_object_add() fails before list_add_tail(&colorop->head, &config->colorop_list), and drm_colorop_pipeline_destroy() only frees colorops already on colorop_list.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, · line 353
Quoted 9 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +6
-0+ +drm_colorop_set_next_property (ops[i-1 ], ops[i]); + + i++; + } + list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , ops[0 ]->base.id);return 0 ;
[Severity: Medium]
This problem wasn't introduced by this patch (it comes from commit "drm/amd/display: enable post-blend CTM colorop" earlier in the series), but what happens if kasprintf() returns NULL for list->name? Returning 0 skips drm_colorop_pipeline_destroy() and leaves a NULL name in pipelines[] when dm_crtc_init_colorops() calls drm_crtc_create_color_pipeline_property(), leading to a NULL pointer dereference in strlen(name) inside drm_property_add_enum().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
PATCH v3 19/19 drm/amd/display: add support to post-blend 1D-LUT colorop
In reply to Melissa WenAdd Regamma LUT operation as 1D LUT colorop to AMD post-blend color pipeline.
---
v3:
- use the committed state of the LUT colorop when it isn't part of the commit
- reject a colorop of unexpected type
- check for the LUT colorop and drop the redundant check from amdgpu_dm_crtc_set_colorop_properties()
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 35 +++++++++++++++++-- .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 18 ++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +33 -2
@@ -1297,6 +1297,8 @@ __set_dm_crtc_colorop_regamma(struct drm_crtc_state *crtc_state,struct drm_atomic_commit *state = crtc_state->state;enum dc_transfer_func_predefined default_tf =TRANSFER_FUNCTION_LINEAR ;struct drm_device *dev = crtc_state->state->dev; +const struct drm_color_lut32 *regamma_lut; +u32 regamma_size;int ret =0 ; tf->type =TF_TYPE_BYPASS ;
@@ -1319,6 +1321,36 @@ __set_dm_crtc_colorop_regamma(struct drm_crtc_state *crtc_state,return ret; } +/* 1D LUT - Regamma LUT */ + colorop = colorop->next; +if (!colorop || colorop->type !=DRM_COLOROP_1D_LUT ) { +drm_dbg (dev,"no Regamma LUT colorop found\n" ); +return -EINVAL ; + } + + colorop_state =drm_atomic_get_new_colorop_state (state, colorop); +if (!colorop_state) + colorop_state = colorop->state; + +if (!colorop_state->bypass) { +drm_dbg (dev,"Regamma LUT colorop with ID: %d\n" , colorop->base.id); + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf = default_tf; + tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; + regamma_lut =__extract_blob_lut32 (colorop_state->data, ®amma_size); + regamma_size = regamma_lut !=NULL ? regamma_size :0 ; + +/* Custom LUT size must be the same as supported size */ +if (regamma_size == colorop->size) { + ret =__set_output_tf_32 (tf, regamma_lut, regamma_size, false); +if (ret) +return ret; + }else { +drm_dbg (dev,"Regamma LUT size doesn't match blob size\n" ); +return -EINVAL ; + } + } +return 0 ; }
@@ -1358,7 +1390,7 @@ amdgpu_dm_crtc_set_colorop_properties(struct drm_crtc_state *crtc_state,if (ret)return ret; -/* 1D Curve - REGAMMA TF */ +/* 1D Curve & LUT - REGAMMA TF & LUT */ colorop = colorop->next;if (!colorop) {drm_dbg (dev,"no regamma TF colorop found\n" );
@@ -1401,7 +1433,6 @@ amdgpu_dm_crtc_set_colorop_properties(struct drm_crtc_state *crtc_state,* Returns: * 0 on success. Error code if validation fails. */ -int amdgpu_dm_check_crtc_color_mgmt (struct dm_crtc_state *crtc,bool check_only) {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +18 -0
@@ -346,6 +346,24 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc,drm_colorop_set_next_property (ops[i-1 ], ops[i]); i++; + +/* 1D LUT - REGAMMA LUT */ + ops[i] =kzalloc_obj (*ops[0 ]); +if (!ops[i]) { + ret = -ENOMEM ; + goto cleanup; + } + + ret =drm_crtc_colorop_curve_1d_lut_init (dev, ops[i], crtc, &dm_colorop_funcs, +MAX_COLOR_LUT_ENTRIES , +DRM_COLOROP_LUT1D_INTERPOLATION_LINEAR , +DRM_COLOROP_FLAG_ALLOW_BYPASS ); +if (ret) + goto cleanup; + +drm_colorop_set_next_property (ops[i-1 ], ops[i]); + + i++; } list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , ops[0 ]->base.id);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 19/19] drm/amd/display: add support to post-blend 1D-LUT colorop
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/amd/display: leak of ops[i] on init failure in amdgpu_dm_initialize_crtc_default_pipeline()…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/amd/display: leak of ops[i] on init failure in amdgpu_dm_initialize_crtc_default_pipeline()
- [Medium] drm/amd/display: unchecked kasprintf() in amdgpu_dm_initialize_crtc_default_pipeline()
--
commit a8178a6daf7c1cd1a2cd47ce46fa81a020bacd1b
Author: Melissa Wen <[email protected]>
drm/amd/display: add support to post-blend 1D-LUT colorop
This commit adds the Regamma 1D LUT colorop to the AMD CRTC post-blend color pipeline and wires up its state handling in __set_dm_crtc_colorop_regamma().
Quoted 12 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +4
-0@@ -350,6 +350,24 @@ int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc,drm_colorop_set_next_property (ops[i-1 ], ops[i]); i++; + +/* 1D LUT - REGAMMA LUT */ + ops[i] =kzalloc_obj (*ops[0 ]); +if (!ops[i]) {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, · line 366
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +10
-0+ ret = -ENOMEM ; + goto cleanup; + } + + ret =drm_crtc_colorop_curve_1d_lut_init (dev, ops[i], crtc, &dm_colorop_funcs, +MAX_COLOR_LUT_ENTRIES , +DRM_COLOROP_LUT1D_INTERPOLATION_LINEAR , +DRM_COLOROP_FLAG_ALLOW_BYPASS ); +if (ret) + goto cleanup;
[Severity: Medium]
Can jumping to cleanup here leak ops[i] ifdrm_crtc_colorop_curve_1d_lut_init() fails?
In drm_crtc_colorop_init() -> drm_common_colorop_init(), if drm_mode_object_add() fails, the function returns before linking ops[i] into config->colorop_list. Because cleanup only calls drm_colorop_pipeline_destroy(dev) to free colorops on config->colorop_list, ops[i] is leaked.
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c int amdgpu_dm_initialize_crtc_default_pipeline(struct drm_crtc *crtc, · line 369
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +4
-0+ +drm_colorop_set_next_property (ops[i-1 ], ops[i]); + + i++; } list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , ops[0 ]->base.id);
[Severity: Medium]
Should list->name be checked for NULL here, as inamdgpu_dm_build_default_pipeline()?
If kasprintf() fails, amdgpu_dm_initialize_crtc_default_pipeline() skips cleanup and returns 0 with list->name set to NULL. The caller dm_crtc_init_colorops() then passes the NULL pipeline name to drm_crtc_create_color_pipeline_property(), causing a NULL pointer dereference in strlen(name) inside drm_property_add_enum().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19