boot_module.h revision 294999
175295Sdes/*-
2230132Suqs * Copyright (c) 2015 Eric McCorkle
375295Sdes * All rights reserved.
475295Sdes *
575295Sdes * Redistribution and use in source and binary forms, with or without
675295Sdes * modification, are permitted provided that the following conditions
775295Sdes * are met:
875295Sdes * 1. Redistributions of source code must retain the above copyright
975295Sdes *    notice, this list of conditions and the following disclaimer.
1075295Sdes * 2. Redistributions in binary form must reproduce the above copyright
1175295Sdes *    notice, this list of conditions and the following disclaimer in the
1275295Sdes *    documentation and/or other materials provided with the distribution.
1375295Sdes *
1475295Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1575295Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1675295Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1775295Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1875295Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1975295Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2075295Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2175295Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2275295Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2375295Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2475295Sdes * SUCH DAMAGE.
2575295Sdes *
2675295Sdes * $FreeBSD: stable/10/sys/boot/efi/boot1/boot_module.h 294999 2016-01-28 17:24:40Z smh $
2775295Sdes */
2875295Sdes
29143592Sdes#ifndef _BOOT_MODULE_H_
30143592Sdes#define _BOOT_MODULE_H_
31143592Sdes
32143592Sdes#include <stdbool.h>
33143592Sdes
3475295Sdes#include <efi.h>
3575295Sdes#include <efilib.h>
3675295Sdes#include <eficonsctl.h>
37112564Sjhb
3878073Sdes#ifdef EFI_DEBUG
3975295Sdes#define DPRINTF(fmt, ...) printf(fmt, __VA_ARGS__)
4077965Sdes#else
4184246Sdes#define DPRINTF(fmt, ...) {}
4275295Sdes#endif
4375295Sdes
4475295Sdes/* EFI device info */
4575295Sdestypedef struct dev_info
4675295Sdes{
4775295Sdes	EFI_BLOCK_IO *dev;
4877998Sdes	EFI_DEVICE_PATH *devpath;
4975295Sdes	EFI_HANDLE *devhandle;
5075295Sdes	void *devdata;
5189071Smsmith	struct dev_info *next;
52112564Sjhb} dev_info_t;
53112564Sjhb
5475295Sdes/*
55227309Sed * A boot loader module.
5675295Sdes *
5775295Sdes * This is a standard interface for filesystem modules in the EFI system.
5884246Sdes */
5984246Sdestypedef struct boot_module_t
6084246Sdes{
6184246Sdes	const char *name;
6284246Sdes
6384246Sdes	/* init is the optional initialiser for the module. */
6484246Sdes	void (*init)();
6584246Sdes
6684246Sdes	/*
6784246Sdes	 * probe checks to see if the module can handle dev.
6875295Sdes	 *
6984246Sdes	 * Return codes:
7084246Sdes	 * EFI_SUCCESS = The module can handle the device.
7175295Sdes	 * EFI_NOT_FOUND = The module can not handle the device.
7275295Sdes	 * Other = The module encountered an error.
7375295Sdes	 */
7484246Sdes	EFI_STATUS (*probe)(dev_info_t* dev);
7584246Sdes
7675295Sdes	/*
7775295Sdes	 * load should select the best out of a set of devices that probe
78138290Sphk	 * indicated were loadable and load it.
7975295Sdes	 *
8075295Sdes	 * Return codes:
8175295Sdes	 * EFI_SUCCESS = The module can handle the device.
8275295Sdes	 * EFI_NOT_FOUND = The module can not handle the device.
8375295Sdes	 * Other = The module encountered an error.
8475295Sdes	 */
8575295Sdes	EFI_STATUS (*load)(const char *loader_path, dev_info_t **devinfo,
86168720Sdes	    void **buf, size_t *bufsize);
87168720Sdes
88168720Sdes	/* status outputs information about the probed devices. */
89112564Sjhb	void (*status)();
90112564Sjhb
9175295Sdes} boot_module_t;
9275295Sdes
9375295Sdes/* Standard boot modules. */
9475295Sdes#ifdef EFI_UFS_BOOT
9575295Sdesextern const boot_module_t ufs_module;
9675295Sdes#endif
9775295Sdes#ifdef EFI_ZFS_BOOT
9875295Sdesextern const boot_module_t zfs_module;
99168720Sdes#endif
100168720Sdes
101112564Sjhb/* Functions available to modules. */
102168720Sdesextern void add_device(dev_info_t **devinfop, dev_info_t *devinfo);
103168720Sdesextern void panic(const char *fmt, ...) __dead2;
10475295Sdesextern int printf(const char *fmt, ...);
10575295Sdesextern int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap);
10675295Sdes
10775295Sdesextern EFI_SYSTEM_TABLE *systab;
10875295Sdesextern EFI_BOOT_SERVICES *bs;
10975295Sdes
11075295Sdes#endif
11177998Sdes