xref: /freebsd/sys/dev/bhnd/nvram/bhnd_nvram_if.m (revision 031beb4e239bfce798af17f5fe8dba8bcaf13d99)
14ad7e9b0SAdrian Chadd#-
24ad7e9b0SAdrian Chadd# Copyright (c) 2016 Landon Fuller <landon@landonf.org>
34ad7e9b0SAdrian Chadd# All rights reserved.
44ad7e9b0SAdrian Chadd#
54ad7e9b0SAdrian Chadd# Redistribution and use in source and binary forms, with or without
64ad7e9b0SAdrian Chadd# modification, are permitted provided that the following conditions
74ad7e9b0SAdrian Chadd# are met:
84ad7e9b0SAdrian Chadd# 1. Redistributions of source code must retain the above copyright
94ad7e9b0SAdrian Chadd#    notice, this list of conditions and the following disclaimer.
104ad7e9b0SAdrian Chadd# 2. Redistributions in binary form must reproduce the above copyright
114ad7e9b0SAdrian Chadd#    notice, this list of conditions and the following disclaimer in the
124ad7e9b0SAdrian Chadd#    documentation and/or other materials provided with the distribution.
134ad7e9b0SAdrian Chadd#
144ad7e9b0SAdrian Chadd# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
154ad7e9b0SAdrian Chadd# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
164ad7e9b0SAdrian Chadd# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
174ad7e9b0SAdrian Chadd# IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
184ad7e9b0SAdrian Chadd# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
194ad7e9b0SAdrian Chadd# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
204ad7e9b0SAdrian Chadd# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
214ad7e9b0SAdrian Chadd# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
224ad7e9b0SAdrian Chadd# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
234ad7e9b0SAdrian Chadd# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
244ad7e9b0SAdrian Chadd#
254ad7e9b0SAdrian Chadd
264ad7e9b0SAdrian Chadd#include <sys/types.h>
274ad7e9b0SAdrian Chadd#include <sys/bus.h>
284ad7e9b0SAdrian Chadd
294ad7e9b0SAdrian Chadd#include <dev/bhnd/bhnd.h>
304ad7e9b0SAdrian Chadd
314ad7e9b0SAdrian ChaddINTERFACE bhnd_nvram;
324ad7e9b0SAdrian Chadd
334ad7e9b0SAdrian Chadd#
344ad7e9b0SAdrian Chadd# bhnd(4) NVRAM device interface.
354ad7e9b0SAdrian Chadd#
364ad7e9b0SAdrian Chadd# Provides a shared interface to HND NVRAM, OTP, and SPROM devices that provide
374ad7e9b0SAdrian Chadd# access to a common set of hardware/device configuration variables.
384ad7e9b0SAdrian Chadd#
394ad7e9b0SAdrian Chadd
404ad7e9b0SAdrian Chadd/**
414ad7e9b0SAdrian Chadd * Read an NVRAM variable.
424ad7e9b0SAdrian Chadd *
434ad7e9b0SAdrian Chadd * @param		dev	The NVRAM device.
444ad7e9b0SAdrian Chadd * @param		name	The NVRAM variable name.
454ad7e9b0SAdrian Chadd * @param[out]		buf	On success, the requested value will be written
464ad7e9b0SAdrian Chadd *				to this buffer. This argment may be NULL if
474ad7e9b0SAdrian Chadd *				the value is not desired.
48e83ce340SAdrian Chadd * @param[in,out]	len	The maximum capacity of @p buf. On success,
49e83ce340SAdrian Chadd *				will be set to the actual size of the requested
50e83ce340SAdrian Chadd *				value.
51*1728aef2SLandon J. Fuller * @param		type	The data type to be written to @p buf.
524ad7e9b0SAdrian Chadd *
534ad7e9b0SAdrian Chadd * @retval 0		success
544ad7e9b0SAdrian Chadd * @retval ENOENT	The requested variable was not found.
55e83ce340SAdrian Chadd * @retval ENOMEM	If @p buf is non-NULL and a buffer of @p len is too
564ad7e9b0SAdrian Chadd *			small to hold the requested value.
57e83ce340SAdrian Chadd * @retval ENODEV	If no supported NVRAM hardware is accessible via this
58e83ce340SAdrian Chadd *			device.
59*1728aef2SLandon J. Fuller * @retval EOPNOTSUPP	If any coercion to @p type is unsupported.
60*1728aef2SLandon J. Fuller * @retval EFTYPE	If the @p name's data type cannot be coerced to @p type.
61*1728aef2SLandon J. Fuller * @retval ERANGE	If value coercion would overflow @p type.
624ad7e9b0SAdrian Chadd * @retval non-zero	If reading @p name otherwise fails, a regular unix
634ad7e9b0SAdrian Chadd *			error code will be returned.
644ad7e9b0SAdrian Chadd */
654ad7e9b0SAdrian ChaddMETHOD int getvar {
664ad7e9b0SAdrian Chadd	device_t	 dev;
674ad7e9b0SAdrian Chadd	const char	*name;
684ad7e9b0SAdrian Chadd	void		*buf;
69e83ce340SAdrian Chadd	size_t		*len;
70*1728aef2SLandon J. Fuller	bhnd_nvram_type	 type;
71e83ce340SAdrian Chadd};
72e83ce340SAdrian Chadd
73e83ce340SAdrian Chadd/**
74*1728aef2SLandon J. Fuller * Set an NVRAM variable's value.
75e83ce340SAdrian Chadd *
76*1728aef2SLandon J. Fuller * No changes will be written to non-volatile storage until explicitly
77*1728aef2SLandon J. Fuller * committed.
78e83ce340SAdrian Chadd *
79e83ce340SAdrian Chadd * @param	dev	The NVRAM device.
80e83ce340SAdrian Chadd * @param	name	The NVRAM variable name.
81*1728aef2SLandon J. Fuller * @param	value	The new value.
82*1728aef2SLandon J. Fuller * @param	len	The size of @p value.
83*1728aef2SLandon J. Fuller * @param	type	The data type of @p value.
84e83ce340SAdrian Chadd *
85e83ce340SAdrian Chadd * @retval 0		success
86e83ce340SAdrian Chadd * @retval ENOENT	The specified variable name is not recognized.
87e83ce340SAdrian Chadd * @retval ENODEV	If no supported NVRAM hardware is accessible via this
88e83ce340SAdrian Chadd *			device.
89*1728aef2SLandon J. Fuller * @retval EOPNOTSUPP	If any coercion to @p type is unsupported.
90*1728aef2SLandon J. Fuller * @retval EFTYPE	If the @p name's data type cannot be coerced to @p type.
91*1728aef2SLandon J. Fuller * @retval ERANGE	If value coercion from  @p type would overflow.
92e83ce340SAdrian Chadd * @retval non-zero	If reading @p name otherwise fails, a regular unix
93e83ce340SAdrian Chadd *			error code will be returned.
94e83ce340SAdrian Chadd */
95e83ce340SAdrian ChaddMETHOD int setvar {
96e83ce340SAdrian Chadd	device_t	 dev;
97e83ce340SAdrian Chadd	const char	*name;
98*1728aef2SLandon J. Fuller	const void	*value;
99e83ce340SAdrian Chadd	size_t		 len;
100*1728aef2SLandon J. Fuller	bhnd_nvram_type	 type;
1014ad7e9b0SAdrian Chadd};
102