xref: /freebsd/sys/dev/bhnd/nvram/bhnd_nvram_storevar.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_STOREVAR_H_
3277cb4d3eSLandon J. Fuller #define _BHND_NVRAM_BHND_NVRAM_STOREVAR_H_
3377cb4d3eSLandon J. Fuller 
3477cb4d3eSLandon J. Fuller #include <sys/types.h>
3577cb4d3eSLandon J. Fuller 
3677cb4d3eSLandon J. Fuller #ifndef _KERNEL
3777cb4d3eSLandon J. Fuller #include <pthread.h>
3877cb4d3eSLandon J. Fuller #endif
3977cb4d3eSLandon J. Fuller 
4019be09f3SLandon J. Fuller #include "bhnd_nvram_plist.h"
4119be09f3SLandon J. Fuller 
4277cb4d3eSLandon J. Fuller #include "bhnd_nvram_store.h"
4377cb4d3eSLandon J. Fuller 
4477cb4d3eSLandon J. Fuller /** Index is only generated if minimum variable count is met */
4519be09f3SLandon J. Fuller #define	BHND_NV_IDX_VAR_THRESHOLD	15
4677cb4d3eSLandon J. Fuller 
4719be09f3SLandon J. Fuller #define	BHND_NVSTORE_ROOT_PATH		"/"
4819be09f3SLandon J. Fuller #define	BHND_NVSTORE_ROOT_PATH_LEN	sizeof(BHND_NVSTORE_ROOT_PATH)
4977cb4d3eSLandon J. Fuller 
5019be09f3SLandon J. Fuller #define BHND_NVSTORE_GET_FLAG(_value, _flag)	\
5119be09f3SLandon J. Fuller 	(((_value) & BHND_NVSTORE_ ## _flag) != 0)
5219be09f3SLandon J. Fuller #define	BHND_NVSTORE_GET_BITS(_value, _field)	\
5319be09f3SLandon J. Fuller 	((_value) & BHND_NVSTORE_ ## _field ## _MASK)
5419be09f3SLandon J. Fuller 
5519be09f3SLandon J. Fuller /* Forward declarations */
5619be09f3SLandon J. Fuller typedef struct bhnd_nvstore_name_info	bhnd_nvstore_name_info;
5719be09f3SLandon J. Fuller typedef struct bhnd_nvstore_index	bhnd_nvstore_index;
5819be09f3SLandon J. Fuller typedef struct bhnd_nvstore_path	bhnd_nvstore_path;
5919be09f3SLandon J. Fuller 
6019be09f3SLandon J. Fuller typedef struct bhnd_nvstore_alias	bhnd_nvstore_alias;
6119be09f3SLandon J. Fuller 
6219be09f3SLandon J. Fuller typedef struct bhnd_nvstore_alias_list	bhnd_nvstore_alias_list;
6319be09f3SLandon J. Fuller typedef struct bhnd_nvstore_update_list	bhnd_nvstore_update_list;
6419be09f3SLandon J. Fuller typedef struct bhnd_nvstore_path_list	bhnd_nvstore_path_list;
6519be09f3SLandon J. Fuller 
6619be09f3SLandon J. Fuller LIST_HEAD(bhnd_nvstore_alias_list,	bhnd_nvstore_alias);
6719be09f3SLandon J. Fuller LIST_HEAD(bhnd_nvstore_update_list,	bhnd_nvstore_update);
6819be09f3SLandon J. Fuller LIST_HEAD(bhnd_nvstore_path_list,	bhnd_nvstore_path);
6977cb4d3eSLandon J. Fuller 
7077cb4d3eSLandon J. Fuller /**
7119be09f3SLandon J. Fuller  * NVRAM store variable entry types.
7277cb4d3eSLandon J. Fuller  */
7319be09f3SLandon J. Fuller typedef enum {
7419be09f3SLandon J. Fuller 	BHND_NVSTORE_VAR	= 0,	/**< simple variable (var=...) */
7519be09f3SLandon J. Fuller 	BHND_NVSTORE_ALIAS_DECL	= 1,	/**< alias declaration ('devpath0=pci/1/1') */
7619be09f3SLandon J. Fuller } bhnd_nvstore_var_type;
7777cb4d3eSLandon J. Fuller 
7819be09f3SLandon J. Fuller /**
7919be09f3SLandon J. Fuller  * NVRAM path descriptor types.
8019be09f3SLandon J. Fuller  */
8119be09f3SLandon J. Fuller typedef enum {
8219be09f3SLandon J. Fuller 	BHND_NVSTORE_PATH_STRING	= 0,	/**< path is a string value */
8319be09f3SLandon J. Fuller 	BHND_NVSTORE_PATH_ALIAS		= 1	/**< path is an alias reference */
8419be09f3SLandon J. Fuller } bhnd_nvstore_path_type;
8519be09f3SLandon J. Fuller 
8619be09f3SLandon J. Fuller /**
8719be09f3SLandon J. Fuller  * NVRAM variable namespaces.
8819be09f3SLandon J. Fuller  */
8919be09f3SLandon J. Fuller typedef enum {
9019be09f3SLandon J. Fuller 	BHND_NVSTORE_NAME_INTERNAL	= 1,	/**< internal namespace. permits
9119be09f3SLandon J. Fuller 						     use of reserved devpath and
9219be09f3SLandon J. Fuller 						     alias name prefixes. */
9319be09f3SLandon J. Fuller 	BHND_NVSTORE_NAME_EXTERNAL	= 2,	/**< external namespace. forbids
9419be09f3SLandon J. Fuller 						     use of name prefixes used
9519be09f3SLandon J. Fuller 						     for device path handling */
9619be09f3SLandon J. Fuller } bhnd_nvstore_name_type;
9719be09f3SLandon J. Fuller 
9819be09f3SLandon J. Fuller bhnd_nvstore_path	*bhnd_nvstore_path_new(const char *path_str,
9919be09f3SLandon J. Fuller 			     size_t path_len);
10019be09f3SLandon J. Fuller void			 bhnd_nvstore_path_free(struct bhnd_nvstore_path *path);
10119be09f3SLandon J. Fuller 
10219be09f3SLandon J. Fuller bhnd_nvstore_index	*bhnd_nvstore_index_new(size_t capacity);
10319be09f3SLandon J. Fuller void			 bhnd_nvstore_index_free(bhnd_nvstore_index *index);
10419be09f3SLandon J. Fuller int			 bhnd_nvstore_index_append(struct bhnd_nvram_store *sc,
10519be09f3SLandon J. Fuller 			     bhnd_nvstore_index *index,
10619be09f3SLandon J. Fuller 			     void *cookiep);
10719be09f3SLandon J. Fuller int			 bhnd_nvstore_index_prepare(
10819be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc,
10919be09f3SLandon J. Fuller 			     bhnd_nvstore_index *index);
11019be09f3SLandon J. Fuller void			*bhnd_nvstore_index_lookup(struct bhnd_nvram_store *sc,
11119be09f3SLandon J. Fuller 			     bhnd_nvstore_index *index, const char *name);
11219be09f3SLandon J. Fuller 
11319be09f3SLandon J. Fuller bhnd_nvstore_path	*bhnd_nvstore_get_root_path(
11419be09f3SLandon J. Fuller 			    struct bhnd_nvram_store *sc);
11519be09f3SLandon J. Fuller bool			 bhnd_nvstore_is_root_path(struct bhnd_nvram_store *sc,
11619be09f3SLandon J. Fuller 			     bhnd_nvstore_path *path);
11719be09f3SLandon J. Fuller 
11819be09f3SLandon J. Fuller void			*bhnd_nvstore_path_data_next(
11919be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc,
12019be09f3SLandon J. Fuller 			     bhnd_nvstore_path *path, void **indexp);
12119be09f3SLandon J. Fuller void			*bhnd_nvstore_path_data_lookup(
12219be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc,
12319be09f3SLandon J. Fuller 			     bhnd_nvstore_path *path, const char *name);
12419be09f3SLandon J. Fuller bhnd_nvram_prop		*bhnd_nvstore_path_get_update(
12519be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc,
12619be09f3SLandon J. Fuller 			     bhnd_nvstore_path *path, const char *name);
12719be09f3SLandon J. Fuller int			 bhnd_nvstore_path_register_update(
12819be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc,
12919be09f3SLandon J. Fuller 			     bhnd_nvstore_path *path, const char *name,
13019be09f3SLandon J. Fuller 			     bhnd_nvram_val *value);
13119be09f3SLandon J. Fuller 
13219be09f3SLandon J. Fuller bhnd_nvstore_alias	*bhnd_nvstore_find_alias(struct bhnd_nvram_store *sc,
13319be09f3SLandon J. Fuller 			     const char *path);
13419be09f3SLandon J. Fuller bhnd_nvstore_alias	*bhnd_nvstore_get_alias(struct bhnd_nvram_store *sc,
13519be09f3SLandon J. Fuller 			     u_long alias_val);
13619be09f3SLandon J. Fuller 
13719be09f3SLandon J. Fuller bhnd_nvstore_path	*bhnd_nvstore_get_path(struct bhnd_nvram_store *sc,
13819be09f3SLandon J. Fuller 			     const char *path, size_t path_len);
13919be09f3SLandon J. Fuller bhnd_nvstore_path	*bhnd_nvstore_resolve_path_alias(
14019be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc, u_long aval);
14119be09f3SLandon J. Fuller 
14219be09f3SLandon J. Fuller bhnd_nvstore_path	*bhnd_nvstore_var_get_path(struct bhnd_nvram_store *sc,
14319be09f3SLandon J. Fuller 			     bhnd_nvstore_name_info *info);
14419be09f3SLandon J. Fuller int			 bhnd_nvstore_var_register_path(
14519be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc,
14619be09f3SLandon J. Fuller 			     bhnd_nvstore_name_info *info, void *cookiep);
14719be09f3SLandon J. Fuller 
14819be09f3SLandon J. Fuller int			 bhnd_nvstore_register_path(struct bhnd_nvram_store *sc,
14919be09f3SLandon J. Fuller 			     const char *path, size_t path_len);
15019be09f3SLandon J. Fuller int			 bhnd_nvstore_register_alias(
15119be09f3SLandon J. Fuller 			     struct bhnd_nvram_store *sc,
15219be09f3SLandon J. Fuller 			     const bhnd_nvstore_name_info *info, void *cookiep);
15319be09f3SLandon J. Fuller 
15419be09f3SLandon J. Fuller const char		*bhnd_nvstore_parse_relpath(const char *parent,
15519be09f3SLandon J. Fuller 			     const char *child);
15619be09f3SLandon J. Fuller int			 bhnd_nvstore_parse_name_info(const char *name,
15719be09f3SLandon J. Fuller 			     bhnd_nvstore_name_type name_type,
15819be09f3SLandon J. Fuller 			     uint32_t data_caps, bhnd_nvstore_name_info *info);
15919be09f3SLandon J. Fuller 
16019be09f3SLandon J. Fuller /**
16119be09f3SLandon J. Fuller  * NVRAM variable name descriptor.
16219be09f3SLandon J. Fuller  *
16319be09f3SLandon J. Fuller  * For NVRAM data instances supporting BHND_NVRAM_DATA_CAP_DEVPATHS, the
16419be09f3SLandon J. Fuller  * NVRAM-vended variable name will be in one of four formats:
16519be09f3SLandon J. Fuller  *
16619be09f3SLandon J. Fuller  * - Simple Variable:
16719be09f3SLandon J. Fuller  * 	'variable'
16819be09f3SLandon J. Fuller  * - Device Variable:
16919be09f3SLandon J. Fuller  * 	'pci/1/1/variable'
17019be09f3SLandon J. Fuller  * - Device Alias Variable:
17119be09f3SLandon J. Fuller  * 	'0:variable'
17219be09f3SLandon J. Fuller  * - Device Path Alias Definition:
17319be09f3SLandon J. Fuller  * 	'devpath0=pci/1/1/variable'
17419be09f3SLandon J. Fuller  *
17519be09f3SLandon J. Fuller  * Device Paths:
17619be09f3SLandon J. Fuller  *
17719be09f3SLandon J. Fuller  * The device path format is device class-specific; the known supported device
17819be09f3SLandon J. Fuller  * classes are:
17919be09f3SLandon J. Fuller  * 	- sb:		BCMA/SIBA SoC core device path.
18019be09f3SLandon J. Fuller  *	- pci:		PCI device path (and PCIe on some earlier devices).
18119be09f3SLandon J. Fuller  *	- pcie:		PCIe device path.
18219be09f3SLandon J. Fuller  *	- usb:		USB device path.
18319be09f3SLandon J. Fuller  *
18419be09f3SLandon J. Fuller  * The device path format is loosely defined as '[class]/[domain]/[bus]/[slot]',
18519be09f3SLandon J. Fuller  * with missing values either assumed to be zero, a value specific to the
18619be09f3SLandon J. Fuller  * device class, or irrelevant to the device class in question.
18719be09f3SLandon J. Fuller  *
18819be09f3SLandon J. Fuller  * Examples:
18919be09f3SLandon J. Fuller  *	sb/1			BCMA/SIBA backplane 0, core 1.
19019be09f3SLandon J. Fuller  *	pc/1/1			PCMCIA bus 1, slot 1
19119be09f3SLandon J. Fuller  *	pci/1/1			PCI/PCIe domain 0, bus 1, device 1
19219be09f3SLandon J. Fuller  *	pcie/1/1		PCIe domain 0, bus 1, device 1
19319be09f3SLandon J. Fuller  *	usb/0xbd17		USB PID 0xbd17 (VID defaults to Broadcom 0x0a5c)
19419be09f3SLandon J. Fuller  *
19519be09f3SLandon J. Fuller  * Device Path Aliases:
19619be09f3SLandon J. Fuller  *
19719be09f3SLandon J. Fuller  * Device path aliases reduce duplication of device paths in the flash encoding
19819be09f3SLandon J. Fuller  * of NVRAM data; a single devpath[alias]=[devpath] variable entry is defined,
19919be09f3SLandon J. Fuller  * and then later variables may reference the device path via its alias:
20019be09f3SLandon J. Fuller  * 	devpath1=usb/0xbd17
20119be09f3SLandon J. Fuller  *	1:mcs5gpo0=0x1100
20219be09f3SLandon J. Fuller  *
20319be09f3SLandon J. Fuller  * Alias values are always positive, base 10 integers.
20419be09f3SLandon J. Fuller  */
20519be09f3SLandon J. Fuller struct bhnd_nvstore_name_info {
20619be09f3SLandon J. Fuller 	const char		*name;		/**< variable name */
20719be09f3SLandon J. Fuller 	bhnd_nvstore_var_type	 type;		/**< variable type */
20819be09f3SLandon J. Fuller 	bhnd_nvstore_path_type	 path_type;	/**< path type */
20919be09f3SLandon J. Fuller 
21019be09f3SLandon J. Fuller 	/** Path information */
21119be09f3SLandon J. Fuller 	union {
21219be09f3SLandon J. Fuller 		/* BHND_NVSTORE_PATH_STRING */
21319be09f3SLandon J. Fuller 		struct {
21419be09f3SLandon J. Fuller 			const char	*value;		/**< device path */
21519be09f3SLandon J. Fuller 			size_t		 value_len;	/**< device path length */
21619be09f3SLandon J. Fuller 		} str;
21719be09f3SLandon J. Fuller 
21819be09f3SLandon J. Fuller 		/** BHND_NVSTORE_PATH_ALIAS */
21919be09f3SLandon J. Fuller 		struct {
22019be09f3SLandon J. Fuller 			u_long		 value;		/**< device alias */
22119be09f3SLandon J. Fuller 		} alias;
22219be09f3SLandon J. Fuller 	} path;
22377cb4d3eSLandon J. Fuller };
22477cb4d3eSLandon J. Fuller 
22577cb4d3eSLandon J. Fuller /**
22619be09f3SLandon J. Fuller  * NVRAM variable index.
22777cb4d3eSLandon J. Fuller  *
22877cb4d3eSLandon J. Fuller  * Provides effecient name-based lookup by maintaining an array of cached
22919be09f3SLandon J. Fuller  * cookiep values, sorted lexicographically by relative variable name.
23077cb4d3eSLandon J. Fuller  */
23177cb4d3eSLandon J. Fuller struct bhnd_nvstore_index {
23219be09f3SLandon J. Fuller 	size_t	 count;		/**< entry count */
23319be09f3SLandon J. Fuller 	size_t	 capacity;	/**< entry capacity */
23477cb4d3eSLandon J. Fuller 	void	*cookiep[];	/**< cookiep values */
23577cb4d3eSLandon J. Fuller };
23677cb4d3eSLandon J. Fuller 
23719be09f3SLandon J. Fuller /**
23819be09f3SLandon J. Fuller  * NVRAM device path.
23919be09f3SLandon J. Fuller  */
24019be09f3SLandon J. Fuller struct bhnd_nvstore_path {
24119be09f3SLandon J. Fuller 	char				*path_str;	/**< canonical path string */
24219be09f3SLandon J. Fuller 	size_t				 num_vars;	/**< per-path count of committed
24319be09f3SLandon J. Fuller 							     (non-pending) variables */
24419be09f3SLandon J. Fuller 	bhnd_nvstore_index		*index;		/**< per-path index, or NULL if
24519be09f3SLandon J. Fuller 							     this is a root path for
24619be09f3SLandon J. Fuller 							     which the data source
24719be09f3SLandon J. Fuller 							     may be queried directly. */
24819be09f3SLandon J. Fuller 	bhnd_nvram_plist		*pending;	/**< pending changes */
24919be09f3SLandon J. Fuller 
25019be09f3SLandon J. Fuller 	LIST_ENTRY(bhnd_nvstore_path) np_link;
25119be09f3SLandon J. Fuller };
25219be09f3SLandon J. Fuller 
25319be09f3SLandon J. Fuller /**
25419be09f3SLandon J. Fuller  * NVRAM device path alias.
25519be09f3SLandon J. Fuller  */
25619be09f3SLandon J. Fuller struct bhnd_nvstore_alias {
25719be09f3SLandon J. Fuller 	bhnd_nvstore_path	*path;		/**< borrowed path reference */
25819be09f3SLandon J. Fuller 	void			*cookiep;	/**< NVRAM variable's cookiep value */
25919be09f3SLandon J. Fuller 	u_long			 alias;		/**< alias value */
26019be09f3SLandon J. Fuller 
26119be09f3SLandon J. Fuller 	LIST_ENTRY(bhnd_nvstore_alias) na_link;
26219be09f3SLandon J. Fuller };
26377cb4d3eSLandon J. Fuller 
26477cb4d3eSLandon J. Fuller /** bhnd nvram store instance state */
26577cb4d3eSLandon J. Fuller struct bhnd_nvram_store {
26677cb4d3eSLandon J. Fuller #ifdef _KERNEL
26777cb4d3eSLandon J. Fuller 	struct mtx		 mtx;
26877cb4d3eSLandon J. Fuller #else
26977cb4d3eSLandon J. Fuller 	pthread_mutex_t		 mtx;
27077cb4d3eSLandon J. Fuller #endif
27119be09f3SLandon J. Fuller 	struct bhnd_nvram_data	*data;		/**< backing data */
27219be09f3SLandon J. Fuller 	uint32_t		 data_caps;	/**< data capability flags */
273*a7c43ebdSLandon J. Fuller 	bhnd_nvram_plist	*data_opts;	/**< data serialization options */
27419be09f3SLandon J. Fuller 
27519be09f3SLandon J. Fuller 	bhnd_nvstore_alias_list	 aliases[4];	/**< path alias hash table */
27619be09f3SLandon J. Fuller 	size_t			 num_aliases;	/**< alias count */
27719be09f3SLandon J. Fuller 
27819be09f3SLandon J. Fuller 	bhnd_nvstore_path	*root_path;	/**< root path instance */
27919be09f3SLandon J. Fuller 	bhnd_nvstore_path_list	 paths[4];	/**< path hash table */
28019be09f3SLandon J. Fuller 	size_t			 num_paths;	/**< path count */
28177cb4d3eSLandon J. Fuller };
28277cb4d3eSLandon J. Fuller 
28377cb4d3eSLandon J. Fuller #ifdef _KERNEL
28477cb4d3eSLandon J. Fuller 
28577cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK_INIT(sc) \
28677cb4d3eSLandon J. Fuller 	mtx_init(&(sc)->mtx, "BHND NVRAM store lock", NULL, MTX_DEF)
28777cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK(sc)			mtx_lock(&(sc)->mtx)
28877cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_UNLOCK(sc)			mtx_unlock(&(sc)->mtx)
28977cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK_ASSERT(sc, what)	mtx_assert(&(sc)->mtx, what)
29077cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK_DESTROY(sc)		mtx_destroy(&(sc)->mtx)
29177cb4d3eSLandon J. Fuller 
29277cb4d3eSLandon J. Fuller #else /* !_KERNEL */
29377cb4d3eSLandon J. Fuller 
29477cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK_INIT(sc)	do {				\
29577cb4d3eSLandon J. Fuller 	int error = pthread_mutex_init(&(sc)->mtx, NULL);		\
29677cb4d3eSLandon J. Fuller 	if (error)							\
29777cb4d3eSLandon J. Fuller 		BHND_NV_PANIC("pthread_mutex_init() failed: %d",	\
29877cb4d3eSLandon J. Fuller 		    error);						\
29977cb4d3eSLandon J. Fuller } while(0)
30077cb4d3eSLandon J. Fuller 
30177cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK(sc)		pthread_mutex_lock(&(sc)->mtx)
30277cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_UNLOCK(sc)		pthread_mutex_unlock(&(sc)->mtx)
30377cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK_DESTROY(sc)	pthread_mutex_destroy(&(sc)->mtx)
30477cb4d3eSLandon J. Fuller #define	BHND_NVSTORE_LOCK_ASSERT(sc, what)
30577cb4d3eSLandon J. Fuller 
30677cb4d3eSLandon J. Fuller #endif /* _KERNEL */
30777cb4d3eSLandon J. Fuller 
30877cb4d3eSLandon J. Fuller #endif /* _BHND_NVRAM_BHND_NVRAM_STOREVAR_H_ */
309