mirror of
https://github.com/torvalds/linux.git
synced 2026-01-25 07:47:50 +00:00
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: Simon Ser <contact@emersion.fr> Signed-off-by: Alex Hung <alex.hung@amd.com> Signed-off-by: Harry Wentland <harry.wentland@amd.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Melissa Wen <mwen@igalia.com> Reviewed-by: Sebastian Wick <sebastian.wick@redhat.com> Signed-off-by: Simon Ser <contact@emersion.fr> Link: https://patch.msgid.link/20251115000237.3561250-5-alex.hung@amd.com
This commit is contained in:
committed by
Simon Ser
parent
bcaefdaaeb
commit
cfc27680ee
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <drm/drm_crtc.h>
|
||||
#include <drm/drm_util.h>
|
||||
#include <drm/drm_colorop.h>
|
||||
|
||||
/**
|
||||
* struct drm_crtc_commit - track modeset commits on a CRTC
|
||||
@@ -157,6 +158,11 @@ struct drm_crtc_commit {
|
||||
bool abort_completion;
|
||||
};
|
||||
|
||||
struct __drm_colorops_state {
|
||||
struct drm_colorop *ptr;
|
||||
struct drm_colorop_state *state, *old_state, *new_state;
|
||||
};
|
||||
|
||||
struct __drm_planes_state {
|
||||
struct drm_plane *ptr;
|
||||
|
||||
@@ -531,6 +537,14 @@ struct drm_atomic_state {
|
||||
*/
|
||||
bool checked : 1;
|
||||
|
||||
/**
|
||||
* @colorops:
|
||||
*
|
||||
* Pointer to array of @drm_colorop and @drm_colorop_state part of this
|
||||
* update.
|
||||
*/
|
||||
struct __drm_colorops_state *colorops;
|
||||
|
||||
/**
|
||||
* @planes:
|
||||
*
|
||||
@@ -672,6 +686,9 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,
|
||||
struct drm_plane_state * __must_check
|
||||
drm_atomic_get_plane_state(struct drm_atomic_state *state,
|
||||
struct drm_plane *plane);
|
||||
struct drm_colorop_state *
|
||||
drm_atomic_get_colorop_state(struct drm_atomic_state *state,
|
||||
struct drm_colorop *colorop);
|
||||
struct drm_connector_state * __must_check
|
||||
drm_atomic_get_connector_state(struct drm_atomic_state *state,
|
||||
struct drm_connector *connector);
|
||||
@@ -768,6 +785,36 @@ drm_atomic_get_new_plane_state(const struct drm_atomic_state *state,
|
||||
return state->planes[drm_plane_index(plane)].new_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_atomic_get_old_colorop_state - get colorop state, if it exists
|
||||
* @state: global atomic state object
|
||||
* @colorop: colorop to grab
|
||||
*
|
||||
* This function returns the old colorop state for the given colorop, or
|
||||
* NULL if the colorop is not part of the global atomic state.
|
||||
*/
|
||||
static inline struct drm_colorop_state *
|
||||
drm_atomic_get_old_colorop_state(struct drm_atomic_state *state,
|
||||
struct drm_colorop *colorop)
|
||||
{
|
||||
return state->colorops[drm_colorop_index(colorop)].old_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_atomic_get_new_colorop_state - get colorop state, if it exists
|
||||
* @state: global atomic state object
|
||||
* @colorop: colorop to grab
|
||||
*
|
||||
* This function returns the new colorop state for the given colorop, or
|
||||
* NULL if the colorop is not part of the global atomic state.
|
||||
*/
|
||||
static inline struct drm_colorop_state *
|
||||
drm_atomic_get_new_colorop_state(struct drm_atomic_state *state,
|
||||
struct drm_colorop *colorop)
|
||||
{
|
||||
return state->colorops[drm_colorop_index(colorop)].new_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* drm_atomic_get_old_connector_state - get connector state, if it exists
|
||||
* @state: global atomic state object
|
||||
@@ -998,6 +1045,29 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
|
||||
(new_crtc_state) = (__state)->crtcs[__i].new_state, \
|
||||
(void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
|
||||
|
||||
/**
|
||||
* for_each_oldnew_colorop_in_state - iterate over all colorops in an atomic update
|
||||
* @__state: &struct drm_atomic_state pointer
|
||||
* @colorop: &struct drm_colorop iteration cursor
|
||||
* @old_colorop_state: &struct drm_colorop_state iteration cursor for the old state
|
||||
* @new_colorop_state: &struct drm_colorop_state iteration cursor for the new state
|
||||
* @__i: int iteration cursor, for macro-internal use
|
||||
*
|
||||
* This iterates over all colorops in an atomic update, tracking both old and
|
||||
* new state. This is useful in places where the state delta needs to be
|
||||
* considered, for example in atomic check functions.
|
||||
*/
|
||||
#define for_each_oldnew_colorop_in_state(__state, colorop, old_colorop_state, \
|
||||
new_colorop_state, __i) \
|
||||
for ((__i) = 0; \
|
||||
(__i) < (__state)->dev->mode_config.num_colorop; \
|
||||
(__i)++) \
|
||||
for_each_if ((__state)->colorops[__i].ptr && \
|
||||
((colorop) = (__state)->colorops[__i].ptr, \
|
||||
(void)(colorop) /* Only to avoid unused-but-set-variable warning */, \
|
||||
(old_colorop_state) = (__state)->colorops[__i].old_state,\
|
||||
(new_colorop_state) = (__state)->colorops[__i].new_state, 1))
|
||||
|
||||
/**
|
||||
* for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
|
||||
* @__state: &struct drm_atomic_state pointer
|
||||
|
||||
@@ -37,6 +37,7 @@ struct drm_crtc;
|
||||
struct drm_connector_state;
|
||||
struct dma_fence;
|
||||
struct drm_framebuffer;
|
||||
struct drm_colorop;
|
||||
|
||||
int __must_check
|
||||
drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
|
||||
|
||||
169
include/drm/drm_colorop.h
Normal file
169
include/drm/drm_colorop.h
Normal file
@@ -0,0 +1,169 @@
|
||||
/* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __DRM_COLOROP_H__
|
||||
#define __DRM_COLOROP_H__
|
||||
|
||||
#include <drm/drm_mode_object.h>
|
||||
#include <drm/drm_mode.h>
|
||||
#include <drm/drm_property.h>
|
||||
|
||||
/**
|
||||
* struct drm_colorop_state - mutable colorop state
|
||||
*/
|
||||
struct drm_colorop_state {
|
||||
/** @colorop: backpointer to the colorop */
|
||||
struct drm_colorop *colorop;
|
||||
|
||||
/*
|
||||
* Color properties
|
||||
*
|
||||
* The following fields are not always valid, their usage depends
|
||||
* on the colorop type. See their associated comment for more
|
||||
* information.
|
||||
*/
|
||||
|
||||
/** @state: backpointer to global drm_atomic_state */
|
||||
struct drm_atomic_state *state;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct drm_colorop - DRM color operation control structure
|
||||
*
|
||||
* A colorop represents one color operation. They can be chained via
|
||||
* the 'next' pointer to build a color pipeline.
|
||||
*
|
||||
* Since colorops cannot stand-alone and are used to describe colorop
|
||||
* operations on a plane they don't have their own locking mechanism but
|
||||
* are locked and programmed along with their associated &drm_plane.
|
||||
*
|
||||
*/
|
||||
struct drm_colorop {
|
||||
/** @dev: parent DRM device */
|
||||
struct drm_device *dev;
|
||||
|
||||
/**
|
||||
* @head:
|
||||
*
|
||||
* List of all colorops on @dev, linked from &drm_mode_config.colorop_list.
|
||||
* Invariant over the lifetime of @dev and therefore does not need
|
||||
* locking.
|
||||
*/
|
||||
struct list_head head;
|
||||
|
||||
/**
|
||||
* @index: Position inside the mode_config.list, can be used as an array
|
||||
* index. It is invariant over the lifetime of the colorop.
|
||||
*/
|
||||
unsigned int index;
|
||||
|
||||
/** @base: base mode object */
|
||||
struct drm_mode_object base;
|
||||
|
||||
/**
|
||||
* @plane:
|
||||
*
|
||||
* The plane on which the colorop sits. A drm_colorop is always unique
|
||||
* to a plane.
|
||||
*/
|
||||
struct drm_plane *plane;
|
||||
|
||||
/**
|
||||
* @state:
|
||||
*
|
||||
* Current atomic state for this colorop.
|
||||
*
|
||||
* This is protected by @mutex. Note that nonblocking atomic commits
|
||||
* access the current colorop state without taking locks.
|
||||
*/
|
||||
struct drm_colorop_state *state;
|
||||
|
||||
/*
|
||||
* Color properties
|
||||
*
|
||||
* The following fields are not always valid, their usage depends
|
||||
* on the colorop type. See their associated comment for more
|
||||
* information.
|
||||
*/
|
||||
|
||||
/** @properties: property tracking for this colorop */
|
||||
struct drm_object_properties properties;
|
||||
|
||||
};
|
||||
|
||||
#define obj_to_colorop(x) container_of(x, struct drm_colorop, base)
|
||||
|
||||
/**
|
||||
* drm_colorop_find - look up a Colorop object from its ID
|
||||
* @dev: DRM device
|
||||
* @file_priv: drm file to check for lease against.
|
||||
* @id: &drm_mode_object ID
|
||||
*
|
||||
* This can be used to look up a Colorop from its userspace ID. Only used by
|
||||
* drivers for legacy IOCTLs and interface, nowadays extensions to the KMS
|
||||
* userspace interface should be done using &drm_property.
|
||||
*/
|
||||
static inline struct drm_colorop *drm_colorop_find(struct drm_device *dev,
|
||||
struct drm_file *file_priv,
|
||||
uint32_t id)
|
||||
{
|
||||
struct drm_mode_object *mo;
|
||||
|
||||
mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_COLOROP);
|
||||
return mo ? obj_to_colorop(mo) : NULL;
|
||||
}
|
||||
|
||||
struct drm_colorop_state *
|
||||
drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colorop);
|
||||
|
||||
void drm_colorop_atomic_destroy_state(struct drm_colorop *colorop,
|
||||
struct drm_colorop_state *state);
|
||||
|
||||
/**
|
||||
* drm_colorop_reset - reset colorop atomic state
|
||||
* @colorop: drm colorop
|
||||
*
|
||||
* Resets the atomic state for @colorop by freeing the state pointer (which might
|
||||
* be NULL, e.g. at driver load time) and allocating a new empty state object.
|
||||
*/
|
||||
void drm_colorop_reset(struct drm_colorop *colorop);
|
||||
|
||||
/**
|
||||
* drm_colorop_index - find the index of a registered colorop
|
||||
* @colorop: colorop to find index for
|
||||
*
|
||||
* Given a registered colorop, return the index of that colorop within a DRM
|
||||
* device's list of colorops.
|
||||
*/
|
||||
static inline unsigned int drm_colorop_index(const struct drm_colorop *colorop)
|
||||
{
|
||||
return colorop->index;
|
||||
}
|
||||
|
||||
#define drm_for_each_colorop(colorop, dev) \
|
||||
list_for_each_entry(colorop, &(dev)->mode_config.colorop_list, head)
|
||||
|
||||
#endif /* __DRM_COLOROP_H__ */
|
||||
@@ -500,6 +500,24 @@ struct drm_mode_config {
|
||||
*/
|
||||
struct raw_spinlock panic_lock;
|
||||
|
||||
/**
|
||||
* @num_colorop:
|
||||
*
|
||||
* Number of colorop objects on this device.
|
||||
* This is invariant over the lifetime of a device and hence doesn't
|
||||
* need any locks.
|
||||
*/
|
||||
int num_colorop;
|
||||
|
||||
/**
|
||||
* @colorop_list:
|
||||
*
|
||||
* List of colorop objects linked with &drm_colorop.head. This is
|
||||
* invariant over the lifetime of a device and hence doesn't need any
|
||||
* locks.
|
||||
*/
|
||||
struct list_head colorop_list;
|
||||
|
||||
/**
|
||||
* @num_crtc:
|
||||
*
|
||||
|
||||
@@ -243,6 +243,14 @@ struct drm_plane_state {
|
||||
*/
|
||||
enum drm_scaling_filter scaling_filter;
|
||||
|
||||
/**
|
||||
* @color_pipeline:
|
||||
*
|
||||
* The first colorop of the active color pipeline, or NULL, if no
|
||||
* color pipeline is active.
|
||||
*/
|
||||
struct drm_colorop *color_pipeline;
|
||||
|
||||
/**
|
||||
* @commit: Tracks the pending commit to prevent use-after-free conditions,
|
||||
* and for async plane updates.
|
||||
|
||||
Reference in New Issue
Block a user