Path: blob/main/sys/dev/bhnd/nvram/bhnd_nvram_io.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_IO_H_31#define _BHND_NVRAM_BHND_NVRAM_IO_H_3233#ifdef _KERNEL34#include <sys/param.h>3536#include <dev/bhnd/bhnd.h>37#else /* !_KERNEL */38#include <errno.h>3940#include <stdbool.h>41#include <stdint.h>42#include <stdlib.h>43#endif /* _KERNEL */4445struct bhnd_nvram_io;4647struct bhnd_nvram_io *bhnd_nvram_iobuf_new(const void *buffer, size_t size);48struct bhnd_nvram_io *bhnd_nvram_iobuf_empty(size_t size, size_t capacity);49struct bhnd_nvram_io *bhnd_nvram_iobuf_copy(struct bhnd_nvram_io *src);50struct bhnd_nvram_io *bhnd_nvram_iobuf_copy_range(struct bhnd_nvram_io *src,51size_t offset, size_t size);5253struct bhnd_nvram_io *bhnd_nvram_ioptr_new(const void *ptr, size_t size,54size_t capacity, uint32_t flags);5556#ifdef _KERNEL57struct bhnd_nvram_io *bhnd_nvram_iores_new(struct bhnd_resource *r,58bus_size_t offset, bus_size_t size,59u_int bus_width);60#endif /* _KERNEL */6162size_t bhnd_nvram_io_getsize(struct bhnd_nvram_io *io);63int bhnd_nvram_io_setsize(struct bhnd_nvram_io *io,64size_t size);6566int bhnd_nvram_io_read(struct bhnd_nvram_io *io,67size_t offset, void *buffer, size_t nbytes);68int bhnd_nvram_io_read_ptr(struct bhnd_nvram_io *io,69size_t offset, const void **ptr, size_t nbytes,70size_t *navail);7172int bhnd_nvram_io_write(struct bhnd_nvram_io *io,73size_t offset, void *buffer, size_t nbytes);74int bhnd_nvram_io_write_ptr(struct bhnd_nvram_io *io,75size_t offset, void **ptr, size_t nbytes,76size_t *navail);7778void bhnd_nvram_io_free(struct bhnd_nvram_io *io);7980/**81* bhnd_nvram_ioptr flags82*/83enum {84BHND_NVRAM_IOPTR_RDONLY = (1<<0), /**< read-only */85BHND_NVRAM_IOPTR_RDWR = (1<<1), /**< read/write */86};8788#endif /* _BHND_NVRAM_BHND_NVRAM_IO_H_ */899091