Path: blob/main/sys/dev/bhnd/nvram/bhnd_nvram_iovar.h
39536 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_IOVAR_H_31#define _BHND_NVRAM_BHND_NVRAM_IOVAR_H_3233#include <sys/param.h>3435#include "bhnd_nvram_io.h"3637/** @see bhnd_nvram_io_read() */38typedef int (bhnd_nvram_iop_read)(struct bhnd_nvram_io *io, size_t offset,39void *buffer, size_t nbytes);4041/** @see bhnd_nvram_io_read_ptr() */42typedef int (bhnd_nvram_iop_read_ptr)(struct bhnd_nvram_io *io, size_t offset,43const void **ptr, size_t nbytes, size_t *navail);4445/** @see bhnd_nvram_io_write() */46typedef int (bhnd_nvram_iop_write)(struct bhnd_nvram_io *io, size_t offset,47void *buffer, size_t nbytes);4849/** @see bhnd_nvram_io_write_ptr() */50typedef int (bhnd_nvram_iop_write_ptr)(struct bhnd_nvram_io *io, size_t offset,51void **ptr, size_t nbytes, size_t *navail);5253/** @see bhnd_nvram_io_getsize() */54typedef size_t (bhnd_nvram_iop_getsize)(struct bhnd_nvram_io *io);5556/** @see bhnd_nvram_io_setsize() */57typedef int (bhnd_nvram_iop_setsize)(struct bhnd_nvram_io *io, size_t size);5859/** @see bhnd_nvram_io_free() */60typedef void (bhnd_nvram_iop_free)(struct bhnd_nvram_io *io);6162/**63* NVRAM abstract I/O operations.64*/65struct bhnd_nvram_iops {66bhnd_nvram_iop_read *read; /**< read() implementation */67bhnd_nvram_iop_read_ptr *read_ptr; /**< read_ptr() implementation */68bhnd_nvram_iop_getsize *getsize; /**< getsize() implementation */69bhnd_nvram_iop_setsize *setsize; /**< setsize() implementation */70bhnd_nvram_iop_write *write; /**< write() implementation */71bhnd_nvram_iop_write_ptr *write_ptr; /**< write_ptr() implementation */72bhnd_nvram_iop_free *free; /**< free() implementation */73};7475/**76* NVRAM abstract I/O context.77*/78struct bhnd_nvram_io {79const struct bhnd_nvram_iops *iops;80};8182/**83* Declare a bhnd_nvram_iops class with name @p _n.84*/85#define BHND_NVRAM_IOPS_DEFN(_n) \86static bhnd_nvram_iop_read bhnd_nvram_ ## _n ## _read; \87static bhnd_nvram_iop_read_ptr bhnd_nvram_ ## _n ## _read_ptr; \88static bhnd_nvram_iop_write bhnd_nvram_ ## _n ## _write; \89static bhnd_nvram_iop_write_ptr bhnd_nvram_ ## _n ## _write_ptr;\90static bhnd_nvram_iop_getsize bhnd_nvram_ ## _n ## _getsize; \91static bhnd_nvram_iop_setsize bhnd_nvram_ ## _n ## _setsize; \92static bhnd_nvram_iop_free bhnd_nvram_ ## _n ## _free; \93\94static struct bhnd_nvram_iops bhnd_nvram_ ## _n ## _ops = { \95.read = bhnd_nvram_ ## _n ## _read, \96.read_ptr = bhnd_nvram_ ## _n ## _read_ptr, \97.write = bhnd_nvram_ ## _n ## _write, \98.write_ptr = bhnd_nvram_ ## _n ## _write_ptr, \99.getsize = bhnd_nvram_ ## _n ## _getsize, \100.setsize = bhnd_nvram_ ## _n ## _setsize, \101.free = bhnd_nvram_ ## _n ## _free \102};103104#endif /* _BHND_NVRAM_BHND_NVRAM_IOVAR_H_ */105106107