1 /*
2 Copyright (c) 2018, MIPI Alliance, Inc.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 * Redistributions of source code must retain the above copyright
10   notice, this list of conditions and the following disclaimer.
11 
12 * Redistributions in binary form must reproduce the above copyright
13   notice, this list of conditions and the following disclaimer in
14   the documentation and/or other materials provided with the
15   distribution.
16 
17 * Neither the name of the copyright holder nor the names of its
18   contributors may be used to endorse or promote products derived
19   from this software without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 /*
35  * Contributors:
36  * Norbert Schulz (Intel Corporation) - Initial API and implementation
37  */
38 
39 /* Internal message storage buffering */
40 
41 #ifndef MIPI_syst_msg_INCLUDED
42 #define MIPI_syst_msg_INCLUDED
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * Catalog ID container
50  */
51 union mipi_syst_catid {
52 	mipi_syst_u32 sci_32;
53 	mipi_syst_u64 sci_64;
54 } ;
55 
56 /**
57  * SyS-T message descriptor
58  *
59  *  This structure stores a SyS-T message in "logical" memory format.
60  *  Logical means that all optional fields are present but not necessarily
61  *  used. Variable length payloads are addressed through a pointer and
62  *  are not copied into the structure.
63  */
64  struct mipi_syst_msgdsc {
65 	struct mipi_syst_msg_tag ed_tag;
66 			     /**< 32-bit message tag  (mandatory)       */
67 #if defined(MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID)
68 	struct mipi_syst_guid ed_guid; /**< origin GUID    (optional)   */
69 #endif
70 
71 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
72 	struct mipi_syst_msglocation ed_loc;
73 			     /**< message source location (optional)    */
74 #endif
75 #if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP)
76 	mipi_syst_u64 ed_ts;  /**< protocol embedded time stamp         */
77 #endif
78 
79 #if defined(MIPI_SYST_PCFG_LENGTH_FIELD)
80 	mipi_syst_u16 ed_len;  /**< variable payload length (optional)  */
81 #endif
82 
83 	union {
84 		struct {
85 			mipi_syst_u64 id;
86 			const void *text;
87 		} data_version;
88 
89 		struct {
90 			union mipi_syst_catid id;
91 			mipi_syst_u32 *param;
92 		} data_catid;
93 
94 #if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP)
95 		mipi_syst_u64 data_clock[2];
96 #endif
97 		const void *data_var;   /**< variable length payload        */
98 	} ed_pld;
99 
100 #if defined(MIPI_SYST_PCFG_ENABLE_CHECKSUM)
101 	mipi_syst_u32 ed_chk;           /**< message checksum (optional)    */
102 #endif
103 };
104 
105 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
106 #define MIPI_SYST_EVDSC_MEMBER_OFF(m)\
107 	((mipi_syst_u16)(mipi_syst_u64)&(((struct mipi_syst_msgdsc*)0)->m))
108 #else
109 #define MIPI_SYST_EVDSC_MEMBER_OFF(m)\
110 	((mipi_syst_u16)(mipi_syst_u32)&(((struct mipi_syst_msgdsc*)0)->m))
111 #endif
112 
113 /**
114  * message scatter write operations
115  */
116 enum u_syst_scatter_op {
117 	MIPI_SYST_SCATTER_OP_SKIP = 0x00,
118 				/**< skip sso_length bytes          */
119 
120 	MIPI_SYST_SCATTER_OP_8BIT = 0x01,
121 				/**< write sso_length times 8 bit   */
122 	MIPI_SYST_SCATTER_OP_16BIT = 0x02,
123 				/**< write sso_length times 16 bit  */
124 	MIPI_SYST_SCATTER_OP_32BIT = 0x04,
125 				/**< write sso_length times 32 bit  */
126 	MIPI_SYST_SCATTER_OP_64BIT = 0x08,
127 				/**< write sso_length times 64 bit  */
128 
129 	MIPI_SYST_SCATTER_OP_BLOB = 0x10,
130 				/**< write sso_length bytes that are
131 				  *  accessed through a pointer   */
132 	MIPI_SYST_SCATTER_OP_END = 0xFF
133 				/**< end of scatter writer program  */
134 };
135 
136 /**
137  *  message scatter write instruction definition
138  */
139 struct mipi_syst_scatter_prog {
140 	mipi_syst_u8 sso_opcode;	/**< scatter write operation
141 				 *   @see u_syst_scatter_op            */
142 	mipi_syst_u8 sso_offset;	/**< data offset in message descriptor    */
143 	mipi_syst_u16 sso_length;
144 				/**< repeat count for sso_opcode       */
145 };
146 
147 #define MIPI_SYST_SCATTER_PROG_LEN   10    /**< maximum needed scatter prog size   */
148 
149 #if defined(MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE)
150 /* default scatter write routine */
151 extern void mipi_syst_scatter_write(struct mipi_syst_handle* systh,
152 		struct mipi_syst_scatter_prog* scatterprog,
153 		const void *pdesc);
154 #endif
155 
156 #ifdef __cplusplus
157 }	/* extern C */
158 #endif
159 #endif
160