/*-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_H_31#define _BHND_NVRAM_BHND_NVRAM_H_3233#ifdef _KERNEL34#include <sys/types.h>35#else /* !_KERNEL */36#include <stdbool.h>37#include <stdint.h>38#endif /* _KERNEL */3940/**41* BHND NVRAM boolean type; guaranteed to be exactly 8-bits, representing42* true as integer constant 1, and false as integer constant 0.43*44* Compatible with stdbool constants (true, false).45*/46typedef uint8_t bhnd_nvram_bool_t;4748/**49* NVRAM data sources supported by bhnd(4) devices.50*/51typedef enum {52BHND_NVRAM_SRC_OTP, /**< On-chip one-time-programmable53* memory. */5455BHND_NVRAM_SRC_FLASH, /**< External flash */56BHND_NVRAM_SRC_SPROM, /**< External serial EEPROM. */5758BHND_NVRAM_SRC_UNKNOWN /**< No NVRAM source is directly59* attached.60*61* This will be returned by ChipCommon62* revisions (rev <= 31) used in early63* chipsets that vend SPROM/OTP via the64* native host bridge interface.65*66* For example, PCMCIA cards may vend67* Broadcom NVRAM data via their standard CIS68* table, and earlier PCI(e) devices map69* SPROM statically into PCI BARs, and the70* control registers into PCI config space.7172* This will also be returned on later73* devices that are attached via PCI(e) to74* BHND SoCs, but do not include an attached75* SPROM, or programmed OTP. On such SoCs,76* NVRAM configuration for individual devices77* is provided by a common platform NVRAM78* device.79*/80} bhnd_nvram_src;8182/**83* NVRAM data types.84*85* @internal86*87* All primitive (non-array) constants should be representable as a 4-bit88* integer (e.g. 0-15) to support SPROM_OPCODE_TYPE_IMM encoding as used by89* nvram_map_gen.awk.90*/91typedef enum {92BHND_NVRAM_TYPE_UINT8 = 0, /**< unsigned 8-bit integer */93BHND_NVRAM_TYPE_UINT16 = 1, /**< unsigned 16-bit integer */94BHND_NVRAM_TYPE_UINT32 = 2, /**< unsigned 32-bit integer */95BHND_NVRAM_TYPE_UINT64 = 3, /**< signed 64-bit integer */96BHND_NVRAM_TYPE_INT8 = 4, /**< signed 8-bit integer */97BHND_NVRAM_TYPE_INT16 = 5, /**< signed 16-bit integer */98BHND_NVRAM_TYPE_INT32 = 6, /**< signed 32-bit integer */99BHND_NVRAM_TYPE_INT64 = 7, /**< signed 64-bit integer */100BHND_NVRAM_TYPE_CHAR = 8, /**< ASCII/UTF-8 character */101BHND_NVRAM_TYPE_STRING = 9, /**< ASCII/UTF-8 NUL-terminated102string */103BHND_NVRAM_TYPE_BOOL = 10, /**< uint8 boolean value. see104bhnd_nvram_bool_t. */105BHND_NVRAM_TYPE_NULL = 11, /**< NULL (empty) value */106BHND_NVRAM_TYPE_DATA = 12, /**< opaque octet string */107108/* 10-15 reserved for primitive (non-array) types */109110BHND_NVRAM_TYPE_UINT8_ARRAY = 16, /**< array of uint8 integers */111BHND_NVRAM_TYPE_UINT16_ARRAY = 17, /**< array of uint16 integers */112BHND_NVRAM_TYPE_UINT32_ARRAY = 18, /**< array of uint32 integers */113BHND_NVRAM_TYPE_UINT64_ARRAY = 19, /**< array of uint64 integers */114BHND_NVRAM_TYPE_INT8_ARRAY = 20, /**< array of int8 integers */115BHND_NVRAM_TYPE_INT16_ARRAY = 21, /**< array of int16 integers */116BHND_NVRAM_TYPE_INT32_ARRAY = 22, /**< array of int32 integers */117BHND_NVRAM_TYPE_INT64_ARRAY = 23, /**< array of int64 integers */118BHND_NVRAM_TYPE_CHAR_ARRAY = 24, /**< array of ASCII/UTF-8119characters */120BHND_NVRAM_TYPE_STRING_ARRAY = 25, /**< array of ASCII/UTF-8121NUL-terminated strings */122BHND_NVRAM_TYPE_BOOL_ARRAY = 26, /**< array of uint8 boolean123values */124} bhnd_nvram_type;125126bool bhnd_nvram_is_signed_type(bhnd_nvram_type type);127bool bhnd_nvram_is_unsigned_type(bhnd_nvram_type type);128bool bhnd_nvram_is_int_type(bhnd_nvram_type type);129bool bhnd_nvram_is_array_type(bhnd_nvram_type type);130bhnd_nvram_type bhnd_nvram_base_type(bhnd_nvram_type type);131bhnd_nvram_type bhnd_nvram_raw_type(bhnd_nvram_type type);132const char *bhnd_nvram_type_name(bhnd_nvram_type type);133size_t bhnd_nvram_type_width(bhnd_nvram_type type);134size_t bhnd_nvram_type_host_align(bhnd_nvram_type type);135136const char *bhnd_nvram_string_array_next(const char *inp, size_t ilen,137const char *prev, size_t *olen);138139#endif /* _BHND_NVRAM_BHND_NVRAM_H_ */140141142