From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A769AC433F5 for ; Thu, 21 Oct 2021 10:51:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5C4D961037 for ; Thu, 21 Oct 2021 10:51:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5C4D961037 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:50540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVfH-00031G-Fn for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:51:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVYE-0002Y8-3W for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVYB-00045k-2j for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634813034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2mNYA6IDBekMNlW8LTQ3HC5m6CdJcnmnKC8KNWJHNY0=; b=XY1kz96nFOfk8LVXr96EhS+QJ0MKG+r94M1aZa5IAWWBGV8C/g6Z9KtznR0a2GbjgNVw/S bNFcQqXFFwJl7n0GXKLmGezQGx412W5nc41IptYmL8f2FCSzscuMOU9viYv+Fefl/kUhuE H/TTrR9BSURBLBb/JYCQ0x06If3XgEk= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-Z7rsh-F4NWqEMp1Gpkhh8A-1; Thu, 21 Oct 2021 06:43:53 -0400 X-MC-Unique: Z7rsh-F4NWqEMp1Gpkhh8A-1 Received: by mail-pg1-f197.google.com with SMTP id z7-20020a63c047000000b0026b13e40309so14879029pgi.19 for ; Thu, 21 Oct 2021 03:43:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2mNYA6IDBekMNlW8LTQ3HC5m6CdJcnmnKC8KNWJHNY0=; b=V/26MruTQiilIV6y+jKrsqNHj2WmtDKyIQlkgJpsg369IcEWAA6wjl0ehRB9DgskZp yYbe0vQm8ddk8L4QKaelMVehybCBEB/GWjXs9eKhm4vRkfMNGiop7rFFXN9Qe8ZafFIO wtiK3EoynBYUtr39MV3g4dEpZClS8oqYorJH2XqtomcyNWh9boFGO6SbZLIqWeRxUqam Xfimcwo8KmrKM5+34Gi9SnkCzQqzSoyV0mCSW2YUd1Ddh6iwaFzf9FmnvgZTRezU/I5h TV5KWFh91psl9ln71KZLhydeg+AvxcIQaLyEoghEP2K5Ov5tU7bzxBMHhOk4NfOMKZi1 XlSg== X-Gm-Message-State: AOAM533vqSNbRM0nfCbuBy+68iAdqQOR9CTDThoIsde+lq4RaWlvI4Ue bR2u4NmpaXb/OoTH682CZHwe/UaNdm1ri7U9dEgzHzy8L3Bc9iidre/QNrBQqKkSvAYIcEV6zlC E2eXfjJt+cxfSyhORGjadOZjm4/gXzJzBSLbSABsbj7dQTk7uRGtyOTwl18jKjleW X-Received: by 2002:a17:90b:78d:: with SMTP id l13mr5811310pjz.37.1634813031927; Thu, 21 Oct 2021 03:43:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxteYFf3Z8SYbUueptdwqZw9C66njC04GXUMehDaXv8lbLKaFmfQwZ5CYUjRImDvpgpIK0YVA== X-Received: by 2002:a17:90b:78d:: with SMTP id l13mr5811251pjz.37.1634813031527; Thu, 21 Oct 2021 03:43:51 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:51 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 7/8] pci: Add pci_for_each_device_all() Date: Thu, 21 Oct 2021 18:42:58 +0800 Message-Id: <20211021104259.57754-8-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211021104259.57754-1-peterx@redhat.com> References: <20211021104259.57754-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , "Daniel P . Berrange" , Eduardo Habkost , "Michael S . Tsirkin" , Jason Wang , David Hildenbrand , Markus Armbruster , peterx@redhat.com, Shannon Zhao , Alex Williamson , Paolo Bonzini , Igor Mammedov , Eric Auger , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" With all the prepared infrastructures, we can easily add one helper now to loop over all the existing PCI devices across the whole system. Signed-off-by: Peter Xu --- hw/pci/pci.c | 25 +++++++++++++++++++++++++ include/hw/pci/pci.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 1623bc9099..5c970f0727 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2124,6 +2124,31 @@ void pci_for_each_root_bus(pci_bus_fn fn, void *opaque) object_child_foreach_recursive(object_get_root(), pci_find_root_bus, &args); } +typedef struct { + pci_bus_dev_fn fn; + void *opaque; +} pci_bus_dev_args; + +static void pci_single_bus_hook(PCIBus *bus, void *opaque) +{ + pci_bus_dev_args *args = opaque; + + pci_for_each_device_under_bus(bus, args->fn, args->opaque); +} + +static void pci_root_bus_hook(PCIBus *bus, void *opaque) +{ + assert(pci_bus_is_root(bus)); + pci_for_each_bus(bus, pci_single_bus_hook, opaque); +} + +void pci_for_each_device_all(pci_bus_dev_fn fn, void *opaque) +{ + pci_bus_dev_args args = { .fn = fn, .opaque = opaque }; + + pci_for_each_root_bus(pci_root_bus_hook, &args); +} + PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn) { bus = pci_find_bus_nr(bus, bus_num); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 9e490d8969..1a862d1903 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -476,6 +476,8 @@ void pci_for_each_bus_depth_first(PCIBus *bus, pci_bus_ret_fn begin, pci_bus_fn end, void *parent_state); /* Call `fn' for each pci root bus on the system */ void pci_for_each_root_bus(pci_bus_fn fn, void *opaque); +/* Call 'fn' for each pci device on the system */ +void pci_for_each_device_all(pci_bus_dev_fn fn, void *opaque); PCIDevice *pci_get_function_0(PCIDevice *pci_dev); /* Use this wrapper when specific scan order is not required. */ -- 2.32.0