ttm_set_memory.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2018 Advanced Micro Devices, Inc.
  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: Huang Rui <ray.huang@amd.com>
  29. */
  30. #ifndef TTM_SET_MEMORY
  31. #define TTM_SET_MEMORY
  32. #include <linux/mm.h>
  33. #ifdef CONFIG_X86
  34. #include <asm/set_memory.h>
  35. static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
  36. {
  37. return set_pages_array_wb(pages, addrinarray);
  38. }
  39. static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
  40. {
  41. return set_pages_array_wc(pages, addrinarray);
  42. }
  43. static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
  44. {
  45. return set_pages_array_uc(pages, addrinarray);
  46. }
  47. static inline int ttm_set_pages_wb(struct page *page, int numpages)
  48. {
  49. return set_pages_wb(page, numpages);
  50. }
  51. static inline int ttm_set_pages_wc(struct page *page, int numpages)
  52. {
  53. unsigned long addr = (unsigned long)page_address(page);
  54. return set_memory_wc(addr, numpages);
  55. }
  56. static inline int ttm_set_pages_uc(struct page *page, int numpages)
  57. {
  58. return set_pages_uc(page, numpages);
  59. }
  60. #else /* for CONFIG_X86 */
  61. #if IS_ENABLED(CONFIG_AGP)
  62. #include <asm/agp.h>
  63. static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
  64. {
  65. int i;
  66. for (i = 0; i < addrinarray; i++)
  67. unmap_page_from_agp(pages[i]);
  68. return 0;
  69. }
  70. static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
  71. {
  72. int i;
  73. for (i = 0; i < addrinarray; i++)
  74. map_page_into_agp(pages[i]);
  75. return 0;
  76. }
  77. static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
  78. {
  79. int i;
  80. for (i = 0; i < addrinarray; i++)
  81. map_page_into_agp(pages[i]);
  82. return 0;
  83. }
  84. static inline int ttm_set_pages_wb(struct page *page, int numpages)
  85. {
  86. int i;
  87. for (i = 0; i < numpages; i++)
  88. unmap_page_from_agp(page++);
  89. return 0;
  90. }
  91. #else /* for CONFIG_AGP */
  92. static inline int ttm_set_pages_array_wb(struct page **pages, int addrinarray)
  93. {
  94. return 0;
  95. }
  96. static inline int ttm_set_pages_array_wc(struct page **pages, int addrinarray)
  97. {
  98. return 0;
  99. }
  100. static inline int ttm_set_pages_array_uc(struct page **pages, int addrinarray)
  101. {
  102. return 0;
  103. }
  104. static inline int ttm_set_pages_wb(struct page *page, int numpages)
  105. {
  106. return 0;
  107. }
  108. #endif /* for CONFIG_AGP */
  109. static inline int ttm_set_pages_wc(struct page *page, int numpages)
  110. {
  111. return 0;
  112. }
  113. static inline int ttm_set_pages_uc(struct page *page, int numpages)
  114. {
  115. return 0;
  116. }
  117. #endif /* for CONFIG_X86 */
  118. #endif