2 * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
32 #ifndef _BHND_NVRAM_BHND_NVRAM_IOVAR_H_
33 #define _BHND_NVRAM_BHND_NVRAM_IOVAR_H_
35 #include <sys/param.h>
37 #include "bhnd_nvram_io.h"
39 /** @see bhnd_nvram_io_read() */
40 typedef int (bhnd_nvram_iop_read)(struct bhnd_nvram_io *io, size_t offset,
41 void *buffer, size_t nbytes);
43 /** @see bhnd_nvram_io_read_ptr() */
44 typedef int (bhnd_nvram_iop_read_ptr)(struct bhnd_nvram_io *io, size_t offset,
45 const void **ptr, size_t nbytes, size_t *navail);
47 /** @see bhnd_nvram_io_write() */
48 typedef int (bhnd_nvram_iop_write)(struct bhnd_nvram_io *io, size_t offset,
49 void *buffer, size_t nbytes);
51 /** @see bhnd_nvram_io_write_ptr() */
52 typedef int (bhnd_nvram_iop_write_ptr)(struct bhnd_nvram_io *io, size_t offset,
53 void **ptr, size_t nbytes, size_t *navail);
55 /** @see bhnd_nvram_io_getsize() */
56 typedef size_t (bhnd_nvram_iop_getsize)(struct bhnd_nvram_io *io);
58 /** @see bhnd_nvram_io_setsize() */
59 typedef int (bhnd_nvram_iop_setsize)(struct bhnd_nvram_io *io, size_t size);
61 /** @see bhnd_nvram_io_free() */
62 typedef void (bhnd_nvram_iop_free)(struct bhnd_nvram_io *io);
65 * NVRAM abstract I/O operations.
67 struct bhnd_nvram_iops {
68 bhnd_nvram_iop_read *read; /**< read() implementation */
69 bhnd_nvram_iop_read_ptr *read_ptr; /**< read_ptr() implementation */
70 bhnd_nvram_iop_getsize *getsize; /**< getsize() implementation */
71 bhnd_nvram_iop_setsize *setsize; /**< setsize() implementation */
72 bhnd_nvram_iop_write *write; /**< write() implementation */
73 bhnd_nvram_iop_write_ptr *write_ptr; /**< write_ptr() implementation */
74 bhnd_nvram_iop_free *free; /**< free() implementation */
78 * NVRAM abstract I/O context.
80 struct bhnd_nvram_io {
81 const struct bhnd_nvram_iops *iops;
85 * Declare a bhnd_nvram_iops class with name @p _n.
87 #define BHND_NVRAM_IOPS_DEFN(_n) \
88 static bhnd_nvram_iop_read bhnd_nvram_ ## _n ## _read; \
89 static bhnd_nvram_iop_read_ptr bhnd_nvram_ ## _n ## _read_ptr; \
90 static bhnd_nvram_iop_write bhnd_nvram_ ## _n ## _write; \
91 static bhnd_nvram_iop_write_ptr bhnd_nvram_ ## _n ## _write_ptr;\
92 static bhnd_nvram_iop_getsize bhnd_nvram_ ## _n ## _getsize; \
93 static bhnd_nvram_iop_setsize bhnd_nvram_ ## _n ## _setsize; \
94 static bhnd_nvram_iop_free bhnd_nvram_ ## _n ## _free; \
96 static struct bhnd_nvram_iops bhnd_nvram_ ## _n ## _ops = { \
97 .read = bhnd_nvram_ ## _n ## _read, \
98 .read_ptr = bhnd_nvram_ ## _n ## _read_ptr, \
99 .write = bhnd_nvram_ ## _n ## _write, \
100 .write_ptr = bhnd_nvram_ ## _n ## _write_ptr, \
101 .getsize = bhnd_nvram_ ## _n ## _getsize, \
102 .setsize = bhnd_nvram_ ## _n ## _setsize, \
103 .free = bhnd_nvram_ ## _n ## _free \
106 #endif /* _BHND_NVRAM_BHND_NVRAM_IOVAR_H_ */