From patchwork Mon May 19 13:42:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Wood X-Patchwork-Id: 4202591 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F15579F37E for ; Mon, 19 May 2014 13:42:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0659E20251 for ; Mon, 19 May 2014 13:42:18 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id DF0452016C for ; Mon, 19 May 2014 13:42:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 408936E4BE; Mon, 19 May 2014 06:42:16 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-we0-f176.google.com (mail-we0-f176.google.com [74.125.82.176]) by gabe.freedesktop.org (Postfix) with ESMTP id 5539F6E4B3 for ; Mon, 19 May 2014 06:42:12 -0700 (PDT) Received: by mail-we0-f176.google.com with SMTP id q59so5424325wes.21 for ; Mon, 19 May 2014 06:42:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=UaszbOWkD+SNAt4k8cTVcRygvwhyXAMTiegF5MuwBzY=; b=Cf5lxxaS92olK0kYenX4HazkDCDk7ksChA7mODn+cai7cMbnntURgBabXoSRla2bwZ wZKO8mXLE/m/l6zmOexCKqXT/X2h6L9rU4ML9KhVEbomn52PtCjo3Um5kmHaHHDQoU9U 8m13jyB0UtEFgXIlMXvtCAFgRoeqRte4rhWXAgy0tbo7BrymGRz2dJ4fWSacPOY2jt1r TdE6YRYMv/gIFL0Y/5USMxCCV3eu0BYh5AcmmdU27qUxkzOrm21UwwUY7VU9OwW41bku folipBL1VgFOo0gTw0kNL4aeg9Gy7qakIccC05SqUoNvkI7H+/ndt1RDgDKQo2sEz/li j7yg== X-Gm-Message-State: ALoCoQmgBfT443im82xRxvZ/Wn5ASVJBWXgF7yiWUPai9ToCMJsyJfMOw57dD0vIZk5YwM6vllb5 X-Received: by 10.180.88.129 with SMTP id bg1mr13033529wib.51.1400506931562; Mon, 19 May 2014 06:42:11 -0700 (PDT) Received: from pistachio.icx.intel.com ([83.217.123.106]) by mx.google.com with ESMTPSA id fz11sm15157538wic.4.2014.05.19.06.42.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 May 2014 06:42:10 -0700 (PDT) From: Thomas Wood To: intel-gfx@lists.freedesktop.org Date: Mon, 19 May 2014 14:42:07 +0100 Message-Id: <1400506928-12775-2-git-send-email-thomas.wood@intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1400506928-12775-1-git-send-email-thomas.wood@intel.com> References: <1400506928-12775-1-git-send-email-thomas.wood@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH i-g-t 1/2] lib: add functions to change connector states X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a function to force a particular state on a connector and a convenience function to find and set the state on the VGA connector. Signed-off-by: Thomas Wood --- lib/igt_kms.c | 78 ++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 12 +++++++ tests/Makefile.sources | 1 + tests/kms_force_connector.c | 87 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 tests/kms_force_connector.c diff --git a/lib/igt_kms.c b/lib/igt_kms.c index d00250d..90c3e56 100644 --- a/lib/igt_kms.c +++ b/lib/igt_kms.c @@ -384,6 +384,61 @@ err1: return -1; } +static int get_card_number(int fd) +{ + struct stat buf; + + /* find the minor number of the device */ + fstat(fd, &buf); + + return minor(buf.st_rdev); +} + +/** + * kmstest_force_connector: + * @fd: drm file descriptor + * @connector: connector + * @state: state to force on @connector + * + * Force the specified state on the specified connector. + */ +void kmstest_force_connector(int drm_fd, drmModeConnector *connector, enum + force_connector state) +{ + char *path; + const char *value; + int sysfs_fd, ret; + + switch (state) { + case FORCE_CONNECTOR_UNSPECIFIED: + value = "unspecified"; + break; + case FORCE_CONNECTOR_ON: + value = "on"; + break; + case FORCE_CONNECTOR_DIGITAL: + value = "digital"; + break; + case FORCE_CONNECTOR_OFF: + value = "off"; + break; + } + + asprintf(&path, "/sys/class/drm/card%d-%s-%d/force", + get_card_number(drm_fd), + kmstest_connector_type_str(connector->connector_type), + connector->connector_type_id); + sysfs_fd = open(path, O_WRONLY | O_TRUNC); + free(path); + + igt_assert(sysfs_fd != -1); + + ret = write(sysfs_fd, value, strlen(value) + 1); + close(sysfs_fd); + + igt_assert(ret != -1); +} + void kmstest_free_connector_config(struct kmstest_connector_config *config) { drmModeFreeCrtc(config->crtc); @@ -1047,3 +1102,26 @@ void igt_wait_for_vblank(int drm_fd, enum pipe pipe) igt_assert(drmWaitVBlank(drm_fd, &wait_vbl) == 0); } + +void igt_set_vga_connector_state(int drm_fd, enum force_connector state) +{ + drmModeRes *res; + drmModeConnector *c; + + res = drmModeGetResources(drm_fd); + + /* find the vga connector */ + for (int i = 0; i < res->count_connectors; i++) { + + c = drmModeGetConnector(drm_fd, res->connectors[i]); + + if (c->connector_type == DRM_MODE_CONNECTOR_VGA) + break; + + drmModeFreeConnector(c); + } + + kmstest_force_connector(drm_fd, c, state); + + drmModeFreeConnector(c); +} diff --git a/lib/igt_kms.h b/lib/igt_kms.h index 8e80d4b..71f6831 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -75,11 +75,20 @@ struct kmstest_connector_config { int pipe; }; +enum force_connector { + FORCE_CONNECTOR_UNSPECIFIED, + FORCE_CONNECTOR_ON, + FORCE_CONNECTOR_DIGITAL, + FORCE_CONNECTOR_OFF +}; + int kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector, drmModeModeInfo *mode); int kmstest_get_connector_config(int drm_fd, uint32_t connector_id, unsigned long crtc_idx_mask, struct kmstest_connector_config *config); +void kmstest_force_connector(int fd, drmModeConnector *connector, + enum force_connector state); void kmstest_free_connector_config(struct kmstest_connector_config *config); void kmstest_dump_mode(drmModeModeInfo *mode); @@ -175,5 +184,8 @@ void igt_wait_for_vblank(int drm_fd, enum pipe pipe); #define IGT_FIXED(i,f) ((i) << 16 | (f)) + +void igt_set_vga_connector_state(int drm_fd, enum force_connector state); + #endif /* __IGT_KMS_H__ */ diff --git a/tests/Makefile.sources b/tests/Makefile.sources index fbf63e9..eff0124 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -134,6 +134,7 @@ TESTS_progs = \ gen3_render_tiledx_blits \ gen3_render_tiledy_blits \ gen7_forcewake_mt \ + kms_force_connector \ kms_sink_crc_basic \ pm_psr \ pm_rc6_residency \ diff --git a/tests/kms_force_connector.c b/tests/kms_force_connector.c new file mode 100644 index 0000000..b2659ae --- /dev/null +++ b/tests/kms_force_connector.c @@ -0,0 +1,87 @@ +/* + * Copyright © 2014 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ + +#include "igt_core.h" +#include "igt_kms.h" +#include "drmtest.h" + +int +main (int argc, char **argv) +{ + /* force the VGA & HDMI output and test it worked */ + int drm_fd; + drmModeRes *res; + drmModeConnector *c, *temp; + + igt_simple_init(); + + drm_fd = drm_open_any(); + res = drmModeGetResources(drm_fd); + + /* find the vga connector */ + for (int i = 0; i < res->count_connectors; i++) { + + c = drmModeGetConnector(drm_fd, res->connectors[i]); + + if (c->connector_type == DRM_MODE_CONNECTOR_LVDS) + break; + + drmModeFreeConnector(c); + } + + /* force the connector state and check the reported value */ + kmstest_force_connector(drm_fd, c, FORCE_CONNECTOR_ON); + temp = drmModeGetConnector(drm_fd, c->connector_id); + igt_assert(temp->connection == DRM_MODE_CONNECTED); + igt_assert(temp->count_modes > 0); + drmModeFreeConnector(temp); + + /* attempt to use the display */ + { + igt_display_t display; + + igt_set_vt_graphics_mode(); + + igt_display_init(&display, drm_fd); + igt_display_commit(&display); + } + + + kmstest_force_connector(drm_fd, c, FORCE_CONNECTOR_OFF); + temp = drmModeGetConnector(drm_fd, c->connector_id); + igt_assert(temp->connection == DRM_MODE_DISCONNECTED); + igt_assert(temp->count_modes = 0); + drmModeFreeConnector(temp); + + + /* check that the previous state is restored */ + kmstest_force_connector(drm_fd, c, FORCE_CONNECTOR_UNSPECIFIED); + temp = drmModeGetConnector(drm_fd, c->connector_id); + igt_assert(temp->connection == c->connection); + drmModeFreeConnector(temp); + + drmModeFreeConnector(c); + + igt_success(); +}