From c0cbe7c2e69185bad65344914e757fe1844ee962 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 17 Dec 2024 13:51:40 +0000 Subject: [efi] Add EFI_TCG2_PROTOCOL header and GUID definition Signed-off-by: Michael Brown --- src/interface/efi/efi_debug.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 52efebe5f..895a712bd 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -209,6 +209,8 @@ static struct efi_well_known_guid efi_well_known_guids[] = { "SimpleTextOutput" }, { &efi_tcg_protocol_guid, "Tcg" }, + { &efi_tcg2_protocol_guid, + "Tcg2" }, { &efi_tcp4_protocol_guid, "Tcp4" }, { &efi_tcp4_service_binding_protocol_guid, -- cgit v1.2.3-55-g7522 From 8706ae36d3bbfaee3ac0e79555f68ac43e1da1af Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 10 Mar 2025 11:20:15 +0000 Subject: [efi] Add EFI_SIGNATURE_LIST header and GUID definitions Signed-off-by: Michael Brown --- src/include/ipxe/efi/Guid/GlobalVariable.h | 194 ++++++++++++ src/include/ipxe/efi/Guid/ImageAuthentication.h | 387 ++++++++++++++++++++++++ src/include/ipxe/efi/Protocol/Hash.h | 171 +++++++++++ src/include/ipxe/efi/efi.h | 1 + src/interface/efi/efi_debug.c | 2 + src/interface/efi/efi_guid.c | 4 + 6 files changed, 759 insertions(+) create mode 100644 src/include/ipxe/efi/Guid/GlobalVariable.h create mode 100644 src/include/ipxe/efi/Guid/ImageAuthentication.h create mode 100644 src/include/ipxe/efi/Protocol/Hash.h (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/include/ipxe/efi/Guid/GlobalVariable.h b/src/include/ipxe/efi/Guid/GlobalVariable.h new file mode 100644 index 000000000..e8f4e0d2b --- /dev/null +++ b/src/include/ipxe/efi/Guid/GlobalVariable.h @@ -0,0 +1,194 @@ +/** @file + GUID for EFI (NVRAM) Variables. + + Copyright (c) 2006 - 2024, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Revision Reference: + GUID defined in UEFI 2.1 +**/ + +#ifndef __GLOBAL_VARIABLE_GUID_H__ +#define __GLOBAL_VARIABLE_GUID_H__ + +FILE_LICENCE ( BSD2_PATENT ); + +#define EFI_GLOBAL_VARIABLE \ + { \ + 0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C } \ + } + +extern EFI_GUID gEfiGlobalVariableGuid; + +// +// Follow UEFI 2.4 spec: +// To prevent name collisions with possible future globally defined variables, +// other internal firmware data variables that are not defined here must be +// saved with a unique VendorGuid other than EFI_GLOBAL_VARIABLE or +// any other GUID defined by the UEFI Specification. Implementations must +// only permit the creation of variables with a UEFI Specification-defined +// VendorGuid when these variables are documented in the UEFI Specification. +// +// Note: except the globally defined variables defined below, the spec also defines +// L"Boot####" - A boot load option. +// L"Driver####" - A driver load option. +// L"SysPrep####" - A System Prep application load option. +// L"Key####" - Describes hot key relationship with a Boot#### load option. +// The attribute for them is NV+BS+RT, #### is a printed hex value, and no 0x or h +// is included in the hex value. They can not be expressed as a #define like other globally +// defined variables, it is because we can not list the Boot0000, Boot0001, etc one by one. +// + +/// +/// The language codes that the firmware supports. This value is deprecated. +/// Its attribute is BS+RT. +/// +#define EFI_LANG_CODES_VARIABLE_NAME L"LangCodes" +/// +/// The language code that the system is configured for. This value is deprecated. +/// Its attribute is NV+BS+RT. +/// +#define EFI_LANG_VARIABLE_NAME L"Lang" +/// +/// The firmware's boot managers timeout, in seconds, before initiating the default boot selection. +/// Its attribute is NV+BS+RT. +/// +#define EFI_TIME_OUT_VARIABLE_NAME L"Timeout" +/// +/// The language codes that the firmware supports. +/// Its attribute is BS+RT. +/// +#define EFI_PLATFORM_LANG_CODES_VARIABLE_NAME L"PlatformLangCodes" +/// +/// The language code that the system is configured for. +/// Its attribute is NV+BS+RT. +/// +#define EFI_PLATFORM_LANG_VARIABLE_NAME L"PlatformLang" +/// +/// The device path of the default input/output/error output console. +/// Its attribute is NV+BS+RT. +/// +#define EFI_CON_IN_VARIABLE_NAME L"ConIn" +#define EFI_CON_OUT_VARIABLE_NAME L"ConOut" +#define EFI_ERR_OUT_VARIABLE_NAME L"ErrOut" +/// +/// The device path of all possible input/output/error output devices. +/// Its attribute is BS+RT. +/// +#define EFI_CON_IN_DEV_VARIABLE_NAME L"ConInDev" +#define EFI_CON_OUT_DEV_VARIABLE_NAME L"ConOutDev" +#define EFI_ERR_OUT_DEV_VARIABLE_NAME L"ErrOutDev" +/// +/// The ordered boot option load list. +/// Its attribute is NV+BS+RT. +/// +#define EFI_BOOT_ORDER_VARIABLE_NAME L"BootOrder" +/// +/// The boot option for the next boot only. +/// Its attribute is NV+BS+RT. +/// +#define EFI_BOOT_NEXT_VARIABLE_NAME L"BootNext" +/// +/// The boot option that was selected for the current boot. +/// Its attribute is BS+RT. +/// +#define EFI_BOOT_CURRENT_VARIABLE_NAME L"BootCurrent" +/// +/// The types of boot options supported by the boot manager. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_BOOT_OPTION_SUPPORT_VARIABLE_NAME L"BootOptionSupport" +/// +/// The ordered driver load option list. +/// Its attribute is NV+BS+RT. +/// +#define EFI_DRIVER_ORDER_VARIABLE_NAME L"DriverOrder" +/// +/// The ordered System Prep Application load option list. +/// Its attribute is NV+BS+RT. +/// +#define EFI_SYS_PREP_ORDER_VARIABLE_NAME L"SysPrepOrder" +/// +/// Identifies the level of hardware error record persistence +/// support implemented by the platform. This variable is +/// only modified by firmware and is read-only to the OS. +/// Its attribute is NV+BS+RT. +/// +#define EFI_HW_ERR_REC_SUPPORT_VARIABLE_NAME L"HwErrRecSupport" +/// +/// Whether the system is operating in setup mode (1) or not (0). +/// All other values are reserved. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_SETUP_MODE_NAME L"SetupMode" +/// +/// The Key Exchange Key Signature Database. +/// Its attribute is NV+BS+RT+AT. +/// +#define EFI_KEY_EXCHANGE_KEY_NAME L"KEK" +/// +/// The public Platform Key. +/// Its attribute is NV+BS+RT+AT. +/// +#define EFI_PLATFORM_KEY_NAME L"PK" +/// +/// Array of GUIDs representing the type of signatures supported +/// by the platform firmware. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_SIGNATURE_SUPPORT_NAME L"SignatureSupport" +/// +/// Whether the platform firmware is operating in Secure boot mode (1) or not (0). +/// All other values are reserved. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_SECURE_BOOT_MODE_NAME L"SecureBoot" +/// +/// The OEM's default Key Exchange Key Signature Database. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_KEK_DEFAULT_VARIABLE_NAME L"KEKDefault" +/// +/// The OEM's default public Platform Key. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_PK_DEFAULT_VARIABLE_NAME L"PKDefault" +/// +/// The OEM's default secure boot signature store. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_DB_DEFAULT_VARIABLE_NAME L"dbDefault" +/// +/// The OEM's default secure boot blacklist signature store. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_DBX_DEFAULT_VARIABLE_NAME L"dbxDefault" +/// +/// The OEM's default secure boot timestamp signature store. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_DBT_DEFAULT_VARIABLE_NAME L"dbtDefault" +/// +/// Allows the firmware to indicate supported features and actions to the OS. +/// Its attribute is BS+RT. +/// +#define EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME L"OsIndicationsSupported" +/// +/// Allows the OS to request the firmware to enable certain features and to take certain actions. +/// Its attribute is NV+BS+RT. +/// +#define EFI_OS_INDICATIONS_VARIABLE_NAME L"OsIndications" +/// +/// Whether the system is configured to use only vendor provided +/// keys or not. Should be treated as read-only. +/// Its attribute is BS+RT. +/// +#define EFI_VENDOR_KEYS_VARIABLE_NAME L"VendorKeys" + +/// +/// Whether the platform firmware is operating in device authentication boot mode (1) or not (0). +/// The content is UINT8. +/// +#define EFI_DEVICE_AUTH_BOOT_MODE_NAME L"devAuthBoot" + +#endif diff --git a/src/include/ipxe/efi/Guid/ImageAuthentication.h b/src/include/ipxe/efi/Guid/ImageAuthentication.h new file mode 100644 index 000000000..9af0b41af --- /dev/null +++ b/src/include/ipxe/efi/Guid/ImageAuthentication.h @@ -0,0 +1,387 @@ +/** @file + Image signature database are defined for the signed image validation. + + Copyright (c) 2009 - 2024, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Revision Reference: + GUIDs defined in UEFI 2.5 spec. +**/ + +#ifndef __IMAGE_AUTHTICATION_H__ +#define __IMAGE_AUTHTICATION_H__ + +FILE_LICENCE ( BSD2_PATENT ); + +#include +#include + +#define EFI_IMAGE_SECURITY_DATABASE_GUID \ + { \ + 0xd719b2cb, 0x3d3a, 0x4596, { 0xa3, 0xbc, 0xda, 0xd0, 0xe, 0x67, 0x65, 0x6f } \ + } + +/// +/// Varialbe name with guid EFI_IMAGE_SECURITY_DATABASE_GUID +/// for the authorized signature database. +/// +#define EFI_IMAGE_SECURITY_DATABASE L"db" +/// +/// Varialbe name with guid EFI_IMAGE_SECURITY_DATABASE_GUID +/// for the forbidden signature database. +/// +#define EFI_IMAGE_SECURITY_DATABASE1 L"dbx" +/// +/// Variable name with guid EFI_IMAGE_SECURITY_DATABASE_GUID +/// for the timestamp signature database. +/// +#define EFI_IMAGE_SECURITY_DATABASE2 L"dbt" + +#define SECURE_BOOT_MODE_ENABLE 1 +#define SECURE_BOOT_MODE_DISABLE 0 + +#define SETUP_MODE 1 +#define USER_MODE 0 + +#define DEVICE_AUTH_BOOT_MODE_ENABLE 1 +#define DEVICE_AUTH_BOOT_MODE_DISABLE 0 + +// *********************************************************************** +// Signature Database +// *********************************************************************** +/// +/// The format of a signature database. +/// +#pragma pack(1) + +typedef struct { + /// + /// An identifier which identifies the agent which added the signature to the list. + /// + EFI_GUID SignatureOwner; + /// + /// The format of the signature is defined by the SignatureType. + /// + UINT8 SignatureData[1]; +} EFI_SIGNATURE_DATA; + +typedef struct { + /// + /// Type of the signature. GUID signature types are defined in below. + /// + EFI_GUID SignatureType; + /// + /// Total size of the signature list, including this header. + /// + UINT32 SignatureListSize; + /// + /// Size of the signature header which precedes the array of signatures. + /// + UINT32 SignatureHeaderSize; + /// + /// Size of each signature. + /// + UINT32 SignatureSize; + /// + /// Header before the array of signatures. The format of this header is specified + /// by the SignatureType. + /// UINT8 SignatureHeader[SignatureHeaderSize]; + /// + /// An array of signatures. Each signature is SignatureSize bytes in length. + /// EFI_SIGNATURE_DATA Signatures[][SignatureSize]; + /// +} EFI_SIGNATURE_LIST; + +typedef struct { + /// + /// The SHA256 hash of an X.509 certificate's To-Be-Signed contents. + /// + EFI_SHA256_HASH ToBeSignedHash; + /// + /// The time that the certificate shall be considered to be revoked. + /// + EFI_TIME TimeOfRevocation; +} EFI_CERT_X509_SHA256; + +typedef struct { + /// + /// The SHA384 hash of an X.509 certificate's To-Be-Signed contents. + /// + EFI_SHA384_HASH ToBeSignedHash; + /// + /// The time that the certificate shall be considered to be revoked. + /// + EFI_TIME TimeOfRevocation; +} EFI_CERT_X509_SHA384; + +typedef struct { + /// + /// The SHA512 hash of an X.509 certificate's To-Be-Signed contents. + /// + EFI_SHA512_HASH ToBeSignedHash; + /// + /// The time that the certificate shall be considered to be revoked. + /// + EFI_TIME TimeOfRevocation; +} EFI_CERT_X509_SHA512; + +typedef UINT8 EFI_SM3_HASH[32]; + +typedef struct { + /// + /// The SM3 hash of an X.509 certificate's To-Be-Signed contents. + /// + EFI_SM3_HASH ToBeSignedHash; + /// + /// The time that the certificate shall be considered to be revoked. + /// + EFI_TIME TimeOfRevocation; +} EFI_CERT_X509_SM3; + +#pragma pack() + +/// +/// This identifies a signature containing a SHA-256 hash. The SignatureHeader size shall +/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) + +/// 32 bytes. +/// +#define EFI_CERT_SHA256_GUID \ + { \ + 0xc1c41626, 0x504c, 0x4092, {0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28} \ + } + +/// +/// This identifies a signature containing an RSA-2048 key. The key (only the modulus +/// since the public key exponent is known to be 0x10001) shall be stored in big-endian +/// order. +/// The SignatureHeader size shall always be 0. The SignatureSize shall always be 16 (size +/// of SignatureOwner component) + 256 bytes. +/// +#define EFI_CERT_RSA2048_GUID \ + { \ + 0x3c5766e8, 0x269c, 0x4e34, {0xaa, 0x14, 0xed, 0x77, 0x6e, 0x85, 0xb3, 0xb6} \ + } + +/// +/// This identifies a signature containing a RSA-2048 signature of a SHA-256 hash. The +/// SignatureHeader size shall always be 0. The SignatureSize shall always be 16 (size of +/// SignatureOwner component) + 256 bytes. +/// +#define EFI_CERT_RSA2048_SHA256_GUID \ + { \ + 0xe2b36190, 0x879b, 0x4a3d, {0xad, 0x8d, 0xf2, 0xe7, 0xbb, 0xa3, 0x27, 0x84} \ + } + +/// +/// This identifies a signature containing a SHA-1 hash. The SignatureSize shall always +/// be 16 (size of SignatureOwner component) + 20 bytes. +/// +#define EFI_CERT_SHA1_GUID \ + { \ + 0x826ca512, 0xcf10, 0x4ac9, {0xb1, 0x87, 0xbe, 0x1, 0x49, 0x66, 0x31, 0xbd} \ + } + +/// +/// This identifies a signature containing a SM3 hash. The SignatureSize shall always +/// be 16 (size of SignatureOwner component) + 32 bytes. +/// +#define EFI_CERT_SM3_GUID \ + { \ + 0x57347f87, 0x7a9b, 0x403a, { 0xb9, 0x3c, 0xdc, 0x4a, 0xfb, 0x7a, 0xe, 0xbc } \ + } + +/// +/// TThis identifies a signature containing a RSA-2048 signature of a SHA-1 hash. The +/// SignatureHeader size shall always be 0. The SignatureSize shall always be 16 (size of +/// SignatureOwner component) + 256 bytes. +/// +#define EFI_CERT_RSA2048_SHA1_GUID \ + { \ + 0x67f8444f, 0x8743, 0x48f1, {0xa3, 0x28, 0x1e, 0xaa, 0xb8, 0x73, 0x60, 0x80} \ + } + +/// +/// This identifies a signature based on an X.509 certificate. If the signature is an X.509 +/// certificate then verification of the signature of an image should validate the public +/// key certificate in the image using certificate path verification, up to this X.509 +/// certificate as a trusted root. The SignatureHeader size shall always be 0. The +/// SignatureSize may vary but shall always be 16 (size of the SignatureOwner component) + +/// the size of the certificate itself. +/// Note: This means that each certificate will normally be in a separate EFI_SIGNATURE_LIST. +/// +#define EFI_CERT_X509_GUID \ + { \ + 0xa5c059a1, 0x94e4, 0x4aa7, {0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72} \ + } + +/// +/// This identifies a signature containing the SM3 hash of an X.509 certificate's To-Be-Signed +/// contents, and a time of revocation. The SignatureHeader size shall always be 0. The +/// SignatureSize shall always be 16 (size of the SignatureOwner component) + 32 bytes for +/// an EFI_CERT_X509_SM3 structure. If the TimeOfRevocation is non-zero, the certificate should +/// be considered to be revoked from that time and onwards, and otherwise the certificate shall +/// be considered to always be revoked. +/// +#define EFI_CERT_X509_SM3_GUID \ + { \ + 0x60d807e5, 0x10b4, 0x49a9, {0x93, 0x31, 0xe4, 0x4, 0x37, 0x88, 0x8d, 0x37 } \ + } + +/// +/// This identifies a signature containing a SHA-224 hash. The SignatureHeader size shall +/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) + +/// 28 bytes. +/// +#define EFI_CERT_SHA224_GUID \ + { \ + 0xb6e5233, 0xa65c, 0x44c9, {0x94, 0x7, 0xd9, 0xab, 0x83, 0xbf, 0xc8, 0xbd} \ + } + +/// +/// This identifies a signature containing a SHA-384 hash. The SignatureHeader size shall +/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) + +/// 48 bytes. +/// +#define EFI_CERT_SHA384_GUID \ + { \ + 0xff3e5307, 0x9fd0, 0x48c9, {0x85, 0xf1, 0x8a, 0xd5, 0x6c, 0x70, 0x1e, 0x1} \ + } + +/// +/// This identifies a signature containing a SHA-512 hash. The SignatureHeader size shall +/// always be 0. The SignatureSize shall always be 16 (size of SignatureOwner component) + +/// 64 bytes. +/// +#define EFI_CERT_SHA512_GUID \ + { \ + 0x93e0fae, 0xa6c4, 0x4f50, {0x9f, 0x1b, 0xd4, 0x1e, 0x2b, 0x89, 0xc1, 0x9a} \ + } + +/// +/// This identifies a signature containing the SHA256 hash of an X.509 certificate's +/// To-Be-Signed contents, and a time of revocation. The SignatureHeader size shall +/// always be 0. The SignatureSize shall always be 16 (size of the SignatureOwner component) +/// + 48 bytes for an EFI_CERT_X509_SHA256 structure. If the TimeOfRevocation is non-zero, +/// the certificate should be considered to be revoked from that time and onwards, and +/// otherwise the certificate shall be considered to always be revoked. +/// +#define EFI_CERT_X509_SHA256_GUID \ + { \ + 0x3bd2a492, 0x96c0, 0x4079, {0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed } \ + } + +/// +/// This identifies a signature containing the SHA384 hash of an X.509 certificate's +/// To-Be-Signed contents, and a time of revocation. The SignatureHeader size shall +/// always be 0. The SignatureSize shall always be 16 (size of the SignatureOwner component) +/// + 64 bytes for an EFI_CERT_X509_SHA384 structure. If the TimeOfRevocation is non-zero, +/// the certificate should be considered to be revoked from that time and onwards, and +/// otherwise the certificate shall be considered to always be revoked. +/// +#define EFI_CERT_X509_SHA384_GUID \ + { \ + 0x7076876e, 0x80c2, 0x4ee6, {0xaa, 0xd2, 0x28, 0xb3, 0x49, 0xa6, 0x86, 0x5b } \ + } + +/// +/// This identifies a signature containing the SHA512 hash of an X.509 certificate's +/// To-Be-Signed contents, and a time of revocation. The SignatureHeader size shall +/// always be 0. The SignatureSize shall always be 16 (size of the SignatureOwner component) +/// + 80 bytes for an EFI_CERT_X509_SHA512 structure. If the TimeOfRevocation is non-zero, +/// the certificate should be considered to be revoked from that time and onwards, and +/// otherwise the certificate shall be considered to always be revoked. +/// +#define EFI_CERT_X509_SHA512_GUID \ + { \ + 0x446dbf63, 0x2502, 0x4cda, {0xbc, 0xfa, 0x24, 0x65, 0xd2, 0xb0, 0xfe, 0x9d } \ + } + +/// +/// This identifies a signature containing a DER-encoded PKCS #7 version 1.5 [RFC2315] +/// SignedData value. +/// +#define EFI_CERT_TYPE_PKCS7_GUID \ + { \ + 0x4aafd29d, 0x68df, 0x49ee, {0x8a, 0xa9, 0x34, 0x7d, 0x37, 0x56, 0x65, 0xa7} \ + } + +// *********************************************************************** +// Image Execution Information Table Definition +// *********************************************************************** +typedef UINT32 EFI_IMAGE_EXECUTION_ACTION; + +#define EFI_IMAGE_EXECUTION_AUTHENTICATION 0x00000007 +#define EFI_IMAGE_EXECUTION_AUTH_UNTESTED 0x00000000 +#define EFI_IMAGE_EXECUTION_AUTH_SIG_FAILED 0x00000001 +#define EFI_IMAGE_EXECUTION_AUTH_SIG_PASSED 0x00000002 +#define EFI_IMAGE_EXECUTION_AUTH_SIG_NOT_FOUND 0x00000003 +#define EFI_IMAGE_EXECUTION_AUTH_SIG_FOUND 0x00000004 +#define EFI_IMAGE_EXECUTION_POLICY_FAILED 0x00000005 +#define EFI_IMAGE_EXECUTION_INITIALIZED 0x00000008 + +// +// EFI_IMAGE_EXECUTION_INFO is added to EFI System Configuration Table +// and assigned the GUID EFI_IMAGE_SECURITY_DATABASE_GUID. +// +typedef struct { + /// + /// Describes the action taken by the firmware regarding this image. + /// + EFI_IMAGE_EXECUTION_ACTION Action; + /// + /// Size of all of the entire structure. + /// + UINT32 InfoSize; + /// + /// If this image was a UEFI device driver (for option ROM, for example) this is the + /// null-terminated, user-friendly name for the device. If the image was for an application, + /// then this is the name of the application. If this cannot be determined, then a simple + /// NULL character should be put in this position. + /// CHAR16 Name[]; + /// + + /// + /// For device drivers, this is the device path of the device for which this device driver + /// was intended. In some cases, the driver itself may be stored as part of the system + /// firmware, but this field should record the device's path, not the firmware path. For + /// applications, this is the device path of the application. If this cannot be determined, + /// a simple end-of-path device node should be put in this position. + /// EFI_DEVICE_PATH_PROTOCOL DevicePath; + /// + + /// + /// Zero or more image signatures. If the image contained no signatures, + /// then this field is empty. + /// EFI_SIGNATURE_LIST Signature; + /// +} EFI_IMAGE_EXECUTION_INFO; + +typedef struct { + /// + /// Number of EFI_IMAGE_EXECUTION_INFO structures. + /// + UINTN NumberOfImages; + /// + /// Number of image instances of EFI_IMAGE_EXECUTION_INFO structures. + /// + // EFI_IMAGE_EXECUTION_INFO InformationInfo[] +} EFI_IMAGE_EXECUTION_INFO_TABLE; + +extern EFI_GUID gEfiImageSecurityDatabaseGuid; +extern EFI_GUID gEfiCertSha256Guid; +extern EFI_GUID gEfiCertRsa2048Guid; +extern EFI_GUID gEfiCertRsa2048Sha256Guid; +extern EFI_GUID gEfiCertSha1Guid; +extern EFI_GUID gEfiCertRsa2048Sha1Guid; +extern EFI_GUID gEfiCertX509Guid; +extern EFI_GUID gEfiCertSha224Guid; +extern EFI_GUID gEfiCertSha384Guid; +extern EFI_GUID gEfiCertSha512Guid; +extern EFI_GUID gEfiCertX509Sha256Guid; +extern EFI_GUID gEfiCertX509Sha384Guid; +extern EFI_GUID gEfiCertX509Sha512Guid; +extern EFI_GUID gEfiCertPkcs7Guid; +extern EFI_GUID gEfiCertSm3Guid; +extern EFI_GUID gEfiCertX509Sm3Guid; + +#endif diff --git a/src/include/ipxe/efi/Protocol/Hash.h b/src/include/ipxe/efi/Protocol/Hash.h new file mode 100644 index 000000000..ac6dcd193 --- /dev/null +++ b/src/include/ipxe/efi/Protocol/Hash.h @@ -0,0 +1,171 @@ +/** @file + EFI_HASH_SERVICE_BINDING_PROTOCOL as defined in UEFI 2.0. + EFI_HASH_PROTOCOL as defined in UEFI 2.0. + The EFI Hash Service Binding Protocol is used to locate hashing services support + provided by a driver and to create and destroy instances of the EFI Hash Protocol + so that a multiple drivers can use the underlying hashing services. + +Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __EFI_HASH_PROTOCOL_H__ +#define __EFI_HASH_PROTOCOL_H__ + +FILE_LICENCE ( BSD2_PATENT ); + +#define EFI_HASH_SERVICE_BINDING_PROTOCOL_GUID \ + { \ + 0x42881c98, 0xa4f3, 0x44b0, {0xa3, 0x9d, 0xdf, 0xa1, 0x86, 0x67, 0xd8, 0xcd } \ + } + +#define EFI_HASH_PROTOCOL_GUID \ + { \ + 0xc5184932, 0xdba5, 0x46db, {0xa5, 0xba, 0xcc, 0x0b, 0xda, 0x9c, 0x14, 0x35 } \ + } + +#define EFI_HASH_ALGORITHM_SHA1_GUID \ + { \ + 0x2ae9d80f, 0x3fb2, 0x4095, {0xb7, 0xb1, 0xe9, 0x31, 0x57, 0xb9, 0x46, 0xb6 } \ + } + +#define EFI_HASH_ALGORITHM_SHA224_GUID \ + { \ + 0x8df01a06, 0x9bd5, 0x4bf7, {0xb0, 0x21, 0xdb, 0x4f, 0xd9, 0xcc, 0xf4, 0x5b } \ + } + +#define EFI_HASH_ALGORITHM_SHA256_GUID \ + { \ + 0x51aa59de, 0xfdf2, 0x4ea3, {0xbc, 0x63, 0x87, 0x5f, 0xb7, 0x84, 0x2e, 0xe9 } \ + } + +#define EFI_HASH_ALGORITHM_SHA384_GUID \ + { \ + 0xefa96432, 0xde33, 0x4dd2, {0xae, 0xe6, 0x32, 0x8c, 0x33, 0xdf, 0x77, 0x7a } \ + } + +#define EFI_HASH_ALGORITHM_SHA512_GUID \ + { \ + 0xcaa4381e, 0x750c, 0x4770, {0xb8, 0x70, 0x7a, 0x23, 0xb4, 0xe4, 0x21, 0x30 } \ + } + +#define EFI_HASH_ALGORTIHM_MD5_GUID \ + { \ + 0xaf7c79c, 0x65b5, 0x4319, {0xb0, 0xae, 0x44, 0xec, 0x48, 0x4e, 0x4a, 0xd7 } \ + } + +#define EFI_HASH_ALGORITHM_SHA1_NOPAD_GUID \ + { \ + 0x24c5dc2f, 0x53e2, 0x40ca, {0x9e, 0xd6, 0xa5, 0xd9, 0xa4, 0x9f, 0x46, 0x3b } \ + } + +#define EFI_HASH_ALGORITHM_SHA256_NOPAD_GUID \ + { \ + 0x8628752a, 0x6cb7, 0x4814, {0x96, 0xfc, 0x24, 0xa8, 0x15, 0xac, 0x22, 0x26 } \ + } + +// +// Note: Use of the following algorithms with EFI_HASH_PROTOCOL is deprecated. +// EFI_HASH_ALGORITHM_SHA1_GUID +// EFI_HASH_ALGORITHM_SHA224_GUID +// EFI_HASH_ALGORITHM_SHA256_GUID +// EFI_HASH_ALGORITHM_SHA384_GUID +// EFI_HASH_ALGORITHM_SHA512_GUID +// EFI_HASH_ALGORTIHM_MD5_GUID +// + +typedef struct _EFI_HASH_PROTOCOL EFI_HASH_PROTOCOL; + +typedef UINT8 EFI_MD5_HASH[16]; +typedef UINT8 EFI_SHA1_HASH[20]; +typedef UINT8 EFI_SHA224_HASH[28]; +typedef UINT8 EFI_SHA256_HASH[32]; +typedef UINT8 EFI_SHA384_HASH[48]; +typedef UINT8 EFI_SHA512_HASH[64]; + +typedef union { + EFI_MD5_HASH *Md5Hash; + EFI_SHA1_HASH *Sha1Hash; + EFI_SHA224_HASH *Sha224Hash; + EFI_SHA256_HASH *Sha256Hash; + EFI_SHA384_HASH *Sha384Hash; + EFI_SHA512_HASH *Sha512Hash; +} EFI_HASH_OUTPUT; + +/** + Returns the size of the hash which results from a specific algorithm. + + @param[in] This Points to this instance of EFI_HASH_PROTOCOL. + @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. + @param[out] HashSize Holds the returned size of the algorithm's hash. + + @retval EFI_SUCCESS Hash size returned successfully. + @retval EFI_INVALID_PARAMETER HashSize is NULL or HashAlgorithm is NULL. + @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported + by this driver. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_HASH_GET_HASH_SIZE)( + IN CONST EFI_HASH_PROTOCOL *This, + IN CONST EFI_GUID *HashAlgorithm, + OUT UINTN *HashSize + ); + +/** + Creates a hash for the specified message text. + + @param[in] This Points to this instance of EFI_HASH_PROTOCOL. + @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. + @param[in] Extend Specifies whether to create a new hash (FALSE) or extend the specified + existing hash (TRUE). + @param[in] Message Points to the start of the message. + @param[in] MessageSize The size of Message, in bytes. + @param[in,out] Hash On input, if Extend is TRUE, then this parameter holds a pointer + to a pointer to an array containing the hash to extend. If Extend + is FALSE, then this parameter holds a pointer to a pointer to a + caller-allocated array that will receive the result of the hash + computation. On output (regardless of the value of Extend), the + array will contain the result of the hash computation. + + @retval EFI_SUCCESS Hash returned successfully. + @retval EFI_INVALID_PARAMETER Message or Hash, HashAlgorithm is NULL or MessageSize is 0. + MessageSize is not an integer multiple of block size. + @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this + driver. Or, Extend is TRUE, and the algorithm doesn't support extending the hash. + +**/ +typedef +EFI_STATUS +(EFIAPI *EFI_HASH_HASH)( + IN CONST EFI_HASH_PROTOCOL *This, + IN CONST EFI_GUID *HashAlgorithm, + IN BOOLEAN Extend, + IN CONST UINT8 *Message, + IN UINT64 MessageSize, + IN OUT EFI_HASH_OUTPUT *Hash + ); + +/// +/// This protocol allows creating a hash of an arbitrary message digest +/// using one or more hash algorithms. +/// +struct _EFI_HASH_PROTOCOL { + EFI_HASH_GET_HASH_SIZE GetHashSize; + EFI_HASH_HASH Hash; +}; + +extern EFI_GUID gEfiHashServiceBindingProtocolGuid; +extern EFI_GUID gEfiHashProtocolGuid; +extern EFI_GUID gEfiHashAlgorithmSha1Guid; +extern EFI_GUID gEfiHashAlgorithmSha224Guid; +extern EFI_GUID gEfiHashAlgorithmSha256Guid; +extern EFI_GUID gEfiHashAlgorithmSha384Guid; +extern EFI_GUID gEfiHashAlgorithmSha512Guid; +extern EFI_GUID gEfiHashAlgorithmMD5Guid; +extern EFI_GUID gEfiHashAlgorithmSha1NoPadGuid; +extern EFI_GUID gEfiHashAlgorithmSha256NoPadGuid; + +#endif diff --git a/src/include/ipxe/efi/efi.h b/src/include/ipxe/efi/efi.h index 843c79e2e..ef492849e 100644 --- a/src/include/ipxe/efi/efi.h +++ b/src/include/ipxe/efi/efi.h @@ -245,6 +245,7 @@ extern EFI_GUID efi_usb2_hc_protocol_guid; extern EFI_GUID efi_usb_io_protocol_guid; extern EFI_GUID efi_vlan_config_protocol_guid; +extern EFI_GUID efi_cert_x509_guid; extern EFI_GUID efi_file_info_id; extern EFI_GUID efi_file_system_info_id; diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 895a712bd..81c442179 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -103,6 +103,8 @@ static struct efi_well_known_guid efi_well_known_guids[] = { "BlockIo2" }, { &efi_bus_specific_driver_override_protocol_guid, "BusSpecificDriverOverride" }, + { &efi_cert_x509_guid, + "CertX509" }, { &efi_component_name_protocol_guid, "ComponentName" }, { &efi_component_name2_protocol_guid, diff --git a/src/interface/efi/efi_guid.c b/src/interface/efi/efi_guid.c index 16c1a5738..bd45d05b9 100644 --- a/src/interface/efi/efi_guid.c +++ b/src/interface/efi/efi_guid.c @@ -83,6 +83,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include +#include /** @file * @@ -391,6 +392,9 @@ EFI_GUID efi_usb_io_protocol_guid EFI_GUID efi_vlan_config_protocol_guid = EFI_VLAN_CONFIG_PROTOCOL_GUID; +/** X.509 certificate GUID */ +EFI_GUID efi_cert_x509_guid = EFI_CERT_X509_GUID; + /** File information GUID */ EFI_GUID efi_file_info_id = EFI_FILE_INFO_ID; -- cgit v1.2.3-55-g7522 From 011c778f06fbfa315f8749f39df016d8865422c6 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 11 Mar 2025 11:52:37 +0000 Subject: [efi] Allow efi_guid_ntoa() to be used in non-EFI builds The debug message transcription of well-known EFI GUIDs does not require any EFI boot services calls. Move this code from efi_debug.c to efi_guid.c, to allow it to be linked in to non-EFI builds. We continue to rely on linker garbage collection to ensure that the code is omitted completely from any non-debug builds. Signed-off-by: Michael Brown --- src/interface/efi/efi_debug.c | 236 ------------------------------------------ src/interface/efi/efi_guid.c | 236 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 236 insertions(+), 236 deletions(-) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 81c442179..030c6a93e 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -31,9 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ #include -#include #include -#include #include #include #include @@ -47,240 +45,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt; EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt ); -/** HttpBootDxe module GUID */ -static EFI_GUID efi_http_boot_dxe_guid = { - 0xecebcb00, 0xd9c8, 0x11e4, - { 0xaf, 0x3d, 0x8c, 0xdc, 0xd4, 0x26, 0xc9, 0x73 } -}; - -/** IScsiDxe module GUID */ -static EFI_GUID efi_iscsi_dxe_guid = { - 0x86cddf93, 0x4872, 0x4597, - { 0x8a, 0xf9, 0xa3, 0x5a, 0xe4, 0xd3, 0x72, 0x5f } -}; - -/** Old IScsi4Dxe module GUID */ -static EFI_GUID efi_iscsi4_dxe_guid = { - 0x4579b72d, 0x7ec4, 0x4dd4, - { 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7 } -}; - -/** UefiPxeBcDxe module GUID */ -static EFI_GUID efi_uefi_pxe_bc_dxe_guid = { - 0xb95e9fda, 0x26de, 0x48d2, - { 0x88, 0x07, 0x1f, 0x91, 0x07, 0xac, 0x5e, 0x3a } -}; - -/** VlanConfigDxe module GUID */ -static EFI_GUID efi_vlan_config_dxe_guid = { - 0xe4f61863, 0xfe2c, 0x4b56, - { 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf } -}; - -/** A well-known GUID */ -struct efi_well_known_guid { - /** GUID */ - EFI_GUID *guid; - /** Name */ - const char *name; -}; - -/** Well-known GUIDs */ -static struct efi_well_known_guid efi_well_known_guids[] = { - { &efi_absolute_pointer_protocol_guid, - "AbsolutePointer" }, - { &efi_acpi_table_protocol_guid, - "AcpiTable" }, - { &efi_apple_net_boot_protocol_guid, - "AppleNetBoot" }, - { &efi_arp_protocol_guid, - "Arp" }, - { &efi_arp_service_binding_protocol_guid, - "ArpSb" }, - { &efi_block_io_protocol_guid, - "BlockIo" }, - { &efi_block_io2_protocol_guid, - "BlockIo2" }, - { &efi_bus_specific_driver_override_protocol_guid, - "BusSpecificDriverOverride" }, - { &efi_cert_x509_guid, - "CertX509" }, - { &efi_component_name_protocol_guid, - "ComponentName" }, - { &efi_component_name2_protocol_guid, - "ComponentName2" }, - { &efi_console_control_protocol_guid, - "ConsoleControl" }, - { &efi_device_path_protocol_guid, - "DevicePath" }, - { &efi_driver_binding_protocol_guid, - "DriverBinding" }, - { &efi_dhcp4_protocol_guid, - "Dhcp4" }, - { &efi_dhcp4_service_binding_protocol_guid, - "Dhcp4Sb" }, - { &efi_dhcp6_protocol_guid, - "Dhcp6" }, - { &efi_dhcp6_service_binding_protocol_guid, - "Dhcp6Sb" }, - { &efi_disk_io_protocol_guid, - "DiskIo" }, - { &efi_dns4_protocol_guid, - "Dns4" }, - { &efi_dns4_service_binding_protocol_guid, - "Dns4Sb" }, - { &efi_dns6_protocol_guid, - "Dns6" }, - { &efi_dns6_service_binding_protocol_guid, - "Dns6Sb" }, - { &efi_graphics_output_protocol_guid, - "GraphicsOutput" }, - { &efi_hii_config_access_protocol_guid, - "HiiConfigAccess" }, - { &efi_hii_font_protocol_guid, - "HiiFont" }, - { &efi_http_boot_dxe_guid, - "HttpBootDxe" }, - { &efi_http_protocol_guid, - "Http" }, - { &efi_http_service_binding_protocol_guid, - "HttpSb" }, - { &efi_ip4_protocol_guid, - "Ip4" }, - { &efi_ip4_config_protocol_guid, - "Ip4Config" }, - { &efi_ip4_config2_protocol_guid, - "Ip4Config2" }, - { &efi_ip4_service_binding_protocol_guid, - "Ip4Sb" }, - { &efi_ip6_protocol_guid, - "Ip6" }, - { &efi_ip6_config_protocol_guid, - "Ip6Config" }, - { &efi_ip6_service_binding_protocol_guid, - "Ip6Sb" }, - { &efi_iscsi_dxe_guid, - "IScsiDxe" }, - { &efi_iscsi4_dxe_guid, - "IScsi4Dxe" }, - { &efi_load_file_protocol_guid, - "LoadFile" }, - { &efi_load_file2_protocol_guid, - "LoadFile2" }, - { &efi_loaded_image_protocol_guid, - "LoadedImage" }, - { &efi_loaded_image_device_path_protocol_guid, - "LoadedImageDevicePath"}, - { &efi_managed_network_protocol_guid, - "ManagedNetwork" }, - { &efi_managed_network_service_binding_protocol_guid, - "ManagedNetworkSb" }, - { &efi_mtftp4_protocol_guid, - "Mtftp4" }, - { &efi_mtftp4_service_binding_protocol_guid, - "Mtftp4Sb" }, - { &efi_mtftp6_protocol_guid, - "Mtftp6" }, - { &efi_mtftp6_service_binding_protocol_guid, - "Mtftp6Sb" }, - { &efi_nii_protocol_guid, - "Nii" }, - { &efi_nii31_protocol_guid, - "Nii31" }, - { &efi_pci_io_protocol_guid, - "PciIo" }, - { &efi_pci_root_bridge_io_protocol_guid, - "PciRootBridgeIo" }, - { &efi_pxe_base_code_protocol_guid, - "PxeBaseCode" }, - { &efi_serial_io_protocol_guid, - "SerialIo" }, - { &efi_shim_lock_protocol_guid, - "ShimLock" }, - { &efi_simple_file_system_protocol_guid, - "SimpleFileSystem" }, - { &efi_simple_network_protocol_guid, - "SimpleNetwork" }, - { &efi_simple_pointer_protocol_guid, - "SimplePointer" }, - { &efi_simple_text_input_protocol_guid, - "SimpleTextInput" }, - { &efi_simple_text_input_ex_protocol_guid, - "SimpleTextInputEx" }, - { &efi_simple_text_output_protocol_guid, - "SimpleTextOutput" }, - { &efi_tcg_protocol_guid, - "Tcg" }, - { &efi_tcg2_protocol_guid, - "Tcg2" }, - { &efi_tcp4_protocol_guid, - "Tcp4" }, - { &efi_tcp4_service_binding_protocol_guid, - "Tcp4Sb" }, - { &efi_tcp6_protocol_guid, - "Tcp6" }, - { &efi_tcp6_service_binding_protocol_guid, - "Tcp6Sb" }, - { &efi_tree_protocol_guid, - "TrEE" }, - { &efi_udp4_protocol_guid, - "Udp4" }, - { &efi_udp4_service_binding_protocol_guid, - "Udp4Sb" }, - { &efi_udp6_protocol_guid, - "Udp6" }, - { &efi_udp6_service_binding_protocol_guid, - "Udp6Sb" }, - { &efi_uefi_pxe_bc_dxe_guid, - "UefiPxeBcDxe" }, - { &efi_uga_draw_protocol_guid, - "UgaDraw" }, - { &efi_unicode_collation_protocol_guid, - "UnicodeCollation" }, - { &efi_usb_hc_protocol_guid, - "UsbHc" }, - { &efi_usb2_hc_protocol_guid, - "Usb2Hc" }, - { &efi_usb_io_protocol_guid, - "UsbIo" }, - { &efi_vlan_config_protocol_guid, - "VlanConfig" }, - { &efi_vlan_config_dxe_guid, - "VlanConfigDxe" }, -}; - -/** - * Convert GUID to a printable string - * - * @v guid GUID - * @ret string Printable string - */ -const __attribute__ (( pure )) char * efi_guid_ntoa ( CONST EFI_GUID *guid ) { - union { - union uuid uuid; - EFI_GUID guid; - } u; - unsigned int i; - - /* Sanity check */ - if ( ! guid ) - return NULL; - - /* Check for a match against well-known GUIDs */ - for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) / - sizeof ( efi_well_known_guids[0] ) ) ; i++ ) { - if ( memcmp ( guid, efi_well_known_guids[i].guid, - sizeof ( *guid ) ) == 0 ) { - return efi_well_known_guids[i].name; - } - } - - /* Convert GUID to standard endianness */ - memcpy ( &u.guid, guid, sizeof ( u.guid ) ); - uuid_mangle ( &u.uuid ); - return uuid_ntoa ( &u.uuid ); -} - /** * Name locate search type * diff --git a/src/interface/efi/efi_guid.c b/src/interface/efi/efi_guid.c index bd45d05b9..bd35b94cc 100644 --- a/src/interface/efi/efi_guid.c +++ b/src/interface/efi/efi_guid.c @@ -23,6 +23,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include +#include #include #include #include @@ -400,3 +402,237 @@ EFI_GUID efi_file_info_id = EFI_FILE_INFO_ID; /** File system information GUID */ EFI_GUID efi_file_system_info_id = EFI_FILE_SYSTEM_INFO_ID; + +/** HttpBootDxe module GUID */ +static EFI_GUID efi_http_boot_dxe_guid = { + 0xecebcb00, 0xd9c8, 0x11e4, + { 0xaf, 0x3d, 0x8c, 0xdc, 0xd4, 0x26, 0xc9, 0x73 } +}; + +/** IScsiDxe module GUID */ +static EFI_GUID efi_iscsi_dxe_guid = { + 0x86cddf93, 0x4872, 0x4597, + { 0x8a, 0xf9, 0xa3, 0x5a, 0xe4, 0xd3, 0x72, 0x5f } +}; + +/** Old IScsi4Dxe module GUID */ +static EFI_GUID efi_iscsi4_dxe_guid = { + 0x4579b72d, 0x7ec4, 0x4dd4, + { 0x84, 0x86, 0x08, 0x3c, 0x86, 0xb1, 0x82, 0xa7 } +}; + +/** UefiPxeBcDxe module GUID */ +static EFI_GUID efi_uefi_pxe_bc_dxe_guid = { + 0xb95e9fda, 0x26de, 0x48d2, + { 0x88, 0x07, 0x1f, 0x91, 0x07, 0xac, 0x5e, 0x3a } +}; + +/** VlanConfigDxe module GUID */ +static EFI_GUID efi_vlan_config_dxe_guid = { + 0xe4f61863, 0xfe2c, 0x4b56, + { 0xa8, 0xf4, 0x08, 0x51, 0x9b, 0xc4, 0x39, 0xdf } +}; + +/** A well-known GUID */ +struct efi_well_known_guid { + /** GUID */ + EFI_GUID *guid; + /** Name */ + const char *name; +}; + +/** Well-known GUIDs */ +static struct efi_well_known_guid efi_well_known_guids[] = { + { &efi_absolute_pointer_protocol_guid, + "AbsolutePointer" }, + { &efi_acpi_table_protocol_guid, + "AcpiTable" }, + { &efi_apple_net_boot_protocol_guid, + "AppleNetBoot" }, + { &efi_arp_protocol_guid, + "Arp" }, + { &efi_arp_service_binding_protocol_guid, + "ArpSb" }, + { &efi_block_io_protocol_guid, + "BlockIo" }, + { &efi_block_io2_protocol_guid, + "BlockIo2" }, + { &efi_bus_specific_driver_override_protocol_guid, + "BusSpecificDriverOverride" }, + { &efi_cert_x509_guid, + "CertX509" }, + { &efi_component_name_protocol_guid, + "ComponentName" }, + { &efi_component_name2_protocol_guid, + "ComponentName2" }, + { &efi_console_control_protocol_guid, + "ConsoleControl" }, + { &efi_device_path_protocol_guid, + "DevicePath" }, + { &efi_driver_binding_protocol_guid, + "DriverBinding" }, + { &efi_dhcp4_protocol_guid, + "Dhcp4" }, + { &efi_dhcp4_service_binding_protocol_guid, + "Dhcp4Sb" }, + { &efi_dhcp6_protocol_guid, + "Dhcp6" }, + { &efi_dhcp6_service_binding_protocol_guid, + "Dhcp6Sb" }, + { &efi_disk_io_protocol_guid, + "DiskIo" }, + { &efi_dns4_protocol_guid, + "Dns4" }, + { &efi_dns4_service_binding_protocol_guid, + "Dns4Sb" }, + { &efi_dns6_protocol_guid, + "Dns6" }, + { &efi_dns6_service_binding_protocol_guid, + "Dns6Sb" }, + { &efi_graphics_output_protocol_guid, + "GraphicsOutput" }, + { &efi_hii_config_access_protocol_guid, + "HiiConfigAccess" }, + { &efi_hii_font_protocol_guid, + "HiiFont" }, + { &efi_http_boot_dxe_guid, + "HttpBootDxe" }, + { &efi_http_protocol_guid, + "Http" }, + { &efi_http_service_binding_protocol_guid, + "HttpSb" }, + { &efi_ip4_protocol_guid, + "Ip4" }, + { &efi_ip4_config_protocol_guid, + "Ip4Config" }, + { &efi_ip4_config2_protocol_guid, + "Ip4Config2" }, + { &efi_ip4_service_binding_protocol_guid, + "Ip4Sb" }, + { &efi_ip6_protocol_guid, + "Ip6" }, + { &efi_ip6_config_protocol_guid, + "Ip6Config" }, + { &efi_ip6_service_binding_protocol_guid, + "Ip6Sb" }, + { &efi_iscsi_dxe_guid, + "IScsiDxe" }, + { &efi_iscsi4_dxe_guid, + "IScsi4Dxe" }, + { &efi_load_file_protocol_guid, + "LoadFile" }, + { &efi_load_file2_protocol_guid, + "LoadFile2" }, + { &efi_loaded_image_protocol_guid, + "LoadedImage" }, + { &efi_loaded_image_device_path_protocol_guid, + "LoadedImageDevicePath"}, + { &efi_managed_network_protocol_guid, + "ManagedNetwork" }, + { &efi_managed_network_service_binding_protocol_guid, + "ManagedNetworkSb" }, + { &efi_mtftp4_protocol_guid, + "Mtftp4" }, + { &efi_mtftp4_service_binding_protocol_guid, + "Mtftp4Sb" }, + { &efi_mtftp6_protocol_guid, + "Mtftp6" }, + { &efi_mtftp6_service_binding_protocol_guid, + "Mtftp6Sb" }, + { &efi_nii_protocol_guid, + "Nii" }, + { &efi_nii31_protocol_guid, + "Nii31" }, + { &efi_pci_io_protocol_guid, + "PciIo" }, + { &efi_pci_root_bridge_io_protocol_guid, + "PciRootBridgeIo" }, + { &efi_pxe_base_code_protocol_guid, + "PxeBaseCode" }, + { &efi_serial_io_protocol_guid, + "SerialIo" }, + { &efi_shim_lock_protocol_guid, + "ShimLock" }, + { &efi_simple_file_system_protocol_guid, + "SimpleFileSystem" }, + { &efi_simple_network_protocol_guid, + "SimpleNetwork" }, + { &efi_simple_pointer_protocol_guid, + "SimplePointer" }, + { &efi_simple_text_input_protocol_guid, + "SimpleTextInput" }, + { &efi_simple_text_input_ex_protocol_guid, + "SimpleTextInputEx" }, + { &efi_simple_text_output_protocol_guid, + "SimpleTextOutput" }, + { &efi_tcg_protocol_guid, + "Tcg" }, + { &efi_tcg2_protocol_guid, + "Tcg2" }, + { &efi_tcp4_protocol_guid, + "Tcp4" }, + { &efi_tcp4_service_binding_protocol_guid, + "Tcp4Sb" }, + { &efi_tcp6_protocol_guid, + "Tcp6" }, + { &efi_tcp6_service_binding_protocol_guid, + "Tcp6Sb" }, + { &efi_tree_protocol_guid, + "TrEE" }, + { &efi_udp4_protocol_guid, + "Udp4" }, + { &efi_udp4_service_binding_protocol_guid, + "Udp4Sb" }, + { &efi_udp6_protocol_guid, + "Udp6" }, + { &efi_udp6_service_binding_protocol_guid, + "Udp6Sb" }, + { &efi_uefi_pxe_bc_dxe_guid, + "UefiPxeBcDxe" }, + { &efi_uga_draw_protocol_guid, + "UgaDraw" }, + { &efi_unicode_collation_protocol_guid, + "UnicodeCollation" }, + { &efi_usb_hc_protocol_guid, + "UsbHc" }, + { &efi_usb2_hc_protocol_guid, + "Usb2Hc" }, + { &efi_usb_io_protocol_guid, + "UsbIo" }, + { &efi_vlan_config_protocol_guid, + "VlanConfig" }, + { &efi_vlan_config_dxe_guid, + "VlanConfigDxe" }, +}; + +/** + * Convert GUID to a printable string + * + * @v guid GUID + * @ret string Printable string + */ +const __attribute__ (( pure )) char * efi_guid_ntoa ( CONST EFI_GUID *guid ) { + union { + union uuid uuid; + EFI_GUID guid; + } u; + unsigned int i; + + /* Sanity check */ + if ( ! guid ) + return NULL; + + /* Check for a match against well-known GUIDs */ + for ( i = 0 ; i < ( sizeof ( efi_well_known_guids ) / + sizeof ( efi_well_known_guids[0] ) ) ; i++ ) { + if ( memcmp ( guid, efi_well_known_guids[i].guid, + sizeof ( *guid ) ) == 0 ) { + return efi_well_known_guids[i].name; + } + } + + /* Convert GUID to standard endianness */ + memcpy ( &u.guid, guid, sizeof ( u.guid ) ); + uuid_mangle ( &u.uuid ); + return uuid_ntoa ( &u.uuid ); +} -- cgit v1.2.3-55-g7522 From 7cda3dbf94936f265ab017841d0236bb62f51efa Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 20 Mar 2025 14:18:02 +0000 Subject: [efi] Attempt to retrieve driver name from image handle for debug messages Not all drivers will install the driver binding protocol on the image handle. Accommodate these drivers by attempting to retrieve the driver name via the component name protocol(s) located on the driver binding's ImageHandle, as well as on the driver handle itself. Signed-off-by: Michael Brown --- src/interface/efi/efi_debug.c | 91 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 030c6a93e..1b778805e 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -38,6 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include +#include #include #include @@ -320,6 +321,90 @@ static const char * efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *wtf ) { return name; } +/** + * Get driver binding name + * + * @v binding Driver binding protocol + * @ret name Driver name, or NULL + */ +static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + union { + EFI_COMPONENT_NAME_PROTOCOL *name; + void *interface; + } u; + EFI_HANDLE image; + const char *name; + EFI_STATUS efirc; + + /* Sanity check */ + if ( ! binding ) { + DBG ( "[NULL DriverBinding]" ); + return NULL; + } + + /* Try to open component name protocol on image handle */ + image = binding->ImageHandle; + if ( ( efirc = bs->OpenProtocol ( image, + &efi_component_name_protocol_guid, + &u.interface, efi_image_handle, image, + EFI_OPEN_PROTOCOL_GET_PROTOCOL)) !=0){ + DBG ( "[DriverBinding no ComponentName]" ); + return NULL; + } + + /* Try to get name from component name protocol */ + name = efi_driver_name ( u.name ); + + /* Close component name protocol */ + bs->CloseProtocol ( image, &efi_component_name_protocol_guid, + efi_image_handle, image ); + + return name; +} + +/** + * Get driver binding name + * + * @v binding Driver binding protocol + * @ret name Driver name, or NULL + */ +static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){ + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + EFI_HANDLE image; + union { + EFI_COMPONENT_NAME2_PROTOCOL *name2; + void *interface; + } u; + const char *name; + EFI_STATUS efirc; + + /* Sanity check */ + if ( ! binding ) { + DBG ( "[NULL DriverBinding]" ); + return NULL; + } + + /* Try to open component name protocol on image handle */ + image = binding->ImageHandle; + if ( ( efirc = bs->OpenProtocol ( image, + &efi_component_name2_protocol_guid, + &u.interface, efi_image_handle, image, + EFI_OPEN_PROTOCOL_GET_PROTOCOL)) !=0){ + DBG ( "[DriverBinding no ComponentName2]" ); + return NULL; + } + + /* Try to get name from component name protocol */ + name = efi_driver_name2 ( u.name2 ); + + /* Close component name protocol */ + bs->CloseProtocol ( image, &efi_component_name2_protocol_guid, + efi_image_handle, image ); + + return name; +} + /** * Get PE/COFF debug filename * @@ -547,6 +632,12 @@ static struct efi_handle_name_type efi_handle_name_types[] = { /* Driver name (via obsolete original ComponentName protocol) */ EFI_HANDLE_NAME_TYPE ( &efi_component_name_protocol_guid, efi_driver_name ), + /* Driver name (for driver binding handles) */ + EFI_HANDLE_NAME_TYPE ( &efi_driver_binding_protocol_guid, + efi_binding_name2 ), + /* Driver name (via obsolete original ComponentName protocol) */ + EFI_HANDLE_NAME_TYPE ( &efi_driver_binding_protocol_guid, + efi_binding_name ), /* PE/COFF debug filename (for image handles) */ EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid, efi_pecoff_debug_name ), -- cgit v1.2.3-55-g7522 From 5d64469a9e6aa6126643cfb33355441496c84c3a Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 20 Mar 2025 14:20:57 +0000 Subject: [efi] Prefer driver name to device path for debug messages The driver name is usually more informative for debug messages than the device path from which a driver was loaded. Try using the various mechanisms for obtaining a driver name before trying the device path. Signed-off-by: Michael Brown --- src/interface/efi/efi_debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 1b778805e..9e28067de 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -623,9 +623,6 @@ struct efi_handle_name_type { /** EFI handle name types */ static struct efi_handle_name_type efi_handle_name_types[] = { - /* Device path */ - EFI_HANDLE_NAME_TYPE ( &efi_device_path_protocol_guid, - efi_devpath_text ), /* Driver name (for driver image handles) */ EFI_HANDLE_NAME_TYPE ( &efi_component_name2_protocol_guid, efi_driver_name2 ), @@ -650,6 +647,9 @@ static struct efi_handle_name_type efi_handle_name_types[] = { /* Handle's loaded image file path (for image handles) */ EFI_HANDLE_NAME_TYPE ( &efi_loaded_image_protocol_guid, efi_loaded_image_filepath_name ), + /* Device path */ + EFI_HANDLE_NAME_TYPE ( &efi_device_path_protocol_guid, + efi_devpath_text ), /* Our standard input file handle */ EFI_HANDLE_NAME_TYPE ( &efi_simple_text_input_protocol_guid, efi_conin_name ), -- cgit v1.2.3-55-g7522 From 8249bbc098319621f6a0db56f7be4bb2873811eb Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 21 Mar 2025 16:58:03 +0000 Subject: [efi] Use driver name only from driver binding handles in debug messages Some non-driver handles may have an installed component name protocol. In particular, iPXE itself installs these protocols on its SNP device handles, to simplify the process of delegating GetControllerName() from our single-instance driver binding protocol to whatever child controllers the relevant EFI driver may have installed. For non-driver handles, the device path is more useful as debugging information than the driver name. Limit the use of the component name protocols to handles with a driver binding protocol installed, so that we will end up using the device path for non-driver handles such as the SNP device. Continue to prefer the driver name to the device path for handles with a driver binding protocol installed, since these will generally map to things we are likely to conceptualise as drivers rather than as devices. Note that we deliberately do not use GetControllerName() to attempt to get a human-readable name for a controller handle. In the normal course of events, iPXE is likely to disconnect at least some existing drivers from their controller handles. This would cause the name obtained via GetControllerName() to change. By using the device path instead, we ensure that the debug message name remains the same even when the driver controlling the handle is changed. Signed-off-by: Michael Brown --- src/interface/efi/efi_debug.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 9e28067de..6f71949fb 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -623,12 +623,6 @@ struct efi_handle_name_type { /** EFI handle name types */ static struct efi_handle_name_type efi_handle_name_types[] = { - /* Driver name (for driver image handles) */ - EFI_HANDLE_NAME_TYPE ( &efi_component_name2_protocol_guid, - efi_driver_name2 ), - /* Driver name (via obsolete original ComponentName protocol) */ - EFI_HANDLE_NAME_TYPE ( &efi_component_name_protocol_guid, - efi_driver_name ), /* Driver name (for driver binding handles) */ EFI_HANDLE_NAME_TYPE ( &efi_driver_binding_protocol_guid, efi_binding_name2 ), -- cgit v1.2.3-55-g7522 From bac318743905e55ce424104cafbc8418e0672a80 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 23 Mar 2025 19:11:13 +0000 Subject: [efi] Use efi_open() for all ephemeral protocol opens Signed-off-by: Michael Brown --- src/drivers/net/efi/snpnet.c | 8 +--- src/drivers/net/efi/snponly.c | 33 ++++----------- src/drivers/usb/usbio.c | 68 +++++++----------------------- src/image/efi_image.c | 7 +--- src/interface/efi/efi_autoboot.c | 14 +------ src/interface/efi/efi_block.c | 67 +++++++----------------------- src/interface/efi/efi_cachedhcp.c | 33 ++++----------- src/interface/efi/efi_debug.c | 50 ++++++---------------- src/interface/efi/efi_driver.c | 27 ++++-------- src/interface/efi/efi_init.c | 9 ++-- src/interface/efi/efi_local.c | 22 +++------- src/interface/efi/efi_pci.c | 87 +++++++++------------------------------ src/interface/efi/efi_service.c | 36 ++++------------ src/interface/efi/efi_shim.c | 21 +++------- src/interface/efi/efi_utils.c | 13 +----- src/interface/efi/efi_veto.c | 64 ++++++---------------------- src/interface/efi/efi_wrap.c | 13 +----- 17 files changed, 130 insertions(+), 442 deletions(-) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/drivers/net/efi/snpnet.c b/src/drivers/net/efi/snpnet.c index fb071d8d3..93ed8cd95 100644 --- a/src/drivers/net/efi/snpnet.c +++ b/src/drivers/net/efi/snpnet.c @@ -493,9 +493,7 @@ static struct net_device_operations snpnet_operations = { * @ret rc Return status code */ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE parent; - EFI_STATUS efirc; int rc; /* Check that this is not a device we are providing ourselves */ @@ -506,13 +504,11 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) { } /* Test for presence of protocol */ - if ( ( efirc = bs->OpenProtocol ( device, protocol, - NULL, efi_image_handle, device, - EFI_OPEN_PROTOCOL_TEST_PROTOCOL))!=0){ + if ( ( rc = efi_open ( device, protocol, NULL ) ) != 0 ) { DBGCP ( device, "HANDLE %s is not a %s device\n", efi_handle_name ( device ), efi_guid_ntoa ( protocol ) ); - return -EEFI ( efirc ); + return rc; } /* Check that there are no instances of this protocol further diff --git a/src/drivers/net/efi/snponly.c b/src/drivers/net/efi/snponly.c index 2ae63fc06..80ddfe00d 100644 --- a/src/drivers/net/efi/snponly.c +++ b/src/drivers/net/efi/snponly.c @@ -86,13 +86,11 @@ static struct chained_protocol chained_mnp = { * @v chained Chainloaded protocol */ static void chained_locate ( struct chained_protocol *chained ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE device = efi_loaded_image->DeviceHandle; EFI_HANDLE handle; void *match = NULL; void *interface; unsigned int skip; - EFI_STATUS efirc; int rc; /* Identify target device handle */ @@ -111,11 +109,8 @@ static void chained_locate ( struct chained_protocol *chained ) { } /* Get protocol instance */ - if ( ( efirc = bs->OpenProtocol ( - handle, chained->protocol, &interface, - efi_image_handle, handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL )) != 0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, chained->protocol, + &interface ) ) != 0 ) { DBGC ( device, "CHAINED %s could not open %s on ", efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol ) ); @@ -123,8 +118,6 @@ static void chained_locate ( struct chained_protocol *chained ) { efi_handle_name ( handle ), strerror ( rc ) ); break; } - bs->CloseProtocol ( handle, chained->protocol, - efi_image_handle, handle ); /* Stop if we reach a non-matching protocol instance */ if ( match && ( match != interface ) ) { @@ -154,20 +147,16 @@ static void chained_locate ( struct chained_protocol *chained ) { */ static int chained_supported ( EFI_HANDLE device, struct chained_protocol *chained ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; void *interface; - EFI_STATUS efirc; int rc; /* Get protocol */ - if ( ( efirc = bs->OpenProtocol ( device, chained->protocol, &interface, - efi_image_handle, device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( device, chained->protocol, + &interface ) ) != 0 ) { DBGCP ( device, "CHAINED %s is not a %s device\n", efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol ) ); - goto err_open_protocol; + return rc; } /* Ignore non-matching handles */ @@ -175,21 +164,13 @@ static int chained_supported ( EFI_HANDLE device, DBGC2 ( device, "CHAINED %s is not the chainloaded %s\n", efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol ) ); - rc = -ENOTTY; - goto err_no_match; + return -ENOTTY; } - /* Success */ - rc = 0; DBGC ( device, "CHAINED %s is the chainloaded %s\n", efi_handle_name ( device ), efi_guid_ntoa ( chained->protocol ) ); - - err_no_match: - bs->CloseProtocol ( device, chained->protocol, efi_image_handle, - device ); - err_open_protocol: - return rc; + return 0; } /** diff --git a/src/drivers/usb/usbio.c b/src/drivers/usb/usbio.c index c5f245fc3..db3beff21 100644 --- a/src/drivers/usb/usbio.c +++ b/src/drivers/usb/usbio.c @@ -1291,7 +1291,6 @@ static struct usb_host_operations usbio_operations = { * @ret rc Return status code */ static int usbio_supported ( EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_USB_DEVICE_DESCRIPTOR device; EFI_USB_INTERFACE_DESCRIPTOR interface; struct usb_function_descriptor desc; @@ -1305,14 +1304,11 @@ static int usbio_supported ( EFI_HANDLE handle ) { int rc; /* Get protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, &efi_usb_io_protocol_guid, - &usb.interface, efi_image_handle, - handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_usb_io_protocol_guid, + &usb.interface ) ) != 0 ) { DBGCP ( handle, "USB %s is not a USB device\n", efi_handle_name ( handle ) ); - goto err_open_protocol; + return rc; } /* Get device descriptor */ @@ -1321,7 +1317,7 @@ static int usbio_supported ( EFI_HANDLE handle ) { rc = -EEFI ( efirc ); DBGC ( handle, "USB %s could not get device descriptor: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_get_device_descriptor; + return rc; } memset ( &desc, 0, sizeof ( desc ) ); desc.vendor = device.IdVendor; @@ -1333,7 +1329,7 @@ static int usbio_supported ( EFI_HANDLE handle ) { rc = -EEFI ( efirc ); DBGC ( handle, "USB %s could not get interface descriptor: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_get_interface_descriptor; + return rc; } desc.class.class.class = interface.InterfaceClass; desc.class.class.subclass = interface.InterfaceSubClass; @@ -1341,21 +1337,10 @@ static int usbio_supported ( EFI_HANDLE handle ) { /* Look for a driver for this interface */ driver = usb_find_driver ( &desc, &id ); - if ( ! driver ) { - rc = -ENOTSUP; - goto err_unsupported; - } - - /* Success */ - rc = 0; + if ( ! driver ) + return -ENOTSUP; - err_unsupported: - err_get_interface_descriptor: - err_get_device_descriptor: - bs->CloseProtocol ( handle, &efi_usb_io_protocol_guid, - efi_image_handle, handle ); - err_open_protocol: - return rc; + return 0; } /** @@ -1471,7 +1456,6 @@ static int usbio_config ( struct usbio_device *usbio ) { * @ret rc Return status code */ static int usbio_path ( struct usbio_device *usbio ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE handle = usbio->handle; EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *end; @@ -1481,19 +1465,14 @@ static int usbio_path ( struct usbio_device *usbio ) { EFI_DEVICE_PATH_PROTOCOL *path; } u; size_t len; - EFI_STATUS efirc; int rc; /* Open device path protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, - &efi_device_path_protocol_guid, - &u.interface, efi_image_handle, - handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( usbio, "USBIO %s cannot open device path protocol: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_open_protocol; + return rc; } path = u.interface; @@ -1502,8 +1481,7 @@ static int usbio_path ( struct usbio_device *usbio ) { if ( len < sizeof ( *usbpath ) ) { DBGC ( usbio, "USBIO %s underlength device path\n", efi_handle_name ( handle ) ); - rc = -EINVAL; - goto err_underlength; + return -EINVAL; } usbpath = ( ( ( void * ) path ) + len - sizeof ( *usbpath ) ); if ( ! ( ( usbpath->Header.Type == MESSAGING_DEVICE_PATH ) && @@ -1511,34 +1489,18 @@ static int usbio_path ( struct usbio_device *usbio ) { DBGC ( usbio, "USBIO %s not a USB device path: ", efi_handle_name ( handle ) ); DBGC ( usbio, "%s\n", efi_devpath_text ( path ) ); - rc = -EINVAL; - goto err_non_usb; + return -EINVAL; } /* Allocate copy of device path */ usbio->path = malloc ( len + sizeof ( *end ) ); - if ( ! usbio->path ) { - rc = -ENOMEM; - goto err_alloc; - } + if ( ! usbio->path ) + return -ENOMEM; memcpy ( usbio->path, path, ( len + sizeof ( *end ) ) ); usbio->usbpath = ( ( ( void * ) usbio->path ) + len - sizeof ( *usbpath ) ); - /* Close protocol */ - bs->CloseProtocol ( handle, &efi_device_path_protocol_guid, - efi_image_handle, handle ); - return 0; - - free ( usbio->path ); - err_alloc: - err_non_usb: - err_underlength: - bs->CloseProtocol ( handle, &efi_device_path_protocol_guid, - efi_image_handle, handle ); - err_open_protocol: - return rc; } /** diff --git a/src/image/efi_image.c b/src/image/efi_image.c index d2171e7de..ae9255ce5 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -234,12 +234,9 @@ static int efi_image_exec ( struct image *image ) { } /* Get the loaded image protocol for the newly loaded image */ - efirc = bs->OpenProtocol ( handle, &efi_loaded_image_protocol_guid, - &loaded.interface, efi_image_handle, - NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); - if ( efirc ) { + if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, + &loaded.interface ) ) != 0 ) { /* Should never happen */ - rc = -EEFI ( efirc ); goto err_open_protocol; } diff --git a/src/interface/efi/efi_autoboot.c b/src/interface/efi/efi_autoboot.c index a103c2f19..528b84f1e 100644 --- a/src/interface/efi/efi_autoboot.c +++ b/src/interface/efi/efi_autoboot.c @@ -48,23 +48,17 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ int efi_set_autoboot_ll_addr ( EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *path ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_SIMPLE_NETWORK_PROTOCOL *snp; void *interface; } snp; EFI_SIMPLE_NETWORK_MODE *mode; - EFI_STATUS efirc; unsigned int vlan; int rc; /* Look for an SNP instance on the image's device handle */ - if ( ( efirc = bs->OpenProtocol ( device, - &efi_simple_network_protocol_guid, - &snp.interface, efi_image_handle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( device, &efi_simple_network_protocol_guid, + &snp.interface ) ) != 0 ) { DBGC ( device, "EFI %s has no SNP instance: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; @@ -90,9 +84,5 @@ int efi_set_autoboot_ll_addr ( EFI_HANDLE device, efi_handle_name ( device ), vlan ); } - /* Close protocol */ - bs->CloseProtocol ( device, &efi_simple_network_protocol_guid, - efi_image_handle, NULL ); - return 0; } diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c index 6296953c5..34b73c265 100644 --- a/src/interface/efi/efi_block.c +++ b/src/interface/efi/efi_block.c @@ -518,8 +518,6 @@ static int efi_block_describe ( void ) { */ static int efi_block_root ( unsigned int drive, EFI_HANDLE handle, EFI_FILE_PROTOCOL **root ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_GUID *protocol = &efi_simple_file_system_protocol_guid; union { EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; void *interface; @@ -528,13 +526,11 @@ static int efi_block_root ( unsigned int drive, EFI_HANDLE handle, int rc; /* Open filesystem protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface, - efi_image_handle, handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_simple_file_system_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open %s filesystem: %s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); - goto err_open; + return rc; } /* Open root volume */ @@ -542,16 +538,10 @@ static int efi_block_root ( unsigned int drive, EFI_HANDLE handle, rc = -EEFI ( efirc ); DBGC ( drive, "EFIBLK %#02x could not open %s root: %s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); - goto err_volume; + return rc; } - /* Success */ - rc = 0; - - err_volume: - bs->CloseProtocol ( handle, protocol, efi_image_handle, handle ); - err_open: - return rc; + return 0; } /** @@ -674,22 +664,17 @@ static int efi_block_match ( unsigned int drive, EFI_HANDLE handle, EFI_DEVICE_PATH_PROTOCOL *path, struct san_boot_config *config, EFI_DEVICE_PATH_PROTOCOL **fspath ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_GUID *protocol = &efi_device_path_protocol_guid; union { EFI_DEVICE_PATH_PROTOCOL *path; void *interface; } u; EFI_FILE *root; union uuid guid; - EFI_STATUS efirc; int rc; /* Identify device path */ - if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface, - efi_image_handle, handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open %s device path: " "%s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); @@ -758,7 +743,6 @@ static int efi_block_match ( unsigned int drive, EFI_HANDLE handle, err_wrong_guid: err_no_guid: err_not_child: - bs->CloseProtocol ( handle, protocol, efi_image_handle, handle ); err_open: return rc; } @@ -776,7 +760,6 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, struct san_boot_config *config, EFI_DEVICE_PATH_PROTOCOL **fspath ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_GUID *protocol = &efi_device_path_protocol_guid; union { EFI_DEVICE_PATH_PROTOCOL *path; void *interface; @@ -791,10 +774,8 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, efi_block_connect ( drive, handle ); /* Identify device path */ - if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface, - efi_image_handle, handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open device path: %s\n", drive, strerror ( rc ) ); goto err_open; @@ -824,7 +805,6 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, bs->FreePool ( handles ); err_locate: - bs->CloseProtocol ( handle, protocol, efi_image_handle, handle ); err_open: return rc; } @@ -921,52 +901,37 @@ static int efi_block_exec ( unsigned int drive, * equivalent functionality to BIOS drive numbers. */ static int efi_block_local ( EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - EFI_GUID *protocol = &efi_block_io_protocol_guid; struct san_device *sandev; struct efi_block_data *block; union { EFI_BLOCK_IO_PROTOCOL *blockio; void *interface; } u; - EFI_STATUS efirc; int rc; /* Check if handle belongs to a SAN device */ for_each_sandev ( sandev ) { block = sandev->priv; - if ( handle == block->handle ) { - rc = -ENOTTY; - goto err_sandev; - } + if ( handle == block->handle ) + return -ENOTTY; } /* Open block I/O protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, protocol, &u.interface, - efi_image_handle, handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_block_io_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( handle, "EFIBLK %s could not open block I/O: %s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_open; + return rc; } /* Do not assign drive numbers for partitions */ if ( u.blockio->Media->LogicalPartition ) { - rc = -ENOTTY; DBGC2 ( handle, "EFLBLK %s is a partition\n", efi_handle_name ( handle ) ); - goto err_partition; + return -ENOTTY; } - /* Success */ - rc = 0; - - err_partition: - bs->CloseProtocol ( handle, protocol, efi_image_handle, handle ); - err_open: - err_sandev: - return rc; + return 0; } /** diff --git a/src/interface/efi/efi_cachedhcp.c b/src/interface/efi/efi_cachedhcp.c index b9e49cf48..68671d7c6 100644 --- a/src/interface/efi/efi_cachedhcp.c +++ b/src/interface/efi/efi_cachedhcp.c @@ -46,38 +46,31 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ int efi_cachedhcp_record ( EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *path ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; unsigned int vlan; union { EFI_PXE_BASE_CODE_PROTOCOL *pxe; void *interface; } pxe; EFI_PXE_BASE_CODE_MODE *mode; - EFI_STATUS efirc; int rc; /* Get VLAN tag, if any */ vlan = efi_path_vlan ( path ); /* Look for a PXE base code instance on the image's device handle */ - if ( ( efirc = bs->OpenProtocol ( device, - &efi_pxe_base_code_protocol_guid, - &pxe.interface, efi_image_handle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( device, &efi_pxe_base_code_protocol_guid, + &pxe.interface ) ) != 0 ) { DBGC ( device, "EFI %s has no PXE base code instance: %s\n", efi_handle_name ( device ), strerror ( rc ) ); - goto err_open; + return rc; } /* Do not attempt to cache IPv6 packets */ mode = pxe.pxe->Mode; if ( mode->UsingIpv6 ) { - rc = -ENOTSUP; DBGC ( device, "EFI %s has IPv6 PXE base code\n", efi_handle_name ( device ) ); - goto err_ipv6; + return -ENOTSUP; } /* Record DHCPACK, if present */ @@ -87,7 +80,7 @@ int efi_cachedhcp_record ( EFI_HANDLE device, sizeof ( mode->DhcpAck ) ) ) != 0 ) ) { DBGC ( device, "EFI %s could not record DHCPACK: %s\n", efi_handle_name ( device ), strerror ( rc ) ); - goto err_dhcpack; + return rc; } /* Record ProxyDHCPOFFER, if present */ @@ -97,7 +90,7 @@ int efi_cachedhcp_record ( EFI_HANDLE device, sizeof ( mode->ProxyOffer ) ) ) != 0)){ DBGC ( device, "EFI %s could not record ProxyDHCPOFFER: %s\n", efi_handle_name ( device ), strerror ( rc ) ); - goto err_proxydhcp; + return rc; } /* Record PxeBSACK, if present */ @@ -107,18 +100,8 @@ int efi_cachedhcp_record ( EFI_HANDLE device, sizeof ( mode->PxeReply ) ) ) != 0)){ DBGC ( device, "EFI %s could not record PXEBSACK: %s\n", efi_handle_name ( device ), strerror ( rc ) ); - goto err_pxebs; + return rc; } - /* Success */ - rc = 0; - - err_pxebs: - err_proxydhcp: - err_dhcpack: - err_ipv6: - bs->CloseProtocol ( device, &efi_pxe_base_code_protocol_guid, - efi_image_handle, NULL ); - err_open: - return rc; + return 0; } diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 6f71949fb..ef650d989 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -328,14 +328,12 @@ static const char * efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *wtf ) { * @ret name Driver name, or NULL */ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_COMPONENT_NAME_PROTOCOL *name; void *interface; } u; EFI_HANDLE image; - const char *name; - EFI_STATUS efirc; + int rc; /* Sanity check */ if ( ! binding ) { @@ -345,22 +343,14 @@ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { /* Try to open component name protocol on image handle */ image = binding->ImageHandle; - if ( ( efirc = bs->OpenProtocol ( image, - &efi_component_name_protocol_guid, - &u.interface, efi_image_handle, image, - EFI_OPEN_PROTOCOL_GET_PROTOCOL)) !=0){ + if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, + &u.interface ) ) != 0 ) { DBG ( "[DriverBinding no ComponentName]" ); return NULL; } /* Try to get name from component name protocol */ - name = efi_driver_name ( u.name ); - - /* Close component name protocol */ - bs->CloseProtocol ( image, &efi_component_name_protocol_guid, - efi_image_handle, image ); - - return name; + return efi_driver_name ( u.name ); } /** @@ -370,14 +360,12 @@ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { * @ret name Driver name, or NULL */ static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){ - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE image; union { EFI_COMPONENT_NAME2_PROTOCOL *name2; void *interface; } u; - const char *name; - EFI_STATUS efirc; + int rc; /* Sanity check */ if ( ! binding ) { @@ -387,22 +375,14 @@ static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){ /* Try to open component name protocol on image handle */ image = binding->ImageHandle; - if ( ( efirc = bs->OpenProtocol ( image, - &efi_component_name2_protocol_guid, - &u.interface, efi_image_handle, image, - EFI_OPEN_PROTOCOL_GET_PROTOCOL)) !=0){ + if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, + &u.interface ) ) != 0 ) { DBG ( "[DriverBinding no ComponentName2]" ); return NULL; } /* Try to get name from component name protocol */ - name = efi_driver_name2 ( u.name2 ); - - /* Close component name protocol */ - bs->CloseProtocol ( image, &efi_component_name2_protocol_guid, - efi_image_handle, image ); - - return name; + return efi_driver_name2 ( u.name2 ); } /** @@ -669,6 +649,7 @@ const __attribute__ (( pure )) char * efi_handle_name ( EFI_HANDLE handle ) { void *interface; const char *name; EFI_STATUS efirc; + int rc; /* Fail immediately for NULL handles */ if ( ! handle ) @@ -681,10 +662,8 @@ const __attribute__ (( pure )) char * efi_handle_name ( EFI_HANDLE handle ) { DBG2 ( "<%d", i ); /* Try to open the applicable protocol */ - efirc = bs->OpenProtocol ( handle, type->protocol, &interface, - efi_image_handle, handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ); - if ( efirc != 0 ) { + if ( ( rc = efi_open ( handle, type->protocol, + &interface ) ) != 0 ) { DBG2 ( ">" ); continue; } @@ -692,12 +671,7 @@ const __attribute__ (( pure )) char * efi_handle_name ( EFI_HANDLE handle ) { /* Try to get name from this protocol */ DBG2 ( "-" ); name = type->name ( interface ); - DBG2 ( "%c", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) ); - - /* Close protocol */ - bs->CloseProtocol ( handle, type->protocol, - efi_image_handle, handle ); - DBG2 ( ">" ); + DBG2 ( "%c>", ( name ? ( name[0] ? 'Y' : 'E' ) : 'N' ) ); /* Use this name, if possible */ if ( name && name[0] ) diff --git a/src/interface/efi/efi_driver.c b/src/interface/efi/efi_driver.c index fd9be5f51..d143249ca 100644 --- a/src/interface/efi/efi_driver.c +++ b/src/interface/efi/efi_driver.c @@ -68,7 +68,6 @@ static int efi_driver_disconnecting; * @ret efidev EFI device, or NULL on error */ struct efi_device * efidev_alloc ( EFI_HANDLE device ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_device *efidev = NULL; union { EFI_DEVICE_PATH_PROTOCOL *path; @@ -76,26 +75,21 @@ struct efi_device * efidev_alloc ( EFI_HANDLE device ) { } path; EFI_DEVICE_PATH_PROTOCOL *path_end; size_t path_len; - EFI_STATUS efirc; int rc; /* Open device path */ - if ( ( efirc = bs->OpenProtocol ( device, - &efi_device_path_protocol_guid, - &path.interface, efi_image_handle, - device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, + &path.interface ) ) != 0 ) { DBGC ( device, "EFIDRV %s could not open device path: %s\n", efi_handle_name ( device ), strerror ( rc ) ); - goto err_open_path; + return NULL; } path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) ); /* Allocate and initialise structure */ efidev = zalloc ( sizeof ( *efidev ) + path_len ); if ( ! efidev ) - goto err_alloc; + return NULL; efidev->device = device; efidev->dev.desc.bus_type = BUS_TYPE_EFI; efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) ); @@ -103,10 +97,6 @@ struct efi_device * efidev_alloc ( EFI_HANDLE device ) { INIT_LIST_HEAD ( &efidev->dev.children ); list_add ( &efidev->dev.siblings, &efi_devices ); - err_alloc: - bs->CloseProtocol ( device, &efi_device_path_protocol_guid, - efi_image_handle, device ); - err_open_path: return efidev; } @@ -375,21 +365,18 @@ static EFI_STATUS EFIAPI efi_driver_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused, EFI_HANDLE device, EFI_HANDLE child, CHAR8 *language, CHAR16 **controller_name ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_COMPONENT_NAME2_PROTOCOL *name2; void *interface; } name2; - EFI_STATUS efirc; + int rc; /* Delegate to the EFI_COMPONENT_NAME2_PROTOCOL instance * installed on child handle, if present. */ if ( ( child != NULL ) && - ( ( efirc = bs->OpenProtocol ( - child, &efi_component_name2_protocol_guid, - &name2.interface, NULL, NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) == 0 ) ) { + ( ( rc = efi_open ( child, &efi_component_name2_protocol_guid, + &name2.interface ) ) == 0 ) ) { return name2.name2->GetControllerName ( name2.name2, device, child, language, controller_name ); diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c index a45ee66a4..03506ec5c 100644 --- a/src/interface/efi/efi_init.c +++ b/src/interface/efi/efi_init.c @@ -263,13 +263,12 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, efi_cmdline_len = efi_loaded_image->LoadOptionsSize; /* Get loaded image's device handle's device path */ - if ( ( efirc = bs->OpenProtocol ( efi_loaded_image->DeviceHandle, - &efi_device_path_protocol_guid, - &device_path, image_handle, NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( efi_loaded_image->DeviceHandle, + &efi_device_path_protocol_guid, + &device_path ) ) != 0 ) { DBGC ( systab, "EFI could not get loaded image's device path: " "%s", strerror ( rc ) ); + efirc = EFIRC ( rc ); goto err_no_device_path; } diff --git a/src/interface/efi/efi_local.c b/src/interface/efi/efi_local.c index ec6d93a1d..80cfb5a22 100644 --- a/src/interface/efi/efi_local.c +++ b/src/interface/efi/efi_local.c @@ -208,7 +208,6 @@ static int efi_local_check_volume_name ( struct efi_local *local, */ static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device, EFI_FILE_PROTOCOL **root ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { void *interface; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; @@ -217,15 +216,11 @@ static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device, int rc; /* Open file system protocol */ - if ( ( efirc = bs->OpenProtocol ( device, - &efi_simple_file_system_protocol_guid, - &u.interface, efi_image_handle, - device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( device, &efi_simple_file_system_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( local, "LOCAL %p could not open filesystem on %s: %s\n", local, efi_handle_name ( device ), strerror ( rc ) ); - goto err_filesystem; + return rc; } /* Open root directory */ @@ -233,17 +228,10 @@ static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device, rc = -EEFI ( efirc ); DBGC ( local, "LOCAL %p could not open volume on %s: %s\n", local, efi_handle_name ( device ), strerror ( rc ) ); - goto err_volume; + return rc; } - /* Success */ - rc = 0; - - err_volume: - bs->CloseProtocol ( device, &efi_simple_file_system_protocol_guid, - efi_image_handle, device ); - err_filesystem: - return rc; + return 0; } /** diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c index b53a88d66..003fa2f4a 100644 --- a/src/interface/efi/efi_pci.c +++ b/src/interface/efi/efi_pci.c @@ -72,7 +72,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { void *interface; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; @@ -94,15 +93,12 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, range->count = 0; /* Open root bridge I/O protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, - &efi_pci_root_bridge_io_protocol_guid, - &root.interface, efi_image_handle, handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_pci_root_bridge_io_protocol_guid, + &root.interface ) ) != 0 ) { DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n", PCI_ARGS ( pci ), efi_handle_name ( handle ), strerror ( rc ) ); - goto err_open; + return rc; } /* Get ACPI resource descriptors */ @@ -112,7 +108,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for " "%s: %s\n", PCI_ARGS ( pci ), efi_handle_name ( handle ), strerror ( rc ) ); - goto err_config; + return rc; } /* Parse resource descriptors */ @@ -159,14 +155,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 ); } - /* Success */ - rc = 0; - - err_config: - bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid, - efi_image_handle, handle ); - err_open: - return rc; + return 0; } /** @@ -260,7 +249,7 @@ static void efipci_discover ( uint32_t busdevfn, struct pci_range *range ) { } /** - * Open EFI PCI root bridge I/O protocol + * Open EFI PCI root bridge I/O protocol for ephemeral use * * @v pci PCI device * @ret handle EFI PCI root bridge handle @@ -269,25 +258,20 @@ static void efipci_discover ( uint32_t busdevfn, struct pci_range *range ) { */ static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct pci_range tmp; union { void *interface; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; } u; - EFI_STATUS efirc; int rc; /* Find matching root bridge I/O protocol handle */ if ( ( rc = efipci_discover_any ( pci, &tmp, handle ) ) != 0 ) return rc; - /* (Re)open PCI root bridge I/O protocol */ - if ( ( efirc = bs->OpenProtocol ( *handle, - &efi_pci_root_bridge_io_protocol_guid, - &u.interface, efi_image_handle, *handle, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); + /* Open PCI root bridge I/O protocol */ + if ( ( rc = efi_open ( *handle, &efi_pci_root_bridge_io_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n", PCI_ARGS ( pci ), efi_handle_name ( *handle ), strerror ( rc ) ); @@ -300,19 +284,6 @@ static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle, return 0; } -/** - * Close EFI PCI root bridge I/O protocol - * - * @v handle EFI PCI root bridge handle - */ -static void efipci_root_close ( EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - - /* Close protocol */ - bs->CloseProtocol ( handle, &efi_pci_root_bridge_io_protocol_guid, - efi_image_handle, handle ); -} - /** * Calculate EFI PCI configuration space address * @@ -346,7 +317,7 @@ int efipci_read ( struct pci_device *pci, unsigned long location, /* Open root bridge */ if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 ) - goto err_root; + return rc; /* Read from configuration space */ if ( ( efirc = root->Pci.Read ( root, EFIPCI_WIDTH ( location ), @@ -356,13 +327,10 @@ int efipci_read ( struct pci_device *pci, unsigned long location, DBGC ( pci, "EFIPCI " PCI_FMT " config read from offset %02lx " "failed: %s\n", PCI_ARGS ( pci ), EFIPCI_OFFSET ( location ), strerror ( rc ) ); - goto err_read; + return rc; } - err_read: - efipci_root_close ( handle ); - err_root: - return rc; + return 0; } /** @@ -382,7 +350,7 @@ int efipci_write ( struct pci_device *pci, unsigned long location, /* Open root bridge */ if ( ( rc = efipci_root_open ( pci, &handle, &root ) ) != 0 ) - goto err_root; + return rc; /* Read from configuration space */ if ( ( efirc = root->Pci.Write ( root, EFIPCI_WIDTH ( location ), @@ -392,13 +360,10 @@ int efipci_write ( struct pci_device *pci, unsigned long location, DBGC ( pci, "EFIPCI " PCI_FMT " config write to offset %02lx " "failed: %s\n", PCI_ARGS ( pci ), EFIPCI_OFFSET ( location ), strerror ( rc ) ); - goto err_write; + return rc; } - err_write: - efipci_root_close ( handle ); - err_root: - return rc; + return 0; } /** @@ -469,7 +434,6 @@ void * efipci_ioremap ( struct pci_device *pci, unsigned long bus_addr, } err_config: - efipci_root_close ( handle ); err_root: return ioremap ( bus_addr, len ); } @@ -778,7 +742,6 @@ static struct dma_operations efipci_dma_operations = { * @ret rc Return status code */ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_PCI_IO_PROTOCOL *pci_io; void *interface; @@ -789,14 +752,11 @@ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { int rc; /* See if device is a PCI device */ - if ( ( efirc = bs->OpenProtocol ( device, &efi_pci_io_protocol_guid, - &pci_io.interface, - efi_image_handle, device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI_PCI ( efirc ); + if ( ( rc = efi_open ( device, &efi_pci_io_protocol_guid, + &pci_io.interface ) ) != 0 ) { DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n", efi_handle_name ( device ), strerror ( rc ) ); - goto err_open_protocol; + return rc; } efipci->io = pci_io.pci_io; @@ -807,7 +767,7 @@ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { rc = -EEFI ( efirc ); DBGC ( device, "EFIPCI %s could not get PCI location: %s\n", efi_handle_name ( device ), strerror ( rc ) ); - goto err_get_location; + return rc; } busdevfn = PCI_BUSDEVFN ( pci_segment, pci_bus, pci_dev, pci_fn ); pci_init ( &efipci->pci, busdevfn ); @@ -836,17 +796,10 @@ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { DBGC ( device, "EFIPCI " PCI_FMT " cannot read PCI " "configuration: %s\n", PCI_ARGS ( &efipci->pci ), strerror ( rc ) ); - goto err_pci_read_config; + return rc; } return 0; - - err_pci_read_config: - err_get_location: - bs->CloseProtocol ( device, &efi_pci_io_protocol_guid, - efi_image_handle, device ); - err_open_protocol: - return rc; } /****************************************************************************** diff --git a/src/interface/efi/efi_service.c b/src/interface/efi/efi_service.c index d4129c0d9..de7353652 100644 --- a/src/interface/efi/efi_service.c +++ b/src/interface/efi/efi_service.c @@ -45,7 +45,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE *handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_SERVICE_BINDING_PROTOCOL *sb; void *interface; @@ -54,14 +53,11 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, int rc; /* Open service binding protocol */ - if ( ( efirc = bs->OpenProtocol ( service, binding, &u.interface, - efi_image_handle, service, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) { DBGC ( service, "EFISVC %s cannot open %s binding: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), strerror ( rc ) ); - goto err_open; + return rc; } /* Create child handle */ @@ -70,19 +66,13 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, DBGC ( service, "EFISVC %s could not create %s child: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), strerror ( rc ) ); - goto err_create; + return rc; } - /* Success */ - rc = 0; DBGC ( service, "EFISVC %s created %s child ", efi_handle_name ( service ), efi_guid_ntoa ( binding ) ); DBGC ( service, "%s\n", efi_handle_name ( *handle ) ); - - err_create: - bs->CloseProtocol ( service, binding, efi_image_handle, service ); - err_open: - return rc; + return 0; } /** @@ -95,7 +85,6 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, */ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_SERVICE_BINDING_PROTOCOL *sb; void *interface; @@ -108,14 +97,11 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, DBGC ( service, "%s\n", efi_handle_name ( handle ) ); /* Open service binding protocol */ - if ( ( efirc = bs->OpenProtocol ( service, binding, &u.interface, - efi_image_handle, service, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) { DBGC ( service, "EFISVC %s cannot open %s binding: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), strerror ( rc ) ); - goto err_open; + return rc; } /* Destroy child handle */ @@ -125,14 +111,8 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, efi_handle_name ( service ), efi_guid_ntoa ( binding ) ); DBGC ( service, "%s: %s\n", efi_handle_name ( handle ), strerror ( rc ) ); - goto err_destroy; + return rc; } - /* Success */ - rc = 0; - - err_destroy: - bs->CloseProtocol ( service, binding, efi_image_handle, service ); - err_open: - return rc; + return 0; } diff --git a/src/interface/efi/efi_shim.c b/src/interface/efi/efi_shim.c index d5419512d..02bd0791f 100644 --- a/src/interface/efi/efi_shim.c +++ b/src/interface/efi/efi_shim.c @@ -272,7 +272,6 @@ static EFIAPI EFI_STATUS efi_shim_get_memory_map ( UINTN *len, * @ret rc Return status code */ static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_PXE_BASE_CODE_PROTOCOL *pxe; void *interface; @@ -281,14 +280,11 @@ static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) { int rc; /* Locate PXE base code */ - if ( ( efirc = bs->OpenProtocol ( handle, - &efi_pxe_base_code_protocol_guid, - &u.interface, efi_image_handle, NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_pxe_base_code_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( &efi_shim, "SHIM could not open PXE base code: %s\n", strerror ( rc ) ); - goto err_no_base; + return rc; } /* Stop PXE base code */ @@ -296,18 +292,11 @@ static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) { rc = -EEFI ( efirc ); DBGC ( &efi_shim, "SHIM could not stop PXE base code: %s\n", strerror ( rc ) ); - goto err_stop; + return rc; } - /* Success */ - rc = 0; DBGC ( &efi_shim, "SHIM stopped PXE base code\n" ); - - err_stop: - bs->CloseProtocol ( handle, &efi_pxe_base_code_protocol_guid, - efi_image_handle, NULL ); - err_no_base: - return rc; + return 0; } /** diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c index 928d8e53a..4f081b67f 100644 --- a/src/interface/efi/efi_utils.c +++ b/src/interface/efi/efi_utils.c @@ -56,12 +56,8 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, int rc; /* Get device path */ - if ( ( efirc = bs->OpenProtocol ( device, - &efi_device_path_protocol_guid, - &u.interface, - efi_image_handle, device, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, + &u.interface ) ) != 0 ) { DBGC ( device, "EFIDEV %s cannot open device path: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open_device_path; @@ -100,14 +96,9 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, efi_path_terminate ( end ); } - /* Success */ - rc = 0; - err_locate_protocol: free ( path ); err_alloc_path: - bs->CloseProtocol ( device, &efi_device_path_protocol_guid, - efi_image_handle, device ); err_open_device_path: return rc; } diff --git a/src/interface/efi/efi_veto.c b/src/interface/efi/efi_veto.c index 17bbf7af4..637eee016 100644 --- a/src/interface/efi/efi_veto.c +++ b/src/interface/efi/efi_veto.c @@ -161,21 +161,14 @@ static int efi_veto_uninstall ( struct efi_veto *veto ) { int rc; /* Open driver binding protocol */ - if ( ( efirc = bs->OpenProtocol ( - driver, &efi_driver_binding_protocol_guid, - &binding.interface, efi_image_handle, driver, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, + &binding.interface ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open driver binding " "protocol: %s\n", efi_handle_name ( driver ), strerror ( rc ) ); return rc; } - /* Close driver binding protocol */ - bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid, - efi_image_handle, driver ); - /* Uninstall driver binding protocol */ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces ( driver, &efi_driver_binding_protocol_guid, @@ -541,7 +534,6 @@ static struct efi_veto_candidate efi_vetoes[] = { */ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, struct efi_veto *veto ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_DRIVER_BINDING_PROTOCOL *binding; void *interface; @@ -568,47 +560,35 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, memset ( veto, 0, sizeof ( *veto ) ); /* Open driver binding protocol */ - if ( ( efirc = bs->OpenProtocol ( - driver, &efi_driver_binding_protocol_guid, - &binding.interface, efi_image_handle, driver, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, + &binding.interface ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open driver binding " "protocol: %s\n", efi_handle_name ( driver ), strerror ( rc ) ); - goto err_binding; + return rc; } image = binding.binding->ImageHandle; /* Open loaded image protocol */ - if ( ( efirc = bs->OpenProtocol ( - image, &efi_loaded_image_protocol_guid, - &loaded.interface, efi_image_handle, image, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( image, &efi_loaded_image_protocol_guid, + &loaded.interface ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open", efi_handle_name ( driver ) ); DBGC ( driver, " %s loaded image protocol: %s\n", efi_handle_name ( image ), strerror ( rc ) ); - goto err_loaded; + return rc; } /* Open component name protocol, if present */ - if ( ( efirc = bs->OpenProtocol ( - image, &efi_component_name2_protocol_guid, - &wtf2.interface, efi_image_handle, image, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { + if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, + &wtf2.interface ) ) != 0 ) { /* Ignore failure; is not required to be present */ - wtf2.interface = NULL; } /* Open obsolete component name protocol, if present */ - if ( ( efirc = bs->OpenProtocol ( - image, &efi_component_name_protocol_guid, - &wtf.interface, efi_image_handle, image, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ) ) != 0 ) { + if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, + &wtf.interface ) ) != 0 ) { /* Ignore failure; is not required to be present */ - wtf.interface = NULL; } /* Get driver name, if available */ @@ -643,25 +623,7 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, } } - /* Success */ - rc = 0; - - /* Close protocols */ - if ( wtf.wtf ) { - bs->CloseProtocol ( image, &efi_component_name_protocol_guid, - efi_image_handle, image ); - } - if ( wtf2.wtf2 ) { - bs->CloseProtocol ( image, &efi_component_name2_protocol_guid, - efi_image_handle, image ); - } - bs->CloseProtocol ( image, &efi_loaded_image_protocol_guid, - efi_image_handle, image ); - err_loaded: - bs->CloseProtocol ( driver, &efi_driver_binding_protocol_guid, - efi_image_handle, driver ); - err_binding: - return rc; + return 0; } /** diff --git a/src/interface/efi/efi_wrap.c b/src/interface/efi/efi_wrap.c index 8891f464b..1cc37f3e3 100644 --- a/src/interface/efi/efi_wrap.c +++ b/src/interface/efi/efi_wrap.c @@ -248,20 +248,15 @@ static int efi_prescroll ( unsigned int lines ) { * @v handle Image handle */ static void efi_dump_image ( EFI_HANDLE handle ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; union { EFI_LOADED_IMAGE_PROTOCOL *image; void *intf; } loaded; - EFI_STATUS efirc; int rc; /* Open loaded image protocol */ - if ( ( efirc = bs->OpenProtocol ( handle, - &efi_loaded_image_protocol_guid, - &loaded.intf, efi_image_handle, NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL ))!=0){ - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, + &loaded.intf ) ) != 0 ) { DBGC ( colour, "WRAP %s could not get loaded image protocol: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); return; @@ -277,10 +272,6 @@ static void efi_dump_image ( EFI_HANDLE handle ) { DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->DeviceHandle )); DBGC ( colour, "WRAP %s file", efi_handle_name ( handle ) ); DBGC ( colour, " %s\n", efi_devpath_text ( loaded.image->FilePath ) ); - - /* Close loaded image protocol */ - bs->CloseProtocol ( handle, &efi_loaded_image_protocol_guid, - efi_image_handle, NULL ); } /** -- cgit v1.2.3-55-g7522 From 37897fbd401b9773f3d8a338564eff67b124e2f7 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 24 Mar 2025 14:22:54 +0000 Subject: [efi] Eliminate uses of HandleProtocol() It is now simpler to use efi_open() than to use HandleProtocol() to obtain an ephemeral protocol instance. Remove all remaining uses of HandleProtocol() to simplify the code. Signed-off-by: Michael Brown --- src/interface/efi/efi_debug.c | 6 +----- src/interface/efi/efi_file.c | 6 ++---- 2 files changed, 3 insertions(+), 9 deletions(-) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index ef650d989..fd4997ccc 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -162,15 +162,11 @@ void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol ) { * @v protocol Protocol GUID */ void dbg_efi_protocol ( EFI_HANDLE handle, EFI_GUID *protocol ) { - EFI_BOOT_SERVICES *bs = efi_systab->BootServices; VOID *interface; - EFI_STATUS efirc; int rc; /* Get protocol instance */ - if ( ( efirc = bs->HandleProtocol ( handle, protocol, - &interface ) ) != 0 ) { - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, protocol, &interface ) ) != 0 ) { printf ( "HANDLE %s could not identify %s: %s\n", efi_handle_name ( handle ), efi_guid_ntoa ( protocol ), strerror ( rc ) ); diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c index f31f2fe3b..d8b9f819c 100644 --- a/src/interface/efi/efi_file.c +++ b/src/interface/efi/efi_file.c @@ -1000,10 +1000,8 @@ static int efi_file_path_claim ( struct efi_file_path *file ) { } /* Locate device path protocol on this handle */ - if ( ( ( efirc = bs->HandleProtocol ( handle, - &efi_device_path_protocol_guid, - &old ) ) != 0 ) ) { - rc = -EEFI ( efirc ); + if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, + &old ) != 0 ) ) { DBGC ( file, "EFIFILE %s could not locate %s: %s\n", efi_file_name ( &file->file ), efi_devpath_text ( file->path ), strerror ( rc ) ); -- cgit v1.2.3-55-g7522 From 32a9408217810498deeeae3d2564ab15468c9c39 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 24 Mar 2025 14:24:47 +0000 Subject: [efi] Allow use of typed pointers for efi_open() et al Provide wrapper macros to allow efi_open() and related functions to accept a pointer to any pointer type as the "interface" argument, in order to allow a substantial amount of type adjustment boilerplate to be removed. Signed-off-by: Michael Brown --- src/drivers/net/efi/mnpnet.c | 7 +--- src/drivers/net/efi/nii.c | 11 +---- src/drivers/net/efi/snpnet.c | 4 +- src/drivers/usb/usbio.c | 34 ++++----------- src/image/efi_image.c | 25 +++++------ src/include/ipxe/efi/efi.h | 87 +++++++++++++++++++++++++++++++++++---- src/interface/efi/efi_autoboot.c | 9 ++-- src/interface/efi/efi_block.c | 40 ++++++------------ src/interface/efi/efi_bofm.c | 3 +- src/interface/efi/efi_cachedhcp.c | 9 ++-- src/interface/efi/efi_console.c | 7 +--- src/interface/efi/efi_debug.c | 18 +++----- src/interface/efi/efi_driver.c | 23 ++++------- src/interface/efi/efi_file.c | 11 ++--- src/interface/efi/efi_init.c | 6 +-- src/interface/efi/efi_local.c | 9 ++-- src/interface/efi/efi_open.c | 15 +++---- src/interface/efi/efi_pci.c | 58 +++++++++----------------- src/interface/efi/efi_service.c | 18 +++----- src/interface/efi/efi_shim.c | 9 ++-- src/interface/efi/efi_utils.c | 13 +++--- src/interface/efi/efi_veto.c | 61 ++++++++++----------------- src/interface/efi/efi_wrap.c | 15 +++---- 23 files changed, 215 insertions(+), 277 deletions(-) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/drivers/net/efi/mnpnet.c b/src/drivers/net/efi/mnpnet.c index ead8691ff..902eb91f3 100644 --- a/src/drivers/net/efi/mnpnet.c +++ b/src/drivers/net/efi/mnpnet.c @@ -370,10 +370,6 @@ int mnpnet_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; EFI_GUID *binding = &efi_managed_network_service_binding_protocol_guid; EFI_SIMPLE_NETWORK_MODE mode; - union { - EFI_MANAGED_NETWORK_PROTOCOL *mnp; - void *interface; - } u; struct net_device *netdev; struct mnp_nic *mnp; EFI_STATUS efirc; @@ -409,12 +405,11 @@ int mnpnet_start ( struct efi_device *efidev ) { /* Open MNP protocol */ if ( ( rc = efi_open_by_driver ( efidev->child, &efi_managed_network_protocol_guid, - &u.interface ) ) != 0 ) { + &mnp->mnp ) ) != 0 ) { DBGC ( mnp, "MNP %s could not open MNP protocol: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open; } - mnp->mnp = u.mnp; /* Get configuration */ efirc = mnp->mnp->GetModeData ( mnp->mnp, NULL, &mode ); diff --git a/src/drivers/net/efi/nii.c b/src/drivers/net/efi/nii.c index 126584eff..81f1838a4 100644 --- a/src/drivers/net/efi/nii.c +++ b/src/drivers/net/efi/nii.c @@ -209,10 +209,6 @@ static int nii_pci_open ( struct nii_nic *nii ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE device = nii->efidev->device; EFI_HANDLE pci_device; - union { - EFI_PCI_IO_PROTOCOL *pci_io; - void *interface; - } pci_io; union { EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *acpi; void *resource; @@ -237,12 +233,11 @@ static int nii_pci_open ( struct nii_nic *nii ) { * therefore use an unsafe open. */ if ( ( rc = efi_open_unsafe ( pci_device, &efi_pci_io_protocol_guid, - &pci_io.interface ) ) != 0 ) { + &nii->pci_io ) ) != 0 ) { DBGC ( nii, "NII %s could not open PCI I/O protocol: %s\n", nii->dev.name, strerror ( rc ) ); goto err_open; } - nii->pci_io = pci_io.pci_io; /* Identify memory and I/O BARs */ nii->mem_bar = PCI_MAX_BAR; @@ -1272,7 +1267,6 @@ int nii_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; struct net_device *netdev; struct nii_nic *nii; - void *interface; int rc; /* Allocate and initialise structure */ @@ -1298,13 +1292,12 @@ int nii_start ( struct efi_device *efidev ) { /* Open NII protocol */ if ( ( rc = efi_open_by_driver ( device, &efi_nii31_protocol_guid, - &interface ) ) != 0 ) { + &nii->nii ) ) != 0 ) { DBGC ( nii, "NII %s cannot open NII protocol: %s\n", nii->dev.name, strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_nii31_protocol_guid ); goto err_open_protocol; } - nii->nii = interface; /* Locate UNDI and entry point */ nii->undi = ( ( void * ) ( intptr_t ) nii->nii->Id ); diff --git a/src/drivers/net/efi/snpnet.c b/src/drivers/net/efi/snpnet.c index 93ed8cd95..c8e2f2f68 100644 --- a/src/drivers/net/efi/snpnet.c +++ b/src/drivers/net/efi/snpnet.c @@ -504,7 +504,7 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) { } /* Test for presence of protocol */ - if ( ( rc = efi_open ( device, protocol, NULL ) ) != 0 ) { + if ( ( rc = efi_test ( device, protocol ) ) != 0 ) { DBGCP ( device, "HANDLE %s is not a %s device\n", efi_handle_name ( device ), efi_guid_ntoa ( protocol ) ); @@ -536,10 +536,10 @@ int snpnet_supported ( EFI_HANDLE device, EFI_GUID *protocol ) { */ int snpnet_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; + EFI_SIMPLE_NETWORK_PROTOCOL *interface; EFI_SIMPLE_NETWORK_MODE *mode; struct net_device *netdev; struct snp_nic *snp; - void *interface; EFI_STATUS efirc; int rc; diff --git a/src/drivers/usb/usbio.c b/src/drivers/usb/usbio.c index db3beff21..73151c536 100644 --- a/src/drivers/usb/usbio.c +++ b/src/drivers/usb/usbio.c @@ -187,10 +187,6 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) { EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *end; USB_DEVICE_PATH *usbpath; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } u; EFI_STATUS efirc; int rc; @@ -231,7 +227,7 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) { /* Open USB I/O protocol on this handle */ if ( ( rc = efi_open_by_driver ( intf->handle, &efi_usb_io_protocol_guid, - &u.interface ) ) != 0 ) { + &intf->io ) ) != 0 ) { DBGC ( usbio, "USBIO %s cannot open ", efi_handle_name ( handle ) ); DBGC ( usbio, "%s: %s\n", @@ -240,7 +236,6 @@ static int usbio_open ( struct usbio_device *usbio, unsigned int interface ) { &efi_usb_io_protocol_guid ); return rc; } - intf->io = u.io; /* Increment usage count */ intf->count++; @@ -1296,24 +1291,20 @@ static int usbio_supported ( EFI_HANDLE handle ) { struct usb_function_descriptor desc; struct usb_driver *driver; struct usb_device_id *id; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } usb; + EFI_USB_IO_PROTOCOL *io; EFI_STATUS efirc; int rc; /* Get protocol */ if ( ( rc = efi_open ( handle, &efi_usb_io_protocol_guid, - &usb.interface ) ) != 0 ) { + &io ) ) != 0 ) { DBGCP ( handle, "USB %s is not a USB device\n", efi_handle_name ( handle ) ); return rc; } /* Get device descriptor */ - if ( ( efirc = usb.io->UsbGetDeviceDescriptor ( usb.io, - &device ) ) != 0 ) { + if ( ( efirc = io->UsbGetDeviceDescriptor ( io, &device ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( handle, "USB %s could not get device descriptor: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); @@ -1324,8 +1315,7 @@ static int usbio_supported ( EFI_HANDLE handle ) { desc.product = device.IdProduct; /* Get interface descriptor */ - if ( ( efirc = usb.io->UsbGetInterfaceDescriptor ( usb.io, - &interface ) ) !=0){ + if ( ( efirc = io->UsbGetInterfaceDescriptor ( io, &interface ) ) != 0){ rc = -EEFI ( efirc ); DBGC ( handle, "USB %s could not get interface descriptor: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); @@ -1460,21 +1450,16 @@ static int usbio_path ( struct usbio_device *usbio ) { EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *end; USB_DEVICE_PATH *usbpath; - union { - void *interface; - EFI_DEVICE_PATH_PROTOCOL *path; - } u; size_t len; int rc; /* Open device path protocol */ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + &path ) ) != 0 ) { DBGC ( usbio, "USBIO %s cannot open device path protocol: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); return rc; } - path = u.interface; /* Locate end of device path and sanity check */ len = efi_path_len ( path ); @@ -1567,10 +1552,6 @@ static int usbio_start ( struct efi_device *efidev ) { EFI_HANDLE handle = efidev->device; struct usbio_device *usbio; struct usb_port *port; - union { - void *interface; - EFI_USB_IO_PROTOCOL *io; - } u; int rc; /* Allocate and initialise structure */ @@ -1585,13 +1566,12 @@ static int usbio_start ( struct efi_device *efidev ) { /* Open USB I/O protocol */ if ( ( rc = efi_open_by_driver ( handle, &efi_usb_io_protocol_guid, - &u.interface ) ) != 0 ) { + &usbio->io ) ) != 0 ) { DBGC ( usbio, "USBIO %s cannot open USB I/O protocol: %s\n", efi_handle_name ( handle ), strerror ( rc ) ); DBGC_EFI_OPENERS ( usbio, handle, &efi_usb_io_protocol_guid ); goto err_open_usbio; } - usbio->io = u.io; /* Describe generic device */ efi_device_info ( handle, "USB", &usbio->dev ); diff --git a/src/image/efi_image.c b/src/image/efi_image.c index ae9255ce5..82101d484 100644 --- a/src/image/efi_image.c +++ b/src/image/efi_image.c @@ -132,10 +132,7 @@ static int efi_image_exec ( struct image *image ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; struct efi_snp_device *snpdev; EFI_DEVICE_PATH_PROTOCOL *path; - union { - EFI_LOADED_IMAGE_PROTOCOL *image; - void *interface; - } loaded; + EFI_LOADED_IMAGE_PROTOCOL *loaded; struct image *shim; struct image *exec; EFI_HANDLE handle; @@ -235,30 +232,30 @@ static int efi_image_exec ( struct image *image ) { /* Get the loaded image protocol for the newly loaded image */ if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, - &loaded.interface ) ) != 0 ) { + &loaded ) ) != 0 ) { /* Should never happen */ goto err_open_protocol; } /* Some EFI 1.10 implementations seem not to fill in DeviceHandle */ - if ( loaded.image->DeviceHandle == NULL ) { + if ( loaded->DeviceHandle == NULL ) { DBGC ( image, "EFIIMAGE %s filling in missing DeviceHandle\n", image->name ); - loaded.image->DeviceHandle = snpdev->handle; + loaded->DeviceHandle = snpdev->handle; } /* Sanity checks */ - assert ( loaded.image->ParentHandle == efi_image_handle ); - assert ( loaded.image->DeviceHandle == snpdev->handle ); - assert ( loaded.image->LoadOptionsSize == 0 ); - assert ( loaded.image->LoadOptions == NULL ); + assert ( loaded->ParentHandle == efi_image_handle ); + assert ( loaded->DeviceHandle == snpdev->handle ); + assert ( loaded->LoadOptionsSize == 0 ); + assert ( loaded->LoadOptions == NULL ); /* Record image code type */ - type = loaded.image->ImageCodeType; + type = loaded->ImageCodeType; /* Set command line */ - loaded.image->LoadOptions = cmdline; - loaded.image->LoadOptionsSize = + loaded->LoadOptions = cmdline; + loaded->LoadOptionsSize = ( ( wcslen ( cmdline ) + 1 /* NUL */ ) * sizeof ( wchar_t ) ); /* Release network devices for use via SNP */ diff --git a/src/include/ipxe/efi/efi.h b/src/include/ipxe/efi/efi.h index 6126d3b87..5fae87731 100644 --- a/src/include/ipxe/efi/efi.h +++ b/src/include/ipxe/efi/efi.h @@ -389,17 +389,88 @@ extern EFI_STATUS efi_init ( EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *systab ); extern void efi_raise_tpl ( struct efi_saved_tpl *tpl ); extern void efi_restore_tpl ( struct efi_saved_tpl *tpl ); -extern int efi_open ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ); -extern int efi_open_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ); +extern int efi_open_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ); +extern int efi_open_unsafe_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ); extern void efi_close_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol ); -extern int efi_open_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ); +extern int efi_open_by_driver_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ); extern void efi_close_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol ); -extern int efi_open_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, - EFI_HANDLE child, void **interface ); +extern int efi_open_by_child_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + EFI_HANDLE child, void **interface ); extern void efi_close_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, EFI_HANDLE child ); +/** + * Test protocol existence + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @ret rc Return status code + */ +#define efi_test( handle, protocol ) \ + efi_open_untyped ( (handle), (protocol), NULL ) + +/** + * Open protocol for ephemeral use + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open( handle, protocol, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_untyped ( (handle), (protocol), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + +/** + * Open protocol for unsafe persistent use + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open_unsafe( handle, protocol, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_unsafe_untyped ( (handle), (protocol), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + +/** + * Open protocol for persistent use by a driver + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open_by_driver( handle, protocol, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_by_driver_untyped ( (handle), (protocol), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + +/** + * Open protocol for persistent use by a child controller + * + * @v handle EFI handle + * @v protocol Protocol GUID + * @v child Child controller handle + * @v interface Protocol interface pointer to fill in + * @ret rc Return status code + */ +#define efi_open_by_child( handle, protocol, child, interface ) ( { \ + typeof ( *(interface) ) check_ptr_ptr = NULL; \ + efi_open_by_child_untyped ( (handle), (protocol), (child), \ + ( ( void ) check_ptr_ptr, \ + ( void ** ) (interface) ) ); \ + } ) + #endif /* _IPXE_EFI_H */ diff --git a/src/interface/efi/efi_autoboot.c b/src/interface/efi/efi_autoboot.c index 528b84f1e..e52c857d8 100644 --- a/src/interface/efi/efi_autoboot.c +++ b/src/interface/efi/efi_autoboot.c @@ -48,24 +48,21 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ int efi_set_autoboot_ll_addr ( EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *path ) { - union { - EFI_SIMPLE_NETWORK_PROTOCOL *snp; - void *interface; - } snp; + EFI_SIMPLE_NETWORK_PROTOCOL *snp; EFI_SIMPLE_NETWORK_MODE *mode; unsigned int vlan; int rc; /* Look for an SNP instance on the image's device handle */ if ( ( rc = efi_open ( device, &efi_simple_network_protocol_guid, - &snp.interface ) ) != 0 ) { + &snp ) ) != 0 ) { DBGC ( device, "EFI %s has no SNP instance: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Record autoboot device */ - mode = snp.snp->Mode; + mode = snp->Mode; vlan = efi_path_vlan ( path ); set_autoboot_ll_addr ( &mode->CurrentAddress, mode->HwAddressSize, vlan ); diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c index 34b73c265..5165bd804 100644 --- a/src/interface/efi/efi_block.c +++ b/src/interface/efi/efi_block.c @@ -518,23 +518,20 @@ static int efi_block_describe ( void ) { */ static int efi_block_root ( unsigned int drive, EFI_HANDLE handle, EFI_FILE_PROTOCOL **root ) { - union { - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; - void *interface; - } u; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; EFI_STATUS efirc; int rc; /* Open filesystem protocol */ if ( ( rc = efi_open ( handle, &efi_simple_file_system_protocol_guid, - &u.interface ) ) != 0 ) { + &fs ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open %s filesystem: %s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); return rc; } /* Open root volume */ - if ( ( efirc = u.fs->OpenVolume ( u.fs, root ) ) != 0 ) { + if ( ( efirc = fs->OpenVolume ( fs, root ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( drive, "EFIBLK %#02x could not open %s root: %s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); @@ -664,26 +661,21 @@ static int efi_block_match ( unsigned int drive, EFI_HANDLE handle, EFI_DEVICE_PATH_PROTOCOL *path, struct san_boot_config *config, EFI_DEVICE_PATH_PROTOCOL **fspath ) { - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } u; EFI_FILE *root; union uuid guid; int rc; /* Identify device path */ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + fspath ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open %s device path: " "%s\n", drive, efi_handle_name ( handle ), strerror ( rc ) ); goto err_open; } - *fspath = u.path; /* Check if filesystem is a child of this block device */ - if ( memcmp ( u.path, path, efi_path_len ( path ) ) != 0 ) { + if ( memcmp ( *fspath, path, efi_path_len ( path ) ) != 0 ) { /* Not a child device */ rc = -ENOTTY; DBGC2 ( drive, "EFIBLK %#02x is not parent of %s\n", @@ -691,11 +683,11 @@ static int efi_block_match ( unsigned int drive, EFI_HANDLE handle, goto err_not_child; } DBGC ( drive, "EFIBLK %#02x contains filesystem %s\n", - drive, efi_devpath_text ( u.path ) ); + drive, efi_devpath_text ( *fspath ) ); /* Check if filesystem matches GUID, if applicable */ if ( config->uuid ) { - if ( ( rc = efi_path_guid ( u.path, &guid ) ) != 0 ) { + if ( ( rc = efi_path_guid ( *fspath, &guid ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not determine GUID: " "%s\n", drive, strerror ( rc ) ); goto err_no_guid; @@ -760,10 +752,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, struct san_boot_config *config, EFI_DEVICE_PATH_PROTOCOL **fspath ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } u; + EFI_DEVICE_PATH_PROTOCOL *path; EFI_HANDLE *handles; UINTN count; unsigned int i; @@ -775,7 +764,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, /* Identify device path */ if ( ( rc = efi_open ( handle, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + &path ) ) != 0 ) { DBGC ( drive, "EFIBLK %#02x could not open device path: %s\n", drive, strerror ( rc ) ); goto err_open; @@ -796,7 +785,7 @@ static int efi_block_scan ( unsigned int drive, EFI_HANDLE handle, for ( i = 0 ; i < count ; i++ ) { /* Check for a matching filesystem */ - if ( ( rc = efi_block_match ( drive, handles[i], u.path, + if ( ( rc = efi_block_match ( drive, handles[i], path, config, fspath ) ) != 0 ) continue; @@ -903,10 +892,7 @@ static int efi_block_exec ( unsigned int drive, static int efi_block_local ( EFI_HANDLE handle ) { struct san_device *sandev; struct efi_block_data *block; - union { - EFI_BLOCK_IO_PROTOCOL *blockio; - void *interface; - } u; + EFI_BLOCK_IO_PROTOCOL *blockio; int rc; /* Check if handle belongs to a SAN device */ @@ -918,14 +904,14 @@ static int efi_block_local ( EFI_HANDLE handle ) { /* Open block I/O protocol */ if ( ( rc = efi_open ( handle, &efi_block_io_protocol_guid, - &u.interface ) ) != 0 ) { + &blockio ) ) != 0 ) { DBGC ( handle, "EFIBLK %s could not open block I/O: %s\n", efi_handle_name ( handle ), strerror ( rc ) ); return rc; } /* Do not assign drive numbers for partitions */ - if ( u.blockio->Media->LogicalPartition ) { + if ( blockio->Media->LogicalPartition ) { DBGC2 ( handle, "EFLBLK %s is a partition\n", efi_handle_name ( handle ) ); return -ENOTTY; diff --git a/src/interface/efi/efi_bofm.c b/src/interface/efi/efi_bofm.c index 6d97ff445..b64770d8a 100644 --- a/src/interface/efi/efi_bofm.c +++ b/src/interface/efi/efi_bofm.c @@ -228,7 +228,6 @@ static int efi_bofm_start ( struct efi_device *efidev ) { struct efi_pci_device efipci; IBM_BOFM_TABLE *bofmtab; IBM_BOFM_TABLE *bofmtab2; - void *pci_io; int bofmrc; EFI_STATUS efirc; int rc; @@ -242,7 +241,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) { /* Open PCI I/O protocol */ if ( ( rc = efi_open_unsafe ( device, &efi_pci_io_protocol_guid, - &pci_io ) ) != 0 ) { + &efipci.io ) ) != 0 ) { DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open; diff --git a/src/interface/efi/efi_cachedhcp.c b/src/interface/efi/efi_cachedhcp.c index 68671d7c6..eb41a8e43 100644 --- a/src/interface/efi/efi_cachedhcp.c +++ b/src/interface/efi/efi_cachedhcp.c @@ -47,10 +47,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); int efi_cachedhcp_record ( EFI_HANDLE device, EFI_DEVICE_PATH_PROTOCOL *path ) { unsigned int vlan; - union { - EFI_PXE_BASE_CODE_PROTOCOL *pxe; - void *interface; - } pxe; + EFI_PXE_BASE_CODE_PROTOCOL *pxe; EFI_PXE_BASE_CODE_MODE *mode; int rc; @@ -59,14 +56,14 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Look for a PXE base code instance on the image's device handle */ if ( ( rc = efi_open ( device, &efi_pxe_base_code_protocol_guid, - &pxe.interface ) ) != 0 ) { + &pxe ) ) != 0 ) { DBGC ( device, "EFI %s has no PXE base code instance: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Do not attempt to cache IPv6 packets */ - mode = pxe.pxe->Mode; + mode = pxe->Mode; if ( mode->UsingIpv6 ) { DBGC ( device, "EFI %s has IPv6 PXE base code\n", efi_handle_name ( device ) ); diff --git a/src/interface/efi/efi_console.c b/src/interface/efi/efi_console.c index 41c4dcf2c..9fc3c65c0 100644 --- a/src/interface/efi/efi_console.c +++ b/src/interface/efi/efi_console.c @@ -416,10 +416,6 @@ struct console_driver efi_console __console_driver = { */ static void efi_console_init ( void ) { EFI_CONSOLE_CONTROL_SCREEN_MODE mode; - union { - void *interface; - EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *wtf; - } u; int rc; /* On some older EFI 1.10 implementations, we must use the @@ -441,8 +437,7 @@ static void efi_console_init ( void ) { */ if ( ( rc = efi_open_unsafe ( efi_systab->ConsoleInHandle, &efi_simple_text_input_ex_protocol_guid, - &u.interface ) ) == 0 ) { - efi_conin_ex = u.wtf; + &efi_conin_ex ) ) == 0 ) { DBG ( "EFI using SimpleTextInputEx\n" ); } else { DBG ( "EFI has no SimpleTextInputEx: %s\n", strerror ( rc ) ); diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index fd4997ccc..026adc25e 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -324,10 +324,7 @@ static const char * efi_driver_name2 ( EFI_COMPONENT_NAME2_PROTOCOL *wtf ) { * @ret name Driver name, or NULL */ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { - union { - EFI_COMPONENT_NAME_PROTOCOL *name; - void *interface; - } u; + EFI_COMPONENT_NAME_PROTOCOL *name; EFI_HANDLE image; int rc; @@ -340,13 +337,13 @@ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { /* Try to open component name protocol on image handle */ image = binding->ImageHandle; if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, - &u.interface ) ) != 0 ) { + &name ) ) != 0 ) { DBG ( "[DriverBinding no ComponentName]" ); return NULL; } /* Try to get name from component name protocol */ - return efi_driver_name ( u.name ); + return efi_driver_name ( name ); } /** @@ -357,10 +354,7 @@ static const char * efi_binding_name ( EFI_DRIVER_BINDING_PROTOCOL *binding ) { */ static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){ EFI_HANDLE image; - union { - EFI_COMPONENT_NAME2_PROTOCOL *name2; - void *interface; - } u; + EFI_COMPONENT_NAME2_PROTOCOL *name2; int rc; /* Sanity check */ @@ -372,13 +366,13 @@ static const char * efi_binding_name2 ( EFI_DRIVER_BINDING_PROTOCOL *binding ){ /* Try to open component name protocol on image handle */ image = binding->ImageHandle; if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, - &u.interface ) ) != 0 ) { + &name2 ) ) != 0 ) { DBG ( "[DriverBinding no ComponentName2]" ); return NULL; } /* Try to get name from component name protocol */ - return efi_driver_name2 ( u.name2 ); + return efi_driver_name2 ( name2 ); } /** diff --git a/src/interface/efi/efi_driver.c b/src/interface/efi/efi_driver.c index d143249ca..56918deba 100644 --- a/src/interface/efi/efi_driver.c +++ b/src/interface/efi/efi_driver.c @@ -69,22 +69,19 @@ static int efi_driver_disconnecting; */ struct efi_device * efidev_alloc ( EFI_HANDLE device ) { struct efi_device *efidev = NULL; - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } path; + EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *path_end; size_t path_len; int rc; /* Open device path */ if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, - &path.interface ) ) != 0 ) { + &path ) ) != 0 ) { DBGC ( device, "EFIDRV %s could not open device path: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return NULL; } - path_len = ( efi_path_len ( path.path ) + sizeof ( *path_end ) ); + path_len = ( efi_path_len ( path ) + sizeof ( *path_end ) ); /* Allocate and initialise structure */ efidev = zalloc ( sizeof ( *efidev ) + path_len ); @@ -93,7 +90,7 @@ struct efi_device * efidev_alloc ( EFI_HANDLE device ) { efidev->device = device; efidev->dev.desc.bus_type = BUS_TYPE_EFI; efidev->path = ( ( ( void * ) efidev ) + sizeof ( *efidev ) ); - memcpy ( efidev->path, path.path, path_len ); + memcpy ( efidev->path, path, path_len ); INIT_LIST_HEAD ( &efidev->dev.children ); list_add ( &efidev->dev.siblings, &efi_devices ); @@ -365,10 +362,7 @@ static EFI_STATUS EFIAPI efi_driver_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused, EFI_HANDLE device, EFI_HANDLE child, CHAR8 *language, CHAR16 **controller_name ) { - union { - EFI_COMPONENT_NAME2_PROTOCOL *name2; - void *interface; - } name2; + EFI_COMPONENT_NAME2_PROTOCOL *name2; int rc; /* Delegate to the EFI_COMPONENT_NAME2_PROTOCOL instance @@ -376,10 +370,9 @@ efi_driver_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused, */ if ( ( child != NULL ) && ( ( rc = efi_open ( child, &efi_component_name2_protocol_guid, - &name2.interface ) ) == 0 ) ) { - return name2.name2->GetControllerName ( name2.name2, device, - child, language, - controller_name ); + &name2 ) ) == 0 ) ) { + return name2->GetControllerName ( name2, device, child, + language, controller_name ); } /* Otherwise, let EFI use the default Device Path Name */ diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c index d8b9f819c..b7b97aee7 100644 --- a/src/interface/efi/efi_file.c +++ b/src/interface/efi/efi_file.c @@ -982,9 +982,9 @@ static EFI_DISK_IO_PROTOCOL efi_disk_io_protocol = { */ static int efi_file_path_claim ( struct efi_file_path *file ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + EFI_DEVICE_PATH_PROTOCOL *old; EFI_DEVICE_PATH_PROTOCOL *end; EFI_HANDLE handle; - VOID *old; EFI_STATUS efirc; int rc; @@ -1116,10 +1116,7 @@ static void efi_file_path_uninstall ( struct efi_file_path *file ) { */ int efi_file_install ( EFI_HANDLE handle ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - union { - EFI_DISK_IO_PROTOCOL *diskio; - void *interface; - } diskio; + EFI_DISK_IO_PROTOCOL *diskio; struct image *image; EFI_STATUS efirc; int rc; @@ -1168,13 +1165,13 @@ int efi_file_install ( EFI_HANDLE handle ) { * shell. I have no idea why this is. */ if ( ( rc = efi_open_by_driver ( handle, &efi_disk_io_protocol_guid, - &diskio.interface ) ) != 0 ) { + &diskio ) ) != 0 ) { DBGC ( handle, "Could not open disk I/O protocol: %s\n", strerror ( rc ) ); DBGC_EFI_OPENERS ( handle, handle, &efi_disk_io_protocol_guid ); goto err_open; } - assert ( diskio.diskio == &efi_disk_io_protocol ); + assert ( diskio == &efi_disk_io_protocol ); /* Claim Linux initrd fixed device path */ if ( ( rc = efi_file_path_claim ( &efi_file_initrd ) ) != 0 ) diff --git a/src/interface/efi/efi_init.c b/src/interface/efi/efi_init.c index 03506ec5c..1ba144ee7 100644 --- a/src/interface/efi/efi_init.c +++ b/src/interface/efi/efi_init.c @@ -173,8 +173,7 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, EFI_BOOT_SERVICES *bs; struct efi_protocol *prot; struct efi_config_table *tab; - void *loaded_image; - void *device_path; + EFI_DEVICE_PATH_PROTOCOL *device_path; void *device_path_copy; size_t device_path_len; EFI_STATUS efirc; @@ -248,13 +247,12 @@ EFI_STATUS efi_init ( EFI_HANDLE image_handle, */ if ( ( rc = efi_open_unsafe ( image_handle, &efi_loaded_image_protocol_guid, - &loaded_image ) ) != 0 ) { + &efi_loaded_image ) ) != 0 ) { DBGC ( systab, "EFI could not get loaded image protocol: %s", strerror ( rc ) ); efirc = EFIRC ( rc ); goto err_no_loaded_image; } - efi_loaded_image = loaded_image; DBGC ( systab, "EFI image base address %p\n", efi_loaded_image->ImageBase ); diff --git a/src/interface/efi/efi_local.c b/src/interface/efi/efi_local.c index 80cfb5a22..4564470fc 100644 --- a/src/interface/efi/efi_local.c +++ b/src/interface/efi/efi_local.c @@ -208,23 +208,20 @@ static int efi_local_check_volume_name ( struct efi_local *local, */ static int efi_local_open_root ( struct efi_local *local, EFI_HANDLE device, EFI_FILE_PROTOCOL **root ) { - union { - void *interface; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; - } u; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *fs; EFI_STATUS efirc; int rc; /* Open file system protocol */ if ( ( rc = efi_open ( device, &efi_simple_file_system_protocol_guid, - &u.interface ) ) != 0 ) { + &fs ) ) != 0 ) { DBGC ( local, "LOCAL %p could not open filesystem on %s: %s\n", local, efi_handle_name ( device ), strerror ( rc ) ); return rc; } /* Open root directory */ - if ( ( efirc = u.fs->OpenVolume ( u.fs, root ) ) != 0 ) { + if ( ( efirc = fs->OpenVolume ( fs, root ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( local, "LOCAL %p could not open volume on %s: %s\n", local, efi_handle_name ( device ), strerror ( rc ) ); diff --git a/src/interface/efi/efi_open.c b/src/interface/efi/efi_open.c index c85c027e1..8f8af4ea0 100644 --- a/src/interface/efi/efi_open.c +++ b/src/interface/efi/efi_open.c @@ -93,7 +93,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @v interface Protocol interface pointer to fill in (or NULL to test) * @ret rc Return status code */ -int efi_open ( EFI_HANDLE handle, EFI_GUID *protocol, void **interface ) { +int efi_open_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; @@ -176,8 +177,8 @@ int efi_open ( EFI_HANDLE handle, EFI_GUID *protocol, void **interface ) { * @v interface Protocol interface pointer to fill in * @ret rc Return status code */ -int efi_open_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ) { +int efi_open_unsafe_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; @@ -236,8 +237,8 @@ void efi_close_unsafe ( EFI_HANDLE handle, EFI_GUID *protocol ) { * @v interface Protocol interface pointer to fill in * @ret rc Return status code */ -int efi_open_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol, - void **interface ) { +int efi_open_by_driver_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; @@ -297,8 +298,8 @@ void efi_close_by_driver ( EFI_HANDLE handle, EFI_GUID *protocol ) { * @v interface Protocol interface pointer to fill in * @ret rc Return status code */ -int efi_open_by_child ( EFI_HANDLE handle, EFI_GUID *protocol, - EFI_HANDLE child, void **interface ) { +int efi_open_by_child_untyped ( EFI_HANDLE handle, EFI_GUID *protocol, + EFI_HANDLE child, void **interface ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE agent = efi_image_handle; EFI_HANDLE controller; diff --git a/src/interface/efi/efi_pci.c b/src/interface/efi/efi_pci.c index 003fa2f4a..0662302d2 100644 --- a/src/interface/efi/efi_pci.c +++ b/src/interface/efi/efi_pci.c @@ -72,10 +72,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, struct pci_range *range ) { - union { - void *interface; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; - } root; + EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; union { union acpi_resource *res; void *raw; @@ -94,7 +91,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, /* Open root bridge I/O protocol */ if ( ( rc = efi_open ( handle, &efi_pci_root_bridge_io_protocol_guid, - &root.interface ) ) != 0 ) { + &root ) ) != 0 ) { DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n", PCI_ARGS ( pci ), efi_handle_name ( handle ), strerror ( rc ) ); @@ -102,8 +99,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, } /* Get ACPI resource descriptors */ - if ( ( efirc = root.root->Configuration ( root.root, - &acpi.raw ) ) != 0 ) { + if ( ( efirc = root->Configuration ( root, &acpi.raw ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( pci, "EFIPCI " PCI_FMT " cannot get configuration for " "%s: %s\n", PCI_ARGS ( pci ), @@ -123,13 +119,13 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, continue; /* Get range for this descriptor */ - start = PCI_BUSDEVFN ( root.root->SegmentNumber, + start = PCI_BUSDEVFN ( root->SegmentNumber, le64_to_cpu ( acpi.res->qword.min ), 0, 0 ); count = PCI_BUSDEVFN ( 0, le64_to_cpu ( acpi.res->qword.len ), 0, 0 ); DBGC2 ( pci, "EFIPCI " PCI_FMT " found %04x:[%02x-%02x] via " - "%s\n", PCI_ARGS ( pci ), root.root->SegmentNumber, + "%s\n", PCI_ARGS ( pci ), root->SegmentNumber, PCI_BUS ( start ), PCI_BUS ( start + count - 1 ), efi_handle_name ( handle ) ); @@ -150,8 +146,7 @@ static int efipci_discover_one ( struct pci_device *pci, EFI_HANDLE handle, * bridge has a single bus. */ if ( ! range->count ) { - range->start = PCI_BUSDEVFN ( root.root->SegmentNumber, - 0, 0, 0 ); + range->start = PCI_BUSDEVFN ( root->SegmentNumber, 0, 0, 0 ); range->count = PCI_BUSDEVFN ( 0, 1, 0, 0 ); } @@ -259,10 +254,6 @@ static void efipci_discover ( uint32_t busdevfn, struct pci_range *range ) { static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL **root ) { struct pci_range tmp; - union { - void *interface; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *root; - } u; int rc; /* Find matching root bridge I/O protocol handle */ @@ -271,16 +262,13 @@ static int efipci_root_open ( struct pci_device *pci, EFI_HANDLE *handle, /* Open PCI root bridge I/O protocol */ if ( ( rc = efi_open ( *handle, &efi_pci_root_bridge_io_protocol_guid, - &u.interface ) ) != 0 ) { + root ) ) != 0 ) { DBGC ( pci, "EFIPCI " PCI_FMT " cannot open %s: %s\n", PCI_ARGS ( pci ), efi_handle_name ( *handle ), strerror ( rc ) ); return rc; } - /* Return opened protocol */ - *root = u.root; - return 0; } @@ -742,10 +730,7 @@ static struct dma_operations efipci_dma_operations = { * @ret rc Return status code */ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { - union { - EFI_PCI_IO_PROTOCOL *pci_io; - void *interface; - } pci_io; + EFI_PCI_IO_PROTOCOL *pci_io; UINTN pci_segment, pci_bus, pci_dev, pci_fn; unsigned int busdevfn; EFI_STATUS efirc; @@ -753,17 +738,16 @@ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { /* See if device is a PCI device */ if ( ( rc = efi_open ( device, &efi_pci_io_protocol_guid, - &pci_io.interface ) ) != 0 ) { + &pci_io ) ) != 0 ) { DBGCP ( device, "EFIPCI %s cannot open PCI protocols: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; } - efipci->io = pci_io.pci_io; + efipci->io = pci_io; /* Get PCI bus:dev.fn address */ - if ( ( efirc = pci_io.pci_io->GetLocation ( pci_io.pci_io, &pci_segment, - &pci_bus, &pci_dev, - &pci_fn ) ) != 0 ) { + if ( ( efirc = pci_io->GetLocation ( pci_io, &pci_segment, &pci_bus, + &pci_dev, &pci_fn ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( device, "EFIPCI %s could not get PCI location: %s\n", efi_handle_name ( device ), strerror ( rc ) ); @@ -781,15 +765,12 @@ int efipci_info ( EFI_HANDLE device, struct efi_pci_device *efipci ) { * support I/O cycles). Work around any such platforms by * enabling bits individually and simply ignoring any errors. */ - pci_io.pci_io->Attributes ( pci_io.pci_io, - EfiPciIoAttributeOperationEnable, - EFI_PCI_IO_ATTRIBUTE_IO, NULL ); - pci_io.pci_io->Attributes ( pci_io.pci_io, - EfiPciIoAttributeOperationEnable, - EFI_PCI_IO_ATTRIBUTE_MEMORY, NULL ); - pci_io.pci_io->Attributes ( pci_io.pci_io, - EfiPciIoAttributeOperationEnable, - EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL ); + pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable, + EFI_PCI_IO_ATTRIBUTE_IO, NULL ); + pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable, + EFI_PCI_IO_ATTRIBUTE_MEMORY, NULL ); + pci_io->Attributes ( pci_io, EfiPciIoAttributeOperationEnable, + EFI_PCI_IO_ATTRIBUTE_BUS_MASTER, NULL ); /* Populate PCI device */ if ( ( rc = pci_read_config ( &efipci->pci ) ) != 0 ) { @@ -857,7 +838,6 @@ static int efipci_supported ( EFI_HANDLE device ) { static int efipci_start ( struct efi_device *efidev ) { EFI_HANDLE device = efidev->device; struct efi_pci_device *efipci; - void *pci_io; int rc; /* Allocate PCI device */ @@ -873,7 +853,7 @@ static int efipci_start ( struct efi_device *efidev ) { /* Open PCI I/O protocol */ if ( ( rc = efi_open_by_driver ( device, &efi_pci_io_protocol_guid, - &pci_io ) ) != 0 ) { + &efipci->io ) ) != 0 ) { DBGC ( device, "EFIPCI %s could not open PCI device: %s\n", efi_handle_name ( device ), strerror ( rc ) ); DBGC_EFI_OPENERS ( device, device, &efi_pci_io_protocol_guid ); diff --git a/src/interface/efi/efi_service.c b/src/interface/efi/efi_service.c index de7353652..f10733b24 100644 --- a/src/interface/efi/efi_service.c +++ b/src/interface/efi/efi_service.c @@ -45,15 +45,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE *handle ) { - union { - EFI_SERVICE_BINDING_PROTOCOL *sb; - void *interface; - } u; + EFI_SERVICE_BINDING_PROTOCOL *sb; EFI_STATUS efirc; int rc; /* Open service binding protocol */ - if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) { + if ( ( rc = efi_open ( service, binding, &sb ) ) != 0 ) { DBGC ( service, "EFISVC %s cannot open %s binding: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), strerror ( rc ) ); @@ -61,7 +58,7 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, } /* Create child handle */ - if ( ( efirc = u.sb->CreateChild ( u.sb, handle ) ) != 0 ) { + if ( ( efirc = sb->CreateChild ( sb, handle ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( service, "EFISVC %s could not create %s child: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), @@ -85,10 +82,7 @@ int efi_service_add ( EFI_HANDLE service, EFI_GUID *binding, */ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, EFI_HANDLE handle ) { - union { - EFI_SERVICE_BINDING_PROTOCOL *sb; - void *interface; - } u; + EFI_SERVICE_BINDING_PROTOCOL *sb; EFI_STATUS efirc; int rc; @@ -97,7 +91,7 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, DBGC ( service, "%s\n", efi_handle_name ( handle ) ); /* Open service binding protocol */ - if ( ( rc = efi_open ( service, binding, &u.interface ) ) != 0 ) { + if ( ( rc = efi_open ( service, binding, &sb ) ) != 0 ) { DBGC ( service, "EFISVC %s cannot open %s binding: %s\n", efi_handle_name ( service ), efi_guid_ntoa ( binding ), strerror ( rc ) ); @@ -105,7 +99,7 @@ int efi_service_del ( EFI_HANDLE service, EFI_GUID *binding, } /* Destroy child handle */ - if ( ( efirc = u.sb->DestroyChild ( u.sb, handle ) ) != 0 ) { + if ( ( efirc = sb->DestroyChild ( sb, handle ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( service, "EFISVC %s could not destroy %s child ", efi_handle_name ( service ), efi_guid_ntoa ( binding ) ); diff --git a/src/interface/efi/efi_shim.c b/src/interface/efi/efi_shim.c index 02bd0791f..4bb6df79f 100644 --- a/src/interface/efi/efi_shim.c +++ b/src/interface/efi/efi_shim.c @@ -272,23 +272,20 @@ static EFIAPI EFI_STATUS efi_shim_get_memory_map ( UINTN *len, * @ret rc Return status code */ static int efi_shim_inhibit_pxe ( EFI_HANDLE handle ) { - union { - EFI_PXE_BASE_CODE_PROTOCOL *pxe; - void *interface; - } u; + EFI_PXE_BASE_CODE_PROTOCOL *pxe; EFI_STATUS efirc; int rc; /* Locate PXE base code */ if ( ( rc = efi_open ( handle, &efi_pxe_base_code_protocol_guid, - &u.interface ) ) != 0 ) { + &pxe ) ) != 0 ) { DBGC ( &efi_shim, "SHIM could not open PXE base code: %s\n", strerror ( rc ) ); return rc; } /* Stop PXE base code */ - if ( ( efirc = u.pxe->Stop ( u.pxe ) ) != 0 ) { + if ( ( efirc = pxe->Stop ( pxe ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( &efi_shim, "SHIM could not stop PXE base code: %s\n", strerror ( rc ) ); diff --git a/src/interface/efi/efi_utils.c b/src/interface/efi/efi_utils.c index 4f081b67f..51da06172 100644 --- a/src/interface/efi/efi_utils.c +++ b/src/interface/efi/efi_utils.c @@ -45,10 +45,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, EFI_HANDLE *parent, unsigned int skip ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; - union { - EFI_DEVICE_PATH_PROTOCOL *path; - void *interface; - } u; + EFI_DEVICE_PATH_PROTOCOL *devpath; EFI_DEVICE_PATH_PROTOCOL *path; EFI_DEVICE_PATH_PROTOCOL *end; size_t len; @@ -57,20 +54,20 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, /* Get device path */ if ( ( rc = efi_open ( device, &efi_device_path_protocol_guid, - &u.interface ) ) != 0 ) { + &devpath ) ) != 0 ) { DBGC ( device, "EFIDEV %s cannot open device path: %s\n", efi_handle_name ( device ), strerror ( rc ) ); goto err_open_device_path; } /* Create modifiable copy of device path */ - len = ( efi_path_len ( u.path ) + sizeof ( EFI_DEVICE_PATH_PROTOCOL )); + len = ( efi_path_len ( devpath ) + sizeof ( *end ) ); path = malloc ( len ); if ( ! path ) { rc = -ENOMEM; goto err_alloc_path; } - memcpy ( path, u.path, len ); + memcpy ( path, devpath, len ); /* Locate parent device(s) */ while ( 1 ) { @@ -111,7 +108,7 @@ int efi_locate_device ( EFI_HANDLE device, EFI_GUID *protocol, * @ret rc Return status code */ int efi_child_add ( EFI_HANDLE parent, EFI_HANDLE child ) { - void *devpath; + EFI_DEVICE_PATH_PROTOCOL *devpath; int rc; /* Re-open the device path protocol */ diff --git a/src/interface/efi/efi_veto.c b/src/interface/efi/efi_veto.c index 637eee016..3f9c9940e 100644 --- a/src/interface/efi/efi_veto.c +++ b/src/interface/efi/efi_veto.c @@ -153,16 +153,13 @@ static int efi_veto_disconnect ( struct efi_veto *veto ) { static int efi_veto_uninstall ( struct efi_veto *veto ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; EFI_HANDLE driver = veto->driver; - union { - EFI_DRIVER_BINDING_PROTOCOL *binding; - void *interface; - } binding; + EFI_DRIVER_BINDING_PROTOCOL *binding; EFI_STATUS efirc; int rc; /* Open driver binding protocol */ if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, - &binding.interface ) ) != 0 ) { + &binding ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open driver binding " "protocol: %s\n", efi_handle_name ( driver ), strerror ( rc ) ); @@ -172,7 +169,7 @@ static int efi_veto_uninstall ( struct efi_veto *veto ) { /* Uninstall driver binding protocol */ if ( ( efirc = bs->UninstallMultipleProtocolInterfaces ( driver, &efi_driver_binding_protocol_guid, - binding.binding, NULL ) ) != 0 ) { + binding, NULL ) ) != 0 ) { rc = -EEFI ( efirc ); DBGC ( driver, "EFIVETO %s could not uninstall driver " "binding protocol: %s\n", @@ -534,22 +531,10 @@ static struct efi_veto_candidate efi_vetoes[] = { */ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, struct efi_veto *veto ) { - union { - EFI_DRIVER_BINDING_PROTOCOL *binding; - void *interface; - } binding; - union { - EFI_LOADED_IMAGE_PROTOCOL *loaded; - void *interface; - } loaded; - union { - EFI_COMPONENT_NAME2_PROTOCOL *wtf2; - void *interface; - } wtf2; - union { - EFI_COMPONENT_NAME_PROTOCOL *wtf; - void *interface; - } wtf; + EFI_DRIVER_BINDING_PROTOCOL *binding; + EFI_LOADED_IMAGE_PROTOCOL *loaded; + EFI_COMPONENT_NAME2_PROTOCOL *wtf2; + EFI_COMPONENT_NAME_PROTOCOL *wtf; CHAR16 *name; unsigned int i; EFI_HANDLE image; @@ -561,17 +546,17 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, /* Open driver binding protocol */ if ( ( rc = efi_open ( driver, &efi_driver_binding_protocol_guid, - &binding.interface ) ) != 0 ) { + &binding ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open driver binding " "protocol: %s\n", efi_handle_name ( driver ), strerror ( rc ) ); return rc; } - image = binding.binding->ImageHandle; + image = binding->ImageHandle; /* Open loaded image protocol */ if ( ( rc = efi_open ( image, &efi_loaded_image_protocol_guid, - &loaded.interface ) ) != 0 ) { + &loaded ) ) != 0 ) { DBGC ( driver, "EFIVETO %s could not open", efi_handle_name ( driver ) ); DBGC ( driver, " %s loaded image protocol: %s\n", @@ -581,23 +566,21 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, /* Open component name protocol, if present */ if ( ( rc = efi_open ( image, &efi_component_name2_protocol_guid, - &wtf2.interface ) ) != 0 ) { + &wtf2 ) ) != 0 ) { /* Ignore failure; is not required to be present */ } /* Open obsolete component name protocol, if present */ if ( ( rc = efi_open ( image, &efi_component_name_protocol_guid, - &wtf.interface ) ) != 0 ) { + &wtf ) ) != 0 ) { /* Ignore failure; is not required to be present */ } /* Get driver name, if available */ - if ( ( wtf2.wtf2 && - ( ( efirc = wtf2.wtf2->GetDriverName ( wtf2.wtf2, "en", - &name ) == 0 ) ) ) || - ( wtf.wtf && - ( ( efirc = wtf.wtf->GetDriverName ( wtf.wtf, "eng", - &name ) == 0 ) ) ) ) { + if ( ( wtf2 && ( ( efirc = wtf2->GetDriverName ( wtf2, "en", + &name ) == 0 ) ) ) || + ( wtf && ( ( efirc = wtf->GetDriverName ( wtf, "eng", + &name ) == 0 ) ) ) ) { /* Driver has a name */ } else { /* Ignore failure; name is not required to be present */ @@ -606,19 +589,19 @@ static int efi_veto_find ( EFI_HANDLE driver, const char *manufacturer, /* Check vetoes */ DBGC2 ( &efi_vetoes, "EFIVETO checking %s [%p,%p)\n", - efi_handle_name ( driver ), loaded.loaded->ImageBase, - ( loaded.loaded->ImageBase + loaded.loaded->ImageSize ) ); + efi_handle_name ( driver ), loaded->ImageBase, + ( loaded->ImageBase + loaded->ImageSize ) ); for ( i = 0 ; i < ( sizeof ( efi_vetoes ) / sizeof ( efi_vetoes[0] ) ) ; i++ ) { - if ( efi_vetoes[i].veto ( binding.binding, loaded.loaded, - manufacturer, name ) ) { + if ( efi_vetoes[i].veto ( binding, loaded, manufacturer, + name ) ) { DBGC ( driver, "EFIVETO %s is vetoed (%s)\n", efi_handle_name ( driver ), efi_vetoes[i].name ); veto->driver = driver; - veto->binding = binding.binding; + veto->binding = binding; veto->image = image; - veto->loaded = loaded.loaded; + veto->loaded = loaded; break; } } diff --git a/src/interface/efi/efi_wrap.c b/src/interface/efi/efi_wrap.c index 1cc37f3e3..a806a7c60 100644 --- a/src/interface/efi/efi_wrap.c +++ b/src/interface/efi/efi_wrap.c @@ -248,15 +248,12 @@ static int efi_prescroll ( unsigned int lines ) { * @v handle Image handle */ static void efi_dump_image ( EFI_HANDLE handle ) { - union { - EFI_LOADED_IMAGE_PROTOCOL *image; - void *intf; - } loaded; + EFI_LOADED_IMAGE_PROTOCOL *loaded; int rc; /* Open loaded image protocol */ if ( ( rc = efi_open ( handle, &efi_loaded_image_protocol_guid, - &loaded.intf ) ) != 0 ) { + &loaded ) ) != 0 ) { DBGC ( colour, "WRAP %s could not get loaded image protocol: " "%s\n", efi_handle_name ( handle ), strerror ( rc ) ); return; @@ -264,14 +261,14 @@ static void efi_dump_image ( EFI_HANDLE handle ) { /* Dump image information */ DBGC ( colour, "WRAP %s at base %p has protocols:\n", - efi_handle_name ( handle ), loaded.image->ImageBase ); + efi_handle_name ( handle ), loaded->ImageBase ); DBGC_EFI_PROTOCOLS ( colour, handle ); DBGC ( colour, "WRAP %s parent", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->ParentHandle )); + DBGC ( colour, " %s\n", efi_handle_name ( loaded->ParentHandle ) ); DBGC ( colour, "WRAP %s device", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_handle_name ( loaded.image->DeviceHandle )); + DBGC ( colour, " %s\n", efi_handle_name ( loaded->DeviceHandle ) ); DBGC ( colour, "WRAP %s file", efi_handle_name ( handle ) ); - DBGC ( colour, " %s\n", efi_devpath_text ( loaded.image->FilePath ) ); + DBGC ( colour, " %s\n", efi_devpath_text ( loaded->FilePath ) ); } /** -- cgit v1.2.3-55-g7522 From c01c3215dcff1be62347db794dddc1e33c219887 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 14 Jul 2025 12:15:08 +0100 Subject: [efi] Provide efi_tpl_name() for transcribing TPLs in debug messages Signed-off-by: Michael Brown --- src/include/ipxe/efi/efi.h | 2 ++ src/interface/efi/efi_debug.c | 21 +++++++++++++++++++++ src/interface/efi/efi_wrap.c | 35 +++++++---------------------------- 3 files changed, 30 insertions(+), 28 deletions(-) (limited to 'src/interface/efi/efi_debug.c') diff --git a/src/include/ipxe/efi/efi.h b/src/include/ipxe/efi/efi.h index 29c292f36..03081f6f4 100644 --- a/src/include/ipxe/efi/efi.h +++ b/src/include/ipxe/efi/efi.h @@ -273,6 +273,8 @@ extern int efi_shutdown_in_progress; extern const __attribute__ (( pure )) char * efi_guid_ntoa ( CONST EFI_GUID *guid ); extern const __attribute__ (( pure )) char * +efi_tpl_name ( EFI_TPL tpl ); +extern const __attribute__ (( pure )) char * efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type ); extern const __attribute__ (( pure )) char * efi_open_attributes_name ( unsigned int attributes ); diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index 026adc25e..067899a72 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -46,6 +46,27 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); static EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *efidpt; EFI_REQUEST_PROTOCOL ( EFI_DEVICE_PATH_TO_TEXT_PROTOCOL, &efidpt ); +/** + * Name EFI TPL + * + * @v tpl Task priority level + * @ret text Task priority level as text + */ +const __attribute__ (( pure )) char * efi_tpl_name ( EFI_TPL tpl ) { + static char buf[ 19 /* "0xXXXXXXXXXXXXXXXX" + NUL */ ]; + + switch ( tpl ) { + case TPL_APPLICATION: return "Application"; + case TPL_CALLBACK: return "Callback"; + case TPL_NOTIFY: return "Notify"; + case TPL_HIGH_LEVEL: return "HighLevel"; + default: + snprintf ( buf, sizeof ( buf ), "%#lx", + ( unsigned long ) tpl ); + return buf; + } +} + /** * Name locate search type * diff --git a/src/interface/efi/efi_wrap.c b/src/interface/efi/efi_wrap.c index a806a7c60..8c3f41e3b 100644 --- a/src/interface/efi/efi_wrap.c +++ b/src/interface/efi/efi_wrap.c @@ -120,27 +120,6 @@ static const char * efi_boolean ( BOOLEAN boolean ) { return ( boolean ? "TRUE" : "FALSE" ); } -/** - * Convert EFI TPL to text - * - * @v tpl Task priority level - * @ret text Task priority level as text - */ -static const char * efi_tpl ( EFI_TPL tpl ) { - static char buf[ 19 /* "0xXXXXXXXXXXXXXXXX" + NUL */ ]; - - switch ( tpl ) { - case TPL_APPLICATION: return "Application"; - case TPL_CALLBACK: return "Callback"; - case TPL_NOTIFY: return "Notify"; - case TPL_HIGH_LEVEL: return "HighLevel"; - default: - snprintf ( buf, sizeof ( buf ), "%#lx", - ( unsigned long ) tpl ); - return buf; - } -} - /** * Convert EFI allocation type to text * @@ -281,9 +260,9 @@ efi_raise_tpl_wrapper ( EFI_TPL new_tpl ) { void *retaddr = __builtin_return_address ( 0 ); EFI_TPL old_tpl; - DBGCP ( colour, "RaiseTPL ( %s ) ", efi_tpl ( new_tpl ) ); + DBGCP ( colour, "RaiseTPL ( %s ) ", efi_tpl_name ( new_tpl ) ); old_tpl = bs->RaiseTPL ( new_tpl ); - DBGCP ( colour, "= %s -> %p\n", efi_tpl ( old_tpl ), retaddr ); + DBGCP ( colour, "= %s -> %p\n", efi_tpl_name ( old_tpl ), retaddr ); return old_tpl; } @@ -296,7 +275,7 @@ efi_restore_tpl_wrapper ( EFI_TPL old_tpl ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; void *retaddr = __builtin_return_address ( 0 ); - DBGCP ( colour, "RestoreTPL ( %s ) ", efi_tpl ( old_tpl ) ); + DBGCP ( colour, "RestoreTPL ( %s ) ", efi_tpl_name ( old_tpl ) ); bs->RestoreTPL ( old_tpl ); DBGCP ( colour, "-> %p\n", retaddr ); } @@ -433,8 +412,8 @@ efi_create_event_wrapper ( UINT32 type, EFI_TPL notify_tpl, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "CreateEvent ( %#x, %s, %p, %p ) ", - type, efi_tpl ( notify_tpl ), notify_function, notify_context ); + DBGC ( colour, "CreateEvent ( %#x, %s, %p, %p ) ", type, + efi_tpl_name ( notify_tpl ), notify_function, notify_context ); efirc = bs->CreateEvent ( type, notify_tpl, notify_function, notify_context, event ); DBGC ( colour, "= %s ( %p ) -> %p\n", @@ -1207,8 +1186,8 @@ efi_create_event_ex_wrapper ( UINT32 type, EFI_TPL notify_tpl, EFI_STATUS efirc; DBGC ( colour, "CreateEventEx ( %#x, %s, %p, %p, %s ) ", - type, efi_tpl ( notify_tpl ), notify_function, notify_context, - efi_guid_ntoa ( event_group ) ); + type, efi_tpl_name ( notify_tpl ), notify_function, + notify_context, efi_guid_ntoa ( event_group ) ); efirc = bs->CreateEventEx ( type, notify_tpl, notify_function, notify_context, event_group, event ); DBGC ( colour, "= %s ( %p ) -> %p\n", -- cgit v1.2.3-55-g7522