2006-08-22 02:24:48 -06:00
|
|
|
|
/**************************************************************************
|
2007-11-04 19:42:22 -07:00
|
|
|
|
*
|
2006-08-22 02:24:48 -06:00
|
|
|
|
* Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
|
|
|
|
|
* All Rights Reserved.
|
2007-11-04 19:42:22 -07:00
|
|
|
|
*
|
2006-08-22 02:24:48 -06:00
|
|
|
|
* 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:
|
2007-11-04 19:42:22 -07:00
|
|
|
|
*
|
2006-08-22 02:24:48 -06:00
|
|
|
|
* 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,
|
2007-11-04 19:42:22 -07:00
|
|
|
|
* 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
|
2006-08-22 02:24:48 -06:00
|
|
|
|
* 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.
|
2007-11-04 19:42:22 -07:00
|
|
|
|
*
|
|
|
|
|
*
|
2006-08-22 02:24:48 -06:00
|
|
|
|
**************************************************************************/
|
|
|
|
|
/*
|
|
|
|
|
* 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-11-05 18:32:58 -07: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-09-22 05:34:33 -06:00
|
|
|
|
int i915_fence_types(struct drm_buffer_object *bo,
|
2007-11-05 18:32:58 -07:00
|
|
|
|
uint32_t *fclass,
|
|
|
|
|
uint32_t *type)
|
2006-08-31 13:42:29 -06:00
|
|
|
|
{
|
2007-10-11 17:46:11 -06:00
|
|
|
|
if (bo->mem.mask & (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-11-05 18:32:58 -07: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-11-05 18:32:58 -07:00
|
|
|
|
int i915_init_mem_type(struct drm_device *dev, uint32_t type,
|
|
|
|
|
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-09-22 05:34:33 -06:00
|
|
|
|
man->gpu_offset = 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-09-22 05:34:33 -06:00
|
|
|
|
man->gpu_offset = 0;
|
2007-01-31 06:50:57 -07:00
|
|
|
|
break;
|
2007-05-22 14:38:58 -06:00
|
|
|
|
case DRM_BO_MEM_VRAM:
|
2007-01-31 06:50:57 -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-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-09-22 05:34:33 -06:00
|
|
|
|
man->gpu_offset = 0;
|
2007-01-31 06:50:57 -07:00
|
|
|
|
break;
|
2007-05-22 14:38:58 -06:00
|
|
|
|
case DRM_BO_MEM_PRIV0: /* for OS preallocated space */
|
|
|
|
|
DRM_ERROR("PRIV0 not used yet.\n");
|
|
|
|
|
break;
|
2007-01-31 06:50:57 -07:00
|
|
|
|
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-10-21 04:31:00 -06:00
|
|
|
|
#if 0 /* See comment below */
|
|
|
|
|
|
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;
|
2007-09-24 15:41:46 -06:00
|
|
|
|
struct drm_i915_private *dev_priv = dev->dev_private;
|
2007-02-05 08:13:32 -07:00
|
|
|
|
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
|
|
|
|
/*
|
2007-11-04 19:42:22 -07:00
|
|
|
|
* Flip destination ttm into cached-coherent AGP,
|
2007-02-09 08:36:53 -07:00
|
|
|
|
* 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-09-22 05:34:33 -06:00
|
|
|
|
ret = drm_bind_ttm(bo->ttm, &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-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-10-21 04:31:00 -06:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
2007-11-05 18:32:58 -07:00
|
|
|
|
* Disable i915_move_flip for now, since we can't guarantee that the hardware
|
|
|
|
|
* lock is held here. To re-enable we need to make sure either
|
2007-10-21 04:31:00 -06:00
|
|
|
|
* a) The X server is using DRM to submit commands to the ring, or
|
2007-11-05 18:32:58 -07:00
|
|
|
|
* b) DRM can use the HP ring for these blits. This means i915 needs to
|
|
|
|
|
* implement a new ring submission mechanism and fence class.
|
2007-10-21 04:31:00 -06:00
|
|
|
|
*/
|
2007-11-05 18:32:58 -07: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-11-05 18:32:58 -07:00
|
|
|
|
if (0) /*i915_move_flip(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
|
|
|
|
} else {
|
2007-11-05 18:32:58 -07:00
|
|
|
|
if (0) /*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;
|
|
|
|
|
}
|
2007-10-30 01:51:59 -06:00
|
|
|
|
|
|
|
|
|
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
|
|
|
|
|
static inline void clflush(volatile void *__p)
|
|
|
|
|
{
|
|
|
|
|
asm volatile("clflush %0" : "+m" (*(char __force *)__p));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static inline void drm_cache_flush_addr(void *virt)
|
2007-11-04 19:42:22 -07:00
|
|
|
|
{
|
2007-11-05 18:32:58 -07:00
|
|
|
|
int i;
|
2007-10-30 01:51:59 -06:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < PAGE_SIZE; i += boot_cpu_data.x86_clflush_size)
|
|
|
|
|
clflush(virt+i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void drm_cache_flush_page(struct page *p)
|
|
|
|
|
{
|
|
|
|
|
drm_cache_flush_addr(page_address(p));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void i915_flush_ttm(struct drm_ttm *ttm)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (!ttm)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
DRM_MEMORYBARRIER();
|
|
|
|
|
for (i = ttm->num_pages-1; i >= 0; i--)
|
|
|
|
|
drm_cache_flush_page(drm_ttm_get_page(ttm, i));
|
|
|
|
|
DRM_MEMORYBARRIER();
|
|
|
|
|
}
|