Path: blob/main/sys/dev/bhnd/nvram/bhnd_nvram_datavar.h
39537 views
/*-1* Copyright (c) 2016 Landon Fuller <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any12* redistribution must be conditioned upon including a substantially13* similar Disclaimer requirement for further binary redistribution.14*15* NO WARRANTY16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY19* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL20* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,21* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS23* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER24* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)25* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF26* THE POSSIBILITY OF SUCH DAMAGES.27*28*/2930#ifndef _BHND_NVRAM_BHND_NVRAM_DATAVAR_H_31#define _BHND_NVRAM_BHND_NVRAM_DATAVAR_H_3233#include <sys/param.h>34#include <sys/linker_set.h>35#include <sys/refcount.h>3637#include "bhnd_nvram_io.h"3839#include "bhnd_nvram_data.h"4041/** Registered NVRAM parser class instances. */42SET_DECLARE(bhnd_nvram_data_class_set, bhnd_nvram_data_class);4344void *bhnd_nvram_data_generic_find(45struct bhnd_nvram_data *nv, const char *name);46int bhnd_nvram_data_generic_rp_getvar(47struct bhnd_nvram_data *nv, void *cookiep,48void *outp, size_t *olen, bhnd_nvram_type otype);49int bhnd_nvram_data_generic_rp_copy_val(50struct bhnd_nvram_data *nv, void *cookiep,51bhnd_nvram_val **val);5253/** @see bhnd_nvram_data_probe() */54typedef int (bhnd_nvram_data_op_probe)(struct bhnd_nvram_io *io);5556/** @see bhnd_nvram_data_probe() */57typedef int (bhnd_nvram_data_op_getvar_direct)(58struct bhnd_nvram_io *io, const char *name,59void *outp, size_t *olen, bhnd_nvram_type otype);6061/** @see bhnd_nvram_data_serialize() */62typedef int (bhnd_nvram_data_op_serialize)(63bhnd_nvram_data_class *cls,64bhnd_nvram_plist *props,65bhnd_nvram_plist *options, void *outp,66size_t *olen);6768/** @see bhnd_nvram_data_new() */69typedef int (bhnd_nvram_data_op_new)(struct bhnd_nvram_data *nv,70struct bhnd_nvram_io *io);7172/** Free all resources associated with @p nv. Called by73* bhnd_nvram_data_release() when the reference count reaches zero. */74typedef void (bhnd_nvram_data_op_free)(struct bhnd_nvram_data *nv);7576/** @see bhnd_nvram_data_count() */77typedef size_t (bhnd_nvram_data_op_count)(struct bhnd_nvram_data *nv);7879/** @see bhnd_nvram_data_options() */80typedef bhnd_nvram_plist*(bhnd_nvram_data_op_options)(81struct bhnd_nvram_data *nv);8283/** @see bhnd_nvram_data_caps() */84typedef uint32_t (bhnd_nvram_data_op_caps)(struct bhnd_nvram_data *nv);8586/** @see bhnd_nvram_data_next() */87typedef const char *(bhnd_nvram_data_op_next)(struct bhnd_nvram_data *nv,88void **cookiep);8990/** @see bhnd_nvram_data_find() */91typedef void *(bhnd_nvram_data_op_find)(struct bhnd_nvram_data *nv,92const char *name);9394/** @see bhnd_nvram_data_copy_val() */95typedef int (bhnd_nvram_data_op_copy_val)(96struct bhnd_nvram_data *nv, void *cookiep,97bhnd_nvram_val **value);9899/** @see bhnd_nvram_data_getvar_order() */100typedef int (bhnd_nvram_data_op_getvar_order)(101struct bhnd_nvram_data *nv, void *cookiep1,102void *cookiep2);103104/** @see bhnd_nvram_data_getvar_name() */105typedef const char *(bhnd_nvram_data_op_getvar_name)(106struct bhnd_nvram_data *nv,107void *cookiep);108109/** @see bhnd_nvram_data_getvar() */110typedef int (bhnd_nvram_data_op_getvar)(struct bhnd_nvram_data *nv,111void *cookiep, void *buf, size_t *len,112bhnd_nvram_type type);113114/** @see bhnd_nvram_data_getvar_ptr() */115typedef const void *(bhnd_nvram_data_op_getvar_ptr)(116struct bhnd_nvram_data *nv, void *cookiep,117size_t *len, bhnd_nvram_type *type);118119/** @see bhnd_nvram_data_filter_setvar() */120typedef int (bhnd_nvram_data_op_filter_setvar)(121struct bhnd_nvram_data *nv, const char *name,122bhnd_nvram_val *value, bhnd_nvram_val **result);123124/** @see bhnd_nvram_data_filter_unsetvar() */125typedef int (bhnd_nvram_data_op_filter_unsetvar)(126struct bhnd_nvram_data *nv, const char *name);127128/**129* NVRAM data class.130*/131struct bhnd_nvram_data_class {132const char *desc; /**< description */133uint32_t caps; /**< capabilities (BHND_NVRAM_DATA_CAP_*) */134size_t size; /**< instance size */135136bhnd_nvram_data_op_probe *op_probe;137bhnd_nvram_data_op_getvar_direct *op_getvar_direct;138bhnd_nvram_data_op_serialize *op_serialize;139bhnd_nvram_data_op_new *op_new;140bhnd_nvram_data_op_free *op_free;141bhnd_nvram_data_op_count *op_count;142bhnd_nvram_data_op_options *op_options;143bhnd_nvram_data_op_caps *op_caps;144bhnd_nvram_data_op_next *op_next;145bhnd_nvram_data_op_find *op_find;146bhnd_nvram_data_op_copy_val *op_copy_val;147bhnd_nvram_data_op_getvar_order *op_getvar_order;148bhnd_nvram_data_op_getvar *op_getvar;149bhnd_nvram_data_op_getvar_ptr *op_getvar_ptr;150bhnd_nvram_data_op_getvar_name *op_getvar_name;151bhnd_nvram_data_op_filter_setvar *op_filter_setvar;152bhnd_nvram_data_op_filter_unsetvar *op_filter_unsetvar;153};154155/**156* NVRAM data instance.157*/158struct bhnd_nvram_data {159struct bhnd_nvram_data_class *cls;160volatile u_int refs;161};162163/*164* Helper macro for BHND_NVRAM_DATA_CLASS_DEFN().165*166* Declares a bhnd_nvram_data_class method implementation with class name167* _cname and method name _mname168*/169#define BHND_NVRAM_DATA_CLASS_DECL_METHOD(_cname, _mname) \170static bhnd_nvram_data_op_ ## _mname \171bhnd_nvram_ ## _cname ## _ ## _mname; \172173/*174* Helper macro for BHND_NVRAM_DATA_CLASS_DEFN().175*176* Assign a bhnd_nvram_data_class method implementation with class name177* @p _cname and method name @p _mname178*/179#define BHND_NVRAM_DATA_CLASS_ASSIGN_METHOD(_cname, _mname) \180.op_ ## _mname = bhnd_nvram_ ## _cname ## _ ## _mname,181182/*183* Helper macro for BHND_NVRAM_DATA_CLASS_DEFN().184*185* Iterate over all bhnd_nvram_data_class method names, calling186* _macro with the class name _cname as the first argument, and187* a bhnd_nvram_data_class method name as the second.188*/189#define BHND_NVRAM_DATA_CLASS_ITER_METHODS(_cname, _macro) \190_macro(_cname, probe) \191_macro(_cname, getvar_direct) \192_macro(_cname, serialize) \193_macro(_cname, new) \194_macro(_cname, free) \195_macro(_cname, count) \196_macro(_cname, options) \197_macro(_cname, caps) \198_macro(_cname, next) \199_macro(_cname, find) \200_macro(_cname, copy_val) \201_macro(_cname, getvar_order) \202_macro(_cname, getvar) \203_macro(_cname, getvar_ptr) \204_macro(_cname, getvar_name) \205_macro(_cname, filter_setvar) \206_macro(_cname, filter_unsetvar)207208/**209* Define a bhnd_nvram_data_class with class name @p _n and description210* @p _desc, and register with bhnd_nvram_data_class_set.211*/212#define BHND_NVRAM_DATA_CLASS_DEFN(_cname, _desc, _caps, _size) \213BHND_NVRAM_DATA_CLASS_ITER_METHODS(_cname, \214BHND_NVRAM_DATA_CLASS_DECL_METHOD) \215\216struct bhnd_nvram_data_class bhnd_nvram_## _cname ## _class = { \217.desc = (_desc), \218.caps = (_caps), \219.size = (_size), \220BHND_NVRAM_DATA_CLASS_ITER_METHODS(_cname, \221BHND_NVRAM_DATA_CLASS_ASSIGN_METHOD) \222}; \223\224DATA_SET(bhnd_nvram_data_class_set, \225bhnd_nvram_## _cname ## _class);226227#endif /* _BHND_NVRAM_BHND_NVRAM_DATAVAR_H_ */228229230