From patchwork Fri Mar 14 15:16:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 3833171 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 77EE0BF540 for ; Fri, 14 Mar 2014 15:16:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EE8C20304 for ; Fri, 14 Mar 2014 15:16:37 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 2404520131 for ; Fri, 14 Mar 2014 15:16:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B2D6FFB4A0; Fri, 14 Mar 2014 08:16:32 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BCA1FB49F for ; Fri, 14 Mar 2014 08:16:30 -0700 (PDT) Received: by mail-ee0-f51.google.com with SMTP id c13so1494616eek.24 for ; Fri, 14 Mar 2014 08:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id; bh=kp2BYHIA3FSj3tQA87y64KbkAjGuy+L9KzeMQO/QSfM=; b=Ty1+JhcvYU/nsoV83ZZoj2fM1nIRawzastjHXnYF1VPRJ9fGhEXLBaXKjEl311acYB f2AsmzSJnquWDXIQ2fvtaEFK4HtJU8svSxuuTybXRCxiSNVI4CaR0mIMq0l7w2TIMmH4 OGIRldldUNsY6t8xxpvCRe0jLb7U9bpbGpAlE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kp2BYHIA3FSj3tQA87y64KbkAjGuy+L9KzeMQO/QSfM=; b=QGnydWzTw5LxroROYD8GlbAjQVScuVED0hECjFgd8FTkP/2KFz+LQXAji2owTWe8dN I7voDmthKuoY1bWU2Yqo9E6iWlZzbFNIZ6WLPRVZq5jxbj2+ZQDq8yyo9pXjjBf0WhmN 7qeecLBhgcw8m11IDVPDXEx2HtMsjZOUNz9lW0rM4FokSFZxngnRSFTPrb75ac5QvlZR btAFRat47x8U6muvlWLnUHbCCVCE5/diGrBJmL3ihLXXfi52h/tzouNZv0U7tS6uepVB 0nOFxZ1Qv1cYT0i5DrmkPwGQXqzW5leuT+6ug3wzctnk4XTIsNkaPhOS9FxO5zI4bH1M e9vQ== X-Gm-Message-State: ALoCoQkEzSsf/W39qQYGHtQHwzAzim+L4o4IHsKdibpvVHxz7zq6kcYnrKh2/aSdsTJWvPSz3vOC X-Received: by 10.14.108.199 with SMTP id q47mr10587eeg.108.1394810188057; Fri, 14 Mar 2014 08:16:28 -0700 (PDT) Received: from aaron.ffwll.local (84-73-67-144.dclient.hispeed.ch. [84.73.67.144]) by mx.google.com with ESMTPSA id l42sm17692353eew.19.2014.03.14.08.16.26 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Mar 2014 08:16:27 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Date: Fri, 14 Mar 2014 16:16:02 +0100 Message-Id: <1394810164-16040-1-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.8.4.rc3 Cc: Daniel Vetter , Paulo Zanoni Subject: [Intel-gfx] [PATCH 1/3] lib: extract igt_open_forcewake_handle X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_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 ... and I immediately regret that I've killed the return value for igt_debugfs_init, since we have callers which need to work without the forcewake stuff, e.g. the reg dumper needs to work without i915 loaded. Put this new helper to good use in the mmio code and the pm_pc8 testcase. Cc: Paulo Zanoni Signed-off-by: Daniel Vetter --- lib/igt_debugfs.c | 45 ++++++++++++++++++++++++++++++++++++--------- lib/igt_debugfs.h | 1 + lib/intel_mmio.c | 52 +++++----------------------------------------------- tests/pm_pc8.c | 5 +++-- 4 files changed, 45 insertions(+), 58 deletions(-) diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index 5c0290197e44..79b2618b4273 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -76,13 +76,7 @@ * General debugfs helpers */ -/** - * igt_debugfs_init: - * @debugfs: debugfs access structure to initialize - * - * Initializes the debugfs access helper library. - */ -void igt_debugfs_init(igt_debugfs_t *debugfs) +static bool __igt_debugfs_init(igt_debugfs_t *debugfs) { const char *path = "/sys/kernel/debug"; struct stat st; @@ -107,13 +101,24 @@ find_minor: sprintf(debugfs->dri_path + len, "/i915_error_state"); if (stat(debugfs->dri_path, &st) == 0) { debugfs->dri_path[len] = '\0'; - return; + return true; } } debugfs->dri_path[0] = '\0'; - igt_fail(4); + return false; +} + +/** + * igt_debugfs_init: + * @debugfs: debugfs access structure to initialize + * + * Initializes the debugfs access helper library. + */ +void igt_debugfs_init(igt_debugfs_t *debugfs) +{ + igt_assert(__igt_debugfs_init(debugfs)); } /** @@ -578,3 +583,25 @@ void igt_enable_prefault(void) { igt_prefault_control(true); } + +/** + * igt_open_forcewake_handle: + * + * This functions opens the debugfs forcewake file and so prevents the GT from + * suspending. The reference is automatically dropped when the is closed. + * + * Returns: The file descriptor of the forcewake handle or -1 if that didn't + * work out. + */ +int igt_open_forcewake_handle(void) +{ + igt_debugfs_t debugfs; + int fd; + + if (!__igt_debugfs_init(&debugfs)) + return -1; + + fd = igt_debugfs_open(&debugfs, "i915_forcewake_user", O_WRONLY); + + return fd; +} diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h index 90e31d7046eb..5e153b175401 100644 --- a/lib/igt_debugfs.h +++ b/lib/igt_debugfs.h @@ -154,5 +154,6 @@ void igt_drop_caches_set(uint64_t val); void igt_disable_prefault(void); void igt_enable_prefault(void); +int igt_open_forcewake_handle(void); #endif /* __IGT_DEBUGFS_H__ */ diff --git a/lib/intel_mmio.c b/lib/intel_mmio.c index 930a44f838fb..224800989189 100644 --- a/lib/intel_mmio.c +++ b/lib/intel_mmio.c @@ -42,6 +42,7 @@ #include #include "intel_gpu_tools.h" +#include "igt_debugfs.h" #define FAKEKEY 0x2468ace0 @@ -50,8 +51,6 @@ void *mmio; static struct _mmio_data { int inited; bool safe; - char debugfs_path[FILENAME_MAX]; - char debugfs_forcewake_path[FILENAME_MAX]; uint32_t i915_devid; struct intel_register_map map; int key; @@ -113,42 +112,6 @@ intel_get_mmio(struct pci_device *pci_dev) } } -/* - * If successful, i915_debugfs_path and i915_debugfs_forcewake_path are both - * updated with the correct path. - */ -static int -find_debugfs_path(const char *dri_base) -{ - char buf[FILENAME_MAX]; - struct stat sb; - int i, ret; - - for (i = 0; i < 16; i++) { - snprintf(buf, FILENAME_MAX, "%s/%i/name", dri_base, i); - - snprintf(mmio_data.debugfs_path, FILENAME_MAX, - "%s/%i/", dri_base, i); - snprintf(mmio_data.debugfs_forcewake_path, FILENAME_MAX, - "%s/%i/i915_forcewake_user", dri_base, i); - - ret = stat(mmio_data.debugfs_forcewake_path, &sb); - if (ret) { - mmio_data.debugfs_path[0] = 0; - mmio_data.debugfs_forcewake_path[0] = 0; - } else - return 0; - } - - return -1; -} - -static int -get_forcewake_lock(void) -{ - return open(mmio_data.debugfs_forcewake_path, 0); -} - static void release_forcewake_lock(int fd) { @@ -184,16 +147,11 @@ intel_register_access_init(struct pci_device *pci_dev, int safe) /* Find where the forcewake lock is. Forcewake doesn't exist * gen < 6, but the debugfs should do the right things for us. */ - ret = find_debugfs_path("/sys/kernel/debug/dri"); - if (ret) { - ret = find_debugfs_path("/debug/dri"); - if (ret) { - fprintf(stderr, "Couldn't find path to dri/debugfs entry\n"); - fprintf(stderr, "warning: forcewake will not be handled\n"); - } + ret = igt_open_forcewake_handle(); + if (ret == -1) mmio_data.key = FAKEKEY; - } else - mmio_data.key = get_forcewake_lock(); + else + mmio_data.key = ret; mmio_data.inited++; return 0; diff --git a/tests/pm_pc8.c b/tests/pm_pc8.c index 5c74b2342e01..c672e809d04e 100644 --- a/tests/pm_pc8.c +++ b/tests/pm_pc8.c @@ -46,6 +46,7 @@ #include "intel_gpu_tools.h" #include "i915_drm.h" #include "igt_kms.h" +#include "igt_debugfs.h" #define MSR_PC8_RES 0x630 #define MSR_PC9_RES 0x631 @@ -1009,8 +1010,8 @@ static void debugfs_forcewake_user_subtest(void) disable_all_screens(&ms_data); igt_assert(wait_for_suspended()); - fd = open("/sys/kernel/debug/dri/0/i915_forcewake_user", O_RDONLY); - igt_require(fd); + fd = igt_open_forcewake_handle(); + igt_require(fd >= 0); if (has_runtime_pm) { igt_assert(wait_for_active());