amdgpu_kms.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <drm/drmP.h>
  29. #include "amdgpu.h"
  30. #include <drm/amdgpu_drm.h>
  31. #include "amdgpu_uvd.h"
  32. #include "amdgpu_vce.h"
  33. #include <linux/vga_switcheroo.h>
  34. #include <linux/slab.h>
  35. #include <linux/pm_runtime.h>
  36. #include "amdgpu_amdkfd.h"
  37. /**
  38. * amdgpu_driver_unload_kms - Main unload function for KMS.
  39. *
  40. * @dev: drm dev pointer
  41. *
  42. * This is the main unload function for KMS (all asics).
  43. * Returns 0 on success.
  44. */
  45. void amdgpu_driver_unload_kms(struct drm_device *dev)
  46. {
  47. struct amdgpu_device *adev = dev->dev_private;
  48. if (adev == NULL)
  49. return;
  50. if (adev->rmmio == NULL)
  51. goto done_free;
  52. if (amdgpu_sriov_vf(adev))
  53. amdgpu_virt_request_full_gpu(adev, false);
  54. if (amdgpu_device_is_px(dev)) {
  55. pm_runtime_get_sync(dev->dev);
  56. pm_runtime_forbid(dev->dev);
  57. }
  58. amdgpu_amdkfd_device_fini(adev);
  59. amdgpu_acpi_fini(adev);
  60. amdgpu_device_fini(adev);
  61. done_free:
  62. kfree(adev);
  63. dev->dev_private = NULL;
  64. }
  65. /**
  66. * amdgpu_driver_load_kms - Main load function for KMS.
  67. *
  68. * @dev: drm dev pointer
  69. * @flags: device flags
  70. *
  71. * This is the main load function for KMS (all asics).
  72. * Returns 0 on success, error on failure.
  73. */
  74. int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags)
  75. {
  76. struct amdgpu_device *adev;
  77. int r, acpi_status;
  78. adev = kzalloc(sizeof(struct amdgpu_device), GFP_KERNEL);
  79. if (adev == NULL) {
  80. return -ENOMEM;
  81. }
  82. dev->dev_private = (void *)adev;
  83. if ((amdgpu_runtime_pm != 0) &&
  84. amdgpu_has_atpx() &&
  85. (amdgpu_is_atpx_hybrid() ||
  86. amdgpu_has_atpx_dgpu_power_cntl()) &&
  87. ((flags & AMD_IS_APU) == 0) &&
  88. !pci_is_thunderbolt_attached(dev->pdev))
  89. flags |= AMD_IS_PX;
  90. /* amdgpu_device_init should report only fatal error
  91. * like memory allocation failure or iomapping failure,
  92. * or memory manager initialization failure, it must
  93. * properly initialize the GPU MC controller and permit
  94. * VRAM allocation
  95. */
  96. r = amdgpu_device_init(adev, dev, dev->pdev, flags);
  97. if (r) {
  98. dev_err(&dev->pdev->dev, "Fatal error during GPU init\n");
  99. goto out;
  100. }
  101. /* Call ACPI methods: require modeset init
  102. * but failure is not fatal
  103. */
  104. if (!r) {
  105. acpi_status = amdgpu_acpi_init(adev);
  106. if (acpi_status)
  107. dev_dbg(&dev->pdev->dev,
  108. "Error during ACPI methods call\n");
  109. }
  110. amdgpu_amdkfd_load_interface(adev);
  111. amdgpu_amdkfd_device_probe(adev);
  112. amdgpu_amdkfd_device_init(adev);
  113. if (amdgpu_device_is_px(dev)) {
  114. pm_runtime_use_autosuspend(dev->dev);
  115. pm_runtime_set_autosuspend_delay(dev->dev, 5000);
  116. pm_runtime_set_active(dev->dev);
  117. pm_runtime_allow(dev->dev);
  118. pm_runtime_mark_last_busy(dev->dev);
  119. pm_runtime_put_autosuspend(dev->dev);
  120. }
  121. if (amdgpu_sriov_vf(adev))
  122. amdgpu_virt_release_full_gpu(adev, true);
  123. out:
  124. if (r) {
  125. /* balance pm_runtime_get_sync in amdgpu_driver_unload_kms */
  126. if (adev->rmmio && amdgpu_device_is_px(dev))
  127. pm_runtime_put_noidle(dev->dev);
  128. amdgpu_driver_unload_kms(dev);
  129. }
  130. return r;
  131. }
  132. static int amdgpu_firmware_info(struct drm_amdgpu_info_firmware *fw_info,
  133. struct drm_amdgpu_query_fw *query_fw,
  134. struct amdgpu_device *adev)
  135. {
  136. switch (query_fw->fw_type) {
  137. case AMDGPU_INFO_FW_VCE:
  138. fw_info->ver = adev->vce.fw_version;
  139. fw_info->feature = adev->vce.fb_version;
  140. break;
  141. case AMDGPU_INFO_FW_UVD:
  142. fw_info->ver = adev->uvd.fw_version;
  143. fw_info->feature = 0;
  144. break;
  145. case AMDGPU_INFO_FW_GMC:
  146. fw_info->ver = adev->mc.fw_version;
  147. fw_info->feature = 0;
  148. break;
  149. case AMDGPU_INFO_FW_GFX_ME:
  150. fw_info->ver = adev->gfx.me_fw_version;
  151. fw_info->feature = adev->gfx.me_feature_version;
  152. break;
  153. case AMDGPU_INFO_FW_GFX_PFP:
  154. fw_info->ver = adev->gfx.pfp_fw_version;
  155. fw_info->feature = adev->gfx.pfp_feature_version;
  156. break;
  157. case AMDGPU_INFO_FW_GFX_CE:
  158. fw_info->ver = adev->gfx.ce_fw_version;
  159. fw_info->feature = adev->gfx.ce_feature_version;
  160. break;
  161. case AMDGPU_INFO_FW_GFX_RLC:
  162. fw_info->ver = adev->gfx.rlc_fw_version;
  163. fw_info->feature = adev->gfx.rlc_feature_version;
  164. break;
  165. case AMDGPU_INFO_FW_GFX_MEC:
  166. if (query_fw->index == 0) {
  167. fw_info->ver = adev->gfx.mec_fw_version;
  168. fw_info->feature = adev->gfx.mec_feature_version;
  169. } else if (query_fw->index == 1) {
  170. fw_info->ver = adev->gfx.mec2_fw_version;
  171. fw_info->feature = adev->gfx.mec2_feature_version;
  172. } else
  173. return -EINVAL;
  174. break;
  175. case AMDGPU_INFO_FW_SMC:
  176. fw_info->ver = adev->pm.fw_version;
  177. fw_info->feature = 0;
  178. break;
  179. case AMDGPU_INFO_FW_SDMA:
  180. if (query_fw->index >= adev->sdma.num_instances)
  181. return -EINVAL;
  182. fw_info->ver = adev->sdma.instance[query_fw->index].fw_version;
  183. fw_info->feature = adev->sdma.instance[query_fw->index].feature_version;
  184. break;
  185. case AMDGPU_INFO_FW_SOS:
  186. fw_info->ver = adev->psp.sos_fw_version;
  187. fw_info->feature = adev->psp.sos_feature_version;
  188. break;
  189. case AMDGPU_INFO_FW_ASD:
  190. fw_info->ver = adev->psp.asd_fw_version;
  191. fw_info->feature = adev->psp.asd_feature_version;
  192. break;
  193. default:
  194. return -EINVAL;
  195. }
  196. return 0;
  197. }
  198. /*
  199. * Userspace get information ioctl
  200. */
  201. /**
  202. * amdgpu_info_ioctl - answer a device specific request.
  203. *
  204. * @adev: amdgpu device pointer
  205. * @data: request object
  206. * @filp: drm filp
  207. *
  208. * This function is used to pass device specific parameters to the userspace
  209. * drivers. Examples include: pci device id, pipeline parms, tiling params,
  210. * etc. (all asics).
  211. * Returns 0 on success, -EINVAL on failure.
  212. */
  213. static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
  214. {
  215. struct amdgpu_device *adev = dev->dev_private;
  216. struct drm_amdgpu_info *info = data;
  217. struct amdgpu_mode_info *minfo = &adev->mode_info;
  218. void __user *out = (void __user *)(uintptr_t)info->return_pointer;
  219. uint32_t size = info->return_size;
  220. struct drm_crtc *crtc;
  221. uint32_t ui32 = 0;
  222. uint64_t ui64 = 0;
  223. int i, found;
  224. int ui32_size = sizeof(ui32);
  225. if (!info->return_size || !info->return_pointer)
  226. return -EINVAL;
  227. switch (info->query) {
  228. case AMDGPU_INFO_ACCEL_WORKING:
  229. ui32 = adev->accel_working;
  230. return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
  231. case AMDGPU_INFO_CRTC_FROM_ID:
  232. for (i = 0, found = 0; i < adev->mode_info.num_crtc; i++) {
  233. crtc = (struct drm_crtc *)minfo->crtcs[i];
  234. if (crtc && crtc->base.id == info->mode_crtc.id) {
  235. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  236. ui32 = amdgpu_crtc->crtc_id;
  237. found = 1;
  238. break;
  239. }
  240. }
  241. if (!found) {
  242. DRM_DEBUG_KMS("unknown crtc id %d\n", info->mode_crtc.id);
  243. return -EINVAL;
  244. }
  245. return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
  246. case AMDGPU_INFO_HW_IP_INFO: {
  247. struct drm_amdgpu_info_hw_ip ip = {};
  248. enum amd_ip_block_type type;
  249. uint32_t ring_mask = 0;
  250. uint32_t ib_start_alignment = 0;
  251. uint32_t ib_size_alignment = 0;
  252. if (info->query_hw_ip.ip_instance >= AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
  253. return -EINVAL;
  254. switch (info->query_hw_ip.type) {
  255. case AMDGPU_HW_IP_GFX:
  256. type = AMD_IP_BLOCK_TYPE_GFX;
  257. for (i = 0; i < adev->gfx.num_gfx_rings; i++)
  258. ring_mask |= ((adev->gfx.gfx_ring[i].ready ? 1 : 0) << i);
  259. ib_start_alignment = AMDGPU_GPU_PAGE_SIZE;
  260. ib_size_alignment = 8;
  261. break;
  262. case AMDGPU_HW_IP_COMPUTE:
  263. type = AMD_IP_BLOCK_TYPE_GFX;
  264. for (i = 0; i < adev->gfx.num_compute_rings; i++)
  265. ring_mask |= ((adev->gfx.compute_ring[i].ready ? 1 : 0) << i);
  266. ib_start_alignment = AMDGPU_GPU_PAGE_SIZE;
  267. ib_size_alignment = 8;
  268. break;
  269. case AMDGPU_HW_IP_DMA:
  270. type = AMD_IP_BLOCK_TYPE_SDMA;
  271. for (i = 0; i < adev->sdma.num_instances; i++)
  272. ring_mask |= ((adev->sdma.instance[i].ring.ready ? 1 : 0) << i);
  273. ib_start_alignment = AMDGPU_GPU_PAGE_SIZE;
  274. ib_size_alignment = 1;
  275. break;
  276. case AMDGPU_HW_IP_UVD:
  277. type = AMD_IP_BLOCK_TYPE_UVD;
  278. ring_mask = adev->uvd.ring.ready ? 1 : 0;
  279. ib_start_alignment = AMDGPU_GPU_PAGE_SIZE;
  280. ib_size_alignment = 16;
  281. break;
  282. case AMDGPU_HW_IP_VCE:
  283. type = AMD_IP_BLOCK_TYPE_VCE;
  284. for (i = 0; i < adev->vce.num_rings; i++)
  285. ring_mask |= ((adev->vce.ring[i].ready ? 1 : 0) << i);
  286. ib_start_alignment = AMDGPU_GPU_PAGE_SIZE;
  287. ib_size_alignment = 1;
  288. break;
  289. case AMDGPU_HW_IP_UVD_ENC:
  290. type = AMD_IP_BLOCK_TYPE_UVD;
  291. for (i = 0; i < adev->uvd.num_enc_rings; i++)
  292. ring_mask |= ((adev->uvd.ring_enc[i].ready ? 1 : 0) << i);
  293. ib_start_alignment = AMDGPU_GPU_PAGE_SIZE;
  294. ib_size_alignment = 1;
  295. break;
  296. default:
  297. return -EINVAL;
  298. }
  299. for (i = 0; i < adev->num_ip_blocks; i++) {
  300. if (adev->ip_blocks[i].version->type == type &&
  301. adev->ip_blocks[i].status.valid) {
  302. ip.hw_ip_version_major = adev->ip_blocks[i].version->major;
  303. ip.hw_ip_version_minor = adev->ip_blocks[i].version->minor;
  304. ip.capabilities_flags = 0;
  305. ip.available_rings = ring_mask;
  306. ip.ib_start_alignment = ib_start_alignment;
  307. ip.ib_size_alignment = ib_size_alignment;
  308. break;
  309. }
  310. }
  311. return copy_to_user(out, &ip,
  312. min((size_t)size, sizeof(ip))) ? -EFAULT : 0;
  313. }
  314. case AMDGPU_INFO_HW_IP_COUNT: {
  315. enum amd_ip_block_type type;
  316. uint32_t count = 0;
  317. switch (info->query_hw_ip.type) {
  318. case AMDGPU_HW_IP_GFX:
  319. type = AMD_IP_BLOCK_TYPE_GFX;
  320. break;
  321. case AMDGPU_HW_IP_COMPUTE:
  322. type = AMD_IP_BLOCK_TYPE_GFX;
  323. break;
  324. case AMDGPU_HW_IP_DMA:
  325. type = AMD_IP_BLOCK_TYPE_SDMA;
  326. break;
  327. case AMDGPU_HW_IP_UVD:
  328. type = AMD_IP_BLOCK_TYPE_UVD;
  329. break;
  330. case AMDGPU_HW_IP_VCE:
  331. type = AMD_IP_BLOCK_TYPE_VCE;
  332. break;
  333. case AMDGPU_HW_IP_UVD_ENC:
  334. type = AMD_IP_BLOCK_TYPE_UVD;
  335. break;
  336. default:
  337. return -EINVAL;
  338. }
  339. for (i = 0; i < adev->num_ip_blocks; i++)
  340. if (adev->ip_blocks[i].version->type == type &&
  341. adev->ip_blocks[i].status.valid &&
  342. count < AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
  343. count++;
  344. return copy_to_user(out, &count, min(size, 4u)) ? -EFAULT : 0;
  345. }
  346. case AMDGPU_INFO_TIMESTAMP:
  347. ui64 = amdgpu_gfx_get_gpu_clock_counter(adev);
  348. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  349. case AMDGPU_INFO_FW_VERSION: {
  350. struct drm_amdgpu_info_firmware fw_info;
  351. int ret;
  352. /* We only support one instance of each IP block right now. */
  353. if (info->query_fw.ip_instance != 0)
  354. return -EINVAL;
  355. ret = amdgpu_firmware_info(&fw_info, &info->query_fw, adev);
  356. if (ret)
  357. return ret;
  358. return copy_to_user(out, &fw_info,
  359. min((size_t)size, sizeof(fw_info))) ? -EFAULT : 0;
  360. }
  361. case AMDGPU_INFO_NUM_BYTES_MOVED:
  362. ui64 = atomic64_read(&adev->num_bytes_moved);
  363. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  364. case AMDGPU_INFO_NUM_EVICTIONS:
  365. ui64 = atomic64_read(&adev->num_evictions);
  366. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  367. case AMDGPU_INFO_VRAM_USAGE:
  368. ui64 = atomic64_read(&adev->vram_usage);
  369. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  370. case AMDGPU_INFO_VIS_VRAM_USAGE:
  371. ui64 = atomic64_read(&adev->vram_vis_usage);
  372. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  373. case AMDGPU_INFO_GTT_USAGE:
  374. ui64 = atomic64_read(&adev->gtt_usage);
  375. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  376. case AMDGPU_INFO_GDS_CONFIG: {
  377. struct drm_amdgpu_info_gds gds_info;
  378. memset(&gds_info, 0, sizeof(gds_info));
  379. gds_info.gds_gfx_partition_size = adev->gds.mem.gfx_partition_size >> AMDGPU_GDS_SHIFT;
  380. gds_info.compute_partition_size = adev->gds.mem.cs_partition_size >> AMDGPU_GDS_SHIFT;
  381. gds_info.gds_total_size = adev->gds.mem.total_size >> AMDGPU_GDS_SHIFT;
  382. gds_info.gws_per_gfx_partition = adev->gds.gws.gfx_partition_size >> AMDGPU_GWS_SHIFT;
  383. gds_info.gws_per_compute_partition = adev->gds.gws.cs_partition_size >> AMDGPU_GWS_SHIFT;
  384. gds_info.oa_per_gfx_partition = adev->gds.oa.gfx_partition_size >> AMDGPU_OA_SHIFT;
  385. gds_info.oa_per_compute_partition = adev->gds.oa.cs_partition_size >> AMDGPU_OA_SHIFT;
  386. return copy_to_user(out, &gds_info,
  387. min((size_t)size, sizeof(gds_info))) ? -EFAULT : 0;
  388. }
  389. case AMDGPU_INFO_VRAM_GTT: {
  390. struct drm_amdgpu_info_vram_gtt vram_gtt;
  391. vram_gtt.vram_size = adev->mc.real_vram_size;
  392. vram_gtt.vram_size -= adev->vram_pin_size;
  393. vram_gtt.vram_cpu_accessible_size = adev->mc.visible_vram_size;
  394. vram_gtt.vram_cpu_accessible_size -= (adev->vram_pin_size - adev->invisible_pin_size);
  395. vram_gtt.gtt_size = adev->mc.gtt_size;
  396. vram_gtt.gtt_size -= adev->gart_pin_size;
  397. return copy_to_user(out, &vram_gtt,
  398. min((size_t)size, sizeof(vram_gtt))) ? -EFAULT : 0;
  399. }
  400. case AMDGPU_INFO_MEMORY: {
  401. struct drm_amdgpu_memory_info mem;
  402. memset(&mem, 0, sizeof(mem));
  403. mem.vram.total_heap_size = adev->mc.real_vram_size;
  404. mem.vram.usable_heap_size =
  405. adev->mc.real_vram_size - adev->vram_pin_size;
  406. mem.vram.heap_usage = atomic64_read(&adev->vram_usage);
  407. mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4;
  408. mem.cpu_accessible_vram.total_heap_size =
  409. adev->mc.visible_vram_size;
  410. mem.cpu_accessible_vram.usable_heap_size =
  411. adev->mc.visible_vram_size -
  412. (adev->vram_pin_size - adev->invisible_pin_size);
  413. mem.cpu_accessible_vram.heap_usage =
  414. atomic64_read(&adev->vram_vis_usage);
  415. mem.cpu_accessible_vram.max_allocation =
  416. mem.cpu_accessible_vram.usable_heap_size * 3 / 4;
  417. mem.gtt.total_heap_size = adev->mc.gtt_size;
  418. mem.gtt.usable_heap_size =
  419. adev->mc.gtt_size - adev->gart_pin_size;
  420. mem.gtt.heap_usage = atomic64_read(&adev->gtt_usage);
  421. mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4;
  422. return copy_to_user(out, &mem,
  423. min((size_t)size, sizeof(mem)))
  424. ? -EFAULT : 0;
  425. }
  426. case AMDGPU_INFO_READ_MMR_REG: {
  427. unsigned n, alloc_size;
  428. uint32_t *regs;
  429. unsigned se_num = (info->read_mmr_reg.instance >>
  430. AMDGPU_INFO_MMR_SE_INDEX_SHIFT) &
  431. AMDGPU_INFO_MMR_SE_INDEX_MASK;
  432. unsigned sh_num = (info->read_mmr_reg.instance >>
  433. AMDGPU_INFO_MMR_SH_INDEX_SHIFT) &
  434. AMDGPU_INFO_MMR_SH_INDEX_MASK;
  435. /* set full masks if the userspace set all bits
  436. * in the bitfields */
  437. if (se_num == AMDGPU_INFO_MMR_SE_INDEX_MASK)
  438. se_num = 0xffffffff;
  439. if (sh_num == AMDGPU_INFO_MMR_SH_INDEX_MASK)
  440. sh_num = 0xffffffff;
  441. regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), GFP_KERNEL);
  442. if (!regs)
  443. return -ENOMEM;
  444. alloc_size = info->read_mmr_reg.count * sizeof(*regs);
  445. for (i = 0; i < info->read_mmr_reg.count; i++)
  446. if (amdgpu_asic_read_register(adev, se_num, sh_num,
  447. info->read_mmr_reg.dword_offset + i,
  448. &regs[i])) {
  449. DRM_DEBUG_KMS("unallowed offset %#x\n",
  450. info->read_mmr_reg.dword_offset + i);
  451. kfree(regs);
  452. return -EFAULT;
  453. }
  454. n = copy_to_user(out, regs, min(size, alloc_size));
  455. kfree(regs);
  456. return n ? -EFAULT : 0;
  457. }
  458. case AMDGPU_INFO_DEV_INFO: {
  459. struct drm_amdgpu_info_device dev_info = {};
  460. dev_info.device_id = dev->pdev->device;
  461. dev_info.chip_rev = adev->rev_id;
  462. dev_info.external_rev = adev->external_rev_id;
  463. dev_info.pci_rev = dev->pdev->revision;
  464. dev_info.family = adev->family;
  465. dev_info.num_shader_engines = adev->gfx.config.max_shader_engines;
  466. dev_info.num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
  467. /* return all clocks in KHz */
  468. dev_info.gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
  469. if (adev->pm.dpm_enabled) {
  470. dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
  471. dev_info.max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
  472. } else {
  473. dev_info.max_engine_clock = adev->pm.default_sclk * 10;
  474. dev_info.max_memory_clock = adev->pm.default_mclk * 10;
  475. }
  476. dev_info.enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
  477. dev_info.num_rb_pipes = adev->gfx.config.max_backends_per_se *
  478. adev->gfx.config.max_shader_engines;
  479. dev_info.num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
  480. dev_info._pad = 0;
  481. dev_info.ids_flags = 0;
  482. if (adev->flags & AMD_IS_APU)
  483. dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
  484. if (amdgpu_sriov_vf(adev))
  485. dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
  486. dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
  487. dev_info.virtual_address_max = (uint64_t)adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
  488. dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
  489. dev_info.pte_fragment_size = (1 << AMDGPU_LOG2_PAGES_PER_FRAG) *
  490. AMDGPU_GPU_PAGE_SIZE;
  491. dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
  492. dev_info.cu_active_number = adev->gfx.cu_info.number;
  493. dev_info.cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
  494. dev_info.ce_ram_size = adev->gfx.ce_ram_size;
  495. memcpy(&dev_info.cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
  496. sizeof(adev->gfx.cu_info.bitmap));
  497. dev_info.vram_type = adev->mc.vram_type;
  498. dev_info.vram_bit_width = adev->mc.vram_width;
  499. dev_info.vce_harvest_config = adev->vce.harvest_config;
  500. dev_info.gc_double_offchip_lds_buf =
  501. adev->gfx.config.double_offchip_lds_buf;
  502. if (amdgpu_ngg) {
  503. dev_info.prim_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PRIM].gpu_addr;
  504. dev_info.prim_buf_size = adev->gfx.ngg.buf[NGG_PRIM].size;
  505. dev_info.pos_buf_gpu_addr = adev->gfx.ngg.buf[NGG_POS].gpu_addr;
  506. dev_info.pos_buf_size = adev->gfx.ngg.buf[NGG_POS].size;
  507. dev_info.cntl_sb_buf_gpu_addr = adev->gfx.ngg.buf[NGG_CNTL].gpu_addr;
  508. dev_info.cntl_sb_buf_size = adev->gfx.ngg.buf[NGG_CNTL].size;
  509. dev_info.param_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PARAM].gpu_addr;
  510. dev_info.param_buf_size = adev->gfx.ngg.buf[NGG_PARAM].size;
  511. }
  512. dev_info.wave_front_size = adev->gfx.cu_info.wave_front_size;
  513. dev_info.num_shader_visible_vgprs = adev->gfx.config.max_gprs;
  514. dev_info.num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
  515. dev_info.num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
  516. dev_info.gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
  517. dev_info.gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
  518. dev_info.max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
  519. return copy_to_user(out, &dev_info,
  520. min((size_t)size, sizeof(dev_info))) ? -EFAULT : 0;
  521. }
  522. case AMDGPU_INFO_VCE_CLOCK_TABLE: {
  523. unsigned i;
  524. struct drm_amdgpu_info_vce_clock_table vce_clk_table = {};
  525. struct amd_vce_state *vce_state;
  526. for (i = 0; i < AMDGPU_VCE_CLOCK_TABLE_ENTRIES; i++) {
  527. vce_state = amdgpu_dpm_get_vce_clock_state(adev, i);
  528. if (vce_state) {
  529. vce_clk_table.entries[i].sclk = vce_state->sclk;
  530. vce_clk_table.entries[i].mclk = vce_state->mclk;
  531. vce_clk_table.entries[i].eclk = vce_state->evclk;
  532. vce_clk_table.num_valid_entries++;
  533. }
  534. }
  535. return copy_to_user(out, &vce_clk_table,
  536. min((size_t)size, sizeof(vce_clk_table))) ? -EFAULT : 0;
  537. }
  538. case AMDGPU_INFO_VBIOS: {
  539. uint32_t bios_size = adev->bios_size;
  540. switch (info->vbios_info.type) {
  541. case AMDGPU_INFO_VBIOS_SIZE:
  542. return copy_to_user(out, &bios_size,
  543. min((size_t)size, sizeof(bios_size)))
  544. ? -EFAULT : 0;
  545. case AMDGPU_INFO_VBIOS_IMAGE: {
  546. uint8_t *bios;
  547. uint32_t bios_offset = info->vbios_info.offset;
  548. if (bios_offset >= bios_size)
  549. return -EINVAL;
  550. bios = adev->bios + bios_offset;
  551. return copy_to_user(out, bios,
  552. min((size_t)size, (size_t)(bios_size - bios_offset)))
  553. ? -EFAULT : 0;
  554. }
  555. default:
  556. DRM_DEBUG_KMS("Invalid request %d\n",
  557. info->vbios_info.type);
  558. return -EINVAL;
  559. }
  560. }
  561. case AMDGPU_INFO_NUM_HANDLES: {
  562. struct drm_amdgpu_info_num_handles handle;
  563. switch (info->query_hw_ip.type) {
  564. case AMDGPU_HW_IP_UVD:
  565. /* Starting Polaris, we support unlimited UVD handles */
  566. if (adev->asic_type < CHIP_POLARIS10) {
  567. handle.uvd_max_handles = adev->uvd.max_handles;
  568. handle.uvd_used_handles = amdgpu_uvd_used_handles(adev);
  569. return copy_to_user(out, &handle,
  570. min((size_t)size, sizeof(handle))) ? -EFAULT : 0;
  571. } else {
  572. return -ENODATA;
  573. }
  574. break;
  575. default:
  576. return -EINVAL;
  577. }
  578. }
  579. case AMDGPU_INFO_SENSOR: {
  580. struct pp_gpu_power query = {0};
  581. int query_size = sizeof(query);
  582. if (amdgpu_dpm == 0)
  583. return -ENOENT;
  584. switch (info->sensor_info.type) {
  585. case AMDGPU_INFO_SENSOR_GFX_SCLK:
  586. /* get sclk in Mhz */
  587. if (amdgpu_dpm_read_sensor(adev,
  588. AMDGPU_PP_SENSOR_GFX_SCLK,
  589. (void *)&ui32, &ui32_size)) {
  590. return -EINVAL;
  591. }
  592. ui32 /= 100;
  593. break;
  594. case AMDGPU_INFO_SENSOR_GFX_MCLK:
  595. /* get mclk in Mhz */
  596. if (amdgpu_dpm_read_sensor(adev,
  597. AMDGPU_PP_SENSOR_GFX_MCLK,
  598. (void *)&ui32, &ui32_size)) {
  599. return -EINVAL;
  600. }
  601. ui32 /= 100;
  602. break;
  603. case AMDGPU_INFO_SENSOR_GPU_TEMP:
  604. /* get temperature in millidegrees C */
  605. if (amdgpu_dpm_read_sensor(adev,
  606. AMDGPU_PP_SENSOR_GPU_TEMP,
  607. (void *)&ui32, &ui32_size)) {
  608. return -EINVAL;
  609. }
  610. break;
  611. case AMDGPU_INFO_SENSOR_GPU_LOAD:
  612. /* get GPU load */
  613. if (amdgpu_dpm_read_sensor(adev,
  614. AMDGPU_PP_SENSOR_GPU_LOAD,
  615. (void *)&ui32, &ui32_size)) {
  616. return -EINVAL;
  617. }
  618. break;
  619. case AMDGPU_INFO_SENSOR_GPU_AVG_POWER:
  620. /* get average GPU power */
  621. if (amdgpu_dpm_read_sensor(adev,
  622. AMDGPU_PP_SENSOR_GPU_POWER,
  623. (void *)&query, &query_size)) {
  624. return -EINVAL;
  625. }
  626. ui32 = query.average_gpu_power >> 8;
  627. break;
  628. case AMDGPU_INFO_SENSOR_VDDNB:
  629. /* get VDDNB in millivolts */
  630. if (amdgpu_dpm_read_sensor(adev,
  631. AMDGPU_PP_SENSOR_VDDNB,
  632. (void *)&ui32, &ui32_size)) {
  633. return -EINVAL;
  634. }
  635. break;
  636. case AMDGPU_INFO_SENSOR_VDDGFX:
  637. /* get VDDGFX in millivolts */
  638. if (amdgpu_dpm_read_sensor(adev,
  639. AMDGPU_PP_SENSOR_VDDGFX,
  640. (void *)&ui32, &ui32_size)) {
  641. return -EINVAL;
  642. }
  643. break;
  644. default:
  645. DRM_DEBUG_KMS("Invalid request %d\n",
  646. info->sensor_info.type);
  647. return -EINVAL;
  648. }
  649. return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
  650. }
  651. default:
  652. DRM_DEBUG_KMS("Invalid request %d\n", info->query);
  653. return -EINVAL;
  654. }
  655. return 0;
  656. }
  657. /*
  658. * Outdated mess for old drm with Xorg being in charge (void function now).
  659. */
  660. /**
  661. * amdgpu_driver_lastclose_kms - drm callback for last close
  662. *
  663. * @dev: drm dev pointer
  664. *
  665. * Switch vga_switcheroo state after last close (all asics).
  666. */
  667. void amdgpu_driver_lastclose_kms(struct drm_device *dev)
  668. {
  669. struct amdgpu_device *adev = dev->dev_private;
  670. amdgpu_fbdev_restore_mode(adev);
  671. vga_switcheroo_process_delayed_switch();
  672. }
  673. /**
  674. * amdgpu_driver_open_kms - drm callback for open
  675. *
  676. * @dev: drm dev pointer
  677. * @file_priv: drm file
  678. *
  679. * On device open, init vm on cayman+ (all asics).
  680. * Returns 0 on success, error on failure.
  681. */
  682. int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  683. {
  684. struct amdgpu_device *adev = dev->dev_private;
  685. struct amdgpu_fpriv *fpriv;
  686. int r;
  687. file_priv->driver_priv = NULL;
  688. r = pm_runtime_get_sync(dev->dev);
  689. if (r < 0)
  690. return r;
  691. fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
  692. if (unlikely(!fpriv)) {
  693. r = -ENOMEM;
  694. goto out_suspend;
  695. }
  696. r = amdgpu_vm_init(adev, &fpriv->vm);
  697. if (r) {
  698. kfree(fpriv);
  699. goto out_suspend;
  700. }
  701. fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL);
  702. if (!fpriv->prt_va) {
  703. r = -ENOMEM;
  704. amdgpu_vm_fini(adev, &fpriv->vm);
  705. kfree(fpriv);
  706. goto out_suspend;
  707. }
  708. if (amdgpu_sriov_vf(adev)) {
  709. r = amdgpu_map_static_csa(adev, &fpriv->vm);
  710. if (r)
  711. goto out_suspend;
  712. }
  713. mutex_init(&fpriv->bo_list_lock);
  714. idr_init(&fpriv->bo_list_handles);
  715. amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
  716. file_priv->driver_priv = fpriv;
  717. out_suspend:
  718. pm_runtime_mark_last_busy(dev->dev);
  719. pm_runtime_put_autosuspend(dev->dev);
  720. return r;
  721. }
  722. /**
  723. * amdgpu_driver_postclose_kms - drm callback for post close
  724. *
  725. * @dev: drm dev pointer
  726. * @file_priv: drm file
  727. *
  728. * On device post close, tear down vm on cayman+ (all asics).
  729. */
  730. void amdgpu_driver_postclose_kms(struct drm_device *dev,
  731. struct drm_file *file_priv)
  732. {
  733. struct amdgpu_device *adev = dev->dev_private;
  734. struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
  735. struct amdgpu_bo_list *list;
  736. int handle;
  737. if (!fpriv)
  738. return;
  739. pm_runtime_get_sync(dev->dev);
  740. amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
  741. amdgpu_uvd_free_handles(adev, file_priv);
  742. amdgpu_vce_free_handles(adev, file_priv);
  743. amdgpu_vm_bo_rmv(adev, fpriv->prt_va);
  744. if (amdgpu_sriov_vf(adev)) {
  745. /* TODO: how to handle reserve failure */
  746. BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, true));
  747. amdgpu_vm_bo_rmv(adev, fpriv->vm.csa_bo_va);
  748. fpriv->vm.csa_bo_va = NULL;
  749. amdgpu_bo_unreserve(adev->virt.csa_obj);
  750. }
  751. amdgpu_vm_fini(adev, &fpriv->vm);
  752. idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
  753. amdgpu_bo_list_free(list);
  754. idr_destroy(&fpriv->bo_list_handles);
  755. mutex_destroy(&fpriv->bo_list_lock);
  756. kfree(fpriv);
  757. file_priv->driver_priv = NULL;
  758. pm_runtime_mark_last_busy(dev->dev);
  759. pm_runtime_put_autosuspend(dev->dev);
  760. }
  761. /*
  762. * VBlank related functions.
  763. */
  764. /**
  765. * amdgpu_get_vblank_counter_kms - get frame count
  766. *
  767. * @dev: drm dev pointer
  768. * @pipe: crtc to get the frame count from
  769. *
  770. * Gets the frame count on the requested crtc (all asics).
  771. * Returns frame count on success, -EINVAL on failure.
  772. */
  773. u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe)
  774. {
  775. struct amdgpu_device *adev = dev->dev_private;
  776. int vpos, hpos, stat;
  777. u32 count;
  778. if (pipe >= adev->mode_info.num_crtc) {
  779. DRM_ERROR("Invalid crtc %u\n", pipe);
  780. return -EINVAL;
  781. }
  782. /* The hw increments its frame counter at start of vsync, not at start
  783. * of vblank, as is required by DRM core vblank counter handling.
  784. * Cook the hw count here to make it appear to the caller as if it
  785. * incremented at start of vblank. We measure distance to start of
  786. * vblank in vpos. vpos therefore will be >= 0 between start of vblank
  787. * and start of vsync, so vpos >= 0 means to bump the hw frame counter
  788. * result by 1 to give the proper appearance to caller.
  789. */
  790. if (adev->mode_info.crtcs[pipe]) {
  791. /* Repeat readout if needed to provide stable result if
  792. * we cross start of vsync during the queries.
  793. */
  794. do {
  795. count = amdgpu_display_vblank_get_counter(adev, pipe);
  796. /* Ask amdgpu_get_crtc_scanoutpos to return vpos as
  797. * distance to start of vblank, instead of regular
  798. * vertical scanout pos.
  799. */
  800. stat = amdgpu_get_crtc_scanoutpos(
  801. dev, pipe, GET_DISTANCE_TO_VBLANKSTART,
  802. &vpos, &hpos, NULL, NULL,
  803. &adev->mode_info.crtcs[pipe]->base.hwmode);
  804. } while (count != amdgpu_display_vblank_get_counter(adev, pipe));
  805. if (((stat & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE)) !=
  806. (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE))) {
  807. DRM_DEBUG_VBL("Query failed! stat %d\n", stat);
  808. } else {
  809. DRM_DEBUG_VBL("crtc %d: dist from vblank start %d\n",
  810. pipe, vpos);
  811. /* Bump counter if we are at >= leading edge of vblank,
  812. * but before vsync where vpos would turn negative and
  813. * the hw counter really increments.
  814. */
  815. if (vpos >= 0)
  816. count++;
  817. }
  818. } else {
  819. /* Fallback to use value as is. */
  820. count = amdgpu_display_vblank_get_counter(adev, pipe);
  821. DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n");
  822. }
  823. return count;
  824. }
  825. /**
  826. * amdgpu_enable_vblank_kms - enable vblank interrupt
  827. *
  828. * @dev: drm dev pointer
  829. * @pipe: crtc to enable vblank interrupt for
  830. *
  831. * Enable the interrupt on the requested crtc (all asics).
  832. * Returns 0 on success, -EINVAL on failure.
  833. */
  834. int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe)
  835. {
  836. struct amdgpu_device *adev = dev->dev_private;
  837. int idx = amdgpu_crtc_idx_to_irq_type(adev, pipe);
  838. return amdgpu_irq_get(adev, &adev->crtc_irq, idx);
  839. }
  840. /**
  841. * amdgpu_disable_vblank_kms - disable vblank interrupt
  842. *
  843. * @dev: drm dev pointer
  844. * @pipe: crtc to disable vblank interrupt for
  845. *
  846. * Disable the interrupt on the requested crtc (all asics).
  847. */
  848. void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)
  849. {
  850. struct amdgpu_device *adev = dev->dev_private;
  851. int idx = amdgpu_crtc_idx_to_irq_type(adev, pipe);
  852. amdgpu_irq_put(adev, &adev->crtc_irq, idx);
  853. }
  854. const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
  855. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_CREATE, amdgpu_gem_create_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  856. DRM_IOCTL_DEF_DRV(AMDGPU_CTX, amdgpu_ctx_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  857. DRM_IOCTL_DEF_DRV(AMDGPU_BO_LIST, amdgpu_bo_list_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  858. /* KMS */
  859. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_MMAP, amdgpu_gem_mmap_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  860. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_WAIT_IDLE, amdgpu_gem_wait_idle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  861. DRM_IOCTL_DEF_DRV(AMDGPU_CS, amdgpu_cs_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  862. DRM_IOCTL_DEF_DRV(AMDGPU_INFO, amdgpu_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  863. DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_CS, amdgpu_cs_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  864. DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_FENCES, amdgpu_cs_wait_fences_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  865. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_METADATA, amdgpu_gem_metadata_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  866. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  867. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  868. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  869. };
  870. const int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms);
  871. /*
  872. * Debugfs info
  873. */
  874. #if defined(CONFIG_DEBUG_FS)
  875. static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
  876. {
  877. struct drm_info_node *node = (struct drm_info_node *) m->private;
  878. struct drm_device *dev = node->minor->dev;
  879. struct amdgpu_device *adev = dev->dev_private;
  880. struct drm_amdgpu_info_firmware fw_info;
  881. struct drm_amdgpu_query_fw query_fw;
  882. int ret, i;
  883. /* VCE */
  884. query_fw.fw_type = AMDGPU_INFO_FW_VCE;
  885. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  886. if (ret)
  887. return ret;
  888. seq_printf(m, "VCE feature version: %u, firmware version: 0x%08x\n",
  889. fw_info.feature, fw_info.ver);
  890. /* UVD */
  891. query_fw.fw_type = AMDGPU_INFO_FW_UVD;
  892. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  893. if (ret)
  894. return ret;
  895. seq_printf(m, "UVD feature version: %u, firmware version: 0x%08x\n",
  896. fw_info.feature, fw_info.ver);
  897. /* GMC */
  898. query_fw.fw_type = AMDGPU_INFO_FW_GMC;
  899. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  900. if (ret)
  901. return ret;
  902. seq_printf(m, "MC feature version: %u, firmware version: 0x%08x\n",
  903. fw_info.feature, fw_info.ver);
  904. /* ME */
  905. query_fw.fw_type = AMDGPU_INFO_FW_GFX_ME;
  906. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  907. if (ret)
  908. return ret;
  909. seq_printf(m, "ME feature version: %u, firmware version: 0x%08x\n",
  910. fw_info.feature, fw_info.ver);
  911. /* PFP */
  912. query_fw.fw_type = AMDGPU_INFO_FW_GFX_PFP;
  913. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  914. if (ret)
  915. return ret;
  916. seq_printf(m, "PFP feature version: %u, firmware version: 0x%08x\n",
  917. fw_info.feature, fw_info.ver);
  918. /* CE */
  919. query_fw.fw_type = AMDGPU_INFO_FW_GFX_CE;
  920. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  921. if (ret)
  922. return ret;
  923. seq_printf(m, "CE feature version: %u, firmware version: 0x%08x\n",
  924. fw_info.feature, fw_info.ver);
  925. /* RLC */
  926. query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC;
  927. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  928. if (ret)
  929. return ret;
  930. seq_printf(m, "RLC feature version: %u, firmware version: 0x%08x\n",
  931. fw_info.feature, fw_info.ver);
  932. /* MEC */
  933. query_fw.fw_type = AMDGPU_INFO_FW_GFX_MEC;
  934. query_fw.index = 0;
  935. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  936. if (ret)
  937. return ret;
  938. seq_printf(m, "MEC feature version: %u, firmware version: 0x%08x\n",
  939. fw_info.feature, fw_info.ver);
  940. /* MEC2 */
  941. if (adev->asic_type == CHIP_KAVERI ||
  942. (adev->asic_type > CHIP_TOPAZ && adev->asic_type != CHIP_STONEY)) {
  943. query_fw.index = 1;
  944. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  945. if (ret)
  946. return ret;
  947. seq_printf(m, "MEC2 feature version: %u, firmware version: 0x%08x\n",
  948. fw_info.feature, fw_info.ver);
  949. }
  950. /* PSP SOS */
  951. query_fw.fw_type = AMDGPU_INFO_FW_SOS;
  952. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  953. if (ret)
  954. return ret;
  955. seq_printf(m, "SOS feature version: %u, firmware version: 0x%08x\n",
  956. fw_info.feature, fw_info.ver);
  957. /* PSP ASD */
  958. query_fw.fw_type = AMDGPU_INFO_FW_ASD;
  959. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  960. if (ret)
  961. return ret;
  962. seq_printf(m, "ASD feature version: %u, firmware version: 0x%08x\n",
  963. fw_info.feature, fw_info.ver);
  964. /* SMC */
  965. query_fw.fw_type = AMDGPU_INFO_FW_SMC;
  966. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  967. if (ret)
  968. return ret;
  969. seq_printf(m, "SMC feature version: %u, firmware version: 0x%08x\n",
  970. fw_info.feature, fw_info.ver);
  971. /* SDMA */
  972. query_fw.fw_type = AMDGPU_INFO_FW_SDMA;
  973. for (i = 0; i < adev->sdma.num_instances; i++) {
  974. query_fw.index = i;
  975. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  976. if (ret)
  977. return ret;
  978. seq_printf(m, "SDMA%d feature version: %u, firmware version: 0x%08x\n",
  979. i, fw_info.feature, fw_info.ver);
  980. }
  981. return 0;
  982. }
  983. static const struct drm_info_list amdgpu_firmware_info_list[] = {
  984. {"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL},
  985. };
  986. #endif
  987. int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
  988. {
  989. #if defined(CONFIG_DEBUG_FS)
  990. return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list,
  991. ARRAY_SIZE(amdgpu_firmware_info_list));
  992. #else
  993. return 0;
  994. #endif
  995. }