1 /* $NetBSD: efi.h,v 1.15 2022/08/20 10:55:27 riastradh 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 #ifndef _X86_EFI_H_ 32 #define _X86_EFI_H_ 33 34 #include <sys/uuid.h> 35 36 #include <dev/efi/efi.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 51 extern const struct uuid EFI_UUID_ACPI20; 52 extern const struct uuid EFI_UUID_ACPI10; 53 extern const struct uuid EFI_UUID_SMBIOS; 54 extern const struct uuid EFI_UUID_SMBIOS3; 55 56 extern bool bootmethod_efi; 57 58 #if defined(__amd64__) 59 typedef uint64_t uintn; 60 #elif defined(__i386__) 61 typedef uint32_t uintn; 62 #endif 63 64 typedef uintn efi_tpl; 65 typedef void *efi_event; 66 typedef void (*efi_event_notify)(efi_event, void *); 67 typedef void *efi_handle; 68 typedef struct { 69 uint8_t type; 70 uint8_t subtype; 71 uint8_t ldnegth[2]; 72 } efi_device_path; 73 74 struct efi_bs { 75 struct efi_tblhdr bs_hdr; 76 #define EFI_BS_SIG 0x56524553544f4f42UL 77 efi_tpl (*bs_raisetpl)(efi_tpl); 78 void (*bs_restoretpl)(efi_tpl); 79 efi_status (*bs_allocatepages)(uint32_t, uint32_t, 80 uintn, paddr_t *); 81 efi_status (*bs_freepages)(paddr_t, uintn); 82 efi_status (*bs_getmemorymap)(uintn *, struct efi_md *, 83 uintn *, uintn *, uint32_t *); 84 efi_status (*bs_allocatepool)(uint32_t, uintn, void **); 85 efi_status (*bs_freepool)(void *); 86 efi_status (*bs_createevent)(uint32_t, efi_tpl, efi_event_notify, 87 void *, efi_event *); 88 efi_status (*bs_settimer)(efi_event, uint32_t, uint64_t); 89 efi_status (*bs_waitforevent)(uintn, efi_event *, uintn *); 90 efi_status (*bs_signalevent)(efi_event); 91 efi_status (*bs_closeevent)(efi_event); 92 efi_status (*bs_checkevent)(efi_event); 93 efi_status (*bs_installprotocolinterface)(efi_handle *, 94 struct uuid *, uint32_t, void *); 95 efi_status (*bs_reinstallprotocolinterface)(efi_handle *, 96 struct uuid *, void *, void *); 97 efi_status (*bs_uninstallprotocolinterface)(efi_handle *, 98 struct uuid *, void *); 99 efi_status (*bs_handleprotocol)(efi_handle, 100 struct uuid *, void **); 101 efi_status (*bs_pchandleprotocol)(efi_handle, 102 struct uuid *, void **); 103 efi_status (*bs_registerprotocolnotify)(struct uuid *, efi_event, 104 void **); 105 efi_status (*bs_locatehandle)(uint32_t, struct uuid *, void *, 106 uintn *, efi_handle *); 107 efi_status (*bs_locatedevicepath)(struct uuid *, efi_device_path **, 108 efi_handle *); 109 efi_status (*bs_installconfigurationtable)(struct uuid *, void *); 110 efi_status (*bs_loadimage)(uint8_t, efi_handle, efi_device_path *, 111 void *, uintn, efi_handle *); 112 efi_status (*bs_startimage)(efi_handle, uintn *, efi_char **); 113 efi_status (*bs_exit)(efi_handle, efi_status, uintn, efi_char *); 114 efi_status (*bs_unloadimage)(efi_handle); 115 efi_status (*bs_exitbootservices)(efi_handle, uintn); 116 efi_status (*bs_getnextmonotoniccount)(uint64_t *); 117 efi_status (*bs_stall)(uintn); 118 efi_status (*bs_setwatchdogtimer)(uintn, uint64_t, 119 uintn, efi_char *); 120 efi_status (*bs_connectcontroller)(efi_handle, efi_handle *, 121 efi_device_path *, uint8_t); 122 efi_status (*bs_disconnectcontroller)(efi_handle, efi_handle, 123 efi_handle); 124 efi_status (*bs_openprotocol)(efi_handle, struct uuid *, void **, 125 efi_handle, efi_handle, uint32_t); 126 efi_status (*bs_closeprotocol)(efi_handle, struct uuid *, 127 efi_handle, efi_handle); 128 efi_status (*bs_openprotocolinformation)(efi_handle, efi_handle, 129 uint32_t, uint32_t); 130 efi_status (*bs_protocolsperhandle)(efi_handle, 131 struct uuid ***, uintn *); 132 efi_status (*bs_locatehandlebuffer)(uint32_t, struct uuid *, 133 void *, uintn *, efi_handle **); 134 efi_status (*bs_locateprotocol)(struct uuid *, void *, void **); 135 efi_status (*bs_installmultipleprotocolinterfaces)(efi_handle *, 136 ...); 137 efi_status (*bs_uninstallmultipleprotocolinterfaces)(efi_handle, 138 ...); 139 efi_status (*bs_calculatecrc32)(void *, uintn, uint32_t *); 140 efi_status (*bs_copymem)(void *, void *, uintn); 141 efi_status (*bs_setmem)(void *, uintn, uint8_t); 142 efi_status (*bs_createeventex)(uint32_t, efi_tpl, 143 efi_event_notify, void *, struct uuid, efi_event *); 144 }; 145 146 struct efi_input; 147 148 struct efi_key { 149 uint16_t scancode; 150 efi_char unicodechar; 151 }; 152 153 struct efi_input { 154 efi_status (*ei_reset)(struct efi_input *, uint8_t); 155 efi_status (*ei_readkeystroke)(struct efi_input *, 156 struct efi_key *); 157 void *ei_waitforkey; 158 }; 159 160 typedef struct efi_input efi_input; 161 162 struct efi_text_output_mode { 163 int32_t maxmode; 164 int32_t mode; 165 int32_t attribute; 166 int32_t cursorcolumn; 167 int32_t cursorrow; 168 uint8_t cursorvisible; 169 }; 170 171 172 struct efi_output; 173 174 struct efi_output { 175 efi_status (*ei_reset)(struct efi_output *, uint8_t); 176 efi_status (*ei_outputstring)(struct efi_output *, efi_char *); 177 efi_status (*ei_teststring)(struct efi_output *, efi_char *); 178 efi_status (*ei_textquerymode)(struct efi_output *, 179 uintn, uintn *, uintn *); 180 efi_status (*ei_textsetmode)(struct efi_output *, uintn); 181 efi_status (*ei_setattribute)(struct efi_output *, uintn); 182 efi_status (*ei_clearscreen)(struct efi_output *); 183 efi_status (*ei_setcursorposition)(struct efi_output *, 184 uintn, uintn); 185 efi_status (*ei_enablecursor)(struct efi_output *, uint8_t); 186 struct efi_text_output_mode *ei_mode; 187 }; 188 189 typedef struct efi_output efi_output; 190 191 #if defined(__amd64__) 192 struct efi_cfgtbl32 { 193 struct uuid ct_uuid; 194 uint32_t ct_data; /* void * */ 195 }; 196 197 struct efi_systbl32 { 198 struct efi_tblhdr st_hdr; 199 200 uint32_t st_fwvendor; 201 uint32_t st_fwrev; 202 uint32_t st_cin; /* = 0 */ 203 uint32_t st_cinif; /* = 0 */ 204 uint32_t st_cout; /* = 0 */ 205 uint32_t st_coutif; /* = 0 */ 206 uint32_t st_cerr; /* = 0 */ 207 uint32_t st_cerrif; /* = 0 */ 208 uint32_t st_rt; /* struct efi_rt32 * */ 209 uint32_t st_bs; /* = 0 */ 210 uint32_t st_entries; 211 uint32_t st_cfgtbl; /* struct efi_cfgtbl32 * */ 212 }; 213 #elif defined(__i386__) 214 struct efi_cfgtbl64 { 215 struct uuid ct_uuid; 216 uint64_t ct_data; /* void * */ 217 }; 218 219 struct efi_systbl64 { 220 struct efi_tblhdr st_hdr; 221 222 uint64_t st_fwvendor; 223 uint32_t st_fwrev; 224 uint32_t __pad; 225 uint64_t st_cin; /* = 0 */ 226 uint64_t st_cinif; /* = 0 */ 227 uint64_t st_cout; /* = 0 */ 228 uint64_t st_coutif; /* = 0 */ 229 uint64_t st_cerr; /* = 0 */ 230 uint64_t st_cerrif; /* = 0 */ 231 uint64_t st_rt; /* struct efi_rt64 * */ 232 uint64_t st_bs; /* = 0 */ 233 uint64_t st_entries; 234 uint64_t st_cfgtbl; /* struct efi_cfgtbl64 * */ 235 }; 236 #endif 237 238 void efi_init(void); 239 bool efi_probe(void); 240 paddr_t efi_getsystblpa(void); 241 struct efi_systbl *efi_getsystbl(void); 242 paddr_t efi_getcfgtblpa(const struct uuid*); 243 void *efi_getcfgtbl(const struct uuid*); 244 int efi_getbiosmemtype(uint32_t, uint64_t); 245 const char *efi_getmemtype_str(uint32_t); 246 struct btinfo_memmap; 247 struct btinfo_memmap *efi_get_e820memmap(void); 248 249 /* 250 void efi_boot_finish(void); 251 int efi_boot_minimal(uint64_t); 252 void *efi_get_table(struct uuid *); 253 void efi_get_time(struct efi_tm *); 254 struct efi_md *efi_md_first(void); 255 struct efi_md *efi_md_next(struct efi_md *); 256 void efi_reset_system(void); 257 efi_status efi_set_time(struct efi_tm *); 258 */ 259 260 #endif /* _X86_EFI_H_ */ 261