xref: /freebsd/sys/dev/bhnd/nvram/bhnd_nvram_store.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
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_STORE_H_
32 #define _BHND_NVRAM_BHND_NVRAM_STORE_H_
33 
34 #ifdef _KERNEL
35 #include <sys/param.h>
36 #include <sys/bus.h>
37 #else /* !_KERNEL */
38 #include <errno.h>
39 #include <stdint.h>
40 #include <stdlib.h>
41 #endif
42 
43 #include <sys/queue.h>
44 
45 #include "bhnd_nvram_data.h"
46 #include "bhnd_nvram_io.h"
47 
48 struct bhnd_nvram_store;
49 
50 /**
51  * NVRAM export flags.
52  */
53 enum {
54 	BHND_NVSTORE_EXPORT_CHILDREN		= (1<<0),	/**< Include all subpaths */
55 	BHND_NVSTORE_EXPORT_PRESERVE_DEVPATHS	= (1<<1),	/**< Preserve existing device path definitions (default) */
56 	BHND_NVSTORE_EXPORT_COMPACT_DEVPATHS	= (1<<2),	/**< Re-encode all device paths using compact syntax */
57 	BHND_NVSTORE_EXPORT_EXPAND_DEVPATHS	= (1<<3),	/**< Re-encode all device paths using non-compact syntax */
58 	BHND_NVSTORE_EXPORT_ALL_VARS		= (1<<6|1<<7),	/**< Include all variables (default) */
59 	BHND_NVSTORE_EXPORT_COMMITTED		= (1<<6),	/**< Include all committed changes */
60 	BHND_NVSTORE_EXPORT_UNCOMMITTED		= (1<<7),	/**< Include all uncommitted changes (not including deletions) */
61 	BHND_NVSTORE_EXPORT_DELETED		= (1<<8),	/**< Include all uncommitted deltions (as
62 								     properties of type BHND_NVRAM_TYPE_NULL) */
63 };
64 
65 int	bhnd_nvram_store_new(struct bhnd_nvram_store **store,
66 	    struct bhnd_nvram_data *data);
67 
68 int	bhnd_nvram_store_parse_new(struct bhnd_nvram_store **store,
69 	    struct bhnd_nvram_io *io, bhnd_nvram_data_class *cls);
70 
71 void	bhnd_nvram_store_free(struct bhnd_nvram_store *store);
72 
73 int	bhnd_nvram_store_export(struct bhnd_nvram_store *store,
74 	    const char *path, bhnd_nvram_data_class **cls,
75 	    bhnd_nvram_plist **props, bhnd_nvram_plist **options,
76 	    uint32_t flags);
77 
78 int	bhnd_nvram_store_serialize(struct bhnd_nvram_store *store,
79 	    const char *path, struct bhnd_nvram_io **data,  uint32_t flags);
80 
81 int	bhnd_nvram_store_getvar(struct bhnd_nvram_store *sc, const char *name,
82 	    void *outp, size_t *olen, bhnd_nvram_type otype);
83 int	bhnd_nvram_store_setvar(struct bhnd_nvram_store *sc, const char *name,
84 	    const void *inp, size_t ilen, bhnd_nvram_type itype);
85 int	bhnd_nvram_store_unsetvar(struct bhnd_nvram_store *sc,
86 	    const char *name);
87 
88 int	bhnd_nvram_store_setval(struct bhnd_nvram_store *sc, const char *name,
89 	    bhnd_nvram_val *value);
90 
91 #endif /* _BHND_NVRAM_BHND_NVRAM_STORE_H_ */
92