/**
* \file drm_bufs.c
* Generic buffer template
*
* \author Rickard E. (Rik) Faith <faith@valinux.com>
* \author Gareth Hughes <gareth@valinux.com>
*/
/*
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
*
* Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
* 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, 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 NONINFRINGEMENT. IN NO EVENT SHALL
* VA LINUX SYSTEMS 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.
*/
#include <linux/vmalloc.h>
#include "drmP.h"
/**
* Adjusts the memory offset to its absolute value according to the mapping
* type. Adds the map to the map list drm_device::maplist. Adds MTRR's where
* applicable and if supported by the kernel.
*/
int drm_initmap(drm_device_t * dev, unsigned int offset, unsigned int size,
int type, int flags)
{
drm_map_t *map;
drm_map_list_t *list;
DRM_DEBUG("\n");
if ((offset & (~PAGE_MASK)) || (size & (~PAGE_MASK)))
return -EINVAL;
#if !defined(__sparc__) && !defined(__alpha__)
if (offset + size < offset || offset < virt_to_phys(high_memory))
return -EINVAL;
#endif
if (!(list = drm_alloc(sizeof(*list), DRM_MEM_MAPS)))
return -ENOMEM;
memset(list, 0, sizeof(*list));
if (!(map = drm_alloc(sizeof(*map), DRM_MEM_MAPS))) {
drm_free(list, sizeof(*list), DRM_MEM_MAPS);
return -ENOMEM;
}
*map = (drm_map_t) {
.offset = offset,.size = size,.type = type,.flags =
flags,.mtrr = -1,.handle = 0,};
list->map = map;
DRM_DEBUG("initmap offset = 0x%08lx, size = 0x%08lx, type = %d\n",
map->offset, map->size, map->type);
#ifdef __alpha__
map->offset += dev->hose->mem_space->start;
#endif
if (drm_core_has_MTRR(dev)) {
if (map->type == _DRM_FRAME_BUFFER ||
(map->flags & _DRM_WRITE_COMBINING)) {
map->mtrr = mtrr_add(map->offset, map->size,
MTRR_TYPE_WRCOMB, 1);
}
}
if (map->type == _DRM_REGISTERS)
|