Merge branch '00.00-inst' of git://github.com/skeggsb/linux into drm-fixes
[linux-2.6-microblaze.git] / drivers / gpu / drm / drm_plane.c
index a0cb746..338650a 100644 (file)
@@ -30,6 +30,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_fourcc.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_vblank.h>
 
 #include "drm_crtc_internal.h"
@@ -40,7 +41,7 @@
  * A plane represents an image source that can be blended with or overlayed on
  * top of a CRTC during the scanout process. Planes take their input data from a
  * &drm_framebuffer object. The plane itself specifies the cropping and scaling
- * of that image, and where it is placed on the visible are of a display
+ * of that image, and where it is placed on the visible area of a display
  * pipeline, represented by &drm_crtc. A plane can also have additional
  * properties that specify how the pixels are positioned and blended, like
  * rotation or Z-position. All these properties are stored in &drm_plane_state.
  * &struct drm_plane (possibly as part of a larger structure) and registers it
  * with a call to drm_universal_plane_init().
  *
- * Cursor and overlay planes are optional. All drivers should provide one
- * primary plane per CRTC to avoid surprising userspace too much. See enum
- * drm_plane_type for a more in-depth discussion of these special uapi-relevant
- * plane types. Special planes are associated with their CRTC by calling
- * drm_crtc_init_with_planes().
- *
  * The type of a plane is exposed in the immutable "type" enumeration property,
- * which has one of the following values: "Overlay", "Primary", "Cursor".
+ * which has one of the following values: "Overlay", "Primary", "Cursor" (see
+ * enum drm_plane_type). A plane can be compatible with multiple CRTCs, see
+ * &drm_plane.possible_crtcs.
+ *
+ * Each CRTC must have a unique primary plane userspace can attach to enable
+ * the CRTC. In other words, userspace must be able to attach a different
+ * primary plane to each CRTC at the same time. Primary planes can still be
+ * compatible with multiple CRTCs. There must be exactly as many primary planes
+ * as there are CRTCs.
+ *
+ * Legacy uAPI doesn't expose the primary and cursor planes directly. DRM core
+ * relies on the driver to set the primary and optionally the cursor plane used
+ * for legacy IOCTLs. This is done by calling drm_crtc_init_with_planes(). All
+ * drivers must provide one primary plane per CRTC to avoid surprising legacy
+ * userspace too much.
+ */
+
+/**
+ * DOC: standard plane properties
+ *
+ * DRM planes have a few standardized properties:
+ *
+ * IN_FORMATS:
+ *     Blob property which contains the set of buffer format and modifier
+ *     pairs supported by this plane. The blob is a struct
+ *     drm_format_modifier_blob. Without this property the plane doesn't
+ *     support buffers with modifiers. Userspace cannot change this property.
  */
 
 static unsigned int drm_num_planes(struct drm_device *dev)
@@ -152,31 +173,16 @@ done:
        return 0;
 }
 
-/**
- * drm_universal_plane_init - Initialize a new universal plane object
- * @dev: DRM device
- * @plane: plane object to init
- * @possible_crtcs: bitmask of possible CRTCs
- * @funcs: callbacks for the new plane
- * @formats: array of supported formats (DRM_FORMAT\_\*)
- * @format_count: number of elements in @formats
- * @format_modifiers: array of struct drm_format modifiers terminated by
- *                    DRM_FORMAT_MOD_INVALID
- * @type: type of plane (overlay, primary, cursor)
- * @name: printf style format string for the plane name, or NULL for default name
- *
- * Initializes a plane object of type @type.
- *
- * Returns:
- * Zero on success, error code on failure.
- */
-int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
-                            uint32_t possible_crtcs,
-                            const struct drm_plane_funcs *funcs,
-                            const uint32_t *formats, unsigned int format_count,
-                            const uint64_t *format_modifiers,
-                            enum drm_plane_type type,
-                            const char *name, ...)
+__printf(9, 0)
+static int __drm_universal_plane_init(struct drm_device *dev,
+                                     struct drm_plane *plane,
+                                     uint32_t possible_crtcs,
+                                     const struct drm_plane_funcs *funcs,
+                                     const uint32_t *formats,
+                                     unsigned int format_count,
+                                     const uint64_t *format_modifiers,
+                                     enum drm_plane_type type,
+                                     const char *name, va_list ap)
 {
        struct drm_mode_config *config = &dev->mode_config;
        unsigned int format_modifier_count = 0;
@@ -237,11 +243,7 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
        }
 
        if (name) {
-               va_list ap;
-
-               va_start(ap, name);
                plane->name = kvasprintf(GFP_KERNEL, name, ap);
-               va_end(ap);
        } else {
                plane->name = kasprintf(GFP_KERNEL, "plane-%d",
                                        drm_num_planes(dev));
@@ -286,8 +288,102 @@ int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
 
        return 0;
 }
+
+/**
+ * drm_universal_plane_init - Initialize a new universal plane object
+ * @dev: DRM device
+ * @plane: plane object to init
+ * @possible_crtcs: bitmask of possible CRTCs
+ * @funcs: callbacks for the new plane
+ * @formats: array of supported formats (DRM_FORMAT\_\*)
+ * @format_count: number of elements in @formats
+ * @format_modifiers: array of struct drm_format modifiers terminated by
+ *                    DRM_FORMAT_MOD_INVALID
+ * @type: type of plane (overlay, primary, cursor)
+ * @name: printf style format string for the plane name, or NULL for default name
+ *
+ * Initializes a plane object of type @type. The &drm_plane_funcs.destroy hook
+ * should call drm_plane_cleanup() and kfree() the plane structure. The plane
+ * structure should not be allocated with devm_kzalloc().
+ *
+ * Note: consider using drmm_universal_plane_alloc() instead of
+ * drm_universal_plane_init() to let the DRM managed resource infrastructure
+ * take care of cleanup and deallocation.
+ *
+ * Returns:
+ * Zero on success, error code on failure.
+ */
+int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
+                            uint32_t possible_crtcs,
+                            const struct drm_plane_funcs *funcs,
+                            const uint32_t *formats, unsigned int format_count,
+                            const uint64_t *format_modifiers,
+                            enum drm_plane_type type,
+                            const char *name, ...)
+{
+       va_list ap;
+       int ret;
+
+       WARN_ON(!funcs->destroy);
+
+       va_start(ap, name);
+       ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
+                                        formats, format_count, format_modifiers,
+                                        type, name, ap);
+       va_end(ap);
+       return ret;
+}
 EXPORT_SYMBOL(drm_universal_plane_init);
 
+static void drmm_universal_plane_alloc_release(struct drm_device *dev, void *ptr)
+{
+       struct drm_plane *plane = ptr;
+
+       if (WARN_ON(!plane->dev))
+               return;
+
+       drm_plane_cleanup(plane);
+}
+
+void *__drmm_universal_plane_alloc(struct drm_device *dev, size_t size,
+                                  size_t offset, uint32_t possible_crtcs,
+                                  const struct drm_plane_funcs *funcs,
+                                  const uint32_t *formats, unsigned int format_count,
+                                  const uint64_t *format_modifiers,
+                                  enum drm_plane_type type,
+                                  const char *name, ...)
+{
+       void *container;
+       struct drm_plane *plane;
+       va_list ap;
+       int ret;
+
+       if (WARN_ON(!funcs || funcs->destroy))
+               return ERR_PTR(-EINVAL);
+
+       container = drmm_kzalloc(dev, size, GFP_KERNEL);
+       if (!container)
+               return ERR_PTR(-ENOMEM);
+
+       plane = container + offset;
+
+       va_start(ap, name);
+       ret = __drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
+                                        formats, format_count, format_modifiers,
+                                        type, name, ap);
+       va_end(ap);
+       if (ret)
+               return ERR_PTR(ret);
+
+       ret = drmm_add_action_or_reset(dev, drmm_universal_plane_alloc_release,
+                                      plane);
+       if (ret)
+               return ERR_PTR(ret);
+
+       return container;
+}
+EXPORT_SYMBOL(__drmm_universal_plane_alloc);
+
 int drm_plane_register_all(struct drm_device *dev)
 {
        unsigned int num_planes = 0;