/*
*/
/*
* Copyright (c) 2008-2010, 2013, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* Authors:
* Eric Anholt <eric@anholt.net>
* Zou Nan hai <nanhai.zou@intel.com>
* Xiang Hai hao<haihao.xiang@intel.com>
*
*/
#include "drmP.h"
#include "drm.h"
#include "i915_drv.h"
#include "i915_drm.h"
#include "intel_drv.h"
/*
* 965+ support PIPE_CONTROL commands, which provide finer grained control
* over cache flushing.
*/
struct pipe_control {
};
{
if (space < 0)
return space;
}
static int
{
int ret;
cmd |= MI_NO_WRITE_FLUSH;
cmd |= MI_READ_FLUSH;
if (ret)
return ret;
return 0;
}
static int
{
int ret;
/*
*
* I915_GEM_DOMAIN_RENDER is always invalidated, but is
* only flushed if MI_NO_WRITE_FLUSH is unset. On 965, it is
* also flushed at 2d versus 3d pipeline switches.
*
* read-only caches:
*
* I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if
* MI_READ_FLUSH is set, and is always flushed on 965.
*
* I915_GEM_DOMAIN_COMMAND may not exist?
*
* I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is
* invalidated when MI_EXE_FLUSH is set.
*
* I915_GEM_DOMAIN_VERTEX, which exists on 965, is
* invalidated with every MI_FLUSH.
*
* TLBs:
*
* On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND
* and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and
* I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER
* are flushed at any MI_FLUSH.
*/
cmd &= ~MI_NO_WRITE_FLUSH;
cmd |= MI_EXE_FLUSH;
cmd |= MI_INVALIDATE_ISP;
if (ret)
return ret;
return 0;
}
/**
* Emits a PIPE_CONTROL with a non-zero post-sync operation, for
* implementing two workarounds on gen6. From section 1.4.7.1
* "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1:
*
* [DevSNB-C+{W/A}] Before any depth stall flush (including those
* produced by non-pipelined state commands), software needs to first
* send a PIPE_CONTROL with no bits set except Post-Sync Operation !=
* 0.
*
* [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache Flush Enable
* =1, a PIPE_CONTROL with any non-zero post-sync-op is required.
*
* And the workaround for these two requires this workaround first:
*
* [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent
* BEFORE the pipe-control with a post-sync op and no write-cache
* flushes.
*
* And this last workaround is tricky because of the requirements on
* that bit. From section 1.4.7.2.3 "Stall" of the Sandy Bridge PRM
* volume 2 part 1:
*
* "1 of the following must also be set:
* - Render Target Cache Flush Enable ([12] of DW1)
* - Depth Cache Flush Enable ([0] of DW1)
* - Stall at Pixel Scoreboard ([1] of DW1)
* - Depth Stall ([13] of DW1)
* - Post-Sync Operation ([13] of DW1)
* - Notify Enable ([8] of DW1)"
*
* The cache flushes require the workaround flush that triggered this
* one, so we can't use it. Depth stall would trigger the same.
* Post-sync nonzero is what triggered this second workaround, so we
* can't use that one either. Notify enable is IRQs, which aren't
* really our business. That leaves only stall at scoreboard.
*/
static int
{
int ret;
if (ret)
return ret;
if (ret)
return ret;
intel_ring_emit(ring, 0);
intel_ring_emit(ring, 0);
return 0;
}
static int
{
int ret;
/* Force SNB workarounds for PIPE_CONTROL flushes */
if (ret)
return ret;
/* Just flush everything. Experiments have shown that reducing the
* number of bits based on the write domains has little performance
* impact.
*/
if (flush_domains) {
/*
* Ensure that any following seqno writes only happen
* when the render cache is indeed flushed.
*/
}
if (invalidate_domains) {
/*
* TLB invalidate requires a post-sync write.
*/
}
if (ret)
return ret;
return 0;
}
static int
{
int ret;
if (ret)
return ret;
intel_ring_emit(ring, 0);
intel_ring_emit(ring, 0);
return 0;
}
{
int ret;
return 0;
if (ret)
return ret;
return 0;
}
static int
{
int ret;
/*
* Ensure that any following seqno writes only happen when the render
* cache is indeed flushed.
*
* Workaround: 4th PIPE_CONTROL command (except the ones with only
* read-cache invalidate bits set) must have the CS_STALL bit set. We
* don't try to be clever and just set it unconditionally.
*/
/* Just flush everything. Experiments have shown that reducing the
* number of bits based on the write domains has little performance
* impact.
*/
if (flush_domains) {
}
if (invalidate_domains) {
/*
* TLB invalidate requires a post-sync write.
*/
/* Workaround: we must issue a pipe_control with CS-stall bit
* set before a pipe_control command that has the state cache
* invalidate bit set. */
}
if (ret)
return ret;
intel_ring_emit(ring, 0);
if (flush_domains)
return 0;
}
{
}
{
}
{
}
{
int ret = 0;
if (HAS_FORCE_WAKE(dev))
if (I915_NEED_GFX_HWS(dev))
else
/* Stop the ring if it's running. */
I915_WRITE_CTL(ring, 0);
I915_WRITE_HEAD(ring, 0);
/* G45 ring initialization fails to reset head to zero */
if (head != 0) {
DRM_DEBUG_KMS("%s head not reset to zero "
"ctl %08x head %08x tail %08x start %08x\n",
I915_WRITE_HEAD(ring, 0);
DRM_ERROR("failed to set %s head to zero "
"ctl %08x head %08x tail %08x start %08x\n",
}
}
/* Initialize the ring. This must happen _after_ we've cleared the ring
* registers with the above sequence (the readback of the HEAD registers
* also enforces ordering), otherwise the hw might lose the new ring
* register values. */
| RING_VALID);
/* If the head is still not zero, the ring is dead */
DRM_ERROR("%s initialization failed "
"ctl %08x head %08x tail %08x start %08x\n",
goto out;
}
else {
}
out:
if (HAS_FORCE_WAKE(dev))
return ret;
}
static int
{
int ret;
return 0;
if (!pc)
return -ENOMEM;
DRM_ERROR("Failed to allocate seqno page\n");
goto err;
}
if (ret)
goto err_unref;
/*LINTED E_BAD_PTR_CAST_ALIGN*/
goto err_unpin;
DRM_DEBUG_DRIVER("%s pipe control offset: 0x%08x\n",
return 0;
err:
return ret;
}
static void
{
}
{
/* We need to disable the AsyncFlip performance optimisations in order
* to use MI_WAIT_FOR_EVENT within the CS. It should already be
* programmed to '1' on all products.
*
* WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv
*/
/* Required for the hardware to program scanline values for waiting */
if (ret)
return ret;
}
/* From the Sandybridge PRM, volume 1 part 3, page 24:
* "If this bit is set, STCunit will have LRA as replacement
* policy. [...] This bit must be reset. LRA replacement
* policy is not supported."
*/
/* This is not explicitly set for GEN6, so read the register.
* see intel_ring_mi_set_context() for why we care.
* TODO: consider explicitly setting the bit for GEN5
*/
}
if (HAS_L3_GPU_CACHE(dev))
return ret;
}
{
return;
if (HAS_BROKEN_CS_TLB(dev))
}
static void
{
/* NB: In order to be able to do semaphore MBOX updates for varying number
* of rings, it's easiest if we round up each individual update to a
* multiple of 2 (since ring updates must always be a multiple of 2)
* even though the actual update only requires 3 dwords.
*/
}
/**
* gen6_add_request - Update the semaphore mailbox registers
*
* @ring - ring that is adding a request
* @seqno - return seqno stuck into the ring
*
* Update the mailbox registers in the *other* rings with the current seqno.
* This acts like a signal in the canonical semaphore.
*/
static int
{
int i, ret;
4);
if (ret)
return ret;
if (mbox_reg != GEN6_NOSYNC)
}
return 0;
}
{
}
/**
* intel_ring_sync - sync the waiter to the signaller on seqno
*
* @waiter - ring that is waiting
* @signaller - ring which has, or will signal
* @seqno - seqno which the waiter will block on
*/
static int
struct intel_ring_buffer *signaller,
{
int ret;
/* Throughout all of the GEM code, seqno passed implies our current
* seqno is >= the last seqno executed. However for hardware the
* comparison is strictly greater than.
*/
seqno -= 1;
if (ret)
return ret;
/* If seqno wrap happened, omit the wait with no-ops */
dw1 |
intel_ring_emit(waiter, 0);
} else {
}
return 0;
}
do { \
intel_ring_emit(ring__, 0); \
intel_ring_emit(ring__, 0); \
} while (0)
static int
{
int ret;
/* For Ironlake, MI_USER_INTERRUPT was deprecated and apparently
* incoherent with writes to memory, i.e. completely fubar,
* so we need to use PIPE_NOTIFY instead.
*
* However, we also need to workaround the qword write
* incoherence by flushing the 6 PIPE_NOTIFY buffers out to
* memory before requesting an interrupt.
*/
if (ret)
return ret;
intel_ring_emit(ring, 0);
scratch_addr += 128;
scratch_addr += 128;
scratch_addr += 128;
scratch_addr += 128;
intel_ring_emit(ring, 0);
return 0;
}
static u32
{
/* Workaround to force correct ordering between irq and seqno writes on
* ivb (and maybe also on snb) by reading from a CS register (like
* ACTHD) before reading the status page. */
if (!lazy_coherency)
(void) intel_ring_get_active_head(ring);
}
static u32
{
}
static void
{
}
static u32
{
}
static void
{
}
static bool
{
unsigned long flags;
if (!dev->irq_enabled)
return false;
}
return true;
}
static void
{
unsigned long flags;
}
}
static bool
{
unsigned long flags;
if (!dev->irq_enabled)
return false;
}
return true;
}
static void
{
unsigned long flags;
}
}
static bool
{
unsigned long flags;
if (!dev->irq_enabled)
return false;
}
return true;
}
static void
{
unsigned long flags;
}
}
{
/* The ring status page addresses are no longer next to the rest of
* the ring registers as of gen7.
*/
case RCS:
break;
case BCS:
break;
case VCS:
break;
case VECS:
break;
}
} else {
}
/* Flush the TLB for this page */
1000))
DRM_ERROR("%s: wait for SyncFlush to complete for TLB invalidation timed out\n",
}
}
static int
{
int ret;
if (ret)
return ret;
return 0;
}
static int
{
int ret;
if (ret)
return ret;
return 0;
}
static bool
{
unsigned long flags;
if (!dev->irq_enabled)
return false;
/* It looks like we need to prevent the gt from suspending while waiting
* for an notifiy irq, otherwise irqs seem to get lost on at least the
~(ring->irq_enable_mask |
else
}
return true;
}
static void
{
unsigned long flags;
else
I915_WRITE_IMR(ring, ~0);
}
}
static bool
{
unsigned long flags;
if (!dev->irq_enabled)
return false;
}
return true;
}
static void
{
unsigned long flags;
if (!dev->irq_enabled)
return;
I915_WRITE_IMR(ring, ~0);
}
}
static int
unsigned flags)
{
int ret;
if (ret)
return ret;
return 0;
}
/* Just userspace ABI convention to limit the wa batch bo to a resonable size */
static int
unsigned flags)
{
int ret;
if (flags & I915_DISPATCH_PINNED) {
if (ret)
return ret;
} else {
if (len > I830_BATCH_LIMIT)
return -ENOSPC;
if (ret)
return ret;
/* Blit the batch (which has now all relocs applied) to the stable batch
* scratch bo area (so that the CS never stumbles over its tlb
* invalidation bug) ... */
intel_ring_emit(ring, 0);
intel_ring_emit(ring, 0);
/* ... and execute it. */
}
return 0;
}
static int
unsigned flags)
{
int ret;
if (ret)
return ret;
return 0;
}
{
return;
}
{
int ret;
DRM_ERROR("Failed to allocate status page\n");
goto err;
}
goto err_unref;
if (ret != 0) {
goto err_unref;
}
goto err_unpin;
}
DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n",
return 0;
err:
return ret;
}
{
if (!dev_priv->status_page_dmah) {
if (!dev_priv->status_page_dmah)
return -ENOMEM;
}
return 0;
}
struct intel_ring_buffer *ring)
{
int ret;
if (I915_NEED_GFX_HWS(dev)) {
if (ret)
return ret;
} else {
if (ret)
return ret;
}
DRM_ERROR("Failed to allocate ringbuffer\n");
goto err_hws;
}
if (ret)
goto err_unref;
if (ret)
goto err_unpin;
DRM_ERROR("Failed to map ringbuffer.\n");
goto err_unpin;
}
if (ret)
goto err_unmap;
/* Workaround an erratum on the i830 which causes a hang if
* the TAIL pointer points to within the last 2 cachelines
* of the buffer.
*/
return 0;
return ret;
}
{
int ret;
return;
/* Disable the ring buffer. The ring must be idle at this point */
if (ret)
DRM_ERROR("failed to quiesce %s whilst cleaning up: %d\n",
I915_WRITE_CTL(ring, 0);
}
{
int ret;
if (!ret)
return ret;
}
{
int ret;
return 0;
}
int space;
continue;
if (space < 0)
if (space >= n) {
break;
}
/* Consume this request in case we need more space than
* is available and so need to prevent a race between
* updating last_retired_head and direct reads of
* I915_RING_HEAD. It also provides a nice sanity check.
*/
}
if (seqno == 0)
return -ENOSPC;
if (ret)
return ret;
return -ENOSPC;
}
return -ENOSPC;
}
return 0;
}
{
unsigned long end;
int ret;
return ret;
/* With GEM the hangcheck timer should kick us out of the loop,
* leaving it early runs the risk of corrupting GEM state (due
* to running on almost untested codepaths). But on resume
* timers don't work yet, so prevent a complete hang in that
* case by choosing an insanely large timeout. */
do {
return 0;
}
if (master_priv->sarea_priv)
}
msleep(1);
if (ret)
return ret;
return -EBUSY;
}
{
unsigned int *virt;
if (ret)
return ret;
}
while (rem--) {
}
return 0;
}
{
int ret;
/* We need to add any requests required to flush the objects and ring */
if (ring->outstanding_lazy_request) {
if (ret)
return ret;
}
/* Wait upon the last request to be completed */
return 0;
struct drm_i915_gem_request,
list);
}
static int
{
if (ring->outstanding_lazy_request)
return 0;
}
int bytes)
{
int ret;
if (ret)
return ret;
}
if (ret)
return ret;
}
return 0;
}
int num_dwords)
{
int ret;
if (ret)
return ret;
/* Preallocate the olr before touching the ring */
if (ret)
return ret;
}
{
}
}
{
return;
}
{
/* Every tail move must follow the sequence below */
/* Disable notification that the ring is IDLE. The GT
* will then assume that it is busy and bring it out of rc6.
*/
/* Clear the context id. Here be magic! */
/* Wait for the ring not to be idle, i.e. for it to wake up. */
GEN6_BSD_SLEEP_INDICATOR) == 0,
50))
DRM_ERROR("timed out waiting for the BSD ring to wake up\n");
/* Now that the ring is fully powered up, update the tail */
/* Let the ring send IDLE messages to the GT again,
* and so let it sleep to conserve power when idle.
*/
}
{
int ret;
if (ret)
return ret;
cmd = MI_FLUSH_DW;
/*
* Bspec vol 1c.5 - video engine command streamer:
* "If ENABLED, all TLBs will be invalidated once the flush
* operation is complete. This bit is only valid when the
* Post-Sync Operation field is a value of 1h or 3h."
*/
if (invalidate & I915_GEM_GPU_DOMAINS)
intel_ring_emit(ring, 0);
return 0;
}
static int
unsigned flags)
{
int ret;
if (ret)
return ret;
/* bit0-7 is the length on GEN6+ */
return 0;
}
static int
unsigned flags)
{
int ret;
if (ret)
return ret;
/* bit0-7 is the length on GEN6+ */
return 0;
}
/* Blitter support (SandyBridge+) */
{
int ret;
if (ret)
return ret;
cmd = MI_FLUSH_DW;
/*
* Bspec vol 1c.3 - blitter engine command streamer:
* "If ENABLED, all TLBs will be invalidated once the flush
* operation is complete. This bit is only valid when the
* Post-Sync Operation field is a value of 1h or 3h."
*/
if (invalidate & I915_GEM_DOMAIN_RENDER)
intel_ring_emit(ring, 0);
return 0;
}
{
} else {
else
} else {
}
}
if (IS_HASWELL(dev))
else
/* Workaround batchbuffer to combat CS tlb bug. */
if (HAS_BROKEN_CS_TLB(dev)) {
int ret;
DRM_ERROR("Failed to allocate batch bo\n");
return -ENOMEM;
}
if (ret != 0) {
DRM_ERROR("Failed to ping batch bo\n");
return ret;
}
}
}
{
int ret;
/* non-kms not supported on gen6+ */
return -ENODEV;
}
* gem_init ioctl returns with -ENODEV). Hence we do not need to set up
* the special gen5 functions. */
else
} else {
}
else
DRM_ERROR("can not ioremap virtual address for"
" ring buffer\n");
return -ENOMEM;
}
if (!I915_NEED_GFX_HWS(dev)) {
if (ret)
return ret;
}
return 0;
}
{
/* gen6 bsd needs a special wa for tail updates */
} else {
} else {
}
}
}
{
}
{
}
int
{
int ret;
if (!ring->gpu_caches_dirty)
return 0;
if (ret)
return ret;
ring->gpu_caches_dirty = false;
return 0;
}
int
{
int ret;
flush_domains = 0;
if (ring->gpu_caches_dirty)
if (ret)
return ret;
ring->gpu_caches_dirty = false;
return 0;
}