From patchwork Wed Mar 16 14:50:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 8601271 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 87BF1C0554 for ; Wed, 16 Mar 2016 14:49:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B9FC20212 for ; Wed, 16 Mar 2016 14:49:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 82980202FE for ; Wed, 16 Mar 2016 14:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935076AbcCPOtT (ORCPT ); Wed, 16 Mar 2016 10:49:19 -0400 Received: from mailout3.hostsharing.net ([176.9.242.54]:56636 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933471AbcCPOtS (ORCPT ); Wed, 16 Mar 2016 10:49:18 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout3.hostsharing.net (Postfix) with ESMTPS id 1B720101E3640; Wed, 16 Mar 2016 15:49:15 +0100 (CET) Received: from localhost (6-38-90-81.adsl.cmo.de [81.90.38.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 3B33D603E02F; Wed, 16 Mar 2016 15:49:13 +0100 (CET) X-Mailbox-Line: From 4560ddb26a2bb15eeaf8eab565ac41c35e36d092 Mon Sep 17 00:00:00 2001 Message-Id: From: Lukas Wunner Date: Wed, 16 Mar 2016 15:50:35 +0100 Subject: [RFC 0/4] Runtime pm for thunderbolt.ko To: linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: Andreas Noever , Matthew Garrett Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This series adds runtime pm to the Thunderbolt driver for Macs. Patches 1 to 3 are just preparatory material, the real action is in patch 4. The series fixes (at least partially) a power regression introduced in Linux 3.17 by 7bc5a2bad0b8 ("ACPI: Support _OSI("Darwin") correctly"): https://bugzilla.kernel.org/show_bug.cgi?id=92111 It would be good if someone could test it with Cactus Ridge or Falcon Ridge. So far I've only tested it with the Light Ridge controller built into older Macs. I've also pushed the patches to GitHub to ease reviewing: https://github.com/l1k/linux/commits/thunderbolt_runpm_v1 I'm posting this as an RFC to get feedback in particular on 2 issues: (1) There are 3 drivers interacting with the Thunderbolt controller: thunderbolt.ko (controls the NHI, Native Host Interface), pcieport (controls the upstream bridge) and pciehp (controls the downstream bridges). The Linux pm model assumes that a child cannot resume before its parent, yet my implementation lets the NHI govern runtime pm and the NHI is a child. So this is a total violation of the Linux pm model. There's an ascii drawing in patch 4 which should make this clearer. To let the parent (upstream bridge) govern runtime pm, I could maybe write a pcieport service driver specifically for Thunderbolt which governs the runtime pm (but does nothing else). However pcieport currently has no runtime pm (yes I know Mika is on it) and a service driver lacks the necessary runtime pm callbacks. So with pcieport the way it is now, that solution isn't attainable. (2) When the system goes to sleep, it shouldn't wake the controller from runtime suspend. Waking the controller takes 2 seconds and costs energy. The ->prepare callback must return 1 to achieve that. However pci_pm_prepare() doesn't do so as it can't deal properly with devices that can be runtime suspended to D3cold even though they're not power manageable by the platform. This could be fixed with something like this: But there's another problem: pci_pm_complete() wakes up the device after resuming from system sleep and there's no need to do that. The controller may stay asleep and will be woken on hotplug by a GPE. We could fix that with an additional flag in struct dev_pm_info. Meanwhile the only solution I could find was a PCI enable fixup which overrides pci_pm_prepare() and pci_pm_complete() using a power domain. That's fairly kludgy, I can never remove and free the allocated struct dev_pm_domain since there is no PCI remove fixup section. It's also not possible to bail out of the ->probe callback if allocation fails since the PCI enable fixup does not allow return values to be passed back. Thanks, Lukas Lukas Wunner (4): PCI: Add Thunderbolt device IDs thunderbolt: Fix typos and magic number thunderbolt: Move pm code to separate file thunderbolt: Support runtime pm drivers/pci/quirks.c | 51 +++++++- drivers/thunderbolt/Kconfig | 2 +- drivers/thunderbolt/Makefile | 3 +- drivers/thunderbolt/ctl.c | 2 +- drivers/thunderbolt/eeprom.c | 2 +- drivers/thunderbolt/nhi.c | 45 ++----- drivers/thunderbolt/nhi.h | 3 + drivers/thunderbolt/power.c | 288 ++++++++++++++++++++++++++++++++++++++++++ drivers/thunderbolt/power.h | 17 +++ drivers/thunderbolt/switch.c | 28 ++-- drivers/thunderbolt/tb.c | 8 +- drivers/thunderbolt/tb.h | 2 +- drivers/thunderbolt/tb_regs.h | 2 +- include/linux/pci_ids.h | 18 +++ 14 files changed, 413 insertions(+), 58 deletions(-) create mode 100644 drivers/thunderbolt/power.c create mode 100644 drivers/thunderbolt/power.h --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1918,7 +1918,8 @@ EXPORT_SYMBOL(pci_wake_from_d3); */ static pci_power_t pci_target_state(struct pci_dev *dev) { - pci_power_t target_state = PCI_D3hot; + pci_power_t target_state = + (dev->current_state == PCI_D3cold) ? PCI_D3cold : PCI_D3hot; if (platform_pci_power_manageable(dev)) { /*