drm: add atomic properties
authorRob Clark <robdclark@gmail.com>
Thu, 18 Dec 2014 21:01:50 +0000 (16:01 -0500)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Mon, 5 Jan 2015 12:54:38 +0000 (13:54 +0100)
Once a driver is using atomic helpers for modeset, the next step is to
switch over to atomic properties.  To do this, make sure that any
modeset objects have their ->atomic_{get,set}_property() vfuncs suitably
populated if they have custom properties (you did already remember to
plug in atomic-helper func for the legacy ->set_property() vfuncs,
right?), and then set DRIVER_ATOMIC bit in driver_features flag.

A new cap is introduced, DRM_CLIENT_CAP_ATOMIC, for the purposes of
shielding legacy userspace from atomic properties.  Mostly for the
benefit of legacy DDX drivers that do silly things like getting/setting
each property at startup (since some of the new atomic properties will
be able to trigger modeset).

Signed-off-by: Rob Clark <robdclark@gmail.com>
[danvet: Squash in fixup patch to check for DRM_MODE_PROP_ATOMIC
instaed of the CAP define when filtering properties. Reported by
Tvrtko Uruslin, acked by Rob.]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Documentation/DocBook/drm.tmpl
drivers/gpu/drm/drm_atomic.c
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/drm_drv.c
drivers/gpu/drm/drm_ioctl.c
include/drm/drmP.h
include/drm/drm_atomic.h
include/drm/drm_crtc.h
include/uapi/drm/drm.h
include/uapi/drm/drm_mode.h

index 4b592ffbafeec8053e09c0c068045505e05757ec..7fa4f9873cf7bd7e5f5a963260365f8ff5e9e8a7 100644 (file)
               Driver supports dedicated render nodes.
             </para></listitem>
           </varlistentry>
+          <varlistentry>
+            <term>DRIVER_ATOMIC</term>
+            <listitem><para>
+              Driver supports atomic properties.  In this case the driver
+              must implement appropriate obj->atomic_get_property() vfuncs
+              for any modeset objects with driver specific properties.
+            </para></listitem>
+          </varlistentry>
         </variablelist>
       </sect3>
       <sect3>
index 9c4e149a61e2f7c138051a739baee434b3cdfd2a..ce3c681d60f81a3e6c0893bfd8d8d379f484a874 100644 (file)
@@ -520,6 +520,51 @@ int drm_atomic_connector_get_property(struct drm_connector *connector,
 }
 EXPORT_SYMBOL(drm_atomic_connector_get_property);
 
+/**
+ * drm_atomic_get_property - helper to read atomic property
+ * @obj: drm mode object whose property to read
+ * @property: the property to read
+ * @val: the read value, returned by reference
+ *
+ * RETURNS:
+ * Zero on success, error code on failure
+ */
+int drm_atomic_get_property(struct drm_mode_object *obj,
+               struct drm_property *property, uint64_t *val)
+{
+       struct drm_device *dev = property->dev;
+       int ret;
+
+       switch (obj->type) {
+       case DRM_MODE_OBJECT_CONNECTOR: {
+               struct drm_connector *connector = obj_to_connector(obj);
+               WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
+               ret = drm_atomic_connector_get_property(connector,
+                               connector->state, property, val);
+               break;
+       }
+       case DRM_MODE_OBJECT_CRTC: {
+               struct drm_crtc *crtc = obj_to_crtc(obj);
+               WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
+               ret = drm_atomic_crtc_get_property(crtc,
+                               crtc->state, property, val);
+               break;
+       }
+       case DRM_MODE_OBJECT_PLANE: {
+               struct drm_plane *plane = obj_to_plane(obj);
+               WARN_ON(!drm_modeset_is_locked(&plane->mutex));
+               ret = drm_atomic_plane_get_property(plane,
+                               plane->state, property, val);
+               break;
+       }
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
 /**
  * drm_atomic_set_crtc_for_plane - set crtc for plane
  * @plane_state: the plane whose incoming state to update
index f5f34d0d7c206adf3a7cb1093a174f7ed6cde13a..3bac877228fac34be1c76804085ffaff9849c535 100644 (file)
@@ -38,6 +38,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_modeset_lock.h>
+#include <drm/drm_atomic.h>
 
 #include "drm_crtc_internal.h"
 #include "drm_internal.h"
@@ -1992,19 +1993,25 @@ static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *conne
 }
 
 /* helper for getconnector and getproperties ioctls */
-static int get_properties(struct drm_mode_object *obj,
+static int get_properties(struct drm_mode_object *obj, bool atomic,
                uint32_t __user *prop_ptr, uint64_t __user *prop_values,
                uint32_t *arg_count_props)
 {
-       int props_count = obj->properties->count;
-       int i, ret, copied = 0;
+       int props_count;
+       int i, ret, copied;
+
+       props_count = obj->properties->count;
+       if (!atomic)
+               props_count -= obj->properties->atomic_count;
 
        if ((*arg_count_props >= props_count) && props_count) {
-               copied = 0;
-               for (i = 0; i < props_count; i++) {
+               for (i = 0, copied = 0; copied < props_count; i++) {
                        struct drm_property *prop = obj->properties->properties[i];
                        uint64_t val;
 
+                       if ((prop->flags & DRM_MODE_PROP_ATOMIC) && !atomic)
+                               continue;
+
                        ret = drm_object_property_get_value(obj, prop, &val);
                        if (ret)
                                return ret;
@@ -2118,7 +2125,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
        }
        out_resp->count_modes = mode_count;
 
-       ret = get_properties(&connector->base,
+       ret = get_properties(&connector->base, file_priv->atomic,
                        (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
                        (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
                        &out_resp->count_props);
@@ -3832,6 +3839,8 @@ void drm_object_attach_property(struct drm_mode_object *obj,
        obj->properties->properties[count] = property;
        obj->properties->values[count] = init_val;
        obj->properties->count++;
+       if (property->flags & DRM_MODE_PROP_ATOMIC)
+               obj->properties->atomic_count++;
 }
 EXPORT_SYMBOL(drm_object_attach_property);
 
@@ -3883,6 +3892,14 @@ int drm_object_property_get_value(struct drm_mode_object *obj,
 {
        int i;
 
+       /* read-only properties bypass atomic mechanism and still store
+        * their value in obj->properties->values[].. mostly to avoid
+        * having to deal w/ EDID and similar props in atomic paths:
+        */
+       if (drm_core_check_feature(property->dev, DRIVER_ATOMIC) &&
+                       !(property->flags & DRM_MODE_PROP_IMMUTABLE))
+               return drm_atomic_get_property(obj, property, val);
+
        for (i = 0; i < obj->properties->count; i++) {
                if (obj->properties->properties[i] == property) {
                        *val = obj->properties->values[i];
@@ -4413,7 +4430,7 @@ int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
                goto out;
        }
 
-       ret = get_properties(obj,
+       ret = get_properties(obj, file_priv->atomic,
                        (uint32_t __user *)(unsigned long)(arg->props_ptr),
                        (uint64_t __user *)(unsigned long)(arg->prop_values_ptr),
                        &arg->count_props);
index 4f41377b0b80963f9ce84b3492412d025924652b..d51213464672a9c1b7d3362f355b6ddde29c2403 100644 (file)
 unsigned int drm_debug = 0;    /* 1 to enable debug output */
 EXPORT_SYMBOL(drm_debug);
 
+bool drm_atomic = 0;
+
 MODULE_AUTHOR(CORE_AUTHOR);
 MODULE_DESCRIPTION(CORE_DESC);
 MODULE_LICENSE("GPL and additional rights");
 MODULE_PARM_DESC(debug, "Enable debug output");
+MODULE_PARM_DESC(atomic, "Enable experimental atomic KMS API");
 MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs] (0: never disable, <0: disable immediately)");
 MODULE_PARM_DESC(timestamp_precision_usec, "Max. error on timestamps [usecs]");
 MODULE_PARM_DESC(timestamp_monotonic, "Use monotonic timestamps");
 
 module_param_named(debug, drm_debug, int, 0600);
+module_param_named_unsafe(atomic, drm_atomic, bool, 0600);
 
 static DEFINE_SPINLOCK(drm_minor_lock);
 static struct idr drm_minors_idr;
index 00587a1e3c83c0dc23c05a55a7d37ea10f891847..adc822312f6cf6c9788f28cd9a8ca5ca8709733c 100644 (file)
@@ -345,6 +345,16 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
                        return -EINVAL;
                file_priv->universal_planes = req->value;
                break;
+       case DRM_CLIENT_CAP_ATOMIC:
+               /* for now, hide behind experimental drm.atomic moduleparam */
+               if (!drm_atomic)
+                       return -EINVAL;
+               if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
+                       return -EINVAL;
+               if (req->value > 1)
+                       return -EINVAL;
+               file_priv->atomic = req->value;
+               break;
        default:
                return -EINVAL;
        }
index 8ba35c622e2202a889a3a06706bdc93e035fb841..0f7115e988a075fe393858abff82128408e6f4c0 100644 (file)
@@ -143,6 +143,7 @@ void drm_err(const char *format, ...);
 #define DRIVER_MODESET     0x2000
 #define DRIVER_PRIME       0x4000
 #define DRIVER_RENDER      0x8000
+#define DRIVER_ATOMIC      0x10000
 
 /***********************************************************************/
 /** \name Macros to make printk easier */
@@ -283,6 +284,8 @@ struct drm_file {
         * in the plane list
         */
        unsigned universal_planes:1;
+       /* true if client understands atomic properties */
+       unsigned atomic:1;
 
        struct pid *pid;
        kuid_t uid;
@@ -950,6 +953,7 @@ extern void drm_master_put(struct drm_master **master);
 extern void drm_put_dev(struct drm_device *dev);
 extern void drm_unplug_dev(struct drm_device *dev);
 extern unsigned int drm_debug;
+extern bool drm_atomic;
 
                                /* Debugfs support */
 #if defined(CONFIG_DEBUG_FS)
index d41233ccbc9e6489638c3b32dbc7290125977ed4..231fb485abb39ca4ceb4ddee8836bc1bfee18254 100644 (file)
@@ -63,6 +63,9 @@ int drm_atomic_connector_get_property(struct drm_connector *connector,
                const struct drm_connector_state *state,
                struct drm_property *property, uint64_t *val);
 
+int drm_atomic_get_property(struct drm_mode_object *obj,
+                          struct drm_property *property, uint64_t *val);
+
 int __must_check
 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
                              struct drm_crtc *crtc);
index e1f34694fcff14326a009bf551aab687b5a1517f..b5ab673add29b797d9d3a3076a455211eb784a94 100644 (file)
@@ -63,7 +63,7 @@ struct drm_mode_object {
 
 #define DRM_OBJECT_MAX_PROPERTY 24
 struct drm_object_properties {
-       int count;
+       int count, atomic_count;
        /* NOTE: if we ever start dynamically destroying properties (ie.
         * not at drm_mode_config_cleanup() time), then we'd have to do
         * a better job of detaching property from mode objects to avoid
index b0b85561364161e7ce5c8196a6a8b03940db4b9d..f7b2baf7ecb27b228a248d49225574a47b3a5967 100644 (file)
@@ -654,6 +654,13 @@ struct drm_get_cap {
  */
 #define DRM_CLIENT_CAP_UNIVERSAL_PLANES  2
 
+/**
+ * DRM_CLIENT_CAP_ATOMIC
+ *
+ * If set to 1, the DRM core will expose atomic properties to userspace
+ */
+#define DRM_CLIENT_CAP_ATOMIC  3
+
 /** DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
 struct drm_set_client_cap {
        __u64 capability;
index aae71cb32123ee9d91439970099a1f8a4670d294..b8f9c0f2e7fec0b88608ca99b0b9c6a65eea0782 100644 (file)
@@ -272,6 +272,13 @@ struct drm_mode_get_connector {
 #define DRM_MODE_PROP_OBJECT           DRM_MODE_PROP_TYPE(1)
 #define DRM_MODE_PROP_SIGNED_RANGE     DRM_MODE_PROP_TYPE(2)
 
+/* the PROP_ATOMIC flag is used to hide properties from userspace that
+ * is not aware of atomic properties.  This is mostly to work around
+ * older userspace (DDX drivers) that read/write each prop they find,
+ * witout being aware that this could be triggering a lengthy modeset.
+ */
+#define DRM_MODE_PROP_ATOMIC        0x80000000
+
 struct drm_mode_property_enum {
        __u64 value;
        char name[DRM_PROP_NAME_LEN];