ctxbitmap.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* ctxbitmap.c -- Context bitmap management -*- linux-c -*-
  2.  * Created: Thu Jan 6 03:56:42 2000 by jhartmann@precisioninsight.com
  3.  * 
  4.  * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
  5.  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6.  * All Rights Reserved.
  7.  *
  8.  * Permission is hereby granted, free of charge, to any person obtaining a
  9.  * copy of this software and associated documentation files (the "Software"),
  10.  * to deal in the Software without restriction, including without limitation
  11.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12.  * and/or sell copies of the Software, and to permit persons to whom the
  13.  * Software is furnished to do so, subject to the following conditions:
  14.  * 
  15.  * The above copyright notice and this permission notice (including the next
  16.  * paragraph) shall be included in all copies or substantial portions of the
  17.  * Software.
  18.  * 
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  25.  * DEALINGS IN THE SOFTWARE.
  26.  *
  27.  * Author: Jeff Hartmann <jhartmann@valinux.com>
  28.  *
  29.  */
  30. #define __NO_VERSION__
  31. #include "drmP.h"
  32. void drm_ctxbitmap_free(drm_device_t *dev, int ctx_handle)
  33. {
  34. if (ctx_handle < 0) goto failed;
  35. if (ctx_handle < DRM_MAX_CTXBITMAP) {
  36. clear_bit(ctx_handle, dev->ctx_bitmap);
  37. return;
  38. }
  39. failed:
  40.         DRM_ERROR("Attempt to free invalid context handle: %dn",
  41.   ctx_handle);
  42.         return;
  43. }
  44. int drm_ctxbitmap_next(drm_device_t *dev)
  45. {
  46. int bit;
  47. bit = find_first_zero_bit(dev->ctx_bitmap, DRM_MAX_CTXBITMAP);
  48. if (bit < DRM_MAX_CTXBITMAP) {
  49. set_bit(bit, dev->ctx_bitmap);
  50.     DRM_DEBUG("drm_ctxbitmap_next bit : %dn", bit);
  51. return bit;
  52. }
  53. return -1;
  54. }
  55. int drm_ctxbitmap_init(drm_device_t *dev)
  56. {
  57. int i;
  58.     int temp;
  59. dev->ctx_bitmap = (unsigned long *) drm_alloc(PAGE_SIZE, 
  60.       DRM_MEM_CTXBITMAP);
  61. if(dev->ctx_bitmap == NULL) {
  62. return -ENOMEM;
  63. }
  64. memset((void *) dev->ctx_bitmap, 0, PAGE_SIZE);
  65. for(i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
  66. temp = drm_ctxbitmap_next(dev);
  67.     DRM_DEBUG("drm_ctxbitmap_init : %dn", temp);
  68. }
  69. return 0;
  70. }
  71. void drm_ctxbitmap_cleanup(drm_device_t *dev)
  72. {
  73. drm_free((void *)dev->ctx_bitmap, PAGE_SIZE,
  74.  DRM_MEM_CTXBITMAP);
  75. }