From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a17:906:6951:b0:a28:f940:7a27 with SMTP id c17csp6046ejs; Mon, 8 Jan 2024 12:56:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFq89fvCOcUBqUVxZfA1za8xjlkBAQsPeOEYsZTi/i4r0RodbnBIV6GA9AZQGEvCwzlO/tA X-Received: by 2002:a37:ef04:0:b0:77d:e60b:4caa with SMTP id j4-20020a37ef04000000b0077de60b4caamr4576066qkk.35.1704747367447; Mon, 08 Jan 2024 12:56:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704747367; cv=none; d=google.com; s=arc-20160816; b=hfyOdey6OJjluvuJIxPMed+KTVBjmV/moKzl6lOwf4C+Sx67xcTVu/ZdUl0m0jein4 0CVcV82uUEv/M8XCIX8A9dZJmCcFxBd4wepZPAxTYiQbQx4BJIW397Kf2/nWyJ21x2cX DyiTdLw7gCC/ldVswxtHnE62pDBGBOEUZwCDeEEAssZhk+mMJeMHgXRrvIzdjnsnrCup Iii+bfK4AyCvNcO3hG/0XSx+FGIIa27mcVhhXMmwKg2PH7U9HBBePqKx3EBOQsBNnyHd tvBZQkHIevWcMxPhV/w/KkD14USkXnCXzppb9I3I1+7Kd+HOH8DE9PNx9hAIcWsAIuxl Ul4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cethWUh/RWDV/5OHSmNNy/kAHmyOEuR7joLxV258gbE=; fh=LeOBNGHwoQQCylLh9v89P/OdTUx8jmDchZ7fstdYfbc=; b=W54y2CLeU/wlqLQWfVKsKXXMSHYU1pS5df/HBg09wIiHOs5FhjOF0QCOUbNkMUm/Ea J8gIAOyDL0To/Q4+VyERt+/Mp+2w2hHRydjJ6JfS0rIcpreHpLN1V54Xdn2WF0sk243N w9VTxob0LQZogntW+7fgzJvAe43+ykCYCourvE4GxLuStSGRN8f8LIuoRrC0EAM446/B FCBE+zamfqa77/kzUvDicvyBy/MAbkSaYbT1Q50CcnpohwMYOfAWldeBq6CaTvt94RGo 7kAI85fR+J5frZ1wE8Buw4RMZ+iR2iDt03KyYztMe1hSa+8DH7fd1F1kU2UoNwuZijZC YGnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=UWpFdiGn; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m10-20020a05620a24ca00b007816c894164si628827qkn.370.2024.01.08.12.56.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jan 2024 12:56:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=UWpFdiGn; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rMwaa-0006Fn-9K; Mon, 08 Jan 2024 15:51:17 -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 1rMwZw-00042u-5u; Mon, 08 Jan 2024 15:50:36 -0500 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rMwZq-0000vA-LM; Mon, 08 Jan 2024 15:50:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=cethWUh/RWDV/5OHSmNNy/kAHmyOEuR7joLxV258gbE=; b=UWpFdiGnLNbiORgtAtG7p/WIdU nqFdfmvFAt8+yDpmkAnslA8FXZL1a921R8Kdz47iQJ7f17BTPcH4js6e2TxfDyTYvHNY1vVjWpW+m Whc4h/FvtK2nvQOQsjYX3o41E5/ptjCAznwTkiO6CNzrlCyTe0eHM75LZR6L5bXa62NGM8JbcGUiG nXsZwYmZ5A1JpV8dCV4PEggRIKS2aDRX8EC3nqa6ZIAI3ndlm5P39xBy+k5aD+gzf0mL8IjBKgRx5 Ikfo9pWQAFrvpUXLgIHi4y8C+yztqZohoFPmmZ09XXK8DdZpROKs9MJnq6Y8exAPocL+bH4EWAJFd D2vqX0yA==; Received: from [2001:8b0:10b:1::ebe] (helo=i7.infradead.org) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1rMwYi-008RPO-0H; Mon, 08 Jan 2024 20:49:21 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.96.2 #2 (Red Hat Linux)) id 1rMwYi-002NEB-22; Mon, 08 Jan 2024 20:49:20 +0000 From: David Woodhouse To: qemu-devel@nongnu.org Cc: Richard Henderson , Beniamino Galvani , Peter Maydell , Strahinja Jankovic , Niek Linnenbank , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Andrew Jeffery , Joel Stanley , Igor Mitsyanko , Jean-Christophe Dubois , Andrey Smirnov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rob Herring , Subbaraya Sundeep , Jan Kiszka , Tyrone Ting , Hao Wu , Radoslaw Biernacki , Leif Lindholm , Marcin Juszkiewicz , "Edgar E. Iglesias" , Alistair Francis , Helge Deller , Paolo Bonzini , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , Song Gao , Thomas Huth , Laurent Vivier , Huacai Chen , Jiaxun Yang , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Aleksandar Rikalo , Aurelien Jarno , Jason Wang , Jia Liu , Stafford Horne , Mark Cave-Ayland , Nicholas Piggin , Daniel Henrique Barboza , David Gibson , Harsh Prateek Bora , Bin Meng , Palmer Dabbelt , Weiwei Li , Liu Zhiwei , Halil Pasic , Christian Borntraeger , Eric Farman , David Hildenbrand , Ilya Leoshkevich , Yoshinori Sato , Magnus Damm , Artyom Tarasenko , Stefano Stabellini , Anthony Perard , Paul Durrant , Max Filippov , qemu-arm@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, xen-devel@lists.xenproject.org, David Woodhouse Subject: [PATCH v3 04/46] hw/pci: add pci_init_nic_devices(), pci_init_nic_in_slot() Date: Mon, 8 Jan 2024 20:26:33 +0000 Message-ID: <20240108204909.564514-5-dwmw2@infradead.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240108204909.564514-1-dwmw2@infradead.org> References: <20240108204909.564514-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Received-SPF: none client-ip=2001:8b0:10b:1236::1; envelope-from=BATV+41a72dc6539c0dfbbc31+7442+infradead.org+dwmw2@casper.srs.infradead.org; helo=casper.infradead.org X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@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-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: GbJ6wICm7L8Z From: David Woodhouse The loop over nd_table[] to add PCI NICs is repeated in quite a few places. Add a helper function to do it. Some platforms also try to instantiate a specific model in a specific slot, to match the real hardware. Add pci_init_nic_in_slot() for that purpose. Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- hw/pci/pci.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 4 +++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 76080af580..5849606f66 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1925,6 +1925,51 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, return pci_dev; } +void pci_init_nic_devices(PCIBus *bus, const char *default_model) +{ + qemu_create_nic_bus_devices(&bus->qbus, TYPE_PCI_DEVICE, default_model, + "virtio", "virtio-net-pci"); +} + +bool pci_init_nic_in_slot(PCIBus *rootbus, const char *model, + const char *alias, const char *devaddr) +{ + NICInfo *nd = qemu_find_nic_info(model, true, alias); + int dom, busnr, devfn; + PCIDevice *pci_dev; + unsigned slot; + PCIBus *bus; + + if (!nd) { + return false; + } + + if (!devaddr || pci_parse_devaddr(devaddr, &dom, &busnr, &slot, NULL) < 0) { + error_report("Invalid PCI device address %s for device %s", + devaddr, model); + exit(1); + } + + if (dom != 0) { + error_report("No support for non-zero PCI domains"); + exit(1); + } + + devfn = PCI_DEVFN(slot, 0); + + bus = pci_find_bus_nr(rootbus, busnr); + if (!bus) { + error_report("Invalid PCI device address %s for device %s", + devaddr, model); + exit(1); + } + + pci_dev = pci_new(devfn, model); + qdev_set_nic_properties(&pci_dev->qdev, nd); + pci_realize_and_unref(pci_dev, bus, &error_fatal); + return true; +} + PCIDevice *pci_vga_init(PCIBus *bus) { vga_interface_created = true; diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index fa6313aabc..6ff0b95a02 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -317,7 +317,9 @@ void pci_device_reset(PCIDevice *dev); PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model, const char *default_devaddr); - +void pci_init_nic_devices(PCIBus *bus, const char *default_model); +bool pci_init_nic_in_slot(PCIBus *rootbus, const char *default_model, + const char *alias, const char *devaddr); PCIDevice *pci_vga_init(PCIBus *bus); static inline PCIBus *pci_get_bus(const PCIDevice *dev) -- 2.41.0