xref: /freebsd/sys/dev/bhnd/nvram/bhnd_nvram_valuevar.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1 /*-
2  * Copyright (c) 2015-2016 Landon Fuller <landonf@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  *
29  */
30 
31 #ifndef _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_
32 #define _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_
33 
34 #include "bhnd_nvram_value.h"
35 
36 int		 bhnd_nvram_val_generic_encode(bhnd_nvram_val *value,
37 		     void *outp, size_t *olen, bhnd_nvram_type otype);
38 int		 bhnd_nvram_val_generic_encode_elem(bhnd_nvram_val *value,
39 		     const void *inp, size_t ilen, void *outp, size_t *olen,
40 		     bhnd_nvram_type otype);
41 const void	*bhnd_nvram_val_generic_next(bhnd_nvram_val *value,
42 		     const void *prev, size_t *olen);
43 
44 /**
45  * Filter input data prior to initialization.
46  *
47  * This may be used to permit direct initialization from data types other than
48  * the default native_type defined by @p fmt.
49  *
50  * @param[in,out]	fmt	Indirect pointer to the NVRAM value format. If
51  *				modified by the caller, initialization will be
52  *				restarted and performed using the provided
53  *				format instance.
54  * @param		inp	Input data.
55  * @param		ilen	Input data length.
56  * @param		itype	Input data type.
57  *
58  * @retval 0		If initialization from @p inp is supported.
59  * @retval EFTYPE	If initialization from @p inp is unsupported.
60  * @retval EFAULT	if @p ilen is not correctly aligned for elements of
61  *			@p itype.
62  */
63 typedef int (bhnd_nvram_val_op_filter)(const bhnd_nvram_val_fmt **fmt,
64     const void *inp, size_t ilen, bhnd_nvram_type itype);
65 
66 /** @see bhnd_nvram_val_encode() */
67 typedef int (bhnd_nvram_val_op_encode)(bhnd_nvram_val *value, void *outp,
68     size_t *olen, bhnd_nvram_type otype);
69 
70 /** @see bhnd_nvram_val_encode_elem() */
71 typedef int (bhnd_nvram_val_op_encode_elem)(bhnd_nvram_val *value,
72     const void *inp, size_t ilen, void *outp, size_t *olen,
73     bhnd_nvram_type otype);
74 
75 /** @see bhnd_nvram_val_next() */
76 typedef const void *(bhnd_nvram_val_op_next)(bhnd_nvram_val *value,
77     const void *prev, size_t *olen);
78 
79 /** @see bhnd_nvram_val_nelem() */
80 typedef size_t (bhnd_nvram_val_op_nelem)(bhnd_nvram_val *value);
81 
82 /**
83  * NVRAM value format.
84  *
85  * Provides a set of callbacks to support defining custom parsing
86  * and encoding/conversion behavior when representing values as
87  * instances of bhnd_nvram_val.
88  */
89 struct bhnd_nvram_val_fmt {
90 	const char			*name;		/**< type name */
91 	bhnd_nvram_type			 native_type;	/**< native value representation */
92 	bhnd_nvram_val_op_filter	*op_filter;
93 	bhnd_nvram_val_op_encode	*op_encode;
94 	bhnd_nvram_val_op_encode_elem	*op_encode_elem;
95 	bhnd_nvram_val_op_nelem		*op_nelem;
96 	bhnd_nvram_val_op_next		*op_next;
97 };
98 
99 #endif /* _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_ */
100