From nobody Thu Dec 26 01:53:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1505403465346470.9847194633197; Thu, 14 Sep 2017 08:37:45 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DECA821E47D6C; Thu, 14 Sep 2017 08:34:43 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F00ED21E11D39 for ; Thu, 14 Sep 2017 08:34:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B381E69064; Thu, 14 Sep 2017 15:37:41 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-121-80.rdu2.redhat.com [10.10.121.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7856360184; Thu, 14 Sep 2017 15:37:40 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B381E69064 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 14 Sep 2017 17:37:34 +0200 Message-Id: <20170914153734.13572-2-lersek@redhat.com> In-Reply-To: <20170914153734.13572-1-lersek@redhat.com> References: <20170914153734.13572-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 14 Sep 2017 15:37:41 +0000 (UTC) Subject: [edk2] [PATCH 1/1] OvmfPkg/QemuBootOrderLib: recognize "usb-storage" devices in XHCI ports X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The feature is primarily useful for modern AARCH64 guests that have no built-in virtio block / SCSI drivers; as on "qemu-system-aarch64 -M virt", there are no IDE or AHCI controllers that could be used as fallback. XHCI is available in "-M virt" however, and because XHCI predates AARCH64 by several years, said guests are expected to have built-in drivers for it. Other device models ("usb-uas", "usb-bot") are out of scope for now, similarly to USB1.x (UHCI) and USB2 (EHCI) host controllers, and similarly to USB hubs (which are USB1.1 only). In particular, port mapping between EHCI and companion UHCI controllers is very complex; it even leads to PCI slot/function differences between the OpenFirmware device paths exported by QEMU and the the UEFI device paths generated by edk2. The number of ports on the XHCI controller defaults to 4, but it can be raised via the "p3" property to 15. In addition, several XHCI controllers can be grouped into a single-slot, multi-function PCI device. These allow for a good number of usb-storage devices, while their desired boot order remains recognizable to this patch. In the example below, we create two XHCI controllers, grouped into PCI slot 00:02 as functions 0 and 1. Both controllers are given 15 ports. We attach a "usb-storage" device to controller 1 at port 3 (ports are 1-based in QEMU, 0-based in edk2), and attach another "usb-storage" device to controller 2 at port 9. QEMU command line options (NB. they apply equally to aarch64/virt and x86_64/{i440fx,q35}): -device qemu-xhci,id=3Dxhci1,p3=3D15,addr=3D02.0,multifunction=3Don \ -device qemu-xhci,id=3Dxhci2,p3=3D15,addr=3D02.1 \ \ -drive id=3Ddisk1,if=3Dnone,format=3Dqcow2,$DISK1_OPTIONS \ -drive id=3Ddisk2,if=3Dnone,format=3Dqcow2,$DISK2_OPTIONS \ \ -device usb-storage,drive=3Ddisk1,bus=3Dxhci1.0,port=3D3,bootindex=3D1 \ -device usb-storage,drive=3Ddisk2,bus=3Dxhci2.0,port=3D9,bootindex=3D2 \ Libvirt domain XML fragment:
Cc: Ard Biesheuvel Cc: Gerd Hoffmann Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Acked-by: Ard Biesheuvel --- OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c | 44 +++++++++++++++++= +++ 1 file changed, 44 insertions(+) diff --git a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c b/OvmfPkg/= Library/QemuBootOrderLib/QemuBootOrderLib.c index 567f6f92f452..7c1f375beb20 100644 --- a/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c +++ b/OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.c @@ -986,6 +986,50 @@ TranslatePciOfwNodes ( Eui64[7], Eui64[6], Eui64[5], Eui64[4], Eui64[3], Eui64[2], Eui64[1], Eui64[0] ); + } else if (NumNodes >=3D FirstNonBridge + 2 && + SubstringEq (OfwNode[FirstNonBridge + 0].DriverName, "usb") && + SubstringEq (OfwNode[FirstNonBridge + 1].DriverName, "storage= ")) { + // + // OpenFirmware device path (usb-storage device in XHCI port): + // + // /pci@i0cf8/usb@3[,1]/storage@2/channel@0/disk@0,0 + // ^ ^ ^ ^ ^ ^ ^ + // | | | | fixed fixed + // | | | XHCI port number, 1-based + // | | PCI function corresponding to XHCI (optional) + // | PCI slot holding XHCI + // PCI root at system bus port, PIO + // + // UEFI device path prefix: + // + // PciRoot(0x0)/Pci(0x3,0x1)/USB(0x1,0x0) + // ^ ^ + // | XHCI port number in 0-based notation + // 0x0 if PCI function is 0, or absent from OFW + // + RETURN_STATUS ParseStatus; + UINT64 OneBasedXhciPort; + + NumEntries =3D 1; + ParseStatus =3D ParseUnitAddressHexList ( + OfwNode[FirstNonBridge + 1].UnitAddress, + &OneBasedXhciPort, + &NumEntries + ); + if (RETURN_ERROR (ParseStatus) || OneBasedXhciPort =3D=3D 0) { + return RETURN_UNSUPPORTED; + } + + Written =3D UnicodeSPrintAsciiFormat ( + Translated, + *TranslatedSize * sizeof (*Translated), // BufferSize in b= ytes + "PciRoot(0x%x)%s/Pci(0x%Lx,0x%Lx)/USB(0x%Lx,0x0)", + PciRoot, + Bridges, + PciDevFun[0], + PciDevFun[1], + OneBasedXhciPort - 1 + ); } else { // // Generic OpenFirmware device path for PCI devices: --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel