From patchwork Wed Nov 13 15:49:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 11242161 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E18F1709 for ; Wed, 13 Nov 2019 15:49:39 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3698322CAD for ; Wed, 13 Nov 2019 15:49:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3698322CAD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D00A16ED7E; Wed, 13 Nov 2019 15:49:38 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 414F26ED70; Wed, 13 Nov 2019 15:49:31 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Nov 2019 07:49:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,300,1569308400"; d="scan'208";a="379263996" Received: from rosetta.fi.intel.com ([10.237.72.194]) by orsmga005.jf.intel.com with ESMTP; 13 Nov 2019 07:49:27 -0800 Received: by rosetta.fi.intel.com (Postfix, from userid 1000) id 7AF778402E8; Wed, 13 Nov 2019 17:49:17 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Wed, 13 Nov 2019 17:49:12 +0200 Message-Id: <20191113154913.8787-6-mika.kuoppala@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191113154913.8787-1-mika.kuoppala@linux.intel.com> References: <20191113154913.8787-1-mika.kuoppala@linux.intel.com> Subject: [Intel-gfx] [PATCH i-g-t 6/7] lib/igt_aux: Add helper to query suspend-to-mem modes 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: igt-dev@lists.freedesktop.org MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Imre Deak Add a helper to query the supported and currently selected suspend-to-mem modes. v2: - Fix for old kernels where the mem_sleep sysfs file didn't yet exist. Signed-off-by: Imre Deak --- lib/igt_aux.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_aux.h | 24 +++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 578f8579..f2cb3247 100644 --- a/lib/igt_aux.c +++ b/lib/igt_aux.c @@ -827,6 +827,87 @@ static uint32_t get_supported_suspend_states(int power_dir) return state_mask; } +static const char *suspend_to_mem_mode_name[] = { + [SUSPEND_TO_MEM_S2IDLE] = "s2idle", + [SUSPEND_TO_MEM_SHALLOW] = "shallow", + [SUSPEND_TO_MEM_DEEP] = "deep", +}; + +static uint32_t +get_supported_suspend_to_mem_modes(int power_dir, + enum igt_suspend_to_mem_mode *selected_mode) +{ + char *modes; + char *mode_name; + uint32_t mode_mask; + bool selected_found = false; + + /* + * Other modes than deep sleep were only introduced with the mem_sleep + * sysfs file. + */ + modes = igt_sysfs_get(power_dir, "mem_sleep"); + if (!modes) { + *selected_mode = SUSPEND_TO_MEM_DEEP; + return 1 << SUSPEND_TO_MEM_DEEP; + } + + mode_mask = 0; + for (mode_name = strtok(modes, " "); mode_name; + mode_name = strtok(NULL, " ")) { + enum igt_suspend_to_mem_mode mode; + bool selected = false; + + if (mode_name[0] == '[') { + char *e = &mode_name[strlen(mode_name) - 1]; + + igt_assert(!selected_found); + igt_assert(*e == ']'); + mode_name++; + *e = '\0'; + + selected = true; + } + + for (mode = SUSPEND_TO_MEM_S2IDLE; + mode < SUSPEND_TO_MEM_NUM; + mode++) + if (strcmp(mode_name, + suspend_to_mem_mode_name[mode]) == 0) + break; + igt_assert(mode < SUSPEND_TO_MEM_NUM); + mode_mask |= 1 << mode; + if (selected) { + selected_found = true; + if (selected_mode) + *selected_mode = mode; + } + } + + igt_assert(selected_found); + + free(modes); + + return mode_mask; +} + +/** + * igt_get_suspend_to_mem_mode: + * + * Returns the currently selected @igt_suspend_to_mem_mode. + */ +enum igt_suspend_to_mem_mode igt_get_suspend_to_mem_mode(void) +{ + int power_dir; + enum igt_suspend_to_mem_mode mode; + + igt_require((power_dir = open("/sys/power", O_RDONLY)) >= 0); + (void)get_supported_suspend_to_mem_modes(power_dir, &mode); + close(power_dir); + + return mode; +} + /** * igt_system_suspend_autoresume: * @state: an #igt_suspend_state, the target suspend state diff --git a/lib/igt_aux.h b/lib/igt_aux.h index 04d22904..7ccaa8c4 100644 --- a/lib/igt_aux.h +++ b/lib/igt_aux.h @@ -184,10 +184,34 @@ enum igt_suspend_test { SUSPEND_TEST_NUM, }; +/** + * igt_suspend_to_mem_mode: + * @SUSPEND_TO_MEM_S2IDLE: suspend to mem maps to @SUSPEND_STATE_FREEZE + * @SUSPEND_TO_MEM_SHALLOW: suspend to mem maps to @SUSPEND_STATE_STANDBY + * @SUSPEND_TO_MEM_DEEP: suspend to mem will target the ACPI S3 state + * + * The target system state when suspending to mem: + * - Suspending with @SUSPEND_STATE_MEM/@SUSPEND_TO_MEM_S2IDLE is equivalent to + * suspending with @SUSPEND_STATE_FREEZE. + * - Suspending with @SUSPEND_STATE_MEM/@SUSPEND_TO_MEM_SHALLOW is equivalent to + * suspending with @SUSPEND_STATE_STANDBY. + * - Suspending with @SUSPEND_STATE_MEM/@SUSPEND_TO_MEM_DEEP will target the + * ACPI S3 state. + */ +enum igt_suspend_to_mem_mode { + SUSPEND_TO_MEM_S2IDLE, + SUSPEND_TO_MEM_SHALLOW, + SUSPEND_TO_MEM_DEEP, + + /*< private >*/ + SUSPEND_TO_MEM_NUM, +}; + void igt_system_suspend_autoresume(enum igt_suspend_state state, enum igt_suspend_test test); void igt_set_autoresume_delay(int delay_secs); int igt_get_autoresume_delay(enum igt_suspend_state state); +enum igt_suspend_to_mem_mode igt_get_suspend_to_mem_mode(void); /* dropping priviledges */ void igt_drop_root(void);