|
|
f2c60e |
From c8218e9b3c38fcd36a2d06eec09952a0c6cee9e0 Mon Sep 17 00:00:00 2001
|
|
|
f2c60e |
From: Peter Jones <pjones@redhat.com>
|
|
|
f2c60e |
Date: Mon, 2 Oct 2017 18:22:13 -0400
|
|
|
f2c60e |
Subject: [PATCH 2/3] Add efi_status_to_str() and rework efi_status_to_err().
|
|
|
f2c60e |
|
|
|
f2c60e |
This adds efi_status_to_str() for use when printing efi_status_t
|
|
|
f2c60e |
messages, and reworks efi_status_to_err() so that the two use a common
|
|
|
f2c60e |
list of errors.
|
|
|
f2c60e |
|
|
|
f2c60e |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
f2c60e |
---
|
|
|
f2c60e |
include/linux/efi.h | 3 ++
|
|
|
f2c60e |
drivers/firmware/efi/efi.c | 122 ++++++++++++++++++++++++++++++++++-----------
|
|
|
f2c60e |
2 files changed, 95 insertions(+), 30 deletions(-)
|
|
|
f2c60e |
|
|
|
f2c60e |
diff --git a/include/linux/efi.h b/include/linux/efi.h
|
|
|
f2c60e |
index 18b16bf5ce1..436b3c93c3d 100644
|
|
|
f2c60e |
--- a/include/linux/efi.h
|
|
|
f2c60e |
+++ b/include/linux/efi.h
|
|
|
f2c60e |
@@ -42,6 +42,8 @@
|
|
|
f2c60e |
#define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG-1)))
|
|
|
f2c60e |
#define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1)))
|
|
|
f2c60e |
|
|
|
f2c60e |
+#define EFI_IS_ERROR(x) ((x) & (1UL << (BITS_PER_LONG-1)))
|
|
|
f2c60e |
+
|
|
|
f2c60e |
typedef unsigned long efi_status_t;
|
|
|
f2c60e |
typedef u8 efi_bool_t;
|
|
|
f2c60e |
typedef u16 efi_char16_t; /* UNICODE character */
|
|
|
f2c60e |
@@ -1183,6 +1185,7 @@ static inline void efi_set_secure_boot(enum efi_secureboot_mode mode) {}
|
|
|
f2c60e |
#endif
|
|
|
f2c60e |
|
|
|
f2c60e |
extern int efi_status_to_err(efi_status_t status);
|
|
|
f2c60e |
+extern const char *efi_status_to_str(efi_status_t status);
|
|
|
f2c60e |
|
|
|
f2c60e |
/*
|
|
|
f2c60e |
* Variable Attributes
|
|
|
f2c60e |
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
|
|
|
f2c60e |
index 557a47829d0..e8f9c7d84e9 100644
|
|
|
f2c60e |
--- a/drivers/firmware/efi/efi.c
|
|
|
f2c60e |
+++ b/drivers/firmware/efi/efi.c
|
|
|
f2c60e |
@@ -31,6 +31,7 @@
|
|
|
f2c60e |
#include <linux/acpi.h>
|
|
|
f2c60e |
#include <linux/ucs2_string.h>
|
|
|
f2c60e |
#include <linux/memblock.h>
|
|
|
f2c60e |
+#include <linux/bsearch.h>
|
|
|
f2c60e |
|
|
|
f2c60e |
#include <asm/early_ioremap.h>
|
|
|
f2c60e |
|
|
|
f2c60e |
@@ -865,40 +866,101 @@ int efi_mem_type(unsigned long phys_addr)
|
|
|
f2c60e |
}
|
|
|
f2c60e |
#endif
|
|
|
f2c60e |
|
|
|
f2c60e |
+struct efi_error_code {
|
|
|
f2c60e |
+ efi_status_t status;
|
|
|
f2c60e |
+ int errno;
|
|
|
f2c60e |
+ const char *description;
|
|
|
f2c60e |
+};
|
|
|
f2c60e |
+
|
|
|
f2c60e |
+static const struct efi_error_code efi_error_codes[] = {
|
|
|
f2c60e |
+ { EFI_SUCCESS, 0, "Success"},
|
|
|
f2c60e |
+#if 0
|
|
|
f2c60e |
+ { EFI_LOAD_ERROR, -EPICK_AN_ERRNO, "Load Error"},
|
|
|
f2c60e |
+#endif
|
|
|
f2c60e |
+ { EFI_INVALID_PARAMETER, -EINVAL, "Invalid Parameter"},
|
|
|
f2c60e |
+ { EFI_UNSUPPORTED, -ENOSYS, "Unsupported"},
|
|
|
f2c60e |
+ { EFI_BAD_BUFFER_SIZE, -ENOSPC, "Bad Buffer Size"},
|
|
|
f2c60e |
+ { EFI_BUFFER_TOO_SMALL, -ENOSPC, "Buffer Too Small"},
|
|
|
f2c60e |
+ { EFI_NOT_READY, -EAGAIN, "Not Ready"},
|
|
|
f2c60e |
+ { EFI_DEVICE_ERROR, -EIO, "Device Error"},
|
|
|
f2c60e |
+ { EFI_WRITE_PROTECTED, -EROFS, "Write Protected"},
|
|
|
f2c60e |
+ { EFI_OUT_OF_RESOURCES, -ENOMEM, "Out of Resources"},
|
|
|
f2c60e |
+#if 0
|
|
|
f2c60e |
+ { EFI_VOLUME_CORRUPTED, -EPICK_AN_ERRNO, "Volume Corrupt"},
|
|
|
f2c60e |
+ { EFI_VOLUME_FULL, -EPICK_AN_ERRNO, "Volume Full"},
|
|
|
f2c60e |
+ { EFI_NO_MEDIA, -EPICK_AN_ERRNO, "No Media"},
|
|
|
f2c60e |
+ { EFI_MEDIA_CHANGED, -EPICK_AN_ERRNO, "Media changed"},
|
|
|
f2c60e |
+#endif
|
|
|
f2c60e |
+ { EFI_NOT_FOUND, -ENOENT, "Not Found"},
|
|
|
f2c60e |
+#if 0
|
|
|
f2c60e |
+ { EFI_ACCESS_DENIED, -EPICK_AN_ERRNO, "Access Denied"},
|
|
|
f2c60e |
+ { EFI_NO_RESPONSE, -EPICK_AN_ERRNO, "No Response"},
|
|
|
f2c60e |
+ { EFI_NO_MAPPING, -EPICK_AN_ERRNO, "No mapping"},
|
|
|
f2c60e |
+ { EFI_TIMEOUT, -EPICK_AN_ERRNO, "Time out"},
|
|
|
f2c60e |
+ { EFI_NOT_STARTED, -EPICK_AN_ERRNO, "Not started"},
|
|
|
f2c60e |
+ { EFI_ALREADY_STARTED, -EPICK_AN_ERRNO, "Already started"},
|
|
|
f2c60e |
+#endif
|
|
|
f2c60e |
+ { EFI_ABORTED, -EINTR, "Aborted"},
|
|
|
f2c60e |
+#if 0
|
|
|
f2c60e |
+ { EFI_ICMP_ERROR, -EPICK_AN_ERRNO, "ICMP Error"},
|
|
|
f2c60e |
+ { EFI_TFTP_ERROR, -EPICK_AN_ERRNO, "TFTP Error"},
|
|
|
f2c60e |
+ { EFI_PROTOCOL_ERROR, -EPICK_AN_ERRNO, "Protocol Error"},
|
|
|
f2c60e |
+ { EFI_INCOMPATIBLE_VERSION, -EPICK_AN_ERRNO, "Incompatible Version"},
|
|
|
f2c60e |
+#endif
|
|
|
f2c60e |
+ { EFI_SECURITY_VIOLATION, -EACCES, "Security Policy Violation"},
|
|
|
f2c60e |
+#if 0
|
|
|
f2c60e |
+ { EFI_CRC_ERROR, -EPICK_AN_ERRNO, "CRC Error"},
|
|
|
f2c60e |
+ { EFI_END_OF_MEDIA, -EPICK_AN_ERRNO, "End of Media"},
|
|
|
f2c60e |
+ { EFI_END_OF_FILE, -EPICK_AN_ERRNO, "End of File"},
|
|
|
f2c60e |
+ { EFI_INVALID_LANGUAGE, -EPICK_AN_ERRNO, "Invalid Languages"},
|
|
|
f2c60e |
+ { EFI_COMPROMISED_DATA, -EPICK_AN_ERRNO, "Compromised Data"},
|
|
|
f2c60e |
+
|
|
|
f2c60e |
+ // warnings
|
|
|
f2c60e |
+ { EFI_WARN_UNKOWN_GLYPH, -EPICK_AN_ERRNO, "Warning Unknown Glyph"},
|
|
|
f2c60e |
+ { EFI_WARN_DELETE_FAILURE, -EPICK_AN_ERRNO, "Warning Delete Failure"},
|
|
|
f2c60e |
+ { EFI_WARN_WRITE_FAILURE, -EPICK_AN_ERRNO, "Warning Write Failure"},
|
|
|
f2c60e |
+ { EFI_WARN_BUFFER_TOO_SMALL, -EPICK_AN_ERRNO, "Warning Buffer Too Small"},
|
|
|
f2c60e |
+#endif
|
|
|
f2c60e |
+};
|
|
|
f2c60e |
+
|
|
|
f2c60e |
+static int
|
|
|
f2c60e |
+efi_status_cmp_bsearch(const void *key, const void *item)
|
|
|
f2c60e |
+{
|
|
|
f2c60e |
+ u64 status = (u64)(uintptr_t)key;
|
|
|
f2c60e |
+ struct efi_error_code *code = (struct efi_error_code *)item;
|
|
|
f2c60e |
+
|
|
|
f2c60e |
+ if (status < code->status)
|
|
|
f2c60e |
+ return -1;
|
|
|
f2c60e |
+ if (status > code->status)
|
|
|
f2c60e |
+ return 1;
|
|
|
f2c60e |
+ return 0;
|
|
|
f2c60e |
+}
|
|
|
f2c60e |
+
|
|
|
f2c60e |
int efi_status_to_err(efi_status_t status)
|
|
|
f2c60e |
{
|
|
|
f2c60e |
- int err;
|
|
|
f2c60e |
+ struct efi_error_code *found;
|
|
|
f2c60e |
+ size_t num = sizeof(efi_error_codes) / sizeof(struct efi_error_code);
|
|
|
f2c60e |
|
|
|
f2c60e |
- switch (status) {
|
|
|
f2c60e |
- case EFI_SUCCESS:
|
|
|
f2c60e |
- err = 0;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- case EFI_INVALID_PARAMETER:
|
|
|
f2c60e |
- err = -EINVAL;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- case EFI_OUT_OF_RESOURCES:
|
|
|
f2c60e |
- err = -ENOSPC;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- case EFI_DEVICE_ERROR:
|
|
|
f2c60e |
- err = -EIO;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- case EFI_WRITE_PROTECTED:
|
|
|
f2c60e |
- err = -EROFS;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- case EFI_SECURITY_VIOLATION:
|
|
|
f2c60e |
- err = -EACCES;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- case EFI_NOT_FOUND:
|
|
|
f2c60e |
- err = -ENOENT;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- case EFI_ABORTED:
|
|
|
f2c60e |
- err = -EINTR;
|
|
|
f2c60e |
- break;
|
|
|
f2c60e |
- default:
|
|
|
f2c60e |
- err = -EINVAL;
|
|
|
f2c60e |
- }
|
|
|
f2c60e |
+ found = bsearch((void *)(uintptr_t)status, efi_error_codes,
|
|
|
f2c60e |
+ sizeof(struct efi_error_code), num,
|
|
|
f2c60e |
+ efi_status_cmp_bsearch);
|
|
|
f2c60e |
+ if (!found)
|
|
|
f2c60e |
+ return -EINVAL;
|
|
|
f2c60e |
+ return found->errno;
|
|
|
f2c60e |
+}
|
|
|
f2c60e |
|
|
|
f2c60e |
- return err;
|
|
|
f2c60e |
+const char *
|
|
|
f2c60e |
+efi_status_to_str(efi_status_t status)
|
|
|
f2c60e |
+{
|
|
|
f2c60e |
+ struct efi_error_code *found;
|
|
|
f2c60e |
+ size_t num = sizeof(efi_error_codes) / sizeof(struct efi_error_code);
|
|
|
f2c60e |
+
|
|
|
f2c60e |
+ found = bsearch((void *)(uintptr_t)status, efi_error_codes,
|
|
|
f2c60e |
+ sizeof(struct efi_error_code), num,
|
|
|
f2c60e |
+ efi_status_cmp_bsearch);
|
|
|
f2c60e |
+ if (!found)
|
|
|
f2c60e |
+ return "Unknown error code";
|
|
|
f2c60e |
+ return found->description;
|
|
|
f2c60e |
}
|
|
|
f2c60e |
|
|
|
f2c60e |
bool efi_is_table_address(unsigned long phys_addr)
|
|
|
f2c60e |
--
|
|
|
f2c60e |
2.15.0
|
|
|
f2c60e |
|