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