Commit 60160310 authored by Melissa Wen's avatar Melissa Wen Committed by Alex Deucher

drm/drm_property: make replace_property_blob_from_id a DRM helper

Place it in drm_property where drm_property_replace_blob and
drm_property_lookup_blob live. Then we can use the DRM helper for
driver-specific KMS properties too.
Reviewed-by: default avatarHarry Wentland <harry.wentland@amd.com>
Reviewed-by: default avatarLiviu Dudau <liviu.dudau@arm.com>
Signed-off-by: default avatarMelissa Wen <mwen@igalia.com>
Acked-by: default avatarMaxime Ripard <mripard@kernel.org>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 1e13c564
...@@ -221,7 +221,7 @@ static int malidp_crtc_atomic_check_ctm(struct drm_crtc *crtc, ...@@ -221,7 +221,7 @@ static int malidp_crtc_atomic_check_ctm(struct drm_crtc *crtc,
/* /*
* The size of the ctm is checked in * The size of the ctm is checked in
* drm_atomic_replace_property_blob_from_id. * drm_property_replace_blob_from_id.
*/ */
ctm = (struct drm_color_ctm *)state->ctm->data; ctm = (struct drm_color_ctm *)state->ctm->data;
for (i = 0; i < ARRAY_SIZE(ctm->matrix); ++i) { for (i = 0; i < ARRAY_SIZE(ctm->matrix); ++i) {
......
...@@ -362,48 +362,6 @@ static s32 __user *get_out_fence_for_connector(struct drm_atomic_state *state, ...@@ -362,48 +362,6 @@ static s32 __user *get_out_fence_for_connector(struct drm_atomic_state *state,
return fence_ptr; return fence_ptr;
} }
static int
drm_atomic_replace_property_blob_from_id(struct drm_device *dev,
struct drm_property_blob **blob,
uint64_t blob_id,
ssize_t expected_size,
ssize_t expected_elem_size,
bool *replaced)
{
struct drm_property_blob *new_blob = NULL;
if (blob_id != 0) {
new_blob = drm_property_lookup_blob(dev, blob_id);
if (new_blob == NULL) {
drm_dbg_atomic(dev,
"cannot find blob ID %llu\n", blob_id);
return -EINVAL;
}
if (expected_size > 0 &&
new_blob->length != expected_size) {
drm_dbg_atomic(dev,
"[BLOB:%d] length %zu different from expected %zu\n",
new_blob->base.id, new_blob->length, expected_size);
drm_property_blob_put(new_blob);
return -EINVAL;
}
if (expected_elem_size > 0 &&
new_blob->length % expected_elem_size != 0) {
drm_dbg_atomic(dev,
"[BLOB:%d] length %zu not divisible by element size %zu\n",
new_blob->base.id, new_blob->length, expected_elem_size);
drm_property_blob_put(new_blob);
return -EINVAL;
}
}
*replaced |= drm_property_replace_blob(blob, new_blob);
drm_property_blob_put(new_blob);
return 0;
}
static int drm_atomic_crtc_set_property(struct drm_crtc *crtc, static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
struct drm_crtc_state *state, struct drm_property *property, struct drm_crtc_state *state, struct drm_property *property,
uint64_t val) uint64_t val)
...@@ -424,7 +382,7 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc, ...@@ -424,7 +382,7 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
} else if (property == config->prop_vrr_enabled) { } else if (property == config->prop_vrr_enabled) {
state->vrr_enabled = val; state->vrr_enabled = val;
} else if (property == config->degamma_lut_property) { } else if (property == config->degamma_lut_property) {
ret = drm_atomic_replace_property_blob_from_id(dev, ret = drm_property_replace_blob_from_id(dev,
&state->degamma_lut, &state->degamma_lut,
val, val,
-1, sizeof(struct drm_color_lut), -1, sizeof(struct drm_color_lut),
...@@ -432,7 +390,7 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc, ...@@ -432,7 +390,7 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
state->color_mgmt_changed |= replaced; state->color_mgmt_changed |= replaced;
return ret; return ret;
} else if (property == config->ctm_property) { } else if (property == config->ctm_property) {
ret = drm_atomic_replace_property_blob_from_id(dev, ret = drm_property_replace_blob_from_id(dev,
&state->ctm, &state->ctm,
val, val,
sizeof(struct drm_color_ctm), -1, sizeof(struct drm_color_ctm), -1,
...@@ -440,7 +398,7 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc, ...@@ -440,7 +398,7 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
state->color_mgmt_changed |= replaced; state->color_mgmt_changed |= replaced;
return ret; return ret;
} else if (property == config->gamma_lut_property) { } else if (property == config->gamma_lut_property) {
ret = drm_atomic_replace_property_blob_from_id(dev, ret = drm_property_replace_blob_from_id(dev,
&state->gamma_lut, &state->gamma_lut,
val, val,
-1, sizeof(struct drm_color_lut), -1, sizeof(struct drm_color_lut),
...@@ -581,7 +539,7 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane, ...@@ -581,7 +539,7 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane,
} else if (property == plane->color_range_property) { } else if (property == plane->color_range_property) {
state->color_range = val; state->color_range = val;
} else if (property == config->prop_fb_damage_clips) { } else if (property == config->prop_fb_damage_clips) {
ret = drm_atomic_replace_property_blob_from_id(dev, ret = drm_property_replace_blob_from_id(dev,
&state->fb_damage_clips, &state->fb_damage_clips,
val, val,
-1, -1,
...@@ -778,7 +736,7 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector, ...@@ -778,7 +736,7 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector,
if (state->link_status != DRM_LINK_STATUS_GOOD) if (state->link_status != DRM_LINK_STATUS_GOOD)
state->link_status = val; state->link_status = val;
} else if (property == config->hdr_output_metadata_property) { } else if (property == config->hdr_output_metadata_property) {
ret = drm_atomic_replace_property_blob_from_id(dev, ret = drm_property_replace_blob_from_id(dev,
&state->hdr_output_metadata, &state->hdr_output_metadata,
val, val,
sizeof(struct hdr_output_metadata), -1, sizeof(struct hdr_output_metadata), -1,
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <drm/drm_drv.h> #include <drm/drm_drv.h>
#include <drm/drm_file.h> #include <drm/drm_file.h>
#include <drm/drm_framebuffer.h> #include <drm/drm_framebuffer.h>
#include <drm/drm_print.h>
#include <drm/drm_property.h> #include <drm/drm_property.h>
#include "drm_crtc_internal.h" #include "drm_crtc_internal.h"
...@@ -751,6 +752,64 @@ bool drm_property_replace_blob(struct drm_property_blob **blob, ...@@ -751,6 +752,64 @@ bool drm_property_replace_blob(struct drm_property_blob **blob,
} }
EXPORT_SYMBOL(drm_property_replace_blob); EXPORT_SYMBOL(drm_property_replace_blob);
/**
* drm_property_replace_blob_from_id - replace a blob property taking a reference
* @dev: DRM device
* @blob: a pointer to the member blob to be replaced
* @blob_id: the id of the new blob to replace with
* @expected_size: expected size of the blob property
* @expected_elem_size: expected size of an element in the blob property
* @replaced: if the blob was in fact replaced
*
* Look up the new blob from id, take its reference, check expected sizes of
* the blob and its element and replace the old blob by the new one. Advertise
* if the replacement operation was successful.
*
* Return: true if the blob was in fact replaced. -EINVAL if the new blob was
* not found or sizes don't match.
*/
int drm_property_replace_blob_from_id(struct drm_device *dev,
struct drm_property_blob **blob,
uint64_t blob_id,
ssize_t expected_size,
ssize_t expected_elem_size,
bool *replaced)
{
struct drm_property_blob *new_blob = NULL;
if (blob_id != 0) {
new_blob = drm_property_lookup_blob(dev, blob_id);
if (new_blob == NULL) {
drm_dbg_atomic(dev,
"cannot find blob ID %llu\n", blob_id);
return -EINVAL;
}
if (expected_size > 0 &&
new_blob->length != expected_size) {
drm_dbg_atomic(dev,
"[BLOB:%d] length %zu different from expected %zu\n",
new_blob->base.id, new_blob->length, expected_size);
drm_property_blob_put(new_blob);
return -EINVAL;
}
if (expected_elem_size > 0 &&
new_blob->length % expected_elem_size != 0) {
drm_dbg_atomic(dev,
"[BLOB:%d] length %zu not divisible by element size %zu\n",
new_blob->base.id, new_blob->length, expected_elem_size);
drm_property_blob_put(new_blob);
return -EINVAL;
}
}
*replaced |= drm_property_replace_blob(blob, new_blob);
drm_property_blob_put(new_blob);
return 0;
}
EXPORT_SYMBOL(drm_property_replace_blob_from_id);
int drm_mode_getblob_ioctl(struct drm_device *dev, int drm_mode_getblob_ioctl(struct drm_device *dev,
void *data, struct drm_file *file_priv) void *data, struct drm_file *file_priv)
{ {
......
...@@ -279,6 +279,12 @@ struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, ...@@ -279,6 +279,12 @@ struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
const void *data); const void *data);
struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
uint32_t id); uint32_t id);
int drm_property_replace_blob_from_id(struct drm_device *dev,
struct drm_property_blob **blob,
uint64_t blob_id,
ssize_t expected_size,
ssize_t expected_elem_size,
bool *replaced);
int drm_property_replace_global_blob(struct drm_device *dev, int drm_property_replace_global_blob(struct drm_device *dev,
struct drm_property_blob **replace, struct drm_property_blob **replace,
size_t length, size_t length,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment