From: "Noralf Trønnes" <noralf@tronnes.org>
To: dri-devel@lists.freedesktop.org
Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org,
"Noralf Trønnes" <noralf@tronnes.org>,
laurent.pinchart@ideasonboard.com, mstaudt@suse.de,
dh.herrmann@gmail.com
Subject: [RFC v4 11/25] drm/connector: Add connector array functions
Date: Fri, 13 Apr 2018 18:53:40 +0200 [thread overview]
Message-ID: <20180413165354.8331-12-noralf@tronnes.org> (raw)
In-Reply-To: <20180413165354.8331-1-noralf@tronnes.org>
Add functions to deal with the registred connectors as an array:
- drm_connector_get_all()
- drm_connector_put_all()
And to get the enabled status of those connectors:
drm_connector_get_enabled_status()
This is prep work to remove struct drm_fb_helper_connector.
Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
drivers/gpu/drm/drm_connector.c | 105 ++++++++++++++++++++++++++++++++++++++++
include/drm/drm_connector.h | 5 ++
2 files changed, 110 insertions(+)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
index b9eb143d70fc..25c333c05a4e 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -1854,3 +1854,108 @@ drm_connector_pick_cmdline_mode(struct drm_connector *connector)
return mode;
}
EXPORT_SYMBOL(drm_connector_pick_cmdline_mode);
+
+/**
+ * drm_connector_get_all - Get all connectors into an array
+ * @dev: DRM device
+ * @connectors: Returned connector array
+ *
+ * This function iterates through all registered connectors and adds them to an
+ * array allocated by this function. A ref is taken on the connectors.
+ *
+ * Use drm_connector_put_all() to drop refs and free the array.
+ *
+ * Returns:
+ * Number of connectors or -ENOMEM on failure.
+ */
+int drm_connector_get_all(struct drm_device *dev, struct drm_connector ***connectors)
+{
+ struct drm_connector *connector, **temp, **conns = NULL;
+ struct drm_connector_list_iter conn_iter;
+ int connector_count = 0;
+
+ drm_connector_list_iter_begin(dev, &conn_iter);
+ drm_for_each_connector_iter(connector, &conn_iter) {
+ temp = krealloc(conns, (connector_count + 1) * sizeof(*conns), GFP_KERNEL);
+ if (!temp)
+ goto err_put_free;
+
+ conns = temp;
+ conns[connector_count++] = connector;
+ drm_connector_get(connector);
+ }
+ drm_connector_list_iter_end(&conn_iter);
+
+ *connectors = conns;
+
+ return connector_count;
+
+err_put_free:
+ drm_connector_list_iter_end(&conn_iter);
+ drm_connector_put_all(conns, connector_count);
+
+ return -ENOMEM;
+}
+EXPORT_SYMBOL(drm_connector_get_all);
+
+/**
+ * drm_connector_put_all - Put and free connector array
+ * @connectors: Array of connectors
+ * @connector_count: Number of connectors in the array (can be negative or zero)
+ *
+ * This function drops the ref on the connectors an frees the array.
+ */
+void drm_connector_put_all(struct drm_connector **connectors, int connector_count)
+{
+ int i;
+
+ if (connector_count < 1)
+ return;
+
+ for (i = 0; i < connector_count; i++)
+ drm_connector_put(connectors[i]);
+ kfree(connectors);
+}
+EXPORT_SYMBOL(drm_connector_put_all);
+
+/**
+ * drm_connector_get_enabled_status - Get enabled status on connectors
+ * @connectors: Array of connectors
+ * @connector_count: Number of connectors in the array
+ *
+ * This loops over the connector array and sets enabled if connector status is
+ * _connected_. If no connectors are connected, a new pass is done and
+ * connectors that are not _disconnected_ are set enabled.
+ *
+ * The caller is responsible for freeing the array using kfree().
+ *
+ * Returns:
+ * A boolean array of connector enabled statuses or NULL on allocation failure.
+ */
+bool *drm_connector_get_enabled_status(struct drm_connector **connectors,
+ unsigned int connector_count)
+{
+ bool *enabled, any_enabled = false;
+ unsigned int i;
+
+ enabled = kcalloc(connector_count, sizeof(*enabled), GFP_KERNEL);
+ if (!enabled)
+ return NULL;
+
+ for (i = 0; i < connector_count; i++) {
+ if (connectors[i]->status == connector_status_connected) {
+ enabled[i] = true;
+ any_enabled = true;
+ }
+ }
+
+ if (any_enabled)
+ return enabled;
+
+ for (i = 0; i < connector_count; i++)
+ if (connectors[i]->status != connector_status_disconnected)
+ enabled[i] = true;
+
+ return enabled;
+}
+EXPORT_SYMBOL(drm_connector_get_enabled_status);
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index 9cb4ca42373c..c3556a5f40c9 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -1169,4 +1169,9 @@ drm_connector_has_preferred_mode(struct drm_connector *connector,
struct drm_display_mode *
drm_connector_pick_cmdline_mode(struct drm_connector *connector);
+int drm_connector_get_all(struct drm_device *dev, struct drm_connector ***connectors);
+void drm_connector_put_all(struct drm_connector **connectors, int connector_count);
+bool *drm_connector_get_enabled_status(struct drm_connector **connectors,
+ unsigned int connector_count);
+
#endif
--
2.15.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2018-04-13 16:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-13 16:53 [RFC v4 00/25] drm: Add generic fbdev emulation Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 01/25] drm: provide management functions for drm_file Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 02/25] drm/file: Don't set master on in-kernel clients Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 03/25] drm/fb-helper: No need to cache rotation and sw_rotations Noralf Trønnes
2018-04-13 17:07 ` Hans de Goede
2018-04-13 16:53 ` [RFC v4 04/25] drm/fb-helper: Remove drm_fb_helper_debug_enter/leave() Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 05/25] drm/fb-helper: dpms_legacy(): Only set on connectors in use Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 06/25] drm/atomic: Move __drm_atomic_helper_disable_plane/set_config() Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 07/25] drm: Begin an API for in-kernel clients Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 08/25] drm/fb-helper: Use struct drm_client_display Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 09/25] drm/fb-helper: Move modeset commit code to drm_client Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 10/25] drm/connector: Add drm_connector_has_preferred_mode/pick_cmdline_mode() Noralf Trønnes
2018-04-13 16:53 ` Noralf Trønnes [this message]
2018-04-13 16:53 ` [RFC v4 12/25] drm/i915: Add drm_driver->initial_client_display callback Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 13/25] drm/fb-helper: Remove struct drm_fb_helper_crtc Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 14/25] drm/fb-helper: Remove struct drm_fb_helper_connector Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 15/25] drm/fb-helper: Move modeset config code to drm_client Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 16/25] drm: Make ioctls available for in-kernel clients Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 17/25] drm/client: Bail out if there's a DRM master Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 18/25] drm/client: Make the display modes available to clients Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 19/25] drm/client: Finish the in-kernel client API Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 20/25] drm/prime: Don't pin module on export for in-kernel clients Noralf Trønnes
2018-04-13 16:53 ` [RFC v4 21/25] drm/fb-helper: Add drm_fb_helper_fb_open/release() Noralf Trønnes
2018-04-13 17:06 ` [RFC v4 00/25] drm: Add generic fbdev emulation Noralf Trønnes
-- strict thread matches above, loose matches on Subject: below --
2018-04-14 11:52 Noralf Trønnes
2018-04-14 11:53 ` [RFC v4 11/25] drm/connector: Add connector array functions Noralf Trønnes
2018-04-16 8:33 ` Daniel Vetter
2018-04-12 13:17 [RFC v4 00/25] drm: Add generic fbdev emulation Noralf Trønnes
2018-04-12 13:17 ` [RFC v4 11/25] drm/connector: Add connector array functions Noralf Trønnes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180413165354.8331-12-noralf@tronnes.org \
--to=noralf@tronnes.org \
--cc=daniel.vetter@ffwll.ch \
--cc=dh.herrmann@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=mstaudt@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).