xref: /freebsd/sys/dev/bhnd/nvram/bhnd_nvram_plist.h (revision b00ab754)
1 /*-
2  * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.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  * $FreeBSD$
30  */
31 
32 #ifndef _BHND_NVRAM_BHND_NVRAM_PLIST_H_
33 #define _BHND_NVRAM_BHND_NVRAM_PLIST_H_
34 
35 #ifdef _KERNEL
36 #include <sys/types.h>
37 #else /* !_KERNEL */
38 #include <stdbool.h>
39 #include <stdint.h>
40 #endif /* _KERNEL */
41 
42 #include "bhnd_nvram.h"
43 #include "bhnd_nvram_value.h"
44 
45 typedef struct bhnd_nvram_prop		bhnd_nvram_prop;
46 typedef struct bhnd_nvram_plist		bhnd_nvram_plist;
47 
48 bhnd_nvram_plist	*bhnd_nvram_plist_new(void);
49 bhnd_nvram_plist	*bhnd_nvram_plist_retain(bhnd_nvram_plist *plist);
50 void			 bhnd_nvram_plist_release(bhnd_nvram_plist *plist);
51 
52 bhnd_nvram_plist	*bhnd_nvram_plist_copy(bhnd_nvram_plist *plist);
53 
54 size_t			 bhnd_nvram_plist_count(bhnd_nvram_plist *plist);
55 
56 int			 bhnd_nvram_plist_append_list(bhnd_nvram_plist *plist,
57 			     bhnd_nvram_plist *tail);
58 
59 int			 bhnd_nvram_plist_append(bhnd_nvram_plist *plist,
60 			     bhnd_nvram_prop *prop);
61 int			 bhnd_nvram_plist_append_val(bhnd_nvram_plist *plist,
62 			     const char *name, bhnd_nvram_val *val);
63 int			 bhnd_nvram_plist_append_bytes(bhnd_nvram_plist *plist,
64 			     const char *name, const void *inp, size_t ilen,
65 			     bhnd_nvram_type itype);
66 int			 bhnd_nvram_plist_append_string(bhnd_nvram_plist *plist,
67 			     const char *name, const char *val);
68 
69 int			 bhnd_nvram_plist_replace(bhnd_nvram_plist *plist,
70 			     bhnd_nvram_prop *prop);
71 int			 bhnd_nvram_plist_replace_val(bhnd_nvram_plist *plist,
72 			     const char *name, bhnd_nvram_val *val);
73 int			 bhnd_nvram_plist_replace_bytes(bhnd_nvram_plist *plist,
74 			     const char *name, const void *inp, size_t ilen,
75 			     bhnd_nvram_type itype);
76 int			 bhnd_nvram_plist_replace_string(bhnd_nvram_plist *plist,
77 			     const char *name, const char *val);
78 
79 void			 bhnd_nvram_plist_remove(bhnd_nvram_plist *plist,
80 			     const char *name);
81 
82 bool			 bhnd_nvram_plist_contains(bhnd_nvram_plist *plist,
83 			     const char *name);
84 bhnd_nvram_prop		*bhnd_nvram_plist_next(bhnd_nvram_plist *plist,
85 			     bhnd_nvram_prop *prop);
86 
87 bhnd_nvram_prop		*bhnd_nvram_plist_get_prop(bhnd_nvram_plist *plist,
88 			     const char *name);
89 bhnd_nvram_val		*bhnd_nvram_plist_get_val(bhnd_nvram_plist *plist,
90 			     const char *name);
91 int			 bhnd_nvram_plist_get_encoded(bhnd_nvram_plist *plist,
92 			     const char *name, void *outp, size_t olen,
93 			     bhnd_nvram_type otype);
94 
95 int			 bhnd_nvram_plist_get_char(bhnd_nvram_plist *plist,
96 			     const char *name, u_char *val);
97 int			 bhnd_nvram_plist_get_uint8(bhnd_nvram_plist *plist,
98 			     const char *name, uint8_t *val);
99 int			 bhnd_nvram_plist_get_uint16(bhnd_nvram_plist *plist,
100 			     const char *name, uint16_t *val);
101 int			 bhnd_nvram_plist_get_uint32(bhnd_nvram_plist *plist,
102 			     const char *name, uint32_t *val);
103 int			 bhnd_nvram_plist_get_uint64(bhnd_nvram_plist *plist,
104 			     const char *name, uint64_t *val);
105 int			 bhnd_nvram_plist_get_string(bhnd_nvram_plist *plist,
106 			     const char *name, const char **val);
107 int			 bhnd_nvram_plist_get_bool(bhnd_nvram_plist *plist,
108 			     const char *name, bool *val);
109 
110 bhnd_nvram_prop		*bhnd_nvram_prop_new(const char *name,
111 			     bhnd_nvram_val *val);
112 bhnd_nvram_prop		*bhnd_nvram_prop_bytes_new(const char *name,
113 			     const void *inp, size_t ilen,
114 			     bhnd_nvram_type itype);
115 
116 bhnd_nvram_prop		*bhnd_nvram_prop_retain(bhnd_nvram_prop *prop);
117 void			 bhnd_nvram_prop_release(bhnd_nvram_prop *prop);
118 
119 const char		*bhnd_nvram_prop_name(bhnd_nvram_prop *prop);
120 bhnd_nvram_val		*bhnd_nvram_prop_val(bhnd_nvram_prop *prop);
121 bhnd_nvram_type		 bhnd_nvram_prop_type(bhnd_nvram_prop *prop);
122 
123 bool			 bhnd_nvram_prop_is_null(bhnd_nvram_prop *prop);
124 
125 const void		*bhnd_nvram_prop_bytes(bhnd_nvram_prop *prop,
126 			     size_t *olen, bhnd_nvram_type *otype);
127 int			 bhnd_nvram_prop_encode(bhnd_nvram_prop *prop,
128 			     void *outp, size_t *olen, bhnd_nvram_type otype);
129 
130 #endif /* _BHND_NVRAM_BHND_NVRAM_PLIST_H_ */
131