1
2
3
4
5
6#ifndef INTEL_RING_H
7#define INTEL_RING_H
8
9#include "i915_gem.h"
10#include "i915_request.h"
11#include "intel_ring_types.h"
12
13struct intel_engine_cs;
14
15struct intel_ring *
16intel_engine_create_ring(struct intel_engine_cs *engine, int size);
17
18u32 *intel_ring_begin(struct i915_request *rq, unsigned int num_dwords);
19int intel_ring_cacheline_align(struct i915_request *rq);
20
21unsigned int intel_ring_update_space(struct intel_ring *ring);
22
23void __intel_ring_pin(struct intel_ring *ring);
24int intel_ring_pin(struct intel_ring *ring, struct i915_gem_ww_ctx *ww);
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 GEM_BUG_ON(!IS_ALIGNED(rq->ring->emit, 8));
53}
54
55static inline u32 intel_ring_wrap(const struct intel_ring *ring, u32 pos)
56{
57 return pos & (ring->size - 1);
58}
59
60static inline int intel_ring_direction(const struct intel_ring *ring,
61 u32 next, u32 prev)
62{
63 typecheck(typeof(ring->size), next);
64 typecheck(typeof(ring->size), prev);
65 return (next - prev) << ring->wrap;
66}
67
68static inline bool
69intel_ring_offset_valid(const struct intel_ring *ring,
70 unsigned int pos)
71{
72 if (pos & -ring->size)
73 return false;
74
75 if (!IS_ALIGNED(pos, 8))
76 return false;
77
78 return true;
79}
80
81static inline u32 intel_ring_offset(const struct i915_request *rq, void *addr)
82{
83
84 u32 offset = addr - rq->ring->vaddr;
85
86 GEM_BUG_ON(offset > rq->ring->size);
87 return intel_ring_wrap(rq->ring, offset);
88}
89
90static inline void
91assert_ring_tail_valid(const struct intel_ring *ring, unsigned int tail)
92{
93 unsigned int head = READ_ONCE(ring->head);
94
95 GEM_BUG_ON(!intel_ring_offset_valid(ring, tail));
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111#define cacheline(a) round_down(a, CACHELINE_BYTES)
112 GEM_BUG_ON(cacheline(tail) == cacheline(head) && tail < head);
113#undef cacheline
114}
115
116static inline unsigned int
117intel_ring_set_tail(struct intel_ring *ring, unsigned int tail)
118{
119
120
121
122
123
124
125 assert_ring_tail_valid(ring, tail);
126 ring->tail = tail;
127 return tail;
128}
129
130static inline unsigned int
131__intel_ring_space(unsigned int head, unsigned int tail, unsigned int size)
132{
133
134
135
136
137
138 GEM_BUG_ON(!is_power_of_2(size));
139 return (head - tail - CACHELINE_BYTES) & (size - 1);
140}
141
142#endif
143