From nobody Thu May 11 20:06:52 2023 X-Original-To: dev-commits-src-all@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 4QHNG50lvqz49xWy; Thu, 11 May 2023 20:06:53 +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 4QHNG50F2zz3p0M; Thu, 11 May 2023 20:06:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683835613; 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=usrcfwdBCef6XYURNQCFf/xhXMRTBx8qx10eQT29w1k=; b=xckmcW3XJzqJObmqRUkHp+/sm1wG0HXmJcrtYUjIno1xILbxYXYiGvO11MYTI8aQDeq9ef +uJKUBSsqjhDvJJdO9m+H8Hw+oyNzbnIxlpgbNZO2YCqT6qPPUyEgv8t7jbY0KEbzfwcQq LfImeuEYXPrbqH4ZwJKT/N+hfYatAxkHPA8Sx+AcZHZUAo4uR1GwuFtRd2wi5sauHs83uR y9gNeDgvcM/DsCmlWXckkj6sfsCsdDLCg743/mDemuxgSSte/SnThAPitoLHgciBI6RflH gpwPpiF5oiViC4J7CdYsyZHvQmhLLPc3KHn7kpw9v6WlRMFbjfzs/YbFfEyIkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683835613; 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=usrcfwdBCef6XYURNQCFf/xhXMRTBx8qx10eQT29w1k=; b=Qpe5wyX3LkvO+w+/NuRyztLn0FN3tumsgKNrBBuC7vaWrS77PhroluHyCX2dqoQ6sAGNKw ADehR5Lb8oN1JWIgalzMKZYKzdpuUDqQZubpKDVsj7Z96V3RkWzomTVEY+FdPwyrGgXKqS lTtJCfsW8VfB51bmfIz8rIGM1hDaMDomXEGusLwpbpxmVhB48YXo8zx8dazO+ZNP6rjROR T5dE87PLDPEDlhTporpxaC4sFKA00L+hjIHXcoKJGKmr3J3WE0K6ApBV5rHxgk0OuHey6z TLpyDNi5ECYSn1KfruFJ636ACutvlUt0amTbvKoUsfHi9zfS/XZr4460EHgxfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683835613; a=rsa-sha256; cv=none; b=eTJ+lfRHdKoSLj3NMFFAr+HEcN5NFgrgw+lk42GqYqb652vmSJEQc9SMMdnFWxXbbMO4r5 mGQ5J6xBqmsN+IHhPc1X+x0PZmjPl7IBpmyVSK7R+HDQD4t1j57PQHG6cqRKV0RfgL4ng6 fcpicCLXqx0dkhjOIguC12ytRryOwX2IYvRRyd8L4NafyAwQagQI1hc9e5nLCt4iGhnTSm dSrB/DQfJvLEbIGQRB+PxMC45v6hs/JaliJ/w/Sg163rPuVlGfKXaijfcOottmxV+CEoHg vlUgGY1mNIsvSGXkcoxMbHbwGLmwVt2iV5T6Ywmivwa+byHvUFWF28LwY6ZPCQ== 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 4QHNG46SYKz16D5; Thu, 11 May 2023 20:06:52 +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 34BK6qkX019620; Thu, 11 May 2023 20:06:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34BK6q0Z019619; Thu, 11 May 2023 20:06:52 GMT (envelope-from git) Date: Thu, 11 May 2023 20:06:52 GMT Message-Id: <202305112006.34BK6q0Z019619@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 8c3d6917c1f1 - main - stand: eficom: Only set baudrate when it changes List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8c3d6917c1f127f70719193959ff42f3f1ab8f5f Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=8c3d6917c1f127f70719193959ff42f3f1ab8f5f commit 8c3d6917c1f127f70719193959ff42f3f1ab8f5f Author: Warner Losh AuthorDate: 2023-05-11 20:04:00 +0000 Commit: Warner Losh CommitDate: 2023-05-11 20:06:03 +0000 stand: eficom: Only set baudrate when it changes Only set the baudrate when it is different than what the device has reported. In addition, pass in the args to effect no change to the other parameters to the serial port. Some EFI firmware gets cranky when you set them to the same value, so avoid doing so (we likely can remove the HyperV workaround with this fix, but I kept it in place). Add comments to the code for why we do this too. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D40010 --- stand/efi/libefi/eficom.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/stand/efi/libefi/eficom.c b/stand/efi/libefi/eficom.c index b0fc0d8fbf6a..b1c84399a05d 100644 --- a/stand/efi/libefi/eficom.c +++ b/stand/efi/libefi/eficom.c @@ -41,6 +41,7 @@ static EFI_GUID serial = SERIAL_IO_PROTOCOL; #define PNP0501 0x501 /* 16550A-compatible COM port */ struct serial { + uint64_t newbaudrate; uint64_t baudrate; uint32_t timeout; uint32_t receivefifodepth; @@ -300,7 +301,8 @@ comc_probe(struct console *sc) if (EFI_ERROR(status)) { comc_port->sio = NULL; } else { - comc_port->baudrate = comc_port->sio->Mode->BaudRate; + comc_port->newbaudrate = + comc_port->baudrate = comc_port->sio->Mode->BaudRate; comc_port->timeout = comc_port->sio->Mode->Timeout; comc_port->receivefifodepth = comc_port->sio->Mode->ReceiveFifoDepth; @@ -322,7 +324,7 @@ comc_probe(struct console *sc) env = getenv("comconsole_speed"); if (comc_parse_intval(env, &val) == CMD_OK) - comc_port->baudrate = val; + comc_port->newbaudrate = val; if (env != NULL) unsetenv("efi_com_speed"); @@ -497,10 +499,9 @@ comc_speed_set(struct env_var *ev, int flags, const void *value) if (comc_parse_intval(value, &speed) != CMD_OK) return (CMD_ERROR); - comc_port->baudrate = speed; - (void) comc_setup(); - - env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); + comc_port->newbaudrate = speed; + if (comc_setup()) + env_setenv(ev->ev_name, flags | EV_NOHOOK, value, NULL, NULL); return (CMD_OK); } @@ -525,20 +526,24 @@ comc_setup(void) return (false); } - if (comc_port->sio->SetAttributes != NULL) { + /* + * Avoid setting the baud rate on Hyper-V. Also, only set the baud rate + * if the baud rate has changed from the default. And pass in '0' or + * DefaultFoo when we're not changing those values. Some EFI + * implementations get cranky when you set things to the values reported + * back even when they are unchanged. + */ + if (comc_port->sio->SetAttributes != NULL && + comc_port->newbaudrate != comc_port->baudrate) { ev = getenv("smbios.bios.version"); - if (ev != NULL && strncmp(ev, "Hyper-V", 7) == 0) { + 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); + comc_port->newbaudrate, 0, 0, DefaultParity, 0, + DefaultStopBits); + if (EFI_ERROR(status)) + return (false); + comc_port->baudrate = comc_port->newbaudrate; } - - if (EFI_ERROR(status)) - return (false); } #ifdef EFI_FORCE_RTS