2007-06-26 14:10:30 -06:00
|
|
|
/****************************************************************************
|
2007-07-24 14:36:02 -06:00
|
|
|
* Copyright (C) 2003-2006 by XGI Technology, Taiwan.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
2007-06-26 14:10:30 -06:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
2007-07-24 14:36:02 -06:00
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation on the rights to use, copy, modify, merge,
|
|
|
|
* publish, distribute, sublicense, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* XGI 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.
|
2007-06-26 14:10:30 -06:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "xgi_drv.h"
|
|
|
|
|
|
|
|
#define XGI_FB_HEAP_START 0x1000000
|
|
|
|
|
2007-08-06 17:09:05 -06:00
|
|
|
int xgi_alloc(struct xgi_info * info, struct xgi_mem_alloc * alloc,
|
2007-08-09 16:30:36 -06:00
|
|
|
struct drm_file * filp)
|
2007-07-19 11:29:18 -06:00
|
|
|
{
|
2007-08-09 17:01:14 -06:00
|
|
|
struct drm_memblock_item *block;
|
2007-08-09 16:30:36 -06:00
|
|
|
const char *const mem_name = (alloc->location == XGI_MEMLOC_LOCAL)
|
|
|
|
? "on-card" : "GART";
|
|
|
|
|
|
|
|
|
|
|
|
if ((alloc->location != XGI_MEMLOC_LOCAL)
|
|
|
|
&& (alloc->location != XGI_MEMLOC_NON_LOCAL)) {
|
|
|
|
DRM_ERROR("Invalid memory pool (0x%08x) specified.\n",
|
|
|
|
alloc->location);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2007-08-09 17:01:14 -06:00
|
|
|
if ((alloc->location == XGI_MEMLOC_LOCAL)
|
|
|
|
? !info->fb_heap_initialized : !info->pcie_heap_initialized) {
|
2007-08-09 16:30:36 -06:00
|
|
|
DRM_ERROR("Attempt to allocate from uninitialized memory "
|
|
|
|
"pool (0x%08x).\n", alloc->location);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2007-07-19 11:29:18 -06:00
|
|
|
|
2007-08-06 17:17:23 -06:00
|
|
|
mutex_lock(&info->dev->struct_mutex);
|
2007-08-09 17:01:14 -06:00
|
|
|
block = drm_sman_alloc(&info->sman, alloc->location, alloc->size,
|
|
|
|
0, (unsigned long) filp);
|
2007-08-06 17:17:23 -06:00
|
|
|
mutex_unlock(&info->dev->struct_mutex);
|
2007-08-06 16:37:56 -06:00
|
|
|
|
|
|
|
if (block == NULL) {
|
|
|
|
alloc->size = 0;
|
2007-08-09 16:30:36 -06:00
|
|
|
DRM_ERROR("%s memory allocation failed\n", mem_name);
|
2007-08-06 16:37:56 -06:00
|
|
|
return -ENOMEM;
|
2007-07-19 11:29:18 -06:00
|
|
|
} else {
|
2007-08-09 17:01:14 -06:00
|
|
|
alloc->offset = (*block->mm->offset)(block->mm,
|
|
|
|
block->mm_info);
|
|
|
|
alloc->hw_addr = alloc->offset;
|
|
|
|
alloc->index = block->user_hash.key;
|
2007-08-06 16:37:56 -06:00
|
|
|
|
2007-09-18 12:03:49 -06:00
|
|
|
if (block->user_hash.key != (unsigned long) alloc->index) {
|
|
|
|
DRM_ERROR("%s truncated handle %lx for pool %d "
|
|
|
|
"offset %x\n",
|
|
|
|
__func__, block->user_hash.key,
|
|
|
|
alloc->location, alloc->offset);
|
|
|
|
}
|
|
|
|
|
2007-08-06 17:09:05 -06:00
|
|
|
if (alloc->location == XGI_MEMLOC_NON_LOCAL) {
|
|
|
|
alloc->hw_addr += info->pcie.base;
|
|
|
|
}
|
|
|
|
|
2007-08-09 17:01:14 -06:00
|
|
|
DRM_DEBUG("%s memory allocation succeeded: 0x%x\n",
|
|
|
|
mem_name, alloc->offset);
|
2007-07-19 11:29:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-09 16:30:36 -06:00
|
|
|
int xgi_alloc_ioctl(struct drm_device * dev, void * data,
|
|
|
|
struct drm_file * filp)
|
2007-07-19 11:29:18 -06:00
|
|
|
{
|
|
|
|
struct xgi_info *info = dev->dev_private;
|
|
|
|
|
2007-08-09 16:30:36 -06:00
|
|
|
return xgi_alloc(info, (struct xgi_mem_alloc *) data, filp);
|
2007-07-19 11:29:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-06 18:27:15 -06:00
|
|
|
int xgi_free(struct xgi_info * info, unsigned long index,
|
|
|
|
struct drm_file * filp)
|
2007-07-19 11:29:18 -06:00
|
|
|
{
|
2007-08-09 16:30:36 -06:00
|
|
|
int err;
|
2007-07-19 11:29:18 -06:00
|
|
|
|
2007-08-06 17:17:23 -06:00
|
|
|
mutex_lock(&info->dev->struct_mutex);
|
2007-08-09 17:01:14 -06:00
|
|
|
err = drm_sman_free_key(&info->sman, index);
|
2007-08-06 17:17:23 -06:00
|
|
|
mutex_unlock(&info->dev->struct_mutex);
|
2007-07-19 11:29:18 -06:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-09 16:30:36 -06:00
|
|
|
int xgi_free_ioctl(struct drm_device * dev, void * data,
|
|
|
|
struct drm_file * filp)
|
2007-07-19 11:29:18 -06:00
|
|
|
{
|
|
|
|
struct xgi_info *info = dev->dev_private;
|
|
|
|
|
2007-08-09 16:30:36 -06:00
|
|
|
return xgi_free(info, *(unsigned long *) data, filp);
|
2007-07-19 11:29:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int xgi_fb_heap_init(struct xgi_info * info)
|
|
|
|
{
|
2007-08-09 17:01:14 -06:00
|
|
|
int err;
|
|
|
|
|
|
|
|
mutex_lock(&info->dev->struct_mutex);
|
|
|
|
err = drm_sman_set_range(&info->sman, XGI_MEMLOC_LOCAL,
|
|
|
|
XGI_FB_HEAP_START,
|
2007-08-09 16:30:36 -06:00
|
|
|
info->fb.size - XGI_FB_HEAP_START);
|
2007-08-09 17:01:14 -06:00
|
|
|
mutex_unlock(&info->dev->struct_mutex);
|
2007-07-19 11:29:18 -06:00
|
|
|
|
2007-08-09 17:01:14 -06:00
|
|
|
info->fb_heap_initialized = (err == 0);
|
|
|
|
return err;
|
2007-06-26 14:10:30 -06:00
|
|
|
}
|