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: 10306573 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 97014600CC for ; Sun, 25 Mar 2018 11:00:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8798B2855C for ; Sun, 25 Mar 2018 11:00:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C34829308; Sun, 25 Mar 2018 11:00:10 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 19B8B2855C for ; Sun, 25 Mar 2018 11:00:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A21406E414; Sun, 25 Mar 2018 11:00:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 745806E412; Sun, 25 Mar 2018 11:00:04 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id f125so10484060wme.4; Sun, 25 Mar 2018 04:00:04 -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=qCuL+7kijiZqxPGtVcG3/RZD7lstdiB8wBTbCD3MD1PM2OR7xhIAs7hHFZLl9Cqcwb FcLDNQyV1+TBk4lG0nOw+hXFs2CzpjoOn53B5g+WUBf5pGGVGCndoKAKPu8sIsKyMYQT lmvk52+RzCa58tfwxAKugGWCsJvVNLuwp7OQ9WlmvsT1f/f7qPMO+CZizGQQufWpbcBU Iot/Kp3++YOP7m70k43gt3Xdlh+VYTJOC7rkTqEk/XaFWDgtjeqGEPi751YbBxlUy2hU ay6vBvKuWWJuEmqJ9wLG7NAKL6Nb2t1rTCtIxWwhg8v5aixIgquo1g2L2Pe+5e0Ue2tx /svw== X-Gm-Message-State: AElRT7F3PTWpsQzWbMBAEHGmYV7/cozGG3Ex1713j1Rhd/jQgphe8Jev UPUkX5Z9Thzh50WRVT3H+piVbQ== 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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);