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