From nobody Sat Mar 18 07:20:33 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Pdspn6Xtqz3yDSk; Sat, 18 Mar 2023 07:20:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Pdspn5fYxz3PqW; Sat, 18 Mar 2023 07:20:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679124033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0Stjp8Qet16wX/ih4Jdzzspmfyf58nkCVXewa3nFMQ0=; b=EF69SPing7+w6uosEKpj1BuUSl4LtY0zBm0wX993F8wTCl+xJjbOlLLv6pZtdB4g5vi7QV P8xBizFrJc+R1QV+aWSNDHYbPFxAP+eR9DHTCz6TDINzQxQ2kShVwmcDjuXKUPN8RmVI5l wDpJhZz5JSTlLweUSGgtl9M6kKZoZVy+gx9FyoLLLctA+nuZ17sr/8yDQ32HXn3oM3Gbbn OuOpa2OKpXLZlkx2OtsfQhcRBsvekmpe+0OA122NvOHwFyoaHv7TcKfHbtA5oL7IXtUxOe ql9CZvlbsrHLbpFN9zwJ82XTUJMQ2opNOrwR3h3Ge+jKOzqkv79tUtV60vKoiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679124033; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=0Stjp8Qet16wX/ih4Jdzzspmfyf58nkCVXewa3nFMQ0=; b=NZLqikSSirPxUWf06Yl6FqZDdUIU2szpN/V3U+sNX26sUqIasMZDsHRqKNo2xXcCAkG2EI 9LmibrXSy5EhoeeWTu75zScGXAW6aPcF3QXQpzZiI7M1VHNQRN11CXbsN/UWu5G7303YmS QWtgEsUVwy6e4ytDMBJHwVaZbCLsRH95Y4LsUVK8fpGQV+nqRcnSVar/+3MY5hMmnKE6g7 KFNYzo8bYeyr9HmBmy8Eky4QR40ZLwFCbeZF6FTc6r4zRvU8Fy9CJONMsffJ1oqnKX3+HY KLF77R2mHc70FlU+mxKCtwLom0nni8I2iUVqy9MUKTiv43KdsDkPQmA1tf43Ug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679124033; a=rsa-sha256; cv=none; b=xlzcz4d96XolVwKF5D59/9PksJssk2sSUZWs/BNmAn/k6AylHCz6ztims4Ne9gp7FDx+fo gQPQMMN1V8aC2qpVba45nj6CZqjEmf9Zakx5KXm27rMAl4O8WfQT6sdOVhBl/DOreCdoFe JAFYWqtcftGe93eqmiaosf05Yr/Q0MRTdTL49ttF2QrbvqM9tRVPZ2ezJn0XuX6uNtiIx5 xMuWFaqQEV/4uxScUQN+uYDjIId/MAjqR+r46HGQGBBDTn3KaFQ6f34I3XtivStSDEMahR zgEALcHJKLyYSoFoWALCrjyuJ6th7zMwWwNJyrvGan8KvpbSEw7JVdYnWyarqA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Pdspn4dbDzyF5; Sat, 18 Mar 2023 07:20:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32I7KX7j030613; Sat, 18 Mar 2023 07:20:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32I7KXOc030612; Sat, 18 Mar 2023 07:20:33 GMT (envelope-from git) Date: Sat, 18 Mar 2023 07:20:33 GMT Message-Id: <202303180720.32I7KXOc030612@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wei Hu Subject: git: 927358dd98cb - main - amd64 loader: Use efiserialio for Hyper-V booted systems List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: whu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 927358dd98cb902160093e0dc0bac002d6b43858 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=927358dd98cb902160093e0dc0bac002d6b43858 commit 927358dd98cb902160093e0dc0bac002d6b43858 Author: Wei Hu AuthorDate: 2023-03-14 15:13:46 +0000 Commit: Wei Hu CommitDate: 2023-03-18 07:07:35 +0000 amd64 loader: Use efiserialio for Hyper-V booted systems UEFI provides ConIn/ConOut handles for consoles that it supports, which include the text-video and serial ports. When the serial port is available, use the UEFI driver instead of direct io-port accesses to avoid conflicts between the firmware and direct hardware access, as happens on Hyper-V (Azure) setups. This change enables efiserialio to be built for efi-amd64 and has higher order priority vs comconsole, and only uses efiserialio if the hypervisor is Hyper-V. When efiserialio successfully probes, it will set efi_comconsole_avail=true which will prevent comconsole from probing in this setup. Tested on Hyper-V, ESXi and Azure VMs. PR: 264267 Reviewed by: kevans, whu Tested by: whu Obtained from: Rubicon Communications, LLC (Netgate) MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC (Netgate) --- stand/efi/loader/arch/amd64/Makefile.inc | 1 + stand/efi/loader/bootinfo.c | 11 ++++++-- stand/efi/loader/conf.c | 6 +++++ stand/efi/loader/efiserialio.c | 43 ++++++++++++++++++++++++++++---- stand/i386/libi386/comconsole.c | 14 +++++++++++ 5 files changed, 68 insertions(+), 7 deletions(-) diff --git a/stand/efi/loader/arch/amd64/Makefile.inc b/stand/efi/loader/arch/amd64/Makefile.inc index 0d9e2648cb59..bd89044bd6c7 100644 --- a/stand/efi/loader/arch/amd64/Makefile.inc +++ b/stand/efi/loader/arch/amd64/Makefile.inc @@ -5,6 +5,7 @@ SRCS+= amd64_tramp.S \ elf64_freebsd.c \ trap.c \ multiboot2.c \ + efiserialio.c \ exc.S .PATH: ${BOOTSRC}/i386/libi386 diff --git a/stand/efi/loader/bootinfo.c b/stand/efi/loader/bootinfo.c index 939f2cf4c3fe..d79f59343af1 100644 --- a/stand/efi/loader/bootinfo.c +++ b/stand/efi/loader/bootinfo.c @@ -119,10 +119,17 @@ bi_getboothowto(char *kargs) if (tmp != NULL) speed = strtol(tmp, NULL, 0); tmp = getenv("efi_com_port"); - if (tmp == NULL) - tmp = getenv("comconsole_port"); if (tmp != NULL) port = strtol(tmp, NULL, 0); + if (port <= 0) { + tmp = getenv("comconsole_port"); + if (tmp != NULL) + port = strtol(tmp, NULL, 0); + else { + if (port == 0) + port = 0x3f8; + } + } if (speed != -1 && port != -1) { snprintf(buf, sizeof(buf), "io:%d,br:%d", port, speed); diff --git a/stand/efi/loader/conf.c b/stand/efi/loader/conf.c index 863c9188c72c..051e1a3381d1 100644 --- a/stand/efi/loader/conf.c +++ b/stand/efi/loader/conf.c @@ -81,6 +81,9 @@ struct netif_driver *netif_drivers[] = { extern struct console efi_console; extern struct console comconsole; +#if defined(__amd64__) +extern struct console eficomconsole; +#endif #if defined(__amd64__) || defined(__i386__) extern struct console nullconsole; extern struct console spinconsole; @@ -88,6 +91,9 @@ extern struct console spinconsole; struct console *consoles[] = { &efi_console, +#if defined(__amd64__) + &eficomconsole, +#endif &comconsole, #if defined(__amd64__) || defined(__i386__) &nullconsole, diff --git a/stand/efi/loader/efiserialio.c b/stand/efi/loader/efiserialio.c index 375e679d2590..5fbc700f6ac2 100644 --- a/stand/efi/loader/efiserialio.c +++ b/stand/efi/loader/efiserialio.c @@ -69,6 +69,11 @@ static int comc_speed_set(struct env_var *, int, const void *); static struct serial *comc_port; extern struct console efi_console; +bool efi_comconsole_avail = false; + +#if defined(__amd64__) +#define comconsole eficomconsole +#endif struct console comconsole = { .c_name = "comconsole", @@ -254,11 +259,22 @@ comc_probe(struct console *sc) char *env, *buf, *ep; size_t sz; +#if defined(__amd64__) + /* + * For x86-64, don't use this driver if not running in Hyper-V. + */ + env = getenv("smbios.bios.version"); + if (env == NULL || strncmp(env, "Hyper-V", 7) != 0) { + return; + } +#endif + if (comc_port == NULL) { comc_port = calloc(1, sizeof (struct serial)); if (comc_port == NULL) return; } + /* Use defaults from firmware */ comc_port->databits = 8; comc_port->parity = DefaultParity; @@ -308,6 +324,10 @@ comc_probe(struct console *sc) comc_port_set, env_nounset); env = getenv("efi_com_speed"); + if (env == NULL) + /* fallback to comconsole setting */ + env = getenv("comconsole_speed"); + if (comc_parse_intval(env, &val) == CMD_OK) comc_port->baudrate = val; @@ -318,8 +338,13 @@ comc_probe(struct console *sc) comc_speed_set, env_nounset); comconsole.c_flags = 0; - if (comc_setup()) + if (comc_setup()) { sc->c_flags = C_PRESENTIN | C_PRESENTOUT; + efi_comconsole_avail = true; + } else { + /* disable being seen as "comconsole" */ + comconsole.c_name = "efiserialio"; + } } static int @@ -489,6 +514,7 @@ comc_setup(void) { EFI_STATUS status; UINT32 control; + char *ev; /* port is not usable */ if (comc_port->sio == NULL) @@ -498,10 +524,17 @@ comc_setup(void) if (EFI_ERROR(status)) return (false); - status = comc_port->sio->SetAttributes(comc_port->sio, - comc_port->baudrate, comc_port->receivefifodepth, - comc_port->timeout, comc_port->parity, - comc_port->databits, comc_port->stopbits); + ev = getenv("smbios.bios.version"); + if (ev != NULL && strncmp(ev, "Hyper-V", 7) == 0) { + status = comc_port->sio->SetAttributes(comc_port->sio, + 0, 0, 0, DefaultParity, 0, DefaultStopBits); + } else { + status = comc_port->sio->SetAttributes(comc_port->sio, + comc_port->baudrate, comc_port->receivefifodepth, + comc_port->timeout, comc_port->parity, + comc_port->databits, comc_port->stopbits); + } + if (EFI_ERROR(status)) return (false); diff --git a/stand/i386/libi386/comconsole.c b/stand/i386/libi386/comconsole.c index ed1f1aa08ed7..3fbb6a292c19 100644 --- a/stand/i386/libi386/comconsole.c +++ b/stand/i386/libi386/comconsole.c @@ -85,6 +85,20 @@ comc_probe(struct console *cp) int speed, port; uint32_t locator; +#if defined(__amd64__) + extern bool efi_comconsole_avail; + + if (efi_comconsole_avail) { + /* + * If EFI provides serial I/O, then don't use this legacy + * com driver to avoid conflicts with the firmware's driver. + * Change c_name so that it cannot be found in the lookup. + */ + comconsole.c_name = "xcomconsole"; + return; + } +#endif + if (comc_curspeed == 0) { comc_curspeed = COMSPEED; /*