Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 1 | #ifndef INTEL_BATCHBUFFER_H |
| 2 | #define INTEL_BATCHBUFFER_H |
| 3 | |
Eric Anholt | b51588b | 2009-04-07 19:07:18 -0700 | [diff] [blame] | 4 | #include <assert.h> |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 5 | #include "intel_bufmgr.h" |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 6 | |
| 7 | #define BATCH_SZ 4096 |
| 8 | #define BATCH_RESERVED 16 |
| 9 | |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 10 | struct intel_batchbuffer { |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 11 | drm_intel_bufmgr *bufmgr; |
Chris Wilson | d4d769a | 2010-10-26 10:59:18 +0100 | [diff] [blame] | 12 | uint32_t devid; |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 13 | |
| 14 | drm_intel_bo *bo; |
| 15 | |
Chris Wilson | 371f87f | 2011-02-01 10:53:57 +0000 | [diff] [blame] | 16 | uint8_t buffer[BATCH_SZ]; |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 17 | uint8_t *ptr; |
Chris Wilson | 1945e2a | 2012-12-06 17:18:52 +0000 | [diff] [blame] | 18 | uint8_t *state; |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 19 | }; |
| 20 | |
Chris Wilson | d4d769a | 2010-10-26 10:59:18 +0100 | [diff] [blame] | 21 | struct intel_batchbuffer *intel_batchbuffer_alloc(drm_intel_bufmgr *bufmgr, |
| 22 | uint32_t devid); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 23 | |
| 24 | void intel_batchbuffer_free(struct intel_batchbuffer *batch); |
| 25 | |
| 26 | |
| 27 | void intel_batchbuffer_flush(struct intel_batchbuffer *batch); |
Daniel Vetter | d42b7f9 | 2011-09-07 09:20:36 +0200 | [diff] [blame] | 28 | void intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring); |
Ben Widawsky | a635a5a | 2012-01-15 14:52:33 -0800 | [diff] [blame] | 29 | void intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch, |
| 30 | drm_intel_context *context); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 31 | |
| 32 | void intel_batchbuffer_reset(struct intel_batchbuffer *batch); |
| 33 | |
| 34 | void intel_batchbuffer_data(struct intel_batchbuffer *batch, |
| 35 | const void *data, unsigned int bytes); |
| 36 | |
| 37 | void intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch, |
| 38 | drm_intel_bo *buffer, |
| 39 | uint32_t delta, |
| 40 | uint32_t read_domains, |
Daniel Vetter | 8ab88c9 | 2011-03-27 16:17:54 +0200 | [diff] [blame] | 41 | uint32_t write_domain, |
| 42 | int fenced); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 43 | |
| 44 | /* Inline functions - might actually be better off with these |
| 45 | * non-inlined. Certainly better off switching all command packets to |
| 46 | * be passed as structs rather than dwords, but that's a little bit of |
| 47 | * work... |
| 48 | */ |
Ben Widawsky | 802bd74 | 2012-01-15 13:41:42 -0800 | [diff] [blame] | 49 | #pragma GCC diagnostic ignored "-Winline" |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 50 | static inline int |
| 51 | intel_batchbuffer_space(struct intel_batchbuffer *batch) |
| 52 | { |
Chris Wilson | 371f87f | 2011-02-01 10:53:57 +0000 | [diff] [blame] | 53 | return (BATCH_SZ - BATCH_RESERVED) - (batch->ptr - batch->buffer); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | |
| 57 | static inline void |
| 58 | intel_batchbuffer_emit_dword(struct intel_batchbuffer *batch, uint32_t dword) |
| 59 | { |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 60 | assert(intel_batchbuffer_space(batch) >= 4); |
| 61 | *(uint32_t *) (batch->ptr) = dword; |
| 62 | batch->ptr += 4; |
| 63 | } |
| 64 | |
| 65 | static inline void |
| 66 | intel_batchbuffer_require_space(struct intel_batchbuffer *batch, |
| 67 | unsigned int sz) |
| 68 | { |
Daniel Vetter | bfbe813 | 2012-05-29 22:14:06 +0200 | [diff] [blame] | 69 | assert(sz < BATCH_SZ - BATCH_RESERVED); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 70 | if (intel_batchbuffer_space(batch) < sz) |
| 71 | intel_batchbuffer_flush(batch); |
| 72 | } |
| 73 | |
| 74 | /* Here are the crusty old macros, to be removed: |
| 75 | */ |
| 76 | #define BATCH_LOCALS |
| 77 | |
| 78 | #define BEGIN_BATCH(n) do { \ |
| 79 | intel_batchbuffer_require_space(batch, (n)*4); \ |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 80 | } while (0) |
| 81 | |
| 82 | #define OUT_BATCH(d) intel_batchbuffer_emit_dword(batch, d) |
| 83 | |
Daniel Vetter | 8ab88c9 | 2011-03-27 16:17:54 +0200 | [diff] [blame] | 84 | #define OUT_RELOC_FENCED(buf, read_domains, write_domain, delta) do { \ |
| 85 | assert((delta) >= 0); \ |
| 86 | intel_batchbuffer_emit_reloc(batch, buf, delta, \ |
| 87 | read_domains, write_domain, 1); \ |
| 88 | } while (0) |
| 89 | |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 90 | #define OUT_RELOC(buf, read_domains, write_domain, delta) do { \ |
| 91 | assert((delta) >= 0); \ |
| 92 | intel_batchbuffer_emit_reloc(batch, buf, delta, \ |
Daniel Vetter | 8ab88c9 | 2011-03-27 16:17:54 +0200 | [diff] [blame] | 93 | read_domains, write_domain, 0); \ |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 94 | } while (0) |
| 95 | |
| 96 | #define ADVANCE_BATCH() do { \ |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 97 | } while(0) |
| 98 | |
Chris Wilson | 719ffef | 2011-05-22 10:34:12 +0100 | [diff] [blame] | 99 | void |
| 100 | intel_batchbuffer_emit_mi_flush(struct intel_batchbuffer *batch); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 101 | |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 102 | void intel_copy_bo(struct intel_batchbuffer *batch, |
| 103 | drm_intel_bo *dst_bo, drm_intel_bo *src_bo, |
Chris Wilson | d4d769a | 2010-10-26 10:59:18 +0100 | [diff] [blame] | 104 | int width, int height); |
Chris Wilson | 9537422 | 2010-04-08 11:56:57 +0100 | [diff] [blame] | 105 | |
Ben Widawsky | 5a28ef8 | 2012-03-18 18:42:44 -0700 | [diff] [blame] | 106 | #define I915_EXEC_CONTEXT_ID_MASK (0xffffffff) |
| 107 | #define i915_execbuffer2_set_context_id(eb2, context) \ |
| 108 | (eb2).rsvd1 = context & I915_EXEC_CONTEXT_ID_MASK |
| 109 | #define i915_execbuffer2_get_context_id(eb2) \ |
| 110 | ((eb2).rsvd1 & I915_EXEC_CONTEXT_ID_MASK) |
| 111 | |
| 112 | |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 113 | #endif |