Received: by 2002:a05:6a10:87d6:0:0:0:0 with SMTP id g22csp289292pxr; Sun, 10 Apr 2022 15:07:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxu2SOY8Pd1VaeEOhIbYRsyw0rxfwwWhQO/QB3LBiU5wN/B1b6dgrnytLeSWrIfDSh1adGX X-Received: by 2002:aa7:888b:0:b0:4fb:10e1:8983 with SMTP id z11-20020aa7888b000000b004fb10e18983mr29184656pfe.62.1649628465539; Sun, 10 Apr 2022 15:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649628465; cv=none; d=google.com; s=arc-20160816; b=LVudNmLRtLJbk0Tiy/Wa0xJgf97eYlc300sbFeDBrslcd2EMI95Sxwoz3FviaRv+En 4cNKQKbxhKeSpkuOBoDaxSRyfqmfIbD4+m9NJh+MRGmHLBaaVi4Xywe6SloUZRUGLLr1 3p7D5SHTK1rX41eX3Lrkjfu6+tTiYoAfe13HrfUrHejupeE2mjPpPrlqoCykEBoeD2tO KJR8qM5mVwnNBnsUobEb/1V9NcVooUM+P68x3oojgO7x53UKb4je6G66SpqzHpsAPPQg sHDmTOvpjPD6GTnF8a1qbSzLpVk++JAsGuMTxFF/wwzP0tspcNQn2g+P+eyN1mVpGkib Q+gw== 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=Kfxr7/hKJzj+Y0l5fPGh2p5yP+ZwXw9KIu14S4CH0Zc=; b=LrMIHHyIOzECHootpZJSQ6vsBVAYDOO4Yu9pNWSLbT6kdP04i+C15t5PGcQftnYcg5 wCrznHiRtEXEdtpb4TV+6zcU9VEJ+h+XNeLXDsxsEcPC1ZVJFRoBd8fMCx1/+ie3ooVu 3YCx8TqaxN+h7hZ5sKYjAwPQh9MXPifhH22bxepKFXR8Pmgn0InL3TCdDVTvp38wYpLO l1kpYipIopS28O+DizZih4YUBPtPjxAmpeOz0lraqISwmlDw/USETOxkCjmkSleXwL/G 8zwQggw46DA2sjNkOLOj/qnDVXbUgdWskHprlLkBDEsM5PKw+2RPw4/Y5cutR4WUZTOq ivsw== 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 x21-20020a17090300d500b00153b2d16621si6339618plc.553.2022.04.10.15.07.31; Sun, 10 Apr 2022 15:07:45 -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 S242099AbiDINbE (ORCPT + 99 others); Sat, 9 Apr 2022 09:31:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241884AbiDINbD (ORCPT ); Sat, 9 Apr 2022 09:31:03 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA46BADD5F; Sat, 9 Apr 2022 06:28:54 -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 1352328eb26ee335; Sat, 9 Apr 2022 15:28:52 +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 C220366BCD0; Sat, 9 Apr 2022 15:28:51 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PCI Cc: Linux PM , LKML , Bjorn Helgaas , Mika Westerberg Subject: [PATCH v1 7/7] PCI/PM: Rearrange pci_set_power_state() Date: Sat, 09 Apr 2022 15:28:38 +0200 Message-ID: <1938958.usQuhbGJ8B@kreacher> In-Reply-To: <4419002.LvFx2qVVIh@kreacher> References: <4419002.LvFx2qVVIh@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: gggruggvucftvghtrhhoucdtuddrgedvvddrudekvddgfeelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvjeelgffhiedukedtleekkedvudfggefhgfegjefgueekjeelvefggfdvledutdenucfkphepkeelrdejjedrhedurdekgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekledrjeejrdehuddrkeegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphgtihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehhvghlghgrrghssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihhkrgdrfigvshht vghrsggvrhhgsehlihhnuhigrdhinhhtvghlrdgtohhm 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 --- 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 @@ -1438,19 +1438,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; }