@@ -49,9 +49,10 @@
* - 1.9.0 - Add MSM_SUBMIT_FENCE_SN_IN
* - 1.10.0 - Add MSM_SUBMIT_BO_NO_IMPLICIT
* - 1.11.0 - Add wait boost (MSM_WAIT_FENCE_BOOST, MSM_PREP_BOOST)
+ * - 1.12.0 - Add MSM_INFO_SET_METADATA and MSM_INFO_GET_METADATA
*/
#define MSM_VERSION_MAJOR 1
-#define MSM_VERSION_MINOR 11
+#define MSM_VERSION_MINOR 12
#define MSM_VERSION_PATCHLEVEL 0
static void msm_deinit_vram(struct drm_device *ddev);
@@ -844,6 +845,8 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
break;
case MSM_INFO_SET_NAME:
case MSM_INFO_GET_NAME:
+ case MSM_INFO_SET_METADATA:
+ case MSM_INFO_GET_METADATA:
break;
default:
return -EINVAL;
@@ -905,6 +908,58 @@ static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
msm_obj->name, args->len))
ret = -EFAULT;
}
+ break;
+ case MSM_INFO_SET_METADATA:
+ /* Impose a moderate upper bound on metadata size: */
+ if (args->len > 128) {
+ ret = -EOVERFLOW;
+ break;
+ }
+
+ ret = msm_gem_lock_interruptible(obj);
+ if (ret)
+ break;
+
+ msm_obj->metadata =
+ krealloc(msm_obj->metadata, args->len, GFP_KERNEL);
+ msm_obj->metadata_size = args->len;
+
+ if (copy_from_user(msm_obj->metadata, u64_to_user_ptr(args->value),
+ args->len)) {
+ msm_obj->metadata_size = 0;
+ ret = -EFAULT;
+ }
+
+ msm_gem_unlock(obj);
+
+ break;
+ case MSM_INFO_GET_METADATA:
+ if (!args->value) {
+ /*
+ * Querying the size is inherently racey, but
+ * EXT_external_objects expects the app to confirm
+ * via device and driver UUIDs that the exporter and
+ * importer versions match. All we can do from the
+ * kernel side is check the length under obj lock
+ * when userspace tries to retrieve the metadata
+ */
+ args->len = msm_obj->metadata_size;
+ break;
+ }
+
+ ret = msm_gem_lock_interruptible(obj);
+ if (ret)
+ break;
+
+ if (args->len < msm_obj->metadata_size) {
+ ret = -ETOOSMALL;
+ } else if (copy_to_user(u64_to_user_ptr(args->value),
+ msm_obj->metadata, args->len)) {
+ ret = -EFAULT;
+ }
+
+ msm_gem_unlock(obj);
+
break;
}
@@ -1058,6 +1058,7 @@ static void msm_gem_free_object(struct drm_gem_object *obj)
drm_gem_object_release(obj);
+ kfree(msm_obj->metadata);
kfree(msm_obj);
}
@@ -109,6 +109,10 @@ struct msm_gem_object {
char name[32]; /* Identifier to print for the debugfs files */
+ /* userspace metadata backchannel */
+ void *metadata;
+ u32 metadata_size;
+
/**
* pin_count: Number of times the pages are pinned
*
@@ -139,6 +139,8 @@ struct drm_msm_gem_new {
#define MSM_INFO_GET_NAME 0x03 /* get debug name, returned by pointer */
#define MSM_INFO_SET_IOVA 0x04 /* set the iova, passed by value */
#define MSM_INFO_GET_FLAGS 0x05 /* get the MSM_BO_x flags */
+#define MSM_INFO_SET_METADATA 0x06 /* set userspace metadata */
+#define MSM_INFO_GET_METADATA 0x07 /* get userspace metadata */
struct drm_msm_gem_info {
__u32 handle; /* in */