1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 3 #ifndef __VPD_H__ 4 #define __VPD_H__ 5 6 #include <types.h> 7 8 #define GOOGLE_VPD_2_0_OFFSET 0x600 9 10 enum vpd_region { 11 VPD_RO, 12 VPD_RW, 13 VPD_RO_THEN_RW, 14 VPD_RW_THEN_RO 15 }; 16 17 /* 18 * Reads VPD string value by key. 19 * 20 * Reads in at most one less than size characters from VPD and stores them 21 * into buffer. A terminating null byte ('\0') is stored after the last 22 * character in the buffer. 23 * 24 * Returns NULL if key is not found, otherwise buffer. 25 */ 26 char *vpd_gets(const char *key, char *buffer, int size, enum vpd_region region); 27 28 /* 29 * Find VPD value by key. 30 * 31 * Searches for a VPD entry in the VPD cache. If found, places the size of the 32 * entry into '*size' and returns the pointer to the entry data. 33 * 34 * This function presumes that VPD is cached in DRAM (which is the case in the 35 * current implementation) and as such returns the pointer into the cache. The 36 * user is not supposed to modify the data, and does not have to free the 37 * memory. 38 * 39 * Returns NULL if key is not found. 40 */ 41 42 const void *vpd_find(const char *key, int *size, enum vpd_region region); 43 44 /* 45 * Find value of boolean type vpd key. 46 * 47 * During the process, necessary checking is done, such as making 48 * sure the value length is 1, and value is either '1' or '0'. 49 */ 50 bool vpd_get_bool(const char *key, enum vpd_region region, 51 uint8_t *val); 52 53 /* 54 * Find value of integer type by vpd key. 55 * 56 * Expects to find a decimal string, trailing chars are ignored. 57 * Returns true if the key is found and the value is not too long and 58 * starts with a decimal digit. 59 */ 60 bool vpd_get_int(const char *key, enum vpd_region region, int *val); 61 62 /* 63 * Extracts the "feature_level" from the "feature_device_info" VPD key. 64 * This key holds a base64-encoded protobuf where "feature_level" is the first entry. 65 */ 66 uint8_t vpd_get_feature_level(void); 67 68 #endif /* __VPD_H__ */ 69