Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 91e24e4 | 2015-08-04 12:33:58 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * |
Simon Glass | 91e24e4 | 2015-08-04 12:33:58 -0600 | [diff] [blame] | 5 | * Access to the EFI information table |
| 6 | */ |
| 7 | |
Simon Glass | 91e24e4 | 2015-08-04 12:33:58 -0600 | [diff] [blame] | 8 | #include <efi.h> |
| 9 | #include <errno.h> |
| 10 | #include <mapmem.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Simon Glass | 91e24e4 | 2015-08-04 12:33:58 -0600 | [diff] [blame] | 12 | |
| 13 | int efi_info_get(enum efi_entry_t type, void **datap, int *sizep) |
| 14 | { |
| 15 | struct efi_entry_hdr *entry; |
| 16 | struct efi_info_hdr *info; |
| 17 | int ret; |
| 18 | |
| 19 | if (!gd->arch.table) |
| 20 | return -ENODATA; |
| 21 | |
| 22 | info = map_sysmem(gd->arch.table, 0); |
| 23 | if (info->version != EFI_TABLE_VERSION) { |
| 24 | ret = -EPROTONOSUPPORT; |
| 25 | goto err; |
| 26 | } |
| 27 | |
| 28 | entry = (struct efi_entry_hdr *)((ulong)info + info->hdr_size); |
| 29 | while (entry->type != EFIET_END) { |
| 30 | if (entry->type == type) { |
| 31 | if (entry->addr) |
| 32 | *datap = map_sysmem(entry->addr, entry->size); |
| 33 | else |
| 34 | *datap = entry + 1; |
| 35 | *sizep = entry->size; |
| 36 | return 0; |
| 37 | } |
| 38 | entry = (struct efi_entry_hdr *)((ulong)entry + entry->link); |
| 39 | } |
| 40 | |
| 41 | ret = -ENOENT; |
| 42 | err: |
| 43 | unmap_sysmem(info); |
| 44 | |
| 45 | return ret; |
| 46 | } |