blob: a23005fca1c5b7a13690291041973112081d49a5 [file] [log] [blame]
Jacob Garber10999ea62020-05-18 13:36:58 -06001/* SPDX-License-Identifier: BSD-3-Clause */
Hung-Te Lin6eaaafa2014-02-21 16:21:00 +08002
Patrick Rudolph28cee592018-03-08 15:43:12 +01003#ifndef __VPD_H__
4#define __VPD_H__
Hung-Te Lin6eaaafa2014-02-21 16:21:00 +08005
Julius Wernera2148372019-11-13 19:50:33 -08006#include <types.h>
Elyes HAOUAS749c3952019-10-20 19:55:56 +02007
Jonathan Zhangb5392f92019-07-16 14:37:23 -07008#define GOOGLE_VPD_2_0_OFFSET 0x600
9
Patrick Rudolph28cee592018-03-08 15:43:12 +010010enum vpd_region {
Jonathan Zhang9b110bf2020-05-28 13:35:44 -070011 VPD_RO,
12 VPD_RW,
13 VPD_RO_THEN_RW,
14 VPD_RW_THEN_RO
Patrick Rudolph28cee592018-03-08 15:43:12 +010015};
Jonathan Zhangb5392f92019-07-16 14:37:23 -070016
Hung-Te Lin6eaaafa2014-02-21 16:21:00 +080017/*
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 */
Patrick Rudolph28cee592018-03-08 15:43:12 +010026char *vpd_gets(const char *key, char *buffer, int size, enum vpd_region region);
Hung-Te Lin6eaaafa2014-02-21 16:21:00 +080027
Vadim Bendebury127c3392014-10-22 17:39:24 -070028/*
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
Patrick Rudolph28cee592018-03-08 15:43:12 +010042const void *vpd_find(const char *key, int *size, enum vpd_region region);
Vadim Bendebury127c3392014-10-22 17:39:24 -070043
Jonathan Zhangb5392f92019-07-16 14:37:23 -070044/*
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 */
50bool vpd_get_bool(const char *key, enum vpd_region region,
51 uint8_t *val);
52
Nico Huberc00ffef2020-09-27 16:21:22 +020053/*
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 */
60bool vpd_get_int(const char *key, enum vpd_region region, int *val);
61
Subrata Banikf45fcd12024-02-26 11:48:03 +053062/*
63 * Return the value after reading the VPD key named "feature_device_info".
64 */
65const char *vpd_get_feature_device_info(void);
66
Patrick Rudolph28cee592018-03-08 15:43:12 +010067#endif /* __VPD_H__ */