intel_disable_clock_gating: New tool for turning off clock gating on ILK.
[platform/upstream/intel-gpu-tools.git] / lib / intel_batchbuffer.h
1 #ifndef INTEL_BATCHBUFFER_H
2 #define INTEL_BATCHBUFFER_H
3
4 #include <assert.h>
5 #include "intel_bufmgr.h"
6 #include "intel_reg.h"
7
8 #define BATCH_SZ 4096
9 #define BATCH_RESERVED 16
10
11 struct intel_batchbuffer
12 {
13         drm_intel_bufmgr *bufmgr;
14         uint32_t devid;
15
16         drm_intel_bo *bo;
17
18         uint8_t *buffer;
19
20         uint8_t *map;
21         uint8_t *ptr;
22
23         /* debug stuff */
24         struct {
25                 uint8_t *start_ptr;
26                 unsigned int total;
27         } emit;
28
29         unsigned int size;
30 };
31
32 struct intel_batchbuffer *intel_batchbuffer_alloc(drm_intel_bufmgr *bufmgr,
33                                                   uint32_t devid);
34
35 void intel_batchbuffer_free(struct intel_batchbuffer *batch);
36
37
38 void intel_batchbuffer_flush(struct intel_batchbuffer *batch);
39
40 void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
41
42 void intel_batchbuffer_data(struct intel_batchbuffer *batch,
43                             const void *data, unsigned int bytes);
44
45 void intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
46                                   drm_intel_bo *buffer,
47                                   uint32_t delta,
48                                   uint32_t read_domains,
49                                   uint32_t write_domain);
50
51 /* Inline functions - might actually be better off with these
52  * non-inlined.  Certainly better off switching all command packets to
53  * be passed as structs rather than dwords, but that's a little bit of
54  * work...
55  */
56 static inline int
57 intel_batchbuffer_space(struct intel_batchbuffer *batch)
58 {
59         return (batch->size - BATCH_RESERVED) - (batch->ptr - batch->map);
60 }
61
62
63 static inline void
64 intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, uint32_t dword)
65 {
66         assert(batch->map);
67         assert(intel_batchbuffer_space(batch) >= 4);
68         *(uint32_t *) (batch->ptr) = dword;
69         batch->ptr += 4;
70 }
71
72 static inline void
73 intel_batchbuffer_require_space(struct intel_batchbuffer *batch,
74                                 unsigned int sz)
75 {
76         assert(sz < batch->size - 8);
77         if (intel_batchbuffer_space(batch) < sz)
78                 intel_batchbuffer_flush(batch);
79 }
80
81 /* Here are the crusty old macros, to be removed:
82  */
83 #define BATCH_LOCALS
84
85 #define BEGIN_BATCH(n) do {                                             \
86         intel_batchbuffer_require_space(batch, (n)*4);                  \
87         assert(batch->emit.start_ptr == NULL);                          \
88         batch->emit.total = (n) * 4;                                    \
89         batch->emit.start_ptr = batch->ptr;                             \
90 } while (0)
91
92 #define OUT_BATCH(d) intel_batchbuffer_emit_dword(batch, d)
93
94 #define OUT_RELOC(buf, read_domains, write_domain, delta) do {          \
95         assert((delta) >= 0);                                           \
96         intel_batchbuffer_emit_reloc(batch, buf, delta,                 \
97                                      read_domains, write_domain);       \
98 } while (0)
99
100 #define ADVANCE_BATCH() do {                                            \
101         unsigned int _n = batch->ptr - batch->emit.start_ptr;           \
102         assert(batch->emit.start_ptr != NULL);                          \
103         if (_n != batch->emit.total) {                                  \
104                 fprintf(stderr,                                         \
105                         "ADVANCE_BATCH: %d of %d dwords emitted\n",     \
106                         _n, batch->emit.total);                         \
107                 abort();                                                \
108         }                                                               \
109         batch->emit.start_ptr = NULL;                                   \
110 } while(0)
111
112
113 static inline void
114 intel_batchbuffer_emit_mi_flush(struct intel_batchbuffer *batch)
115 {
116         intel_batchbuffer_require_space(batch, 4);
117         intel_batchbuffer_emit_dword(batch, MI_FLUSH);
118 }
119
120 void intel_copy_bo(struct intel_batchbuffer *batch,
121                    drm_intel_bo *dst_bo, drm_intel_bo *src_bo,
122                    int width, int height);
123
124 #endif