From patchwork Fri May 13 11:15:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 9090401 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1FBA49F441 for ; Fri, 13 May 2016 11:15:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23ACD2021A for ; Fri, 13 May 2016 11:15:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B063B2024D for ; Fri, 13 May 2016 11:15:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752552AbcEMLPw (ORCPT ); Fri, 13 May 2016 07:15:52 -0400 Received: from mailout1.hostsharing.net ([83.223.95.204]:41330 "EHLO mailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752538AbcEMLPv (ORCPT ); Fri, 13 May 2016 07:15:51 -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 mailout1.hostsharing.net (Postfix) with ESMTPS id EC3FC1039814F; Fri, 13 May 2016 13:15:48 +0200 (CEST) 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 5A571603E03D; Fri, 13 May 2016 13:15:47 +0200 (CEST) X-Mailbox-Line: From 0d326baadc1f81e338ca628b64b330f1f84f889e Mon Sep 17 00:00:00 2001 Message-Id: <0d326baadc1f81e338ca628b64b330f1f84f889e.1463134231.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Fri, 13 May 2016 13:15:31 +0200 Subject: [PATCH v2 01/13] PCI: Recognize Thunderbolt devices To: linux-pci@vger.kernel.org, linux-pm@vger.kernel.org Cc: Andreas Noever Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 We're about to add a Thunderbolt port service in pcie/portdrv_core.c, allow runtime PM for Thunderbolt ports on Macs in pcie/portdrv_pci.c and allow power state D3 for Thunderbolt ports in pci.c. In each case we need to uniquely identify if a PCI device belongs to a Thunderbolt controller. We also have the need to detect presence of a Thunderbolt controller in drivers/platform/x86/apple-gmux.c because dual GPU MacBook Pros cannot switch external DP/HDMI ports between GPUs if they have Thunderbolt. Intel uses a Vendor-Specific Extended Capability (VSEC) with ID 0x1234 on all Thunderbolt devices which allows us to recognize them. Detect presence of this VSEC on device probe and cache it in a newly added is_thunderbolt bit in struct pci_dev which can then be queried by pci.c, portdrv, apple-gmux and possibly others. Signed-off-by: Lukas Wunner --- drivers/pci/pci.h | 2 ++ drivers/pci/probe.c | 17 +++++++++++++++++ include/linux/pci.h | 1 + 3 files changed, 20 insertions(+) diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 9730c47..14ceed7 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -6,6 +6,8 @@ #define PCI_FIND_CAP_TTL 48 +#define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ + extern const unsigned char pcie_link_speed[]; bool pcie_cap_has_lnkctl(const struct pci_dev *dev); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ae7daeb..57f175e 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1078,6 +1078,20 @@ void set_pcie_hotplug_bridge(struct pci_dev *pdev) pdev->is_hotplug_bridge = 1; } +static void parse_pcie_vendor_specific_caps(struct pci_dev *dev) +{ + int vsec = 0; + u32 header; + + while ((vsec = pci_find_next_ext_capability(dev, vsec, + PCI_EXT_CAP_ID_VNDR))) { + pci_read_config_dword(dev, vsec + PCI_VNDR_HEADER, &header); + if (dev->vendor == PCI_VENDOR_ID_INTEL && + PCI_VNDR_HEADER_ID(header) == PCI_VSEC_ID_INTEL_TBT) + dev->is_thunderbolt = 1; + } +} + /** * pci_ext_cfg_is_aliased - is ext config space just an alias of std config? * @dev: PCI device @@ -1230,6 +1244,9 @@ int pci_setup_device(struct pci_dev *dev) /* need to have dev->class ready */ dev->cfg_size = pci_cfg_space_size(dev); + /* need to have dev->cfg_size ready */ + parse_pcie_vendor_specific_caps(dev); + /* "Unknown power state" */ dev->current_state = PCI_UNKNOWN; diff --git a/include/linux/pci.h b/include/linux/pci.h index 7081db3f..267564d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -346,6 +346,7 @@ struct pci_dev { unsigned int is_virtfn:1; unsigned int reset_fn:1; unsigned int is_hotplug_bridge:1; + unsigned int is_thunderbolt:1; unsigned int __aer_firmware_first_valid:1; unsigned int __aer_firmware_first:1; unsigned int broken_intx_masking:1;