xref: /freebsd/stand/efi/include/efilib.h (revision cc426dd31990b8b50b210efc450e404596548ca1)
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 #include <stand.h>
34 #include <stdbool.h>
35 #include <sys/queue.h>
36 
37 extern EFI_HANDLE		IH;
38 extern EFI_SYSTEM_TABLE		*ST;
39 extern EFI_BOOT_SERVICES	*BS;
40 extern EFI_RUNTIME_SERVICES	*RS;
41 
42 extern struct devsw efipart_fddev;
43 extern struct devsw efipart_cddev;
44 extern struct devsw efipart_hddev;
45 extern struct devsw efinet_dev;
46 extern struct netif_driver efinetif;
47 
48 /* EFI block device data, included here to help efi_zfs_probe() */
49 typedef STAILQ_HEAD(pdinfo_list, pdinfo) pdinfo_list_t;
50 
51 typedef struct pdinfo
52 {
53 	STAILQ_ENTRY(pdinfo)	pd_link;	/* link in device list */
54 	pdinfo_list_t		pd_part;	/* list of partitions */
55 	EFI_HANDLE		pd_handle;
56 	EFI_HANDLE		pd_alias;
57 	EFI_DEVICE_PATH		*pd_devpath;
58 	EFI_BLOCK_IO		*pd_blkio;
59 	uint32_t		pd_unit;	/* unit number */
60 	uint32_t		pd_open;	/* reference counter */
61 	void			*pd_bcache;	/* buffer cache data */
62 	struct pdinfo		*pd_parent;	/* Linked items (eg partitions) */
63 	struct devsw		*pd_devsw;	/* Back pointer to devsw */
64 } pdinfo_t;
65 
66 pdinfo_list_t *efiblk_get_pdinfo_list(struct devsw *dev);
67 pdinfo_t *efiblk_get_pdinfo(struct devdesc *dev);
68 pdinfo_t *efiblk_get_pdinfo_by_handle(EFI_HANDLE h);
69 pdinfo_t *efiblk_get_pdinfo_by_device_path(EFI_DEVICE_PATH *path);
70 
71 void *efi_get_table(EFI_GUID *tbl);
72 
73 int efi_getdev(void **vdev, const char *devspec, const char **path);
74 char *efi_fmtdev(void *vdev);
75 int efi_setcurrdev(struct env_var *ev, int flags, const void *value);
76 
77 
78 int efi_register_handles(struct devsw *, EFI_HANDLE *, EFI_HANDLE *, int);
79 EFI_HANDLE efi_find_handle(struct devsw *, int);
80 int efi_handle_lookup(EFI_HANDLE, struct devsw **, int *,  uint64_t *);
81 int efi_handle_update_dev(EFI_HANDLE, struct devsw *, int, uint64_t);
82 
83 EFI_DEVICE_PATH *efi_lookup_image_devpath(EFI_HANDLE);
84 EFI_DEVICE_PATH *efi_lookup_devpath(EFI_HANDLE);
85 EFI_HANDLE efi_devpath_handle(EFI_DEVICE_PATH *);
86 EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *);
87 EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *);
88 bool efi_devpath_match(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
89 bool efi_devpath_match_node(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
90 bool efi_devpath_is_prefix(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
91 CHAR16 *efi_devpath_name(EFI_DEVICE_PATH *);
92 void efi_free_devpath_name(CHAR16 *);
93 EFI_DEVICE_PATH *efi_devpath_to_media_path(EFI_DEVICE_PATH *);
94 UINTN efi_devpath_length(EFI_DEVICE_PATH *);
95 
96 int efi_status_to_errno(EFI_STATUS);
97 EFI_STATUS errno_to_efi_status(int errno);
98 
99 void efi_time_init(void);
100 void efi_time_fini(void);
101 
102 EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab);
103 
104 EFI_STATUS main(int argc, CHAR16 *argv[]);
105 void efi_exit(EFI_STATUS status) __dead2;
106 void delay(int usecs);
107 
108 /* EFI environment initialization. */
109 void efi_init_environment(void);
110 
111 /* CHAR16 utility functions. */
112 int wcscmp(CHAR16 *, CHAR16 *);
113 void cpy8to16(const char *, CHAR16 *, size_t);
114 void cpy16to8(const CHAR16 *, char *, size_t);
115 
116 /*
117  * Routines for interacting with EFI's env vars in a more unix-like
118  * way than the standard APIs. In addition, convenience routines for
119  * the loader setting / getting FreeBSD specific variables.
120  */
121 
122 EFI_STATUS efi_freebsd_getenv(const char *v, void *data, __size_t *len);
123 EFI_STATUS efi_getenv(EFI_GUID *g, const char *v, void *data, __size_t *len);
124 EFI_STATUS efi_global_getenv(const char *v, void *data, __size_t *len);
125 EFI_STATUS efi_setenv_freebsd_wcs(const char *varname, CHAR16 *valstr);
126 
127 /* efipart.c */
128 int	efipart_inithandles(void);
129 
130 #endif	/* _LOADER_EFILIB_H */
131