From patchwork Thu Apr 2 21:10:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sostalle X-Patchwork-Id: 6151641 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@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 623C7BF4A6 for ; Thu, 2 Apr 2015 21:11:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 93051203A9 for ; Thu, 2 Apr 2015 21:11:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F1332039D for ; Thu, 2 Apr 2015 21:11:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751139AbbDBVLk (ORCPT ); Thu, 2 Apr 2015 17:11:40 -0400 Received: from mga03.intel.com ([134.134.136.65]:46027 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751780AbbDBVLj (ORCPT ); Thu, 2 Apr 2015 17:11:39 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 02 Apr 2015 14:11:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,512,1422950400"; d="scan'208";a="550360601" Received: from dev.jf.intel.com ([134.134.147.26]) by orsmga003.jf.intel.com with ESMTP; 02 Apr 2015 14:11:39 -0700 From: "Sean O. Stalley" To: bhelgaas@google.com, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Sean O. Stalley" Subject: [PATCH] Read ID & Pointer from PCI Capabilities List in 1 call Date: Thu, 2 Apr 2015 14:10:19 -0700 Message-Id: <1428009019-19563-1-git-send-email-sean.stalley@intel.com> X-Mailer: git-send-email 1.9.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 Reading both fields at the same time lets us parse the list with half the number of configspace reads. Signed-off-by: Sean O. Stalley --- drivers/pci/pci.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 5e3c8e9..db7f3d6 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -145,19 +145,22 @@ static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn, u8 pos, int cap, int *ttl) { u8 id; + u16 ent; + + pci_bus_read_config_byte(bus, devfn, pos, &pos); while ((*ttl)--) { - pci_bus_read_config_byte(bus, devfn, pos, &pos); if (pos < 0x40) break; pos &= ~3; - pci_bus_read_config_byte(bus, devfn, pos + PCI_CAP_LIST_ID, - &id); + pci_bus_read_config_word(bus, devfn, pos, &ent); + + id = ent & 0xff; if (id == 0xff) break; if (id == cap) return pos; - pos += PCI_CAP_LIST_NEXT; + pos = (ent >> 8); } return 0; }