Path: blob/main/sys/dev/bhnd/nvram/bhnd_nvram_data.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_DATA_H_31#define _BHND_NVRAM_BHND_NVRAM_DATA_H_3233#ifdef _KERNEL34#include <sys/param.h>35#include <sys/bus.h>36#else /* !_KERNEL */37#include <errno.h>3839#include <stdint.h>40#include <stdlib.h>41#endif /* _KERNEL */4243#include "bhnd_nvram.h"44#include "bhnd_nvram_io.h"45#include "bhnd_nvram_plist.h"46#include "bhnd_nvram_value.h"4748/* NVRAM data class */49typedef struct bhnd_nvram_data_class bhnd_nvram_data_class;5051/* NVRAM data instance */52struct bhnd_nvram_data;5354/** Declare a bhnd_nvram_data_class with name @p _n */55#define BHND_NVRAM_DATA_CLASS_DECL(_n) \56extern struct bhnd_nvram_data_class bhnd_nvram_ ## _n ## _class5758BHND_NVRAM_DATA_CLASS_DECL(bcm);59BHND_NVRAM_DATA_CLASS_DECL(bcmraw);60BHND_NVRAM_DATA_CLASS_DECL(tlv);61BHND_NVRAM_DATA_CLASS_DECL(btxt);62BHND_NVRAM_DATA_CLASS_DECL(sprom);6364/** bhnd_nvram_data capabilities */65enum {66/** Supports efficient lookup of variables by name */67BHND_NVRAM_DATA_CAP_INDEXED = (1<<0),6869/** Supports direct access to backing buffer */70BHND_NVRAM_DATA_CAP_READ_PTR = (1<<1),7172/** Supports device path prefixed variables */73BHND_NVRAM_DATA_CAP_DEVPATHS = (1<<2),74};7576/**77* A standard set of probe priorities returned by bhnd_nvram_data_probe().78*79* Priority is defined in ascending order, with 0 being the highest priority.80* Return values greater than zero are interpreted as regular unix error codes.81*/82enum {83BHND_NVRAM_DATA_PROBE_MAYBE = -40, /**< Possible match */84BHND_NVRAM_DATA_PROBE_DEFAULT = -20, /**< Definite match of a base85OS-supplied data class */86BHND_NVRAM_DATA_PROBE_SPECIFIC = 0, /**< Terminate search and use87this data class for88parsing */89};9091const char *bhnd_nvram_data_class_desc(bhnd_nvram_data_class *cls);92uint32_t bhnd_nvram_data_class_caps(bhnd_nvram_data_class *cls);9394int bhnd_nvram_data_serialize(bhnd_nvram_data_class *cls,95bhnd_nvram_plist *props, bhnd_nvram_plist *options,96void *outp, size_t *olen);9798int bhnd_nvram_data_probe(bhnd_nvram_data_class *cls,99struct bhnd_nvram_io *io);100int bhnd_nvram_data_probe_classes(101struct bhnd_nvram_data **data,102struct bhnd_nvram_io *io,103bhnd_nvram_data_class *classes[],104size_t num_classes);105106int bhnd_nvram_data_getvar_direct(107bhnd_nvram_data_class *cls,108struct bhnd_nvram_io *io, const char *name,109void *buf, size_t *len, bhnd_nvram_type type);110111int bhnd_nvram_data_new(bhnd_nvram_data_class *cls,112struct bhnd_nvram_data **nv,113struct bhnd_nvram_io *io);114115struct bhnd_nvram_data *bhnd_nvram_data_retain(struct bhnd_nvram_data *nv);116void bhnd_nvram_data_release(struct bhnd_nvram_data *nv);117118bhnd_nvram_data_class *bhnd_nvram_data_get_class(struct bhnd_nvram_data *nv);119120size_t bhnd_nvram_data_count(struct bhnd_nvram_data *nv);121bhnd_nvram_plist *bhnd_nvram_data_options(struct bhnd_nvram_data *nv);122uint32_t bhnd_nvram_data_caps(struct bhnd_nvram_data *nv);123124const char *bhnd_nvram_data_next(struct bhnd_nvram_data *nv,125void **cookiep);126void *bhnd_nvram_data_find(struct bhnd_nvram_data *nv,127const char *name);128129int bhnd_nvram_data_getvar_order(130struct bhnd_nvram_data *nv, void *cookiep1,131void *cookiep2);132133int bhnd_nvram_data_getvar(struct bhnd_nvram_data *nv,134void *cookiep, void *buf, size_t *len,135bhnd_nvram_type type);136137const void *bhnd_nvram_data_getvar_ptr(struct bhnd_nvram_data *nv,138void *cookiep, size_t *len, bhnd_nvram_type *type);139140const char *bhnd_nvram_data_getvar_name(struct bhnd_nvram_data *nv,141void *cookiep);142143int bhnd_nvram_data_copy_val(struct bhnd_nvram_data *nv,144void *cookiep, bhnd_nvram_val **val);145146int bhnd_nvram_data_filter_setvar(147struct bhnd_nvram_data *nv, const char *name,148bhnd_nvram_val *value, bhnd_nvram_val **result);149int bhnd_nvram_data_filter_unsetvar(150struct bhnd_nvram_data *nv, const char *name);151152#endif /* _BHND_NVRAM_BHND_NVRAM_DATA_H_ */153154155