From nobody Mon Apr 29 18:12:43 2024 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=reject dis=none) header.from=aol.com ARC-Seal: i=1; a=rsa-sha256; t=1673301424; cv=none; d=zohomail.com; s=zohoarc; b=HUT+K1toFDthkCLb9cMk/tfD8oQliR8KbUZiPtr4niCl8JLzNbLurmU3d/GHJR56Q0t3FavRT1JgBQ7zE+rVPwO+Gzz6ItYuNxWanEpeiGCS7NUIxis1xmpuKdK3UZ9DmKfW8IW9Qki7plfVc1AkJQztXyuCQ45qfLKShE07nW8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673301424; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XmjEY3smFSBeH1GvhJfSTsSYJbxF46CwAKG5dAKcmRI=; b=H/Ifs8n173V/JlTxpPDqMLitiTltQ1FNo53uXM18tqSZTnPZv0tVtk7DIZRsD/rj6/oBg6QxucmzdG2aYhylI9AfkBeH4igVQk+wRnJ8F5FYQs8WaFdrEJXlwv3fsgiQUsLouMQy9EH2PVZNN99C41bHoMf33bzLMV7DGTa0aU0= 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=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167330142472171.55951530655466; Mon, 9 Jan 2023 13:57:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pF07r-0007Oj-6X; Mon, 09 Jan 2023 16:56:15 -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 1pF07p-0007Nw-OT for qemu-devel@nongnu.org; Mon, 09 Jan 2023 16:56:13 -0500 Received: from sonic312-24.consmr.mail.gq1.yahoo.com ([98.137.69.205]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pF07l-0005vZ-KN for qemu-devel@nongnu.org; Mon, 09 Jan 2023 16:56:13 -0500 Received: from sonic.gate.mail.ne1.yahoo.com by sonic312.consmr.mail.gq1.yahoo.com with HTTP; Mon, 9 Jan 2023 21:56:03 +0000 Received: by hermes--production-ne1-7b69748c4d-drrwg (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 3063e915763b79494c5a1a49c3c8038d; Mon, 09 Jan 2023 21:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1673301363; bh=XmjEY3smFSBeH1GvhJfSTsSYJbxF46CwAKG5dAKcmRI=; h=From:To:Cc:Subject:Date:References:From:Subject:Reply-To; b=XQ4jxMvUKo2m81vt7fXP25qsUhR1PI6kigX4sFvJZ89oiNMiM0L1oeUygYTBH2w/MnnXB6LLsgprZ1eETJsBJUZU7unMRYVFvuQgiqKSfGq6k0lfkLJA/XuPjLw/OVCPMwELYfwhfWvqJhRygAW2g21Onrw4Kdjo0yOI5Hc0dr5X0Y+qMuutFrGDVLUOFIjiOfwXvLISDGUrKqH4QWciOB9bpYFw1UsQiax8pWoKDgTEM7SqdJH8jMcOdo62agw/QY2eYzmMTZLv8wfSxF7izdB90v6dCbENHe5FqRFKmjMyMZK+wFUodJE1LWuv3CBfY3fD0Bnn/qlBrqb3PPtrbQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1673301363; bh=lcJGVb/afW/9QWvR+7d3BL+WwFDW/zQtJ9DNlrryTAD=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=QOgQo3tegk8jmBv3Ng7w79LJ/aNZzX5ERi9ymMQFCrWbayQ8uUhDFy0obt6l2lWh2qOHi1fd0LHR93v7XeI9OREnDWnXEVMs2yUZJk5NYDwKtqMRsBjK+TRmMq5lLv0YjnlPIN+FuBaa/P8esnQ3iFqaJ6kEmLPH/ebhYypsHFaL7EhDWTj2YdS6910kIBJo1yUbfe7V3bRH1GAszdULZEUUNHZ2kM8CcksfbHeK0b2CRgIK/aWdevby31waCzAPrfnCwxt6HHtKovcC4b162AwrEyWXRaXdRAIYomU5Wu2aLZ5dFxZ7nPjOKAi2c5y0/SlzRy2xCD8cDmj766CObg== X-YMail-OSG: jD7hKu8VM1l0oOLuaqgRaeb30aQv6Qp.ODCmKP8f6Q9mBSVWzcsfDNYVsykA2ho behgY_jMFk_aXME9xrjnRS_UbMzJzOjYrDdoHuBBzXjRybX5ZJpAKTcm5mQC_sDQTYgOe.ec_iAM Myn.yvyAZfixP0ZhyiSdQHFTK4O7S1mYEbP_EnvNTk1wCOGbXUWhRrwUwfT7ysui.KhNPs4WfHNE ss69qDq30QYPN.igM4i96y25hYBsFq9PPfxFB7Lj07UuZt7Y9dzwZo14h77gQ6KOw4p0GuHrcNIp OL_JGjZOopff5u5r__uhwXfmZVS9mH5QdZf4HePHJbfgydDeo8DCbqlxl9FSCeMBB.8ly6bOnY1L fNW9Mq5UyvPhekEHUZa.cr1Plr6__p3mLtRSkefaiL8NldguAqJxo7J.2GWQjFItbcRwNuekenlP uqfUoZ_WITspASb_vkBokN3PhGG7UwY.4InnuWo3wNlez3CtngNLdJy0n59mgEb9ODF3tv96dXAx 2Z3OEyVG7Rx4F0ceHoO9l4h_GVKrkX326EfaLiYvWeqAxw27WRowzgPWhcJjnk90pQSacKJnQhgV YUUDyV13LFZmhT56JVJ5ZsS8hOh0b3O1lFxsrUcP17XrLk1cd3ExodjeHQy9KqmVQUftBIGeXOhC wi8zEb.Og9kAVPf88sGf0uCFmn8egoa4F03lP4p0bBLeIUWPc19V9Nxoq0ubKb77g0ZDNbGM6WgP TzOou3wKPVh6EVSQFmExoBO.KvctLL5GwwwUtb1U4joolbv2p.AIeleTYmoetMIF7vWRhnsnffXj PnxAYJSGenBv17Y6fL9GsxI6VEQDYEUwgkCB_IZnFQIVz4j2eAfjV46LMX7kfAqPTvMQ0fjRet1L .4PDQda5tboB8o1lJN29wjT7m_LI_.y5MY33uUWbqS87og.ChzviNmVN8R3MQwYtFecpX0PhyvnP 4kOnn5qRgEaC0aL9wSR6G6X44ucjrtWUXvsjLxRib91kWnnvxP3qajCnnUMbCgG51Q1ZByeE6zpW YdJO.EFMvbsk_P1uCPdJY2ruXmtNf6NhfiSQBXd9Rc.sCZXJz38sR0_Yj2IXUuIVWGVTo.KyIbwa aKctdmpnN0MLzBy4SxVkXP9RmSAXpKDQDDqkSI3_FmU_2jYvrSlEORoJUta44jh_CmzLGD9D9RpE GtYlfbu73Wvr_OR3UqtG97pTwxWzct9qsFmGqcTrnJ1jSVqCHvFXpZMYfQ10Fs5UzBalA5qi01zC u7DJo2ajgyrXRVAHpMatMXzxXVTSOJaI2o6b_5NADyxHasar5U8EfUQxOA2T9mm9jwwnei9kaPuH X19Poc7zTetiMVRLtEgBfMYJfOyq2CTMpOpaWRD6Uh6ZgWi8l9NysycpuGVsH.ecj2KqwtZ5oJFW KcnTKZUoL8epoDkWNWXNQxAgUcJPHwtDzoogyzwTqpEf1SQBQ0QRH4Ec7XacoBtCYNXfFCs28x_o eBVi9bI0v8e8u6TtjoN9gumUJ5RBlvxoMd90_CdiQ3Kki5XA1yDZKNPEDogWz1n2rqbppweaOIjx LibIevRK3I86zHkKsWZc4I5XDQCOpNm7oiPn2kuvDstRyZM.TVLVC3FbZEO.oV2z7pMdLeVVj_uq ncCUF1idA.F1GO3HcwrmBWdPzlNjxIt_Iy.jlgrNBCMLadpHitdH7vEK2LptFnVlmLIvug1EYBO. sDyWyOOPhrH_N07SPb2UnXVnT4YHflcctzylOwYjtZoiDaSX1fuhiUwt1OFopV2la7OTn0cOPBKS qF8mpGMgHwAHLd.4Z5U.QsTaSvLwTn.o3twGe0jZ4PqP1bAXGFNn4rIZMoRfcUZbwUxlNRhtfvLP wkmzXtBeNTcgzlwsJTBOXU9cSb3ufinbkNSBzifJsp49v4jCV4cPTchJtB1xbu5S3ikvCpvNILpI MX_XcDsT7s.YlEqNQYFtA6vILJifBpdjyErNLDcVyru7a9CvXniTmoJebP.gF8al7iHYJiSVUAG2 Vrz_zgbHeYkJvq6Wa1hERRnpXFjSXOOC36mIep93Mpy4QDHLRagXhPJURx7znW._g989jDQjb0oO Nq7_Fza3JFyu2L2y75ql9ZE8IlrcIoF0da8gd8KrS_b7jWGHQ7K0LWi9GnomoOcMs1b26_Q_Ir1n FOHmWVywIISIOGTISU2ulzbCuvDunxL6flF5FMPvYLqr0hs4RFfQEJPaahPD1GXbDmudEP2YvCR9 Yhgn1kyE- X-Sonic-MF: From: Chuck Zmudzinski To: qemu-devel@nongnu.org Cc: Stefano Stabellini , Anthony Perard , Paul Durrant , Paolo Bonzini , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum , xen-devel@lists.xenproject.org Subject: [PATCH v7] xen/pt: reserve PCI slot 2 for Intel igd-passthru Date: Mon, 9 Jan 2023 16:55:42 -0500 Message-Id: <8349506149de6d81b0762f17623552c248439e93.1673297742.git.brchuckz@aol.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable References: <8349506149de6d81b0762f17623552c248439e93.1673297742.git.brchuckz.ref@aol.com> Content-Length: 19874 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=98.137.69.205; envelope-from=brchuckz@aim.com; helo=sonic312-24.consmr.mail.gq1.yahoo.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.096, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 @aol.com) X-ZM-MESSAGEID: 1673301426721100003 Content-Type: text/plain; charset="utf-8" Intel specifies that the Intel IGD must occupy slot 2 on the PCI bus, as noted in docs/igd-assign.txt in the Qemu source code. Currently, when the xl toolstack is used to configure a Xen HVM guest with Intel IGD passthrough to the guest with the Qemu upstream device model, a Qemu emulated PCI device will occupy slot 2 and the Intel IGD will occupy a different slot. This problem often prevents the guest from booting. The only available workaround is not good: Configure Xen HVM guests to use the old and no longer maintained Qemu traditional device model available from xenbits.xen.org which does reserve slot 2 for the Intel IGD. To implement this feature in the Qemu upstream device model for Xen HVM guests, introduce the following new functions, types, and macros: * XEN_PT_DEVICE_CLASS declaration, based on the existing TYPE_XEN_PT_DEVICE * XEN_PT_DEVICE_GET_CLASS macro helper function for XEN_PT_DEVICE_CLASS * typedef XenPTQdevRealize function pointer * XEN_PCI_IGD_SLOT_MASK, the value of slot_reserved_mask to reserve slot 2 * xen_igd_reserve_slot and xen_igd_clear_slot functions The new xen_igd_reserve_slot function uses the existing slot_reserved_mask member of PCIBus to reserve PCI slot 2 for Xen HVM guests configured using the xl toolstack with the gfx_passthru option enabled, which sets the igd-passthru=3Don option to Qemu for the Xen HVM machine type. The new xen_igd_reserve_slot function also needs to be implemented in hw/xen/xen_pt_stub.c to prevent FTBFS during the link stage for the case when Qemu is configured with --enable-xen and --disable-xen-pci-passthrough, in which case it does nothing. The new xen_igd_clear_slot function overrides qdev->realize of the parent PCI device class to enable the Intel IGD to occupy slot 2 on the PCI bus since slot 2 was reserved by xen_igd_reserve_slot when the PCI bus was created in hw/i386/pc_piix.c for the case when igd-passthru=3Don. Move the call to xen_host_pci_device_get, and the associated error handling, from xen_pt_realize to the new xen_igd_clear_slot function to initialize the device class and vendor values which enables the checks for the Intel IGD to succeed. The verification that the host device is an Intel IGD to be passed through is done by checking the domain, bus, slot, and function values as well as by checking that gfx_passthru is enabled, the device class is VGA, and the device vendor in Intel. Signed-off-by: Chuck Zmudzinski --- Notes that might be helpful to reviewers of patched code in hw/xen: The new functions and types are based on recommendations from Qemu docs: https://qemu.readthedocs.io/en/latest/devel/qom.html Notes that might be helpful to reviewers of patched code in hw/i386: The small patch to hw/i386/pc_piix.c is protected by CONFIG_XEN so it does not affect builds that do not have CONFIG_XEN defined. xen_igd_gfx_pt_enabled() in the patched hw/i386/pc_piix.c file is an existing function that is only true when Qemu is built with xen-pci-passthrough enabled and the administrator has configured the Xen HVM guest with Qemu's igd-passthru=3Don option. v2: Remove From: tag at top of commit message v3: Changed the test for the Intel IGD in xen_igd_clear_slot: if (is_igd_vga_passthrough(&s->real_device) && (s->real_device.vendor_id =3D=3D PCI_VENDOR_ID_INTEL)) { is changed to if (xen_igd_gfx_pt_enabled() && (s->hostaddr.slot =3D=3D 2) && (s->hostaddr.function =3D=3D 0)) { I hoped that I could use the test in v2, since it matches the other tests for the Intel IGD in Qemu and Xen, but those tests do not work because the necessary data structures are not set with their values yet. So instead use the test that the administrator has enabled gfx_passthru and the device address on the host is 02.0. This test does detect the Intel IGD correctly. v4: Use brchuckz@aol.com instead of brchuckz@netscape.net for the author's email address to match the address used by the same author in commits be9c61da and c0e86b76 =20 Change variable for XEN_PT_DEVICE_CLASS: xptc changed to xpdc v5: The patch of xen_pt.c was re-worked to allow a more consistent test for the Intel IGD that uses the same criteria as in other places. This involved moving the call to xen_host_pci_device_get from xen_pt_realize to xen_igd_clear_slot and updating the checks for the Intel IGD in xen_igd_clear_slot: =20 if (xen_igd_gfx_pt_enabled() && (s->hostaddr.slot =3D=3D 2) && (s->hostaddr.function =3D=3D 0)) { is changed to if (is_igd_vga_passthrough(&s->real_device) && s->real_device.domain =3D=3D 0 && s->real_device.bus =3D=3D 0 && s->real_device.dev =3D=3D 2 && s->real_device.func =3D=3D 0 && s->real_device.vendor_id =3D=3D PCI_VENDOR_ID_INTEL) { Added an explanation for the move of xen_host_pci_device_get from xen_pt_realize to xen_igd_clear_slot to the commit message. Rebase. v6: Fix logging by removing these lines from the move from xen_pt_realize to xen_igd_clear_slot that was done in v5: XEN_PT_LOG(d, "Assigning real physical device %02x:%02x.%d" " to devfn 0x%x\n", s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function, s->dev.devfn); This log needs to be in xen_pt_realize because s->dev.devfn is not set yet in xen_igd_clear_slot. v7: Inhibit out of context log message and needless processing by adding 2 lines at the top of the new xen_igd_clear_slot function: if (!(pci_bus->slot_reserved_mask & XEN_PCI_IGD_SLOT_MASK)) return; Rebase. This removed an unnecessary header file from xen_pt.h=20 hw/i386/pc_piix.c | 127 ++++++++++++++++++++++++++++++++----------- hw/xen/xen_pt.c | 49 ++++++++++++++--- hw/xen/xen_pt.h | 16 ++++++ hw/xen/xen_pt_stub.c | 4 ++ 4 files changed, 154 insertions(+), 42 deletions(-) diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index b48047f50c..34a9736b5e 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -32,6 +32,7 @@ #include "hw/i386/pc.h" #include "hw/i386/apic.h" #include "hw/pci-host/i440fx.h" +#include "hw/rtc/mc146818rtc.h" #include "hw/southbridge/piix.h" #include "hw/display/ramfb.h" #include "hw/firmware/smbios.h" @@ -40,16 +41,16 @@ #include "hw/usb.h" #include "net/net.h" #include "hw/ide/pci.h" -#include "hw/ide/piix.h" #include "hw/irq.h" #include "sysemu/kvm.h" #include "hw/kvm/clock.h" #include "hw/sysbus.h" +#include "hw/i2c/i2c.h" #include "hw/i2c/smbus_eeprom.h" #include "hw/xen/xen-x86.h" +#include "hw/xen/xen.h" #include "exec/memory.h" #include "hw/acpi/acpi.h" -#include "hw/acpi/piix4.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "sysemu/xen.h" @@ -66,6 +67,7 @@ #include "kvm/kvm-cpu.h" =20 #define MAX_IDE_BUS 2 +#define XEN_IOAPIC_NUM_PIRQS 128ULL =20 #ifdef CONFIG_IDE_ISA static const int ide_iobase[MAX_IDE_BUS] =3D { 0x1f0, 0x170 }; @@ -73,6 +75,32 @@ static const int ide_iobase2[MAX_IDE_BUS] =3D { 0x3f6, 0= x376 }; static const int ide_irq[MAX_IDE_BUS] =3D { 14, 15 }; #endif =20 +/* + * Return the global irq number corresponding to a given device irq + * pin. We could also use the bus number to have a more precise mapping. + */ +static int pci_slot_get_pirq(PCIDevice *pci_dev, int pci_intx) +{ + int slot_addend; + slot_addend =3D PCI_SLOT(pci_dev->devfn) - 1; + return (pci_intx + slot_addend) & 3; +} + +static void piix_intx_routing_notifier_xen(PCIDevice *dev) +{ + int i; + + /* Scan for updates to PCI link routes (0x60-0x63). */ + for (i =3D 0; i < PIIX_NUM_PIRQS; i++) { + uint8_t v =3D dev->config_read(dev, PIIX_PIRQCA + i, 1); + if (v & 0x80) { + v =3D 0; + } + v &=3D 0xf; + xen_set_pci_link_route(i, v); + } +} + /* PC hardware initialisation */ static void pc_init1(MachineState *machine, const char *host_type, const char *pci_type) @@ -84,7 +112,7 @@ static void pc_init1(MachineState *machine, MemoryRegion *system_io =3D get_system_io(); PCIBus *pci_bus; ISABus *isa_bus; - int piix3_devfn =3D -1; + Object *piix4_pm; qemu_irq smi_irq; GSIState *gsi_state; BusState *idebus[MAX_IDE_BUS]; @@ -205,10 +233,9 @@ static void pc_init1(MachineState *machine, gsi_state =3D pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled); =20 if (pcmc->pci_enabled) { - PIIX3State *piix3; + DeviceState *dev; PCIDevice *pci_dev; - const char *type =3D xen_enabled() ? TYPE_PIIX3_XEN_DEVICE - : TYPE_PIIX3_DEVICE; + int i; =20 pci_bus =3D i440fx_init(pci_type, i440fx_host, @@ -216,21 +243,65 @@ static void pc_init1(MachineState *machine, x86ms->below_4g_mem_size, x86ms->above_4g_mem_size, pci_memory, ram_memory); + pci_bus_map_irqs(pci_bus, + xen_enabled() ? xen_pci_slot_get_pirq + : pci_slot_get_pirq); pcms->bus =3D pci_bus; =20 - pci_dev =3D pci_create_simple_multifunction(pci_bus, -1, true, typ= e); - piix3 =3D PIIX3_PCI_DEVICE(pci_dev); - piix3->pic =3D x86ms->gsi; - piix3_devfn =3D piix3->dev.devfn; - isa_bus =3D ISA_BUS(qdev_get_child_bus(DEVICE(piix3), "isa.0")); + pci_dev =3D pci_new_multifunction(-1, true, TYPE_PIIX3_DEVICE); + object_property_set_bool(OBJECT(pci_dev), "has-usb", + machine_usb(machine), &error_abort); + object_property_set_bool(OBJECT(pci_dev), "has-acpi", + x86_machine_is_acpi_enabled(x86ms), + &error_abort); + qdev_prop_set_uint32(DEVICE(pci_dev), "smb_io_base", 0xb100); + object_property_set_bool(OBJECT(pci_dev), "smm-enabled", + x86_machine_is_smm_enabled(x86ms), + &error_abort); + pci_realize_and_unref(pci_dev, pci_bus, &error_fatal); + + if (xen_enabled()) { + pci_device_set_intx_routing_notifier( + pci_dev, piix_intx_routing_notifier_xen); + + /* + * Xen supports additional interrupt routes from the PCI devic= es to + * the IOAPIC: the four pins of each PCI device on the bus are= also + * connected to the IOAPIC directly. + * These additional routes can be discovered through ACPI. + */ + pci_bus_irqs(pci_bus, xen_intx_set_irq, pci_dev, + XEN_IOAPIC_NUM_PIRQS); + } + + dev =3D DEVICE(object_resolve_path_component(OBJECT(pci_dev), "pic= ")); + for (i =3D 0; i < ISA_NUM_IRQS; i++) { + qdev_connect_gpio_out(dev, i, x86ms->gsi[i]); + } + isa_bus =3D ISA_BUS(qdev_get_child_bus(DEVICE(pci_dev), "isa.0")); + rtc_state =3D ISA_DEVICE(object_resolve_path_component(OBJECT(pci_= dev), + "rtc")); + piix4_pm =3D object_resolve_path_component(OBJECT(pci_dev), "pm"); + dev =3D DEVICE(object_resolve_path_component(OBJECT(pci_dev), "ide= ")); + pci_ide_create_devs(PCI_DEVICE(dev)); + idebus[0] =3D qdev_get_child_bus(dev, "ide.0"); + idebus[1] =3D qdev_get_child_bus(dev, "ide.1"); } else { pci_bus =3D NULL; + piix4_pm =3D NULL; isa_bus =3D isa_bus_new(NULL, get_system_memory(), system_io, &error_abort); + isa_bus_irqs(isa_bus, x86ms->gsi); + + rtc_state =3D isa_new(TYPE_MC146818_RTC); + qdev_prop_set_int32(DEVICE(rtc_state), "base_year", 2000); + isa_realize_and_unref(rtc_state, isa_bus, &error_fatal); + i8257_dma_init(isa_bus, 0); pcms->hpet_enabled =3D false; + idebus[0] =3D NULL; + idebus[1] =3D NULL; } - isa_bus_irqs(isa_bus, x86ms->gsi); =20 if (x86ms->pic =3D=3D ON_OFF_AUTO_ON || x86ms->pic =3D=3D ON_OFF_AUTO_= AUTO) { pc_i8259_create(isa_bus, gsi_state->i8259_irq); @@ -252,18 +323,12 @@ static void pc_init1(MachineState *machine, } =20 /* init basic PC hardware */ - pc_basic_device_init(pcms, isa_bus, x86ms->gsi, &rtc_state, true, + pc_basic_device_init(pcms, isa_bus, x86ms->gsi, rtc_state, true, 0x4); =20 pc_nic_init(pcmc, isa_bus, pci_bus); =20 if (pcmc->pci_enabled) { - PCIDevice *dev; - - dev =3D pci_create_simple(pci_bus, piix3_devfn + 1, TYPE_PIIX3_IDE= ); - pci_ide_create_devs(dev); - idebus[0] =3D qdev_get_child_bus(&dev->qdev, "ide.0"); - idebus[1] =3D qdev_get_child_bus(&dev->qdev, "ide.1"); pc_cmos_init(pcms, idebus[0], idebus[1], rtc_state); } #ifdef CONFIG_IDE_ISA @@ -289,21 +354,9 @@ static void pc_init1(MachineState *machine, } #endif =20 - if (pcmc->pci_enabled && machine_usb(machine)) { - pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci"); - } - - if (pcmc->pci_enabled && x86_machine_is_acpi_enabled(X86_MACHINE(pcms)= )) { - PCIDevice *piix4_pm; - + if (piix4_pm) { smi_irq =3D qemu_allocate_irq(pc_acpi_smi_interrupt, first_cpu, 0); - piix4_pm =3D pci_new(piix3_devfn + 3, TYPE_PIIX4_PM); - qdev_prop_set_uint32(DEVICE(piix4_pm), "smb_io_base", 0xb100); - qdev_prop_set_bit(DEVICE(piix4_pm), "smm-enabled", - x86_machine_is_smm_enabled(x86ms)); - pci_realize_and_unref(piix4_pm, pci_bus, &error_fatal); =20 - qdev_connect_gpio_out(DEVICE(piix4_pm), 0, x86ms->gsi[9]); qdev_connect_gpio_out_named(DEVICE(piix4_pm), "smi-irq", 0, smi_ir= q); pcms->smbus =3D I2C_BUS(qdev_get_child_bus(DEVICE(piix4_pm), "i2c"= )); /* TODO: Populate SPD eeprom data. */ @@ -315,7 +368,7 @@ static void pc_init1(MachineState *machine, object_property_allow_set_link, OBJ_PROP_LINK_STRONG); object_property_set_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_P= ROP, - OBJECT(piix4_pm), &error_abort); + piix4_pm, &error_abort); } =20 if (machine->nvdimms_state->is_enabled) { @@ -405,6 +458,9 @@ static void pc_xen_hvm_init(MachineState *machine) } =20 pc_xen_hvm_init_pci(machine); + if (xen_igd_gfx_pt_enabled()) { + xen_igd_reserve_slot(pcms->bus); + } pci_create_simple(pcms->bus, -1, "xen-platform"); } #endif @@ -441,6 +497,11 @@ static void pc_i440fx_8_0_machine_options(MachineClass= *m) pc_i440fx_machine_options(m); m->alias =3D "pc"; m->is_default =3D true; +#ifdef CONFIG_MICROVM_DEFAULT + m->is_default =3D false; +#else + m->is_default =3D true; +#endif } =20 DEFINE_I440FX_MACHINE(v8_0, "pc-i440fx-8.0", NULL, diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 0ec7e52183..eff38155ef 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -780,15 +780,6 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function, s->dev.devfn); =20 - xen_host_pci_device_get(&s->real_device, - s->hostaddr.domain, s->hostaddr.bus, - s->hostaddr.slot, s->hostaddr.function, - errp); - if (*errp) { - error_append_hint(errp, "Failed to \"open\" the real pci device"); - return; - } - s->is_virtfn =3D s->real_device.is_virtfn; if (s->is_virtfn) { XEN_PT_LOG(d, "%04x:%02x:%02x.%d is a SR-IOV Virtual Function\n", @@ -950,11 +941,50 @@ static void xen_pci_passthrough_instance_init(Object = *obj) PCI_DEVICE(obj)->cap_present |=3D QEMU_PCI_CAP_EXPRESS; } =20 +void xen_igd_reserve_slot(PCIBus *pci_bus) +{ + XEN_PT_LOG(0, "Reserving PCI slot 2 for IGD\n"); + pci_bus->slot_reserved_mask |=3D XEN_PCI_IGD_SLOT_MASK; +} + +static void xen_igd_clear_slot(DeviceState *qdev, Error **errp) +{ + ERRP_GUARD(); + PCIDevice *pci_dev =3D (PCIDevice *)qdev; + XenPCIPassthroughState *s =3D XEN_PT_DEVICE(pci_dev); + XenPTDeviceClass *xpdc =3D XEN_PT_DEVICE_GET_CLASS(s); + PCIBus *pci_bus =3D pci_get_bus(pci_dev); + + if (!(pci_bus->slot_reserved_mask & XEN_PCI_IGD_SLOT_MASK)) + return; + + xen_host_pci_device_get(&s->real_device, + s->hostaddr.domain, s->hostaddr.bus, + s->hostaddr.slot, s->hostaddr.function, + errp); + if (*errp) { + error_append_hint(errp, "Failed to \"open\" the real pci device"); + return; + } + + if (is_igd_vga_passthrough(&s->real_device) && + s->real_device.domain =3D=3D 0 && s->real_device.bus =3D=3D 0 && + s->real_device.dev =3D=3D 2 && s->real_device.func =3D=3D 0 && + s->real_device.vendor_id =3D=3D PCI_VENDOR_ID_INTEL) { + pci_bus->slot_reserved_mask &=3D ~XEN_PCI_IGD_SLOT_MASK; + XEN_PT_LOG(pci_dev, "Intel IGD found, using slot 2\n"); + } + xpdc->pci_qdev_realize(qdev, errp); +} + static void xen_pci_passthrough_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); =20 + XenPTDeviceClass *xpdc =3D XEN_PT_DEVICE_CLASS(klass); + xpdc->pci_qdev_realize =3D dc->realize; + dc->realize =3D xen_igd_clear_slot; k->realize =3D xen_pt_realize; k->exit =3D xen_pt_unregister_device; k->config_read =3D xen_pt_pci_read_config; @@ -977,6 +1007,7 @@ static const TypeInfo xen_pci_passthrough_info =3D { .instance_size =3D sizeof(XenPCIPassthroughState), .instance_finalize =3D xen_pci_passthrough_finalize, .class_init =3D xen_pci_passthrough_class_init, + .class_size =3D sizeof(XenPTDeviceClass), .instance_init =3D xen_pci_passthrough_instance_init, .interfaces =3D (InterfaceInfo[]) { { INTERFACE_CONVENTIONAL_PCI_DEVICE }, diff --git a/hw/xen/xen_pt.h b/hw/xen/xen_pt.h index cf10fc7bbf..8c25932b4b 100644 --- a/hw/xen/xen_pt.h +++ b/hw/xen/xen_pt.h @@ -2,6 +2,7 @@ #define XEN_PT_H =20 #include "hw/xen/xen_common.h" +#include "hw/pci/pci_bus.h" #include "xen-host-pci-device.h" #include "qom/object.h" =20 @@ -40,7 +41,20 @@ typedef struct XenPTReg XenPTReg; #define TYPE_XEN_PT_DEVICE "xen-pci-passthrough" OBJECT_DECLARE_SIMPLE_TYPE(XenPCIPassthroughState, XEN_PT_DEVICE) =20 +#define XEN_PT_DEVICE_CLASS(klass) \ + OBJECT_CLASS_CHECK(XenPTDeviceClass, klass, TYPE_XEN_PT_DEVICE) +#define XEN_PT_DEVICE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(XenPTDeviceClass, obj, TYPE_XEN_PT_DEVICE) + +typedef void (*XenPTQdevRealize)(DeviceState *qdev, Error **errp); + +typedef struct XenPTDeviceClass { + PCIDeviceClass parent_class; + XenPTQdevRealize pci_qdev_realize; +} XenPTDeviceClass; + uint32_t igd_read_opregion(XenPCIPassthroughState *s); +void xen_igd_reserve_slot(PCIBus *pci_bus); void igd_write_opregion(XenPCIPassthroughState *s, uint32_t val); void xen_igd_passthrough_isa_bridge_create(XenPCIPassthroughState *s, XenHostPCIDevice *dev); @@ -75,6 +89,8 @@ typedef int (*xen_pt_conf_byte_read) =20 #define XEN_PCI_INTEL_OPREGION 0xfc =20 +#define XEN_PCI_IGD_SLOT_MASK 0x4UL /* Intel IGD slot_reserved_mask */ + typedef enum { XEN_PT_GRP_TYPE_HARDWIRED =3D 0, /* 0 Hardwired reg group */ XEN_PT_GRP_TYPE_EMU, /* emul reg group */ diff --git a/hw/xen/xen_pt_stub.c b/hw/xen/xen_pt_stub.c index 2d8cac8d54..5c108446a8 100644 --- a/hw/xen/xen_pt_stub.c +++ b/hw/xen/xen_pt_stub.c @@ -20,3 +20,7 @@ void xen_igd_gfx_pt_set(bool value, Error **errp) error_setg(errp, "Xen PCI passthrough support not built in"); } } + +void xen_igd_reserve_slot(PCIBus *pci_bus) +{ +} --=20 2.39.0