1
2
3
4
5
6
7#ifndef INTEL_RING_H
8#define INTEL_RING_H
9
10#include "i915_gem.h"
11#include "i915_request.h"
12#include "intel_ring_types.h"
13
14struct intel_engine_cs;
15
16struct intel_ring *
17intel_engine_create_ring(struct intel_engine_cs *engine, int size);
18
19u32 *intel_ring_begin(struct i915_request *rq, unsigned int num_dwords);
20int intel_ring_cacheline_align(struct i915_request *rq);
21
22unsigned int intel_ring_update_space(struct intel_ring *ring);
23
24int intel_ring_pin(struct intel_ring *ring);
25void intel_ring_unpin(struct intel_ring *ring);
26void intel_ring_reset(struct intel_ring *ring, u32 tail);
27
28void intel_ring_free(struct kref *ref);
29
30static inline struct intel_ring *intel_ring_get(struct intel_ring *ring)
31{
32 kref_get(&ring->ref);
33 return ring;
34}
35
36static inline void intel_ring_put(struct intel_ring *ring)
37{
38 kref_put(&ring->ref, intel_ring_free);
39}
40
41static inline void intel_ring_advance(struct i915_request *rq, u32 *cs)
42{
43
44
45
46
47
48
49
50
51 GEM_BUG_ON((rq->ring->vaddr + rq->ring->emit) != cs);
52}
53
54static inline u32 intel_ring_wrap(const struct intel_ring *ring, u32 pos)
55{
56 return pos & (ring->size - 1);
57}
58
59static inline int intel_ring_direction(const struct intel_ring *ring,
60 u32 next, u32 prev)
61{
62 typecheck(typeof(ring->size), next);
63 typecheck(typeof(ring->size), prev);
64 return (next - prev) << ring->wrap;
65}
66
67static inline bool
68intel_ring_offset_valid(const struct intel_ring *ring,
69 unsigned int pos)
70{
71 if (pos & -ring->size)
72 return false;
73
74 if (!IS_ALIGNED(pos, 8))
75 return false;
76
77 return true;
78}
79
80static inline u32 intel_ring_offset(const struct i915_request *rq, void *addr)
81{
82
83 u32 offset = addr - rq->ring->vaddr;
84 GEM_BUG_ON(offset > rq->ring->size);
85 return intel_ring_wrap(rq->ring, offset);
86}
87
88static inline void
89assert_ring_tail_valid(const struct intel_ring *ring, unsigned int tail)
90{
91 GEM_BUG_ON(!intel_ring_offset_valid(ring, tail));
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107#define cacheline(a) round_down(a, CACHELINE_BYTES)
108 GEM_BUG_ON(cacheline(tail) == cacheline(ring->head) &&
109 tail < ring->head);
110#undef cacheline
111}
112
113static inline unsigned int
114intel_ring_set_tail(struct intel_ring *ring, unsigned int tail)
115{
116
117
118
119
120
121
122 assert_ring_tail_valid(ring, tail);
123 ring->tail = tail;
124 return tail;
125}
126
127static inline unsigned int
128__intel_ring_space(unsigned int head, unsigned int tail, unsigned int size)
129{
130
131
132
133
134
135 GEM_BUG_ON(!is_power_of_2(size));
136 return (head - tail - CACHELINE_BYTES) & (size - 1);
137}
138
139#endif
140