drm_memory.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * \file drm_memory.c
  3. * Memory management wrappers for DRM
  4. *
  5. * \author Rickard E. (Rik) Faith <faith@valinux.com>
  6. * \author Gareth Hughes <gareth@valinux.com>
  7. */
  8. /*
  9. * Created: Thu Feb 4 14:00:34 1999 by faith@valinux.com
  10. *
  11. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  12. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  13. * All Rights Reserved.
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a
  16. * copy of this software and associated documentation files (the "Software"),
  17. * to deal in the Software without restriction, including without limitation
  18. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  19. * and/or sell copies of the Software, and to permit persons to whom the
  20. * Software is furnished to do so, subject to the following conditions:
  21. *
  22. * The above copyright notice and this permission notice (including the next
  23. * paragraph) shall be included in all copies or substantial portions of the
  24. * Software.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  27. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  29. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  30. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  31. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  32. * OTHER DEALINGS IN THE SOFTWARE.
  33. */
  34. #include <linux/config.h>
  35. #include <linux/highmem.h>
  36. #include "drmP.h"
  37. #ifdef DEBUG_MEMORY
  38. #include "drm_memory_debug.h"
  39. #else
  40. /** No-op. */
  41. void drm_mem_init(void)
  42. {
  43. }
  44. /**
  45. * Called when "/proc/dri/%dev%/mem" is read.
  46. *
  47. * \param buf output buffer.
  48. * \param start start of output data.
  49. * \param offset requested start offset.
  50. * \param len requested number of bytes.
  51. * \param eof whether there is no more data to return.
  52. * \param data private data.
  53. * \return number of written bytes.
  54. *
  55. * No-op.
  56. */
  57. int drm_mem_info(char *buf, char **start, off_t offset,
  58. int len, int *eof, void *data)
  59. {
  60. return 0;
  61. }
  62. /** Wrapper around kmalloc() and kfree() */
  63. void *drm_realloc(void *oldpt, size_t oldsize, size_t size, int area)
  64. {
  65. void *pt;
  66. if (!(pt = kmalloc(size, GFP_KERNEL)))
  67. return NULL;
  68. if (oldpt && oldsize) {
  69. memcpy(pt, oldpt, oldsize);
  70. kfree(oldpt);
  71. }
  72. return pt;
  73. }
  74. #if __OS_HAS_AGP
  75. /** Wrapper around agp_allocate_memory() */
  76. DRM_AGP_MEM *drm_alloc_agp(drm_device_t * dev, int pages, u32 type)
  77. {
  78. return drm_agp_allocate_memory(dev->agp->bridge, pages, type);
  79. }
  80. /** Wrapper around agp_free_memory() */
  81. int drm_free_agp(DRM_AGP_MEM * handle, int pages)
  82. {
  83. return drm_agp_free_memory(handle) ? 0 : -EINVAL;
  84. }
  85. /** Wrapper around agp_bind_memory() */
  86. int drm_bind_agp(DRM_AGP_MEM * handle, unsigned int start)
  87. {
  88. return drm_agp_bind_memory(handle, start);
  89. }
  90. /** Wrapper around agp_unbind_memory() */
  91. int drm_unbind_agp(DRM_AGP_MEM * handle)
  92. {
  93. return drm_agp_unbind_memory(handle);
  94. }
  95. #endif /* agp */
  96. #endif /* debug_memory */