vbox_ttm.c revision 4cedb1a5cf9082f72e6b8373e0dc8a15e312ea46
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller/** @file $Id$
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * VirtualBox Additions Linux kernel video driver
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * Copyright (C) 2013 Oracle Corporation
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * This file is part of VirtualBox Open Source Edition (OSE), as
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * available from http://www.virtualbox.org. This file is free software;
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * you can redistribute it and/or modify it under the terms of the GNU
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * General Public License (GPL) as published by the Free Software
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * Foundation, in version 2 as it comes in the "COPYING" file of the
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * --------------------------------------------------------------------
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * This code is based on
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * with the following copyright and permission notice:
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * Copyright 2012 Red Hat Inc.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * Permission is hereby granted, free of charge, to any person obtaining a
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * copy of this software and associated documentation files (the
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * "Software"), to deal in the Software without restriction, including
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * without limitation the rights to use, copy, modify, merge, publish,
21dcdac963f79c098a5ea1a2c5c5e109429c9786Brendan Miller * distribute, sub license, and/or sell copies of the Software, and to
47191265a0ac73f0ac0db0330969ce6920adaa1fBrendan Miller * permit persons to whom the Software is furnished to do so, subject to
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * the following conditions:
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47191265a0ac73f0ac0db0330969ce6920adaa1fBrendan Miller * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47191265a0ac73f0ac0db0330969ce6920adaa1fBrendan Miller * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * USE OR OTHER DEALINGS IN THE SOFTWARE.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * The above copyright notice and this permission notice (including the
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * next paragraph) shall be included in all copies or substantial portions
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * of the Software.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * Authors: Dave Airlie <airlied@redhat.com>
47191265a0ac73f0ac0db0330969ce6920adaa1fBrendan Millerstatic inline struct vbox_private *
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller return container_of(bd, struct vbox_private, ttm.bdev);
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillervbox_ttm_mem_global_init(struct drm_global_reference *ref)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillervbox_ttm_mem_global_release(struct drm_global_reference *ref)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * Adds the vbox memory manager object/structures to the global memory manager.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerstatic int vbox_ttm_global_init(struct vbox_private *vbox)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller global_ref->global_type = DRM_GLOBAL_TTM_MEM;
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller global_ref->size = sizeof(struct ttm_mem_global);
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller global_ref->init = &vbox_ttm_mem_global_init;
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller global_ref->release = &vbox_ttm_mem_global_release;
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller DRM_ERROR("Failed setting up TTM memory accounting "
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller "subsystem.\n");
0c3f79f75f596c8d6700b2de830000f754bb28a9Phill Cunnington global_ref->global_type = DRM_GLOBAL_TTM_BO;
21dcdac963f79c098a5ea1a2c5c5e109429c9786Brendan Miller global_ref->size = sizeof(struct ttm_bo_global);
21dcdac963f79c098a5ea1a2c5c5e109429c9786Brendan Miller global_ref->release = &ttm_bo_global_release;
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller DRM_ERROR("Failed setting up TTM BO subsystem.\n");
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller drm_global_item_unref(&vbox->ttm.mem_global_ref);
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller * Removes the vbox memory manager object from the global memory manager.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillervbox_ttm_global_release(struct vbox_private *vbox)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller if (vbox->ttm.mem_global_ref.release == NULL)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller drm_global_item_unref(&vbox->ttm.bo_global_ref.ref);
47191265a0ac73f0ac0db0330969ce6920adaa1fBrendan Miller drm_global_item_unref(&vbox->ttm.mem_global_ref);
641b861c668fdb84b7ed44966216b36863ffb608Brendan Mmillerstatic void vbox_bo_ttm_destroy(struct ttm_buffer_object *tbo)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerbool vbox_ttm_bo_is_vbox_bo(struct ttm_buffer_object *bo)
switch (type)
case TTM_PL_SYSTEM:
case TTM_PL_VRAM:
return -EINVAL;
return -EINVAL;
case TTM_PL_SYSTEM:
case TTM_PL_VRAM:
return -EINVAL;
bool no_wait_gpu,
return NULL;
return NULL;
return tt;
int ret;
if (ret)
return ret;
if (ret)
return ret;
if (ret)
return ret;
#ifdef DRM_MTRR_WC
#ifdef DRM_MTRR_WC
u32 c = 0;
int ret;
if (ret)
return ret;
int ret;
if (!vboxbo)
return -ENOMEM;
if (ret)
return ret;
sizeof(struct vbox_bo));
if (ret)
return ret;
int i, ret;
if (gpu_addr)
if (ret)
return ret;
if (gpu_addr)
int i, ret;
if (ret)
return ret;
int i, ret;
if (ret)
return ret;