[PATCH 09/10] drm: Move tile group code into drm_connector.c

2016-11-15 Thread Chris Wilson
On Mon, Nov 14, 2016 at 12:58:24PM +0100, Daniel Vetter wrote:
> And also put the overview section into the KMS Properties part of the
> docs, instead of randomly-placed within the helpers - this is part of
> the uabi.
> 
> With this patch I think drm_crtc.[hc] is cleaned up and entirely
> documented.
> 
> Signed-off-by: Daniel Vetter 

Code motion looks ok, placement inside the rst I'll take you at your
word.
Reviewed-by: Chris Wilson 
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre


[PATCH 09/10] drm: Move tile group code into drm_connector.c

2016-11-14 Thread Daniel Vetter
And also put the overview section into the KMS Properties part of the
docs, instead of randomly-placed within the helpers - this is part of
the uabi.

With this patch I think drm_crtc.[hc] is cleaned up and entirely
documented.

Signed-off-by: Daniel Vetter 
---
 Documentation/gpu/drm-kms-helpers.rst |   8 ---
 Documentation/gpu/drm-kms.rst |   6 ++
 drivers/gpu/drm/drm_connector.c   | 104 ++
 drivers/gpu/drm/drm_crtc.c|  99 
 include/drm/drm_connector.h   |  24 
 include/drm/drm_crtc.h|  15 -
 6 files changed, 134 insertions(+), 122 deletions(-)

diff --git a/Documentation/gpu/drm-kms-helpers.rst 
b/Documentation/gpu/drm-kms-helpers.rst
index bb4254d19cbb..4ca77f675967 100644
--- a/Documentation/gpu/drm-kms-helpers.rst
+++ b/Documentation/gpu/drm-kms-helpers.rst
@@ -261,14 +261,6 @@ Plane Helper Reference
 .. kernel-doc:: drivers/gpu/drm/drm_plane_helper.c
:export:

-Tile group
-==
-
-# FIXME: This should probably be moved into a property documentation section
-
-.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
-   :doc: Tile group
-
 Auxiliary Modeset Helpers
 =

diff --git a/Documentation/gpu/drm-kms.rst b/Documentation/gpu/drm-kms.rst
index a8ff2c87c0e9..568f3c2b6e46 100644
--- a/Documentation/gpu/drm-kms.rst
+++ b/Documentation/gpu/drm-kms.rst
@@ -281,6 +281,12 @@ Color Management Properties
 .. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
:export:

+Tile Group Property
+---
+
+.. kernel-doc:: drivers/gpu/drm/drm_connector.c
+   :doc: Tile group
+
 Existing KMS Properties
 ---

diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index 0b89577aa9f8..f370663b49f2 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -1126,3 +1126,107 @@ int drm_mode_getconnector(struct drm_device *dev, void 
*data,
return ret;
 }

+
+/**
+ * DOC: Tile group
+ *
+ * Tile groups are used to represent tiled monitors with a unique integer
+ * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
+ * we store this in a tile group, so we have a common identifier for all tiles
+ * in a monitor group. The property is called "TILE". Drivers can manage tile
+ * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
+ * drm_mode_get_tile_group(). But this is only needed for internal panels where
+ * the tile group information is exposed through a non-standard way.
+ */
+
+static void drm_tile_group_free(struct kref *kref)
+{
+   struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, 
refcount);
+   struct drm_device *dev = tg->dev;
+   mutex_lock(>mode_config.idr_mutex);
+   idr_remove(>mode_config.tile_idr, tg->id);
+   mutex_unlock(>mode_config.idr_mutex);
+   kfree(tg);
+}
+
+/**
+ * drm_mode_put_tile_group - drop a reference to a tile group.
+ * @dev: DRM device
+ * @tg: tile group to drop reference to.
+ *
+ * drop reference to tile group and free if 0.
+ */
+void drm_mode_put_tile_group(struct drm_device *dev,
+struct drm_tile_group *tg)
+{
+   kref_put(>refcount, drm_tile_group_free);
+}
+EXPORT_SYMBOL(drm_mode_put_tile_group);
+
+/**
+ * drm_mode_get_tile_group - get a reference to an existing tile group
+ * @dev: DRM device
+ * @topology: 8-bytes unique per monitor.
+ *
+ * Use the unique bytes to get a reference to an existing tile group.
+ *
+ * RETURNS:
+ * tile group or NULL if not found.
+ */
+struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
+  char topology[8])
+{
+   struct drm_tile_group *tg;
+   int id;
+   mutex_lock(>mode_config.idr_mutex);
+   idr_for_each_entry(>mode_config.tile_idr, tg, id) {
+   if (!memcmp(tg->group_data, topology, 8)) {
+   if (!kref_get_unless_zero(>refcount))
+   tg = NULL;
+   mutex_unlock(>mode_config.idr_mutex);
+   return tg;
+   }
+   }
+   mutex_unlock(>mode_config.idr_mutex);
+   return NULL;
+}
+EXPORT_SYMBOL(drm_mode_get_tile_group);
+
+/**
+ * drm_mode_create_tile_group - create a tile group from a displayid 
description
+ * @dev: DRM device
+ * @topology: 8-bytes unique per monitor.
+ *
+ * Create a tile group for the unique monitor, and get a unique
+ * identifier for the tile group.
+ *
+ * RETURNS:
+ * new tile group or error.
+ */
+struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
+ char topology[8])
+{
+   struct drm_tile_group *tg;
+   int ret;
+
+   tg = kzalloc(sizeof(*tg), GFP_KERNEL);
+   if (!tg)
+   return ERR_PTR(-ENOMEM);
+
+   kref_init(>refcount);
+   memcpy(tg->group_data, topology,