/* BEGIN CSTYLED */
/* i915_mem.c -- Simple agp/fb memory manager for i915 -*- linux-c -*-
*/
/*
* Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
* 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,
* 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.
* 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.
*
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
* mechanisms used by the clients. Specifically, it operates by
* setting the 'in_use' fields of the global LRU to indicate whether
* this region is privately allocated to a client.
*
* This does require the client to actually respect that field.
*
* Currently no effort is made to allocate 'private' memory in any
* clever way - the LRU information isn't used to determine which
* block to allocate, and the ring is drained prior to allocations --
* in other words allocation is expensive.
*/
#include "drmP.h"
#include "drm.h"
#include "i915_drm.h"
#include "i915_drv.h"
{
unsigned start;
unsigned end;
unsigned i;
int age;
/* Mark the regions with the new flag and update their age. Move
* them to head of list to preserve LRU semantics.
*/
/* remove_from_list(i)
*/
/* insert_at_head(list, i)
*/
}
}
/* Very simple allocator for agp memory, working on a static range
* already mapped into each client's address space.
*/
{
/* Maybe cut off the start of an existing block */
if (!newblock)
goto out;
p = newblock;
}
/* Maybe cut off the end of an existing block */
if (!newblock)
goto out;
}
out:
/* Our block is in the middle */
return (p);
}
{
struct mem_block *p;
}
return NULL;
}
{
struct mem_block *p;
return (p);
return (NULL);
}
{
struct mem_block *p;
return (p);
return (NULL);
}
{
/* Assumes a single contiguous range. Needs a special filp in
* 'heap' to stop it being subsumed.
*/
drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
}
drm_free(p, sizeof(*q), DRM_MEM_BUFLISTS);
}
}
/* Initialize. How to check for an uninitialized heap?
*/
{
if (!blocks)
return (ENOMEM);
if (!*heap) {
return (ENOMEM);
}
return (0);
}
/* Free all blocks associated with the releasing file.
*/
{
struct mem_block *p;
return;
mark_block(dev, p, 0);
}
}
/* Assumes a single contiguous range. Needs a special filp in
* 'heap' to stop it being subsumed.
*/
drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
}
}
}
/* Shutdown.
*/
{
struct mem_block *p;
if (!*heap)
return;
struct mem_block *q = p;
p = p->next;
drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS);
}
}
{
switch (region) {
case I915_MEM_REGION_AGP:
default:
return (NULL);
}
}
/* IOCTL HANDLERS */
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
} else
return (EFAULT);
/* Make things easier on ourselves: all allocations at least
* 4k aligned.
*/
if (!block)
return (ENOMEM);
DRM_ERROR("copy_to_user\n");
return (EFAULT);
}
return (0);
}
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
return (EFAULT);
if (!block)
return (EFAULT);
return (EPERM);
return (0);
}
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
if (!heap)
return (EFAULT);
if (*heap) {
DRM_ERROR("heap already initialized?");
return (EFAULT);
}
}
/*ARGSUSED*/
{
if (!dev_priv) {
return (EINVAL);
}
if (!heap) {
DRM_ERROR("get_heap failed");
return (EFAULT);
}
if (!*heap) {
DRM_ERROR("heap not initialized?");
return (EFAULT);
}
return (0);
}