2 * Copyright (c) 2015-2016 Landon Fuller <landonf@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
32 #ifndef _BHND_NVRAM_BHND_NVRAM_DATA_H_
33 #define _BHND_NVRAM_BHND_NVRAM_DATA_H_
36 #include <sys/param.h>
45 #include "bhnd_nvram.h"
46 #include "bhnd_nvram_io.h"
47 #include "bhnd_nvram_plist.h"
48 #include "bhnd_nvram_value.h"
50 /* NVRAM data class */
51 typedef struct bhnd_nvram_data_class bhnd_nvram_data_class;
53 /* NVRAM data instance */
54 struct bhnd_nvram_data;
56 /** Declare a bhnd_nvram_data_class with name @p _n */
57 #define BHND_NVRAM_DATA_CLASS_DECL(_n) \
58 extern struct bhnd_nvram_data_class bhnd_nvram_ ## _n ## _class
60 BHND_NVRAM_DATA_CLASS_DECL(bcm);
61 BHND_NVRAM_DATA_CLASS_DECL(bcmraw);
62 BHND_NVRAM_DATA_CLASS_DECL(tlv);
63 BHND_NVRAM_DATA_CLASS_DECL(btxt);
64 BHND_NVRAM_DATA_CLASS_DECL(sprom);
66 /** bhnd_nvram_data capabilities */
68 /** Supports efficient lookup of variables by name */
69 BHND_NVRAM_DATA_CAP_INDEXED = (1<<0),
71 /** Supports direct access to backing buffer */
72 BHND_NVRAM_DATA_CAP_READ_PTR = (1<<1),
74 /** Supports device path prefixed variables */
75 BHND_NVRAM_DATA_CAP_DEVPATHS = (1<<2),
79 * A standard set of probe priorities returned by bhnd_nvram_data_probe().
81 * Priority is defined in ascending order, with 0 being the highest priority.
82 * Return values greater than zero are interpreted as regular unix error codes.
85 BHND_NVRAM_DATA_PROBE_MAYBE = -40, /**< Possible match */
86 BHND_NVRAM_DATA_PROBE_DEFAULT = -20, /**< Definite match of a base
87 OS-supplied data class */
88 BHND_NVRAM_DATA_PROBE_SPECIFIC = 0, /**< Terminate search and use
93 const char *bhnd_nvram_data_class_desc(bhnd_nvram_data_class *cls);
94 uint32_t bhnd_nvram_data_class_caps(bhnd_nvram_data_class *cls);
96 int bhnd_nvram_data_serialize(bhnd_nvram_data_class *cls,
97 bhnd_nvram_plist *props, bhnd_nvram_plist *options,
98 void *outp, size_t *olen);
100 int bhnd_nvram_data_probe(bhnd_nvram_data_class *cls,
101 struct bhnd_nvram_io *io);
102 int bhnd_nvram_data_probe_classes(
103 struct bhnd_nvram_data **data,
104 struct bhnd_nvram_io *io,
105 bhnd_nvram_data_class *classes[],
108 int bhnd_nvram_data_getvar_direct(
109 bhnd_nvram_data_class *cls,
110 struct bhnd_nvram_io *io, const char *name,
111 void *buf, size_t *len, bhnd_nvram_type type);
113 int bhnd_nvram_data_new(bhnd_nvram_data_class *cls,
114 struct bhnd_nvram_data **nv,
115 struct bhnd_nvram_io *io);
117 struct bhnd_nvram_data *bhnd_nvram_data_retain(struct bhnd_nvram_data *nv);
118 void bhnd_nvram_data_release(struct bhnd_nvram_data *nv);
120 bhnd_nvram_data_class *bhnd_nvram_data_get_class(struct bhnd_nvram_data *nv);
122 size_t bhnd_nvram_data_count(struct bhnd_nvram_data *nv);
123 bhnd_nvram_plist *bhnd_nvram_data_options(struct bhnd_nvram_data *nv);
124 uint32_t bhnd_nvram_data_caps(struct bhnd_nvram_data *nv);
126 const char *bhnd_nvram_data_next(struct bhnd_nvram_data *nv,
128 void *bhnd_nvram_data_find(struct bhnd_nvram_data *nv,
131 int bhnd_nvram_data_getvar_order(
132 struct bhnd_nvram_data *nv, void *cookiep1,
135 int bhnd_nvram_data_getvar(struct bhnd_nvram_data *nv,
136 void *cookiep, void *buf, size_t *len,
137 bhnd_nvram_type type);
139 const void *bhnd_nvram_data_getvar_ptr(struct bhnd_nvram_data *nv,
140 void *cookiep, size_t *len, bhnd_nvram_type *type);
142 const char *bhnd_nvram_data_getvar_name(struct bhnd_nvram_data *nv,
145 int bhnd_nvram_data_copy_val(struct bhnd_nvram_data *nv,
146 void *cookiep, bhnd_nvram_val **val);
148 int bhnd_nvram_data_filter_setvar(
149 struct bhnd_nvram_data *nv, const char *name,
150 bhnd_nvram_val *value, bhnd_nvram_val **result);
151 int bhnd_nvram_data_filter_unsetvar(
152 struct bhnd_nvram_data *nv, const char *name);
154 #endif /* _BHND_NVRAM_BHND_NVRAM_DATA_H_ */