efi.h revision 1.6 1 1.6 nonaka /* $NetBSD: efi.h,v 1.6 2017/02/23 12:17:36 nonaka Exp $ */
2 1.1 christos
3 1.1 christos /*-
4 1.1 christos * Copyright (c) 2004 Marcel Moolenaar
5 1.1 christos * All rights reserved.
6 1.1 christos *
7 1.1 christos * Redistribution and use in source and binary forms, with or without
8 1.1 christos * modification, are permitted provided that the following conditions
9 1.1 christos * are met:
10 1.1 christos *
11 1.1 christos * 1. Redistributions of source code must retain the above copyright
12 1.1 christos * notice, this list of conditions and the following disclaimer.
13 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 christos * notice, this list of conditions and the following disclaimer in the
15 1.1 christos * documentation and/or other materials provided with the distribution.
16 1.1 christos *
17 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 christos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1 christos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 christos *
28 1.1 christos * $FreeBSD$
29 1.1 christos */
30 1.1 christos
31 1.1 christos /* This file is mainly ia64/include/efi.h with little modifications. */
32 1.1 christos
33 1.1 christos #ifndef _X86_EFI_H_
34 1.1 christos #define _X86_EFI_H_
35 1.1 christos
36 1.1 christos #include <sys/uuid.h>
37 1.1 christos
38 1.1 christos #define EFI_PAGE_SHIFT 12
39 1.1 christos #define EFI_PAGE_SIZE (1 << EFI_PAGE_SHIFT)
40 1.1 christos #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
41 1.1 christos
42 1.1 christos extern const struct uuid EFI_UUID_ACPI20;
43 1.1 christos extern const struct uuid EFI_UUID_ACPI10;
44 1.1 christos
45 1.1 christos enum efi_reset {
46 1.1 christos EFI_RESET_COLD,
47 1.1 christos EFI_RESET_WARM
48 1.1 christos };
49 1.1 christos
50 1.1 christos typedef uint16_t efi_char;
51 1.1 christos typedef unsigned long efi_status;
52 1.1 christos
53 1.1 christos struct efi_cfgtbl {
54 1.1 christos struct uuid ct_uuid;
55 1.2 nonaka void *ct_data;
56 1.1 christos };
57 1.6 nonaka
58 1.1 christos struct efi_md {
59 1.1 christos uint32_t md_type;
60 1.1 christos #define EFI_MD_TYPE_NULL 0
61 1.1 christos #define EFI_MD_TYPE_CODE 1 /* Loader text. */
62 1.1 christos #define EFI_MD_TYPE_DATA 2 /* Loader data. */
63 1.1 christos #define EFI_MD_TYPE_BS_CODE 3 /* Boot services text. */
64 1.1 christos #define EFI_MD_TYPE_BS_DATA 4 /* Boot services data. */
65 1.1 christos #define EFI_MD_TYPE_RT_CODE 5 /* Runtime services text. */
66 1.1 christos #define EFI_MD_TYPE_RT_DATA 6 /* Runtime services data. */
67 1.1 christos #define EFI_MD_TYPE_FREE 7 /* Unused/free memory. */
68 1.1 christos #define EFI_MD_TYPE_BAD 8 /* Bad memory */
69 1.1 christos #define EFI_MD_TYPE_RECLAIM 9 /* ACPI reclaimable memory. */
70 1.1 christos #define EFI_MD_TYPE_FIRMWARE 10 /* ACPI NV memory */
71 1.1 christos #define EFI_MD_TYPE_IOMEM 11 /* Memory-mapped I/O. */
72 1.1 christos #define EFI_MD_TYPE_IOPORT 12 /* I/O port space. */
73 1.1 christos #define EFI_MD_TYPE_PALCODE 13 /* PAL */
74 1.5 nonaka #define EFI_MD_TYPE_PMEM 14 /* Persistent memory. */
75 1.1 christos uint32_t __pad;
76 1.1 christos uint64_t md_phys;
77 1.3 nonaka uint64_t md_virt;
78 1.1 christos uint64_t md_pages;
79 1.1 christos uint64_t md_attr;
80 1.1 christos #define EFI_MD_ATTR_UC 0x0000000000000001UL
81 1.1 christos #define EFI_MD_ATTR_WC 0x0000000000000002UL
82 1.1 christos #define EFI_MD_ATTR_WT 0x0000000000000004UL
83 1.1 christos #define EFI_MD_ATTR_WB 0x0000000000000008UL
84 1.1 christos #define EFI_MD_ATTR_UCE 0x0000000000000010UL
85 1.1 christos #define EFI_MD_ATTR_WP 0x0000000000001000UL
86 1.1 christos #define EFI_MD_ATTR_RP 0x0000000000002000UL
87 1.1 christos #define EFI_MD_ATTR_XP 0x0000000000004000UL
88 1.1 christos #define EFI_MD_ATTR_RT 0x8000000000000000UL
89 1.1 christos };
90 1.1 christos
91 1.1 christos struct efi_tm {
92 1.1 christos uint16_t tm_year; /* 1998 - 20XX */
93 1.1 christos uint8_t tm_mon; /* 1 - 12 */
94 1.1 christos uint8_t tm_mday; /* 1 - 31 */
95 1.1 christos uint8_t tm_hour; /* 0 - 23 */
96 1.1 christos uint8_t tm_min; /* 0 - 59 */
97 1.1 christos uint8_t tm_sec; /* 0 - 59 */
98 1.1 christos uint8_t __pad1;
99 1.1 christos uint32_t tm_nsec; /* 0 - 999,999,999 */
100 1.1 christos int16_t tm_tz; /* -1440 to 1440 or 2047 */
101 1.1 christos uint8_t tm_dst;
102 1.1 christos uint8_t __pad2;
103 1.1 christos };
104 1.1 christos
105 1.1 christos struct efi_tmcap {
106 1.1 christos uint32_t tc_res; /* 1e-6 parts per million */
107 1.1 christos uint32_t tc_prec; /* hertz */
108 1.1 christos uint8_t tc_stz; /* Set clears sub-second time */
109 1.1 christos };
110 1.1 christos
111 1.1 christos struct efi_tblhdr {
112 1.1 christos uint64_t th_sig;
113 1.1 christos uint32_t th_rev;
114 1.1 christos uint32_t th_hdrsz;
115 1.1 christos uint32_t th_crc32;
116 1.1 christos uint32_t __res;
117 1.1 christos };
118 1.1 christos
119 1.1 christos struct efi_rt {
120 1.1 christos struct efi_tblhdr rt_hdr;
121 1.1 christos efi_status (*rt_gettime)(struct efi_tm *, struct efi_tmcap *);
122 1.1 christos efi_status (*rt_settime)(struct efi_tm *);
123 1.1 christos efi_status (*rt_getwaketime)(uint8_t *, uint8_t *,
124 1.1 christos struct efi_tm *);
125 1.1 christos efi_status (*rt_setwaketime)(uint8_t, struct efi_tm *);
126 1.1 christos efi_status (*rt_setvirtual)(u_long, u_long, uint32_t,
127 1.1 christos struct efi_md *);
128 1.1 christos efi_status (*rt_cvtptr)(u_long, void **);
129 1.1 christos efi_status (*rt_getvar)(efi_char *, struct uuid *, uint32_t *,
130 1.1 christos u_long *, void *);
131 1.1 christos efi_status (*rt_scanvar)(u_long *, efi_char *, struct uuid *);
132 1.1 christos efi_status (*rt_setvar)(efi_char *, struct uuid *, uint32_t,
133 1.1 christos u_long, void *);
134 1.1 christos efi_status (*rt_gethicnt)(uint32_t *);
135 1.1 christos efi_status (*rt_reset)(enum efi_reset, efi_status, u_long,
136 1.1 christos efi_char *);
137 1.1 christos };
138 1.1 christos
139 1.1 christos struct efi_systbl {
140 1.1 christos struct efi_tblhdr st_hdr;
141 1.1 christos #define EFI_SYSTBL_SIG 0x5453595320494249UL
142 1.1 christos efi_char *st_fwvendor;
143 1.1 christos uint32_t st_fwrev;
144 1.2 nonaka #ifdef __amd64__
145 1.1 christos uint32_t __pad;
146 1.2 nonaka #endif
147 1.1 christos void *st_cin;
148 1.1 christos void *st_cinif;
149 1.1 christos void *st_cout;
150 1.1 christos void *st_coutif;
151 1.1 christos void *st_cerr;
152 1.1 christos void *st_cerrif;
153 1.2 nonaka struct efi_rt *st_rt;
154 1.1 christos void *st_bs;
155 1.1 christos u_long st_entries;
156 1.2 nonaka struct efi_cfgtbl *st_cfgtbl;
157 1.1 christos };
158 1.1 christos
159 1.6 nonaka #if defined(__amd64__)
160 1.6 nonaka struct efi_cfgtbl32 {
161 1.6 nonaka struct uuid ct_uuid;
162 1.6 nonaka uint32_t ct_data; /* void * */
163 1.6 nonaka };
164 1.6 nonaka
165 1.6 nonaka struct efi_systbl32 {
166 1.6 nonaka struct efi_tblhdr st_hdr;
167 1.6 nonaka
168 1.6 nonaka uint32_t st_fwvendor;
169 1.6 nonaka uint32_t st_fwrev;
170 1.6 nonaka uint32_t st_cin; /* = 0 */
171 1.6 nonaka uint32_t st_cinif; /* = 0 */
172 1.6 nonaka uint32_t st_cout; /* = 0 */
173 1.6 nonaka uint32_t st_coutif; /* = 0 */
174 1.6 nonaka uint32_t st_cerr; /* = 0 */
175 1.6 nonaka uint32_t st_cerrif; /* = 0 */
176 1.6 nonaka uint32_t st_rt; /* struct efi_rt32 * */
177 1.6 nonaka uint32_t st_bs; /* = 0 */
178 1.6 nonaka uint32_t st_entries;
179 1.6 nonaka uint32_t st_cfgtbl; /* struct efi_cfgtbl32 * */
180 1.6 nonaka };
181 1.6 nonaka #elif defined(__i386__)
182 1.6 nonaka struct efi_cfgtbl64 {
183 1.6 nonaka struct uuid ct_uuid;
184 1.6 nonaka uint64_t ct_data; /* void * */
185 1.6 nonaka };
186 1.6 nonaka
187 1.6 nonaka struct efi_systbl64 {
188 1.6 nonaka struct efi_tblhdr st_hdr;
189 1.6 nonaka
190 1.6 nonaka uint64_t st_fwvendor;
191 1.6 nonaka uint32_t st_fwrev;
192 1.6 nonaka uint32_t __pad;
193 1.6 nonaka uint64_t st_cin; /* = 0 */
194 1.6 nonaka uint64_t st_cinif; /* = 0 */
195 1.6 nonaka uint64_t st_cout; /* = 0 */
196 1.6 nonaka uint64_t st_coutif; /* = 0 */
197 1.6 nonaka uint64_t st_cerr; /* = 0 */
198 1.6 nonaka uint64_t st_cerrif; /* = 0 */
199 1.6 nonaka uint64_t st_rt; /* struct efi_rt64 * */
200 1.6 nonaka uint64_t st_bs; /* = 0 */
201 1.6 nonaka uint64_t st_entries;
202 1.6 nonaka uint64_t st_cfgtbl; /* struct efi_cfgtbl64 * */
203 1.6 nonaka };
204 1.6 nonaka #endif
205 1.6 nonaka
206 1.1 christos bool efi_probe(void);
207 1.1 christos paddr_t efi_getsystblpa(void);
208 1.1 christos struct efi_systbl *efi_getsystbl(void);
209 1.1 christos paddr_t efi_getcfgtblpa(const struct uuid*);
210 1.1 christos void *efi_getcfgtbl(const struct uuid*);
211 1.2 nonaka int efi_getbiosmemtype(uint32_t, uint64_t);
212 1.2 nonaka const char *efi_getmemtype_str(uint32_t);
213 1.4 nonaka struct btinfo_memmap;
214 1.4 nonaka struct btinfo_memmap *efi_get_e820memmap(void);
215 1.4 nonaka
216 1.1 christos /*
217 1.1 christos void efi_boot_finish(void);
218 1.1 christos int efi_boot_minimal(uint64_t);
219 1.1 christos void *efi_get_table(struct uuid *);
220 1.1 christos void efi_get_time(struct efi_tm *);
221 1.1 christos struct efi_md *efi_md_first(void);
222 1.1 christos struct efi_md *efi_md_next(struct efi_md *);
223 1.1 christos void efi_reset_system(void);
224 1.1 christos efi_status efi_set_time(struct efi_tm *);
225 1.1 christos */
226 1.1 christos
227 1.1 christos #endif /* _X86_EFI_H_ */
228