From patchwork Mon Jul 23 11:46:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A96213BB for ; Mon, 23 Jul 2018 11:47:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE8B428640 for ; Mon, 23 Jul 2018 11:47:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2DDA2866C; Mon, 23 Jul 2018 11:47:12 +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 875E428640 for ; Mon, 23 Jul 2018 11:47:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B08C06E298; Mon, 23 Jul 2018 11:47:10 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2C8D66E15B for ; Mon, 23 Jul 2018 11:47:05 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id r16-v6so372614wrt.11 for ; Mon, 23 Jul 2018 04:47:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tK6h/trZ+BTVHsoymSwpp5+3Py92kDjBl8Q3bApQ7Bs=; b=LhLJXCi4ursATTQf63Cz680LHsMrVQn8yA6HqMgZBWSICCNEvGUgGQfmDXEdV5Oztd c6tZu1ZyFJlErbsFhK4D7PmERlNX/vKJKjjXC6orkGFkAv5Z/Qo2aOKee+9x9qvgXCI9 QLX/YPKydRoo+GLiQjhkYMDLjblJLPVSLz2HdS47eCBdCRoLiP1VXbRDiJqdFbpDK2rl kfEBzMDEue//xxmJyj8xdsPErwhlYSsIUJZI7z/IVQMChgYrZSaf0xxnYDzLopkken4m aQY0fjUbdNs/1qN+2aM9JisHTvsof21sXuHBKJRFic7cYQhopyhJ3AInTGuLr+XoXRMc 1oYw== X-Gm-Message-State: AOUpUlHfagajsaQ7ne1iUjrFp1S0sLjMyKtytBFjQ+EG7JmqzKl1Qs8M Zof5TPJNQW4v+Umgp0P41xiCxQ== X-Google-Smtp-Source: AAOMgpfafueiGU7orT/8P4mUlmno5PDbCT13JOhW3NGdr5qxplIbx5AnsUmNVQR3gReEe3qCEx/+Tw== X-Received: by 2002:adf:8405:: with SMTP id 5-v6mr8628783wrf.167.1532346423853; Mon, 23 Jul 2018 04:47:03 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id l14-v6sm23658407wrw.65.2018.07.23.04.47.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 04:47:03 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 12:46:56 +0100 Message-Id: <20180723114658.13025-2-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> References: <20180723114658.13025-1-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 2/4] lib/igt_pm: Find HDA device when attempting to enable runtime PM 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: intel-gfx@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Tvrtko Ursulin HDA audio device can be present at various PCI paths on different systems which the existing code did not account for. Furthermore the failure to enable runtime PM was silent leaving callers in the dark. Improve it by auto-locating the PCI path and logging a warning when something is not as expected. Signed-off-by: Tvrtko Ursulin --- lib/igt_pm.c | 77 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 6f3b0a2d897d..a4c0cf335f6d 100644 --- a/lib/igt_pm.c +++ b/lib/igt_pm.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "drmtest.h" #include "igt_pm.h" @@ -64,6 +65,7 @@ enum { #define MAX_POLICY_STRLEN strlen(MAX_PERFORMANCE_STR) static char __igt_pm_audio_runtime_power_save[64]; +static const char * __igt_pm_audio_runtime_control_path; static char __igt_pm_audio_runtime_control[64]; static int __igt_pm_audio_restore_runtime_pm(void) @@ -86,7 +88,7 @@ static int __igt_pm_audio_restore_runtime_pm(void) close(fd); - fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_WRONLY); + fd = open(__igt_pm_audio_runtime_control_path, O_WRONLY); if (fd < 0) return errno; @@ -130,36 +132,77 @@ static void strchomp(char *str) */ void igt_pm_enable_audio_runtime_pm(void) { + char *path = NULL; + struct dirent *de; + DIR *dir; int fd; /* Check if already enabled. */ if (__igt_pm_audio_runtime_power_save[0]) return; - fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR); - if (fd >= 0) { - igt_assert(read(fd, __igt_pm_audio_runtime_power_save, - sizeof(__igt_pm_audio_runtime_power_save)) > 0); - strchomp(__igt_pm_audio_runtime_power_save); - igt_install_exit_handler(__igt_pm_audio_runtime_exit_handler); - igt_assert_eq(write(fd, "1\n", 2), 2); - close(fd); - } - fd = open("/sys/bus/pci/devices/0000:00:03.0/power/control", O_RDWR); - if (fd >= 0) { - igt_assert(read(fd, __igt_pm_audio_runtime_control, - sizeof(__igt_pm_audio_runtime_control)) > 0); - strchomp(__igt_pm_audio_runtime_control); - igt_assert_eq(write(fd, "auto\n", 5), 5); - close(fd); + dir = opendir("/sys/bus/pci/drivers/snd_hda_intel"); + if (!dir) + goto err; + + while ((de = readdir(dir))) { + const char *prefix = "/sys/bus/pci/devices/"; + const char *suffix = "/power/control"; + const char *match = "0000:00:"; + + if (strncmp(de->d_name, match, strlen(match))) + continue; + + path = malloc(strlen(prefix) + + strlen(de->d_name) + + strlen(suffix) + + 1); + if (!path) + goto err; + + strcpy(path, prefix); + strcat(path, de->d_name); + strcat(path, suffix); + + igt_debug("Audio device PCI path is %s\n", path); } + if (!path) + goto err; + + fd = open("/sys/module/snd_hda_intel/parameters/power_save", O_RDWR); + if (fd < 0) + goto err; + + igt_assert(read(fd, __igt_pm_audio_runtime_power_save, + sizeof(__igt_pm_audio_runtime_power_save)) > 0); + strchomp(__igt_pm_audio_runtime_power_save); + igt_install_exit_handler(__igt_pm_audio_runtime_exit_handler); + igt_assert_eq(write(fd, "1\n", 2), 2); + close(fd); + + fd = open(path, O_RDWR); + if (fd < 0) + goto err; + + igt_assert(read(fd, __igt_pm_audio_runtime_control, + sizeof(__igt_pm_audio_runtime_control)) > 0); + strchomp(__igt_pm_audio_runtime_control); + igt_assert_eq(write(fd, "auto\n", 5), 5); + close(fd); + __igt_pm_audio_runtime_control_path = path; + igt_debug("Saved audio power management as '%s' and '%s'\n", __igt_pm_audio_runtime_power_save, __igt_pm_audio_runtime_control); /* Give some time for it to react. */ sleep(1); + + return; + +err: + igt_warn("Failed to enable audio runtime PM! (%d)", errno); } /**