Path: blob/master/drivers/gpu/drm/nouveau/nouveau_ttm.c
15112 views
/*1* Copyright (c) 2007-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA,2* All Rights Reserved.3* Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA,4* All Rights Reserved.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* the rights to use, copy, modify, merge, publish, distribute, sub license,10* and/or sell copies of the Software, and to permit persons to whom the11* Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL20* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,21* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR22* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE23* USE OR OTHER DEALINGS IN THE SOFTWARE.24*/2526#include "drmP.h"2728#include "nouveau_drv.h"2930int31nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma)32{33struct drm_file *file_priv = filp->private_data;34struct drm_nouveau_private *dev_priv =35file_priv->minor->dev->dev_private;3637if (unlikely(vma->vm_pgoff < DRM_FILE_PAGE_OFFSET))38return drm_mmap(filp, vma);3940return ttm_bo_mmap(filp, vma, &dev_priv->ttm.bdev);41}4243static int44nouveau_ttm_mem_global_init(struct drm_global_reference *ref)45{46return ttm_mem_global_init(ref->object);47}4849static void50nouveau_ttm_mem_global_release(struct drm_global_reference *ref)51{52ttm_mem_global_release(ref->object);53}5455int56nouveau_ttm_global_init(struct drm_nouveau_private *dev_priv)57{58struct drm_global_reference *global_ref;59int ret;6061global_ref = &dev_priv->ttm.mem_global_ref;62global_ref->global_type = DRM_GLOBAL_TTM_MEM;63global_ref->size = sizeof(struct ttm_mem_global);64global_ref->init = &nouveau_ttm_mem_global_init;65global_ref->release = &nouveau_ttm_mem_global_release;6667ret = drm_global_item_ref(global_ref);68if (unlikely(ret != 0)) {69DRM_ERROR("Failed setting up TTM memory accounting\n");70dev_priv->ttm.mem_global_ref.release = NULL;71return ret;72}7374dev_priv->ttm.bo_global_ref.mem_glob = global_ref->object;75global_ref = &dev_priv->ttm.bo_global_ref.ref;76global_ref->global_type = DRM_GLOBAL_TTM_BO;77global_ref->size = sizeof(struct ttm_bo_global);78global_ref->init = &ttm_bo_global_init;79global_ref->release = &ttm_bo_global_release;8081ret = drm_global_item_ref(global_ref);82if (unlikely(ret != 0)) {83DRM_ERROR("Failed setting up TTM BO subsystem\n");84drm_global_item_unref(&dev_priv->ttm.mem_global_ref);85dev_priv->ttm.mem_global_ref.release = NULL;86return ret;87}8889return 0;90}9192void93nouveau_ttm_global_release(struct drm_nouveau_private *dev_priv)94{95if (dev_priv->ttm.mem_global_ref.release == NULL)96return;9798drm_global_item_unref(&dev_priv->ttm.bo_global_ref.ref);99drm_global_item_unref(&dev_priv->ttm.mem_global_ref);100dev_priv->ttm.mem_global_ref.release = NULL;101}102103104105