From nobody Mon Jan 10 19:50:45 2022 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 1F16C195494C; Mon, 10 Jan 2022 19:50:51 +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 4JXkvr6mzpz3NkJ; Mon, 10 Jan 2022 19:50:48 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 08E5130A2; Mon, 10 Jan 2022 19:50:46 +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 20AJojiv009177; Mon, 10 Jan 2022 19:50:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20AJojq4009176; Mon, 10 Jan 2022 19:50:45 GMT (envelope-from git) Date: Mon, 10 Jan 2022 19:50:45 GMT Message-Id: <202201101950.20AJojq4009176@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 89bb7f9bda32 - main - LinuxKPI: Implement efi_enabled(EFI_BOOT) 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: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 89bb7f9bda32d9d54c03a488ed136efdd366cdeb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641844249; 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=GIElQFjINWEqzW0sMs5FMZdfldUIhAK8x4moW2iY+7o=; b=ZfKABxcwLvVGvGhAdcJnenpQnwTq6O4O/fAwnOPfkUdS/M1uGIwxwbHPWxyvYEkJ7ZrXj3 d3nAscB7EdOAiu5A41xASx9p/pn6/iCEX4hx5sWGS2vV/0jbnUrUyv7OBPrDtW1bMZWjCo ZrAFN9v8lfr6z9EdSHBKjty6s14cEe0IOgxQ9XYjn3mJiqjEm1i4+mguQ0xb1epTol/wGD nJe2LR76QUbuNwSAQTySaKD+4WS8SmJRAgCsAMpoJyEOzJKoGmwXdmOulPbiKMbCGIBb6o +WWfrWMdIG7ONIXbKAe22Qvvlm3yk2eKA4F0iwbcVIIydroDo7yc5F0UrfOSeQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641844249; a=rsa-sha256; cv=none; b=Tj8hDEMMEfPjd/pEgqfoU9WHjIlsRNa+YDDsjfZQMZsE7qZVGxoq8+eARjgEE+rkwC9/aX 6TavHM+Uh4aYrLPxp8uoM9la97noLky+ecFvi286FMSsC+Q63bQuDJZvstiS9Dzwk+cQl5 wVpoLPgVaCVf7m+X9ovLtdvDavNsY09s2bBOowhIHluuQcaC1W0757ySHcZLJSUZsGPu2I Rf/8wzoZZ8rwYcgtWhNGnyqMHs5wMUf3/8m7+PFBhgsYCESYvLkXnmAVhksyUP6w2j7jsa +O0SBB/bE58Zlvm6ZxwJ/NlMv9Yam+S5dxpgHpBmZ+z8xMeMwgzdrRWSPakjXQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=89bb7f9bda32d9d54c03a488ed136efdd366cdeb commit 89bb7f9bda32d9d54c03a488ed136efdd366cdeb Author: Vladimir Kondratyev AuthorDate: 2021-12-06 10:14:36 +0000 Commit: Vladimir Kondratyev CommitDate: 2022-01-10 19:49:38 +0000 LinuxKPI: Implement efi_enabled(EFI_BOOT) efi_enabled(EFI_BOOT) returns true if machine was booted from EFI Used by drm-kmod and some unported drm drivers like hyperv MFC after: 1 week Reviewed by: hselasky, manu Differential Revision: https://reviews.freebsd.org/D33300 --- sys/compat/linuxkpi/common/include/linux/efi.h | 73 ++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/efi.h b/sys/compat/linuxkpi/common/include/linux/efi.h new file mode 100644 index 000000000000..b7b0e681b6f2 --- /dev/null +++ b/sys/compat/linuxkpi/common/include/linux/efi.h @@ -0,0 +1,73 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Vladimir Kondratyev + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _LINUX_EFI_H_ +#define _LINUX_EFI_H_ + +#include +#include +#include + +#include +#include + +#define EFI_BOOT 0 + +static inline bool +__efi_enabled(int feature) +{ +#if defined(MODINFOMD_EFI_MAP) && !defined(__amd64__) + caddr_t kmdp; +#endif + bool enabled = false; + + switch (feature) { + case EFI_BOOT: +#ifdef __amd64__ + /* Use cached value on amd64 */ + enabled = efi_boot; +#elif defined(MODINFOMD_EFI_MAP) + kmdp = preload_search_by_type("elf kernel"); + if (kmdp == NULL) + kmdp = preload_search_by_type("elf64 kernel"); + enabled = preload_search_info(kmdp, + MODINFO_METADATA | MODINFOMD_EFI_MAP) != NULL; +#endif + break; + default: + break; + } + + return (enabled); +} + +#define efi_enabled(x) ({ \ + _Static_assert((x) == EFI_BOOT, "unsupported feature"); \ + __efi_enabled(x); \ +}) + +#endif /* _LINUX_EFI_H_ */