Path: blob/main/sys/dev/bhnd/nvram/bhnd_nvram_valuevar.h
39536 views
/*-1* Copyright (c) 2015-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_VALUEVAR_H_31#define _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_3233#include "bhnd_nvram_value.h"3435int bhnd_nvram_val_generic_encode(bhnd_nvram_val *value,36void *outp, size_t *olen, bhnd_nvram_type otype);37int bhnd_nvram_val_generic_encode_elem(bhnd_nvram_val *value,38const void *inp, size_t ilen, void *outp, size_t *olen,39bhnd_nvram_type otype);40const void *bhnd_nvram_val_generic_next(bhnd_nvram_val *value,41const void *prev, size_t *olen);4243/**44* Filter input data prior to initialization.45*46* This may be used to permit direct initialization from data types other than47* the default native_type defined by @p fmt.48*49* @param[in,out] fmt Indirect pointer to the NVRAM value format. If50* modified by the caller, initialization will be51* restarted and performed using the provided52* format instance.53* @param inp Input data.54* @param ilen Input data length.55* @param itype Input data type.56*57* @retval 0 If initialization from @p inp is supported.58* @retval EFTYPE If initialization from @p inp is unsupported.59* @retval EFAULT if @p ilen is not correctly aligned for elements of60* @p itype.61*/62typedef int (bhnd_nvram_val_op_filter)(const bhnd_nvram_val_fmt **fmt,63const void *inp, size_t ilen, bhnd_nvram_type itype);6465/** @see bhnd_nvram_val_encode() */66typedef int (bhnd_nvram_val_op_encode)(bhnd_nvram_val *value, void *outp,67size_t *olen, bhnd_nvram_type otype);6869/** @see bhnd_nvram_val_encode_elem() */70typedef int (bhnd_nvram_val_op_encode_elem)(bhnd_nvram_val *value,71const void *inp, size_t ilen, void *outp, size_t *olen,72bhnd_nvram_type otype);7374/** @see bhnd_nvram_val_next() */75typedef const void *(bhnd_nvram_val_op_next)(bhnd_nvram_val *value,76const void *prev, size_t *olen);7778/** @see bhnd_nvram_val_nelem() */79typedef size_t (bhnd_nvram_val_op_nelem)(bhnd_nvram_val *value);8081/**82* NVRAM value format.83*84* Provides a set of callbacks to support defining custom parsing85* and encoding/conversion behavior when representing values as86* instances of bhnd_nvram_val.87*/88struct bhnd_nvram_val_fmt {89const char *name; /**< type name */90bhnd_nvram_type native_type; /**< native value representation */91bhnd_nvram_val_op_filter *op_filter;92bhnd_nvram_val_op_encode *op_encode;93bhnd_nvram_val_op_encode_elem *op_encode_elem;94bhnd_nvram_val_op_nelem *op_nelem;95bhnd_nvram_val_op_next *op_next;96};9798#endif /* _BHND_NVRAM_BHND_NVRAM_VALUEVAR_H_ */99100101