1
2
3
4
5
6
7
8
9
10
11#include <common.h>
12#include <debug_uart.h>
13#include <errno.h>
14#include <malloc.h>
15#include <linux/err.h>
16#include <linux/types.h>
17#include <efi.h>
18#include <efi_api.h>
19
20
21
22
23
24
25
26
27struct global_data *global_data_ptr = (struct global_data *)~0;
28
29
30
31
32
33
34static void efi_memset(void *ptr, int ch, int size)
35{
36 char *dest = ptr;
37
38 while (size-- > 0)
39 *dest++ = ch;
40}
41
42
43
44
45
46
47void efi_putc(struct efi_priv *priv, const char ch)
48{
49 struct efi_simple_text_output_protocol *con = priv->sys_table->con_out;
50 uint16_t ucode[2];
51
52 ucode[0] = ch;
53 ucode[1] = '\0';
54 con->output_string(con, ucode);
55}
56
57void efi_puts(struct efi_priv *priv, const char *str)
58{
59 while (*str)
60 efi_putc(priv, *str++);
61}
62
63int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
64 struct efi_system_table *sys_table)
65{
66 efi_guid_t loaded_image_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
67 struct efi_boot_services *boot = sys_table->boottime;
68 struct efi_loaded_image *loaded_image;
69 int ret;
70
71 efi_memset(priv, '\0', sizeof(*priv));
72 priv->sys_table = sys_table;
73 priv->boot = sys_table->boottime;
74 priv->parent_image = image;
75 priv->run = sys_table->runtime;
76
77 efi_puts(priv, "U-Boot EFI ");
78 efi_puts(priv, banner);
79 efi_putc(priv, ' ');
80
81 ret = boot->open_protocol(priv->parent_image, &loaded_image_guid,
82 (void **)&loaded_image, priv->parent_image,
83 NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
84 if (ret) {
85 efi_puts(priv, "Failed to get loaded image protocol\n");
86 return ret;
87 }
88 priv->image_data_type = loaded_image->image_data_type;
89
90 return 0;
91}
92
93void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp)
94{
95 struct efi_boot_services *boot = priv->boot;
96 void *buf = NULL;
97
98 *retp = boot->allocate_pool(priv->image_data_type, size, &buf);
99
100 return buf;
101}
102
103void efi_free(struct efi_priv *priv, void *ptr)
104{
105 struct efi_boot_services *boot = priv->boot;
106
107 boot->free_pool(ptr);
108}
109