From patchwork Thu Oct 21 10:42:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574669 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 BA1D6C433EF for ; Thu, 21 Oct 2021 10:46:11 +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 32E4F60F9E for ; Thu, 21 Oct 2021 10:46:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 32E4F60F9E 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]:39240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVaM-0003dx-2N for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:46:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXd-00020P-8j for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXb-0001uu-6X for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634812998; 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=9pnGsoIk9DwjVvIK5mv02Ef2J26qjf6hM046vHC95gs=; b=LXhpo1GLj31bcmuXIsfymp8YxN2h2cZxYxhRutWF8sG7gbw/c6rDI8bHX7qPSVYlGNk9CT GKVhEbqcFI4mOi6LqNBeeo3F/Kd+xdIm5Xos06r1PRn1tuqo7O2GGqa3WpB0uPJXYRg4Nv 00r2Wm92yk1bee6fDXDJRKYuNJL4ZXY= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-210-_S1nUSiNMFORvqnjg0_TLg-1; Thu, 21 Oct 2021 06:43:17 -0400 X-MC-Unique: _S1nUSiNMFORvqnjg0_TLg-1 Received: by mail-pl1-f199.google.com with SMTP id k18-20020a170902c41200b0013f24806d35so81856plk.1 for ; Thu, 21 Oct 2021 03:43:17 -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=9pnGsoIk9DwjVvIK5mv02Ef2J26qjf6hM046vHC95gs=; b=0ey69VqaV0PN1qB+4Skri4DfUaL+9V6hLN8Nz+J7Mu0la0W7F3X0jYA6F6JQO5PhSp onQgjrnae8mhSiw/ldTMuYGLTHU2JIlt1oTsTQPu7NvtSkSB9eITgNR9yGjV42dSthtd 4BPYDAcJLjRMnd/h92aM8+K+StjvV0+azFnvQiQTPHGkeXrUpy+B2qa00In4ask1Hc6y bVNq6tnCn/4nsW/vmxwuWTb9CU9MWb9T3LYYDVhmdf56ykP3eUAEGdaZiuLu7tAlA2K+ Sho1fA+iqU0SuOvomhgSj81kkpIVJYpRSRNN1GXAZOeIxARcQh2IGf9DsrrXliyc0MPZ NhTA== X-Gm-Message-State: AOAM533XtIZTY74SRQ6RfVc8YXvoCvEJWVAtO3FCIQ+0ltym+e59QkoN +ofkI55bbEkOhBsrEmzIOCu1iUKQSbXZ4MVkuX9KezqljNhwEnhbXyYLyv8usEdgLhUoTJR3l4+ 7cq4CwrloIgL7GRCY8Rn2fXWrETc5pbu6sPpxP8ipdIZWp2ZmOasLJZ20NC/nveeV X-Received: by 2002:a63:7a58:: with SMTP id j24mr2869075pgn.210.1634812995893; Thu, 21 Oct 2021 03:43:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqFMbNPKr9S/3frrGXqq4JfaWSCeNvfx99r3WGCuAI8aN+GwY0xs7ZFKLT65+wRNDesk3Etw== X-Received: by 2002:a63:7a58:: with SMTP id j24mr2869040pgn.210.1634812995485; Thu, 21 Oct 2021 03:43:15 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:14 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 1/8] pci: Define pci_bus_dev_fn type Date: Thu, 21 Oct 2021 18:42:52 +0800 Message-Id: <20211021104259.57754-2-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 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" It's used in quite a few places of pci.c and also in the rest of the code base. Define such a hook so that it doesn't need to be defined all over the places. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Eric Auger Reviewed-by: Philippe Mathieu-Daudé --- hw/pci/pci.c | 14 ++++---------- include/hw/pci/pci.h | 7 ++++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 186758ee11..1ab2b78321 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1655,9 +1655,7 @@ static const pci_class_desc pci_class_descriptions[] = }; static void pci_for_each_device_under_bus_reverse(PCIBus *bus, - void (*fn)(PCIBus *b, - PCIDevice *d, - void *opaque), + pci_bus_dev_fn fn, void *opaque) { PCIDevice *d; @@ -1672,8 +1670,7 @@ static void pci_for_each_device_under_bus_reverse(PCIBus *bus, } void pci_for_each_device_reverse(PCIBus *bus, int bus_num, - void (*fn)(PCIBus *b, PCIDevice *d, void *opaque), - void *opaque) + pci_bus_dev_fn fn, void *opaque) { bus = pci_find_bus_nr(bus, bus_num); @@ -1683,9 +1680,7 @@ void pci_for_each_device_reverse(PCIBus *bus, int bus_num, } static void pci_for_each_device_under_bus(PCIBus *bus, - void (*fn)(PCIBus *b, PCIDevice *d, - void *opaque), - void *opaque) + pci_bus_dev_fn fn, void *opaque) { PCIDevice *d; int devfn; @@ -1699,8 +1694,7 @@ static void pci_for_each_device_under_bus(PCIBus *bus, } void pci_for_each_device(PCIBus *bus, int bus_num, - void (*fn)(PCIBus *b, PCIDevice *d, void *opaque), - void *opaque) + pci_bus_dev_fn fn, void *opaque) { bus = pci_find_bus_nr(bus, bus_num); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 7fc90132cf..8e2d80860b 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -401,6 +401,8 @@ typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin); OBJECT_DECLARE_TYPE(PCIBus, PCIBusClass, PCI_BUS) #define TYPE_PCIE_BUS "PCIE" +typedef void (*pci_bus_dev_fn)(PCIBus *b, PCIDevice *d, void *opaque); + bool pci_bus_is_express(PCIBus *bus); void pci_root_bus_init(PCIBus *bus, size_t bus_size, DeviceState *parent, @@ -458,11 +460,10 @@ static inline int pci_dev_bus_num(const PCIDevice *dev) int pci_bus_numa_node(PCIBus *bus); void pci_for_each_device(PCIBus *bus, int bus_num, - void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque), + pci_bus_dev_fn fn, void *opaque); void pci_for_each_device_reverse(PCIBus *bus, int bus_num, - void (*fn)(PCIBus *bus, PCIDevice *d, - void *opaque), + pci_bus_dev_fn fn, void *opaque); void pci_for_each_bus_depth_first(PCIBus *bus, void *(*begin)(PCIBus *bus, void *parent_state), From patchwork Thu Oct 21 10:42:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574671 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 45FCAC433EF for ; Thu, 21 Oct 2021 10:47:38 +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 F116660F46 for ; Thu, 21 Oct 2021 10:47:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F116660F46 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]:43260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVbl-0006XA-2D for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:47:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXj-00029N-VD for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48282) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXi-0002TN-0m for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634813005; 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=pho+TtIdP4qBZG3cdR7uV3of32w57JyQCr7ZXpyaYms=; b=gSsQcSDCJvbhF6ikWA0bauSMXqmELOoiTYm3caP5S9cNqKBWJ1T8Fa+fg3/+Qm72e1nUHu ivoSVkK2GLiFA6OSGgxNVSvh5D6l6kUq10eP32sCnW7PKD1pmEGG18Qk9RzBqIFSAVqqkh 1W1z/9iKQssyHCzYkoPsXQG08xoxuwE= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-220-GDC7uu-UOF6YKAmwkzhHzQ-1; Thu, 21 Oct 2021 06:43:24 -0400 X-MC-Unique: GDC7uu-UOF6YKAmwkzhHzQ-1 Received: by mail-pj1-f71.google.com with SMTP id r7-20020a17090a454700b001a1ca0191b8so161761pjm.4 for ; Thu, 21 Oct 2021 03:43:24 -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=pho+TtIdP4qBZG3cdR7uV3of32w57JyQCr7ZXpyaYms=; b=4dwts9i1puQffeJfZmi32fkdSK/WU4E5QpIxlgJCNNEhWIIGifVz4QRkZ1QWyGwCT1 SmdgQUCEdAAJKQIZFuKR+7t4A7r/eazp7icGB5ng12eMlT6UQgY/3Iq+ydcoQrUC1yZj GH8/AG79LEgVdzUrYzE458US/zZZlytq8uXM8vvTaMlgzEj3/TPTWbunuQ0LW1c2MIiA B2SmBJYYoQJDzro8HA9tq7lM2Gyh0gatQyJJSxLlO9pZf3qoEHmz+dzGowesZqJmbVE+ IR+fsHny4S6cMOoeoprR9ctnaWTdwv7bi5g7TPwOogxTA21rWI+g4hwNXVSVTSGlg1gl JCxg== X-Gm-Message-State: AOAM532EwcY6KhxQNYpZ+j6O/NLpemRB0B6ScrzO+DMLB79ocMNfJodI nY92WRTQgX3Ki6JYtnMo8/1vGhn5RR788RWo8sIejyf0qE42FWTqT/g/gTwjZ7EfuKM8AdIgVj9 yC3IRI8yvzqObXQfYYrTBy31hOyT1CUy/YKCkqqAjPT3HoWokADfOfAwhnF5oppX9 X-Received: by 2002:a17:90b:3ecd:: with SMTP id rm13mr5624498pjb.189.1634813002468; Thu, 21 Oct 2021 03:43:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwx8fU69lZ5q3MmA1VBiGyPN6r1fFX70ZYjzJOmTw3DOuArHjYiS5kCU9UIvJLB4XtiQj7p6A== X-Received: by 2002:a17:90b:3ecd:: with SMTP id rm13mr5624385pjb.189.1634813001333; Thu, 21 Oct 2021 03:43:21 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:20 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 2/8] pci: Export pci_for_each_device_under_bus*() Date: Thu, 21 Oct 2021 18:42:53 +0800 Message-Id: <20211021104259.57754-3-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 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" They're actually more commonly used than the helper without _under_bus, because most callers do have the pci bus on hand. After exporting we can switch a lot of the call sites to use these two helpers. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Eric Auger Reviewed-by: Philippe Mathieu-Daudé --- hw/pci/pci.c | 10 +++++----- include/hw/pci/pci.h | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 1ab2b78321..6b834cace5 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1654,9 +1654,9 @@ static const pci_class_desc pci_class_descriptions[] = { 0, NULL} }; -static void pci_for_each_device_under_bus_reverse(PCIBus *bus, - pci_bus_dev_fn fn, - void *opaque) +void pci_for_each_device_under_bus_reverse(PCIBus *bus, + pci_bus_dev_fn fn, + void *opaque) { PCIDevice *d; int devfn; @@ -1679,8 +1679,8 @@ void pci_for_each_device_reverse(PCIBus *bus, int bus_num, } } -static void pci_for_each_device_under_bus(PCIBus *bus, - pci_bus_dev_fn fn, void *opaque) +void pci_for_each_device_under_bus(PCIBus *bus, + pci_bus_dev_fn fn, void *opaque) { PCIDevice *d; int devfn; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 8e2d80860b..437eabe609 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -465,6 +465,11 @@ void pci_for_each_device(PCIBus *bus, int bus_num, void pci_for_each_device_reverse(PCIBus *bus, int bus_num, pci_bus_dev_fn fn, void *opaque); +void pci_for_each_device_under_bus(PCIBus *bus, + pci_bus_dev_fn fn, void *opaque); +void pci_for_each_device_under_bus_reverse(PCIBus *bus, + pci_bus_dev_fn fn, + void *opaque); void pci_for_each_bus_depth_first(PCIBus *bus, void *(*begin)(PCIBus *bus, void *parent_state), void (*end)(PCIBus *bus, void *state), From patchwork Thu Oct 21 10:42:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574673 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 2B726C433EF for ; Thu, 21 Oct 2021 10:47:46 +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 A194A60F46 for ; Thu, 21 Oct 2021 10:47:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A194A60F46 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]:43676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVbs-0006os-LN for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:47:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXp-0002Hi-6R for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52476) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXn-0002i5-02 for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634813010; 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=CaeapVhIc3JhMn3WXa8Vnaag8s3+s4YzQ5lKkHRVcJ8=; b=RT6Qe8HhBjocxsuiXqSxiBRxrGD77yIXU/GaJo/JCjTRJCP4BIy+WWaSkMOl/+bn37sOsk J8P0l9KRZUBLNa5fhfOsHW1ZyeyybVEM8iCk00oSjDqOhJHEvSvIWiJs1wqJhNYg0wwkM1 rGy+6bEUIuu1n/31a4GDtbV8kRyl4sU= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-514-UMRiq-pOMdu1W2nRCDHudQ-1; Thu, 21 Oct 2021 06:43:29 -0400 X-MC-Unique: UMRiq-pOMdu1W2nRCDHudQ-1 Received: by mail-pl1-f198.google.com with SMTP id e6-20020a170902ed8600b0013f165d1b51so59231plj.15 for ; Thu, 21 Oct 2021 03:43:29 -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=CaeapVhIc3JhMn3WXa8Vnaag8s3+s4YzQ5lKkHRVcJ8=; b=Yl17be7YD9NUZBomnC2tiS4ye98ELd/E1E73Mj+6MT48yfmqOsbB1qP6ejmfrLUbaX 860bEkcsR0prepvgqHcIepdOY/xAlj4gClJgSuJMlWiizMnUq/rgpk5yyZT3nsBnuKVn 2MzGAHr7iDloMhQ7YWejQ5368jwmtMB6KWMLC6pZZd1tA4nmtAD0pEZCmYsGzxvwHcb1 5EAQaHgbPngTZc3ZZV9wgmAcfeP83jm533t9KJs2eiX5Cw3K7lxz9sNU8sbMm1K1uOqf NZWcKhsVlQX5ju6lwUaTjDpB3Ukyzmh5J+rj5GVE+82G+c+tKy2zet5u+xH0w3Pn99hV KuYw== X-Gm-Message-State: AOAM533oOttc5jI1rtFkM/+rV9orkkLBO8lN5xlWvV+J4MvBcUhb7MZN Q+ejm9PW0xZz83QAtP8bundAZQW+LUQSw/3a2RnGP/1Z0dtQ1RVhSmwWDZ3lXBDGgwzrd0kfBc9 Ap3+DQq+sLzfiRBxplNZuoiZw7HGOngXKT/dzRd5fhfzg3lFwX+x0vyCCBTk2Kqc1 X-Received: by 2002:a05:6a00:1309:b0:44d:4d1e:c930 with SMTP id j9-20020a056a00130900b0044d4d1ec930mr4732468pfu.65.1634813007772; Thu, 21 Oct 2021 03:43:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx36RFxuGCviM5+t8cMBL6RdbLO4q0eD7bMv/NrXD5/a18064WwnIAeu7ET+NjbQALdEcmJOQ== X-Received: by 2002:a05:6a00:1309:b0:44d:4d1e:c930 with SMTP id j9-20020a056a00130900b0044d4d1ec930mr4732425pfu.65.1634813007384; Thu, 21 Oct 2021 03:43:27 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:26 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 3/8] pci: Use pci_for_each_device_under_bus*() Date: Thu, 21 Oct 2021 18:42:54 +0800 Message-Id: <20211021104259.57754-4-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 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" Replace all the call sites of existing pci_for_each_device*() where the bus number is calculated from a PCIBus* already. It should avoid the lookup of the PCIBus again. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Eric Auger --- hw/i386/acpi-build.c | 5 ++--- hw/pci/pcie.c | 4 +--- hw/ppc/spapr_pci.c | 12 +++++------- hw/ppc/spapr_pci_nvlink2.c | 7 +++---- hw/ppc/spapr_pci_vfio.c | 4 ++-- hw/s390x/s390-pci-bus.c | 5 ++--- hw/xen/xen_pt.c | 4 ++-- 7 files changed, 17 insertions(+), 24 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 81418b7911..a76b17ed92 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2132,8 +2132,7 @@ dmar_host_bridges(Object *obj, void *opaque) PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; if (bus && !pci_bus_bypass_iommu(bus)) { - pci_for_each_device(bus, pci_bus_num(bus), insert_scope, - scope_blob); + pci_for_each_device_under_bus(bus, insert_scope, scope_blob); } } @@ -2339,7 +2338,7 @@ ivrs_host_bridges(Object *obj, void *opaque) PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; if (bus && !pci_bus_bypass_iommu(bus)) { - pci_for_each_device(bus, pci_bus_num(bus), insert_ivhd, ivhd_blob); + pci_for_each_device_under_bus(bus, insert_ivhd, ivhd_blob); } } diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c index 6e95d82903..914a9bf3d1 100644 --- a/hw/pci/pcie.c +++ b/hw/pci/pcie.c @@ -694,9 +694,7 @@ void pcie_cap_slot_write_config(PCIDevice *dev, (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) || (old_slt_ctl & PCI_EXP_SLTCTL_PIC_OFF) != PCI_EXP_SLTCTL_PIC_OFF)) { PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), - pcie_unplug_device, NULL); - + pci_for_each_device_under_bus(sec_bus, pcie_unplug_device, NULL); pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, PCI_EXP_SLTSTA_PDS); if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA || diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 7430bd6314..5bfd4aa9e5 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -1317,8 +1317,7 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus, RESOURCE_CELLS_SIZE)); assert(bus); - pci_for_each_device_reverse(bus, pci_bus_num(bus), - spapr_dt_pci_device_cb, &cbinfo); + pci_for_each_device_under_bus_reverse(bus, spapr_dt_pci_device_cb, &cbinfo); if (cbinfo.err) { return cbinfo.err; } @@ -2306,8 +2305,8 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev, return; } - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), - spapr_phb_pci_enumerate_bridge, bus_no); + pci_for_each_device_under_bus(sec_bus, spapr_phb_pci_enumerate_bridge, + bus_no); pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1); } @@ -2316,9 +2315,8 @@ static void spapr_phb_pci_enumerate(SpaprPhbState *phb) PCIBus *bus = PCI_HOST_BRIDGE(phb)->bus; unsigned int bus_no = 0; - pci_for_each_device(bus, pci_bus_num(bus), - spapr_phb_pci_enumerate_bridge, - &bus_no); + pci_for_each_device_under_bus(bus, spapr_phb_pci_enumerate_bridge, + &bus_no); } diff --git a/hw/ppc/spapr_pci_nvlink2.c b/hw/ppc/spapr_pci_nvlink2.c index 8ef9b40a18..7fb0cf4d04 100644 --- a/hw/ppc/spapr_pci_nvlink2.c +++ b/hw/ppc/spapr_pci_nvlink2.c @@ -164,8 +164,7 @@ static void spapr_phb_pci_collect_nvgpu(PCIBus *bus, PCIDevice *pdev, return; } - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), - spapr_phb_pci_collect_nvgpu, opaque); + pci_for_each_device_under_bus(sec_bus, spapr_phb_pci_collect_nvgpu, opaque); } void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp) @@ -183,8 +182,8 @@ void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp) sphb->nvgpus->nv2_atsd_current = sphb->nv2_atsd_win_addr; bus = PCI_HOST_BRIDGE(sphb)->bus; - pci_for_each_device(bus, pci_bus_num(bus), - spapr_phb_pci_collect_nvgpu, sphb->nvgpus); + pci_for_each_device_under_bus(bus, spapr_phb_pci_collect_nvgpu, + sphb->nvgpus); if (sphb->nvgpus->err) { error_propagate(errp, sphb->nvgpus->err); diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c index f3b37df8ea..2a76b4e0b5 100644 --- a/hw/ppc/spapr_pci_vfio.c +++ b/hw/ppc/spapr_pci_vfio.c @@ -164,8 +164,8 @@ static void spapr_phb_vfio_eeh_clear_dev_msix(PCIBus *bus, static void spapr_phb_vfio_eeh_clear_bus_msix(PCIBus *bus, void *opaque) { - pci_for_each_device(bus, pci_bus_num(bus), - spapr_phb_vfio_eeh_clear_dev_msix, NULL); + pci_for_each_device_under_bus(bus, spapr_phb_vfio_eeh_clear_dev_msix, + NULL); } static void spapr_phb_vfio_eeh_pre_reset(SpaprPhbState *sphb) diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c index 6fafffb029..1b51a72838 100644 --- a/hw/s390x/s390-pci-bus.c +++ b/hw/s390x/s390-pci-bus.c @@ -1163,8 +1163,7 @@ static void s390_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev, } /* Assign numbers to all child bridges. The last is the highest number. */ - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), - s390_pci_enumerate_bridge, s); + pci_for_each_device_under_bus(sec_bus, s390_pci_enumerate_bridge, s); pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, s->bus_no, 1); } @@ -1193,7 +1192,7 @@ static void s390_pcihost_reset(DeviceState *dev) * on every system reset, we also have to reassign numbers. */ s->bus_no = 0; - pci_for_each_device(bus, pci_bus_num(bus), s390_pci_enumerate_bridge, s); + pci_for_each_device_under_bus(bus, s390_pci_enumerate_bridge, s); } static void s390_pcihost_class_init(ObjectClass *klass, void *data) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index ca0a98187e..027190fa44 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -615,8 +615,8 @@ static void xen_pt_region_update(XenPCIPassthroughState *s, } args.type = d->io_regions[bar].type; - pci_for_each_device(pci_get_bus(d), pci_dev_bus_num(d), - xen_pt_check_bar_overlap, &args); + pci_for_each_device_under_bus(pci_get_bus(d), + xen_pt_check_bar_overlap, &args); if (args.rc) { XEN_PT_WARN(d, "Region: %d (addr: 0x%"FMT_PCIBUS ", len: 0x%"FMT_PCIBUS") is overlapped.\n", From patchwork Thu Oct 21 10:42:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574711 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 7DE79C433F5 for ; Thu, 21 Oct 2021 10:49:35 +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 2654561037 for ; Thu, 21 Oct 2021 10:49:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2654561037 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]:47576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVde-00010p-7Y for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:49:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXv-0002L4-8F for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXt-0002nK-AV for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634813016; 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=qA2xR3nTmoE7PUCnmVtIB+SYHwB2jij1XP/u2/ka5O4=; b=gjTi8TGQTwdgq5kJNf89S/GDXT+3VG3uFSrNXc/IPE1pitHH76W0r7wv59QqpgAlUWbyqy s9ZS7UTt+SEoGK+AwOdjYXi050buqfkxD/t9fU2Z/s8tcno8hTkPa/HbRc0jzvYxlRtn3M AXyMFt+5bhJ0kVPIypU0xKnIUr/0cbc= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-iHB6OdCgP02FBE7C-XD45A-1; Thu, 21 Oct 2021 06:43:35 -0400 X-MC-Unique: iHB6OdCgP02FBE7C-XD45A-1 Received: by mail-pj1-f72.google.com with SMTP id nk17-20020a17090b195100b001a199d7a415so2069545pjb.7 for ; Thu, 21 Oct 2021 03:43:35 -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=qA2xR3nTmoE7PUCnmVtIB+SYHwB2jij1XP/u2/ka5O4=; b=fgJe1iYK4qH30OqoyDgtlKLDRoZW8WgU46iFWXr2Ra2d0kxPoIsjQieKGOGpRp8t4K CsVf2nxV3gN2AMl0SWf0A0sZ3ym7dkAztUxV/WPHA6B0TT53KMCUQ74TJpGZmufGyzMA 1YByr7y0mmJGsC3xVwnX3AfvMi/cixY+cTxLbBq3gNCjtm7QBwTq3Yeb72tzkBznAnXL hZ/Rw3zLzJhaXFjF8Bir/7HPgvvrwvDPnV4GBfUroojCu7bCB/+jYzOZsGjXJpR734qh z+TQnICDrDroS3x1jLrkJuuTtwmdfjtxOY+vP3Wk+cDzUayGysjZZX/YY/2YzrMly0Ti l7VQ== X-Gm-Message-State: AOAM533dEclQ7s63kfjJD78vHXAQmAcO2tWmRyqE0Ypk6QCnm936f1Rr HNtzz04HMk9UwCoA1MIFr013iHmnofIbRgxNzI5jP9i/1O2Hc6xeHDk+67bKVBF7cl9UhKNw9+a 1kh7CD2u0LbI+JfHl5D9zO8mhZ8Eh2bSSk1ZbmjM7wMVloBiuWjtijuA4VUeBcmD0 X-Received: by 2002:a17:902:6808:b0:13e:a85b:52bd with SMTP id h8-20020a170902680800b0013ea85b52bdmr4409793plk.76.1634813013990; Thu, 21 Oct 2021 03:43:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8v0BRfpG3ehB+u+O5Brrn6R6VLFhKQYHp1nJFme6ocetV5ubP/dVr06purwX1ogD9+VjMZA== X-Received: by 2002:a17:902:6808:b0:13e:a85b:52bd with SMTP id h8-20020a170902680800b0013ea85b52bdmr4409755plk.76.1634813013577; Thu, 21 Oct 2021 03:43:33 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:33 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 4/8] pci: Define pci_bus_fn/pci_bus_ret_fn type Date: Thu, 21 Oct 2021 18:42:55 +0800 Message-Id: <20211021104259.57754-5-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 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" The pci_bus_fn is similar to pci_bus_dev_fn that only takes a PCIBus* and an opaque. The pci_bus_ret_fn is similar to pci_bus_fn but it allows to return a void* pointer. Use them where proper in pci.[ch], and to be used elsewhere. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Eric Auger Reviewed-by: Philippe Mathieu-Daudé --- hw/pci/pci.c | 6 ++---- include/hw/pci/pci.h | 12 +++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 6b834cace5..4a84e478ce 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2072,10 +2072,8 @@ static PCIBus *pci_find_bus_nr(PCIBus *bus, int bus_num) return NULL; } -void pci_for_each_bus_depth_first(PCIBus *bus, - void *(*begin)(PCIBus *bus, void *parent_state), - void (*end)(PCIBus *bus, void *state), - void *parent_state) +void pci_for_each_bus_depth_first(PCIBus *bus, pci_bus_ret_fn begin, + pci_bus_fn end, void *parent_state) { PCIBus *sec; void *state; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 437eabe609..a7e81f04d3 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -402,6 +402,8 @@ OBJECT_DECLARE_TYPE(PCIBus, PCIBusClass, PCI_BUS) #define TYPE_PCIE_BUS "PCIE" typedef void (*pci_bus_dev_fn)(PCIBus *b, PCIDevice *d, void *opaque); +typedef void (*pci_bus_fn)(PCIBus *b, void *opaque); +typedef void* (*pci_bus_ret_fn)(PCIBus *b, void *opaque); bool pci_bus_is_express(PCIBus *bus); @@ -470,17 +472,13 @@ void pci_for_each_device_under_bus(PCIBus *bus, void pci_for_each_device_under_bus_reverse(PCIBus *bus, pci_bus_dev_fn fn, void *opaque); -void pci_for_each_bus_depth_first(PCIBus *bus, - void *(*begin)(PCIBus *bus, void *parent_state), - void (*end)(PCIBus *bus, void *state), - void *parent_state); +void pci_for_each_bus_depth_first(PCIBus *bus, pci_bus_ret_fn begin, + pci_bus_fn end, void *parent_state); PCIDevice *pci_get_function_0(PCIDevice *pci_dev); /* Use this wrapper when specific scan order is not required. */ static inline -void pci_for_each_bus(PCIBus *bus, - void (*fn)(PCIBus *bus, void *opaque), - void *opaque) +void pci_for_each_bus(PCIBus *bus, pci_bus_fn fn, void *opaque) { pci_for_each_bus_depth_first(bus, NULL, fn, opaque); } From patchwork Thu Oct 21 10:42:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574715 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 1C554C433EF for ; Thu, 21 Oct 2021 10:52:42 +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 D75D26103D for ; Thu, 21 Oct 2021 10:52:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D75D26103D 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]:53864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVge-0005IL-R7 for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:52:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVY1-0002P7-W6 for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVXz-00031k-8n for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634813022; 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=FJFzjMvrQujXC/2qJTkLr/Ge40TESEwyA20j1eeaERk=; b=PgkjCNloZTlXbsVr9lRECqxXvo/yPyctXJLtj7zi/E8H3sYJpUZnFNLN7k0q537hbUaYQc MHqEuMLuHEMDJRtDVZyYEO2c5hDuk4fDLIWSVIDxzmXSKVHlfWT+Chn05E7Vx3yqAXHuw3 hMM+Dmp/IkyavkKznVJ/QcUDr8/kXFk= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-440-_jHqtqm2OvW57hg3dcD5Pg-1; Thu, 21 Oct 2021 06:43:41 -0400 X-MC-Unique: _jHqtqm2OvW57hg3dcD5Pg-1 Received: by mail-pj1-f71.google.com with SMTP id nk17-20020a17090b195100b001a199d7a415so2069650pjb.7 for ; Thu, 21 Oct 2021 03:43:41 -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=FJFzjMvrQujXC/2qJTkLr/Ge40TESEwyA20j1eeaERk=; b=i0vjJMjBOXWATeFyQnLTz7Cn2XP3g4/L3jwPZUpcYmlYmNsDg1XhXDNj6tvf6cLZUE DmtmgtnJoS8hR1N/5ep7TODXOZWmWECOsuFSNC//c7LKdFgFe6b2RikXTYdtheYXILHo cR+OI9riU5LXh7jSlkrI9cGCinGwClifhmF9x6eC0UhimqM/9YGUKX6vOa1YJfYrpqWb c9GFKOcCXOt3ucDxooASjZHKbCZDPqyOTWmRE+XDtSfzG6gHCpG+HFZwatQeCEPD73D2 drOxzu6hj2VUUS8xbjvx3BJb1mTwLElrTyPzapHKFEAKB8ucBu/U67mWVoxgfIckxXsV 7y/g== X-Gm-Message-State: AOAM532poMpE2YzcimkMo53uSqPUtRo7/o4Rv5DgqN/tVUO/pSdtsGy+ GzOXhfclwQwIwNPZNFuvGGay/kRVV3lgkoHw7KTu8SqczgcB8PtPsosm7iHW7yVhzsrnIAFm1LW wE/mdVc0hfH6R1HXBSlzJp/Ve8DjPLXo45EWKDg8QTVTMMyGfML7yxreHfX+qY9mI X-Received: by 2002:a62:e51a:0:b0:44d:67bd:53ab with SMTP id n26-20020a62e51a000000b0044d67bd53abmr5181671pff.86.1634813019909; Thu, 21 Oct 2021 03:43:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0+SJsQ+n6hsr5+enk6reIjf/5lMUL6e+04yFnJI54/8hk0BOFsiWsojOgyXK6/rkZNFYm7A== X-Received: by 2002:a62:e51a:0:b0:44d:67bd:53ab with SMTP id n26-20020a62e51a000000b0044d67bd53abmr5181633pff.86.1634813019571; Thu, 21 Oct 2021 03:43:39 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:38 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 5/8] pci: Add pci_for_each_root_bus() Date: Thu, 21 Oct 2021 18:42:56 +0800 Message-Id: <20211021104259.57754-6-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 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" Add a helper to loop over each root bus of the system, either the default root bus or extended buses like pxb-pcie. Signed-off-by: Peter Xu Reviewed-by: Eric Auger --- hw/pci/pci.c | 26 ++++++++++++++++++++++++++ include/hw/pci/pci.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 4a84e478ce..1623bc9099 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2097,6 +2097,32 @@ void pci_for_each_bus_depth_first(PCIBus *bus, pci_bus_ret_fn begin, } } +typedef struct { + pci_bus_fn fn; + void *opaque; +} pci_root_bus_args; + +static int pci_find_root_bus(Object *obj, void *opaque) +{ + pci_root_bus_args *args = opaque; + + if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) { + PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; + + if (bus) { + args->fn(bus, args->opaque); + } + } + + return 0; +} + +void pci_for_each_root_bus(pci_bus_fn fn, void *opaque) +{ + pci_root_bus_args args = { .fn = fn, .opaque = opaque }; + + object_child_foreach_recursive(object_get_root(), pci_find_root_bus, &args); +} PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn) { diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index a7e81f04d3..9e490d8969 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -474,6 +474,8 @@ void pci_for_each_device_under_bus_reverse(PCIBus *bus, void *opaque); 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); PCIDevice *pci_get_function_0(PCIDevice *pci_dev); /* Use this wrapper when specific scan order is not required. */ From patchwork Thu Oct 21 10:42:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574719 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 48E1DC433F5 for ; Thu, 21 Oct 2021 10:54:13 +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 D59FB6103D for ; Thu, 21 Oct 2021 10:54:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D59FB6103D 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]:58266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVi8-0008Ix-1Z for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:54:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVY8-0002TG-LT for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35598) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVY6-0003b7-JA for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:43:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634813028; 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=Xh54kiHT0i6I588s5LcRb0tKQb3jeRCY3nUsIqN63CM=; b=NBVps8Uye+x1qFyl2kMmxgfRQQ8vszM5JFLgRzZ4raAGqd75c6+gqbS2pjMx5nXbZVHjsn NpY5VNqjYRs7sQTyM63Fe0bZDjkJ97GfyyQ3OPDwQVB3OyqD5rygSC93DuBbPaOxije4Zx /FGtycnSLd8Fa2YI9+be4QuVmQrkl2M= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-194-gowHznN6NOyoBe3bnC3dhg-1; Thu, 21 Oct 2021 06:43:47 -0400 X-MC-Unique: gowHznN6NOyoBe3bnC3dhg-1 Received: by mail-pg1-f199.google.com with SMTP id i14-20020a63d44e000000b002955652e9deso14899217pgj.16 for ; Thu, 21 Oct 2021 03:43:47 -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=Xh54kiHT0i6I588s5LcRb0tKQb3jeRCY3nUsIqN63CM=; b=7QMihlj2mjxkxTJIhEPX1C2v/HXRmLP1YAbg8AGDZDemXbuRb/NhOtnTkdOIhyeu9R IPSlUf92d2Yt7NMTFO7tyLSq5R5w9aRkZZRfz3ffSvqyYls8/5XA4t+bnizfcM5PinZ0 q6zpQsdQ6wDOkWVi9aVqPYyRDfXO9VHM+n0MMtrHrCaHvQ4jDNnCzoKPZq7MosphafI2 8Va1DMzdBjwAgzL+GCVDk9XZnXIzaKrAFt9IDlkyp9BLkqo/DJotPP7Gp4m+x5diRLuB m2QNVaFWxKDrn/aiQA3Ior2kjudSZYpRqo31elY1+/5/SqyOvxoZzcxZU5wG6YWitJuu NGxw== X-Gm-Message-State: AOAM531fsOWgqdeoJcxqixHNEimS0BR5FY0WFvLYWgMe35KNk83z/h7z edq+sr2HjHIgXVG4R7RQJLZMQXzIF7OkCW3HMA/y/ZvHv7V1NuVvazXnDycY2cYYIcURsrou5S4 XXHFLb/oN266eBkXUkF5zsnbzUffovyOOjlq5LDqRVgGv/47Jz/jXrdvf4F4Lr04a X-Received: by 2002:a05:6a00:190d:b0:46d:516c:4ed9 with SMTP id y13-20020a056a00190d00b0046d516c4ed9mr2959429pfi.57.1634813025967; Thu, 21 Oct 2021 03:43:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+t+eyvqxBEilF1qSUacufCy9dHNU7uvmc3/r+uEL5av1niKBR+Uxg9P01vkICIpRddJcgOQ== X-Received: by 2002:a05:6a00:190d:b0:46d:516c:4ed9 with SMTP id y13-20020a056a00190d00b0046d516c4ed9mr2959383pfi.57.1634813025597; Thu, 21 Oct 2021 03:43:45 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:45 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 6/8] pci: Use pci_for_each_root_bus() in current code Date: Thu, 21 Oct 2021 18:42:57 +0800 Message-Id: <20211021104259.57754-7-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 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" There're three places that can be rewritten with the pci_for_each_root_bus() helper that we just introduced. De-dup the code. Signed-off-by: Peter Xu Reviewed-by: David Hildenbrand Reviewed-by: Eric Auger --- hw/arm/virt-acpi-build.c | 31 +++++++++++-------------------- hw/i386/acpi-build.c | 38 ++++++++++---------------------------- 2 files changed, 21 insertions(+), 48 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 6cec97352b..54b82aa863 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -263,28 +263,20 @@ struct AcpiIortIdMapping { typedef struct AcpiIortIdMapping AcpiIortIdMapping; /* Build the iort ID mapping to SMMUv3 for a given PCI host bridge */ -static int -iort_host_bridges(Object *obj, void *opaque) +static void +iort_host_bridges(PCIBus *bus, void *opaque) { - GArray *idmap_blob = opaque; - - if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) { - PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; - - if (bus && !pci_bus_bypass_iommu(bus)) { - int min_bus, max_bus; + if (!pci_bus_bypass_iommu(bus)) { + int min_bus, max_bus; - pci_bus_range(bus, &min_bus, &max_bus); + pci_bus_range(bus, &min_bus, &max_bus); - AcpiIortIdMapping idmap = { - .input_base = min_bus << 8, - .id_count = (max_bus - min_bus + 1) << 8, - }; - g_array_append_val(idmap_blob, idmap); - } + AcpiIortIdMapping idmap = { + .input_base = min_bus << 8, + .id_count = (max_bus - min_bus + 1) << 8, + }; + g_array_append_val((GArray *)opaque, idmap); } - - return 0; } static int iort_idmap_compare(gconstpointer a, gconstpointer b) @@ -318,8 +310,7 @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) if (vms->iommu == VIRT_IOMMU_SMMUV3) { AcpiIortIdMapping next_range = {0}; - object_child_foreach_recursive(object_get_root(), - iort_host_bridges, smmu_idmaps); + pci_for_each_root_bus(iort_host_bridges, smmu_idmaps); /* Sort the smmu idmap by input_base */ g_array_sort(smmu_idmaps, iort_idmap_compare); diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index a76b17ed92..3e50acfe35 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2123,20 +2123,12 @@ insert_scope(PCIBus *bus, PCIDevice *dev, void *opaque) } /* For a given PCI host bridge, walk and insert DMAR scope */ -static int -dmar_host_bridges(Object *obj, void *opaque) +static void +dmar_host_bridges(PCIBus *bus, void *opaque) { - GArray *scope_blob = opaque; - - if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) { - PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; - - if (bus && !pci_bus_bypass_iommu(bus)) { - pci_for_each_device_under_bus(bus, insert_scope, scope_blob); - } + if (!pci_bus_bypass_iommu(bus)) { + pci_for_each_device_under_bus(bus, insert_scope, opaque); } - - return 0; } /* @@ -2165,8 +2157,7 @@ build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id, * Insert scope for each PCI bridge and endpoint device which * is attached to a bus with iommu enabled. */ - object_child_foreach_recursive(object_get_root(), - dmar_host_bridges, scope_blob); + pci_for_each_root_bus(dmar_host_bridges, scope_blob); assert(iommu); if (x86_iommu_ir_supported(iommu)) { @@ -2329,20 +2320,12 @@ insert_ivhd(PCIBus *bus, PCIDevice *dev, void *opaque) } /* For all PCI host bridges, walk and insert IVHD entries */ -static int -ivrs_host_bridges(Object *obj, void *opaque) +static void +ivrs_host_bridges(PCIBus *bus, void *opaque) { - GArray *ivhd_blob = opaque; - - if (object_dynamic_cast(obj, TYPE_PCI_HOST_BRIDGE)) { - PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; - - if (bus && !pci_bus_bypass_iommu(bus)) { - pci_for_each_device_under_bus(bus, insert_ivhd, ivhd_blob); - } + if (!pci_bus_bypass_iommu(bus)) { + pci_for_each_device_under_bus(bus, insert_ivhd, opaque); } - - return 0; } static void @@ -2380,8 +2363,7 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linker, const char *oem_id, * blob further below. Fall back to an entry covering all devices, which * is sufficient when no aliases are present. */ - object_child_foreach_recursive(object_get_root(), - ivrs_host_bridges, ivhd_blob); + pci_for_each_root_bus(ivrs_host_bridges, ivhd_blob); if (!ivhd_blob->len) { /* From patchwork Thu Oct 21 10:42:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574713 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 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. */ From patchwork Thu Oct 21 10:42:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12574721 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 6F2D8C433F5 for ; Thu, 21 Oct 2021 10:57:47 +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 1649961205 for ; Thu, 21 Oct 2021 10:57:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1649961205 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]:37298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVlZ-0004zH-4T for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:57:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVYI-0002aa-Kf for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:44:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25914) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdVYH-0004JH-3V for qemu-devel@nongnu.org; Thu, 21 Oct 2021 06:44:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634813040; 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=LAHZVTTSpFR2aYi9YoixPjZOJE9O81a6qTEA4Wx3tno=; b=hYQeYmQoci+uTgnWcZCPLpUUzW0oBHoyBZ01uBLX50f4WvGhNWokM1bF49OkAcHEsdwiiw WTNRqRjwohuEnBUdJW7P7nD1p7+dGsnT/x7ypYr43y4BmsS5OsDOQwgHhP1/SSWX12UPow zgRdxQEcFFwC14aynbPl7Vi6ZyaYyUE= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-nDf7SAVGPsukRpxukQXWSw-1; Thu, 21 Oct 2021 06:43:59 -0400 X-MC-Unique: nDf7SAVGPsukRpxukQXWSw-1 Received: by mail-pl1-f199.google.com with SMTP id h3-20020a170902704300b0013dbfc88e14so60670plt.13 for ; Thu, 21 Oct 2021 03:43:59 -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=LAHZVTTSpFR2aYi9YoixPjZOJE9O81a6qTEA4Wx3tno=; b=Bh9nsOMfePFO4fu4yf1aYs9wmoSk9dJFP2hhBmV70KT0Eio078sVpePKVBYtFuTtD6 wTOSbfLOfWL7HV/+PwMcy5Mes4kiQnOrY7JMKqY8b+dp/6apu3CeRQ0Yk60Q50kZeStz DnRjxcUuK2fb6e7Qgk4XTMyVqz6CaQ2cNs9srCBaS+FAtyMJWIxbGqkOMShyVMbI/RmQ qPLQGwbatzCAlnuaifxWvUYXCRem9gfxMyx6qcYnCEaoAezsGniQT3B7+DmGdoS3Q75t MWEhkUwWe/ZNCgMlVCzko5BNbqxzp2msCDW+tG3asIuA2Zpa8Y+yjvcoXnzBYXqneAXM EY2Q== X-Gm-Message-State: AOAM531Paqtd8rXbxjne1HsHrcYYSuhEhpId6VOI3jm5jQGJsc1aWfYj WoL7GVeYpW65jzguWRmKgLERNCY1ZV4SJbUBi9MHieuTZRjuQy2GUpRJ/ZyeehrNliRzG7CWCFD 5jdH4bGEVzXXaPwsaJTuOYeSIt4ApUQ+fhSVWfjql5KlowvhCyS+lBMSLkb7/Wbsk X-Received: by 2002:a62:7656:0:b0:44c:591b:5a42 with SMTP id r83-20020a627656000000b0044c591b5a42mr4744644pfc.57.1634813037938; Thu, 21 Oct 2021 03:43:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7T8Rrvr/LBsD+hJPH7C6Z0SSgGsqjwF5DZ0l1IK+3zQYA94se44x37sRul01libGydPdLHQ== X-Received: by 2002:a62:7656:0:b0:44c:591b:5a42 with SMTP id r83-20020a627656000000b0044c591b5a42mr4744598pfc.57.1634813037593; Thu, 21 Oct 2021 03:43:57 -0700 (PDT) Received: from localhost.localdomain ([84.17.34.135]) by smtp.gmail.com with ESMTPSA id e1sm5246893pgi.43.2021.10.21.03.43.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Oct 2021 03:43:56 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH 8/8] x86-iommu: Fail early if vIOMMU specified after vfio-pci Date: Thu, 21 Oct 2021 18:42:59 +0800 Message-Id: <20211021104259.57754-9-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 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" Scan the pci bus to make sure there's no vfio-pci device attached before vIOMMU is realized. Suggested-by: Igor Mammedov Signed-off-by: Peter Xu --- hw/i386/x86-iommu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c index 86ad03972e..58abce7edc 100644 --- a/hw/i386/x86-iommu.c +++ b/hw/i386/x86-iommu.c @@ -21,6 +21,7 @@ #include "hw/sysbus.h" #include "hw/i386/x86-iommu.h" #include "hw/qdev-properties.h" +#include "hw/vfio/pci.h" #include "hw/i386/pc.h" #include "qapi/error.h" #include "qemu/error-report.h" @@ -103,6 +104,16 @@ IommuType x86_iommu_get_type(void) return x86_iommu_default->type; } +static void x86_iommu_pci_dev_hook(PCIBus *bus, PCIDevice *dev, void *opaque) +{ + Error **errp = (Error **)opaque; + + if (object_dynamic_cast(OBJECT(dev), TYPE_VFIO_PCI)) { + error_setg(errp, "Device '%s' must be specified before vIOMMUs", + TYPE_VFIO_PCI); + } +} + static void x86_iommu_realize(DeviceState *dev, Error **errp) { X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev); @@ -120,6 +131,12 @@ static void x86_iommu_realize(DeviceState *dev, Error **errp) return; } + /* Make sure there's no special device plugged before vIOMMU */ + pci_for_each_device_all(x86_iommu_pci_dev_hook, (void *)errp); + if (*errp) { + return; + } + /* If the user didn't specify IR, choose a default value for it */ if (x86_iommu->intr_supported == ON_OFF_AUTO_AUTO) { x86_iommu->intr_supported = irq_all_kernel ? @@ -151,6 +168,7 @@ static Property x86_iommu_properties[] = { static void x86_iommu_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + dc->realize = x86_iommu_realize; device_class_set_props(dc, x86_iommu_properties); }