All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Jones <pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Peter Jones <pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 2/3] efi: add firmware version information to sysfs
Date: Tue,  6 Sep 2016 11:51:10 -0400	[thread overview]
Message-ID: <1473177071-11791-2-git-send-email-pjones@redhat.com> (raw)
In-Reply-To: <1473177071-11791-1-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

This adds the EFI Spec version from the system table to sysfs as
/sys/firmware/efi/spec_version .

Userland tools need this information in order to work around
specification deficiencies in 2.4 and earlier firmwares.  Specifically,
UEFI 2.4 and 2.5+ treat management of BootOrder very differently (See
UEFI 2.4 section 3.1.1 vs UEFI 2.5 section 3.1), which means on older
firmware we'll want to work around BDS's boot order management by adding
fwupdate entries to BootOrder.  We'd prefer not to do this on newer
firmware, as it is both non-sensical in terms of what it expresses, and
it results in more relatively failure prone flash writes.

Signed-off-by: Peter Jones <pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 Documentation/ABI/testing/sysfs-firmware-efi |  6 +++
 drivers/firmware/efi/efi.c                   | 66 ++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-firmware-efi b/Documentation/ABI/testing/sysfs-firmware-efi
index e794eac..4eec7c2 100644
--- a/Documentation/ABI/testing/sysfs-firmware-efi
+++ b/Documentation/ABI/testing/sysfs-firmware-efi
@@ -28,3 +28,9 @@ Description:	Displays the physical addresses of all EFI Configuration
 		versions are always printed first, i.e. ACPI20 comes
 		before ACPI.
 Users:		dmidecode
+
+What:		/sys/firmware/efi/spec_version
+Date:		August 2016
+Contact:	linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
+Description:	Displays the UEFI Specification revision the firmware claims to
+		be based upon.
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 5a2631a..c7cdd3f 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -141,11 +141,76 @@ static ssize_t fw_platform_size_show(struct kobject *kobj,
 	return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32);
 }
 
+static ssize_t spec_version_show(struct kobject *kobj,
+				 struct kobj_attribute *attr,
+				 char *buf)
+{
+	u16 major, minor;
+	ssize_t rc;
+
+	if (!buf)
+		return -EINVAL;
+
+	/* The spec says:
+	 *  The revision of the EFI Specification to which this table
+	 *  conforms. The upper 16 bits of this field contain the major
+	 *  revision value, and the lower 16 bits contain the minor revision
+	 *  value. The minor revision values are binary coded decimals and are
+	 *  limited to the range of 00..99.
+	 *
+	 *  When printed or displayed UEFI spec revision is referred as (Major
+	 *  revision).(Minor revision upper decimal).(Minor revision lower
+	 *  decimal) or (Major revision).(Minor revision upper decimal) in
+	 *  case Minor revision lower decimal is set to 0. For example:
+	 *
+	 *  A specification with the revision value ((2<<16) | (30)) would be
+	 *  referred as 2.3;
+	 *  A specification with the revision value ((2<<16) | (31)) would be
+	 *  referred as 2.3.1
+	 *
+	 * Then later it says:
+	 *  Related Definitions
+	 *   #define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
+	 *   #define EFI_2_40_SYSTEM_TABLE_REVISION ((2<<16) | (40))
+	 *   #define EFI_2_31_SYSTEM_TABLE_REVISION ((2<<16) | (31))
+	 *   #define EFI_2_30_SYSTEM_TABLE_REVISION ((2<<16) | (30))
+	 *   #define EFI_2_20_SYSTEM_TABLE_REVISION ((2<<16) | (20))
+	 *   #define EFI_2_10_SYSTEM_TABLE_REVISION ((2<<16) | (10))
+	 *   #define EFI_2_00_SYSTEM_TABLE_REVISION ((2<<16) | (00))
+	 *   #define EFI_1_10_SYSTEM_TABLE_REVISION ((1<<16) | (10))
+	 *   #define EFI_1_02_SYSTEM_TABLE_REVISION ((1<<16) | (02))
+	 *   #define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION
+	 *   #define EFI_SYSTEM_TABLE_REVISION EFI_2_40_SYSTEM_TABLE_REVISION
+	 *
+	 * (Apparently this bit of the spec failed to get updated for 2.5
+	 * and 2.6; UefiSpec.h in Tiano has been updated, though.)
+	 *
+	 * This of course does not match the description above at all, but it
+	 * does match the code in Tiano.  So we decode it Tiano's way.
+	 */
+	major = (efi.spec_version & 0xffff0000) >> 16;
+	minor = (efi.spec_version & 0x0000ffff);
+
+	if ((minor % 10) == 0)
+		rc = sprintf(buf, "%u.%u", major, minor / 10);
+	else
+		rc = sprintf(buf, "%u.%u.%u", major, minor / 10, minor % 10);
+
+	if (rc < 0) {
+		char *str;
+
+		str = strcpy(buf, "(unknown)");
+		return str - buf;
+	}
+	return rc;
+}
+
 static struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor);
 static struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime);
 static struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table);
 static struct kobj_attribute efi_attr_fw_platform_size =
 	__ATTR_RO(fw_platform_size);
+static struct kobj_attribute efi_attr_spec_version = __ATTR_RO(spec_version);
 
 static struct attribute *efi_subsys_attrs[] = {
 	&efi_attr_systab.attr,
@@ -153,6 +218,7 @@ static struct attribute *efi_subsys_attrs[] = {
 	&efi_attr_runtime.attr,
 	&efi_attr_config_table.attr,
 	&efi_attr_fw_platform_size.attr,
+	&efi_attr_spec_version.attr,
 	NULL,
 };
 
-- 
2.7.4

  parent reply	other threads:[~2016-09-06 15:51 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 16:13 [PATCH 1/2] efi: don't call the system table version the runtime services version Peter Jones
     [not found] ` <1471968832-19847-1-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-08-23 16:13   ` [PATCH 2/2] efi: add firmware version information to sysfs Peter Jones
     [not found]     ` <1471968832-19847-2-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-08-24 10:30       ` Lukas Wunner
     [not found]         ` <20160824103021.GA22888-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2016-09-02 18:57           ` Peter Jones
     [not found]             ` <20160902185758.GB9082-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-02 20:57               ` [PATCH 1/3] efi: don't call the system table version the runtime services version Peter Jones
     [not found]                 ` <1472849873-32041-1-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-02 20:57                   ` [PATCH 2/3] efi: add firmware version information to sysfs Peter Jones
     [not found]                     ` <1472849873-32041-2-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-05 12:00                       ` Lukas Wunner
     [not found]                         ` <20160905120006.GA27048-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2016-09-06 15:35                           ` Peter Jones
2016-09-06 15:51                           ` [PATCH 1/3] efi: don't call the system table version the runtime services version Peter Jones
     [not found]                             ` <1473177071-11791-1-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-06 15:51                               ` Peter Jones [this message]
     [not found]                                 ` <1473177071-11791-2-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-07 12:23                                   ` [PATCH 2/3] efi: add firmware version information to sysfs Lukas Wunner
     [not found]                                     ` <20160907122339.GB28333-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2016-09-07 14:56                                       ` [PATCH 1/3] efi: don't call the system table version the runtime services version Peter Jones
     [not found]                                         ` <1473260186-4500-1-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-07 14:56                                           ` [PATCH 2/3] efi: add firmware version information to sysfs Peter Jones
     [not found]                                             ` <1473260186-4500-2-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-13 13:24                                               ` Matt Fleming
2016-09-07 14:56                                           ` [PATCH 3/3] efi: Format EFI version prints the way the standard says Peter Jones
     [not found]                                             ` <1473260186-4500-3-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-15  9:18                                               ` Matt Fleming
     [not found]                                                 ` <20160915091822.GA16797-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-09-15 13:13                                                   ` Peter Jones
     [not found]                                                     ` <20160915131305.5mhdpc6vql5nv2gw-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-16  9:40                                                       ` Matt Fleming
     [not found]                                                         ` <20160916094006.GD16797-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-09-16 14:42                                                           ` Peter Jones
2016-09-13 12:32                                           ` [PATCH 1/3] efi: don't call the system table version the runtime services version Matt Fleming
2016-09-06 15:51                               ` [PATCH 3/3] efi: Format EFI version prints the way the standard says Peter Jones
     [not found]                                 ` <1473177071-11791-3-git-send-email-pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-09-07 12:21                                   ` Lukas Wunner
2016-09-02 20:57                   ` Peter Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473177071-11791-2-git-send-email-pjones@redhat.com \
    --to=pjones-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.