2006-08-22 02:24:48 -06:00
|
|
|
|
/**************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
|
|
|
|
|
* All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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, sub license, and/or sell copies of the Software, and to
|
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
* the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* 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 NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS 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.
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
|
* of the Software.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
/*
|
|
|
|
|
* Authors: Thomas Hellstr<EFBFBD>m <thomas-at-tungstengraphics-dot-com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "drmP.h"
|
2006-08-31 13:42:29 -06:00
|
|
|
|
#include "i915_drm.h"
|
|
|
|
|
#include "i915_drv.h"
|
2006-08-22 02:24:48 -06:00
|
|
|
|
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_ttm_backend *i915_create_ttm_backend_entry(struct drm_device * dev)
|
2006-08-22 02:24:48 -06:00
|
|
|
|
{
|
2007-04-18 08:33:28 -06:00
|
|
|
|
return drm_agp_init_ttm(dev);
|
2006-08-22 02:24:48 -06:00
|
|
|
|
}
|
2006-08-31 13:42:29 -06:00
|
|
|
|
|
2007-07-15 21:37:02 -06:00
|
|
|
|
int i915_fence_types(struct drm_buffer_object *bo, uint32_t * type)
|
2006-08-31 13:42:29 -06:00
|
|
|
|
{
|
2007-02-16 12:22:24 -07:00
|
|
|
|
if (bo->mem.flags & (DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE))
|
2006-08-31 13:42:29 -06:00
|
|
|
|
*type = 3;
|
2006-09-01 03:23:21 -06:00
|
|
|
|
else
|
|
|
|
|
*type = 1;
|
2006-08-31 13:42:29 -06:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
|
int i915_invalidate_caches(struct drm_device * dev, uint64_t flags)
|
2006-08-31 13:42:29 -06:00
|
|
|
|
{
|
2006-10-12 04:09:16 -06:00
|
|
|
|
/*
|
|
|
|
|
* FIXME: Only emit once per batchbuffer submission.
|
|
|
|
|
*/
|
2006-09-12 08:28:34 -06:00
|
|
|
|
|
2006-08-31 13:42:29 -06:00
|
|
|
|
uint32_t flush_cmd = MI_NO_WRITE_FLUSH;
|
|
|
|
|
|
|
|
|
|
if (flags & DRM_BO_FLAG_READ)
|
|
|
|
|
flush_cmd |= MI_READ_FLUSH;
|
|
|
|
|
if (flags & DRM_BO_FLAG_EXE)
|
|
|
|
|
flush_cmd |= MI_EXE_FLUSH;
|
|
|
|
|
|
|
|
|
|
return i915_emit_mi_flush(dev, flush_cmd);
|
|
|
|
|
}
|
2007-01-31 06:50:57 -07:00
|
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
|
int i915_init_mem_type(struct drm_device * dev, uint32_t type,
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_mem_type_manager * man)
|
2007-01-31 06:50:57 -07:00
|
|
|
|
{
|
2007-02-12 12:34:50 -07:00
|
|
|
|
switch (type) {
|
2007-01-31 06:50:57 -07:00
|
|
|
|
case DRM_BO_MEM_LOCAL:
|
2007-02-07 09:25:13 -07:00
|
|
|
|
man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
|
2007-02-12 12:34:50 -07:00
|
|
|
|
_DRM_FLAG_MEMTYPE_CACHED;
|
2007-02-14 04:39:02 -07:00
|
|
|
|
man->drm_bus_maptype = 0;
|
2007-02-07 09:25:13 -07:00
|
|
|
|
break;
|
2007-01-31 06:50:57 -07:00
|
|
|
|
case DRM_BO_MEM_TT:
|
2007-02-06 08:59:45 -07:00
|
|
|
|
if (!(drm_core_has_AGP(dev) && dev->agp)) {
|
2007-02-12 12:34:50 -07:00
|
|
|
|
DRM_ERROR("AGP is not enabled for memory type %u\n",
|
|
|
|
|
(unsigned)type);
|
2007-02-06 08:59:45 -07:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
man->io_offset = dev->agp->agp_info.aper_base;
|
|
|
|
|
man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
|
|
|
|
|
man->io_addr = NULL;
|
2007-01-31 06:50:57 -07:00
|
|
|
|
man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
|
2007-02-12 12:34:50 -07:00
|
|
|
|
_DRM_FLAG_MEMTYPE_CSELECT | _DRM_FLAG_NEEDS_IOREMAP;
|
2007-02-14 04:39:02 -07:00
|
|
|
|
man->drm_bus_maptype = _DRM_AGP;
|
2007-01-31 06:50:57 -07:00
|
|
|
|
break;
|
|
|
|
|
case DRM_BO_MEM_PRIV0:
|
|
|
|
|
if (!(drm_core_has_AGP(dev) && dev->agp)) {
|
2007-02-12 12:34:50 -07:00
|
|
|
|
DRM_ERROR("AGP is not enabled for memory type %u\n",
|
|
|
|
|
(unsigned)type);
|
2007-01-31 06:50:57 -07:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
man->io_offset = dev->agp->agp_info.aper_base;
|
|
|
|
|
man->io_size = dev->agp->agp_info.aper_size * 1024 * 1024;
|
2007-02-06 08:59:45 -07:00
|
|
|
|
man->io_addr = NULL;
|
2007-02-13 12:05:32 -07:00
|
|
|
|
man->flags = _DRM_FLAG_MEMTYPE_MAPPABLE |
|
2007-02-12 12:34:50 -07:00
|
|
|
|
_DRM_FLAG_MEMTYPE_FIXED | _DRM_FLAG_NEEDS_IOREMAP;
|
2007-02-14 04:39:02 -07:00
|
|
|
|
man->drm_bus_maptype = _DRM_AGP;
|
2007-01-31 06:50:57 -07:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2007-02-12 12:34:50 -07:00
|
|
|
|
DRM_ERROR("Unsupported memory type %u\n", (unsigned)type);
|
2007-01-31 06:50:57 -07:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2007-02-05 08:13:32 -07:00
|
|
|
|
|
2007-07-15 21:37:02 -06:00
|
|
|
|
uint32_t i915_evict_mask(struct drm_buffer_object *bo)
|
2007-02-06 06:20:33 -07:00
|
|
|
|
{
|
2007-02-16 12:22:24 -07:00
|
|
|
|
switch (bo->mem.mem_type) {
|
2007-02-06 06:20:33 -07:00
|
|
|
|
case DRM_BO_MEM_LOCAL:
|
|
|
|
|
case DRM_BO_MEM_TT:
|
|
|
|
|
return DRM_BO_FLAG_MEM_LOCAL;
|
|
|
|
|
default:
|
2007-02-13 12:05:32 -07:00
|
|
|
|
return DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_CACHED;
|
2007-02-06 06:20:33 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-15 20:32:51 -06:00
|
|
|
|
static void i915_emit_copy_blit(struct drm_device * dev,
|
2007-02-12 12:34:50 -07:00
|
|
|
|
uint32_t src_offset,
|
|
|
|
|
uint32_t dst_offset,
|
|
|
|
|
uint32_t pages, int direction)
|
2007-02-05 08:13:32 -07:00
|
|
|
|
{
|
|
|
|
|
uint32_t cur_pages;
|
|
|
|
|
uint32_t stride = PAGE_SIZE;
|
|
|
|
|
drm_i915_private_t *dev_priv = dev->dev_private;
|
|
|
|
|
RING_LOCALS;
|
|
|
|
|
|
|
|
|
|
if (!dev_priv)
|
|
|
|
|
return;
|
2007-02-12 12:34:50 -07:00
|
|
|
|
|
2007-02-09 08:36:53 -07:00
|
|
|
|
i915_kernel_lost_context(dev);
|
2007-02-12 12:34:50 -07:00
|
|
|
|
while (pages > 0) {
|
2007-02-05 08:13:32 -07:00
|
|
|
|
cur_pages = pages;
|
|
|
|
|
if (cur_pages > 2048)
|
|
|
|
|
cur_pages = 2048;
|
|
|
|
|
pages -= cur_pages;
|
|
|
|
|
|
2007-02-09 08:36:53 -07:00
|
|
|
|
BEGIN_LP_RING(6);
|
|
|
|
|
OUT_RING(SRC_COPY_BLT_CMD | XY_SRC_COPY_BLT_WRITE_ALPHA |
|
2007-02-05 08:13:32 -07:00
|
|
|
|
XY_SRC_COPY_BLT_WRITE_RGB);
|
2007-02-12 12:34:50 -07:00
|
|
|
|
OUT_RING((stride & 0xffff) | (0xcc << 16) | (1 << 24) |
|
2007-02-09 08:36:53 -07:00
|
|
|
|
(1 << 25) | (direction ? (1 << 30) : 0));
|
|
|
|
|
OUT_RING((cur_pages << 16) | PAGE_SIZE);
|
2007-02-05 08:13:32 -07:00
|
|
|
|
OUT_RING(dst_offset);
|
|
|
|
|
OUT_RING(stride & 0xffff);
|
|
|
|
|
OUT_RING(src_offset);
|
|
|
|
|
ADVANCE_LP_RING();
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-02-08 13:28:33 -07:00
|
|
|
|
|
2007-07-15 21:37:02 -06:00
|
|
|
|
static int i915_move_blit(struct drm_buffer_object * bo,
|
|
|
|
|
int evict, int no_wait, struct drm_bo_mem_reg * new_mem)
|
2007-02-08 13:28:33 -07:00
|
|
|
|
{
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_bo_mem_reg *old_mem = &bo->mem;
|
2007-02-08 13:28:33 -07:00
|
|
|
|
int dir = 0;
|
|
|
|
|
|
2007-02-12 12:34:50 -07:00
|
|
|
|
if ((old_mem->mem_type == new_mem->mem_type) &&
|
|
|
|
|
(new_mem->mm_node->start <
|
|
|
|
|
old_mem->mm_node->start + old_mem->mm_node->size)) {
|
2007-02-08 13:28:33 -07:00
|
|
|
|
dir = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i915_emit_copy_blit(bo->dev,
|
|
|
|
|
old_mem->mm_node->start << PAGE_SHIFT,
|
|
|
|
|
new_mem->mm_node->start << PAGE_SHIFT,
|
2007-02-12 12:34:50 -07:00
|
|
|
|
new_mem->num_pages, dir);
|
2007-02-08 13:28:33 -07:00
|
|
|
|
|
|
|
|
|
i915_emit_mi_flush(bo->dev, MI_READ_FLUSH | MI_EXE_FLUSH);
|
|
|
|
|
|
2007-02-15 04:10:33 -07:00
|
|
|
|
return drm_bo_move_accel_cleanup(bo, evict, no_wait, 0,
|
2007-02-08 13:28:33 -07:00
|
|
|
|
DRM_FENCE_TYPE_EXE |
|
2007-02-12 12:34:50 -07:00
|
|
|
|
DRM_I915_FENCE_TYPE_RW,
|
|
|
|
|
DRM_I915_FENCE_FLAG_FLUSHED, new_mem);
|
2007-02-08 13:28:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
2007-02-09 08:36:53 -07:00
|
|
|
|
/*
|
|
|
|
|
* Flip destination ttm into cached-coherent AGP,
|
|
|
|
|
* then blit and subsequently move out again.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-07-15 21:37:02 -06:00
|
|
|
|
static int i915_move_flip(struct drm_buffer_object * bo,
|
|
|
|
|
int evict, int no_wait, struct drm_bo_mem_reg * new_mem)
|
2007-02-09 08:36:53 -07:00
|
|
|
|
{
|
2007-07-15 20:32:51 -06:00
|
|
|
|
struct drm_device *dev = bo->dev;
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_bo_mem_reg tmp_mem;
|
2007-02-09 08:36:53 -07:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
tmp_mem = *new_mem;
|
|
|
|
|
tmp_mem.mm_node = NULL;
|
|
|
|
|
tmp_mem.mask = DRM_BO_FLAG_MEM_TT |
|
2007-02-12 12:34:50 -07:00
|
|
|
|
DRM_BO_FLAG_CACHED | DRM_BO_FLAG_FORCE_CACHING;
|
|
|
|
|
|
2007-02-12 09:47:57 -07:00
|
|
|
|
ret = drm_bo_mem_space(bo, &tmp_mem, no_wait);
|
2007-02-12 12:34:50 -07:00
|
|
|
|
if (ret)
|
2007-02-09 08:36:53 -07:00
|
|
|
|
return ret;
|
2007-02-12 12:34:50 -07:00
|
|
|
|
|
2007-02-09 08:36:53 -07:00
|
|
|
|
ret = drm_bind_ttm(bo->ttm, 1, tmp_mem.mm_node->start);
|
2007-02-12 12:34:50 -07:00
|
|
|
|
if (ret)
|
2007-02-09 08:36:53 -07:00
|
|
|
|
goto out_cleanup;
|
2007-02-08 13:28:33 -07:00
|
|
|
|
|
2007-02-09 08:36:53 -07:00
|
|
|
|
ret = i915_move_blit(bo, 1, no_wait, &tmp_mem);
|
2007-02-12 12:34:50 -07:00
|
|
|
|
if (ret)
|
2007-02-09 08:36:53 -07:00
|
|
|
|
goto out_cleanup;
|
2007-02-12 12:34:50 -07:00
|
|
|
|
|
2007-02-09 08:36:53 -07:00
|
|
|
|
ret = drm_bo_move_ttm(bo, evict, no_wait, new_mem);
|
2007-02-13 12:05:32 -07:00
|
|
|
|
out_cleanup:
|
2007-02-09 08:36:53 -07:00
|
|
|
|
if (tmp_mem.mm_node) {
|
|
|
|
|
mutex_lock(&dev->struct_mutex);
|
2007-02-13 12:05:32 -07:00
|
|
|
|
if (tmp_mem.mm_node != bo->pinned_node)
|
|
|
|
|
drm_mm_put_block(tmp_mem.mm_node);
|
2007-02-09 08:36:53 -07:00
|
|
|
|
tmp_mem.mm_node = NULL;
|
|
|
|
|
mutex_unlock(&dev->struct_mutex);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-15 21:37:02 -06:00
|
|
|
|
int i915_move(struct drm_buffer_object * bo,
|
|
|
|
|
int evict, int no_wait, struct drm_bo_mem_reg * new_mem)
|
2007-02-09 08:36:53 -07:00
|
|
|
|
{
|
2007-07-15 21:37:02 -06:00
|
|
|
|
struct drm_bo_mem_reg *old_mem = &bo->mem;
|
2007-02-09 08:36:53 -07:00
|
|
|
|
|
2007-02-10 04:06:36 -07:00
|
|
|
|
if (old_mem->mem_type == DRM_BO_MEM_LOCAL) {
|
2007-02-09 08:36:53 -07:00
|
|
|
|
return drm_bo_move_memcpy(bo, evict, no_wait, new_mem);
|
2007-02-10 04:06:36 -07:00
|
|
|
|
} else if (new_mem->mem_type == DRM_BO_MEM_LOCAL) {
|
2007-02-12 12:34:50 -07:00
|
|
|
|
if (i915_move_flip(bo, evict, no_wait, new_mem))
|
|
|
|
|
return drm_bo_move_memcpy(bo, evict, no_wait, new_mem);
|
2007-02-09 08:36:53 -07:00
|
|
|
|
} else {
|
2007-02-12 09:47:57 -07:00
|
|
|
|
if (i915_move_blit(bo, evict, no_wait, new_mem))
|
2007-02-12 12:34:50 -07:00
|
|
|
|
return drm_bo_move_memcpy(bo, evict, no_wait, new_mem);
|
2007-02-09 08:36:53 -07:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|