1848b8605Smrg/* 2848b8605Smrg * Copyright 2009 VMware, Inc. 3848b8605Smrg * All Rights Reserved. 4848b8605Smrg * 5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6848b8605Smrg * copy of this software and associated documentation files (the "Software"), 7848b8605Smrg * to deal in the Software without restriction, including without limitation 8848b8605Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 9848b8605Smrg * license, and/or sell copies of the Software, and to permit persons to whom 10848b8605Smrg * the Software is furnished to do so, subject to the following conditions: 11848b8605Smrg * 12848b8605Smrg * The above copyright notice and this permission notice (including the next 13848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the 14848b8605Smrg * Software. 15848b8605Smrg * 16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19848b8605Smrg * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20848b8605Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21848b8605Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22848b8605Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 23848b8605Smrg */ 24848b8605Smrg 25848b8605Smrg/* 26848b8605Smrg * This file holds the function implementation for one of the rbug extensions. 27848b8605Smrg * Prototypes and declerations of functions and structs is in the same folder 28848b8605Smrg * in the header file matching this file's name. 29848b8605Smrg * 30848b8605Smrg * The functions starting rbug_send_* encodes a call to the write format and 31848b8605Smrg * sends that to the supplied connection, while functions starting with 32848b8605Smrg * rbug_demarshal_* demarshal data in the wire protocol. 33848b8605Smrg * 34848b8605Smrg * Functions ending with _reply are replies to requests. 35848b8605Smrg */ 36848b8605Smrg 37848b8605Smrg#include "rbug_internal.h" 38848b8605Smrg#include "rbug_shader.h" 39848b8605Smrg 40848b8605Smrgint rbug_send_shader_list(struct rbug_connection *__con, 41848b8605Smrg rbug_context_t context, 42848b8605Smrg uint32_t *__serial) 43848b8605Smrg{ 44848b8605Smrg uint32_t __len = 0; 45848b8605Smrg uint32_t __pos = 0; 46848b8605Smrg uint8_t *__data = NULL; 47848b8605Smrg int __ret = 0; 48848b8605Smrg 49848b8605Smrg LEN(8); /* header */ 50848b8605Smrg LEN(8); /* context */ 51848b8605Smrg 52848b8605Smrg /* align */ 53848b8605Smrg PAD(__len, 8); 54848b8605Smrg 55848b8605Smrg __data = (uint8_t*)MALLOC(__len); 56848b8605Smrg if (!__data) 57848b8605Smrg return -ENOMEM; 58848b8605Smrg 59848b8605Smrg WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST)); 60848b8605Smrg WRITE(4, uint32_t, ((uint32_t)(__len / 4))); 61848b8605Smrg WRITE(8, rbug_context_t, context); /* context */ 62848b8605Smrg 63848b8605Smrg /* final pad */ 64848b8605Smrg PAD(__pos, 8); 65848b8605Smrg 66848b8605Smrg if (__pos != __len) { 67848b8605Smrg __ret = -EINVAL; 68848b8605Smrg } else { 69848b8605Smrg rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST, __len); 70848b8605Smrg rbug_connection_write(__con, __data, __len); 71848b8605Smrg __ret = rbug_connection_send_finish(__con, __serial); 72848b8605Smrg } 73848b8605Smrg 74848b8605Smrg FREE(__data); 75848b8605Smrg return __ret; 76848b8605Smrg} 77848b8605Smrg 78848b8605Smrgint rbug_send_shader_info(struct rbug_connection *__con, 79848b8605Smrg rbug_context_t context, 80848b8605Smrg rbug_shader_t shader, 81848b8605Smrg uint32_t *__serial) 82848b8605Smrg{ 83848b8605Smrg uint32_t __len = 0; 84848b8605Smrg uint32_t __pos = 0; 85848b8605Smrg uint8_t *__data = NULL; 86848b8605Smrg int __ret = 0; 87848b8605Smrg 88848b8605Smrg LEN(8); /* header */ 89848b8605Smrg LEN(8); /* context */ 90848b8605Smrg LEN(8); /* shader */ 91848b8605Smrg 92848b8605Smrg /* align */ 93848b8605Smrg PAD(__len, 8); 94848b8605Smrg 95848b8605Smrg __data = (uint8_t*)MALLOC(__len); 96848b8605Smrg if (!__data) 97848b8605Smrg return -ENOMEM; 98848b8605Smrg 99848b8605Smrg WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO)); 100848b8605Smrg WRITE(4, uint32_t, ((uint32_t)(__len / 4))); 101848b8605Smrg WRITE(8, rbug_context_t, context); /* context */ 102848b8605Smrg WRITE(8, rbug_shader_t, shader); /* shader */ 103848b8605Smrg 104848b8605Smrg /* final pad */ 105848b8605Smrg PAD(__pos, 8); 106848b8605Smrg 107848b8605Smrg if (__pos != __len) { 108848b8605Smrg __ret = -EINVAL; 109848b8605Smrg } else { 110848b8605Smrg rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len); 111848b8605Smrg rbug_connection_write(__con, __data, __len); 112848b8605Smrg __ret = rbug_connection_send_finish(__con, __serial); 113848b8605Smrg } 114848b8605Smrg 115848b8605Smrg FREE(__data); 116848b8605Smrg return __ret; 117848b8605Smrg} 118848b8605Smrg 119848b8605Smrgint rbug_send_shader_disable(struct rbug_connection *__con, 120848b8605Smrg rbug_context_t context, 121848b8605Smrg rbug_shader_t shader, 122848b8605Smrg uint8_t disable, 123848b8605Smrg uint32_t *__serial) 124848b8605Smrg{ 125848b8605Smrg uint32_t __len = 0; 126848b8605Smrg uint32_t __pos = 0; 127848b8605Smrg uint8_t *__data = NULL; 128848b8605Smrg int __ret = 0; 129848b8605Smrg 130848b8605Smrg LEN(8); /* header */ 131848b8605Smrg LEN(8); /* context */ 132848b8605Smrg LEN(8); /* shader */ 133848b8605Smrg LEN(1); /* disable */ 134848b8605Smrg 135848b8605Smrg /* align */ 136848b8605Smrg PAD(__len, 8); 137848b8605Smrg 138848b8605Smrg __data = (uint8_t*)MALLOC(__len); 139848b8605Smrg if (!__data) 140848b8605Smrg return -ENOMEM; 141848b8605Smrg 142848b8605Smrg WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_DISABLE)); 143848b8605Smrg WRITE(4, uint32_t, ((uint32_t)(__len / 4))); 144848b8605Smrg WRITE(8, rbug_context_t, context); /* context */ 145848b8605Smrg WRITE(8, rbug_shader_t, shader); /* shader */ 146848b8605Smrg WRITE(1, uint8_t, disable); /* disable */ 147848b8605Smrg 148848b8605Smrg /* final pad */ 149848b8605Smrg PAD(__pos, 8); 150848b8605Smrg 151848b8605Smrg if (__pos != __len) { 152848b8605Smrg __ret = -EINVAL; 153848b8605Smrg } else { 154848b8605Smrg rbug_connection_send_start(__con, RBUG_OP_SHADER_DISABLE, __len); 155848b8605Smrg rbug_connection_write(__con, __data, __len); 156848b8605Smrg __ret = rbug_connection_send_finish(__con, __serial); 157848b8605Smrg } 158848b8605Smrg 159848b8605Smrg FREE(__data); 160848b8605Smrg return __ret; 161848b8605Smrg} 162848b8605Smrg 163848b8605Smrgint rbug_send_shader_replace(struct rbug_connection *__con, 164848b8605Smrg rbug_context_t context, 165848b8605Smrg rbug_shader_t shader, 166848b8605Smrg uint32_t *tokens, 167848b8605Smrg uint32_t tokens_len, 168848b8605Smrg uint32_t *__serial) 169848b8605Smrg{ 170848b8605Smrg uint32_t __len = 0; 171848b8605Smrg uint32_t __pos = 0; 172848b8605Smrg uint8_t *__data = NULL; 173848b8605Smrg int __ret = 0; 174848b8605Smrg 175848b8605Smrg LEN(8); /* header */ 176848b8605Smrg LEN(8); /* context */ 177848b8605Smrg LEN(8); /* shader */ 178848b8605Smrg LEN_ARRAY(4, tokens); /* tokens */ 179848b8605Smrg 180848b8605Smrg /* align */ 181848b8605Smrg PAD(__len, 8); 182848b8605Smrg 183848b8605Smrg __data = (uint8_t*)MALLOC(__len); 184848b8605Smrg if (!__data) 185848b8605Smrg return -ENOMEM; 186848b8605Smrg 187848b8605Smrg WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_REPLACE)); 188848b8605Smrg WRITE(4, uint32_t, ((uint32_t)(__len / 4))); 189848b8605Smrg WRITE(8, rbug_context_t, context); /* context */ 190848b8605Smrg WRITE(8, rbug_shader_t, shader); /* shader */ 191848b8605Smrg WRITE_ARRAY(4, uint32_t, tokens); /* tokens */ 192848b8605Smrg 193848b8605Smrg /* final pad */ 194848b8605Smrg PAD(__pos, 8); 195848b8605Smrg 196848b8605Smrg if (__pos != __len) { 197848b8605Smrg __ret = -EINVAL; 198848b8605Smrg } else { 199848b8605Smrg rbug_connection_send_start(__con, RBUG_OP_SHADER_REPLACE, __len); 200848b8605Smrg rbug_connection_write(__con, __data, __len); 201848b8605Smrg __ret = rbug_connection_send_finish(__con, __serial); 202848b8605Smrg } 203848b8605Smrg 204848b8605Smrg FREE(__data); 205848b8605Smrg return __ret; 206848b8605Smrg} 207848b8605Smrg 208848b8605Smrgint rbug_send_shader_list_reply(struct rbug_connection *__con, 209848b8605Smrg uint32_t serial, 210848b8605Smrg rbug_shader_t *shaders, 211848b8605Smrg uint32_t shaders_len, 212848b8605Smrg uint32_t *__serial) 213848b8605Smrg{ 214848b8605Smrg uint32_t __len = 0; 215848b8605Smrg uint32_t __pos = 0; 216848b8605Smrg uint8_t *__data = NULL; 217848b8605Smrg int __ret = 0; 218848b8605Smrg 219848b8605Smrg LEN(8); /* header */ 220848b8605Smrg LEN(4); /* serial */ 221848b8605Smrg LEN_ARRAY(8, shaders); /* shaders */ 222848b8605Smrg 223848b8605Smrg /* align */ 224848b8605Smrg PAD(__len, 8); 225848b8605Smrg 226848b8605Smrg __data = (uint8_t*)MALLOC(__len); 227848b8605Smrg if (!__data) 228848b8605Smrg return -ENOMEM; 229848b8605Smrg 230848b8605Smrg WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY)); 231848b8605Smrg WRITE(4, uint32_t, ((uint32_t)(__len / 4))); 232848b8605Smrg WRITE(4, uint32_t, serial); /* serial */ 233848b8605Smrg WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */ 234848b8605Smrg 235848b8605Smrg /* final pad */ 236848b8605Smrg PAD(__pos, 8); 237848b8605Smrg 238848b8605Smrg if (__pos != __len) { 239848b8605Smrg __ret = -EINVAL; 240848b8605Smrg } else { 241848b8605Smrg rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len); 242848b8605Smrg rbug_connection_write(__con, __data, __len); 243848b8605Smrg __ret = rbug_connection_send_finish(__con, __serial); 244848b8605Smrg } 245848b8605Smrg 246848b8605Smrg FREE(__data); 247848b8605Smrg return __ret; 248848b8605Smrg} 249848b8605Smrg 250848b8605Smrgint rbug_send_shader_info_reply(struct rbug_connection *__con, 251848b8605Smrg uint32_t serial, 252848b8605Smrg uint32_t *original, 253848b8605Smrg uint32_t original_len, 254848b8605Smrg uint32_t *replaced, 255848b8605Smrg uint32_t replaced_len, 256848b8605Smrg uint8_t disabled, 257848b8605Smrg uint32_t *__serial) 258848b8605Smrg{ 259848b8605Smrg uint32_t __len = 0; 260848b8605Smrg uint32_t __pos = 0; 261848b8605Smrg uint8_t *__data = NULL; 262848b8605Smrg int __ret = 0; 263848b8605Smrg 264848b8605Smrg LEN(8); /* header */ 265848b8605Smrg LEN(4); /* serial */ 266848b8605Smrg LEN_ARRAY(4, original); /* original */ 267848b8605Smrg LEN_ARRAY(4, replaced); /* replaced */ 268848b8605Smrg LEN(1); /* disabled */ 269848b8605Smrg 270848b8605Smrg /* align */ 271848b8605Smrg PAD(__len, 8); 272848b8605Smrg 273848b8605Smrg __data = (uint8_t*)MALLOC(__len); 274848b8605Smrg if (!__data) 275848b8605Smrg return -ENOMEM; 276848b8605Smrg 277848b8605Smrg WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO_REPLY)); 278848b8605Smrg WRITE(4, uint32_t, ((uint32_t)(__len / 4))); 279848b8605Smrg WRITE(4, uint32_t, serial); /* serial */ 280848b8605Smrg WRITE_ARRAY(4, uint32_t, original); /* original */ 281848b8605Smrg WRITE_ARRAY(4, uint32_t, replaced); /* replaced */ 282848b8605Smrg WRITE(1, uint8_t, disabled); /* disabled */ 283848b8605Smrg 284848b8605Smrg /* final pad */ 285848b8605Smrg PAD(__pos, 8); 286848b8605Smrg 287848b8605Smrg if (__pos != __len) { 288848b8605Smrg __ret = -EINVAL; 289848b8605Smrg } else { 290848b8605Smrg rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO_REPLY, __len); 291848b8605Smrg rbug_connection_write(__con, __data, __len); 292848b8605Smrg __ret = rbug_connection_send_finish(__con, __serial); 293848b8605Smrg } 294848b8605Smrg 295848b8605Smrg FREE(__data); 296848b8605Smrg return __ret; 297848b8605Smrg} 298848b8605Smrg 299848b8605Smrgstruct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header) 300848b8605Smrg{ 301848b8605Smrg uint32_t len = 0; 302848b8605Smrg uint32_t pos = 0; 303848b8605Smrg uint8_t *data = NULL; 304848b8605Smrg struct rbug_proto_shader_list *ret; 305848b8605Smrg 306848b8605Smrg if (!header) 307848b8605Smrg return NULL; 308848b8605Smrg if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST) 309848b8605Smrg return NULL; 310848b8605Smrg 311848b8605Smrg pos = 0; 312848b8605Smrg len = header->length * 4; 313848b8605Smrg data = (uint8_t*)&header[1]; 314848b8605Smrg ret = MALLOC(sizeof(*ret)); 315848b8605Smrg if (!ret) 316848b8605Smrg return NULL; 317848b8605Smrg 318848b8605Smrg ret->header.__message = header; 319848b8605Smrg ret->header.opcode = header->opcode; 320848b8605Smrg 321848b8605Smrg READ(8, rbug_context_t, context); /* context */ 322848b8605Smrg 323848b8605Smrg return ret; 324848b8605Smrg} 325848b8605Smrg 326848b8605Smrgstruct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header) 327848b8605Smrg{ 328848b8605Smrg uint32_t len = 0; 329848b8605Smrg uint32_t pos = 0; 330848b8605Smrg uint8_t *data = NULL; 331848b8605Smrg struct rbug_proto_shader_info *ret; 332848b8605Smrg 333848b8605Smrg if (!header) 334848b8605Smrg return NULL; 335848b8605Smrg if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO) 336848b8605Smrg return NULL; 337848b8605Smrg 338848b8605Smrg pos = 0; 339848b8605Smrg len = header->length * 4; 340848b8605Smrg data = (uint8_t*)&header[1]; 341848b8605Smrg ret = MALLOC(sizeof(*ret)); 342848b8605Smrg if (!ret) 343848b8605Smrg return NULL; 344848b8605Smrg 345848b8605Smrg ret->header.__message = header; 346848b8605Smrg ret->header.opcode = header->opcode; 347848b8605Smrg 348848b8605Smrg READ(8, rbug_context_t, context); /* context */ 349848b8605Smrg READ(8, rbug_shader_t, shader); /* shader */ 350848b8605Smrg 351848b8605Smrg return ret; 352848b8605Smrg} 353848b8605Smrg 354848b8605Smrgstruct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header) 355848b8605Smrg{ 356848b8605Smrg uint32_t len = 0; 357848b8605Smrg uint32_t pos = 0; 358848b8605Smrg uint8_t *data = NULL; 359848b8605Smrg struct rbug_proto_shader_disable *ret; 360848b8605Smrg 361848b8605Smrg if (!header) 362848b8605Smrg return NULL; 363848b8605Smrg if (header->opcode != (int32_t)RBUG_OP_SHADER_DISABLE) 364848b8605Smrg return NULL; 365848b8605Smrg 366848b8605Smrg pos = 0; 367848b8605Smrg len = header->length * 4; 368848b8605Smrg data = (uint8_t*)&header[1]; 369848b8605Smrg ret = MALLOC(sizeof(*ret)); 370848b8605Smrg if (!ret) 371848b8605Smrg return NULL; 372848b8605Smrg 373848b8605Smrg ret->header.__message = header; 374848b8605Smrg ret->header.opcode = header->opcode; 375848b8605Smrg 376848b8605Smrg READ(8, rbug_context_t, context); /* context */ 377848b8605Smrg READ(8, rbug_shader_t, shader); /* shader */ 378848b8605Smrg READ(1, uint8_t, disable); /* disable */ 379848b8605Smrg 380848b8605Smrg return ret; 381848b8605Smrg} 382848b8605Smrg 383848b8605Smrgstruct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header) 384848b8605Smrg{ 385848b8605Smrg uint32_t len = 0; 386848b8605Smrg uint32_t pos = 0; 387848b8605Smrg uint8_t *data = NULL; 388848b8605Smrg struct rbug_proto_shader_replace *ret; 389848b8605Smrg 390848b8605Smrg if (!header) 391848b8605Smrg return NULL; 392848b8605Smrg if (header->opcode != (int32_t)RBUG_OP_SHADER_REPLACE) 393848b8605Smrg return NULL; 394848b8605Smrg 395848b8605Smrg pos = 0; 396848b8605Smrg len = header->length * 4; 397848b8605Smrg data = (uint8_t*)&header[1]; 398848b8605Smrg ret = MALLOC(sizeof(*ret)); 399848b8605Smrg if (!ret) 400848b8605Smrg return NULL; 401848b8605Smrg 402848b8605Smrg ret->header.__message = header; 403848b8605Smrg ret->header.opcode = header->opcode; 404848b8605Smrg 405848b8605Smrg READ(8, rbug_context_t, context); /* context */ 406848b8605Smrg READ(8, rbug_shader_t, shader); /* shader */ 407848b8605Smrg READ_ARRAY(4, uint32_t, tokens); /* tokens */ 408848b8605Smrg 409848b8605Smrg return ret; 410848b8605Smrg} 411848b8605Smrg 412848b8605Smrgstruct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header) 413848b8605Smrg{ 414848b8605Smrg uint32_t len = 0; 415848b8605Smrg uint32_t pos = 0; 416848b8605Smrg uint8_t *data = NULL; 417848b8605Smrg struct rbug_proto_shader_list_reply *ret; 418848b8605Smrg 419848b8605Smrg if (!header) 420848b8605Smrg return NULL; 421848b8605Smrg if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST_REPLY) 422848b8605Smrg return NULL; 423848b8605Smrg 424848b8605Smrg pos = 0; 425848b8605Smrg len = header->length * 4; 426848b8605Smrg data = (uint8_t*)&header[1]; 427848b8605Smrg ret = MALLOC(sizeof(*ret)); 428848b8605Smrg if (!ret) 429848b8605Smrg return NULL; 430848b8605Smrg 431848b8605Smrg ret->header.__message = header; 432848b8605Smrg ret->header.opcode = header->opcode; 433848b8605Smrg 434848b8605Smrg READ(4, uint32_t, serial); /* serial */ 435848b8605Smrg READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */ 436848b8605Smrg 437848b8605Smrg return ret; 438848b8605Smrg} 439848b8605Smrg 440848b8605Smrgstruct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header) 441848b8605Smrg{ 442848b8605Smrg uint32_t len = 0; 443848b8605Smrg uint32_t pos = 0; 444848b8605Smrg uint8_t *data = NULL; 445848b8605Smrg struct rbug_proto_shader_info_reply *ret; 446848b8605Smrg 447848b8605Smrg if (!header) 448848b8605Smrg return NULL; 449848b8605Smrg if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO_REPLY) 450848b8605Smrg return NULL; 451848b8605Smrg 452848b8605Smrg pos = 0; 453848b8605Smrg len = header->length * 4; 454848b8605Smrg data = (uint8_t*)&header[1]; 455848b8605Smrg ret = MALLOC(sizeof(*ret)); 456848b8605Smrg if (!ret) 457848b8605Smrg return NULL; 458848b8605Smrg 459848b8605Smrg ret->header.__message = header; 460848b8605Smrg ret->header.opcode = header->opcode; 461848b8605Smrg 462848b8605Smrg READ(4, uint32_t, serial); /* serial */ 463848b8605Smrg READ_ARRAY(4, uint32_t, original); /* original */ 464848b8605Smrg READ_ARRAY(4, uint32_t, replaced); /* replaced */ 465848b8605Smrg READ(1, uint8_t, disabled); /* disabled */ 466848b8605Smrg 467848b8605Smrg return ret; 468848b8605Smrg} 469