Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2008-2009 VMware, Inc., Palo Alto, CA., USA
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21.  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24.  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27. /*
  28.  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
  29.  */
  30.  
  31. #include "ttm/ttm_module.h"
  32. //#include <linux/mutex.h>
  33. //#include <linux/slab.h>
  34. #include "ttm/ttm_bo_driver.h"
  35. #include "ttm/ttm_placement.h"
  36. #include <linux/module.h>
  37.  
  38. struct ttm_global_item {
  39. //   struct mutex mutex;
  40.         void *object;
  41.         int refcount;
  42. };
  43.  
  44. static struct ttm_global_item glob[TTM_GLOBAL_NUM];
  45.  
  46. void ttm_global_init(void)
  47. {
  48.         int i;
  49.  
  50.         for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
  51.                 struct ttm_global_item *item = &glob[i];
  52. //       mutex_init(&item->mutex);
  53.                 item->object = NULL;
  54.                 item->refcount = 0;
  55.         }
  56. }
  57.  
  58. void ttm_global_release(void)
  59. {
  60.         int i;
  61.         for (i = 0; i < TTM_GLOBAL_NUM; ++i) {
  62.                 struct ttm_global_item *item = &glob[i];
  63.                 BUG_ON(item->object != NULL);
  64.                 BUG_ON(item->refcount != 0);
  65.         }
  66. }
  67.  
  68. int ttm_global_item_ref(struct ttm_global_reference *ref)
  69. {
  70.         int ret;
  71.         struct ttm_global_item *item = &glob[ref->global_type];
  72.         void *object;
  73.  
  74. //   mutex_lock(&item->mutex);
  75.         if (item->refcount == 0) {
  76.                 item->object = kzalloc(ref->size, GFP_KERNEL);
  77.                 if (unlikely(item->object == NULL)) {
  78.                         ret = -ENOMEM;
  79.                         goto out_err;
  80.                 }
  81.  
  82.                 ref->object = item->object;
  83.                 ret = ref->init(ref);
  84.                 if (unlikely(ret != 0))
  85.                         goto out_err;
  86.  
  87.         }
  88.         ++item->refcount;
  89.         ref->object = item->object;
  90.         object = item->object;
  91. //   mutex_unlock(&item->mutex);
  92.         return 0;
  93. out_err:
  94. //   mutex_unlock(&item->mutex);
  95.         item->object = NULL;
  96.         return ret;
  97. }
  98. EXPORT_SYMBOL(ttm_global_item_ref);
  99.  
  100. void ttm_global_item_unref(struct ttm_global_reference *ref)
  101. {
  102.         struct ttm_global_item *item = &glob[ref->global_type];
  103.  
  104. //   mutex_lock(&item->mutex);
  105.         BUG_ON(item->refcount == 0);
  106.         BUG_ON(ref->object != item->object);
  107.         if (--item->refcount == 0) {
  108.                 ref->release(ref);
  109.                 item->object = NULL;
  110.         }
  111. //   mutex_unlock(&item->mutex);
  112. }
  113. EXPORT_SYMBOL(ttm_global_item_unref);
  114.  
  115.