amdgpu_kms.c 36 KB

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