From patchwork Fri Apr 13 16:53:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10340555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4973660541 for ; Fri, 13 Apr 2018 16:56:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3979028923 for ; Fri, 13 Apr 2018 16:56:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E5072892A; Fri, 13 Apr 2018 16:56:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C75ED28923 for ; Fri, 13 Apr 2018 16:56:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF9BD6E688; Fri, 13 Apr 2018 16:55:48 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F9776EB4D; Fri, 13 Apr 2018 16:55:46 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:49758 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1f71yl-0000eO-V6; Fri, 13 Apr 2018 18:55:15 +0200 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Date: Fri, 13 Apr 2018 18:53:40 +0200 Message-Id: <20180413165354.8331-12-noralf@tronnes.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180413165354.8331-1-noralf@tronnes.org> References: <20180413165354.8331-1-noralf@tronnes.org> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC v4 11/25] drm/connector: Add connector array functions X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org, =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , laurent.pinchart@ideasonboard.com, mstaudt@suse.de, dh.herrmann@gmail.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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