Commit cfc27680 authored by Harry Wentland's avatar Harry Wentland Committed by Simon Ser
Browse files

drm/colorop: Introduce new drm_colorop mode object



This patches introduces a new drm_colorop mode object. This
object represents color transformations and can be used to
define color pipelines.

We also introduce the drm_colorop_state here, as well as
various helpers and state tracking bits.

Reviewed-by: default avatarSimon Ser <contact@emersion.fr>
Signed-off-by: default avatarAlex Hung <alex.hung@amd.com>
Signed-off-by: default avatarHarry Wentland <harry.wentland@amd.com>
Reviewed-by: default avatarDaniel Stone <daniels@collabora.com>
Reviewed-by: default avatarMelissa Wen <mwen@igalia.com>
Reviewed-by: default avatarSebastian Wick <sebastian.wick@redhat.com>
Signed-off-by: default avatarSimon Ser <contact@emersion.fr>
Link: https://patch.msgid.link/20251115000237.3561250-5-alex.hung@amd.com
parent bcaefdaa
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ drm-y := \
	drm_bridge.o \
	drm_cache.o \
	drm_color_mgmt.o \
	drm_colorop.o \
	drm_connector.o \
	drm_crtc.o \
	drm_displayid.o \
+69 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include <drm/drm_mode.h>
#include <drm/drm_print.h>
#include <drm/drm_writeback.h>
#include <drm/drm_colorop.h>

#include "drm_crtc_internal.h"
#include "drm_internal.h"
@@ -107,6 +108,7 @@ void drm_atomic_state_default_release(struct drm_atomic_state *state)
	kfree(state->connectors);
	kfree(state->crtcs);
	kfree(state->planes);
	kfree(state->colorops);
	kfree(state->private_objs);
}
EXPORT_SYMBOL(drm_atomic_state_default_release);
@@ -138,6 +140,10 @@ drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
				sizeof(*state->planes), GFP_KERNEL);
	if (!state->planes)
		goto fail;
	state->colorops = kcalloc(dev->mode_config.num_colorop,
				  sizeof(*state->colorops), GFP_KERNEL);
	if (!state->colorops)
		goto fail;

	/*
	 * Because drm_atomic_state can be committed asynchronously we need our
@@ -251,6 +257,20 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state)
		state->planes[i].new_state = NULL;
	}

	for (i = 0; i < config->num_colorop; i++) {
		struct drm_colorop *colorop = state->colorops[i].ptr;

		if (!colorop)
			continue;

		drm_colorop_atomic_destroy_state(colorop,
						 state->colorops[i].state);
		state->colorops[i].ptr = NULL;
		state->colorops[i].state = NULL;
		state->colorops[i].old_state = NULL;
		state->colorops[i].new_state = NULL;
	}

	for (i = 0; i < state->num_private_objs; i++) {
		struct drm_private_obj *obj = state->private_objs[i].ptr;

@@ -572,6 +592,55 @@ drm_atomic_get_plane_state(struct drm_atomic_state *state,
}
EXPORT_SYMBOL(drm_atomic_get_plane_state);

/**
 * drm_atomic_get_colorop_state - get colorop state
 * @state: global atomic state object
 * @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.
 *
 * Returns:
 *
 * Either the allocated state or the error code encoded into the pointer. When
 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
 * entire atomic sequence must be restarted. All other errors are fatal.
 */
struct drm_colorop_state *
drm_atomic_get_colorop_state(struct drm_atomic_state *state,
			     struct drm_colorop *colorop)
{
	int ret, index = drm_colorop_index(colorop);
	struct drm_colorop_state *colorop_state;

	WARN_ON(!state->acquire_ctx);

	colorop_state = drm_atomic_get_new_colorop_state(state, colorop);
	if (colorop_state)
		return colorop_state;

	ret = drm_modeset_lock(&colorop->plane->mutex, state->acquire_ctx);
	if (ret)
		return ERR_PTR(ret);

	colorop_state = drm_atomic_helper_colorop_duplicate_state(colorop);
	if (!colorop_state)
		return ERR_PTR(-ENOMEM);

	state->colorops[index].state = colorop_state;
	state->colorops[index].ptr = colorop;
	state->colorops[index].old_state = colorop->state;
	state->colorops[index].new_state = colorop_state;
	colorop_state->state = state;

	drm_dbg_atomic(colorop->dev, "Added [COLOROP:%d] %p state to %p\n",
		       colorop->base.id, colorop_state, state);

	return colorop_state;
}
EXPORT_SYMBOL(drm_atomic_get_colorop_state);

static bool
plane_switching_crtc(const struct drm_plane_state *old_plane_state,
		     const struct drm_plane_state *new_plane_state)
+12 −0
Original line number Diff line number Diff line
@@ -3184,6 +3184,8 @@ int drm_atomic_helper_swap_state(struct drm_atomic_state *state,
	struct drm_crtc_state *old_crtc_state, *new_crtc_state;
	struct drm_plane *plane;
	struct drm_plane_state *old_plane_state, *new_plane_state;
	struct drm_colorop *colorop;
	struct drm_colorop_state *old_colorop_state, *new_colorop_state;
	struct drm_crtc_commit *commit;
	struct drm_private_obj *obj;
	struct drm_private_state *old_obj_state, *new_obj_state;
@@ -3261,6 +3263,16 @@ int drm_atomic_helper_swap_state(struct drm_atomic_state *state,
		}
	}

	for_each_oldnew_colorop_in_state(state, colorop, old_colorop_state, new_colorop_state, i) {
		WARN_ON(colorop->state != old_colorop_state);

		old_colorop_state->state = state;
		new_colorop_state->state = NULL;

		state->colorops[i].state = old_colorop_state;
		colorop->state = new_colorop_state;
	}

	drm_panic_lock(state->dev, flags);
	for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
		WARN_ON(plane->state != old_plane_state);
+45 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <drm/drm_drv.h>
#include <drm/drm_writeback.h>
#include <drm/drm_vblank.h>
#include <drm/drm_colorop.h>

#include <linux/export.h>
#include <linux/dma-fence.h>
@@ -648,6 +649,26 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
	return 0;
}

static int drm_atomic_colorop_set_property(struct drm_colorop *colorop,
					   struct drm_colorop_state *state,
					   struct drm_file *file_priv,
					   struct drm_property *property,
					   uint64_t val)
{
	drm_dbg_atomic(colorop->dev,
		       "[COLOROP:%d] unknown property [PROP:%d:%s]]\n",
		       colorop->base.id, property->base.id, property->name);
	return -EINVAL;
}

static int
drm_atomic_colorop_get_property(struct drm_colorop *colorop,
				const struct drm_colorop_state *state,
				struct drm_property *property, uint64_t *val)
{
	return -EINVAL;
}

static int drm_atomic_set_writeback_fb_for_connector(
		struct drm_connector_state *conn_state,
		struct drm_framebuffer *fb)
@@ -914,6 +935,15 @@ int drm_atomic_get_property(struct drm_mode_object *obj,
				plane->state, property, val);
		break;
	}
	case DRM_MODE_OBJECT_COLOROP: {
		struct drm_colorop *colorop = obj_to_colorop(obj);

		if (colorop->plane)
			WARN_ON(!drm_modeset_is_locked(&colorop->plane->mutex));

		ret = drm_atomic_colorop_get_property(colorop, colorop->state, property, val);
		break;
	}
	default:
		drm_dbg_atomic(dev, "[OBJECT:%d] has no properties\n", obj->id);
		ret = -EINVAL;
@@ -1111,6 +1141,21 @@ int drm_atomic_set_property(struct drm_atomic_state *state,
		ret = drm_atomic_plane_set_property(plane,
				plane_state, file_priv,
				prop, prop_value);

		break;
	}
	case DRM_MODE_OBJECT_COLOROP: {
		struct drm_colorop *colorop = obj_to_colorop(obj);
		struct drm_colorop_state *colorop_state;

		colorop_state = drm_atomic_get_colorop_state(state, colorop);
		if (IS_ERR(colorop_state)) {
			ret = PTR_ERR(colorop_state);
			break;
		}

		ret = drm_atomic_colorop_set_property(colorop, colorop_state,
						      file_priv, prop, prop_value);
		break;
	}
	default:
+103 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: MIT
/*
 * Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: AMD
 *
 */

#include <drm/drm_colorop.h>
#include <drm/drm_print.h>
#include <drm/drm_drv.h>
#include <drm/drm_plane.h>

#include "drm_crtc_internal.h"

static void __drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colorop,
							struct drm_colorop_state *state)
{
	memcpy(state, colorop->state, sizeof(*state));
}

struct drm_colorop_state *
drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colorop)
{
	struct drm_colorop_state *state;

	if (WARN_ON(!colorop->state))
		return NULL;

	state = kmalloc(sizeof(*state), GFP_KERNEL);
	if (state)
		__drm_atomic_helper_colorop_duplicate_state(colorop, state);

	return state;
}

void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
				      struct drm_colorop_state *state)
{
	kfree(state);
}

/**
 * __drm_colorop_state_reset - resets colorop state to default values
 * @colorop_state: atomic colorop state, must not be NULL
 * @colorop: colorop object, must not be NULL
 *
 * Initializes the newly allocated @colorop_state with default
 * values. This is useful for drivers that subclass the CRTC state.
 */
static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state,
				      struct drm_colorop *colorop)
{
	colorop_state->colorop = colorop;
}

/**
 * __drm_colorop_reset - reset state on colorop
 * @colorop: drm colorop
 * @colorop_state: colorop state to assign
 *
 * Initializes the newly allocated @colorop_state and assigns it to
 * the &drm_crtc->state pointer of @colorop, usually required when
 * initializing the drivers or when called from the &drm_colorop_funcs.reset
 * hook.
 *
 * This is useful for drivers that subclass the colorop state.
 */
static void __drm_colorop_reset(struct drm_colorop *colorop,
				struct drm_colorop_state *colorop_state)
{
	if (colorop_state)
		__drm_colorop_state_reset(colorop_state, colorop);

	colorop->state = colorop_state;
}

void drm_colorop_reset(struct drm_colorop *colorop)
{
	kfree(colorop->state);
	colorop->state = kzalloc(sizeof(*colorop->state), GFP_KERNEL);

	if (colorop->state)
		__drm_colorop_reset(colorop, colorop->state);
}
Loading