RTEMS 6.1-rc6
Loading...
Searching...
No Matches
efilib.h
1/*-
2 * Copyright (c) 2000 Doug Rabson
3 * Copyright (c) 2006 Marcel Moolenaar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30#ifndef _LOADER_EFILIB_H
31#define _LOADER_EFILIB_H
32
33#ifndef __rtems__
34#include <stand.h>
35#endif /* __rtems__ */
36#include <stdbool.h>
37#include <sys/queue.h>
38#ifdef __rtems__
39#include <errno.h>
40#include <stdbool.h>
41#include <stdlib.h>
42#endif /* __rtems__ */
43
44extern EFI_HANDLE IH;
45extern EFI_SYSTEM_TABLE *ST;
46extern EFI_BOOT_SERVICES *BS;
47extern EFI_RUNTIME_SERVICES *RS;
48
49#ifndef __rtems__
50
51extern struct devsw efipart_fddev;
52extern struct devsw efipart_cddev;
53extern struct devsw efipart_hddev;
54extern struct devsw efihttp_dev;
55extern struct devsw efinet_dev;
56extern struct netif_driver efinetif;
57
58/* EFI block device data, included here to help efi_zfs_probe() */
59typedef STAILQ_HEAD(pdinfo_list, pdinfo) pdinfo_list_t;
60
61typedef struct pdinfo
62{
63 STAILQ_ENTRY(pdinfo) pd_link; /* link in device list */
64 pdinfo_list_t pd_part; /* list of partitions */
65 EFI_HANDLE pd_handle;
66 EFI_HANDLE pd_alias;
67 EFI_DEVICE_PATH *pd_devpath;
68 EFI_BLOCK_IO *pd_blkio;
69 uint32_t pd_unit; /* unit number */
70 uint32_t pd_open; /* reference counter */
71 void *pd_bcache; /* buffer cache data */
72 struct pdinfo *pd_parent; /* Linked items (eg partitions) */
73 struct devsw *pd_devsw; /* Back pointer to devsw */
74} pdinfo_t;
75
76pdinfo_list_t *efiblk_get_pdinfo_list(struct devsw *dev);
77pdinfo_t *efiblk_get_pdinfo(struct devdesc *dev);
78pdinfo_t *efiblk_get_pdinfo_by_handle(EFI_HANDLE h);
79pdinfo_t *efiblk_get_pdinfo_by_device_path(EFI_DEVICE_PATH *path);
80
81/* libefi.c */
82void *efi_get_table(EFI_GUID *tbl);
83EFI_STATUS OpenProtocolByHandle(EFI_HANDLE, EFI_GUID *, void **);
84
85static inline EFI_STATUS
86efi_exit_boot_services(UINTN key)
87{
88 EFI_STATUS status;
89
90 status = BS->ExitBootServices(IH, key);
91 if (!EFI_ERROR(status))
92 boot_services_active = false;
93 return (status);
94}
95
96int efi_getdev(void **vdev, const char *devspec, const char **path);
97
98int efi_register_handles(struct devsw *, EFI_HANDLE *, EFI_HANDLE *, int);
99EFI_HANDLE efi_find_handle(struct devsw *, int);
100int efi_handle_lookup(EFI_HANDLE, struct devsw **, int *, uint64_t *);
101int efi_handle_update_dev(EFI_HANDLE, struct devsw *, int, uint64_t);
102
103EFI_DEVICE_PATH *efi_lookup_image_devpath(EFI_HANDLE);
104EFI_DEVICE_PATH *efi_lookup_devpath(EFI_HANDLE);
105void efi_close_devpath(EFI_HANDLE);
106EFI_HANDLE efi_devpath_handle(EFI_DEVICE_PATH *);
107EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *);
108EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *);
109bool efi_devpath_match(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
110bool efi_devpath_match_node(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
111bool efi_devpath_is_prefix(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
112CHAR16 *efi_devpath_name(EFI_DEVICE_PATH *);
113void efi_free_devpath_name(CHAR16 *);
114bool efi_devpath_same_disk(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
115EFI_DEVICE_PATH *efi_devpath_to_media_path(EFI_DEVICE_PATH *);
116UINTN efi_devpath_length(EFI_DEVICE_PATH *);
117EFI_DEVICE_PATH *efi_name_to_devpath(const char *path);
118EFI_DEVICE_PATH *efi_name_to_devpath16(CHAR16 *path);
119void efi_devpath_free(EFI_DEVICE_PATH *dp);
120EFI_HANDLE efi_devpath_to_handle(EFI_DEVICE_PATH *path, EFI_HANDLE *handles, unsigned nhandles);
121
122int efi_status_to_errno(EFI_STATUS);
123EFI_STATUS errno_to_efi_status(int errno);
124
125void efi_time_init(void);
126void efi_time_fini(void);
127
128int parse_uefi_con_out(void);
129EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab);
130
131EFI_STATUS main(int argc, CHAR16 *argv[]);
132void efi_exit(EFI_STATUS status) __dead2;
133
134/* EFI environment initialization. */
135void efi_init_environment(void);
136
137/* EFI Memory type strings. */
138const char *efi_memory_type(EFI_MEMORY_TYPE);
139#endif /* __rtems__ */
140
141/* CHAR16 utility functions. */
142int wcscmp(CHAR16 *, CHAR16 *);
143void cpy8to16(const char *, CHAR16 *, size_t);
144void cpy16to8(const CHAR16 *, char *, size_t);
145
146#ifndef __rtems__
147/*
148 * Routines for interacting with EFI's env vars in a more unix-like
149 * way than the standard APIs. In addition, convenience routines for
150 * the loader setting / getting FreeBSD specific variables.
151 */
152
153EFI_STATUS efi_delenv(EFI_GUID *guid, const char *varname);
154EFI_STATUS efi_freebsd_delenv(const char *varname);
155EFI_STATUS efi_freebsd_getenv(const char *v, void *data, __size_t *len);
156EFI_STATUS efi_getenv(EFI_GUID *g, const char *v, void *data, __size_t *len);
157EFI_STATUS efi_global_getenv(const char *v, void *data, __size_t *len);
158EFI_STATUS efi_setenv(EFI_GUID *guid, const char *varname, UINT32 attr, void *data, __size_t len);
159EFI_STATUS efi_setenv_freebsd_wcs(const char *varname, CHAR16 *valstr);
160
161/* guids and names */
162bool efi_guid_to_str(const EFI_GUID *, char **);
163bool efi_str_to_guid(const char *, EFI_GUID *);
164bool efi_name_to_guid(const char *, EFI_GUID *);
165bool efi_guid_to_name(EFI_GUID *, char **);
166
167/* efipart.c */
168int efipart_inithandles(void);
169
170#endif /* __rtems__ */
171
172#endif /* _LOADER_EFILIB_H */
Definition: efiapi.h:738
Definition: efidef.h:74
Definition: efiapi.h:694
Definition: efidevp.h:36
Definition: efiapi.h:903
Definition: flashPgmPvt.h:168
Definition: efilib.h:62