1 /************************************************************************** 2 * 3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 6 * Copyright 2014, 2015 Intel Corporation 7 * All Rights Reserved. 8 * 9 * Permission is hereby granted, free of charge, to any person obtaining a 10 * copy of this software and associated documentation files (the 11 * "Software"), to deal in the Software without restriction, including 12 * without limitation the rights to use, copy, modify, merge, publish, 13 * distribute, sub license, and/or sell copies of the Software, and to 14 * permit persons to whom the Software is furnished to do so, subject to 15 * the following conditions: 16 * 17 * The above copyright notice and this permission notice (including the 18 * next paragraph) shall be included in all copies or substantial portions 19 * of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 24 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 * 29 **************************************************************************/ 30 31 #ifndef _INTEL_BATCHBUFFER_H 32 #define _INTEL_BATCHBUFFER_H 33 34 #include <stdint.h> 35 36 #define MAX_RELOCS 64 37 #define MAX_ITEMS 1024 38 #define MAX_STRLEN 256 39 40 #define ALIGN(x, y) (((x) + (y)-1) & ~((y)-1)) 41 42 typedef enum { 43 UNINITIALIZED, 44 CMD, 45 STATE, 46 RELOC, 47 RELOC_STATE, 48 STATE_OFFSET, 49 PAD, 50 } item_type; 51 52 struct bb_item { 53 uint32_t data; 54 item_type type; 55 char str[MAX_STRLEN]; 56 }; 57 58 struct bb_area { 59 struct bb_item item[MAX_ITEMS]; 60 unsigned long num_items; 61 }; 62 63 struct intel_batchbuffer { 64 struct bb_area *cmds; 65 struct bb_area *state; 66 unsigned long cmds_end_offset; 67 unsigned long state_start_offset; 68 }; 69 70 struct intel_batchbuffer *intel_batchbuffer_create(void); 71 72 #define OUT_CMD_B(cmd, len, bias) intel_batch_cmd_emit_null(batch, (cmd), (len), (bias), #cmd " " #len) 73 #define OUT_CMD(cmd, len) OUT_CMD_B(cmd, len, 2) 74 75 #define OUT_BATCH(d) bb_area_emit(batch->cmds, d, CMD, #d) 76 #define OUT_BATCH_STATE_OFFSET(d) bb_area_emit(batch->cmds, d, STATE_OFFSET, #d) 77 #define OUT_RELOC(batch, read_domain, write_domain, d) bb_area_emit(batch->cmds, d, RELOC, #d) 78 #define OUT_RELOC_STATE(batch, read_domain, write_domain, d) bb_area_emit(batch->cmds, d, RELOC_STATE, #d); 79 #define OUT_STATE(d) bb_area_emit(batch->state, d, STATE, #d) 80 #define OUT_STATE_OFFSET(offset) bb_area_emit(batch->state, offset, STATE_OFFSET, #offset) 81 #define OUT_STATE_STRUCT(name, align) intel_batch_state_copy(batch, &name, sizeof(name), align, #name " " #align) 82 83 uint32_t intel_batch_state_copy(struct intel_batchbuffer *batch, const void *d, unsigned bytes, unsigned align, 84 const char *name); 85 uint32_t intel_batch_state_alloc(struct intel_batchbuffer *batch, unsigned bytes, unsigned align, 86 const char *name); 87 uint32_t intel_batch_state_offset(struct intel_batchbuffer *batch, unsigned align); 88 unsigned intel_batch_num_cmds(struct intel_batchbuffer *batch); 89 struct bb_item *intel_batch_state_get(struct intel_batchbuffer *batch, unsigned i); 90 unsigned intel_batch_num_state(struct intel_batchbuffer *batch); 91 92 struct bb_item *intel_batch_cmd_get(struct intel_batchbuffer *batch, unsigned i); 93 int intel_batch_is_reloc(struct intel_batchbuffer *batch, unsigned i); 94 95 void intel_batch_relocate_state(struct intel_batchbuffer *batch); 96 97 const char *intel_batch_type_as_str(const struct bb_item *item); 98 99 void bb_area_emit(struct bb_area *a, uint32_t dword, item_type type, const char *str); 100 void bb_area_emit_offset(struct bb_area *a, unsigned i, uint32_t dword, item_type type, const char *str); 101 102 void intel_batch_cmd_emit_null(struct intel_batchbuffer *batch, 103 const int cmd, 104 const int len, const int len_bias, 105 const char *str); 106 #endif 107