diff mbox

[U-Boot,41/48] efi: Add functions for decoding the EFI tables

Message ID 1437580180-6405-42-git-send-email-sjg@chromium.org
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass July 22, 2015, 3:49 p.m. UTC
The EFI stub can pass a table to U-Boot with information about the memory map
Potentially other things will follow. Add a way to access this table.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 lib/efi/Makefile   |  1 +
 lib/efi/efi_info.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
 create mode 100644 lib/efi/efi_info.c

Comments

Bin Meng July 24, 2015, 8:19 a.m. UTC | #1
Hi Simon,

On Wed, Jul 22, 2015 at 11:49 PM, Simon Glass <sjg@chromium.org> wrote:
> The EFI stub can pass a table to U-Boot with information about the memory map
> Potentially other things will follow. Add a way to access this table.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

But please see nits below.

>  lib/efi/Makefile   |  1 +
>  lib/efi/efi_info.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 48 insertions(+)
>  create mode 100644 lib/efi/efi_info.c
>
> diff --git a/lib/efi/Makefile b/lib/efi/Makefile
> index ba2824e..84bc5e3 100644
> --- a/lib/efi/Makefile
> +++ b/lib/efi/Makefile
> @@ -5,6 +5,7 @@
>  #
>
>  obj-$(CONFIG_ARCH_EFI) += efi_app.o efi.o
> +obj-$(CONFIG_EFI_STUB) += efi_info.o
>
>  CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \
>         $(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
> diff --git a/lib/efi/efi_info.c b/lib/efi/efi_info.c
> new file mode 100644
> index 0000000..0cd9a7e
> --- /dev/null
> +++ b/lib/efi/efi_info.c
> @@ -0,0 +1,47 @@
> +/*
> + * Copyright (c) 2015 Google, Inc
> + *
> + * SPDX-License-Identifier:    GPL-2.0+
> + *
> + * Access to the EFI information table
> + */
> +
> +#include <common.h>
> +#include <efi.h>
> +#include <errno.h>
> +#include <mapmem.h>
> +
> +int efi_info_get(enum efi_entry_t type, void **datap, int *sizep)
> +{
> +       struct efi_entry_hdr *entry;
> +       struct efi_info_hdr *info;
> +       int ret;
> +
> +       if (!gd->arch.table)
> +               return -ENODATA;
> +
> +       info = map_sysmem(gd->arch.table, 0);

Is map_sysmem() necessary? I think it only matters for sandbox. If
not, please remove.

> +       if (info->version != EFI_TABLE_VERSION) {
> +               ret = -EPROTONOSUPPORT;
> +               goto err;
> +       }
> +
> +       entry = (struct efi_entry_hdr *)((ulong)info + info->hdr_size);
> +       while (entry->type != EFIET_END) {
> +               if (entry->type == type) {
> +                       if (entry->addr)
> +                               *datap = map_sysmem(entry->addr, entry->size);
> +                       else
> +                               *datap = entry + 1;
> +                       *sizep = entry->size;
> +                       return 0;
> +               }
> +               entry = (struct efi_entry_hdr *)((ulong)entry + entry->link);
> +       }
> +
> +       ret = -ENOENT;
> +err:
> +       unmap_sysmem(info);
> +
> +       return ret;
> +}
> --

Regards,
Bin
Simon Glass July 31, 2015, 3:45 p.m. UTC | #2
Hi Bin,

On 24 July 2015 at 02:19, Bin Meng <bmeng.cn@gmail.com> wrote:
> Hi Simon,
>
> On Wed, Jul 22, 2015 at 11:49 PM, Simon Glass <sjg@chromium.org> wrote:
>> The EFI stub can pass a table to U-Boot with information about the memory map
>> Potentially other things will follow. Add a way to access this table.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
>
> But please see nits below.
>
>>  lib/efi/Makefile   |  1 +
>>  lib/efi/efi_info.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>>  2 files changed, 48 insertions(+)
>>  create mode 100644 lib/efi/efi_info.c
>>
>> diff --git a/lib/efi/Makefile b/lib/efi/Makefile
>> index ba2824e..84bc5e3 100644
>> --- a/lib/efi/Makefile
>> +++ b/lib/efi/Makefile
>> @@ -5,6 +5,7 @@
>>  #
>>
>>  obj-$(CONFIG_ARCH_EFI) += efi_app.o efi.o
>> +obj-$(CONFIG_EFI_STUB) += efi_info.o
>>
>>  CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \
>>         $(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
>> diff --git a/lib/efi/efi_info.c b/lib/efi/efi_info.c
>> new file mode 100644
>> index 0000000..0cd9a7e
>> --- /dev/null
>> +++ b/lib/efi/efi_info.c
>> @@ -0,0 +1,47 @@
>> +/*
>> + * Copyright (c) 2015 Google, Inc
>> + *
>> + * SPDX-License-Identifier:    GPL-2.0+
>> + *
>> + * Access to the EFI information table
>> + */
>> +
>> +#include <common.h>
>> +#include <efi.h>
>> +#include <errno.h>
>> +#include <mapmem.h>
>> +
>> +int efi_info_get(enum efi_entry_t type, void **datap, int *sizep)
>> +{
>> +       struct efi_entry_hdr *entry;
>> +       struct efi_info_hdr *info;
>> +       int ret;
>> +
>> +       if (!gd->arch.table)
>> +               return -ENODATA;
>> +
>> +       info = map_sysmem(gd->arch.table, 0);
>
> Is map_sysmem() necessary? I think it only matters for sandbox. If
> not, please remove.

That's true but I think it is good practice to use it most of the
time. It avoids a cast and I suspect we may consider adding a sandbox
EFI implementation in future.

>
>> +       if (info->version != EFI_TABLE_VERSION) {
>> +               ret = -EPROTONOSUPPORT;
>> +               goto err;
>> +       }
>> +
>> +       entry = (struct efi_entry_hdr *)((ulong)info + info->hdr_size);
>> +       while (entry->type != EFIET_END) {
>> +               if (entry->type == type) {
>> +                       if (entry->addr)
>> +                               *datap = map_sysmem(entry->addr, entry->size);
>> +                       else
>> +                               *datap = entry + 1;
>> +                       *sizep = entry->size;
>> +                       return 0;
>> +               }
>> +               entry = (struct efi_entry_hdr *)((ulong)entry + entry->link);
>> +       }
>> +
>> +       ret = -ENOENT;
>> +err:
>> +       unmap_sysmem(info);
>> +
>> +       return ret;
>> +}
>> --
>
> Regards,
> Bin

Regards,
Simon
diff mbox

Patch

diff --git a/lib/efi/Makefile b/lib/efi/Makefile
index ba2824e..84bc5e3 100644
--- a/lib/efi/Makefile
+++ b/lib/efi/Makefile
@@ -5,6 +5,7 @@ 
 #
 
 obj-$(CONFIG_ARCH_EFI) += efi_app.o efi.o
+obj-$(CONFIG_EFI_STUB) += efi_info.o
 
 CFLAGS_REMOVE_efi_stub.o := -mregparm=3 \
 	$(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32)
diff --git a/lib/efi/efi_info.c b/lib/efi/efi_info.c
new file mode 100644
index 0000000..0cd9a7e
--- /dev/null
+++ b/lib/efi/efi_info.c
@@ -0,0 +1,47 @@ 
+/*
+ * Copyright (c) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * Access to the EFI information table
+ */
+
+#include <common.h>
+#include <efi.h>
+#include <errno.h>
+#include <mapmem.h>
+
+int efi_info_get(enum efi_entry_t type, void **datap, int *sizep)
+{
+	struct efi_entry_hdr *entry;
+	struct efi_info_hdr *info;
+	int ret;
+
+	if (!gd->arch.table)
+		return -ENODATA;
+
+	info = map_sysmem(gd->arch.table, 0);
+	if (info->version != EFI_TABLE_VERSION) {
+		ret = -EPROTONOSUPPORT;
+		goto err;
+	}
+
+	entry = (struct efi_entry_hdr *)((ulong)info + info->hdr_size);
+	while (entry->type != EFIET_END) {
+		if (entry->type == type) {
+			if (entry->addr)
+				*datap = map_sysmem(entry->addr, entry->size);
+			else
+				*datap = entry + 1;
+			*sizep = entry->size;
+			return 0;
+		}
+		entry = (struct efi_entry_hdr *)((ulong)entry + entry->link);
+	}
+
+	ret = -ENOENT;
+err:
+	unmap_sysmem(info);
+
+	return ret;
+}