xref: /freebsd/sys/dev/bhnd/nvram/bhnd_nvram_valuevar.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
177cb4d3eSLandon J. Fuller /*-
277cb4d3eSLandon J. Fuller  * Copyright (c) 2015-2016 Landon Fuller <landonf@FreeBSD.org>
377cb4d3eSLandon J. Fuller  * All rights reserved.
477cb4d3eSLandon J. Fuller  *
577cb4d3eSLandon J. Fuller  * Redistribution and use in source and binary forms, with or without
677cb4d3eSLandon J. Fuller  * modification, are permitted provided that the following conditions
777cb4d3eSLandon J. Fuller  * are met:
877cb4d3eSLandon J. Fuller  * 1. Redistributions of source code must retain the above copyright
977cb4d3eSLandon J. Fuller  *    notice, this list of conditions and the following disclaimer,
1077cb4d3eSLandon J. Fuller  *    without modification.
1177cb4d3eSLandon J. Fuller  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1277cb4d3eSLandon J. Fuller  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
1377cb4d3eSLandon J. Fuller  *    redistribution must be conditioned upon including a substantially
1477cb4d3eSLandon J. Fuller  *    similar Disclaimer requirement for further binary redistribution.
1577cb4d3eSLandon J. Fuller  *
1677cb4d3eSLandon J. Fuller  * NO WARRANTY
1777cb4d3eSLandon J. Fuller  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1877cb4d3eSLandon J. Fuller  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1977cb4d3eSLandon J. Fuller  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
2077cb4d3eSLandon J. Fuller  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
2177cb4d3eSLandon J. Fuller  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
2277cb4d3eSLandon J. Fuller  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2377cb4d3eSLandon J. Fuller  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2477cb4d3eSLandon J. Fuller  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2577cb4d3eSLandon J. Fuller  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2677cb4d3eSLandon J. Fuller  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
2777cb4d3eSLandon J. Fuller  * THE POSSIBILITY OF SUCH DAMAGES.
2877cb4d3eSLandon J. Fuller  *
2977cb4d3eSLandon J. Fuller  */
3077cb4d3eSLandon J. Fuller 
3177cb4d3eSLandon J. Fuller #ifndef _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_
3277cb4d3eSLandon J. Fuller #define _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_
3377cb4d3eSLandon J. Fuller 
3477cb4d3eSLandon J. Fuller #include "bhnd_nvram_value.h"
3577cb4d3eSLandon J. Fuller 
3658efe686SLandon J. Fuller int		 bhnd_nvram_val_generic_encode(bhnd_nvram_val *value,
3777cb4d3eSLandon J. Fuller 		     void *outp, size_t *olen, bhnd_nvram_type otype);
3858efe686SLandon J. Fuller int		 bhnd_nvram_val_generic_encode_elem(bhnd_nvram_val *value,
3977cb4d3eSLandon J. Fuller 		     const void *inp, size_t ilen, void *outp, size_t *olen,
4077cb4d3eSLandon J. Fuller 		     bhnd_nvram_type otype);
4158efe686SLandon J. Fuller const void	*bhnd_nvram_val_generic_next(bhnd_nvram_val *value,
42*9be0790dSLandon J. Fuller 		     const void *prev, size_t *olen);
43*9be0790dSLandon J. Fuller 
4477cb4d3eSLandon J. Fuller /**
4577cb4d3eSLandon J. Fuller  * Filter input data prior to initialization.
4677cb4d3eSLandon J. Fuller  *
4777cb4d3eSLandon J. Fuller  * This may be used to permit direct initialization from data types other than
4877cb4d3eSLandon J. Fuller  * the default native_type defined by @p fmt.
4977cb4d3eSLandon J. Fuller  *
5077cb4d3eSLandon J. Fuller  * @param[in,out]	fmt	Indirect pointer to the NVRAM value format. If
5177cb4d3eSLandon J. Fuller  *				modified by the caller, initialization will be
5277cb4d3eSLandon J. Fuller  *				restarted and performed using the provided
5377cb4d3eSLandon J. Fuller  *				format instance.
5477cb4d3eSLandon J. Fuller  * @param		inp	Input data.
5577cb4d3eSLandon J. Fuller  * @param		ilen	Input data length.
5677cb4d3eSLandon J. Fuller  * @param		itype	Input data type.
5777cb4d3eSLandon J. Fuller  *
5877cb4d3eSLandon J. Fuller  * @retval 0		If initialization from @p inp is supported.
5977cb4d3eSLandon J. Fuller  * @retval EFTYPE	If initialization from @p inp is unsupported.
6077cb4d3eSLandon J. Fuller  * @retval EFAULT	if @p ilen is not correctly aligned for elements of
6177cb4d3eSLandon J. Fuller  *			@p itype.
6277cb4d3eSLandon J. Fuller  */
6358efe686SLandon J. Fuller typedef int (bhnd_nvram_val_op_filter)(const bhnd_nvram_val_fmt **fmt,
6477cb4d3eSLandon J. Fuller     const void *inp, size_t ilen, bhnd_nvram_type itype);
6577cb4d3eSLandon J. Fuller 
6677cb4d3eSLandon J. Fuller /** @see bhnd_nvram_val_encode() */
6758efe686SLandon J. Fuller typedef int (bhnd_nvram_val_op_encode)(bhnd_nvram_val *value, void *outp,
6877cb4d3eSLandon J. Fuller     size_t *olen, bhnd_nvram_type otype);
6977cb4d3eSLandon J. Fuller 
7077cb4d3eSLandon J. Fuller /** @see bhnd_nvram_val_encode_elem() */
7158efe686SLandon J. Fuller typedef int (bhnd_nvram_val_op_encode_elem)(bhnd_nvram_val *value,
7277cb4d3eSLandon J. Fuller     const void *inp, size_t ilen, void *outp, size_t *olen,
7377cb4d3eSLandon J. Fuller     bhnd_nvram_type otype);
7477cb4d3eSLandon J. Fuller 
7577cb4d3eSLandon J. Fuller /** @see bhnd_nvram_val_next() */
7658efe686SLandon J. Fuller typedef const void *(bhnd_nvram_val_op_next)(bhnd_nvram_val *value,
77*9be0790dSLandon J. Fuller     const void *prev, size_t *olen);
7877cb4d3eSLandon J. Fuller 
7977cb4d3eSLandon J. Fuller /** @see bhnd_nvram_val_nelem() */
8058efe686SLandon J. Fuller typedef size_t (bhnd_nvram_val_op_nelem)(bhnd_nvram_val *value);
8177cb4d3eSLandon J. Fuller 
8277cb4d3eSLandon J. Fuller /**
8377cb4d3eSLandon J. Fuller  * NVRAM value format.
8477cb4d3eSLandon J. Fuller  *
8577cb4d3eSLandon J. Fuller  * Provides a set of callbacks to support defining custom parsing
8677cb4d3eSLandon J. Fuller  * and encoding/conversion behavior when representing values as
8777cb4d3eSLandon J. Fuller  * instances of bhnd_nvram_val.
8877cb4d3eSLandon J. Fuller  */
8977cb4d3eSLandon J. Fuller struct bhnd_nvram_val_fmt {
9077cb4d3eSLandon J. Fuller 	const char			*name;		/**< type name */
9177cb4d3eSLandon J. Fuller 	bhnd_nvram_type			 native_type;	/**< native value representation */
9277cb4d3eSLandon J. Fuller 	bhnd_nvram_val_op_filter	*op_filter;
9377cb4d3eSLandon J. Fuller 	bhnd_nvram_val_op_encode	*op_encode;
9477cb4d3eSLandon J. Fuller 	bhnd_nvram_val_op_encode_elem	*op_encode_elem;
9577cb4d3eSLandon J. Fuller 	bhnd_nvram_val_op_nelem		*op_nelem;
9677cb4d3eSLandon J. Fuller 	bhnd_nvram_val_op_next		*op_next;
9777cb4d3eSLandon J. Fuller };
9877cb4d3eSLandon J. Fuller 
9977cb4d3eSLandon J. Fuller #endif /* _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_ */
100