blob: 1747e329ee9445206cc94259950146d8a8c0585e [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,
60 struct drm_i915_gem_execbuffer2 *exec,
61 struct drm_clip_rect *cliprects,
62 uint64_t exec_offset);
Zou Nan hai8d192152010-11-02 16:31:01 +080063 void (*cleanup)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080064
65 /**
66 * List of objects currently involved in rendering from the
67 * ringbuffer.
68 *
69 * Includes buffers having the contents of their GPU caches
70 * flushed, not necessarily primitives. last_rendering_seqno
71 * represents when the rendering involved will be completed.
72 *
73 * A reference is held on the buffer while on this list.
74 */
75 struct list_head active_list;
76
77 /**
78 * List of breadcrumbs associated with GPU requests currently
79 * outstanding.
80 */
81 struct list_head request_list;
82
Chris Wilsona56ba562010-09-28 10:07:56 +010083 /**
Chris Wilson64193402010-10-24 12:38:05 +010084 * List of objects currently pending a GPU write flush.
85 *
86 * All elements on this list will belong to either the
87 * active_list or flushing_list, last_rendering_seqno can
88 * be used to differentiate between the two elements.
89 */
90 struct list_head gpu_write_list;
91
92 /**
Chris Wilsona56ba562010-09-28 10:07:56 +010093 * Do we have some not yet emitted requests outstanding?
94 */
Chris Wilson5d97eb62010-11-10 20:40:02 +000095 u32 outstanding_lazy_request;
Chris Wilsona56ba562010-09-28 10:07:56 +010096
Zou Nan hai8187a2b2010-05-21 09:08:55 +080097 wait_queue_head_t irq_queue;
98 drm_local_map_t map;
Zou Nan hai8d192152010-11-02 16:31:01 +080099
100 void *private;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800101};
102
103static inline u32
104intel_read_status_page(struct intel_ring_buffer *ring,
Chris Wilson78501ea2010-10-27 12:18:21 +0100105 int reg)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800106{
Chris Wilson78501ea2010-10-27 12:18:21 +0100107 return ioread32(ring->status_page.page_addr + reg);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800108}
109
Chris Wilson78501ea2010-10-27 12:18:21 +0100110void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
Chris Wilsone1f99ce2010-10-27 12:45:26 +0100111int __must_check intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n);
112int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
Chris Wilsone898cd22010-08-04 15:18:14 +0100113
Chris Wilson78501ea2010-10-27 12:18:21 +0100114static inline void intel_ring_emit(struct intel_ring_buffer *ring,
115 u32 data)
Chris Wilsone898cd22010-08-04 15:18:14 +0100116{
Chris Wilson78501ea2010-10-27 12:18:21 +0100117 iowrite32(data, ring->virtual_start + ring->tail);
Chris Wilsone898cd22010-08-04 15:18:14 +0100118 ring->tail += 4;
119}
120
Chris Wilson78501ea2010-10-27 12:18:21 +0100121void intel_ring_advance(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800122
Chris Wilson78501ea2010-10-27 12:18:21 +0100123u32 intel_ring_get_seqno(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800124
Xiang, Haihao5c1143b2010-09-16 10:43:11 +0800125int intel_init_render_ring_buffer(struct drm_device *dev);
126int intel_init_bsd_ring_buffer(struct drm_device *dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100127int intel_init_blt_ring_buffer(struct drm_device *dev);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800128
Chris Wilson78501ea2010-10-27 12:18:21 +0100129u32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
130void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
Daniel Vetter79f321b2010-09-24 21:20:10 +0200131
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800132#endif /* _INTEL_RINGBUFFER_H_ */