Path: blob/main/sys/dev/bhnd/nvram/bhnd_nvram_if.m
39536 views
#-1# Copyright (c) 2016 Landon Fuller <[email protected]>2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions6# are met:7# 1. Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# 2. Redistributions in binary form must reproduce the above copyright10# notice, this list of conditions and the following disclaimer in the11# documentation and/or other materials provided with the distribution.12#13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR14# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES15# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,17# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES18# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR19# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER20# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,21# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE22# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23#2425#include <sys/types.h>26#include <sys/bus.h>2728#include <dev/bhnd/bhnd.h>2930INTERFACE bhnd_nvram;3132#33# bhnd(4) NVRAM device interface.34#35# Provides a shared interface to HND NVRAM, OTP, and SPROM devices that provide36# access to a common set of hardware/device configuration variables.37#3839/**40* Read an NVRAM variable.41*42* @param dev The NVRAM device.43* @param name The NVRAM variable name.44* @param[out] buf On success, the requested value will be written45* to this buffer. This argment may be NULL if46* the value is not desired.47* @param[in,out] len The maximum capacity of @p buf. On success,48* will be set to the actual size of the requested49* value.50* @param type The data type to be written to @p buf.51*52* @retval 0 success53* @retval ENOENT The requested variable was not found.54* @retval ENOMEM If @p buf is non-NULL and a buffer of @p len is too55* small to hold the requested value.56* @retval ENODEV If no supported NVRAM hardware is accessible via this57* device.58* @retval EOPNOTSUPP If any coercion to @p type is unsupported.59* @retval EFTYPE If the @p name's data type cannot be coerced to @p type.60* @retval ERANGE If value coercion would overflow @p type.61* @retval non-zero If reading @p name otherwise fails, a regular unix62* error code will be returned.63*/64METHOD int getvar {65device_t dev;66const char *name;67void *buf;68size_t *len;69bhnd_nvram_type type;70};7172/**73* Set an NVRAM variable's value.74*75* No changes will be written to non-volatile storage until explicitly76* committed.77*78* @param dev The NVRAM device.79* @param name The NVRAM variable name.80* @param value The new value.81* @param len The size of @p value.82* @param type The data type of @p value.83*84* @retval 0 success85* @retval ENOENT The specified variable name is not recognized.86* @retval ENODEV If no supported NVRAM hardware is accessible via this87* device.88* @retval EOPNOTSUPP If any coercion to @p type is unsupported.89* @retval EFTYPE If the @p name's data type cannot be coerced to @p type.90* @retval ERANGE If value coercion from @p type would overflow.91* @retval non-zero If reading @p name otherwise fails, a regular unix92* error code will be returned.93*/94METHOD int setvar {95device_t dev;96const char *name;97const void *value;98size_t len;99bhnd_nvram_type type;100};101102103