From patchwork Mon Jul 23 12:46:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tvrtko Ursulin X-Patchwork-Id: 10540159 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 26E7213BB for ; Mon, 23 Jul 2018 12:47:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 149EA2847D for ; Mon, 23 Jul 2018 12:47:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 08DF5286A1; Mon, 23 Jul 2018 12:47:01 +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 8887A2847D for ; Mon, 23 Jul 2018 12:46:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8841E6E43E; Mon, 23 Jul 2018 12:46:57 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id E96AD6E43E for ; Mon, 23 Jul 2018 12:46:55 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id s14-v6so1092317wmc.1 for ; Mon, 23 Jul 2018 05:46:55 -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=nQJijD17Q/NJ04ZiM+yZWEbBNSSqmGCemrHNQGCQYM0=; b=iVPutnsyzmuU/tbD9FgobYs400N5KWUy3f1u8mpACscZ/Vgyi8o1W39ZNE+ANZJNr4 y/VFqSAGMAvEKL9R2ucGndZy6cH0HIDdj+IK+clpu7eoWxpjFa5b6Cqf2FjqUDteXbUa gVQz16RZFZhx/o5rz5LV6TWG7/5Ababy2X47P5/zVSK3cx+lqTsFr3UhGu8FCRa8rTrg 3e+ZGwTPVaWpR6oDxZl6gg7Cbhm/Kor2pwwz4jT7CcBTDOPF6G+ooJbzShWBazsvajV4 LpaNMrGAkKuMgRcwbDBuSiZAEch/0QkUtygxeceEC/zddLKZdGcgZJKrNdaDO/COeLKf lvew== X-Gm-Message-State: AOUpUlHnc4m5qFlqNt4OjmmigI4gBZSRgN0Bqw/wO2aehXmcSlAcmmNB zHB0E2ocDJRKrfxgse+k/0Jcsw== X-Google-Smtp-Source: AAOMgpdcIg+zQddANJ9FXWMKJInbIgBnuZapkcotVHlduCvs4nGc9sOnbMLBLK9uwbL94Rm0M9yihQ== X-Received: by 2002:a1c:9042:: with SMTP id s63-v6mr7023087wmd.91.1532350014577; Mon, 23 Jul 2018 05:46:54 -0700 (PDT) Received: from localhost.localdomain ([95.146.151.144]) by smtp.gmail.com with ESMTPSA id s16-v6sm8134429wrq.20.2018.07.23.05.46.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Jul 2018 05:46:54 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: igt-dev@lists.freedesktop.org Date: Mon, 23 Jul 2018 13:46:49 +0100 Message-Id: <20180723124649.13719-1-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723114658.13025-2-tvrtko.ursulin@linux.intel.com> References: <20180723114658.13025-2-tvrtko.ursulin@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t v2 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. 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..26150fdfedf5 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) + return; + + 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); } /**