From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.26257.1683901404155799422 for ; Fri, 12 May 2023 07:23:24 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cdtSIaaG; spf=pass (domain: redhat.com, ip: 170.10.129.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683901403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/oiJcs3SYyE+1tisCV4iKFcOHH70XLFQdVwsCFuIMcQ=; b=cdtSIaaGIgtrcF8u8FRrtgkyW4E2XzAqT+348/ikiL7UfKWlRdd6iptbnHfD+CFD1EOOAL KlUEAU88CcSaqI9ridVRAz3/C0P4MQR+fSAKf5qyQY42hbWNydjni5wq95QbN46yIbKvEP 6IabxuJcVYUYOLn9EImd0R5xpYOVsvw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-635-OXpIlst2PeSdbgTZK737OA-1; Fri, 12 May 2023 10:23:20 -0400 X-MC-Unique: OXpIlst2PeSdbgTZK737OA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF55C1857F22; Fri, 12 May 2023 14:23:19 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2ABD140C6EC4; Fri, 12 May 2023 14:23:12 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id B980D1800915; Fri, 12 May 2023 16:23:06 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Jiewen Yao , Jordan Justen , Leif Lindholm , Pawel Polawski , Sami Mujawar , Oliver Steffen , Ard Biesheuvel Subject: [PATCH 4/5] ArmVirt/PlatformBootManagerLib: set up virtio serial as console Date: Fri, 12 May 2023 16:23:05 +0200 Message-Id: <20230512142306.1323983-5-kraxel@redhat.com> In-Reply-To: <20230512142306.1323983-1-kraxel@redhat.com> References: <20230512142306.1323983-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; 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 | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c index ed38c42a43ee..7010d73c1388 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); } +/** + This FILTER_FUNCTION checks if a handle corresponds to a Virtio serial device 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 given at the EFI_PCI_IO_PROTOCOL level. @@ -446,6 +461,21 @@ IsVirtioPciRng ( return IsVirtioPci (Handle, ReportText, VIRTIO_SUBSYSTEM_ENTROPY_SOURCE); } +/** + This FILTER_FUNCTION checks if a handle corresponds to a Virtio serial device 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, asking the matching driver to produce all first-level child handles. @@ -534,6 +564,133 @@ AddOutput ( )); } +/** + 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 ACPI_HID_DEVICE_PATH SerialNode = { + { + ACPI_DEVICE_PATH, + ACPI_DP, + { + (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)), + (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8) + }, + }, + EISA_PNP_ID (0x0501), + 0 + }; + + STATIC UART_DEVICE_PATH UartNode = { + { + MESSAGING_DEVICE_PATH, + MSG_UART_DP, + { + (UINT8)(sizeof (UART_DEVICE_PATH)), + (UINT8)((sizeof (UART_DEVICE_PATH)) >> 8) + }, + }, + 0, + 115200, + 8, + 1, + 1 + }; + + STATIC VENDOR_DEVICE_PATH TerminalNode = { + { + 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; + + DevicePath = DevicePathFromHandle (Handle); + + if (DevicePath == NULL) { + DEBUG (( + DEBUG_ERROR, + "%a: %s: handle %p: device path not found\n", + __func__, + ReportText, + Handle + )); + return; + } + + DevicePath = AppendDevicePathNode ( + DevicePath, + (EFI_DEVICE_PATH_PROTOCOL *)&SerialNode + ); + DevicePath = AppendDevicePathNode ( + DevicePath, + (EFI_DEVICE_PATH_PROTOCOL *)&UartNode + ); + DevicePath = AppendDevicePathNode ( + DevicePath, + (EFI_DEVICE_PATH_PROTOCOL *)&TerminalNode + ); + + Status = EfiBootManagerUpdateConsoleVariable (ConIn, DevicePath, NULL); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: %s: adding to ConIn: %r\n", + __func__, + ReportText, + Status + )); + return; + } + + Status = EfiBootManagerUpdateConsoleVariable (ConOut, DevicePath, NULL); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: %s: adding to ConOut: %r\n", + __func__, + ReportText, + Status + )); + return; + } + + Status = EfiBootManagerUpdateConsoleVariable (ErrOut, DevicePath, NULL); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: %s: adding to ErrOut: %r\n", + __func__, + ReportText, + Status + )); + return; + } + + DEBUG (( + DEBUG_VERBOSE, + "%a: %s: added to ConIn, ConOut and ErrOut\n", + __func__, + ReportText + )); +} + STATIC VOID PlatformRegisterFvBootOption ( @@ -932,6 +1089,12 @@ PlatformBootManagerBeforeConsole ( // instances on Virtio PCI RNG devices. // FilterAndProcess (&gEfiPciIoProtocolGuid, IsVirtioPciRng, Connect); + + // + // Register Virtio serial devices as console. + // + FilterAndProcess (&gVirtioDeviceProtocolGuid, IsVirtioSerial, SetupVirtioSerial); + FilterAndProcess (&gEfiPciIoProtocolGuid, IsVirtioPciSerial, SetupVirtioSerial); } /** -- 2.40.1