xref: /freebsd/stand/efi/boot1/boot_module.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
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 
27 #ifndef _BOOT_MODULE_H_
28 #define _BOOT_MODULE_H_
29 
30 #include <stdbool.h>
31 
32 #include <efi.h>
33 #include <efilib.h>
34 #include <eficonsctl.h>
35 
36 #ifdef EFI_DEBUG
37 #define DPRINTF(fmt, args...) printf(fmt, ##args)
38 #define DSTALL(d) BS->Stall(d)
39 #else
40 #define DPRINTF(fmt, ...) {}
41 #define DSTALL(d) {}
42 #endif
43 
44 /* EFI device info */
45 typedef struct dev_info
46 {
47 	EFI_BLOCK_IO *dev;
48 	EFI_DEVICE_PATH *devpath;
49 	EFI_HANDLE devhandle;
50 	void *devdata;
51 	uint64_t partoff;
52 	int preferred;
53 	struct dev_info *next;
54 } dev_info_t;
55 
56 /*
57  * A boot loader module.
58  *
59  * This is a standard interface for filesystem modules in the EFI system.
60  */
61 typedef struct boot_module_t
62 {
63 	const char *name;
64 
65 	/* init is the optional initialiser for the module. */
66 	void (*init)(void);
67 
68 	/*
69 	 * probe checks to see if the module can handle dev.
70 	 *
71 	 * Return codes:
72 	 * EFI_SUCCESS = The module can handle the device.
73 	 * EFI_NOT_FOUND = The module can not handle the device.
74 	 * Other = The module encountered an error.
75 	 */
76 	EFI_STATUS (*probe)(dev_info_t* dev);
77 
78 	/*
79 	 * load should select the best out of a set of devices that probe
80 	 * indicated were loadable and load the specified file.
81 	 *
82 	 * Return codes:
83 	 * EFI_SUCCESS = The module can handle the device.
84 	 * EFI_NOT_FOUND = The module can not handle the device.
85 	 * Other = The module encountered an error.
86 	 */
87 	EFI_STATUS (*load)(const char *filepath, dev_info_t *devinfo,
88 	    void **buf, size_t *bufsize);
89 
90 	/* status outputs information about the probed devices. */
91 	void (*status)(void);
92 
93 	/* valid devices as found by probe. */
94 	dev_info_t *(*devices)(void);
95 
96 	/* return any environment variables to pass to next stage */
97 	const char *(*extra_env)(void);
98 } boot_module_t;
99 
100 extern const boot_module_t *boot_modules[];
101 extern const UINTN num_boot_modules;
102 
103 /* Standard boot modules. */
104 #ifdef EFI_UFS_BOOT
105 extern const boot_module_t ufs_module;
106 #endif
107 #ifdef EFI_ZFS_BOOT
108 extern const boot_module_t zfs_module;
109 #endif
110 
111 /* Functions available to modules. */
112 extern void add_device(dev_info_t **devinfop, dev_info_t *devinfo);
113 #endif
114