2 * Copyright (c) 2000 Doug Rabson
3 * Copyright (c) 2006 Marcel Moolenaar
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
28 #ifndef _LOADER_EFILIB_H
29 #define _LOADER_EFILIB_H
33 #include <sys/queue.h>
36 extern EFI_SYSTEM_TABLE
*ST
;
37 extern EFI_BOOT_SERVICES
*BS
;
38 extern EFI_RUNTIME_SERVICES
*RS
;
40 extern struct devsw efipart_fddev
;
41 extern struct devsw efipart_cddev
;
42 extern struct devsw efipart_hddev
;
43 extern struct devsw efinet_dev
;
44 extern struct netif_driver efinetif
;
46 /* EFI block device data, included here to help efi_zfs_probe() */
47 typedef STAILQ_HEAD(pdinfo_list
, pdinfo
) pdinfo_list_t
;
51 STAILQ_ENTRY(pdinfo
) pd_link
; /* link in device list */
52 pdinfo_list_t pd_part
; /* list of partitions */
55 EFI_DEVICE_PATH
*pd_devpath
;
56 EFI_BLOCK_IO
*pd_blkio
;
57 uint32_t pd_unit
; /* unit number */
58 uint32_t pd_open
; /* reference counter */
59 void *pd_bcache
; /* buffer cache data */
62 pdinfo_list_t
*efiblk_get_pdinfo_list(struct devsw
*dev
);
63 pdinfo_t
*efiblk_get_pdinfo(struct devdesc
*dev
);
65 void *efi_get_table(EFI_GUID
*tbl
);
67 int efi_getdev(void **, const char *, const char **);
68 char *efi_fmtdev(void *);
69 int efi_setcurrdev(struct env_var
*, int, const void *);
71 int efi_register_handles(struct devsw
*, EFI_HANDLE
*, EFI_HANDLE
*, int);
72 EFI_HANDLE
efi_find_handle(struct devsw
*, int);
73 int efi_handle_lookup(EFI_HANDLE
, struct devsw
**, int *, uint64_t *);
74 int efi_handle_update_dev(EFI_HANDLE
, struct devsw
*, int, uint64_t);
76 EFI_DEVICE_PATH
*efi_lookup_image_devpath(EFI_HANDLE
);
77 EFI_DEVICE_PATH
*efi_lookup_devpath(EFI_HANDLE
);
78 EFI_HANDLE
efi_devpath_handle(EFI_DEVICE_PATH
*);
79 EFI_DEVICE_PATH
*efi_devpath_last_node(EFI_DEVICE_PATH
*);
80 EFI_DEVICE_PATH
*efi_devpath_trim(EFI_DEVICE_PATH
*);
81 bool efi_devpath_match(EFI_DEVICE_PATH
*, EFI_DEVICE_PATH
*);
82 bool efi_devpath_is_prefix(EFI_DEVICE_PATH
*, EFI_DEVICE_PATH
*);
83 CHAR16
*efi_devpath_name(EFI_DEVICE_PATH
*);
84 void efi_free_devpath_name(CHAR16
*);
86 int efi_status_to_errno(EFI_STATUS
);
87 EFI_STATUS
errno_to_efi_status(int errno
);
89 void efi_time_init(void);
90 void efi_time_fini(void);
92 EFI_STATUS
efi_main(EFI_HANDLE Ximage
, EFI_SYSTEM_TABLE
* Xsystab
);
94 EFI_STATUS
main(int argc
, CHAR16
*argv
[]);
95 void efi_exit(EFI_STATUS status
) __dead2
;
96 void delay(int usecs
);
98 /* EFI environment initialization. */
99 void efi_init_environment(void);
101 /* EFI Memory type strings. */
102 const char *efi_memory_type(EFI_MEMORY_TYPE
);
104 /* CHAR16 utility functions. */
105 int wcscmp(CHAR16
*, CHAR16
*);
106 void cpy8to16(const char *, CHAR16
*, size_t);
107 void cpy16to8(const CHAR16
*, char *, size_t);
110 * Routines for interacting with EFI's env vars in a more unix-like
111 * way than the standard APIs. In addition, convenience routines for
112 * the loader setting / getting illumos specific variables.
115 EFI_STATUS
efi_illumos_getenv(const char *v
, void *data
, size_t *len
);
116 EFI_STATUS
efi_getenv(EFI_GUID
*g
, const char *v
, void *data
, size_t *len
);
117 EFI_STATUS
efi_global_getenv(const char *v
, void *data
, size_t *len
);
118 EFI_STATUS
efi_setenv_illumos_wcs(const char *varname
, CHAR16
*valstr
);
120 /* guids and names */
121 bool efi_guid_to_str(const EFI_GUID
*, char **);
122 bool efi_str_to_guid(const char *, EFI_GUID
*);
123 bool efi_name_to_guid(const char *, EFI_GUID
*);
124 bool efi_guid_to_name(EFI_GUID
*, char **);
127 int efipart_inithandles(void);
129 #endif /* _LOADER_EFILIB_H */