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