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 /*  Instrumentation API inline code definitions */
40 
41 #ifndef MIPI_SYST_INLINE_INCLUDED
42 #define MIPI_SYST_INLINE_INCLUDED
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
49 
50 /**
51  * Update File Location in syst handle
52  * @param h syst handle pointer
53  * @param f file id (16 bit)
54  * @param l line number in file (16 bit)
55  */
56 MIPI_SYST_INLINE struct mipi_syst_msglocation* MIPI_SYST_CALLCONV
mipi_syst_make_file_location32(struct mipi_syst_handle * h,mipi_syst_u16 f,mipi_syst_u16 l)57 mipi_syst_make_file_location32(struct mipi_syst_handle* h, mipi_syst_u16 f, mipi_syst_u16 l)
58 {
59 	if (h) {
60 		h->systh_location.el_format = 0;
61 		h->systh_location.el_u.loc32.etls_source_location.etls_fileID = f;
62 		h->systh_location.el_u.loc32.etls_source_location.etls_lineNo = l;
63 	}
64 
65 	return &h->systh_location;
66 }
67 /**
68  * Update File Location in syst handle
69  * @param h syst handle pointer
70  * @param f file id (32 bit)
71  * @param l line number in file (32 bit)
72  */
73 MIPI_SYST_INLINE struct mipi_syst_msglocation* MIPI_SYST_CALLCONV
mipi_syst_make_file_location64(struct mipi_syst_handle * h,mipi_syst_u32 f,mipi_syst_u32 l)74 mipi_syst_make_file_location64(struct mipi_syst_handle* h, mipi_syst_u32 f, mipi_syst_u32 l)
75 {
76 	if (h) {
77 		h->systh_location.el_format = 1;
78 		h->systh_location.el_u.loc64.etls_source_location.etls_fileID = f;
79 		h->systh_location.el_u.loc64.etls_source_location.etls_lineNo = l;
80 	}
81 
82 	return &h->systh_location;
83 }
84 
85 /**
86  * Update address Location in syst handle
87  * @param h syst handle pointer
88  * @param p address at instrumentation point
89  */
90 MIPI_SYST_INLINE struct mipi_syst_msglocation* MIPI_SYST_CALLCONV
mipi_syst_make_address_location(struct mipi_syst_handle * h,void * p)91 mipi_syst_make_address_location(struct mipi_syst_handle* h, void *p)
92 {
93 	if (h) {
94 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
95 
96 		h->systh_location.el_format = 3;
97 		h->systh_location.el_u.loc64.etls_code_location = (mipi_syst_u64) p;
98 #else
99 		h->systh_location.el_format = 2;
100 		h->systh_location.el_u.loc32.etls_code_location = (mipi_syst_u32) p;
101 #endif
102 	}
103 	return &h->systh_location;
104 }
105 
106 #endif	/* defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD) */
107 
108 /**
109  * Setup handle for 0 parameters passed to catid message.
110  */
mipi_syst_make_param0(struct mipi_syst_handle * h)111 MIPI_SYST_INLINE void MIPI_SYST_CALLCONV mipi_syst_make_param0(struct mipi_syst_handle* h)
112 {
113 	if (h)
114 		h->systh_param_count = 0;
115 }
116 /**
117  * Setup handle for 1 parameter passed to catid message.
118  */
mipi_syst_make_param1(struct mipi_syst_handle * h,mipi_syst_u32 p1)119 MIPI_SYST_INLINE void MIPI_SYST_CALLCONV mipi_syst_make_param1(struct mipi_syst_handle* h,
120 						 mipi_syst_u32 p1)
121 {
122 	if (h) {
123 		h->systh_param_count = 1;
124 		h->systh_param[0] = p1;
125 	}
126 }
127 
128 /**
129  * Setup handle for 2 parameters passed to catid message.
130  */
mipi_syst_make_param2(struct mipi_syst_handle * h,mipi_syst_u32 p1,mipi_syst_u32 p2)131 MIPI_SYST_INLINE void MIPI_SYST_CALLCONV mipi_syst_make_param2(struct mipi_syst_handle* h,
132 						 mipi_syst_u32 p1,
133 						 mipi_syst_u32 p2)
134 {
135 	if (h) {
136 		h->systh_param_count = 2;
137 		h->systh_param[0] = p1;
138 		h->systh_param[1] = p2;
139 	}
140 }
141 
142 /**
143  * Setup handle for 3 parameters passed to catid message.
144  */
mipi_syst_make_param3(struct mipi_syst_handle * h,mipi_syst_u32 p1,mipi_syst_u32 p2,mipi_syst_u32 p3)145 MIPI_SYST_INLINE void MIPI_SYST_CALLCONV mipi_syst_make_param3(struct mipi_syst_handle* h,
146 						 mipi_syst_u32 p1,
147 						 mipi_syst_u32 p2,
148 						 mipi_syst_u32 p3)
149 {
150 	if (h) {
151 		h->systh_param_count = 3;
152 		h->systh_param[0] = p1;
153 		h->systh_param[1] = p2;
154 		h->systh_param[2] = p3;
155 	}
156 }
157 
158 /**
159  * Setup handle for 4 parameters passed to catid message.
160  */
mipi_syst_make_param4(struct mipi_syst_handle * h,mipi_syst_u32 p1,mipi_syst_u32 p2,mipi_syst_u32 p3,mipi_syst_u32 p4)161 MIPI_SYST_INLINE void MIPI_SYST_CALLCONV mipi_syst_make_param4(struct mipi_syst_handle* h,
162 						 mipi_syst_u32 p1,
163 						 mipi_syst_u32 p2,
164 						 mipi_syst_u32 p3,
165 						 mipi_syst_u32 p4)
166 {
167 	if (h) {
168 		h->systh_param_count = 4;
169 		h->systh_param[0] = p1;
170 		h->systh_param[1] = p2;
171 		h->systh_param[2] = p3;
172 		h->systh_param[3] = p4;
173 	}
174 }
175 
176 /**
177  * Setup handle for 5 parameters passed to catid message.
178  */
mipi_syst_make_param5(struct mipi_syst_handle * h,mipi_syst_u32 p1,mipi_syst_u32 p2,mipi_syst_u32 p3,mipi_syst_u32 p4,mipi_syst_u32 p5)179 MIPI_SYST_INLINE void MIPI_SYST_CALLCONV mipi_syst_make_param5(struct mipi_syst_handle* h,
180 						 mipi_syst_u32 p1,
181 						 mipi_syst_u32 p2,
182 						 mipi_syst_u32 p3,
183 						 mipi_syst_u32 p4,
184 						 mipi_syst_u32 p5)
185 {
186 	if (h) {
187 		h->systh_param_count = 5;
188 		h->systh_param[0] = p1;
189 		h->systh_param[1] = p2;
190 		h->systh_param[2] = p3;
191 		h->systh_param[3] = p4;
192 		h->systh_param[4] = p5;
193 	}
194 }
195 
196 /**
197  * Setup handle for 6 parameters passed to catid message.
198  */
mipi_syst_make_param6(struct mipi_syst_handle * h,mipi_syst_u32 p1,mipi_syst_u32 p2,mipi_syst_u32 p3,mipi_syst_u32 p4,mipi_syst_u32 p5,mipi_syst_u32 p6)199 MIPI_SYST_INLINE void MIPI_SYST_CALLCONV mipi_syst_make_param6(struct mipi_syst_handle* h,
200 						 mipi_syst_u32 p1,
201 						 mipi_syst_u32 p2,
202 						 mipi_syst_u32 p3,
203 						 mipi_syst_u32 p4,
204 						 mipi_syst_u32 p5,
205 						 mipi_syst_u32 p6)
206 {
207 	if (h) {
208 		h->systh_param_count = 6;
209 		h->systh_param[0] = p1;
210 		h->systh_param[1] = p2;
211 		h->systh_param[2] = p3;
212 		h->systh_param[3] = p4;
213 		h->systh_param[4] = p5;
214 		h->systh_param[5] = p6;
215 	}
216 }
217 
218 /**
219  * Runtime computation of hash values for catalog message IDs.
220  * This function is used in debug builds to avoid a code explosion
221  * by the preprocessor method ( @see mipi_syst_hash_x65599 ). The
222  * preprocesssor methods does compute this value at compile time only
223  * if const expression optimisations are enabled.
224  */
mipi_syst_hash_x65599(const char * p,mipi_syst_u32 length)225 MIPI_SYST_INLINE  mipi_syst_u32 mipi_syst_hash_x65599(
226 	const char * p, mipi_syst_u32 length)
227 {
228 	mipi_syst_u32 hash;
229 	mipi_syst_u8 c;
230 	hash = 0;
231 
232 	p += (length > 0x3F) ? (length-0x40): 0;
233 
234 	while (0 != (c = *p++))
235 	{
236 		hash = hash * 65599U + c;
237 	}
238 
239 	return hash;
240 }
241 #ifdef __cplusplus
242 }	/* extern C */
243 #endif
244 
245 #endif
246