[PATCH v2 1/3] drm: Introduce CRTC checksum region and CRC properties
Alan Liu
HaoPing.Liu at amd.com
Sun Jun 18 10:38:45 UTC 2023
Introduce per-CRTC properties: CHECKSUM_REGION and CHECKSUM_CRC.
Userspace can configure a region by setting the region property and
retrieve the CRC values from the CRC property to validate the content
of the region.
Apon userspace submits the 4 coordinate values with checksum_region_enable true,
kernel instructs DC hardware to calculate the CRC value accordingly as frames
scanned out. The result CRC value of RGB colors are then stored in CHECKSUM_CRC
property, with a reference frame count for userspace to know which frame the
CRCs are calculated at.
Driver can set up these properties for a CRTC by calling
drm_crtc_create_checksum_region_properties() and hook its own
implementation on new CRTC function update_chechsum_region_crc() to update
the values of the CRC property for the incoming userspace request.
Signed-off-by: Alan Liu <HaoPing.Liu at amd.com>
---
drivers/gpu/drm/drm_atomic_state_helper.c | 7 ++++
drivers/gpu/drm/drm_atomic_uapi.c | 21 ++++++++++-
drivers/gpu/drm/drm_crtc.c | 44 +++++++++++++++++++++++
include/drm/drm_crtc.h | 43 ++++++++++++++++++++++
include/uapi/drm/drm_mode.h | 42 ++++++++++++++++++++++
5 files changed, 156 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c
index dfb57217253b..a8f25575edef 100644
--- a/drivers/gpu/drm/drm_atomic_state_helper.c
+++ b/drivers/gpu/drm/drm_atomic_state_helper.c
@@ -143,6 +143,11 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
drm_property_blob_get(state->ctm);
if (state->gamma_lut)
drm_property_blob_get(state->gamma_lut);
+ if (state->checksum_region.region_blob)
+ drm_property_blob_get(state->checksum_region.region_blob);
+ if (state->checksum_region.crc_blob)
+ drm_property_blob_get(state->checksum_region.crc_blob);
+
state->mode_changed = false;
state->active_changed = false;
state->planes_changed = false;
@@ -215,6 +220,8 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
drm_property_blob_put(state->degamma_lut);
drm_property_blob_put(state->ctm);
drm_property_blob_put(state->gamma_lut);
+ drm_property_blob_put(state->checksum_region.region_blob);
+ drm_property_blob_put(state->checksum_region.crc_blob);
}
EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c
index c06d0639d552..5a934f191940 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -450,6 +450,17 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
set_out_fence_for_crtc(state->state, crtc, fence_ptr);
} else if (property == crtc->scaling_filter_property) {
state->scaling_filter = val;
+ } else if (property == crtc->checksum_region_property) {
+ ret = drm_atomic_replace_property_blob_from_id(dev,
+ &state->checksum_region.region_blob,
+ val,
+ -1, sizeof(struct drm_checksum_region),
+ &replaced);
+ state->checksum_region.region_changed |= replaced;
+ return ret;
+ } else if (property == crtc->checksum_crc_property) {
+ /* don't let user set CRC data */
+ return -EPERM;
} else if (crtc->funcs->atomic_set_property) {
return crtc->funcs->atomic_set_property(crtc, state, property, val);
} else {
@@ -487,7 +498,15 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
*val = 0;
else if (property == crtc->scaling_filter_property)
*val = state->scaling_filter;
- else if (crtc->funcs->atomic_get_property)
+ else if (property == crtc->checksum_region_property)
+ *val = (state->checksum_region.region_blob)
+ ? state->checksum_region.region_blob->base.id : 0;
+ else if (property == crtc->checksum_crc_property) {
+ if (crtc->funcs->update_checksum_region_crc)
+ crtc->funcs->update_checksum_region_crc(crtc);
+ *val = (state->checksum_region.crc_blob)
+ ? state->checksum_region.crc_blob->base.id : 0;
+ } else if (crtc->funcs->atomic_get_property)
return crtc->funcs->atomic_get_property(crtc, state, property, val);
else
return -EINVAL;
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index df9bf3c9206e..07186cb8bfd4 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -955,3 +955,47 @@ int drm_crtc_create_scaling_filter_property(struct drm_crtc *crtc,
return 0;
}
EXPORT_SYMBOL(drm_crtc_create_scaling_filter_property);
+
+/**
+ * drm_crtc_create_checksum_region_properties - create new checksum_region
+ * properties
+ *
+ * @crtc: drm CRTC
+ *
+ * This function creates and attaches CHECKSUM_REGION and CHECKSUM_CRC blob
+ * properties for the given CRTC.
+ *
+ * RETURNS:
+ * Zero for success or -ENOMEM
+ */
+int drm_crtc_create_checksum_region_properties(struct drm_crtc *crtc)
+{
+ struct drm_device *dev = crtc->dev;
+ struct drm_property *region_prop, *crc_prop;
+
+ region_prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
+ "CHECKSUM_REGION", 0);
+ crc_prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
+ "CHECKSUM_CRC", 0);
+
+ if (!region_prop || !crc_prop)
+ goto fail;
+
+ drm_object_attach_property(&crtc->base, region_prop, 0);
+ drm_object_attach_property(&crtc->base, crc_prop, 0);
+
+ crtc->checksum_region_property = region_prop;
+ crtc->checksum_crc_property = crc_prop;
+
+ return 0;
+
+fail:
+ if (region_prop)
+ drm_property_destroy(dev, region_prop);
+
+ if (crc_prop)
+ drm_property_destroy(dev, crc_prop);
+
+ return -ENOMEM;
+}
+EXPORT_SYMBOL(drm_crtc_create_checksum_region_properties);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 8e1cbc75143e..e588c321eb7a 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -322,6 +322,21 @@ struct drm_crtc_state {
*/
enum drm_scaling_filter scaling_filter;
+ /**
+ * @checksum_region:
+ *
+ * Checksum_region properties for configuring the region and retrieving the
+ * CRC checksum values of the region content. The region_changed is set when
+ * a new region is set by the userspace. If not NULL, the region_blob is of
+ * type struct drm_checksum_region and the crc_blob is of type struct
+ * drm_checksum_crc.
+ */
+ struct {
+ struct drm_property_blob *region_blob;
+ struct drm_property_blob *crc_blob;
+ bool region_changed: 1;
+ } checksum_region;
+
/**
* @event:
*
@@ -926,6 +941,22 @@ struct drm_crtc_funcs {
int *max_error,
ktime_t *vblank_time,
bool in_vblank_irq);
+
+ /**
+ * @update_checksum_region_crc:
+ *
+ * Driver callback to update the content of CRTC CHECKSUM_CRC property.
+ * This function fetches the latest checksum CRC values and replaces the
+ * old crc_blob in struct drm_crtc_state.
+ *
+ * This callback is optional if the driver does not support any CRC
+ * generation functionality.
+ *
+ * RETURNS:
+ *
+ * True on success, false on failure.
+ */
+ bool (*update_checksum_region_crc) (struct drm_crtc *crtc);
};
/**
@@ -1180,6 +1211,17 @@ struct drm_crtc {
* Initialized via drm_self_refresh_helper_init().
*/
struct drm_self_refresh_data *self_refresh_data;
+
+ /**
+ * @checksum_region_property: property for checksum region configuration.
+ */
+ struct drm_property *checksum_region_property;
+
+ /**
+ * @checksum_crc_property: property for retrieving the CRC checksum
+ * values of the content of checksum region.
+ */
+ struct drm_property *checksum_crc_property;
};
/**
@@ -1329,4 +1371,5 @@ 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_checksum_region_properties(struct drm_crtc *crtc);
#endif /* __DRM_CRTC_H__ */
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index 46becedf5b2f..a2b7d2be94d3 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -1303,6 +1303,48 @@ struct drm_mode_rect {
__s32 y2;
};
+/**
+ * struct drm_checksum_region - The enablement and region of checksum_region
+ * @x_start: Horizontal starting coordinate of the region.
+ * @y_start: Vertical starting coordinate of the region.
+ * @x_end: Horizontal ending coordinate of the region.
+ * @y_end: Vertical ending coordinate of the region.
+ * @checksum_region_enable: To enable or disable checksum_region.
+ *
+ * Userspace uses this structure to configure the region and enablement for
+ * checksum_region. Userspace should not submit a region out of the displayable
+ * region because there is nothing to display and need protection.
+ */
+struct drm_checksum_region {
+ __u32 x_start;
+ __u32 y_start;
+ __u32 x_end;
+ __u32 y_end;
+ __u8 checksum_region_enable;
+ __u8 pad[7];
+};
+
+/**
+ * struct drm_checksum_crc - The CRC value of the corresponding checksum region.
+ * @crc_r: CRC value of red color.
+ * @crc_g: CRC value of green color.
+ * @crc_b: CRC value of blue color.
+ * @frame_count: a referenced frame count to indicate which frame the CRC values
+ * are generated at.
+ *
+ * Userspace uses this structure to retrieve the CRC values of the current
+ * checksum region. @frame_count will be reset once a new region is updated or
+ * it reaches a maximum value. Currently these CRC values are designed to
+ * be validated with pre-saved CRC values, so userspace doesn't need to concern
+ * about the algorithm used to compute the CRC.
+ */
+struct drm_checksum_crc {
+ __u32 crc_r;
+ __u32 crc_g;
+ __u32 crc_b;
+ __u32 frame_count;
+};
+
#if defined(__cplusplus)
}
#endif
--
2.34.1
More information about the dri-devel
mailing list