blob: d73145c790bd6a8433b2df3d5af63680e91f4bcf [file] [log] [blame]
Zou Nan hai8187a2b2010-05-21 09:08:55 +08001#ifndef _INTEL_RINGBUFFER_H_
2#define _INTEL_RINGBUFFER_H_
3
4struct intel_hw_status_page {
Chris Wilson78501ea2010-10-27 12:18:21 +01005 u32 __iomem *page_addr;
Zou Nan hai8187a2b2010-05-21 09:08:55 +08006 unsigned int gfx_addr;
7 struct drm_gem_object *obj;
8};
9
Daniel Vetter870e86d2010-08-02 16:29:44 +020010#define I915_READ_TAIL(ring) I915_READ(RING_TAIL(ring->mmio_base))
11#define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL(ring->mmio_base), val)
Daniel Vetter6c0e1c52010-08-02 16:33:33 +020012#define I915_READ_START(ring) I915_READ(RING_START(ring->mmio_base))
13#define I915_WRITE_START(ring, val) I915_WRITE(RING_START(ring->mmio_base), val)
Daniel Vetter570ef602010-08-02 17:06:23 +020014#define I915_READ_HEAD(ring) I915_READ(RING_HEAD(ring->mmio_base))
15#define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD(ring->mmio_base), val)
Daniel Vetter7f2ab692010-08-02 17:06:59 +020016#define I915_READ_CTL(ring) I915_READ(RING_CTL(ring->mmio_base))
17#define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL(ring->mmio_base), val)
Daniel Vetter870e86d2010-08-02 16:29:44 +020018
Zou Nan hai8187a2b2010-05-21 09:08:55 +080019struct drm_i915_gem_execbuffer2;
20struct intel_ring_buffer {
21 const char *name;
Chris Wilson92204342010-09-18 11:02:01 +010022 enum intel_ring_id {
23 RING_RENDER = 0x1,
24 RING_BSD = 0x2,
Chris Wilson549f7362010-10-19 11:19:32 +010025 RING_BLT = 0x4,
Chris Wilson92204342010-09-18 11:02:01 +010026 } id;
Daniel Vetter333e9fe2010-08-02 16:24:01 +020027 u32 mmio_base;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080028 void *virtual_start;
29 struct drm_device *dev;
30 struct drm_gem_object *gem_object;
31
32 unsigned int head;
33 unsigned int tail;
Chris Wilson780f0ca2010-09-23 17:45:39 +010034 int space;
Chris Wilsonc2c347a92010-10-27 15:11:53 +010035 int size;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080036 struct intel_hw_status_page status_page;
37
Chris Wilsonb2223492010-10-27 15:27:33 +010038 u32 irq_seqno; /* last seq seem at irq time */
39 u32 waiting_seqno;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080040 int user_irq_refcount;
Chris Wilson78501ea2010-10-27 12:18:21 +010041 void (*user_irq_get)(struct intel_ring_buffer *ring);
42 void (*user_irq_put)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080043
Chris Wilson78501ea2010-10-27 12:18:21 +010044 int (*init)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080045
Chris Wilson78501ea2010-10-27 12:18:21 +010046 void (*write_tail)(struct intel_ring_buffer *ring,
Chris Wilson297b0c52010-10-22 17:02:41 +010047 u32 value);
Chris Wilson78501ea2010-10-27 12:18:21 +010048 void (*flush)(struct intel_ring_buffer *ring,
49 u32 invalidate_domains,
50 u32 flush_domains);
Chris Wilson3cce4692010-10-27 16:11:02 +010051 int (*add_request)(struct intel_ring_buffer *ring,
52 u32 *seqno);
Chris Wilson78501ea2010-10-27 12:18:21 +010053 u32 (*get_seqno)(struct intel_ring_buffer *ring);
54 int (*dispatch_execbuffer)(struct intel_ring_buffer *ring,
55 struct drm_i915_gem_execbuffer2 *exec,
56 struct drm_clip_rect *cliprects,
57 uint64_t exec_offset);
Zou Nan hai8d192152010-11-02 16:31:01 +080058 void (*cleanup)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080059
60 /**
61 * List of objects currently involved in rendering from the
62 * ringbuffer.
63 *
64 * Includes buffers having the contents of their GPU caches
65 * flushed, not necessarily primitives. last_rendering_seqno
66 * represents when the rendering involved will be completed.
67 *
68 * A reference is held on the buffer while on this list.
69 */
70 struct list_head active_list;
71
72 /**
73 * List of breadcrumbs associated with GPU requests currently
74 * outstanding.
75 */
76 struct list_head request_list;
77
Chris Wilsona56ba562010-09-28 10:07:56 +010078 /**
Chris Wilson64193402010-10-24 12:38:05 +010079 * List of objects currently pending a GPU write flush.
80 *
81 * All elements on this list will belong to either the
82 * active_list or flushing_list, last_rendering_seqno can
83 * be used to differentiate between the two elements.
84 */
85 struct list_head gpu_write_list;
86
87 /**
Chris Wilsona56ba562010-09-28 10:07:56 +010088 * Do we have some not yet emitted requests outstanding?
89 */
Chris Wilson5d97eb62010-11-10 20:40:02 +000090 u32 outstanding_lazy_request;
Chris Wilsona56ba562010-09-28 10:07:56 +010091
Zou Nan hai8187a2b2010-05-21 09:08:55 +080092 wait_queue_head_t irq_queue;
93 drm_local_map_t map;
Zou Nan hai8d192152010-11-02 16:31:01 +080094
95 void *private;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080096};
97
98static inline u32
99intel_read_status_page(struct intel_ring_buffer *ring,
Chris Wilson78501ea2010-10-27 12:18:21 +0100100 int reg)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800101{
Chris Wilson78501ea2010-10-27 12:18:21 +0100102 return ioread32(ring->status_page.page_addr + reg);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800103}
104
Chris Wilson78501ea2010-10-27 12:18:21 +0100105void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
Chris Wilsone1f99ce2010-10-27 12:45:26 +0100106int __must_check intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n);
107int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
Chris Wilsone898cd22010-08-04 15:18:14 +0100108
Chris Wilson78501ea2010-10-27 12:18:21 +0100109static inline void intel_ring_emit(struct intel_ring_buffer *ring,
110 u32 data)
Chris Wilsone898cd22010-08-04 15:18:14 +0100111{
Chris Wilson78501ea2010-10-27 12:18:21 +0100112 iowrite32(data, ring->virtual_start + ring->tail);
Chris Wilsone898cd22010-08-04 15:18:14 +0100113 ring->tail += 4;
114}
115
Chris Wilson78501ea2010-10-27 12:18:21 +0100116void intel_ring_advance(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800117
Chris Wilson78501ea2010-10-27 12:18:21 +0100118u32 intel_ring_get_seqno(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800119
Xiang, Haihao5c1143b2010-09-16 10:43:11 +0800120int intel_init_render_ring_buffer(struct drm_device *dev);
121int intel_init_bsd_ring_buffer(struct drm_device *dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100122int intel_init_blt_ring_buffer(struct drm_device *dev);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800123
Chris Wilson78501ea2010-10-27 12:18:21 +0100124u32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
125void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
Daniel Vetter79f321b2010-09-24 21:20:10 +0200126
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800127#endif /* _INTEL_RINGBUFFER_H_ */