blob: 8e3526777926c70a75a01099f21406ba435c46e6 [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;
Chris Wilson05394f32010-11-08 19:18:58 +00007 struct drm_i915_gem_object *obj;
Zou Nan hai8187a2b2010-05-21 09:08:55 +08008};
9
Zou Nan haicae58522010-11-09 17:17:32 +080010#define I915_RING_READ(reg) i915_safe_read(dev_priv, reg)
11
12#define I915_READ_TAIL(ring) I915_RING_READ(RING_TAIL(ring->mmio_base))
Daniel Vetter870e86d2010-08-02 16:29:44 +020013#define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL(ring->mmio_base), val)
Zou Nan haicae58522010-11-09 17:17:32 +080014
15#define I915_READ_START(ring) I915_RING_READ(RING_START(ring->mmio_base))
Daniel Vetter6c0e1c52010-08-02 16:33:33 +020016#define I915_WRITE_START(ring, val) I915_WRITE(RING_START(ring->mmio_base), val)
Zou Nan haicae58522010-11-09 17:17:32 +080017
18#define I915_READ_HEAD(ring) I915_RING_READ(RING_HEAD(ring->mmio_base))
Daniel Vetter570ef602010-08-02 17:06:23 +020019#define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD(ring->mmio_base), val)
Zou Nan haicae58522010-11-09 17:17:32 +080020
21#define I915_READ_CTL(ring) I915_RING_READ(RING_CTL(ring->mmio_base))
Daniel Vetter7f2ab692010-08-02 17:06:59 +020022#define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL(ring->mmio_base), val)
Daniel Vetter870e86d2010-08-02 16:29:44 +020023
Zou Nan hai8187a2b2010-05-21 09:08:55 +080024struct drm_i915_gem_execbuffer2;
25struct intel_ring_buffer {
26 const char *name;
Chris Wilson92204342010-09-18 11:02:01 +010027 enum intel_ring_id {
28 RING_RENDER = 0x1,
29 RING_BSD = 0x2,
Chris Wilson549f7362010-10-19 11:19:32 +010030 RING_BLT = 0x4,
Chris Wilson92204342010-09-18 11:02:01 +010031 } id;
Daniel Vetter333e9fe2010-08-02 16:24:01 +020032 u32 mmio_base;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080033 void *virtual_start;
34 struct drm_device *dev;
Chris Wilson05394f32010-11-08 19:18:58 +000035 struct drm_i915_gem_object *obj;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080036
37 unsigned int head;
38 unsigned int tail;
Chris Wilson780f0ca2010-09-23 17:45:39 +010039 int space;
Chris Wilsonc2c347a92010-10-27 15:11:53 +010040 int size;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080041 struct intel_hw_status_page status_page;
42
Chris Wilsonb2223492010-10-27 15:27:33 +010043 u32 irq_seqno; /* last seq seem at irq time */
44 u32 waiting_seqno;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080045 int user_irq_refcount;
Chris Wilson78501ea2010-10-27 12:18:21 +010046 void (*user_irq_get)(struct intel_ring_buffer *ring);
47 void (*user_irq_put)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080048
Chris Wilson78501ea2010-10-27 12:18:21 +010049 int (*init)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080050
Chris Wilson78501ea2010-10-27 12:18:21 +010051 void (*write_tail)(struct intel_ring_buffer *ring,
Chris Wilson297b0c52010-10-22 17:02:41 +010052 u32 value);
Chris Wilson78501ea2010-10-27 12:18:21 +010053 void (*flush)(struct intel_ring_buffer *ring,
54 u32 invalidate_domains,
55 u32 flush_domains);
Chris Wilson3cce4692010-10-27 16:11:02 +010056 int (*add_request)(struct intel_ring_buffer *ring,
57 u32 *seqno);
Chris Wilson78501ea2010-10-27 12:18:21 +010058 u32 (*get_seqno)(struct intel_ring_buffer *ring);
59 int (*dispatch_execbuffer)(struct intel_ring_buffer *ring,
Chris Wilsonc4e7a412010-11-30 14:10:25 +000060 u32 offset, u32 length);
Zou Nan hai8d192152010-11-02 16:31:01 +080061 void (*cleanup)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080062
63 /**
64 * List of objects currently involved in rendering from the
65 * ringbuffer.
66 *
67 * Includes buffers having the contents of their GPU caches
68 * flushed, not necessarily primitives. last_rendering_seqno
69 * represents when the rendering involved will be completed.
70 *
71 * A reference is held on the buffer while on this list.
72 */
73 struct list_head active_list;
74
75 /**
76 * List of breadcrumbs associated with GPU requests currently
77 * outstanding.
78 */
79 struct list_head request_list;
80
Chris Wilsona56ba562010-09-28 10:07:56 +010081 /**
Chris Wilson64193402010-10-24 12:38:05 +010082 * List of objects currently pending a GPU write flush.
83 *
84 * All elements on this list will belong to either the
85 * active_list or flushing_list, last_rendering_seqno can
86 * be used to differentiate between the two elements.
87 */
88 struct list_head gpu_write_list;
89
90 /**
Chris Wilsona56ba562010-09-28 10:07:56 +010091 * Do we have some not yet emitted requests outstanding?
92 */
Chris Wilson5d97eb62010-11-10 20:40:02 +000093 u32 outstanding_lazy_request;
Chris Wilsona56ba562010-09-28 10:07:56 +010094
Zou Nan hai8187a2b2010-05-21 09:08:55 +080095 wait_queue_head_t irq_queue;
96 drm_local_map_t map;
Zou Nan hai8d192152010-11-02 16:31:01 +080097
98 void *private;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080099};
100
101static inline u32
102intel_read_status_page(struct intel_ring_buffer *ring,
Chris Wilson78501ea2010-10-27 12:18:21 +0100103 int reg)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800104{
Chris Wilson78501ea2010-10-27 12:18:21 +0100105 return ioread32(ring->status_page.page_addr + reg);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800106}
107
Chris Wilson78501ea2010-10-27 12:18:21 +0100108void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
Chris Wilsone1f99ce2010-10-27 12:45:26 +0100109int __must_check intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n);
110int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
Chris Wilsone898cd22010-08-04 15:18:14 +0100111
Chris Wilson78501ea2010-10-27 12:18:21 +0100112static inline void intel_ring_emit(struct intel_ring_buffer *ring,
113 u32 data)
Chris Wilsone898cd22010-08-04 15:18:14 +0100114{
Chris Wilson78501ea2010-10-27 12:18:21 +0100115 iowrite32(data, ring->virtual_start + ring->tail);
Chris Wilsone898cd22010-08-04 15:18:14 +0100116 ring->tail += 4;
117}
118
Chris Wilson78501ea2010-10-27 12:18:21 +0100119void intel_ring_advance(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800120
Chris Wilson78501ea2010-10-27 12:18:21 +0100121u32 intel_ring_get_seqno(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800122
Xiang, Haihao5c1143b2010-09-16 10:43:11 +0800123int intel_init_render_ring_buffer(struct drm_device *dev);
124int intel_init_bsd_ring_buffer(struct drm_device *dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100125int intel_init_blt_ring_buffer(struct drm_device *dev);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800126
Chris Wilson78501ea2010-10-27 12:18:21 +0100127u32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
128void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
Daniel Vetter79f321b2010-09-24 21:20:10 +0200129
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800130#endif /* _INTEL_RINGBUFFER_H_ */