1450N/A/*
1450N/A * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
1450N/A */
1450N/A
1450N/A/*
1450N/A * Copyright (c) 2008-2010, 2013, Intel Corporation
1450N/A *
1450N/A * Permission is hereby granted, free of charge, to any person obtaining a
1450N/A * copy of this software and associated documentation files (the "Software"),
1450N/A * to deal in the Software without restriction, including without limitation
1450N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1450N/A * and/or sell copies of the Software, and to permit persons to whom the
1450N/A * Software is furnished to do so, subject to the following conditions:
1450N/A *
1450N/A * The above copyright notice and this permission notice (including the next
1450N/A * paragraph) shall be included in all copies or substantial portions of the
1450N/A * Software.
1450N/A *
1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1450N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1450N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1450N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
1450N/A * IN THE SOFTWARE.
1450N/A *
1450N/A * Authors:
1450N/A * Eric Anholt <eric@anholt.net>
1450N/A * Zou Nan hai <nanhai.zou@intel.com>
1450N/A * Xiang Hai hao<haihao.xiang@intel.com>
1450N/A *
1450N/A */
1450N/A
1450N/A#ifndef _INTEL_RINGBUFFER_H_
1450N/A#define _INTEL_RINGBUFFER_H_
1450N/A
1450N/A/*
1450N/A * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
1450N/A * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
1450N/A * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
1450N/A *
1450N/A * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
1450N/A * cacheline, the Head Pointer must not be greater than the Tail
1450N/A * Pointer."
1450N/A */
1450N/A#define I915_RING_FREE_SPACE 64
1450N/A
1450N/Astruct intel_hw_status_page {
1450N/A void *page_addr;
1450N/A unsigned int gfx_addr;
1450N/A struct drm_i915_gem_object *obj;
1450N/A};
1450N/A
1450N/A#define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base))
1450N/A#define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
1450N/A
1450N/A#define I915_READ_START(ring) I915_READ(RING_START((ring)->mmio_base))
1450N/A#define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val)
1450N/A
1450N/A#define I915_READ_HEAD(ring) I915_READ(RING_HEAD((ring)->mmio_base))
1450N/A#define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val)
1450N/A
1450N/A#define I915_READ_CTL(ring) I915_READ(RING_CTL((ring)->mmio_base))
1450N/A#define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val)
1450N/A
1450N/A#define I915_READ_IMR(ring) I915_READ(RING_IMR((ring)->mmio_base))
1450N/A#define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val)
1450N/A
1450N/A#define I915_READ_NOPID(ring) I915_READ(RING_NOPID((ring)->mmio_base))
1450N/A#define I915_READ_SYNC_0(ring) I915_READ(RING_SYNC_0((ring)->mmio_base))
1450N/A#define I915_READ_SYNC_1(ring) I915_READ(RING_SYNC_1((ring)->mmio_base))
1450N/A
1450N/Aenum intel_ring_hangcheck_action { wait, active, kick, hung };
1450N/A
1450N/Astruct intel_ring_hangcheck {
1450N/A bool deadlock;
1450N/A u32 seqno;
1450N/A u32 acthd;
1450N/A int score;
1450N/A enum intel_ring_hangcheck_action action;
1450N/A};
1450N/A
1450N/Astruct intel_ring_buffer {
1450N/A const char *name;
1450N/A enum intel_ring_id {
1450N/A RCS = 0x0,
1450N/A VCS,
1450N/A BCS,
1450N/A VECS,
1450N/A } id;
1450N/A#define I915_NUM_RINGS 4
1450N/A u32 mmio_base;
1450N/A void *virtual_start;
1450N/A struct drm_device *dev;
1450N/A struct drm_i915_gem_object *obj;
1450N/A
1450N/A u32 head;
1450N/A u32 tail;
1450N/A int space;
1450N/A int size;
1450N/A int effective_size;
1450N/A struct intel_hw_status_page status_page;
1450N/A
1450N/A /** We track the position of the requests in the ring buffer, and
1450N/A * when each is retired we increment last_retired_head as the GPU
1450N/A * must have finished processing the request and so we know we
1450N/A * can advance the ringbuffer up to that position.
1450N/A *
1450N/A * last_retired_head is set to -1 after the value is consumed so
1450N/A * we can detect new retirements.
1450N/A */
1450N/A u32 last_retired_head;
1450N/A
1450N/A struct {
1450N/A u32 gt; /* protected by dev_priv->irq_lock */
1450N/A u32 pm; /* protected by dev_priv->rps.lock (sucks) */
1450N/A } irq_refcount;
1450N/A u32 irq_enable_mask; /* bitmask to enable ring interrupt */
1450N/A u32 trace_irq_seqno;
1450N/A u32 sync_seqno[I915_NUM_RINGS-1];
1450N/A bool (*irq_get)(struct intel_ring_buffer *ring);
1450N/A void (*irq_put)(struct intel_ring_buffer *ring);
1450N/A
1450N/A int (*init)(struct intel_ring_buffer *ring);
1450N/A
1450N/A void (*write_tail)(struct intel_ring_buffer *ring,
1450N/A u32 value);
1450N/A int (*flush)(struct intel_ring_buffer *ring,
1450N/A u32 invalidate_domains,
1450N/A u32 flush_domains);
1450N/A int (*add_request)(struct intel_ring_buffer *ring);
1450N/A /* Some chipsets are not quite as coherent as advertised and need
1450N/A * an expensive kick to force a true read of the up-to-date seqno.
1450N/A * However, the up-to-date seqno is not always required and the last
1450N/A * seen value is good enough. Note that the seqno will always be
1450N/A * monotonic, even if not coherent.
1450N/A */
1450N/A u32 (*get_seqno)(struct intel_ring_buffer *ring,
1450N/A bool lazy_coherency);
1450N/A void (*set_seqno)(struct intel_ring_buffer *ring,
1450N/A u32 seqno);
1450N/A int (*dispatch_execbuffer)(struct intel_ring_buffer *ring,
1450N/A u32 offset, u32 length,
1450N/A unsigned flags);
1450N/A#define I915_DISPATCH_SECURE 0x1
1450N/A#define I915_DISPATCH_PINNED 0x2
1450N/A void (*cleanup)(struct intel_ring_buffer *ring);
1450N/A int (*sync_to)(struct intel_ring_buffer *ring,
1450N/A struct intel_ring_buffer *to,
1450N/A u32 seqno);
1450N/A
1450N/A /* our mbox written by others */
1450N/A u32 semaphore_register[I915_NUM_RINGS];
1450N/A /* mboxes this ring signals to */
1450N/A u32 signal_mbox[I915_NUM_RINGS];
1450N/A
1450N/A /**
1450N/A * List of objects currently involved in rendering from the
1450N/A * ringbuffer.
1450N/A *
1450N/A * Includes buffers having the contents of their GPU caches
1450N/A * flushed, not necessarily primitives. last_rendering_seqno
1450N/A * represents when the rendering involved will be completed.
1450N/A *
1450N/A * A reference is held on the buffer while on this list.
1450N/A */
1450N/A struct list_head active_list;
1450N/A
1450N/A /**
1450N/A * List of breadcrumbs associated with GPU requests currently
1450N/A * outstanding.
1450N/A */
1450N/A struct list_head request_list;
1450N/A
1450N/A /**
1450N/A * Do we have some not yet emitted requests outstanding?
1450N/A */
1450N/A u32 outstanding_lazy_request;
1450N/A bool gpu_caches_dirty;
1450N/A bool fbc_dirty;
1450N/A
1450N/A wait_queue_head_t irq_queue;
1450N/A drm_local_map_t map;
1450N/A
1450N/A /**
1450N/A * Do an explicit TLB flush before MI_SET_CONTEXT
1450N/A */
1450N/A bool itlb_before_ctx_switch;
1450N/A struct i915_hw_context *default_context;
1450N/A struct i915_hw_context *last_context;
1450N/A
1450N/A struct intel_ring_hangcheck hangcheck;
1450N/A
1450N/A void *private;
1450N/A};
1450N/A
1450N/Astatic inline bool
1450N/Aintel_ring_initialized(struct intel_ring_buffer *ring)
1450N/A{
1450N/A return ring->obj != NULL;
1450N/A}
1450N/A
1450N/Astatic inline unsigned
1450N/Aintel_ring_flag(struct intel_ring_buffer *ring)
1450N/A{
1450N/A return 1 << ring->id;
1450N/A}
1450N/A
1450N/Astatic inline u32
1450N/Aintel_ring_sync_index(struct intel_ring_buffer *ring,
1450N/A struct intel_ring_buffer *other)
1450N/A{
1450N/A int idx;
1450N/A
1450N/A /*
1450N/A * cs -> 0 = vcs, 1 = bcs
1450N/A * vcs -> 0 = bcs, 1 = cs,
1450N/A * bcs -> 0 = cs, 1 = vcs.
1450N/A */
1450N/A
1450N/A idx = (other - ring) - 1;
1450N/A if (idx < 0)
1450N/A idx += I915_NUM_RINGS;
1450N/A
1450N/A return idx;
1450N/A}
1450N/A
1450N/Astatic inline u32
1450N/Aintel_read_status_page(struct intel_ring_buffer *ring,
1450N/A int reg)
1450N/A{
1450N/A u32 *regs = ring->status_page.page_addr;
1450N/A return regs[reg];
1450N/A}
1450N/A
1450N/Astatic inline void
1450N/Aintel_write_status_page(struct intel_ring_buffer *ring,
1450N/A int reg, u32 value)
1450N/A{
1450N/A u32 *regs = ring->status_page.page_addr;
1450N/A regs[reg] = value;
1450N/A}
1450N/A
1450N/A/**
1450N/A * Reads a dword out of the status page, which is written to from the command
1450N/A * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
1450N/A * MI_STORE_DATA_IMM.
1450N/A *
1450N/A * The following dwords have a reserved meaning:
1450N/A * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
1450N/A * 0x04: ring 0 head pointer
1450N/A * 0x05: ring 1 head pointer (915-class)
1450N/A * 0x06: ring 2 head pointer (915-class)
1450N/A * 0x10-0x1b: Context status DWords (GM45)
1450N/A * 0x1f: Last written status offset. (GM45)
1450N/A *
1450N/A * The area from dword 0x20 to 0x3ff is available for driver usage.
1450N/A */
1450N/A#define I915_GEM_HWS_INDEX 0x20
1450N/A#define I915_GEM_HWS_SCRATCH_INDEX 0x30
1450N/A#define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
1450N/A
1450N/Avoid intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
1450N/A
1450N/Aint intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n);
1450N/Aint intel_wait_ring_idle(struct intel_ring_buffer *ring);
1450N/A
1450N/Aint intel_ring_begin(struct intel_ring_buffer *ring, int n);
1450N/A
1450N/Astatic inline void intel_ring_emit(struct intel_ring_buffer *ring,
1450N/A u32 data)
1450N/A{
1450N/A unsigned int *virt = (unsigned int *)((intptr_t)ring->virtual_start + ring->tail);
1450N/A *virt = data;
1450N/A ring->tail += 4;
1450N/A}
1450N/A
1450N/Avoid intel_ring_advance(struct intel_ring_buffer *ring);
1450N/Aint intel_ring_idle(struct intel_ring_buffer *ring);
1450N/Avoid intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno);
1450N/Aint intel_ring_flush_all_caches(struct intel_ring_buffer *ring);
1450N/Aint intel_ring_invalidate_all_caches(struct intel_ring_buffer *ring);
1450N/A
1450N/Aint intel_init_render_ring_buffer(struct drm_device *dev);
1450N/Aint intel_init_bsd_ring_buffer(struct drm_device *dev);
1450N/Aint intel_init_blt_ring_buffer(struct drm_device *dev);
1450N/Aint intel_init_vebox_ring_buffer(struct drm_device *dev);
1450N/A
1450N/Au32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
1450N/Avoid intel_ring_setup_status_page(struct intel_ring_buffer *ring);
1450N/A
1450N/Astatic inline u32 intel_ring_get_tail(struct intel_ring_buffer *ring)
1450N/A{
1450N/A return ring->tail;
1450N/A}
1450N/A
1450N/Astatic inline u32 intel_ring_get_seqno(struct intel_ring_buffer *ring)
1450N/A{
1450N/A BUG_ON(ring->outstanding_lazy_request == 0);
1450N/A return ring->outstanding_lazy_request;
1450N/A}
1450N/A
1450N/Astatic inline void i915_trace_irq_get(struct intel_ring_buffer *ring, u32 seqno)
1450N/A{
1450N/A if (ring->trace_irq_seqno == 0 && ring->irq_get(ring))
1450N/A ring->trace_irq_seqno = seqno;
1450N/A}
1450N/A
1450N/A/* DRI warts */
1450N/Aint intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size);
1450N/A
1450N/A#endif /* _INTEL_RINGBUFFER_H_ */