blob: 771d1c801492ae96e5d003668ede665e3df789f3 [file] [log] [blame]
Mika Kuoppalad60d4c82014-04-10 15:15:13 +03001/**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
Thomas Woodb9d27f02015-08-26 12:05:13 +01006 * Copyright 2014, 2015 Intel Corporation
Mika Kuoppalad60d4c82014-04-10 15:15:13 +03007 * 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
Mika Kuoppalaa1f847c2014-10-09 18:39:05 +030037#define MAX_ITEMS 1024
Mika Kuoppala4a604de2014-08-01 21:19:56 +030038#define MAX_STRLEN 256
39
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030040#define ALIGN(x, y) (((x) + (y)-1) & ~((y)-1))
41
Mika Kuoppala4a604de2014-08-01 21:19:56 +030042typedef enum {
43 UNINITIALIZED,
44 CMD,
45 STATE,
46 RELOC,
47 RELOC_STATE,
48 STATE_OFFSET,
49 PAD,
50} item_type;
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030051
Mika Kuoppala4a604de2014-08-01 21:19:56 +030052struct bb_item {
53 uint32_t data;
54 item_type type;
55 char str[MAX_STRLEN];
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030056};
57
Mika Kuoppala4a604de2014-08-01 21:19:56 +030058struct bb_area {
59 struct bb_item item[MAX_ITEMS];
60 unsigned long num_items;
61};
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030062
Mika Kuoppala4a604de2014-08-01 21:19:56 +030063struct 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};
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030069
Mika Kuoppala4a604de2014-08-01 21:19:56 +030070struct intel_batchbuffer *intel_batchbuffer_create(void);
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030071
Mika Kuoppalab69659c2014-09-08 10:41:38 +030072#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
Mika Kuoppala4a604de2014-08-01 21:19:56 +030075#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)
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030082
Thomas Wood35465142015-09-08 16:49:24 +010083uint32_t intel_batch_state_copy(struct intel_batchbuffer *batch, const void *d, unsigned bytes, unsigned align,
Mika Kuoppala4a604de2014-08-01 21:19:56 +030084 const char *name);
85uint32_t intel_batch_state_alloc(struct intel_batchbuffer *batch, unsigned bytes, unsigned align,
86 const char *name);
Mika Kuoppala0e8ac722014-09-08 10:49:59 +030087uint32_t intel_batch_state_offset(struct intel_batchbuffer *batch, unsigned align);
Mika Kuoppala4a604de2014-08-01 21:19:56 +030088unsigned intel_batch_num_cmds(struct intel_batchbuffer *batch);
Thomas Woodb9d27f02015-08-26 12:05:13 +010089struct bb_item *intel_batch_state_get(struct intel_batchbuffer *batch, unsigned i);
90unsigned intel_batch_num_state(struct intel_batchbuffer *batch);
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030091
Mika Kuoppala4a604de2014-08-01 21:19:56 +030092struct bb_item *intel_batch_cmd_get(struct intel_batchbuffer *batch, unsigned i);
93int intel_batch_is_reloc(struct intel_batchbuffer *batch, unsigned i);
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030094
Mika Kuoppala4a604de2014-08-01 21:19:56 +030095void intel_batch_relocate_state(struct intel_batchbuffer *batch);
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030096
Mika Kuoppala4a604de2014-08-01 21:19:56 +030097const char *intel_batch_type_as_str(const struct bb_item *item);
Mika Kuoppalad60d4c82014-04-10 15:15:13 +030098
Mika Kuoppala4a604de2014-08-01 21:19:56 +030099void bb_area_emit(struct bb_area *a, uint32_t dword, item_type type, const char *str);
100void bb_area_emit_offset(struct bb_area *a, unsigned i, uint32_t dword, item_type type, const char *str);
Mika Kuoppalad60d4c82014-04-10 15:15:13 +0300101
Mika Kuoppalab69659c2014-09-08 10:41:38 +0300102void 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);
Mika Kuoppalad60d4c82014-04-10 15:15:13 +0300106#endif