From patchwork Fri Jan 4 19:10:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1934321 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 95A09402E1 for ; Fri, 4 Jan 2013 19:11:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754655Ab3ADTKx (ORCPT ); Fri, 4 Jan 2013 14:10:53 -0500 Received: from mail-ee0-f74.google.com ([74.125.83.74]:44929 "EHLO mail-ee0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754528Ab3ADTKo (ORCPT ); Fri, 4 Jan 2013 14:10:44 -0500 Received: by mail-ee0-f74.google.com with SMTP id t10so1049343eei.1 for ; Fri, 04 Jan 2013 11:10:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=6hXs2Ral0hoktRfz8nfihsgPIkwChr4lPI2/ZjQKp6A=; b=RgRhXg0oqAw+9RNBCUZG7h++9O1w7yYkw9IqanqugyY5jee21dLof83jagA7543kDy jyrsNiV7i8tsievdxD5WPjWS78wIVO5jZ1MsRn/3Dy35c3ifJUw+Ip2Aiqjln/+7hih0 9Q9VonD7fQw1MGlIorC+0glf1Ry9u8ZasMooOqUjmRkjodD+TIqsOckRg7HJmjawlGxl OB0QFXtML66MbX0/YEv4J/HY1Ix0L+cEtNLT8CyyoQ52NcexuBHqxo7vrpjbn12yX9zw CQLHBni6/wIpPYX/R0FjtPP0XVxo7UbdxMWhbm3Cj2Xr+i14/wSuWXVquy49A+gnALQ6 52rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:subject:to:from:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=6hXs2Ral0hoktRfz8nfihsgPIkwChr4lPI2/ZjQKp6A=; b=n2WybqkpZKDY5MsrROVkC0PDEGje/IqkFTdFpibrksXLXa+08L1Z5VfrjoD/ggV+4q uXs81MPKBRDriYYlu895UzzYN2wqoLbAZYrEj3pjiu9A7hJyJAQ87xztQFhBnLQerMlH v8iYWRJCWRVQMM+9L0cjrGPoQSfXQHukGeOLRKjnZZmqvUSEy0SK0yrbvOSlrGhULFUI +KGaePhsooWIrjHqi7+jQ3TeSnpLynJyuYPA+e7hImmkfh9/YwOUBzsOwbbammY5OVIz WgNevF/Yyfn341WCX0VcnzuQVrLdmm9hnnPSB7uMEzLI53NUV0QaJWZQFYSh4BfVDUxj jpew== X-Received: by 10.14.224.201 with SMTP id x49mr67860011eep.5.1357326643312; Fri, 04 Jan 2013 11:10:43 -0800 (PST) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id z44si18858153een.0.2013.01.04.11.10.43 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 04 Jan 2013 11:10:43 -0800 (PST) Received: from bhelgaas.mtv.corp.google.com (bhelgaas.mtv.corp.google.com [172.17.131.112]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id E662620004E; Fri, 4 Jan 2013 11:10:42 -0800 (PST) Received: from bhelgaas.mtv.corp.google.com (unknown [IPv6:::1]) by bhelgaas.mtv.corp.google.com (Postfix) with ESMTP id 49A0C18016C; Fri, 4 Jan 2013 11:10:42 -0800 (PST) Subject: [PATCH 3/3] drm/pci: Use PCI Express Capability accessors To: David Airlie From: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, dri-devel@lists.freedesktop.org, Alex Deucher , Betty Dall , Lucas Kannebley Tavares , Ilija Hadzic Date: Fri, 04 Jan 2013 12:10:42 -0700 Message-ID: <20130104191042.4586.39304.stgit@bhelgaas.mtv.corp.google.com> In-Reply-To: <20130104190833.4586.16520.stgit@bhelgaas.mtv.corp.google.com> References: <20130104190833.4586.16520.stgit@bhelgaas.mtv.corp.google.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm8VkJ/Yy1sT0bxZY0K8P9p7759n/jn0Uw2IE8MIppPI8B1AnXR9K/C7dtgFBWKFJz+KimbLsT1pwWP0+z3TxLULNvxo0EZqkr+qmZkF8Vpwm5Uuwrxu0obkX5YKc+0k66q1tNfxBO81nAAXvWgWW7sBZbcwOFr2mLKA31wcdx6LuNxfAuqxYrjdNb8O+yCKk3tOOC1z12N5Qsi+VMfRw72Hq7mKw== Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Use PCI Express Capability access functions to simplify this code a bit. For non-PCIe devices or pre-PCIe 3.0 devices that don't implement the Link Capabilities 2 register, pcie_capability_read_dword() reads a zero. Since we're only testing whether the bits we care about are set, there's no need to mask out the other bits we *don't* care about. Signed-off-by: Bjorn Helgaas --- drivers/gpu/drm/drm_pci.c | 21 +++++---------------- 1 files changed, 5 insertions(+), 16 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c index 50e26f2..86102a0 100644 --- a/drivers/gpu/drm/drm_pci.c +++ b/drivers/gpu/drm/drm_pci.c @@ -469,41 +469,30 @@ EXPORT_SYMBOL(drm_pci_exit); int drm_pcie_get_speed_cap_mask(struct drm_device *dev, u32 *mask) { struct pci_dev *root; - int pos; - u32 lnkcap = 0, lnkcap2 = 0; + u32 lnkcap, lnkcap2; *mask = 0; if (!dev->pdev) return -EINVAL; - if (!pci_is_pcie(dev->pdev)) - return -EINVAL; - root = dev->pdev->bus->self; - pos = pci_pcie_cap(root); - if (!pos) - return -EINVAL; - /* we've been informed via and serverworks don't make the cut */ if (root->vendor == PCI_VENDOR_ID_VIA || root->vendor == PCI_VENDOR_ID_SERVERWORKS) return -EINVAL; - pci_read_config_dword(root, pos + PCI_EXP_LNKCAP, &lnkcap); - pci_read_config_dword(root, pos + PCI_EXP_LNKCAP2, &lnkcap2); - - lnkcap &= PCI_EXP_LNKCAP_SLS; - lnkcap2 &= 0xfe; + pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap); + pcie_capability_read_dword(root, PCI_EXP_LNKCAP2, &lnkcap2); - if (lnkcap2) { /* PCIE GEN 3.0 */ + if (lnkcap2) { /* PCIe r3.0-compliant */ if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB) *mask |= DRM_PCIE_SPEED_25; if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB) *mask |= DRM_PCIE_SPEED_50; if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB) *mask |= DRM_PCIE_SPEED_80; - } else { + } else { /* pre-r3.0 */ if (lnkcap & PCI_EXP_LNKCAP_SLS_2_5GB) *mask |= DRM_PCIE_SPEED_25; if (lnkcap & PCI_EXP_LNKCAP_SLS_5_0GB)