From nobody Wed Feb 11 01:09:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1668615224; cv=none; d=zohomail.com; s=zohoarc; b=B5o7sdI+oclciLgRuID+SGy3z/3/F+uydQXOlhFX+TEmHNFQD3eOVPkruPANjuK3Yctyg2fUfowt+uWlzAhSizuwPizNx/RW2bXhyw6vbhUN/aezMav/B97ols1OC0OHawQsJ95gIcY4psAaggFzmUSLyJdL9qAhIakUfqZSDPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668615224; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pXL2EsPAT+iu0OJdzb46Em8htiMdE0Ui/fug/j2J5HI=; b=LrQbju6RBrNgrp420LG81Q4M9//SqX3RRUFpOT1ZiCaejzo+kOkI4t88XRmYUCVeBjMo6cl6O3AxJslxq8s6dlZ4z72s/WC9y5Y6EJYc6BJi3tTjluCOdtkI3N0hFXTmTl9DPbq6MsnnkSPeGuaVuXaPfmF1T2v7e9xbKSZfD7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1668615224302510.13505159691977; Wed, 16 Nov 2022 08:13:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovL2D-0007gS-JV; Wed, 16 Nov 2022 11:13:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovL26-0007fn-R5 for qemu-devel@nongnu.org; Wed, 16 Nov 2022 11:13:02 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ovL25-0000ey-85 for qemu-devel@nongnu.org; Wed, 16 Nov 2022 11:13:02 -0500 Received: from vla5-b2806cb321eb.qloud-c.yandex.net (vla5-b2806cb321eb.qloud-c.yandex.net [IPv6:2a02:6b8:c18:3e0d:0:640:b280:6cb3]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTP id AC52F600F5; Wed, 16 Nov 2022 19:12:45 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:8128::1:3]) by vla5-b2806cb321eb.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6qDkL1QYoB-CjO0pUUi; Wed, 16 Nov 2022 19:12:45 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1668615165; bh=pXL2EsPAT+iu0OJdzb46Em8htiMdE0Ui/fug/j2J5HI=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=Qqi19rsxBMEoDiY/v5LqhDhpO+ultO3rmWxAwY+9m4dJh79dYt6R2S9Fo1eFg7ktN DBc1RBYqsiaf/nYBYpZn4vBBarPrIcasCQH7Z60a/Iiv3TSgyvEhtGw12ePIu7b4JZ O7g+NfZ14qnBQ1rvFl7n7yaPugp24mVhq3Af+2xA= Authentication-Results: vla5-b2806cb321eb.qloud-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: eduardo@habkost.net, berrange@redhat.com, pbonzini@redhat.com, armbru@redhat.com, eblake@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com, imammedo@redhat.com, ani@anisinha.ca, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 1/2] hw/pci/shpc: introduce FOR_EACH_DEVICE_IN_SLOT Date: Wed, 16 Nov 2022 19:12:33 +0300 Message-Id: <20221116161234.44206-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221116161234.44206-1-vsementsov@yandex-team.ru> References: <20221116161234.44206-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1668615306725100001 Content-Type: text/plain; charset="utf-8" Introduce a macro to loop through devices like in shpc_free_devices_in_slot(), as we are going to add one more similar function. Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/pci/shpc.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/hw/pci/shpc.c b/hw/pci/shpc.c index e71f3a7483..ba241e2818 100644 --- a/hw/pci/shpc.c +++ b/hw/pci/shpc.c @@ -236,22 +236,41 @@ static void shpc_invalid_command(SHPCDevice *shpc) SHPC_CMD_STATUS_INVALID_CMD); } =20 -static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot) +static PCIDevice *shpc_next_device_in_slot(SHPCDevice *shpc, int slot, + int *start_devfn) { - HotplugHandler *hotplug_ctrl; int devfn; int pci_slot =3D SHPC_IDX_TO_PCI(slot); - for (devfn =3D PCI_DEVFN(pci_slot, 0); + + for (devfn =3D *start_devfn ?: PCI_DEVFN(pci_slot, 0); devfn <=3D PCI_DEVFN(pci_slot, PCI_FUNC_MAX - 1); ++devfn) { - PCIDevice *affected_dev =3D shpc->sec_bus->devices[devfn]; - if (affected_dev) { - hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(affected_dev)= ); - hotplug_handler_unplug(hotplug_ctrl, DEVICE(affected_dev), - &error_abort); - object_unparent(OBJECT(affected_dev)); + PCIDevice *dev =3D shpc->sec_bus->devices[devfn]; + if (dev) { + *start_devfn =3D devfn + 1; /* for next iteration */ + return dev; } } + + return NULL; +} + +#define FOR_EACH_DEVICE_IN_SLOT(shpc, slot, dev, devfn) \ + for ((devfn) =3D 0, \ + (dev) =3D shpc_next_device_in_slot((shpc), (slot), &(devfn)); \ + (dev); (dev) =3D shpc_next_device_in_slot((shpc), (slot), &(devfn= ))) + +static void shpc_free_devices_in_slot(SHPCDevice *shpc, int slot) +{ + HotplugHandler *hotplug_ctrl; + int devfn; + PCIDevice *dev; + + FOR_EACH_DEVICE_IN_SLOT(shpc, slot, dev, devfn) { + hotplug_ctrl =3D qdev_get_hotplug_handler(DEVICE(dev)); + hotplug_handler_unplug(hotplug_ctrl, DEVICE(dev), &error_abort); + object_unparent(OBJECT(dev)); + } } =20 static void shpc_slot_command(SHPCDevice *shpc, uint8_t target, --=20 2.34.1