xref: /linux/drivers/firmware/coreboot/vpd_decode.h (revision 9e947d96915af63e28896caae85a81b74855621b)
1*44e33a5aSSean Rhodes /* SPDX-License-Identifier: GPL-2.0-only */
2*44e33a5aSSean Rhodes /*
3*44e33a5aSSean Rhodes  * vpd_decode.h
4*44e33a5aSSean Rhodes  *
5*44e33a5aSSean Rhodes  * Google VPD decoding routines.
6*44e33a5aSSean Rhodes  *
7*44e33a5aSSean Rhodes  * Copyright 2017 Google Inc.
8*44e33a5aSSean Rhodes  */
9*44e33a5aSSean Rhodes 
10*44e33a5aSSean Rhodes #ifndef __VPD_DECODE_H
11*44e33a5aSSean Rhodes #define __VPD_DECODE_H
12*44e33a5aSSean Rhodes 
13*44e33a5aSSean Rhodes #include <linux/types.h>
14*44e33a5aSSean Rhodes 
15*44e33a5aSSean Rhodes enum {
16*44e33a5aSSean Rhodes 	VPD_OK = 0,
17*44e33a5aSSean Rhodes 	VPD_FAIL,
18*44e33a5aSSean Rhodes };
19*44e33a5aSSean Rhodes 
20*44e33a5aSSean Rhodes enum {
21*44e33a5aSSean Rhodes 	VPD_TYPE_TERMINATOR = 0,
22*44e33a5aSSean Rhodes 	VPD_TYPE_STRING,
23*44e33a5aSSean Rhodes 	VPD_TYPE_INFO                = 0xfe,
24*44e33a5aSSean Rhodes 	VPD_TYPE_IMPLICIT_TERMINATOR = 0xff,
25*44e33a5aSSean Rhodes };
26*44e33a5aSSean Rhodes 
27*44e33a5aSSean Rhodes /* Callback for vpd_decode_string to invoke. */
28*44e33a5aSSean Rhodes typedef int vpd_decode_callback(const u8 *key, u32 key_len,
29*44e33a5aSSean Rhodes 				const u8 *value, u32 value_len,
30*44e33a5aSSean Rhodes 				void *arg);
31*44e33a5aSSean Rhodes 
32*44e33a5aSSean Rhodes /*
33*44e33a5aSSean Rhodes  * vpd_decode_string
34*44e33a5aSSean Rhodes  *
35*44e33a5aSSean Rhodes  * Given the encoded string, this function invokes callback with extracted
36*44e33a5aSSean Rhodes  * (key, value). The *consumed will be plused the number of bytes consumed in
37*44e33a5aSSean Rhodes  * this function.
38*44e33a5aSSean Rhodes  *
39*44e33a5aSSean Rhodes  * The input_buf points to the first byte of the input buffer.
40*44e33a5aSSean Rhodes  *
41*44e33a5aSSean Rhodes  * The *consumed starts from 0, which is actually the next byte to be decoded.
42*44e33a5aSSean Rhodes  * It can be non-zero to be used in multiple calls.
43*44e33a5aSSean Rhodes  *
44*44e33a5aSSean Rhodes  * If one entry is successfully decoded, sends it to callback and returns the
45*44e33a5aSSean Rhodes  * result.
46*44e33a5aSSean Rhodes  */
47*44e33a5aSSean Rhodes int vpd_decode_string(const u32 max_len, const u8 *input_buf, u32 *consumed,
48*44e33a5aSSean Rhodes 		      vpd_decode_callback callback, void *callback_arg);
49*44e33a5aSSean Rhodes 
50*44e33a5aSSean Rhodes #endif  /* __VPD_DECODE_H */
51