ttm_memory.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2006-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. #ifndef TTM_MEMORY_H
  28. #define TTM_MEMORY_H
  29. #include <linux/workqueue.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/bug.h>
  32. #include <linux/wait.h>
  33. #include <linux/errno.h>
  34. #include <linux/kobject.h>
  35. #include <linux/mm.h>
  36. #include "ttm_bo_api.h"
  37. /**
  38. * struct ttm_mem_global - Global memory accounting structure.
  39. *
  40. * @shrink: A single callback to shrink TTM memory usage. Extend this
  41. * to a linked list to be able to handle multiple callbacks when needed.
  42. * @swap_queue: A workqueue to handle shrinking in low memory situations. We
  43. * need a separate workqueue since it will spend a lot of time waiting
  44. * for the GPU, and this will otherwise block other workqueue tasks(?)
  45. * At this point we use only a single-threaded workqueue.
  46. * @work: The workqueue callback for the shrink queue.
  47. * @lock: Lock to protect the @shrink - and the memory accounting members,
  48. * that is, essentially the whole structure with some exceptions.
  49. * @lower_mem_limit: include lower limit of swap space and lower limit of
  50. * system memory.
  51. * @zones: Array of pointers to accounting zones.
  52. * @num_zones: Number of populated entries in the @zones array.
  53. * @zone_kernel: Pointer to the kernel zone.
  54. * @zone_highmem: Pointer to the highmem zone if there is one.
  55. * @zone_dma32: Pointer to the dma32 zone if there is one.
  56. *
  57. * Note that this structure is not per device. It should be global for all
  58. * graphics devices.
  59. */
  60. #define TTM_MEM_MAX_ZONES 2
  61. struct ttm_mem_zone;
  62. struct ttm_mem_global {
  63. struct kobject kobj;
  64. struct ttm_bo_global *bo_glob;
  65. struct workqueue_struct *swap_queue;
  66. struct work_struct work;
  67. spinlock_t lock;
  68. uint64_t lower_mem_limit;
  69. struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES];
  70. unsigned int num_zones;
  71. struct ttm_mem_zone *zone_kernel;
  72. #ifdef CONFIG_HIGHMEM
  73. struct ttm_mem_zone *zone_highmem;
  74. #else
  75. struct ttm_mem_zone *zone_dma32;
  76. #endif
  77. };
  78. extern int ttm_mem_global_init(struct ttm_mem_global *glob);
  79. extern void ttm_mem_global_release(struct ttm_mem_global *glob);
  80. extern int ttm_mem_global_alloc(struct ttm_mem_global *glob, uint64_t memory,
  81. struct ttm_operation_ctx *ctx);
  82. extern void ttm_mem_global_free(struct ttm_mem_global *glob,
  83. uint64_t amount);
  84. extern int ttm_mem_global_alloc_page(struct ttm_mem_global *glob,
  85. struct page *page, uint64_t size,
  86. struct ttm_operation_ctx *ctx);
  87. extern void ttm_mem_global_free_page(struct ttm_mem_global *glob,
  88. struct page *page, uint64_t size);
  89. extern size_t ttm_round_pot(size_t size);
  90. extern uint64_t ttm_get_kernel_zone_memory_size(struct ttm_mem_global *glob);
  91. extern bool ttm_check_under_lowerlimit(struct ttm_mem_global *glob,
  92. uint64_t num_pages, struct ttm_operation_ctx *ctx);
  93. #endif