Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3317623pxb; Sat, 9 Oct 2021 07:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzriW4n4npToi+UPLMecz5HL4HnCpaCApf0PQRocwOKBZc/COB9P8BPlBpu7Vt5aAeapbzW X-Received: by 2002:a05:6a00:1a02:b0:446:d18c:8e7e with SMTP id g2-20020a056a001a0200b00446d18c8e7emr15759705pfv.46.1633789440324; Sat, 09 Oct 2021 07:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633789440; cv=none; d=google.com; s=arc-20160816; b=c+VpjwbOdqjtmDEfdVpor5U6eTR/SazMVWMJ/oj1+5DyPbQ6JtLpjv0oPuSYMWI1hW Ad3EJLWAlgjFaW5PPK68E5MhG2kP3l2pehoQfu/nQlLWCFREqsjpd2gNyziUa6CkcuQ0 dw6K4FYncncDBLdVxbs7vuW8LSXVApvLRLwDKbO/2BPrKsTQb1LDnj2tF8f7wuXRxtLi nskZBWTOA206P+vdALPf0iKN4UXFIj+hd4hwvdXkbHZg6CRYiIlFbn0NaRDEPSNO8Fws GeWplVuNtD24izVxEpprwxfUYM7OflcRg4YrcvgJTjy2RB61U+tRpTepjH4LFuQnyr9P NJxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=PFxMRw3tMW/y7mvrf/FYw0N8AlOBnT4mN7rUlypeW8o=; b=ddCPzyJDNi+5g3+iu5gG1gGJecQmW6KZCe9mDmprVp/MrTPUZrB4hZv6sT+kmPLmbi jRuHgjartdCT6ioss1r4tCDM5vofx50DFM9/VcMPVCHFqWT2Uhm3UD0GEzKYxnwIOMXX RAy8ZbRqaBFUWVVswDDf9OXj6KQhoLMzWlY6ICS+o4p4A044aeBo7afVS258GbxmRm7R 7QqZSx8j7g6SfNVcRu912OTDi6lYcde8WmRVmmRPq7A4w4IdpOVssD+5rXDrR68yhc0F R0RuxEgLL0+gBLbTMzJN3hAYMxwvHk04ixjBL9CD9coFTBJNCa+5W+rejALBvLWOGBLU gapg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l16si3444111pgc.45.2021.10.09.07.23.47; Sat, 09 Oct 2021 07:24:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233743AbhJIOYP (ORCPT + 99 others); Sat, 9 Oct 2021 10:24:15 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:55750 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233093AbhJIOYO (ORCPT ); Sat, 9 Oct 2021 10:24:14 -0400 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 3.0.0) id d3d322a473f577f6; Sat, 9 Oct 2021 16:22:16 +0200 Received: from kreacher.localnet (89-77-51-84.dynamic.chello.pl [89.77.51.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 5020B66A6C1; Sat, 9 Oct 2021 16:22:15 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI , Mario Limonciello Cc: Linux PCI , Linux PM , LKML Subject: [PATCH] ACPI: scan: Release PM resources blocked by unused objects Date: Sat, 09 Oct 2021 16:22:09 +0200 Message-ID: <5507158.DvuYhMxLoT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 89.77.51.84 X-CLIENT-HOSTNAME: 89-77-51-84.dynamic.chello.pl X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvtddrvddtvddgjeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvvefgteeuteehkeduuedvudetleevffdtffdtjeejueekffetieekgfeigfehudenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecukfhppeekledrjeejrdehuddrkeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepkeelrdejjedrhedurdekgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmrghrihhordhlihhmohhntghivghllhhosegrmhgurdgtohhmpdhrtghpthhtoheplhhinhhugidqphgtihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthho pehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki On some systems the ACPI namespace contains device objects that are not used in certain configurations of the system. If they start off in the D0 power state configuration, they will stay in it until the system reboots, because of the lack of any mechanism possibly causing their configuration to change. If that happens, they may prevent some power resources from being turned off or generally they may prevent the platform from getting into the deepest low-power states thus causing some energy to be wasted. Address this issue by changing the configuration of unused ACPI device objects to the D3cold power state one after carrying out the ACPI-based enumeration of devices. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=214091 Link: https://lore.kernel.org/linux-acpi/20211007205126.11769-1-mario.limonciello@amd.com/ Reported-by: Mario Limonciello Signed-off-by: Rafael J. Wysocki --- Mario, I've changed acpi_dev_turn_off_if_unused() to check pnp.type.hardware_id instead of pnp.type.bus_address, because on some systems there are objects with both _ADR and _HID (which is against the spec) and the former is bogus. Please test this one, even though for PCI devices there should be no difference. Thanks! --- drivers/acpi/glue.c | 25 +++++++++++++++++++++++++ drivers/acpi/internal.h | 1 + drivers/acpi/scan.c | 6 ++++++ 3 files changed, 32 insertions(+) Index: linux-pm/drivers/acpi/scan.c =================================================================== --- linux-pm.orig/drivers/acpi/scan.c +++ linux-pm/drivers/acpi/scan.c @@ -2559,6 +2559,12 @@ int __init acpi_scan_init(void) } } + /* + * Make sure that power management resources are not blocked by ACPI + * device objects with no users. + */ + bus_for_each_dev(&acpi_bus_type, NULL, NULL, acpi_dev_turn_off_if_unused); + acpi_turn_off_unused_power_resources(); acpi_scan_initialized = true; Index: linux-pm/drivers/acpi/glue.c =================================================================== --- linux-pm.orig/drivers/acpi/glue.c +++ linux-pm/drivers/acpi/glue.c @@ -350,3 +350,28 @@ void acpi_device_notify_remove(struct de acpi_unbind_one(dev); } + +int acpi_dev_turn_off_if_unused(struct device *dev, void *not_used) +{ + struct acpi_device *adev = to_acpi_device(dev); + + /* + * Skip device objects with device IDs, because they may be in use even + * if they are not companions of any physical device objects. + */ + if (adev->pnp.type.hardware_id) + return 0; + + mutex_lock(&adev->physical_node_lock); + + /* + * Device objects without device IDs are not in use if they have no + * corresponding physical device objects. + */ + if (list_empty(&adev->physical_node_list)) + acpi_device_set_power(adev, ACPI_STATE_D3_COLD); + + mutex_unlock(&adev->physical_node_lock); + + return 0; +} Index: linux-pm/drivers/acpi/internal.h =================================================================== --- linux-pm.orig/drivers/acpi/internal.h +++ linux-pm/drivers/acpi/internal.h @@ -117,6 +117,7 @@ bool acpi_device_is_battery(struct acpi_ bool acpi_device_is_first_physical_node(struct acpi_device *adev, const struct device *dev); int acpi_bus_register_early_device(int type); +int acpi_dev_turn_off_if_unused(struct device *dev, void *not_used); /* -------------------------------------------------------------------------- Device Matching and Notification