From patchwork Mon Jul 23 15:31:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540519 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 109BE17FD for ; Mon, 23 Jul 2018 15:31:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F207028B7D for ; Mon, 23 Jul 2018 15:31:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E50FF28C95; Mon, 23 Jul 2018 15:31:46 +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 33A2928B7D for ; Mon, 23 Jul 2018 15:31:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8F8A06E49D; Mon, 23 Jul 2018 15:31:45 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 826E46E47E for ; Mon, 23 Jul 2018 15:31:43 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id q10-v6so1150129wrd.4 for ; Mon, 23 Jul 2018 08:31:43 -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=QDV5rcJGKcfmy1RJPnv9S8wqcwa6ljYZSKp1Eu+5rP4=; b=a2GdoMa0FsmH/8mLSVjx6X7Ko8sT4MTljcaFftcpEBZbohFBp6xSDIE4Xr/DEaCb05 rCXm8qRPG3DhuzxjWrIBHBHEy/64EBJ+v1YSuxeMMMXSrXK6kI/6cIKUhrq6bJ1GX5If KcDsO2q6cXPZli0v8PfE7po6slTonvZLrks3yXsXcg1KNWT5kv2LInJO7Q7v/Op29D5z VuwcNxOm+6qzNYdeulBUmCuRntAwWQWiRY92yovVBE0x74I6eskkui4Zx/jkPoYByrSv 2lVw4fsCWuafV9qyViGJrbC9jvNr1WcVkqiLNPDML7x1egbhs+FNYyo/Y1VxBU7PglSe aYQA== X-Gm-Message-State: AOUpUlGoLiqEmIygldl2jRZPLHJ0HNeQx4+Fx9swPvu4DVSu5aXwXHhr GHuilrvCYqBqMjwrK4bPKsjeFQ== X-Google-Smtp-Source: AAOMgpeRLwbwCahcKegnUuqzLu//M42iYjAASqcW9nmLRetZIHtMJDscBGnWM6Q+rHeNtE6oESYD/Q== X-Received: by 2002:a5d:4985:: with SMTP id r5-v6mr8973585wrq.116.1532359902098; Mon, 23 Jul 2018 08:31:42 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id f12-v6sm8556088wrg.88.2018.07.23.08.31.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 08:31:41 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 16:31:36 +0100 Message-Id: <20180723153136.15531-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <153235048851.26238.17694902495417158505@skylake-alporthouse-com> References: <153235048851.26238.17694902495417158505@skylake-alporthouse-com> Subject: [Intel-gfx] [PATCH i-g-t v3 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. v2: * If there is no audio hw/driver there is no failure. v3 * Comment. * Skip non-symlinks. * Free path on failure and restore. * Simplify with asprintf. (Chris Wilson) Signed-off-by: Tvrtko Ursulin --- lib/igt_pm.c | 76 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/lib/igt_pm.c b/lib/igt_pm.c index 6f3b0a2d897d..fd2880c9df11 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 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; @@ -100,6 +102,8 @@ static int __igt_pm_audio_restore_runtime_pm(void) close(fd); __igt_pm_audio_runtime_power_save[0] = 0; + free(__igt_pm_audio_runtime_control_path); + __igt_pm_audio_runtime_control_path = NULL; return 0; } @@ -130,36 +134,74 @@ 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) + return; + + /* Find PCI device claimed by snd_hda_intel. */ + while ((de = readdir(dir))) { + const char *match = "0000:00:"; + + if (de->d_type != DT_LNK || + strncmp(de->d_name, match, strlen(match))) + continue; + + igt_assert(asprintf(&path, + "/sys/bus/pci/devices/%s/power/control", + de->d_name)); + + igt_debug("Audio device PCI path is %s\n", path); + + break; } + 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); + free(path); } /**