Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp826171lfv; Tue, 12 Apr 2022 06:20:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxryHNgWKIwCy0ZddrCdD56e0BxLisA0XIOVz2IlYFUyE4Ze5S93gFfWdkjyVfzy+paz9a+ X-Received: by 2002:a05:6a00:1890:b0:505:c046:6bff with SMTP id x16-20020a056a00189000b00505c0466bffmr10512250pfh.28.1649769632655; Tue, 12 Apr 2022 06:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649769632; cv=none; d=google.com; s=arc-20160816; b=Vd6OBRJHmaCV1bQkIwieKctmeGX5gtCV3m7MOB0oihHlkULkvWWqZu0M1bk7E7FypB 6oqxy1C3sbsAZILObJ8fIPXVAXH8NiW7FBjeuvO7thCrKByebv6TOOWuwlaKEw5jKhFW H6qm/30n4tvZQKyFJuSV4hBtjkvwRyWJYJIs8alLIGSKRVCX769hPRya6XdqvdyOoGC1 geEOfbBtyv/Qvpf2PYvogVk83AA/eE20H8o7mSZTTjBrZW3qTDOIVjBBkxKceLWITp+A vzFhKSNVE+kN24a8vO2B/JBDCFSDnVpZ1mpgTbFFN0RWbyErXgQFCrjsJr8gNwcqcbYd +n0A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PlhDmcpMZnyy6AtBvNO8hu5+CXDQTBDN+aIUhOxRgqs=; b=MrxC4YIOVJY89IB+lQAdppGLaA6tVVu50y/r8Mu94/WU3gSWhf9aFbYClOROf4Ru6j irPu5cgrh1mSmRNccJ5D9X4FxuAKRBG4JuKnzgSL71iuVj7vKUcXHXEL7RGZ1pQ1DVYC ub37KNC88c2OdatNIR9EfkIKC2t5NnfRJpU9osnLaMSPnvqCQV1XCGuL8MoE24IPXhX0 abYIi6uT2zxDyHVmrOSRwNFPrKzac26jtBuWxlK9HdNjgt1Dy5tNXGJUBd6mHUlFuaxt YA5/C+qE7oS8bbRQzi2eKsJ8++nbapq2mPRcjMVLQ64v95mss0QtSvHWJiU1ywkXb8Xu JdkQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a17090341c500b00158745f32c1si4744567ple.171.2022.04.12.06.20.11; Tue, 12 Apr 2022 06:20:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347334AbiDKOgc (ORCPT + 99 others); Mon, 11 Apr 2022 10:36:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347322AbiDKOgS (ORCPT ); Mon, 11 Apr 2022 10:36:18 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 517FCB6A; Mon, 11 Apr 2022 07:34:04 -0700 (PDT) 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 5.0.0) id 396842a589674701; Mon, 11 Apr 2022 16:34:02 +0200 Received: from kreacher.localnet (unknown [213.134.175.113]) (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 03E3066BDED; Mon, 11 Apr 2022 16:34:01 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PCI Cc: Linux PM , LKML , Bjorn Helgaas , Mika Westerberg Subject: [PATCH v2 7/9] PCI/PM: Rearrange pci_set_power_state() Date: Mon, 11 Apr 2022 16:30:00 +0200 Message-ID: <21446164.EfDdHjke4D@kreacher> In-Reply-To: <11975904.O9o76ZdvQC@kreacher> References: <4419002.LvFx2qVVIh@kreacher> <11975904.O9o76ZdvQC@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.175.113 X-CLIENT-HOSTNAME: 213.134.175.113 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvvddrudekiedgjeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvjeelgffhiedukedtleekkedvudfggefhgfegjefgueekjeelvefggfdvledutdenucfkphepvddufedrudefgedrudejhedruddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvudefrddufeegrddujeehrdduudefpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphgtihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehhvghlghgrrghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehm ihhkrgdrfigvshhtvghrsggvrhhgsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki The part of pci_set_power_state() related to transitions into low-power states is unnecessary convoluted, so clearly divide it into the D3cold special case and the general case covering all of the other states. Also fix a potential issue with calling pci_bus_set_current_state() to set the current state of all devices on the subordinate to D3cold without checking if the power state of the parent bridge has really changed to D3cold. Signed-off-by: Rafael J. Wysocki --- v1 -> v2: No changes. --- drivers/pci/pci.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) Index: linux-pm/drivers/pci/pci.c =================================================================== --- linux-pm.orig/drivers/pci/pci.c +++ linux-pm/drivers/pci/pci.c @@ -1431,19 +1431,25 @@ int pci_set_power_state(struct pci_dev * if (state >= PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3)) return 0; - /* - * To put device in D3cold, we put device into D3hot in native - * way, then put device into D3cold with platform ops - */ - error = pci_set_low_power_state(dev, state > PCI_D3hot ? - PCI_D3hot : state); + if (state == PCI_D3cold) { + /* + * To put the device in D3cold, put it into D3hot in the native + * way, then put it into D3cold using platform ops. + */ + error = pci_set_low_power_state(dev, PCI_D3hot); - if (pci_platform_power_transition(dev, state)) - return error; + if (pci_platform_power_transition(dev, PCI_D3cold)) + return error; - /* Powering off a bridge may power off the whole hierarchy */ - if (state == PCI_D3cold) - pci_bus_set_current_state(dev->subordinate, PCI_D3cold); + /* Powering off a bridge may power off the whole hierarchy */ + if (dev->current_state == PCI_D3cold) + pci_bus_set_current_state(dev->subordinate, PCI_D3cold); + } else { + error = pci_set_low_power_state(dev, state); + + if (pci_platform_power_transition(dev, state)) + return error; + } return 0; }