From patchwork Sun Mar 25 10:59:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10306615 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 31AAF600CC for ; Sun, 25 Mar 2018 11:01:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B572855C for ; Sun, 25 Mar 2018 11:01:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19ACF29308; Sun, 25 Mar 2018 11:01:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1C0E2855C for ; Sun, 25 Mar 2018 11:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753346AbeCYLBk (ORCPT ); Sun, 25 Mar 2018 07:01:40 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35829 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751985AbeCYLAE (ORCPT ); Sun, 25 Mar 2018 07:00:04 -0400 Received: by mail-wm0-f67.google.com with SMTP id r82so10571066wme.0; Sun, 25 Mar 2018 04:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YkgOg1ftodmovEOpRZL7mrHfuaWe9jEaNCSmD6Wg7uU=; b=cWDXNLoDZsWhV6kCR1AJio2GdwV6uuR7q2VzoRdCUrG1NV9n4hwwG0xnYp8oxBqNxT 53xjEMTLPbl3SsQ/k5wIcJaU73OEOW0oNAa9H4BRBuaEuZWgmHL2Cqa6O6+KdtWaPSZV toQ+ja3/IBHQ0zJvq0NmdxLSABv6k35287WIP/DFz3v1eSewnjcsJLdNIEfpCUbQmhIG ztCqSGnWKHq+ubJd1UuivLQFhVpPs9CAyfYdZm7eM+iZ5+Nazaxb7LaSkOnq3GWZrzfE UA5QTeb/RxL5fV2jFMkBaQuQ7zjeVp5qHpGHfxCMJj1zjnZ/ynL0aNcH7kUlfxyphMcG 5AKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YkgOg1ftodmovEOpRZL7mrHfuaWe9jEaNCSmD6Wg7uU=; b=qVlWKX9XwvvGnm8UdKJrPpDY3RPbZPDWsTTzi8HGUgyvcoYbfH2vqjQthDO+fYK6PZ xbOBES5FP2ThyFml5rE4sZFSy+O9xMSIwo9KeHCngNYfFIEzEAGHcZ9zF+U0s67tReeF gPmJ1ewrlFUSyuoj30wWQhileExZhyjXKlS+MZ9zdua/3+QUbTxyBbArp5IXaBrJ4egV 6zY3+B0fjlXo+mEODxuFnSo+BnTdg6BBh6aG5doVkagnbM+YguMyEq9NKwY2PBFlTWk6 Ie8EU7wFmuO/dVPVjpR9D4wCpGDvQ0phvdOFThjONTENYEvyyI0CWysbjZ5PX2nLHuMM ztsg== X-Gm-Message-State: AElRT7GBBqOxOxZ3nw0bn2D1as02/wjO1mbZ3trUf0XZWkO7CU54eww4 uQS4TVLFKNEwmKA6Ylo4Zs4= X-Google-Smtp-Source: AG47ELtBqyddKEp6NKBA4Ug0ewu05nvVO6GclUCDbNQG4wUv1E9IBcmIjzS1RQuSh6H5ycV7j6Ii1A== X-Received: by 10.28.109.27 with SMTP id i27mr13580230wmc.109.1521975603132; Sun, 25 Mar 2018 04:00:03 -0700 (PDT) Received: from baker.fritz.box ([2a02:908:1257:4460:80f2:8bcd:4355:2edc]) by smtp.gmail.com with ESMTPSA id z3sm20492230wme.3.2018.03.25.04.00.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Mar 2018 04:00:02 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] PCI: Add pci_find_common_upstream_dev() Date: Sun, 25 Mar 2018 12:59:54 +0200 Message-Id: <20180325110000.2238-2-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180325110000.2238-1-christian.koenig@amd.com> References: <20180325110000.2238-1-christian.koenig@amd.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "wdavis@nvidia.com" Add an interface to find the first device which is upstream of both devices. Signed-off-by: Will Davis Signed-off-by: Christian König --- drivers/pci/search.c | 24 ++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/drivers/pci/search.c b/drivers/pci/search.c index bc1e023f1353..446648f4238b 100644 --- a/drivers/pci/search.c +++ b/drivers/pci/search.c @@ -393,3 +393,27 @@ int pci_dev_present(const struct pci_device_id *ids) return 0; } EXPORT_SYMBOL(pci_dev_present); + +/** + * pci_find_common_upstream_dev - Returns the first common upstream device + * @dev: the PCI device from which the bus hierarchy walk will start + * @other: the PCI device whose bus number will be used for the search + * + * Walks up the bus hierarchy from the @dev device, looking for the first bus + * which the @other device is downstream of. Returns %NULL if the devices do + * not share any upstream devices. + */ +struct pci_dev *pci_find_common_upstream_dev(struct pci_dev *dev, + struct pci_dev *other) +{ + struct pci_dev *pdev = dev; + + while (pdev != NULL) { + if ((other->bus->number >= pdev->bus->busn_res.start) && + (other->bus->number <= pdev->bus->busn_res.end)) + return pdev; + pdev = pci_upstream_bridge(pdev); + } + + return NULL; +} diff --git a/include/linux/pci.h b/include/linux/pci.h index 024a1beda008..0d29f5cdcb04 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -956,6 +956,8 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus, } struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from); int pci_dev_present(const struct pci_device_id *ids); +struct pci_dev *pci_find_common_upstream_dev(struct pci_dev *from, + struct pci_dev *to); int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn, int where, u8 *val);