From nobody Sat Jan 22 19:36:32 2022 X-Original-To: dev-commits-src-branches@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 EF94A196BB1C; Sat, 22 Jan 2022 19:36:36 +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 4Jh61v277mz3h1J; Sat, 22 Jan 2022 19:36:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642880196; 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=Z4IFEWpuRx8V1WW7ou8mlHlPJBGtRCG0v8LWbsA77fY=; b=mwi4nYWAXnECJ057ORJdJKWxeQ8AqIPnf4c4QwLH1wlnA3ooKtYvZTctihPhvNot2wrQjv TnNYyMSuz2m9XKn4CGZEsChRRJBr7pZr1fAzYh7zAOKTgvY0tIDkRT+7RriwY1CaCdnYzF FlCymBDGhWU1p0g8Sxf1Ou2Km6196sn1sic2ub1sN5S5QCibtFG2IPPf+KzhCv+0pnPdo7 iukHWsa0c7Ps2Gx/QQvq9V4zWhhnCG6B2F/yuj7lnEDGUFjZoHMX0ZkC2+slUd2ZNamW/q dMaoudfdQwM5qDR+J+DtkqoJS79RbIPukTZHCFUFhJYMU5x9pzbs1K5ziUbR1w== 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 038DC1518B; Sat, 22 Jan 2022 19:36: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 20MJaWcn000267; Sat, 22 Jan 2022 19:36:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20MJaWvx000266; Sat, 22 Jan 2022 19:36:32 GMT (envelope-from git) Date: Sat, 22 Jan 2022 19:36:32 GMT Message-Id: <202201221936.20MJaWvx000266@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: 0576a1c27778 - stable/13 - LinuxKPI: Implement efi_enabled(EFI_BOOT) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 0576a1c2777885a31260f0f5b8895a3e3e088096 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642880195; 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=Z4IFEWpuRx8V1WW7ou8mlHlPJBGtRCG0v8LWbsA77fY=; b=odRrdgidRCAxZgrVQTM0BIfSCgozjJF9LwxaZV1OmrO5wVe442QU1otltavzZRxxEW3iJf BBiYLR/EnWICCGhqm5h8n9KFA+AIodllwDhQPOAkIXlqKK4sSWJ2konYSU1n0nuv3BECyV mMEoEpHG7tvRLJA+AlLaGlwmrViAcOL+/dRTuzpa05UGJAvibvC9NGRA0xnzXZEpeoCaNF 2Zj1bvmpmBsmNy1mqYiDOw1x3uabMZ7zGbwxahz3iA5+46t5wluZZjsL7duW7Fhr0fqfM4 jcZHD3BUVOlFoFYLHhrxVGLyim05TfX1kTNaR3wE1CiT33c0YA5kaORI/D1HLw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642880195; a=rsa-sha256; cv=none; b=wmBtwUK5w8vuk8jbY2O3llsS/RFFANqmUwq03LxUm/J6x8eSS/k2KRQ9y1v3MkTQarYP33 kKz6LH3Wx0hScebP5WmmxKzNwWWLFO9W8FJf9mjTZhR8ps7z7bbNC1zU6TE7p8MSbT4ZvJ 6By3XkuZi0WFc3b5YYF7xGNvRIck6mZayxsAxoSfe4IsjjXAdHbhk85q/mXaPzsxjXW3Tq ZMwYHZbi2PY3su2PipFFFEmH+4oxyvyeaY11zeI8eq5+arUYF2lsxDPu4lwqEepBqZzZZ3 o8eWmEMBrZBBtUCBnFVW8+AB7fmmGLGR23PxRrXiXcTXYnOG6pX718bhH1vbpQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=0576a1c2777885a31260f0f5b8895a3e3e088096 commit 0576a1c2777885a31260f0f5b8895a3e3e088096 Author: Vladimir Kondratyev AuthorDate: 2021-12-06 10:14:36 +0000 Commit: Vladimir Kondratyev CommitDate: 2022-01-22 19:34:37 +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 (cherry picked from commit 89bb7f9bda32d9d54c03a488ed136efdd366cdeb) --- 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_ */