From nobody Wed Jan 15 10:13:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+105561+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105561+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1685620644; cv=none; d=zohomail.com; s=zohoarc; b=PzHgOBRtQSpiXUMeBq9sEsubFImOlHxOGNI4DYX64i+v1mLSp+jI6WnqG62SgFtrNTq/61n4oyVbxhJSsyPbKfg57rxWD4sUFuopHQhqbW+KFW4xo+X6ebRmPSNXASdV/BAvZxTS1PfAhC7myOIpa5MhIODh/rrwA0MZUr2dNRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685620644; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bc9eKffedCQi3uMcts6y9jlrw5FY3Ehmqs569msJ168=; b=buglgqxAMqE1C/OzYkRWfzDhG8i15K0/pCi9sM7gOe/kajZ/5ekDWxKGp2JLVLL4daTqf/g7p8vayNkZjjLhsU8XiUcYolXFff4qhQcsCg+5p5W+1mFXY4ME5TIZx10sP6MEH+4phRWVfQYFOGmVad1mfTU9VIIjqPvgJ+K4+3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+105561+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 168562064440744.571927957247; Thu, 1 Jun 2023 04:57:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6tMMYY1788612xS6zqvzKKTl; Thu, 01 Jun 2023 04:57:24 -0700 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.29289.1685620643311710655 for ; Thu, 01 Jun 2023 04:57:23 -0700 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-GTNH4wKHMr-fwBZ749Y2Hg-1; Thu, 01 Jun 2023 07:57:18 -0400 X-MC-Unique: GTNH4wKHMr-fwBZ749Y2Hg-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 14A9F3C17C6B; Thu, 1 Jun 2023 11:57:18 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC68CC154DA; Thu, 1 Jun 2023 11:57:17 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C80161800993; Thu, 1 Jun 2023 13:57:13 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Jiewen Yao , Gerd Hoffmann , Leif Lindholm , Ard Biesheuvel , Oliver Steffen , Pawel Polawski , Jordan Justen , Sami Mujawar Subject: [edk2-devel] [PATCH v2 4/4] ArmVirt/PlatformBootManagerLib: set up virtio serial as console Date: Thu, 1 Jun 2023 13:57:13 +0200 Message-Id: <20230601115713.1212372-5-kraxel@redhat.com> In-Reply-To: <20230601115713.1212372-1-kraxel@redhat.com> References: <20230601115713.1212372-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com X-Gm-Message-State: rmA6h7VdTTlEXJxOy9mkfwMbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1685620644; bh=J3PiExlpY22+vkFgkByPzIMxT14YDLWWCjJLNFON1Ps=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=EZia0KnpatcW7l4HnRxlb6w/ulCKAHE01p+DrvB9oMIGA1+2X/83fSnP5LuOUSHhhWN plZdMwlt7KNcpS30Z1Sm1tN0f0iK7NkT0sHuIyMPHzbE+HHlChLkCCDHzXYtqK2BlNGtB XiSxMaHN0YOFWi0FReBz9cWb/lOXNJTz4L8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1685620646429100019 Content-Type: text/plain; charset="utf-8"; x-default="true" In case a virtio serial device is found in the system register the first console port as EFI console, by updating ConIn, ConOut and ErrOut. Signed-off-by: Gerd Hoffmann --- .../PlatformBootManagerLib/PlatformBm.c | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmVi= rtPkg/Library/PlatformBootManagerLib/PlatformBm.c index ed38c42a43ee..b92a916f7eec 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c +++ b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c @@ -312,6 +312,21 @@ IsVirtioRng ( return IsVirtio (Handle, ReportText, VIRTIO_SUBSYSTEM_ENTROPY_SOURCE); } =20 +/** + This FILTER_FUNCTION checks if a handle corresponds to a Virtio serial d= evice at + the VIRTIO_DEVICE_PROTOCOL level. +**/ +STATIC +BOOLEAN +EFIAPI +IsVirtioSerial ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ) +{ + return IsVirtio (Handle, ReportText, VIRTIO_SUBSYSTEM_CONSOLE); +} + /** This function checks if a handle corresponds to the Virtio Device ID giv= en at the EFI_PCI_IO_PROTOCOL level. @@ -446,6 +461,21 @@ IsVirtioPciRng ( return IsVirtioPci (Handle, ReportText, VIRTIO_SUBSYSTEM_ENTROPY_SOURCE); } =20 +/** + This FILTER_FUNCTION checks if a handle corresponds to a Virtio serial d= evice at + the EFI_PCI_IO_PROTOCOL level. +**/ +STATIC +BOOLEAN +EFIAPI +IsVirtioPciSerial ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ) +{ + return IsVirtioPci (Handle, ReportText, VIRTIO_SUBSYSTEM_CONSOLE); +} + /** This CALLBACK_FUNCTION attempts to connect a handle non-recursively, ask= ing the matching driver to produce all first-level child handles. @@ -534,6 +564,142 @@ AddOutput ( )); } =20 +/** + This CALLBACK_FUNCTION retrieves the EFI_DEVICE_PATH_PROTOCOL from + the handle, appends serial, uart and terminal nodes, finally updates + ConIn, ConOut and ErrOut. +**/ +STATIC +VOID +EFIAPI +SetupVirtioSerial ( + IN EFI_HANDLE Handle, + IN CONST CHAR16 *ReportText + ) +{ + STATIC CONST ACPI_HID_DEVICE_PATH SerialNode =3D { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) + }, + }, + EISA_PNP_ID (0x0501), + 0 + }; + + STATIC CONST UART_DEVICE_PATH UartNode =3D { + { + MESSAGING_DEVICE_PATH, + MSG_UART_DP, + { + (UINT8)(sizeof (UART_DEVICE_PATH)), + (UINT8)((sizeof (UART_DEVICE_PATH)) >> 8) + }, + }, + 0, + 115200, + 8, + 1, + 1 + }; + + STATIC CONST VENDOR_DEVICE_PATH TerminalNode =3D { + { + MESSAGING_DEVICE_PATH, + MSG_VENDOR_DP, + { + (UINT8)(sizeof (VENDOR_DEVICE_PATH)), + (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) + }, + }, + DEVICE_PATH_MESSAGING_VT_UTF8 + }; + + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath, *OldDevicePath; + + DevicePath =3D DevicePathFromHandle (Handle); + + if (DevicePath =3D=3D NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: %s: handle %p: device path not found\n", + __func__, + ReportText, + Handle + )); + return; + } + + DevicePath =3D AppendDevicePathNode ( + DevicePath, + &SerialNode.Header + ); + + OldDevicePath =3D DevicePath; + DevicePath =3D AppendDevicePathNode ( + DevicePath, + &UartNode.Header + ); + FreePool (OldDevicePath); + + OldDevicePath =3D DevicePath; + DevicePath =3D AppendDevicePathNode ( + DevicePath, + &TerminalNode.Header + ); + FreePool (OldDevicePath); + + Status =3D EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: %s: adding to ConIn: %r\n", + __func__, + ReportText, + Status + )); + return; + } + + Status =3D EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL= ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + + "%a: %s: adding to ConOut: %r\n", + __func__, + ReportText, + Status + )); + return; + } + + Status =3D EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL= ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: %s: adding to ErrOut: %r\n", + __func__, + ReportText, + Status + )); + return; + } + + FreePool (DevicePath); + + DEBUG (( + DEBUG_VERBOSE, + "%a: %s: added to ConIn, ConOut and ErrOut\n", + __func__, + ReportText + )); +} + STATIC VOID PlatformRegisterFvBootOption ( @@ -932,6 +1098,12 @@ PlatformBootManagerBeforeConsole ( // instances on Virtio PCI RNG devices. // FilterAndProcess (&gEfiPciIoProtocolGuid, IsVirtioPciRng, Connect); + + // + // Register Virtio serial devices as console. + // + FilterAndProcess (&gVirtioDeviceProtocolGuid, IsVirtioSerial, SetupVirti= oSerial); + FilterAndProcess (&gEfiPciIoProtocolGuid, IsVirtioPciSerial, SetupVirtio= Serial); } =20 /** --=20 2.40.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#105561): https://edk2.groups.io/g/devel/message/105561 Mute This Topic: https://groups.io/mt/99261957/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-