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