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