ttm_module.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* SPDX-License-Identifier: GPL-2.0 OR MIT */
  2. /**************************************************************************
  3. *
  4. * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
  5. * All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
  22. * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  23. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  24. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  25. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. **************************************************************************/
  28. /*
  29. * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
  30. * Jerome Glisse
  31. */
  32. #include <linux/module.h>
  33. #include <linux/device.h>
  34. #include <linux/pgtable.h>
  35. #include <linux/sched.h>
  36. #include <linux/debugfs.h>
  37. #include <drm/drm_sysfs.h>
  38. #include <drm/ttm/ttm_caching.h>
  39. #include "ttm_module.h"
  40. /**
  41. * DOC: TTM
  42. *
  43. * TTM is a memory manager for accelerator devices with dedicated memory.
  44. *
  45. * The basic idea is that resources are grouped together in buffer objects of
  46. * certain size and TTM handles lifetime, movement and CPU mappings of those
  47. * objects.
  48. *
  49. * TODO: Add more design background and information here.
  50. */
  51. /**
  52. * ttm_prot_from_caching - Modify the page protection according to the
  53. * ttm cacing mode
  54. * @caching: The ttm caching mode
  55. * @tmp: The original page protection
  56. *
  57. * Return: The modified page protection
  58. */
  59. pgprot_t ttm_prot_from_caching(enum ttm_caching caching, pgprot_t tmp)
  60. {
  61. /* Cached mappings need no adjustment */
  62. if (caching == ttm_cached)
  63. return tmp;
  64. #if defined(__i386__) || defined(__x86_64__)
  65. if (caching == ttm_write_combined)
  66. tmp = pgprot_writecombine(tmp);
  67. #ifndef CONFIG_UML
  68. else if (boot_cpu_data.x86 > 3)
  69. tmp = pgprot_noncached(tmp);
  70. #endif /* CONFIG_UML */
  71. #endif /* __i386__ || __x86_64__ */
  72. #if defined(__ia64__) || defined(__arm__) || defined(__aarch64__) || \
  73. defined(__powerpc__) || defined(__mips__) || defined(__loongarch__) || \
  74. defined(__riscv)
  75. if (caching == ttm_write_combined)
  76. tmp = pgprot_writecombine(tmp);
  77. else
  78. tmp = pgprot_noncached(tmp);
  79. #endif
  80. #if defined(__sparc__)
  81. tmp = pgprot_noncached(tmp);
  82. #endif
  83. return tmp;
  84. }
  85. MODULE_AUTHOR("Thomas Hellstrom, Jerome Glisse");
  86. MODULE_DESCRIPTION("TTM memory manager subsystem (for DRM device)");
  87. MODULE_LICENSE("GPL and additional rights");