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