amdgpu_drv.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /**
  2. * \file amdgpu_drv.c
  3. * AMD Amdgpu driver
  4. *
  5. * \author Gareth Hughes <gareth@valinux.com>
  6. */
  7. /*
  8. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  9. * All Rights Reserved.
  10. *
  11. * Permission is hereby granted, free of charge, to any person obtaining a
  12. * copy of this software and associated documentation files (the "Software"),
  13. * to deal in the Software without restriction, including without limitation
  14. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  15. * and/or sell copies of the Software, and to permit persons to whom the
  16. * Software is furnished to do so, subject to the following conditions:
  17. *
  18. * The above copyright notice and this permission notice (including the next
  19. * paragraph) shall be included in all copies or substantial portions of the
  20. * Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  26. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  27. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  28. * OTHER DEALINGS IN THE SOFTWARE.
  29. */
  30. #include <drm/drmP.h>
  31. #include <drm/amdgpu_drm.h>
  32. #include <drm/drm_gem.h>
  33. #include "amdgpu_drv.h"
  34. #include <drm/drm_pciids.h>
  35. #include <linux/console.h>
  36. #include <linux/module.h>
  37. #include <linux/pm_runtime.h>
  38. #include <linux/vga_switcheroo.h>
  39. #include "drm_crtc_helper.h"
  40. #include "amdgpu.h"
  41. #include "amdgpu_irq.h"
  42. #include "amdgpu_amdkfd.h"
  43. /*
  44. * KMS wrapper.
  45. * - 3.0.0 - initial driver
  46. * - 3.1.0 - allow reading more status registers (GRBM, SRBM, SDMA, CP)
  47. */
  48. #define KMS_DRIVER_MAJOR 3
  49. #define KMS_DRIVER_MINOR 1
  50. #define KMS_DRIVER_PATCHLEVEL 0
  51. int amdgpu_vram_limit = 0;
  52. int amdgpu_gart_size = -1; /* auto */
  53. int amdgpu_benchmarking = 0;
  54. int amdgpu_testing = 0;
  55. int amdgpu_audio = -1;
  56. int amdgpu_disp_priority = 0;
  57. int amdgpu_hw_i2c = 0;
  58. int amdgpu_pcie_gen2 = -1;
  59. int amdgpu_msi = -1;
  60. int amdgpu_lockup_timeout = 0;
  61. int amdgpu_dpm = -1;
  62. int amdgpu_smc_load_fw = 1;
  63. int amdgpu_aspm = -1;
  64. int amdgpu_runtime_pm = -1;
  65. int amdgpu_hard_reset = 0;
  66. unsigned amdgpu_ip_block_mask = 0xffffffff;
  67. int amdgpu_bapm = -1;
  68. int amdgpu_deep_color = 0;
  69. int amdgpu_vm_size = 64;
  70. int amdgpu_vm_block_size = -1;
  71. int amdgpu_vm_fault_stop = 0;
  72. int amdgpu_vm_debug = 0;
  73. int amdgpu_exp_hw_support = 0;
  74. int amdgpu_enable_scheduler = 1;
  75. int amdgpu_sched_jobs = 16;
  76. int amdgpu_sched_hw_submission = 2;
  77. int amdgpu_enable_semaphores = 0;
  78. MODULE_PARM_DESC(vramlimit, "Restrict VRAM for testing, in megabytes");
  79. module_param_named(vramlimit, amdgpu_vram_limit, int, 0600);
  80. MODULE_PARM_DESC(gartsize, "Size of PCIE/IGP gart to setup in megabytes (32, 64, etc., -1 = auto)");
  81. module_param_named(gartsize, amdgpu_gart_size, int, 0600);
  82. MODULE_PARM_DESC(benchmark, "Run benchmark");
  83. module_param_named(benchmark, amdgpu_benchmarking, int, 0444);
  84. MODULE_PARM_DESC(test, "Run tests");
  85. module_param_named(test, amdgpu_testing, int, 0444);
  86. MODULE_PARM_DESC(audio, "Audio enable (-1 = auto, 0 = disable, 1 = enable)");
  87. module_param_named(audio, amdgpu_audio, int, 0444);
  88. MODULE_PARM_DESC(disp_priority, "Display Priority (0 = auto, 1 = normal, 2 = high)");
  89. module_param_named(disp_priority, amdgpu_disp_priority, int, 0444);
  90. MODULE_PARM_DESC(hw_i2c, "hw i2c engine enable (0 = disable)");
  91. module_param_named(hw_i2c, amdgpu_hw_i2c, int, 0444);
  92. MODULE_PARM_DESC(pcie_gen2, "PCIE Gen2 mode (-1 = auto, 0 = disable, 1 = enable)");
  93. module_param_named(pcie_gen2, amdgpu_pcie_gen2, int, 0444);
  94. MODULE_PARM_DESC(msi, "MSI support (1 = enable, 0 = disable, -1 = auto)");
  95. module_param_named(msi, amdgpu_msi, int, 0444);
  96. MODULE_PARM_DESC(lockup_timeout, "GPU lockup timeout in ms (default 0 = disable)");
  97. module_param_named(lockup_timeout, amdgpu_lockup_timeout, int, 0444);
  98. MODULE_PARM_DESC(dpm, "DPM support (1 = enable, 0 = disable, -1 = auto)");
  99. module_param_named(dpm, amdgpu_dpm, int, 0444);
  100. MODULE_PARM_DESC(smc_load_fw, "SMC firmware loading(1 = enable, 0 = disable)");
  101. module_param_named(smc_load_fw, amdgpu_smc_load_fw, int, 0444);
  102. MODULE_PARM_DESC(aspm, "ASPM support (1 = enable, 0 = disable, -1 = auto)");
  103. module_param_named(aspm, amdgpu_aspm, int, 0444);
  104. MODULE_PARM_DESC(runpm, "PX runtime pm (1 = force enable, 0 = disable, -1 = PX only default)");
  105. module_param_named(runpm, amdgpu_runtime_pm, int, 0444);
  106. MODULE_PARM_DESC(hard_reset, "PCI config reset (1 = force enable, 0 = disable (default))");
  107. module_param_named(hard_reset, amdgpu_hard_reset, int, 0444);
  108. MODULE_PARM_DESC(ip_block_mask, "IP Block Mask (all blocks enabled (default))");
  109. module_param_named(ip_block_mask, amdgpu_ip_block_mask, uint, 0444);
  110. MODULE_PARM_DESC(bapm, "BAPM support (1 = enable, 0 = disable, -1 = auto)");
  111. module_param_named(bapm, amdgpu_bapm, int, 0444);
  112. MODULE_PARM_DESC(deep_color, "Deep Color support (1 = enable, 0 = disable (default))");
  113. module_param_named(deep_color, amdgpu_deep_color, int, 0444);
  114. MODULE_PARM_DESC(vm_size, "VM address space size in gigabytes (default 64GB)");
  115. module_param_named(vm_size, amdgpu_vm_size, int, 0444);
  116. MODULE_PARM_DESC(vm_block_size, "VM page table size in bits (default depending on vm_size)");
  117. module_param_named(vm_block_size, amdgpu_vm_block_size, int, 0444);
  118. MODULE_PARM_DESC(vm_fault_stop, "Stop on VM fault (0 = never (default), 1 = print first, 2 = always)");
  119. module_param_named(vm_fault_stop, amdgpu_vm_fault_stop, int, 0444);
  120. MODULE_PARM_DESC(vm_debug, "Debug VM handling (0 = disabled (default), 1 = enabled)");
  121. module_param_named(vm_debug, amdgpu_vm_debug, int, 0644);
  122. MODULE_PARM_DESC(exp_hw_support, "experimental hw support (1 = enable, 0 = disable (default))");
  123. module_param_named(exp_hw_support, amdgpu_exp_hw_support, int, 0444);
  124. MODULE_PARM_DESC(enable_scheduler, "enable SW GPU scheduler (1 = enable (default), 0 = disable)");
  125. module_param_named(enable_scheduler, amdgpu_enable_scheduler, int, 0444);
  126. MODULE_PARM_DESC(sched_jobs, "the max number of jobs supported in the sw queue (default 16)");
  127. module_param_named(sched_jobs, amdgpu_sched_jobs, int, 0444);
  128. MODULE_PARM_DESC(sched_hw_submission, "the max number of HW submissions (default 2)");
  129. module_param_named(sched_hw_submission, amdgpu_sched_hw_submission, int, 0444);
  130. MODULE_PARM_DESC(enable_semaphores, "Enable semaphores (1 = enable, 0 = disable (default))");
  131. module_param_named(enable_semaphores, amdgpu_enable_semaphores, int, 0644);
  132. static struct pci_device_id pciidlist[] = {
  133. #ifdef CONFIG_DRM_AMDGPU_CIK
  134. /* Kaveri */
  135. {0x1002, 0x1304, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  136. {0x1002, 0x1305, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  137. {0x1002, 0x1306, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  138. {0x1002, 0x1307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  139. {0x1002, 0x1309, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  140. {0x1002, 0x130A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  141. {0x1002, 0x130B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  142. {0x1002, 0x130C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  143. {0x1002, 0x130D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  144. {0x1002, 0x130E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  145. {0x1002, 0x130F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  146. {0x1002, 0x1310, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  147. {0x1002, 0x1311, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  148. {0x1002, 0x1312, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  149. {0x1002, 0x1313, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  150. {0x1002, 0x1315, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  151. {0x1002, 0x1316, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  152. {0x1002, 0x1317, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  153. {0x1002, 0x1318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_MOBILITY|AMD_IS_APU},
  154. {0x1002, 0x131B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  155. {0x1002, 0x131C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  156. {0x1002, 0x131D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KAVERI|AMD_IS_APU},
  157. /* Bonaire */
  158. {0x1002, 0x6640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
  159. {0x1002, 0x6641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
  160. {0x1002, 0x6646, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
  161. {0x1002, 0x6647, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE|AMD_IS_MOBILITY},
  162. {0x1002, 0x6649, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
  163. {0x1002, 0x6650, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
  164. {0x1002, 0x6651, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
  165. {0x1002, 0x6658, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
  166. {0x1002, 0x665c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
  167. {0x1002, 0x665d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
  168. {0x1002, 0x665f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_BONAIRE},
  169. /* Hawaii */
  170. {0x1002, 0x67A0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  171. {0x1002, 0x67A1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  172. {0x1002, 0x67A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  173. {0x1002, 0x67A8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  174. {0x1002, 0x67A9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  175. {0x1002, 0x67AA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  176. {0x1002, 0x67B0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  177. {0x1002, 0x67B1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  178. {0x1002, 0x67B8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  179. {0x1002, 0x67B9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  180. {0x1002, 0x67BA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  181. {0x1002, 0x67BE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HAWAII},
  182. /* Kabini */
  183. {0x1002, 0x9830, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
  184. {0x1002, 0x9831, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  185. {0x1002, 0x9832, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
  186. {0x1002, 0x9833, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  187. {0x1002, 0x9834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
  188. {0x1002, 0x9835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  189. {0x1002, 0x9836, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
  190. {0x1002, 0x9837, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  191. {0x1002, 0x9838, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
  192. {0x1002, 0x9839, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
  193. {0x1002, 0x983a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  194. {0x1002, 0x983b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_MOBILITY|AMD_IS_APU},
  195. {0x1002, 0x983c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  196. {0x1002, 0x983d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  197. {0x1002, 0x983e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  198. {0x1002, 0x983f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_KABINI|AMD_IS_APU},
  199. /* mullins */
  200. {0x1002, 0x9850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  201. {0x1002, 0x9851, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  202. {0x1002, 0x9852, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  203. {0x1002, 0x9853, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  204. {0x1002, 0x9854, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  205. {0x1002, 0x9855, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  206. {0x1002, 0x9856, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  207. {0x1002, 0x9857, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  208. {0x1002, 0x9858, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  209. {0x1002, 0x9859, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  210. {0x1002, 0x985A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  211. {0x1002, 0x985B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  212. {0x1002, 0x985C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  213. {0x1002, 0x985D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  214. {0x1002, 0x985E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  215. {0x1002, 0x985F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MULLINS|AMD_IS_MOBILITY|AMD_IS_APU},
  216. #endif
  217. /* topaz */
  218. {0x1002, 0x6900, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
  219. {0x1002, 0x6901, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
  220. {0x1002, 0x6902, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
  221. {0x1002, 0x6903, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
  222. {0x1002, 0x6907, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TOPAZ},
  223. /* tonga */
  224. {0x1002, 0x6920, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  225. {0x1002, 0x6921, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  226. {0x1002, 0x6928, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  227. {0x1002, 0x6929, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  228. {0x1002, 0x692B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  229. {0x1002, 0x692F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  230. {0x1002, 0x6930, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  231. {0x1002, 0x6938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  232. {0x1002, 0x6939, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_TONGA},
  233. /* fiji */
  234. {0x1002, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_FIJI},
  235. /* carrizo */
  236. {0x1002, 0x9870, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
  237. {0x1002, 0x9874, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
  238. {0x1002, 0x9875, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
  239. {0x1002, 0x9876, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
  240. {0x1002, 0x9877, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CARRIZO|AMD_IS_APU},
  241. /* stoney */
  242. {0x1002, 0x98E4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_STONEY|AMD_IS_APU},
  243. {0, 0, 0}
  244. };
  245. MODULE_DEVICE_TABLE(pci, pciidlist);
  246. static struct drm_driver kms_driver;
  247. static int amdgpu_kick_out_firmware_fb(struct pci_dev *pdev)
  248. {
  249. struct apertures_struct *ap;
  250. bool primary = false;
  251. ap = alloc_apertures(1);
  252. if (!ap)
  253. return -ENOMEM;
  254. ap->ranges[0].base = pci_resource_start(pdev, 0);
  255. ap->ranges[0].size = pci_resource_len(pdev, 0);
  256. #ifdef CONFIG_X86
  257. primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
  258. #endif
  259. remove_conflicting_framebuffers(ap, "amdgpudrmfb", primary);
  260. kfree(ap);
  261. return 0;
  262. }
  263. static int amdgpu_pci_probe(struct pci_dev *pdev,
  264. const struct pci_device_id *ent)
  265. {
  266. unsigned long flags = ent->driver_data;
  267. int ret;
  268. if ((flags & AMD_EXP_HW_SUPPORT) && !amdgpu_exp_hw_support) {
  269. DRM_INFO("This hardware requires experimental hardware support.\n"
  270. "See modparam exp_hw_support\n");
  271. return -ENODEV;
  272. }
  273. /* Get rid of things like offb */
  274. ret = amdgpu_kick_out_firmware_fb(pdev);
  275. if (ret)
  276. return ret;
  277. return drm_get_pci_dev(pdev, ent, &kms_driver);
  278. }
  279. static void
  280. amdgpu_pci_remove(struct pci_dev *pdev)
  281. {
  282. struct drm_device *dev = pci_get_drvdata(pdev);
  283. drm_put_dev(dev);
  284. }
  285. static int amdgpu_pmops_suspend(struct device *dev)
  286. {
  287. struct pci_dev *pdev = to_pci_dev(dev);
  288. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  289. return amdgpu_suspend_kms(drm_dev, true, true);
  290. }
  291. static int amdgpu_pmops_resume(struct device *dev)
  292. {
  293. struct pci_dev *pdev = to_pci_dev(dev);
  294. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  295. return amdgpu_resume_kms(drm_dev, true, true);
  296. }
  297. static int amdgpu_pmops_freeze(struct device *dev)
  298. {
  299. struct pci_dev *pdev = to_pci_dev(dev);
  300. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  301. return amdgpu_suspend_kms(drm_dev, false, true);
  302. }
  303. static int amdgpu_pmops_thaw(struct device *dev)
  304. {
  305. struct pci_dev *pdev = to_pci_dev(dev);
  306. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  307. return amdgpu_resume_kms(drm_dev, false, true);
  308. }
  309. static int amdgpu_pmops_runtime_suspend(struct device *dev)
  310. {
  311. struct pci_dev *pdev = to_pci_dev(dev);
  312. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  313. int ret;
  314. if (!amdgpu_device_is_px(drm_dev)) {
  315. pm_runtime_forbid(dev);
  316. return -EBUSY;
  317. }
  318. drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  319. drm_kms_helper_poll_disable(drm_dev);
  320. vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_OFF);
  321. ret = amdgpu_suspend_kms(drm_dev, false, false);
  322. pci_save_state(pdev);
  323. pci_disable_device(pdev);
  324. pci_ignore_hotplug(pdev);
  325. pci_set_power_state(pdev, PCI_D3cold);
  326. drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
  327. return 0;
  328. }
  329. static int amdgpu_pmops_runtime_resume(struct device *dev)
  330. {
  331. struct pci_dev *pdev = to_pci_dev(dev);
  332. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  333. int ret;
  334. if (!amdgpu_device_is_px(drm_dev))
  335. return -EINVAL;
  336. drm_dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  337. pci_set_power_state(pdev, PCI_D0);
  338. pci_restore_state(pdev);
  339. ret = pci_enable_device(pdev);
  340. if (ret)
  341. return ret;
  342. pci_set_master(pdev);
  343. ret = amdgpu_resume_kms(drm_dev, false, false);
  344. drm_kms_helper_poll_enable(drm_dev);
  345. vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_ON);
  346. drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
  347. return 0;
  348. }
  349. static int amdgpu_pmops_runtime_idle(struct device *dev)
  350. {
  351. struct pci_dev *pdev = to_pci_dev(dev);
  352. struct drm_device *drm_dev = pci_get_drvdata(pdev);
  353. struct drm_crtc *crtc;
  354. if (!amdgpu_device_is_px(drm_dev)) {
  355. pm_runtime_forbid(dev);
  356. return -EBUSY;
  357. }
  358. list_for_each_entry(crtc, &drm_dev->mode_config.crtc_list, head) {
  359. if (crtc->enabled) {
  360. DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
  361. return -EBUSY;
  362. }
  363. }
  364. pm_runtime_mark_last_busy(dev);
  365. pm_runtime_autosuspend(dev);
  366. /* we don't want the main rpm_idle to call suspend - we want to autosuspend */
  367. return 1;
  368. }
  369. long amdgpu_drm_ioctl(struct file *filp,
  370. unsigned int cmd, unsigned long arg)
  371. {
  372. struct drm_file *file_priv = filp->private_data;
  373. struct drm_device *dev;
  374. long ret;
  375. dev = file_priv->minor->dev;
  376. ret = pm_runtime_get_sync(dev->dev);
  377. if (ret < 0)
  378. return ret;
  379. ret = drm_ioctl(filp, cmd, arg);
  380. pm_runtime_mark_last_busy(dev->dev);
  381. pm_runtime_put_autosuspend(dev->dev);
  382. return ret;
  383. }
  384. static const struct dev_pm_ops amdgpu_pm_ops = {
  385. .suspend = amdgpu_pmops_suspend,
  386. .resume = amdgpu_pmops_resume,
  387. .freeze = amdgpu_pmops_freeze,
  388. .thaw = amdgpu_pmops_thaw,
  389. .poweroff = amdgpu_pmops_freeze,
  390. .restore = amdgpu_pmops_resume,
  391. .runtime_suspend = amdgpu_pmops_runtime_suspend,
  392. .runtime_resume = amdgpu_pmops_runtime_resume,
  393. .runtime_idle = amdgpu_pmops_runtime_idle,
  394. };
  395. static const struct file_operations amdgpu_driver_kms_fops = {
  396. .owner = THIS_MODULE,
  397. .open = drm_open,
  398. .release = drm_release,
  399. .unlocked_ioctl = amdgpu_drm_ioctl,
  400. .mmap = amdgpu_mmap,
  401. .poll = drm_poll,
  402. .read = drm_read,
  403. #ifdef CONFIG_COMPAT
  404. .compat_ioctl = amdgpu_kms_compat_ioctl,
  405. #endif
  406. };
  407. static struct drm_driver kms_driver = {
  408. .driver_features =
  409. DRIVER_USE_AGP |
  410. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
  411. DRIVER_PRIME | DRIVER_RENDER,
  412. .dev_priv_size = 0,
  413. .load = amdgpu_driver_load_kms,
  414. .open = amdgpu_driver_open_kms,
  415. .preclose = amdgpu_driver_preclose_kms,
  416. .postclose = amdgpu_driver_postclose_kms,
  417. .lastclose = amdgpu_driver_lastclose_kms,
  418. .set_busid = drm_pci_set_busid,
  419. .unload = amdgpu_driver_unload_kms,
  420. .get_vblank_counter = amdgpu_get_vblank_counter_kms,
  421. .enable_vblank = amdgpu_enable_vblank_kms,
  422. .disable_vblank = amdgpu_disable_vblank_kms,
  423. .get_vblank_timestamp = amdgpu_get_vblank_timestamp_kms,
  424. .get_scanout_position = amdgpu_get_crtc_scanoutpos,
  425. #if defined(CONFIG_DEBUG_FS)
  426. .debugfs_init = amdgpu_debugfs_init,
  427. .debugfs_cleanup = amdgpu_debugfs_cleanup,
  428. #endif
  429. .irq_preinstall = amdgpu_irq_preinstall,
  430. .irq_postinstall = amdgpu_irq_postinstall,
  431. .irq_uninstall = amdgpu_irq_uninstall,
  432. .irq_handler = amdgpu_irq_handler,
  433. .ioctls = amdgpu_ioctls_kms,
  434. .gem_free_object = amdgpu_gem_object_free,
  435. .gem_open_object = amdgpu_gem_object_open,
  436. .gem_close_object = amdgpu_gem_object_close,
  437. .dumb_create = amdgpu_mode_dumb_create,
  438. .dumb_map_offset = amdgpu_mode_dumb_mmap,
  439. .dumb_destroy = drm_gem_dumb_destroy,
  440. .fops = &amdgpu_driver_kms_fops,
  441. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  442. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  443. .gem_prime_export = amdgpu_gem_prime_export,
  444. .gem_prime_import = drm_gem_prime_import,
  445. .gem_prime_pin = amdgpu_gem_prime_pin,
  446. .gem_prime_unpin = amdgpu_gem_prime_unpin,
  447. .gem_prime_res_obj = amdgpu_gem_prime_res_obj,
  448. .gem_prime_get_sg_table = amdgpu_gem_prime_get_sg_table,
  449. .gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table,
  450. .gem_prime_vmap = amdgpu_gem_prime_vmap,
  451. .gem_prime_vunmap = amdgpu_gem_prime_vunmap,
  452. .name = DRIVER_NAME,
  453. .desc = DRIVER_DESC,
  454. .date = DRIVER_DATE,
  455. .major = KMS_DRIVER_MAJOR,
  456. .minor = KMS_DRIVER_MINOR,
  457. .patchlevel = KMS_DRIVER_PATCHLEVEL,
  458. };
  459. static struct drm_driver *driver;
  460. static struct pci_driver *pdriver;
  461. static struct pci_driver amdgpu_kms_pci_driver = {
  462. .name = DRIVER_NAME,
  463. .id_table = pciidlist,
  464. .probe = amdgpu_pci_probe,
  465. .remove = amdgpu_pci_remove,
  466. .driver.pm = &amdgpu_pm_ops,
  467. };
  468. static int __init amdgpu_init(void)
  469. {
  470. #ifdef CONFIG_VGA_CONSOLE
  471. if (vgacon_text_force()) {
  472. DRM_ERROR("VGACON disables amdgpu kernel modesetting.\n");
  473. return -EINVAL;
  474. }
  475. #endif
  476. DRM_INFO("amdgpu kernel modesetting enabled.\n");
  477. driver = &kms_driver;
  478. pdriver = &amdgpu_kms_pci_driver;
  479. driver->driver_features |= DRIVER_MODESET;
  480. driver->num_ioctls = amdgpu_max_kms_ioctl;
  481. amdgpu_register_atpx_handler();
  482. amdgpu_amdkfd_init();
  483. /* let modprobe override vga console setting */
  484. return drm_pci_init(driver, pdriver);
  485. }
  486. static void __exit amdgpu_exit(void)
  487. {
  488. amdgpu_amdkfd_fini();
  489. drm_pci_exit(driver, pdriver);
  490. amdgpu_unregister_atpx_handler();
  491. }
  492. module_init(amdgpu_init);
  493. module_exit(amdgpu_exit);
  494. MODULE_AUTHOR(DRIVER_AUTHOR);
  495. MODULE_DESCRIPTION(DRIVER_DESC);
  496. MODULE_LICENSE("GPL and additional rights");