sys/boot/efi/boot1: Port efi boot1 loader from FreeBSD to DragonFly.
[dragonfly.git] / sys / boot / efi / boot1 / boot_module.h
1 /*-
2  * Copyright (c) 2015 Eric McCorkle
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: head/sys/boot/efi/boot1/boot_module.h 295320 2016-02-05 15:35:33Z smh $
27  */
28
29 #ifndef _BOOT_MODULE_H_
30 #define _BOOT_MODULE_H_
31
32 #include <stdbool.h>
33
34 #include <efi.h>
35 #include <efilib.h>
36 #include <eficonsctl.h>
37
38 #ifdef EFI_DEBUG
39 #define DPRINTF(fmt, args...) printf(fmt, ##args)
40 #define DSTALL(d) bs->Stall(d)
41 #else
42 #define DPRINTF(fmt, ...) {}
43 #define DSTALL(d) {}
44 #endif
45
46 /* EFI device info */
47 typedef struct dev_info
48 {
49         EFI_BLOCK_IO *dev;
50         EFI_DEVICE_PATH *devpath;
51         EFI_HANDLE *devhandle;
52         void *devdata;
53         BOOLEAN preferred;
54         struct dev_info *next;
55 } dev_info_t;
56
57 /*
58  * A boot loader module.
59  *
60  * This is a standard interface for filesystem modules in the EFI system.
61  */
62 typedef struct boot_module_t
63 {
64         const char *name;
65
66         /* init is the optional initialiser for the module. */
67         void (*init)(void);
68
69         /*
70          * probe checks to see if the module can handle dev.
71          *
72          * Return codes:
73          * EFI_SUCCESS = The module can handle the device.
74          * EFI_NOT_FOUND = The module can not handle the device.
75          * Other = The module encountered an error.
76          */
77         EFI_STATUS (*probe)(dev_info_t* dev);
78
79         /*
80          * load should select the best out of a set of devices that probe
81          * indicated were loadable and load the specified file.
82          *
83          * Return codes:
84          * EFI_SUCCESS = The module can handle the device.
85          * EFI_NOT_FOUND = The module can not handle the device.
86          * Other = The module encountered an error.
87          */
88         EFI_STATUS (*load)(const char *filepath, dev_info_t *devinfo,
89             void **buf, size_t *bufsize);
90
91         /* status outputs information about the probed devices. */
92         void (*status)(void);
93
94         /* valid devices as found by probe. */
95         dev_info_t *(*devices)(void);
96 } boot_module_t;
97
98 /* Standard boot modules. */
99 #ifdef EFI_UFS_BOOT
100 extern const boot_module_t ufs_module;
101 #endif
102
103 /* Functions available to modules. */
104 extern void add_device(dev_info_t **devinfop, dev_info_t *devinfo);
105
106 extern EFI_SYSTEM_TABLE *systab;
107 extern EFI_BOOT_SERVICES *bs;
108
109 extern int devpath_strlcat(char *buf, size_t size, EFI_DEVICE_PATH *devpath);
110 extern char *devpath_str(EFI_DEVICE_PATH *devpath);
111 #endif