/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _LIBUEFI_RT_H_
#define _LIBUEFI_RT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/uefi.h>
typedef void *uefirt_hdl_t;
extern int uefirt_get_variable(uefirt_hdl_t hdl,
CHAR16 *name, EFI_GUID *vendor_guid,
UINT32 *attributes, UINTN *data_size, void *data, EFI_STATUS *ret);
extern int uefirt_get_next_variable_name(uefirt_hdl_t hdl,
UINTN *variable_name_size,
CHAR16 *variable_name, EFI_GUID *vendor_guid, EFI_STATUS *ret);
extern int uefirt_set_variable(uefirt_hdl_t hdl,
CHAR16 *variable_name,
EFI_GUID *vendor_guid, UINT32 attributes, UINTN data_size,
void *data, EFI_STATUS *ret);
/*
* Attributes for uefirt_var_get_attr and
* uefirt_var_set_attr. See UEFI spec section 3.1.3.
*/
#define LOAD_OPTION_ACTIVE 0x00000001
#define LOAD_OPTION_FORCE_RECONNECT 0x00000002
#define LOAD_OPTION_HIDDEN 0x00000008
#define LOAD_OPTION_CATEGORY 0x00001f00
#define LOAD_OPTION_CATEGORY_BOOT 0x00000000
#define LOAD_OPTION_CATEGORY_APP 0x00000100
/*
* Enable access to UEFI boot option functions.
*/
extern int uefirt_init(uefirt_hdl_t *hdl);
/*
* Disable access to UEFI boot option variables.
* Deallocate resources associated with handle,
* and flush any pending writes to NVRAM.
*
* Memory allocated and returned as a result of
* calling the access functions, include all
* the uefirt_var_boot_get_* functions, is released
* and should not be referenced after calling this
* function.
*/
extern void uefirt_fini(uefirt_hdl_t hdl);
/*
* Return an array of existing Boot#### variables. Each element
* of the array represents an individual Boot#### option. The
* array is terminated with -1.
*/
extern int uefirt_var_boot_array(uefirt_hdl_t hdl,
int **bootopt);
/*
* Search the list of existing boot option Boot#### properties
* for one which matches logical_partition and return the Boot####
* in bootopt. bootopt is a pointer to a NULL-terminated
* array of bootopt's. There may be multiple boot options
* associated with a given drive.
*
* logdev is of the form "c0t0d0s0" or "c0t0d0p0".
*/
extern int uefirt_var_boot_get_bootopt(uefirt_hdl_t hdl,
char *logdev, int **bootopt);
/*
* Search the list of logical path devices that match the given
* bootopt. There may be more than one device (eg multi-pathing).
* Returns a NULL-terminated list of matching logical drives in
* logdev.
*/
extern int uefirt_var_boot_get_logdev(uefirt_hdl_t hdl,
int bootopt, char **logdev[]);
/*
* Remove Boot#### property and reference in BootOrder.
*/
extern int uefirt_var_boot_destroy(uefirt_hdl_t hdl,
int bootopt);
#define UEFIRT_BOOTOPT_FULL 0x01
/*
* Default EFI path for Solaris bootloader
*/
#define UEFI_BOOTLOADER "\\EFI\\Oracle\\grubx64.efi"
/*
* Create a new load option from logical_drive and initialize.
*
* input: logical_drive, description
* input: flags - UEFIRT_BOOTOPT_FULL to use a full UEFI pathname
* output: bootopt
*/
extern int uefirt_var_boot_create(uefirt_hdl_t hdl,
char *logdev, char *desc, int *bootopt,
uint32_t attr, char **bootfiles, void *optdata,
size_t optdata_len, int create_flags);
/*
* Boot option access functions for reading or writing boot
* option data.
*/
extern int uefirt_var_boot_set_attr(uefirt_hdl_t hdl,
int bootopt, uint32_t attr);
extern int uefirt_var_boot_get_attr(uefirt_hdl_t hdl,
int bootopt, uint32_t *attr);
extern int uefirt_var_boot_set_desc(uefirt_hdl_t hdl,
int bootopt, char *desc);
extern int uefirt_var_boot_get_desc(uefirt_hdl_t hdl,
int bootopt, char **desc);
extern int uefirt_var_boot_set_bootfile(uefirt_hdl_t hdl,
int bootopt, char **bootfiles);
extern int uefirt_var_boot_get_bootfile(uefirt_hdl_t hdl,
int bootopt, char ***bootfiles);
extern int uefirt_var_boot_set_optdata(uefirt_hdl_t hdl,
int bootopt, char *optdata, size_t optdata_len);
extern int uefirt_var_boot_get_optdata(uefirt_hdl_t hdl,
int bootopt, void **optdata, size_t *optdata_len);
/*
* Returns the UEFI path in UEFI display notation, of the given
* bootopt. It displays only the path information contained in
* the variable, so if it's a short form, only a relative path
* is returned.
*/
extern int uefirt_var_boot_get_uefipath(uefirt_hdl_t hdl,
int bootopt, char **uefi_path);
/*
* Insert or move bootopt in BootOrder.
*/
extern int uefirt_var_boot_insert_bootorder(uefirt_hdl_t hdl,
int bootopt, int position);
extern int uefirt_var_boot_remove_bootorder(uefirt_hdl_t hdl,
int bootopt);
/*
* Return position in BootOrder array of bootopt.
*/
extern int uefirt_var_boot_get_position_bootorder(uefirt_hdl_t hdl,
int bootopt, int *position);
/*
* Return the bootopt at position in the BootOrder array.
*/
extern int uefirt_var_boot_get_bootopt_bootorder(uefirt_hdl_t hdl,
int *bootopt, int position);
/*
* Returns BootCurrent in bootopt.
*/
extern int uefirt_var_boot_get_current(uefirt_hdl_t hdl,
int *bootopt);
/*
* Set bootopt as the bootoption to boot from at next reboot.
* Sets BootNext.
*/
extern int uefirt_var_boot_set_next(uefirt_hdl_t hdl,
int bootopt);
#ifdef __cplusplus
}
#endif
#endif /* _LIBUEFI_RT_H_ */