14a49301eSmrg/*
24a49301eSmrg * Copyright 2009 VMware, Inc.
34a49301eSmrg * All Rights Reserved.
44a49301eSmrg *
54a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
64a49301eSmrg * copy of this software and associated documentation files (the "Software"),
74a49301eSmrg * to deal in the Software without restriction, including without limitation
84a49301eSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub
94a49301eSmrg * license, and/or sell copies of the Software, and to permit persons to whom
104a49301eSmrg * the Software is furnished to do so, subject to the following conditions:
114a49301eSmrg *
124a49301eSmrg * The above copyright notice and this permission notice (including the next
134a49301eSmrg * paragraph) shall be included in all copies or substantial portions of the
144a49301eSmrg * Software.
154a49301eSmrg *
164a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
174a49301eSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
184a49301eSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
194a49301eSmrg * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
204a49301eSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
214a49301eSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
224a49301eSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
234a49301eSmrg */
244a49301eSmrg
254a49301eSmrg/*
264a49301eSmrg * This file holds the function implementation for one of the rbug extensions.
274a49301eSmrg * Prototypes and declerations of functions and structs is in the same folder
284a49301eSmrg * in the header file matching this file's name.
294a49301eSmrg *
304a49301eSmrg * The functions starting rbug_send_* encodes a call to the write format and
314a49301eSmrg * sends that to the supplied connection, while functions starting with
324a49301eSmrg * rbug_demarshal_* demarshal data in the wire protocol.
334a49301eSmrg *
344a49301eSmrg * Functions ending with _reply are replies to requests.
354a49301eSmrg */
364a49301eSmrg
374a49301eSmrg#include "rbug_internal.h"
38af69d88dSmrg#include "rbug_context.h"
394a49301eSmrg
404a49301eSmrgint rbug_send_context_list(struct rbug_connection *__con,
414a49301eSmrg                           uint32_t *__serial)
424a49301eSmrg{
434a49301eSmrg	uint32_t __len = 0;
444a49301eSmrg	uint32_t __pos = 0;
454a49301eSmrg	uint8_t *__data = NULL;
464a49301eSmrg	int __ret = 0;
474a49301eSmrg
484a49301eSmrg	LEN(8); /* header */
494a49301eSmrg
504a49301eSmrg	/* align */
514a49301eSmrg	PAD(__len, 8);
524a49301eSmrg
534a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
544a49301eSmrg	if (!__data)
554a49301eSmrg		return -ENOMEM;
564a49301eSmrg
574a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST));
584a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
594a49301eSmrg
604a49301eSmrg	/* final pad */
614a49301eSmrg	PAD(__pos, 8);
624a49301eSmrg
634a49301eSmrg	if (__pos != __len) {
644a49301eSmrg		__ret = -EINVAL;
654a49301eSmrg	} else {
664a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST, __len);
674a49301eSmrg		rbug_connection_write(__con, __data, __len);
684a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
694a49301eSmrg	}
704a49301eSmrg
714a49301eSmrg	FREE(__data);
724a49301eSmrg	return __ret;
734a49301eSmrg}
744a49301eSmrg
754a49301eSmrgint rbug_send_context_info(struct rbug_connection *__con,
764a49301eSmrg                           rbug_context_t context,
774a49301eSmrg                           uint32_t *__serial)
784a49301eSmrg{
794a49301eSmrg	uint32_t __len = 0;
804a49301eSmrg	uint32_t __pos = 0;
814a49301eSmrg	uint8_t *__data = NULL;
824a49301eSmrg	int __ret = 0;
834a49301eSmrg
844a49301eSmrg	LEN(8); /* header */
854a49301eSmrg	LEN(8); /* context */
864a49301eSmrg
874a49301eSmrg	/* align */
884a49301eSmrg	PAD(__len, 8);
894a49301eSmrg
904a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
914a49301eSmrg	if (!__data)
924a49301eSmrg		return -ENOMEM;
934a49301eSmrg
944a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO));
954a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
964a49301eSmrg	WRITE(8, rbug_context_t, context); /* context */
974a49301eSmrg
984a49301eSmrg	/* final pad */
994a49301eSmrg	PAD(__pos, 8);
1004a49301eSmrg
1014a49301eSmrg	if (__pos != __len) {
1024a49301eSmrg		__ret = -EINVAL;
1034a49301eSmrg	} else {
1044a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO, __len);
1054a49301eSmrg		rbug_connection_write(__con, __data, __len);
1064a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
1074a49301eSmrg	}
1084a49301eSmrg
1094a49301eSmrg	FREE(__data);
1104a49301eSmrg	return __ret;
1114a49301eSmrg}
1124a49301eSmrg
1134a49301eSmrgint rbug_send_context_draw_block(struct rbug_connection *__con,
1144a49301eSmrg                                 rbug_context_t context,
1154a49301eSmrg                                 rbug_block_t block,
1164a49301eSmrg                                 uint32_t *__serial)
1174a49301eSmrg{
1184a49301eSmrg	uint32_t __len = 0;
1194a49301eSmrg	uint32_t __pos = 0;
1204a49301eSmrg	uint8_t *__data = NULL;
1214a49301eSmrg	int __ret = 0;
1224a49301eSmrg
1234a49301eSmrg	LEN(8); /* header */
1244a49301eSmrg	LEN(8); /* context */
1254a49301eSmrg	LEN(4); /* block */
1264a49301eSmrg
1274a49301eSmrg	/* align */
1284a49301eSmrg	PAD(__len, 8);
1294a49301eSmrg
1304a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
1314a49301eSmrg	if (!__data)
1324a49301eSmrg		return -ENOMEM;
1334a49301eSmrg
1344a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCK));
1354a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
1364a49301eSmrg	WRITE(8, rbug_context_t, context); /* context */
1374a49301eSmrg	WRITE(4, rbug_block_t, block); /* block */
1384a49301eSmrg
1394a49301eSmrg	/* final pad */
1404a49301eSmrg	PAD(__pos, 8);
1414a49301eSmrg
1424a49301eSmrg	if (__pos != __len) {
1434a49301eSmrg		__ret = -EINVAL;
1444a49301eSmrg	} else {
1454a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCK, __len);
1464a49301eSmrg		rbug_connection_write(__con, __data, __len);
1474a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
1484a49301eSmrg	}
1494a49301eSmrg
1504a49301eSmrg	FREE(__data);
1514a49301eSmrg	return __ret;
1524a49301eSmrg}
1534a49301eSmrg
1544a49301eSmrgint rbug_send_context_draw_step(struct rbug_connection *__con,
1554a49301eSmrg                                rbug_context_t context,
1564a49301eSmrg                                rbug_block_t step,
1574a49301eSmrg                                uint32_t *__serial)
1584a49301eSmrg{
1594a49301eSmrg	uint32_t __len = 0;
1604a49301eSmrg	uint32_t __pos = 0;
1614a49301eSmrg	uint8_t *__data = NULL;
1624a49301eSmrg	int __ret = 0;
1634a49301eSmrg
1644a49301eSmrg	LEN(8); /* header */
1654a49301eSmrg	LEN(8); /* context */
1664a49301eSmrg	LEN(4); /* step */
1674a49301eSmrg
1684a49301eSmrg	/* align */
1694a49301eSmrg	PAD(__len, 8);
1704a49301eSmrg
1714a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
1724a49301eSmrg	if (!__data)
1734a49301eSmrg		return -ENOMEM;
1744a49301eSmrg
1754a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_STEP));
1764a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
1774a49301eSmrg	WRITE(8, rbug_context_t, context); /* context */
1784a49301eSmrg	WRITE(4, rbug_block_t, step); /* step */
1794a49301eSmrg
1804a49301eSmrg	/* final pad */
1814a49301eSmrg	PAD(__pos, 8);
1824a49301eSmrg
1834a49301eSmrg	if (__pos != __len) {
1844a49301eSmrg		__ret = -EINVAL;
1854a49301eSmrg	} else {
1864a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_STEP, __len);
1874a49301eSmrg		rbug_connection_write(__con, __data, __len);
1884a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
1894a49301eSmrg	}
1904a49301eSmrg
1914a49301eSmrg	FREE(__data);
1924a49301eSmrg	return __ret;
1934a49301eSmrg}
1944a49301eSmrg
1954a49301eSmrgint rbug_send_context_draw_unblock(struct rbug_connection *__con,
1964a49301eSmrg                                   rbug_context_t context,
1974a49301eSmrg                                   rbug_block_t unblock,
1984a49301eSmrg                                   uint32_t *__serial)
1994a49301eSmrg{
2004a49301eSmrg	uint32_t __len = 0;
2014a49301eSmrg	uint32_t __pos = 0;
2024a49301eSmrg	uint8_t *__data = NULL;
2034a49301eSmrg	int __ret = 0;
2044a49301eSmrg
2054a49301eSmrg	LEN(8); /* header */
2064a49301eSmrg	LEN(8); /* context */
2074a49301eSmrg	LEN(4); /* unblock */
2084a49301eSmrg
2094a49301eSmrg	/* align */
2104a49301eSmrg	PAD(__len, 8);
2114a49301eSmrg
2124a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
2134a49301eSmrg	if (!__data)
2144a49301eSmrg		return -ENOMEM;
2154a49301eSmrg
2164a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK));
2174a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
2184a49301eSmrg	WRITE(8, rbug_context_t, context); /* context */
2194a49301eSmrg	WRITE(4, rbug_block_t, unblock); /* unblock */
2204a49301eSmrg
2214a49301eSmrg	/* final pad */
2224a49301eSmrg	PAD(__pos, 8);
2234a49301eSmrg
2244a49301eSmrg	if (__pos != __len) {
2254a49301eSmrg		__ret = -EINVAL;
2264a49301eSmrg	} else {
2274a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_UNBLOCK, __len);
2284a49301eSmrg		rbug_connection_write(__con, __data, __len);
2294a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
2304a49301eSmrg	}
2314a49301eSmrg
2324a49301eSmrg	FREE(__data);
2334a49301eSmrg	return __ret;
2344a49301eSmrg}
2354a49301eSmrg
2364a49301eSmrgint rbug_send_context_draw_rule(struct rbug_connection *__con,
2374a49301eSmrg                                rbug_context_t context,
2384a49301eSmrg                                rbug_shader_t vertex,
2394a49301eSmrg                                rbug_shader_t fragment,
2404a49301eSmrg                                rbug_texture_t texture,
2414a49301eSmrg                                rbug_texture_t surface,
2424a49301eSmrg                                rbug_block_t block,
2434a49301eSmrg                                uint32_t *__serial)
2444a49301eSmrg{
2454a49301eSmrg	uint32_t __len = 0;
2464a49301eSmrg	uint32_t __pos = 0;
2474a49301eSmrg	uint8_t *__data = NULL;
2484a49301eSmrg	int __ret = 0;
2494a49301eSmrg
2504a49301eSmrg	LEN(8); /* header */
2514a49301eSmrg	LEN(8); /* context */
2524a49301eSmrg	LEN(8); /* vertex */
2534a49301eSmrg	LEN(8); /* fragment */
2544a49301eSmrg	LEN(8); /* texture */
2554a49301eSmrg	LEN(8); /* surface */
2564a49301eSmrg	LEN(4); /* block */
2574a49301eSmrg
2584a49301eSmrg	/* align */
2594a49301eSmrg	PAD(__len, 8);
2604a49301eSmrg
2614a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
2624a49301eSmrg	if (!__data)
2634a49301eSmrg		return -ENOMEM;
2644a49301eSmrg
2654a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_RULE));
2664a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
2674a49301eSmrg	WRITE(8, rbug_context_t, context); /* context */
2684a49301eSmrg	WRITE(8, rbug_shader_t, vertex); /* vertex */
2694a49301eSmrg	WRITE(8, rbug_shader_t, fragment); /* fragment */
2704a49301eSmrg	WRITE(8, rbug_texture_t, texture); /* texture */
2714a49301eSmrg	WRITE(8, rbug_texture_t, surface); /* surface */
2724a49301eSmrg	WRITE(4, rbug_block_t, block); /* block */
2734a49301eSmrg
2744a49301eSmrg	/* final pad */
2754a49301eSmrg	PAD(__pos, 8);
2764a49301eSmrg
2774a49301eSmrg	if (__pos != __len) {
2784a49301eSmrg		__ret = -EINVAL;
2794a49301eSmrg	} else {
2804a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_RULE, __len);
2814a49301eSmrg		rbug_connection_write(__con, __data, __len);
2824a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
2834a49301eSmrg	}
2844a49301eSmrg
2854a49301eSmrg	FREE(__data);
2864a49301eSmrg	return __ret;
2874a49301eSmrg}
2884a49301eSmrg
2894a49301eSmrgint rbug_send_context_flush(struct rbug_connection *__con,
2904a49301eSmrg                            rbug_context_t context,
2914a49301eSmrg                            uint32_t *__serial)
2924a49301eSmrg{
2934a49301eSmrg	uint32_t __len = 0;
2944a49301eSmrg	uint32_t __pos = 0;
2954a49301eSmrg	uint8_t *__data = NULL;
2964a49301eSmrg	int __ret = 0;
2974a49301eSmrg
2984a49301eSmrg	LEN(8); /* header */
2994a49301eSmrg	LEN(8); /* context */
3004a49301eSmrg
3014a49301eSmrg	/* align */
3024a49301eSmrg	PAD(__len, 8);
3034a49301eSmrg
3044a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
3054a49301eSmrg	if (!__data)
3064a49301eSmrg		return -ENOMEM;
3074a49301eSmrg
3084a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_FLUSH));
3094a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
3104a49301eSmrg	WRITE(8, rbug_context_t, context); /* context */
3114a49301eSmrg
3124a49301eSmrg	/* final pad */
3134a49301eSmrg	PAD(__pos, 8);
3144a49301eSmrg
3154a49301eSmrg	if (__pos != __len) {
3164a49301eSmrg		__ret = -EINVAL;
3174a49301eSmrg	} else {
3184a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_FLUSH, __len);
3194a49301eSmrg		rbug_connection_write(__con, __data, __len);
3204a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
3214a49301eSmrg	}
3224a49301eSmrg
3234a49301eSmrg	FREE(__data);
3244a49301eSmrg	return __ret;
3254a49301eSmrg}
3264a49301eSmrg
3274a49301eSmrgint rbug_send_context_list_reply(struct rbug_connection *__con,
3284a49301eSmrg                                 uint32_t serial,
3294a49301eSmrg                                 rbug_context_t *contexts,
3304a49301eSmrg                                 uint32_t contexts_len,
3314a49301eSmrg                                 uint32_t *__serial)
3324a49301eSmrg{
3334a49301eSmrg	uint32_t __len = 0;
3344a49301eSmrg	uint32_t __pos = 0;
3354a49301eSmrg	uint8_t *__data = NULL;
3364a49301eSmrg	int __ret = 0;
3374a49301eSmrg
3384a49301eSmrg	LEN(8); /* header */
3394a49301eSmrg	LEN(4); /* serial */
3404a49301eSmrg	LEN_ARRAY(8, contexts); /* contexts */
3414a49301eSmrg
3424a49301eSmrg	/* align */
3434a49301eSmrg	PAD(__len, 8);
3444a49301eSmrg
3454a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
3464a49301eSmrg	if (!__data)
3474a49301eSmrg		return -ENOMEM;
3484a49301eSmrg
3494a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_LIST_REPLY));
3504a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
3514a49301eSmrg	WRITE(4, uint32_t, serial); /* serial */
3524a49301eSmrg	WRITE_ARRAY(8, rbug_context_t, contexts); /* contexts */
3534a49301eSmrg
3544a49301eSmrg	/* final pad */
3554a49301eSmrg	PAD(__pos, 8);
3564a49301eSmrg
3574a49301eSmrg	if (__pos != __len) {
3584a49301eSmrg		__ret = -EINVAL;
3594a49301eSmrg	} else {
3604a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_LIST_REPLY, __len);
3614a49301eSmrg		rbug_connection_write(__con, __data, __len);
3624a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
3634a49301eSmrg	}
3644a49301eSmrg
3654a49301eSmrg	FREE(__data);
3664a49301eSmrg	return __ret;
3674a49301eSmrg}
3684a49301eSmrg
3694a49301eSmrgint rbug_send_context_info_reply(struct rbug_connection *__con,
3704a49301eSmrg                                 uint32_t serial,
3714a49301eSmrg                                 rbug_shader_t vertex,
3724a49301eSmrg                                 rbug_shader_t fragment,
3734a49301eSmrg                                 rbug_texture_t *texs,
3744a49301eSmrg                                 uint32_t texs_len,
3754a49301eSmrg                                 rbug_texture_t *cbufs,
3764a49301eSmrg                                 uint32_t cbufs_len,
3774a49301eSmrg                                 rbug_texture_t zsbuf,
3784a49301eSmrg                                 rbug_block_t blocker,
3794a49301eSmrg                                 rbug_block_t blocked,
3804a49301eSmrg                                 uint32_t *__serial)
3814a49301eSmrg{
3824a49301eSmrg	uint32_t __len = 0;
3834a49301eSmrg	uint32_t __pos = 0;
3844a49301eSmrg	uint8_t *__data = NULL;
3854a49301eSmrg	int __ret = 0;
3864a49301eSmrg
3874a49301eSmrg	LEN(8); /* header */
3884a49301eSmrg	LEN(4); /* serial */
3894a49301eSmrg	LEN(8); /* vertex */
3904a49301eSmrg	LEN(8); /* fragment */
3914a49301eSmrg	LEN_ARRAY(8, texs); /* texs */
3924a49301eSmrg	LEN_ARRAY(8, cbufs); /* cbufs */
3934a49301eSmrg	LEN(8); /* zsbuf */
3944a49301eSmrg	LEN(4); /* blocker */
3954a49301eSmrg	LEN(4); /* blocked */
3964a49301eSmrg
3974a49301eSmrg	/* align */
3984a49301eSmrg	PAD(__len, 8);
3994a49301eSmrg
4004a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
4014a49301eSmrg	if (!__data)
4024a49301eSmrg		return -ENOMEM;
4034a49301eSmrg
4044a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_INFO_REPLY));
4054a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
4064a49301eSmrg	WRITE(4, uint32_t, serial); /* serial */
4074a49301eSmrg	WRITE(8, rbug_shader_t, vertex); /* vertex */
4084a49301eSmrg	WRITE(8, rbug_shader_t, fragment); /* fragment */
4094a49301eSmrg	WRITE_ARRAY(8, rbug_texture_t, texs); /* texs */
4104a49301eSmrg	WRITE_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */
4114a49301eSmrg	WRITE(8, rbug_texture_t, zsbuf); /* zsbuf */
4124a49301eSmrg	WRITE(4, rbug_block_t, blocker); /* blocker */
4134a49301eSmrg	WRITE(4, rbug_block_t, blocked); /* blocked */
4144a49301eSmrg
4154a49301eSmrg	/* final pad */
4164a49301eSmrg	PAD(__pos, 8);
4174a49301eSmrg
4184a49301eSmrg	if (__pos != __len) {
4194a49301eSmrg		__ret = -EINVAL;
4204a49301eSmrg	} else {
4214a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_INFO_REPLY, __len);
4224a49301eSmrg		rbug_connection_write(__con, __data, __len);
4234a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
4244a49301eSmrg	}
4254a49301eSmrg
4264a49301eSmrg	FREE(__data);
4274a49301eSmrg	return __ret;
4284a49301eSmrg}
4294a49301eSmrg
4304a49301eSmrgint rbug_send_context_draw_blocked(struct rbug_connection *__con,
4314a49301eSmrg                                   rbug_context_t context,
4324a49301eSmrg                                   rbug_block_t block,
4334a49301eSmrg                                   uint32_t *__serial)
4344a49301eSmrg{
4354a49301eSmrg	uint32_t __len = 0;
4364a49301eSmrg	uint32_t __pos = 0;
4374a49301eSmrg	uint8_t *__data = NULL;
4384a49301eSmrg	int __ret = 0;
4394a49301eSmrg
4404a49301eSmrg	LEN(8); /* header */
4414a49301eSmrg	LEN(8); /* context */
4424a49301eSmrg	LEN(4); /* block */
4434a49301eSmrg
4444a49301eSmrg	/* align */
4454a49301eSmrg	PAD(__len, 8);
4464a49301eSmrg
4474a49301eSmrg	__data = (uint8_t*)MALLOC(__len);
4484a49301eSmrg	if (!__data)
4494a49301eSmrg		return -ENOMEM;
4504a49301eSmrg
4514a49301eSmrg	WRITE(4, int32_t, ((int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED));
4524a49301eSmrg	WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
4534a49301eSmrg	WRITE(8, rbug_context_t, context); /* context */
4544a49301eSmrg	WRITE(4, rbug_block_t, block); /* block */
4554a49301eSmrg
4564a49301eSmrg	/* final pad */
4574a49301eSmrg	PAD(__pos, 8);
4584a49301eSmrg
4594a49301eSmrg	if (__pos != __len) {
4604a49301eSmrg		__ret = -EINVAL;
4614a49301eSmrg	} else {
4624a49301eSmrg		rbug_connection_send_start(__con, RBUG_OP_CONTEXT_DRAW_BLOCKED, __len);
4634a49301eSmrg		rbug_connection_write(__con, __data, __len);
4644a49301eSmrg		__ret = rbug_connection_send_finish(__con, __serial);
4654a49301eSmrg	}
4664a49301eSmrg
4674a49301eSmrg	FREE(__data);
4684a49301eSmrg	return __ret;
4694a49301eSmrg}
4704a49301eSmrg
4714a49301eSmrgstruct rbug_proto_context_list * rbug_demarshal_context_list(struct rbug_proto_header *header)
4724a49301eSmrg{
4734a49301eSmrg	struct rbug_proto_context_list *ret;
4744a49301eSmrg
4754a49301eSmrg	if (!header)
4764a49301eSmrg		return NULL;
4773464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_LIST)
4784a49301eSmrg		return NULL;
4794a49301eSmrg
4804a49301eSmrg	ret = MALLOC(sizeof(*ret));
4814a49301eSmrg	if (!ret)
4824a49301eSmrg		return NULL;
4834a49301eSmrg
4844a49301eSmrg	ret->header.__message = header;
4854a49301eSmrg	ret->header.opcode = header->opcode;
4864a49301eSmrg
4874a49301eSmrg	return ret;
4884a49301eSmrg}
4894a49301eSmrg
4904a49301eSmrgstruct rbug_proto_context_info * rbug_demarshal_context_info(struct rbug_proto_header *header)
4914a49301eSmrg{
4924a49301eSmrg	uint32_t len = 0;
4934a49301eSmrg	uint32_t pos = 0;
4944a49301eSmrg	uint8_t *data =  NULL;
4954a49301eSmrg	struct rbug_proto_context_info *ret;
4964a49301eSmrg
4974a49301eSmrg	if (!header)
4984a49301eSmrg		return NULL;
4993464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_INFO)
5004a49301eSmrg		return NULL;
5014a49301eSmrg
5024a49301eSmrg	pos = 0;
5034a49301eSmrg	len = header->length * 4;
5044a49301eSmrg	data = (uint8_t*)&header[1];
5054a49301eSmrg	ret = MALLOC(sizeof(*ret));
5064a49301eSmrg	if (!ret)
5074a49301eSmrg		return NULL;
5084a49301eSmrg
5094a49301eSmrg	ret->header.__message = header;
5104a49301eSmrg	ret->header.opcode = header->opcode;
5114a49301eSmrg
5124a49301eSmrg	READ(8, rbug_context_t, context); /* context */
5134a49301eSmrg
5144a49301eSmrg	return ret;
5154a49301eSmrg}
5164a49301eSmrg
5174a49301eSmrgstruct rbug_proto_context_draw_block * rbug_demarshal_context_draw_block(struct rbug_proto_header *header)
5184a49301eSmrg{
5194a49301eSmrg	uint32_t len = 0;
5204a49301eSmrg	uint32_t pos = 0;
5214a49301eSmrg	uint8_t *data =  NULL;
5224a49301eSmrg	struct rbug_proto_context_draw_block *ret;
5234a49301eSmrg
5244a49301eSmrg	if (!header)
5254a49301eSmrg		return NULL;
5263464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_BLOCK)
5274a49301eSmrg		return NULL;
5284a49301eSmrg
5294a49301eSmrg	pos = 0;
5304a49301eSmrg	len = header->length * 4;
5314a49301eSmrg	data = (uint8_t*)&header[1];
5324a49301eSmrg	ret = MALLOC(sizeof(*ret));
5334a49301eSmrg	if (!ret)
5344a49301eSmrg		return NULL;
5354a49301eSmrg
5364a49301eSmrg	ret->header.__message = header;
5374a49301eSmrg	ret->header.opcode = header->opcode;
5384a49301eSmrg
5394a49301eSmrg	READ(8, rbug_context_t, context); /* context */
5404a49301eSmrg	READ(4, rbug_block_t, block); /* block */
5414a49301eSmrg
5424a49301eSmrg	return ret;
5434a49301eSmrg}
5444a49301eSmrg
5454a49301eSmrgstruct rbug_proto_context_draw_step * rbug_demarshal_context_draw_step(struct rbug_proto_header *header)
5464a49301eSmrg{
5474a49301eSmrg	uint32_t len = 0;
5484a49301eSmrg	uint32_t pos = 0;
5494a49301eSmrg	uint8_t *data =  NULL;
5504a49301eSmrg	struct rbug_proto_context_draw_step *ret;
5514a49301eSmrg
5524a49301eSmrg	if (!header)
5534a49301eSmrg		return NULL;
5543464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_STEP)
5554a49301eSmrg		return NULL;
5564a49301eSmrg
5574a49301eSmrg	pos = 0;
5584a49301eSmrg	len = header->length * 4;
5594a49301eSmrg	data = (uint8_t*)&header[1];
5604a49301eSmrg	ret = MALLOC(sizeof(*ret));
5614a49301eSmrg	if (!ret)
5624a49301eSmrg		return NULL;
5634a49301eSmrg
5644a49301eSmrg	ret->header.__message = header;
5654a49301eSmrg	ret->header.opcode = header->opcode;
5664a49301eSmrg
5674a49301eSmrg	READ(8, rbug_context_t, context); /* context */
5684a49301eSmrg	READ(4, rbug_block_t, step); /* step */
5694a49301eSmrg
5704a49301eSmrg	return ret;
5714a49301eSmrg}
5724a49301eSmrg
5734a49301eSmrgstruct rbug_proto_context_draw_unblock * rbug_demarshal_context_draw_unblock(struct rbug_proto_header *header)
5744a49301eSmrg{
5754a49301eSmrg	uint32_t len = 0;
5764a49301eSmrg	uint32_t pos = 0;
5774a49301eSmrg	uint8_t *data =  NULL;
5784a49301eSmrg	struct rbug_proto_context_draw_unblock *ret;
5794a49301eSmrg
5804a49301eSmrg	if (!header)
5814a49301eSmrg		return NULL;
5823464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_UNBLOCK)
5834a49301eSmrg		return NULL;
5844a49301eSmrg
5854a49301eSmrg	pos = 0;
5864a49301eSmrg	len = header->length * 4;
5874a49301eSmrg	data = (uint8_t*)&header[1];
5884a49301eSmrg	ret = MALLOC(sizeof(*ret));
5894a49301eSmrg	if (!ret)
5904a49301eSmrg		return NULL;
5914a49301eSmrg
5924a49301eSmrg	ret->header.__message = header;
5934a49301eSmrg	ret->header.opcode = header->opcode;
5944a49301eSmrg
5954a49301eSmrg	READ(8, rbug_context_t, context); /* context */
5964a49301eSmrg	READ(4, rbug_block_t, unblock); /* unblock */
5974a49301eSmrg
5984a49301eSmrg	return ret;
5994a49301eSmrg}
6004a49301eSmrg
6014a49301eSmrgstruct rbug_proto_context_draw_rule * rbug_demarshal_context_draw_rule(struct rbug_proto_header *header)
6024a49301eSmrg{
6034a49301eSmrg	uint32_t len = 0;
6044a49301eSmrg	uint32_t pos = 0;
6054a49301eSmrg	uint8_t *data =  NULL;
6064a49301eSmrg	struct rbug_proto_context_draw_rule *ret;
6074a49301eSmrg
6084a49301eSmrg	if (!header)
6094a49301eSmrg		return NULL;
6103464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_RULE)
6114a49301eSmrg		return NULL;
6124a49301eSmrg
6134a49301eSmrg	pos = 0;
6144a49301eSmrg	len = header->length * 4;
6154a49301eSmrg	data = (uint8_t*)&header[1];
6164a49301eSmrg	ret = MALLOC(sizeof(*ret));
6174a49301eSmrg	if (!ret)
6184a49301eSmrg		return NULL;
6194a49301eSmrg
6204a49301eSmrg	ret->header.__message = header;
6214a49301eSmrg	ret->header.opcode = header->opcode;
6224a49301eSmrg
6234a49301eSmrg	READ(8, rbug_context_t, context); /* context */
6244a49301eSmrg	READ(8, rbug_shader_t, vertex); /* vertex */
6254a49301eSmrg	READ(8, rbug_shader_t, fragment); /* fragment */
6264a49301eSmrg	READ(8, rbug_texture_t, texture); /* texture */
6274a49301eSmrg	READ(8, rbug_texture_t, surface); /* surface */
6284a49301eSmrg	READ(4, rbug_block_t, block); /* block */
6294a49301eSmrg
6304a49301eSmrg	return ret;
6314a49301eSmrg}
6324a49301eSmrg
6334a49301eSmrgstruct rbug_proto_context_flush * rbug_demarshal_context_flush(struct rbug_proto_header *header)
6344a49301eSmrg{
6354a49301eSmrg	uint32_t len = 0;
6364a49301eSmrg	uint32_t pos = 0;
6374a49301eSmrg	uint8_t *data =  NULL;
6384a49301eSmrg	struct rbug_proto_context_flush *ret;
6394a49301eSmrg
6404a49301eSmrg	if (!header)
6414a49301eSmrg		return NULL;
6423464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_FLUSH)
6434a49301eSmrg		return NULL;
6444a49301eSmrg
6454a49301eSmrg	pos = 0;
6464a49301eSmrg	len = header->length * 4;
6474a49301eSmrg	data = (uint8_t*)&header[1];
6484a49301eSmrg	ret = MALLOC(sizeof(*ret));
6494a49301eSmrg	if (!ret)
6504a49301eSmrg		return NULL;
6514a49301eSmrg
6524a49301eSmrg	ret->header.__message = header;
6534a49301eSmrg	ret->header.opcode = header->opcode;
6544a49301eSmrg
6554a49301eSmrg	READ(8, rbug_context_t, context); /* context */
6564a49301eSmrg
6574a49301eSmrg	return ret;
6584a49301eSmrg}
6594a49301eSmrg
6604a49301eSmrgstruct rbug_proto_context_list_reply * rbug_demarshal_context_list_reply(struct rbug_proto_header *header)
6614a49301eSmrg{
6624a49301eSmrg	uint32_t len = 0;
6634a49301eSmrg	uint32_t pos = 0;
6644a49301eSmrg	uint8_t *data =  NULL;
6654a49301eSmrg	struct rbug_proto_context_list_reply *ret;
6664a49301eSmrg
6674a49301eSmrg	if (!header)
6684a49301eSmrg		return NULL;
6693464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_LIST_REPLY)
6704a49301eSmrg		return NULL;
6714a49301eSmrg
6724a49301eSmrg	pos = 0;
6734a49301eSmrg	len = header->length * 4;
6744a49301eSmrg	data = (uint8_t*)&header[1];
6754a49301eSmrg	ret = MALLOC(sizeof(*ret));
6764a49301eSmrg	if (!ret)
6774a49301eSmrg		return NULL;
6784a49301eSmrg
6794a49301eSmrg	ret->header.__message = header;
6804a49301eSmrg	ret->header.opcode = header->opcode;
6814a49301eSmrg
6824a49301eSmrg	READ(4, uint32_t, serial); /* serial */
6834a49301eSmrg	READ_ARRAY(8, rbug_context_t, contexts); /* contexts */
6844a49301eSmrg
6854a49301eSmrg	return ret;
6864a49301eSmrg}
6874a49301eSmrg
6884a49301eSmrgstruct rbug_proto_context_info_reply * rbug_demarshal_context_info_reply(struct rbug_proto_header *header)
6894a49301eSmrg{
6904a49301eSmrg	uint32_t len = 0;
6914a49301eSmrg	uint32_t pos = 0;
6924a49301eSmrg	uint8_t *data =  NULL;
6934a49301eSmrg	struct rbug_proto_context_info_reply *ret;
6944a49301eSmrg
6954a49301eSmrg	if (!header)
6964a49301eSmrg		return NULL;
6973464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_INFO_REPLY)
6984a49301eSmrg		return NULL;
6994a49301eSmrg
7004a49301eSmrg	pos = 0;
7014a49301eSmrg	len = header->length * 4;
7024a49301eSmrg	data = (uint8_t*)&header[1];
7034a49301eSmrg	ret = MALLOC(sizeof(*ret));
7044a49301eSmrg	if (!ret)
7054a49301eSmrg		return NULL;
7064a49301eSmrg
7074a49301eSmrg	ret->header.__message = header;
7084a49301eSmrg	ret->header.opcode = header->opcode;
7094a49301eSmrg
7104a49301eSmrg	READ(4, uint32_t, serial); /* serial */
7114a49301eSmrg	READ(8, rbug_shader_t, vertex); /* vertex */
7124a49301eSmrg	READ(8, rbug_shader_t, fragment); /* fragment */
7134a49301eSmrg	READ_ARRAY(8, rbug_texture_t, texs); /* texs */
7144a49301eSmrg	READ_ARRAY(8, rbug_texture_t, cbufs); /* cbufs */
7154a49301eSmrg	READ(8, rbug_texture_t, zsbuf); /* zsbuf */
7164a49301eSmrg	READ(4, rbug_block_t, blocker); /* blocker */
7174a49301eSmrg	READ(4, rbug_block_t, blocked); /* blocked */
7184a49301eSmrg
7194a49301eSmrg	return ret;
7204a49301eSmrg}
7214a49301eSmrg
7224a49301eSmrgstruct rbug_proto_context_draw_blocked * rbug_demarshal_context_draw_blocked(struct rbug_proto_header *header)
7234a49301eSmrg{
7244a49301eSmrg	uint32_t len = 0;
7254a49301eSmrg	uint32_t pos = 0;
7264a49301eSmrg	uint8_t *data =  NULL;
7274a49301eSmrg	struct rbug_proto_context_draw_blocked *ret;
7284a49301eSmrg
7294a49301eSmrg	if (!header)
7304a49301eSmrg		return NULL;
7313464ebd5Sriastradh	if (header->opcode != (int32_t)RBUG_OP_CONTEXT_DRAW_BLOCKED)
7324a49301eSmrg		return NULL;
7334a49301eSmrg
7344a49301eSmrg	pos = 0;
7354a49301eSmrg	len = header->length * 4;
7364a49301eSmrg	data = (uint8_t*)&header[1];
7374a49301eSmrg	ret = MALLOC(sizeof(*ret));
7384a49301eSmrg	if (!ret)
7394a49301eSmrg		return NULL;
7404a49301eSmrg
7414a49301eSmrg	ret->header.__message = header;
7424a49301eSmrg	ret->header.opcode = header->opcode;
7434a49301eSmrg
7444a49301eSmrg	READ(8, rbug_context_t, context); /* context */
7454a49301eSmrg	READ(4, rbug_block_t, block); /* block */
7464a49301eSmrg
7474a49301eSmrg	return ret;
7484a49301eSmrg}
749