Jacob Garber | 10999ea6 | 2020-05-18 13:36:58 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Hung-Te Lin | 6eaaafa | 2014-02-21 16:21:00 +0800 | [diff] [blame] | 2 | |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 3 | #ifndef __VPD_H__ |
| 4 | #define __VPD_H__ |
Hung-Te Lin | 6eaaafa | 2014-02-21 16:21:00 +0800 | [diff] [blame] | 5 | |
Julius Werner | a214837 | 2019-11-13 19:50:33 -0800 | [diff] [blame] | 6 | #include <types.h> |
Elyes HAOUAS | 749c395 | 2019-10-20 19:55:56 +0200 | [diff] [blame] | 7 | |
Jonathan Zhang | b5392f9 | 2019-07-16 14:37:23 -0700 | [diff] [blame] | 8 | #define GOOGLE_VPD_2_0_OFFSET 0x600 |
| 9 | |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 10 | enum vpd_region { |
Jonathan Zhang | 9b110bf | 2020-05-28 13:35:44 -0700 | [diff] [blame] | 11 | VPD_RO, |
| 12 | VPD_RW, |
| 13 | VPD_RO_THEN_RW, |
| 14 | VPD_RW_THEN_RO |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 15 | }; |
Jonathan Zhang | b5392f9 | 2019-07-16 14:37:23 -0700 | [diff] [blame] | 16 | |
Hung-Te Lin | 6eaaafa | 2014-02-21 16:21:00 +0800 | [diff] [blame] | 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 | */ |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 26 | char *vpd_gets(const char *key, char *buffer, int size, enum vpd_region region); |
Hung-Te Lin | 6eaaafa | 2014-02-21 16:21:00 +0800 | [diff] [blame] | 27 | |
Vadim Bendebury | 127c339 | 2014-10-22 17:39:24 -0700 | [diff] [blame] | 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 | |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 42 | const void *vpd_find(const char *key, int *size, enum vpd_region region); |
Vadim Bendebury | 127c339 | 2014-10-22 17:39:24 -0700 | [diff] [blame] | 43 | |
Jonathan Zhang | b5392f9 | 2019-07-16 14:37:23 -0700 | [diff] [blame] | 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 | |
Nico Huber | c00ffef | 2020-09-27 16:21:22 +0200 | [diff] [blame] | 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 | |
Subrata Banik | f45fcd1 | 2024-02-26 11:48:03 +0530 | [diff] [blame^] | 62 | /* |
| 63 | * Return the value after reading the VPD key named "feature_device_info". |
| 64 | */ |
| 65 | const char *vpd_get_feature_device_info(void); |
| 66 | |
Patrick Rudolph | 28cee59 | 2018-03-08 15:43:12 +0100 | [diff] [blame] | 67 | #endif /* __VPD_H__ */ |