1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc.
3bf215546Sopenharmony_ci * All Rights Reserved.
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
8bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
9bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
10bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
14bf215546Sopenharmony_ci * Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci/*
26bf215546Sopenharmony_ci * This file holds the function implementation for one of the rbug extensions.
27bf215546Sopenharmony_ci * Prototypes and declerations of functions and structs is in the same folder
28bf215546Sopenharmony_ci * in the header file matching this file's name.
29bf215546Sopenharmony_ci *
30bf215546Sopenharmony_ci * The functions starting rbug_send_* encodes a call to the write format and
31bf215546Sopenharmony_ci * sends that to the supplied connection, while functions starting with
32bf215546Sopenharmony_ci * rbug_demarshal_* demarshal data in the wire protocol.
33bf215546Sopenharmony_ci *
34bf215546Sopenharmony_ci * Functions ending with _reply are replies to requests.
35bf215546Sopenharmony_ci */
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci#include "rbug_internal.h"
38bf215546Sopenharmony_ci#include "rbug_shader.h"
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_ciint rbug_send_shader_list(struct rbug_connection *__con,
41bf215546Sopenharmony_ci                          rbug_context_t context,
42bf215546Sopenharmony_ci                          uint32_t *__serial)
43bf215546Sopenharmony_ci{
44bf215546Sopenharmony_ci	uint32_t __len = 0;
45bf215546Sopenharmony_ci	uint32_t __pos = 0;
46bf215546Sopenharmony_ci	uint8_t *__data = NULL;
47bf215546Sopenharmony_ci	int __ret = 0;
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci	LEN(8); /* header */
50bf215546Sopenharmony_ci	LEN(8); /* context */
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci	/* align */
53bf215546Sopenharmony_ci	PAD(__len, 8);
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
56bf215546Sopenharmony_ci	if (!__data)
57bf215546Sopenharmony_ci		return -ENOMEM;
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST));
60bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
61bf215546Sopenharmony_ci	WRITE(8, rbug_context_t, context); /* context */
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci	/* final pad */
64bf215546Sopenharmony_ci	PAD(__pos, 8);
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci	if (__pos != __len) {
67bf215546Sopenharmony_ci		__ret = -EINVAL;
68bf215546Sopenharmony_ci	} else {
69bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST, __len);
70bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
71bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
72bf215546Sopenharmony_ci	}
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_ci	FREE(__data);
75bf215546Sopenharmony_ci	return __ret;
76bf215546Sopenharmony_ci}
77bf215546Sopenharmony_ci
78bf215546Sopenharmony_ciint rbug_send_shader_info(struct rbug_connection *__con,
79bf215546Sopenharmony_ci                          rbug_context_t context,
80bf215546Sopenharmony_ci                          rbug_shader_t shader,
81bf215546Sopenharmony_ci                          uint32_t *__serial)
82bf215546Sopenharmony_ci{
83bf215546Sopenharmony_ci	uint32_t __len = 0;
84bf215546Sopenharmony_ci	uint32_t __pos = 0;
85bf215546Sopenharmony_ci	uint8_t *__data = NULL;
86bf215546Sopenharmony_ci	int __ret = 0;
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci	LEN(8); /* header */
89bf215546Sopenharmony_ci	LEN(8); /* context */
90bf215546Sopenharmony_ci	LEN(8); /* shader */
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci	/* align */
93bf215546Sopenharmony_ci	PAD(__len, 8);
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
96bf215546Sopenharmony_ci	if (!__data)
97bf215546Sopenharmony_ci		return -ENOMEM;
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO));
100bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
101bf215546Sopenharmony_ci	WRITE(8, rbug_context_t, context); /* context */
102bf215546Sopenharmony_ci	WRITE(8, rbug_shader_t, shader); /* shader */
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci	/* final pad */
105bf215546Sopenharmony_ci	PAD(__pos, 8);
106bf215546Sopenharmony_ci
107bf215546Sopenharmony_ci	if (__pos != __len) {
108bf215546Sopenharmony_ci		__ret = -EINVAL;
109bf215546Sopenharmony_ci	} else {
110bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len);
111bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
112bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
113bf215546Sopenharmony_ci	}
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci	FREE(__data);
116bf215546Sopenharmony_ci	return __ret;
117bf215546Sopenharmony_ci}
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ciint rbug_send_shader_disable(struct rbug_connection *__con,
120bf215546Sopenharmony_ci                             rbug_context_t context,
121bf215546Sopenharmony_ci                             rbug_shader_t shader,
122bf215546Sopenharmony_ci                             uint8_t disable,
123bf215546Sopenharmony_ci                             uint32_t *__serial)
124bf215546Sopenharmony_ci{
125bf215546Sopenharmony_ci	uint32_t __len = 0;
126bf215546Sopenharmony_ci	uint32_t __pos = 0;
127bf215546Sopenharmony_ci	uint8_t *__data = NULL;
128bf215546Sopenharmony_ci	int __ret = 0;
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci	LEN(8); /* header */
131bf215546Sopenharmony_ci	LEN(8); /* context */
132bf215546Sopenharmony_ci	LEN(8); /* shader */
133bf215546Sopenharmony_ci	LEN(1); /* disable */
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci	/* align */
136bf215546Sopenharmony_ci	PAD(__len, 8);
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
139bf215546Sopenharmony_ci	if (!__data)
140bf215546Sopenharmony_ci		return -ENOMEM;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_DISABLE));
143bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
144bf215546Sopenharmony_ci	WRITE(8, rbug_context_t, context); /* context */
145bf215546Sopenharmony_ci	WRITE(8, rbug_shader_t, shader); /* shader */
146bf215546Sopenharmony_ci	WRITE(1, uint8_t, disable); /* disable */
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci	/* final pad */
149bf215546Sopenharmony_ci	PAD(__pos, 8);
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_ci	if (__pos != __len) {
152bf215546Sopenharmony_ci		__ret = -EINVAL;
153bf215546Sopenharmony_ci	} else {
154bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_SHADER_DISABLE, __len);
155bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
156bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
157bf215546Sopenharmony_ci	}
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci	FREE(__data);
160bf215546Sopenharmony_ci	return __ret;
161bf215546Sopenharmony_ci}
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ciint rbug_send_shader_replace(struct rbug_connection *__con,
164bf215546Sopenharmony_ci                             rbug_context_t context,
165bf215546Sopenharmony_ci                             rbug_shader_t shader,
166bf215546Sopenharmony_ci                             uint32_t *tokens,
167bf215546Sopenharmony_ci                             uint32_t tokens_len,
168bf215546Sopenharmony_ci                             uint32_t *__serial)
169bf215546Sopenharmony_ci{
170bf215546Sopenharmony_ci	uint32_t __len = 0;
171bf215546Sopenharmony_ci	uint32_t __pos = 0;
172bf215546Sopenharmony_ci	uint8_t *__data = NULL;
173bf215546Sopenharmony_ci	int __ret = 0;
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci	LEN(8); /* header */
176bf215546Sopenharmony_ci	LEN(8); /* context */
177bf215546Sopenharmony_ci	LEN(8); /* shader */
178bf215546Sopenharmony_ci	LEN_ARRAY(4, tokens); /* tokens */
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_ci	/* align */
181bf215546Sopenharmony_ci	PAD(__len, 8);
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
184bf215546Sopenharmony_ci	if (!__data)
185bf215546Sopenharmony_ci		return -ENOMEM;
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_REPLACE));
188bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
189bf215546Sopenharmony_ci	WRITE(8, rbug_context_t, context); /* context */
190bf215546Sopenharmony_ci	WRITE(8, rbug_shader_t, shader); /* shader */
191bf215546Sopenharmony_ci	WRITE_ARRAY(4, uint32_t, tokens); /* tokens */
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci	/* final pad */
194bf215546Sopenharmony_ci	PAD(__pos, 8);
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_ci	if (__pos != __len) {
197bf215546Sopenharmony_ci		__ret = -EINVAL;
198bf215546Sopenharmony_ci	} else {
199bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_SHADER_REPLACE, __len);
200bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
201bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
202bf215546Sopenharmony_ci	}
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci	FREE(__data);
205bf215546Sopenharmony_ci	return __ret;
206bf215546Sopenharmony_ci}
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_ciint rbug_send_shader_list_reply(struct rbug_connection *__con,
209bf215546Sopenharmony_ci                                uint32_t serial,
210bf215546Sopenharmony_ci                                rbug_shader_t *shaders,
211bf215546Sopenharmony_ci                                uint32_t shaders_len,
212bf215546Sopenharmony_ci                                uint32_t *__serial)
213bf215546Sopenharmony_ci{
214bf215546Sopenharmony_ci	uint32_t __len = 0;
215bf215546Sopenharmony_ci	uint32_t __pos = 0;
216bf215546Sopenharmony_ci	uint8_t *__data = NULL;
217bf215546Sopenharmony_ci	int __ret = 0;
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci	LEN(8); /* header */
220bf215546Sopenharmony_ci	LEN(4); /* serial */
221bf215546Sopenharmony_ci	LEN_ARRAY(8, shaders); /* shaders */
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ci	/* align */
224bf215546Sopenharmony_ci	PAD(__len, 8);
225bf215546Sopenharmony_ci
226bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
227bf215546Sopenharmony_ci	if (!__data)
228bf215546Sopenharmony_ci		return -ENOMEM;
229bf215546Sopenharmony_ci
230bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY));
231bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
232bf215546Sopenharmony_ci	WRITE(4, uint32_t, serial); /* serial */
233bf215546Sopenharmony_ci	WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */
234bf215546Sopenharmony_ci
235bf215546Sopenharmony_ci	/* final pad */
236bf215546Sopenharmony_ci	PAD(__pos, 8);
237bf215546Sopenharmony_ci
238bf215546Sopenharmony_ci	if (__pos != __len) {
239bf215546Sopenharmony_ci		__ret = -EINVAL;
240bf215546Sopenharmony_ci	} else {
241bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len);
242bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
243bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
244bf215546Sopenharmony_ci	}
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_ci	FREE(__data);
247bf215546Sopenharmony_ci	return __ret;
248bf215546Sopenharmony_ci}
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_ciint rbug_send_shader_info_reply(struct rbug_connection *__con,
251bf215546Sopenharmony_ci                                uint32_t serial,
252bf215546Sopenharmony_ci                                uint32_t *original,
253bf215546Sopenharmony_ci                                uint32_t original_len,
254bf215546Sopenharmony_ci                                uint32_t *replaced,
255bf215546Sopenharmony_ci                                uint32_t replaced_len,
256bf215546Sopenharmony_ci                                uint8_t disabled,
257bf215546Sopenharmony_ci                                uint32_t *__serial)
258bf215546Sopenharmony_ci{
259bf215546Sopenharmony_ci	uint32_t __len = 0;
260bf215546Sopenharmony_ci	uint32_t __pos = 0;
261bf215546Sopenharmony_ci	uint8_t *__data = NULL;
262bf215546Sopenharmony_ci	int __ret = 0;
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_ci	LEN(8); /* header */
265bf215546Sopenharmony_ci	LEN(4); /* serial */
266bf215546Sopenharmony_ci	LEN_ARRAY(4, original); /* original */
267bf215546Sopenharmony_ci	LEN_ARRAY(4, replaced); /* replaced */
268bf215546Sopenharmony_ci	LEN(1); /* disabled */
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ci	/* align */
271bf215546Sopenharmony_ci	PAD(__len, 8);
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_ci	__data = (uint8_t*)MALLOC(__len);
274bf215546Sopenharmony_ci	if (!__data)
275bf215546Sopenharmony_ci		return -ENOMEM;
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci	WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO_REPLY));
278bf215546Sopenharmony_ci	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
279bf215546Sopenharmony_ci	WRITE(4, uint32_t, serial); /* serial */
280bf215546Sopenharmony_ci	WRITE_ARRAY(4, uint32_t, original); /* original */
281bf215546Sopenharmony_ci	WRITE_ARRAY(4, uint32_t, replaced); /* replaced */
282bf215546Sopenharmony_ci	WRITE(1, uint8_t, disabled); /* disabled */
283bf215546Sopenharmony_ci
284bf215546Sopenharmony_ci	/* final pad */
285bf215546Sopenharmony_ci	PAD(__pos, 8);
286bf215546Sopenharmony_ci
287bf215546Sopenharmony_ci	if (__pos != __len) {
288bf215546Sopenharmony_ci		__ret = -EINVAL;
289bf215546Sopenharmony_ci	} else {
290bf215546Sopenharmony_ci		rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO_REPLY, __len);
291bf215546Sopenharmony_ci		rbug_connection_write(__con, __data, __len);
292bf215546Sopenharmony_ci		__ret = rbug_connection_send_finish(__con, __serial);
293bf215546Sopenharmony_ci	}
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci	FREE(__data);
296bf215546Sopenharmony_ci	return __ret;
297bf215546Sopenharmony_ci}
298bf215546Sopenharmony_ci
299bf215546Sopenharmony_cistruct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header)
300bf215546Sopenharmony_ci{
301bf215546Sopenharmony_ci	uint32_t len = 0;
302bf215546Sopenharmony_ci	uint32_t pos = 0;
303bf215546Sopenharmony_ci	uint8_t *data =  NULL;
304bf215546Sopenharmony_ci	struct rbug_proto_shader_list *ret;
305bf215546Sopenharmony_ci
306bf215546Sopenharmony_ci	if (!header)
307bf215546Sopenharmony_ci		return NULL;
308bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST)
309bf215546Sopenharmony_ci		return NULL;
310bf215546Sopenharmony_ci
311bf215546Sopenharmony_ci	pos = 0;
312bf215546Sopenharmony_ci	len = header->length * 4;
313bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
314bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
315bf215546Sopenharmony_ci	if (!ret)
316bf215546Sopenharmony_ci		return NULL;
317bf215546Sopenharmony_ci
318bf215546Sopenharmony_ci	ret->header.__message = header;
319bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci	READ(8, rbug_context_t, context); /* context */
322bf215546Sopenharmony_ci
323bf215546Sopenharmony_ci	return ret;
324bf215546Sopenharmony_ci}
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_cistruct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header)
327bf215546Sopenharmony_ci{
328bf215546Sopenharmony_ci	uint32_t len = 0;
329bf215546Sopenharmony_ci	uint32_t pos = 0;
330bf215546Sopenharmony_ci	uint8_t *data =  NULL;
331bf215546Sopenharmony_ci	struct rbug_proto_shader_info *ret;
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci	if (!header)
334bf215546Sopenharmony_ci		return NULL;
335bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO)
336bf215546Sopenharmony_ci		return NULL;
337bf215546Sopenharmony_ci
338bf215546Sopenharmony_ci	pos = 0;
339bf215546Sopenharmony_ci	len = header->length * 4;
340bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
341bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
342bf215546Sopenharmony_ci	if (!ret)
343bf215546Sopenharmony_ci		return NULL;
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci	ret->header.__message = header;
346bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_ci	READ(8, rbug_context_t, context); /* context */
349bf215546Sopenharmony_ci	READ(8, rbug_shader_t, shader); /* shader */
350bf215546Sopenharmony_ci
351bf215546Sopenharmony_ci	return ret;
352bf215546Sopenharmony_ci}
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_cistruct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header)
355bf215546Sopenharmony_ci{
356bf215546Sopenharmony_ci	uint32_t len = 0;
357bf215546Sopenharmony_ci	uint32_t pos = 0;
358bf215546Sopenharmony_ci	uint8_t *data =  NULL;
359bf215546Sopenharmony_ci	struct rbug_proto_shader_disable *ret;
360bf215546Sopenharmony_ci
361bf215546Sopenharmony_ci	if (!header)
362bf215546Sopenharmony_ci		return NULL;
363bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_SHADER_DISABLE)
364bf215546Sopenharmony_ci		return NULL;
365bf215546Sopenharmony_ci
366bf215546Sopenharmony_ci	pos = 0;
367bf215546Sopenharmony_ci	len = header->length * 4;
368bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
369bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
370bf215546Sopenharmony_ci	if (!ret)
371bf215546Sopenharmony_ci		return NULL;
372bf215546Sopenharmony_ci
373bf215546Sopenharmony_ci	ret->header.__message = header;
374bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
375bf215546Sopenharmony_ci
376bf215546Sopenharmony_ci	READ(8, rbug_context_t, context); /* context */
377bf215546Sopenharmony_ci	READ(8, rbug_shader_t, shader); /* shader */
378bf215546Sopenharmony_ci	READ(1, uint8_t, disable); /* disable */
379bf215546Sopenharmony_ci
380bf215546Sopenharmony_ci	return ret;
381bf215546Sopenharmony_ci}
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_cistruct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header)
384bf215546Sopenharmony_ci{
385bf215546Sopenharmony_ci	uint32_t len = 0;
386bf215546Sopenharmony_ci	uint32_t pos = 0;
387bf215546Sopenharmony_ci	uint8_t *data =  NULL;
388bf215546Sopenharmony_ci	struct rbug_proto_shader_replace *ret;
389bf215546Sopenharmony_ci
390bf215546Sopenharmony_ci	if (!header)
391bf215546Sopenharmony_ci		return NULL;
392bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_SHADER_REPLACE)
393bf215546Sopenharmony_ci		return NULL;
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_ci	pos = 0;
396bf215546Sopenharmony_ci	len = header->length * 4;
397bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
398bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
399bf215546Sopenharmony_ci	if (!ret)
400bf215546Sopenharmony_ci		return NULL;
401bf215546Sopenharmony_ci
402bf215546Sopenharmony_ci	ret->header.__message = header;
403bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
404bf215546Sopenharmony_ci
405bf215546Sopenharmony_ci	READ(8, rbug_context_t, context); /* context */
406bf215546Sopenharmony_ci	READ(8, rbug_shader_t, shader); /* shader */
407bf215546Sopenharmony_ci	READ_ARRAY(4, uint32_t, tokens); /* tokens */
408bf215546Sopenharmony_ci
409bf215546Sopenharmony_ci	return ret;
410bf215546Sopenharmony_ci}
411bf215546Sopenharmony_ci
412bf215546Sopenharmony_cistruct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header)
413bf215546Sopenharmony_ci{
414bf215546Sopenharmony_ci	uint32_t len = 0;
415bf215546Sopenharmony_ci	uint32_t pos = 0;
416bf215546Sopenharmony_ci	uint8_t *data =  NULL;
417bf215546Sopenharmony_ci	struct rbug_proto_shader_list_reply *ret;
418bf215546Sopenharmony_ci
419bf215546Sopenharmony_ci	if (!header)
420bf215546Sopenharmony_ci		return NULL;
421bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST_REPLY)
422bf215546Sopenharmony_ci		return NULL;
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci	pos = 0;
425bf215546Sopenharmony_ci	len = header->length * 4;
426bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
427bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
428bf215546Sopenharmony_ci	if (!ret)
429bf215546Sopenharmony_ci		return NULL;
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_ci	ret->header.__message = header;
432bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
433bf215546Sopenharmony_ci
434bf215546Sopenharmony_ci	READ(4, uint32_t, serial); /* serial */
435bf215546Sopenharmony_ci	READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */
436bf215546Sopenharmony_ci
437bf215546Sopenharmony_ci	return ret;
438bf215546Sopenharmony_ci}
439bf215546Sopenharmony_ci
440bf215546Sopenharmony_cistruct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header)
441bf215546Sopenharmony_ci{
442bf215546Sopenharmony_ci	uint32_t len = 0;
443bf215546Sopenharmony_ci	uint32_t pos = 0;
444bf215546Sopenharmony_ci	uint8_t *data =  NULL;
445bf215546Sopenharmony_ci	struct rbug_proto_shader_info_reply *ret;
446bf215546Sopenharmony_ci
447bf215546Sopenharmony_ci	if (!header)
448bf215546Sopenharmony_ci		return NULL;
449bf215546Sopenharmony_ci	if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO_REPLY)
450bf215546Sopenharmony_ci		return NULL;
451bf215546Sopenharmony_ci
452bf215546Sopenharmony_ci	pos = 0;
453bf215546Sopenharmony_ci	len = header->length * 4;
454bf215546Sopenharmony_ci	data = (uint8_t*)&header[1];
455bf215546Sopenharmony_ci	ret = MALLOC(sizeof(*ret));
456bf215546Sopenharmony_ci	if (!ret)
457bf215546Sopenharmony_ci		return NULL;
458bf215546Sopenharmony_ci
459bf215546Sopenharmony_ci	ret->header.__message = header;
460bf215546Sopenharmony_ci	ret->header.opcode = header->opcode;
461bf215546Sopenharmony_ci
462bf215546Sopenharmony_ci	READ(4, uint32_t, serial); /* serial */
463bf215546Sopenharmony_ci	READ_ARRAY(4, uint32_t, original); /* original */
464bf215546Sopenharmony_ci	READ_ARRAY(4, uint32_t, replaced); /* replaced */
465bf215546Sopenharmony_ci	READ(1, uint8_t, disabled); /* disabled */
466bf215546Sopenharmony_ci
467bf215546Sopenharmony_ci	return ret;
468bf215546Sopenharmony_ci}
469