ttm_pool.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /*
  3. * Copyright 2020 Advanced Micro Devices, Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors: Christian König
  24. */
  25. #ifndef _TTM_PAGE_POOL_H_
  26. #define _TTM_PAGE_POOL_H_
  27. #include <linux/mmzone.h>
  28. #include <linux/llist.h>
  29. #include <linux/spinlock.h>
  30. #include <drm/ttm/ttm_caching.h>
  31. struct device;
  32. struct ttm_tt;
  33. struct ttm_pool;
  34. struct ttm_operation_ctx;
  35. /**
  36. * struct ttm_pool_type - Pool for a certain memory type
  37. *
  38. * @pool: the pool we belong to, might be NULL for the global ones
  39. * @order: the allocation order our pages have
  40. * @caching: the caching type our pages have
  41. * @shrinker_list: our place on the global shrinker list
  42. * @lock: protection of the page list
  43. * @pages: the list of pages in the pool
  44. */
  45. struct ttm_pool_type {
  46. struct ttm_pool *pool;
  47. unsigned int order;
  48. enum ttm_caching caching;
  49. struct list_head shrinker_list;
  50. spinlock_t lock;
  51. struct list_head pages;
  52. };
  53. /**
  54. * struct ttm_pool - Pool for all caching and orders
  55. *
  56. * @dev: the device we allocate pages for
  57. * @use_dma_alloc: if coherent DMA allocations should be used
  58. * @use_dma32: if GFP_DMA32 should be used
  59. * @caching: pools for each caching/order
  60. */
  61. struct ttm_pool {
  62. struct device *dev;
  63. bool use_dma_alloc;
  64. bool use_dma32;
  65. struct {
  66. struct ttm_pool_type orders[MAX_ORDER];
  67. } caching[TTM_NUM_CACHING_TYPES];
  68. };
  69. int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
  70. struct ttm_operation_ctx *ctx);
  71. void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt);
  72. void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
  73. bool use_dma_alloc, bool use_dma32);
  74. void ttm_pool_fini(struct ttm_pool *pool);
  75. int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m);
  76. int ttm_pool_mgr_init(unsigned long num_pages);
  77. void ttm_pool_mgr_fini(void);
  78. #endif