amdgpu_kms.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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. case AMDGPU_HW_IP_VCN_DEC:
  297. type = AMD_IP_BLOCK_TYPE_VCN;
  298. ring_mask = adev->vcn.ring_dec.ready ? 1 : 0;
  299. ib_start_alignment = AMDGPU_GPU_PAGE_SIZE;
  300. ib_size_alignment = 16;
  301. break;
  302. default:
  303. return -EINVAL;
  304. }
  305. for (i = 0; i < adev->num_ip_blocks; i++) {
  306. if (adev->ip_blocks[i].version->type == type &&
  307. adev->ip_blocks[i].status.valid) {
  308. ip.hw_ip_version_major = adev->ip_blocks[i].version->major;
  309. ip.hw_ip_version_minor = adev->ip_blocks[i].version->minor;
  310. ip.capabilities_flags = 0;
  311. ip.available_rings = ring_mask;
  312. ip.ib_start_alignment = ib_start_alignment;
  313. ip.ib_size_alignment = ib_size_alignment;
  314. break;
  315. }
  316. }
  317. return copy_to_user(out, &ip,
  318. min((size_t)size, sizeof(ip))) ? -EFAULT : 0;
  319. }
  320. case AMDGPU_INFO_HW_IP_COUNT: {
  321. enum amd_ip_block_type type;
  322. uint32_t count = 0;
  323. switch (info->query_hw_ip.type) {
  324. case AMDGPU_HW_IP_GFX:
  325. type = AMD_IP_BLOCK_TYPE_GFX;
  326. break;
  327. case AMDGPU_HW_IP_COMPUTE:
  328. type = AMD_IP_BLOCK_TYPE_GFX;
  329. break;
  330. case AMDGPU_HW_IP_DMA:
  331. type = AMD_IP_BLOCK_TYPE_SDMA;
  332. break;
  333. case AMDGPU_HW_IP_UVD:
  334. type = AMD_IP_BLOCK_TYPE_UVD;
  335. break;
  336. case AMDGPU_HW_IP_VCE:
  337. type = AMD_IP_BLOCK_TYPE_VCE;
  338. break;
  339. case AMDGPU_HW_IP_UVD_ENC:
  340. type = AMD_IP_BLOCK_TYPE_UVD;
  341. break;
  342. case AMDGPU_HW_IP_VCN_DEC:
  343. type = AMD_IP_BLOCK_TYPE_VCN;
  344. break;
  345. default:
  346. return -EINVAL;
  347. }
  348. for (i = 0; i < adev->num_ip_blocks; i++)
  349. if (adev->ip_blocks[i].version->type == type &&
  350. adev->ip_blocks[i].status.valid &&
  351. count < AMDGPU_HW_IP_INSTANCE_MAX_COUNT)
  352. count++;
  353. return copy_to_user(out, &count, min(size, 4u)) ? -EFAULT : 0;
  354. }
  355. case AMDGPU_INFO_TIMESTAMP:
  356. ui64 = amdgpu_gfx_get_gpu_clock_counter(adev);
  357. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  358. case AMDGPU_INFO_FW_VERSION: {
  359. struct drm_amdgpu_info_firmware fw_info;
  360. int ret;
  361. /* We only support one instance of each IP block right now. */
  362. if (info->query_fw.ip_instance != 0)
  363. return -EINVAL;
  364. ret = amdgpu_firmware_info(&fw_info, &info->query_fw, adev);
  365. if (ret)
  366. return ret;
  367. return copy_to_user(out, &fw_info,
  368. min((size_t)size, sizeof(fw_info))) ? -EFAULT : 0;
  369. }
  370. case AMDGPU_INFO_NUM_BYTES_MOVED:
  371. ui64 = atomic64_read(&adev->num_bytes_moved);
  372. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  373. case AMDGPU_INFO_NUM_EVICTIONS:
  374. ui64 = atomic64_read(&adev->num_evictions);
  375. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  376. case AMDGPU_INFO_VRAM_USAGE:
  377. ui64 = atomic64_read(&adev->vram_usage);
  378. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  379. case AMDGPU_INFO_VIS_VRAM_USAGE:
  380. ui64 = atomic64_read(&adev->vram_vis_usage);
  381. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  382. case AMDGPU_INFO_GTT_USAGE:
  383. ui64 = atomic64_read(&adev->gtt_usage);
  384. return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
  385. case AMDGPU_INFO_GDS_CONFIG: {
  386. struct drm_amdgpu_info_gds gds_info;
  387. memset(&gds_info, 0, sizeof(gds_info));
  388. gds_info.gds_gfx_partition_size = adev->gds.mem.gfx_partition_size >> AMDGPU_GDS_SHIFT;
  389. gds_info.compute_partition_size = adev->gds.mem.cs_partition_size >> AMDGPU_GDS_SHIFT;
  390. gds_info.gds_total_size = adev->gds.mem.total_size >> AMDGPU_GDS_SHIFT;
  391. gds_info.gws_per_gfx_partition = adev->gds.gws.gfx_partition_size >> AMDGPU_GWS_SHIFT;
  392. gds_info.gws_per_compute_partition = adev->gds.gws.cs_partition_size >> AMDGPU_GWS_SHIFT;
  393. gds_info.oa_per_gfx_partition = adev->gds.oa.gfx_partition_size >> AMDGPU_OA_SHIFT;
  394. gds_info.oa_per_compute_partition = adev->gds.oa.cs_partition_size >> AMDGPU_OA_SHIFT;
  395. return copy_to_user(out, &gds_info,
  396. min((size_t)size, sizeof(gds_info))) ? -EFAULT : 0;
  397. }
  398. case AMDGPU_INFO_VRAM_GTT: {
  399. struct drm_amdgpu_info_vram_gtt vram_gtt;
  400. vram_gtt.vram_size = adev->mc.real_vram_size;
  401. vram_gtt.vram_size -= adev->vram_pin_size;
  402. vram_gtt.vram_cpu_accessible_size = adev->mc.visible_vram_size;
  403. vram_gtt.vram_cpu_accessible_size -= (adev->vram_pin_size - adev->invisible_pin_size);
  404. vram_gtt.gtt_size = adev->mc.gtt_size;
  405. vram_gtt.gtt_size -= adev->gart_pin_size;
  406. return copy_to_user(out, &vram_gtt,
  407. min((size_t)size, sizeof(vram_gtt))) ? -EFAULT : 0;
  408. }
  409. case AMDGPU_INFO_MEMORY: {
  410. struct drm_amdgpu_memory_info mem;
  411. memset(&mem, 0, sizeof(mem));
  412. mem.vram.total_heap_size = adev->mc.real_vram_size;
  413. mem.vram.usable_heap_size =
  414. adev->mc.real_vram_size - adev->vram_pin_size;
  415. mem.vram.heap_usage = atomic64_read(&adev->vram_usage);
  416. mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4;
  417. mem.cpu_accessible_vram.total_heap_size =
  418. adev->mc.visible_vram_size;
  419. mem.cpu_accessible_vram.usable_heap_size =
  420. adev->mc.visible_vram_size -
  421. (adev->vram_pin_size - adev->invisible_pin_size);
  422. mem.cpu_accessible_vram.heap_usage =
  423. atomic64_read(&adev->vram_vis_usage);
  424. mem.cpu_accessible_vram.max_allocation =
  425. mem.cpu_accessible_vram.usable_heap_size * 3 / 4;
  426. mem.gtt.total_heap_size = adev->mc.gtt_size;
  427. mem.gtt.usable_heap_size =
  428. adev->mc.gtt_size - adev->gart_pin_size;
  429. mem.gtt.heap_usage = atomic64_read(&adev->gtt_usage);
  430. mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4;
  431. return copy_to_user(out, &mem,
  432. min((size_t)size, sizeof(mem)))
  433. ? -EFAULT : 0;
  434. }
  435. case AMDGPU_INFO_READ_MMR_REG: {
  436. unsigned n, alloc_size;
  437. uint32_t *regs;
  438. unsigned se_num = (info->read_mmr_reg.instance >>
  439. AMDGPU_INFO_MMR_SE_INDEX_SHIFT) &
  440. AMDGPU_INFO_MMR_SE_INDEX_MASK;
  441. unsigned sh_num = (info->read_mmr_reg.instance >>
  442. AMDGPU_INFO_MMR_SH_INDEX_SHIFT) &
  443. AMDGPU_INFO_MMR_SH_INDEX_MASK;
  444. /* set full masks if the userspace set all bits
  445. * in the bitfields */
  446. if (se_num == AMDGPU_INFO_MMR_SE_INDEX_MASK)
  447. se_num = 0xffffffff;
  448. if (sh_num == AMDGPU_INFO_MMR_SH_INDEX_MASK)
  449. sh_num = 0xffffffff;
  450. regs = kmalloc_array(info->read_mmr_reg.count, sizeof(*regs), GFP_KERNEL);
  451. if (!regs)
  452. return -ENOMEM;
  453. alloc_size = info->read_mmr_reg.count * sizeof(*regs);
  454. for (i = 0; i < info->read_mmr_reg.count; i++)
  455. if (amdgpu_asic_read_register(adev, se_num, sh_num,
  456. info->read_mmr_reg.dword_offset + i,
  457. &regs[i])) {
  458. DRM_DEBUG_KMS("unallowed offset %#x\n",
  459. info->read_mmr_reg.dword_offset + i);
  460. kfree(regs);
  461. return -EFAULT;
  462. }
  463. n = copy_to_user(out, regs, min(size, alloc_size));
  464. kfree(regs);
  465. return n ? -EFAULT : 0;
  466. }
  467. case AMDGPU_INFO_DEV_INFO: {
  468. struct drm_amdgpu_info_device dev_info = {};
  469. dev_info.device_id = dev->pdev->device;
  470. dev_info.chip_rev = adev->rev_id;
  471. dev_info.external_rev = adev->external_rev_id;
  472. dev_info.pci_rev = dev->pdev->revision;
  473. dev_info.family = adev->family;
  474. dev_info.num_shader_engines = adev->gfx.config.max_shader_engines;
  475. dev_info.num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
  476. /* return all clocks in KHz */
  477. dev_info.gpu_counter_freq = amdgpu_asic_get_xclk(adev) * 10;
  478. if (adev->pm.dpm_enabled) {
  479. dev_info.max_engine_clock = amdgpu_dpm_get_sclk(adev, false) * 10;
  480. dev_info.max_memory_clock = amdgpu_dpm_get_mclk(adev, false) * 10;
  481. } else {
  482. dev_info.max_engine_clock = adev->pm.default_sclk * 10;
  483. dev_info.max_memory_clock = adev->pm.default_mclk * 10;
  484. }
  485. dev_info.enabled_rb_pipes_mask = adev->gfx.config.backend_enable_mask;
  486. dev_info.num_rb_pipes = adev->gfx.config.max_backends_per_se *
  487. adev->gfx.config.max_shader_engines;
  488. dev_info.num_hw_gfx_contexts = adev->gfx.config.max_hw_contexts;
  489. dev_info._pad = 0;
  490. dev_info.ids_flags = 0;
  491. if (adev->flags & AMD_IS_APU)
  492. dev_info.ids_flags |= AMDGPU_IDS_FLAGS_FUSION;
  493. if (amdgpu_sriov_vf(adev))
  494. dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
  495. dev_info.virtual_address_offset = AMDGPU_VA_RESERVED_SIZE;
  496. dev_info.virtual_address_max = (uint64_t)adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
  497. dev_info.virtual_address_alignment = max((int)PAGE_SIZE, AMDGPU_GPU_PAGE_SIZE);
  498. dev_info.pte_fragment_size = (1 << AMDGPU_LOG2_PAGES_PER_FRAG) *
  499. AMDGPU_GPU_PAGE_SIZE;
  500. dev_info.gart_page_size = AMDGPU_GPU_PAGE_SIZE;
  501. dev_info.cu_active_number = adev->gfx.cu_info.number;
  502. dev_info.cu_ao_mask = adev->gfx.cu_info.ao_cu_mask;
  503. dev_info.ce_ram_size = adev->gfx.ce_ram_size;
  504. memcpy(&dev_info.cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
  505. sizeof(adev->gfx.cu_info.bitmap));
  506. dev_info.vram_type = adev->mc.vram_type;
  507. dev_info.vram_bit_width = adev->mc.vram_width;
  508. dev_info.vce_harvest_config = adev->vce.harvest_config;
  509. dev_info.gc_double_offchip_lds_buf =
  510. adev->gfx.config.double_offchip_lds_buf;
  511. if (amdgpu_ngg) {
  512. dev_info.prim_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PRIM].gpu_addr;
  513. dev_info.prim_buf_size = adev->gfx.ngg.buf[NGG_PRIM].size;
  514. dev_info.pos_buf_gpu_addr = adev->gfx.ngg.buf[NGG_POS].gpu_addr;
  515. dev_info.pos_buf_size = adev->gfx.ngg.buf[NGG_POS].size;
  516. dev_info.cntl_sb_buf_gpu_addr = adev->gfx.ngg.buf[NGG_CNTL].gpu_addr;
  517. dev_info.cntl_sb_buf_size = adev->gfx.ngg.buf[NGG_CNTL].size;
  518. dev_info.param_buf_gpu_addr = adev->gfx.ngg.buf[NGG_PARAM].gpu_addr;
  519. dev_info.param_buf_size = adev->gfx.ngg.buf[NGG_PARAM].size;
  520. }
  521. dev_info.wave_front_size = adev->gfx.cu_info.wave_front_size;
  522. dev_info.num_shader_visible_vgprs = adev->gfx.config.max_gprs;
  523. dev_info.num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
  524. dev_info.num_tcc_blocks = adev->gfx.config.max_texture_channel_caches;
  525. dev_info.gs_vgt_table_depth = adev->gfx.config.gs_vgt_table_depth;
  526. dev_info.gs_prim_buffer_depth = adev->gfx.config.gs_prim_buffer_depth;
  527. dev_info.max_gs_waves_per_vgt = adev->gfx.config.max_gs_threads;
  528. return copy_to_user(out, &dev_info,
  529. min((size_t)size, sizeof(dev_info))) ? -EFAULT : 0;
  530. }
  531. case AMDGPU_INFO_VCE_CLOCK_TABLE: {
  532. unsigned i;
  533. struct drm_amdgpu_info_vce_clock_table vce_clk_table = {};
  534. struct amd_vce_state *vce_state;
  535. for (i = 0; i < AMDGPU_VCE_CLOCK_TABLE_ENTRIES; i++) {
  536. vce_state = amdgpu_dpm_get_vce_clock_state(adev, i);
  537. if (vce_state) {
  538. vce_clk_table.entries[i].sclk = vce_state->sclk;
  539. vce_clk_table.entries[i].mclk = vce_state->mclk;
  540. vce_clk_table.entries[i].eclk = vce_state->evclk;
  541. vce_clk_table.num_valid_entries++;
  542. }
  543. }
  544. return copy_to_user(out, &vce_clk_table,
  545. min((size_t)size, sizeof(vce_clk_table))) ? -EFAULT : 0;
  546. }
  547. case AMDGPU_INFO_VBIOS: {
  548. uint32_t bios_size = adev->bios_size;
  549. switch (info->vbios_info.type) {
  550. case AMDGPU_INFO_VBIOS_SIZE:
  551. return copy_to_user(out, &bios_size,
  552. min((size_t)size, sizeof(bios_size)))
  553. ? -EFAULT : 0;
  554. case AMDGPU_INFO_VBIOS_IMAGE: {
  555. uint8_t *bios;
  556. uint32_t bios_offset = info->vbios_info.offset;
  557. if (bios_offset >= bios_size)
  558. return -EINVAL;
  559. bios = adev->bios + bios_offset;
  560. return copy_to_user(out, bios,
  561. min((size_t)size, (size_t)(bios_size - bios_offset)))
  562. ? -EFAULT : 0;
  563. }
  564. default:
  565. DRM_DEBUG_KMS("Invalid request %d\n",
  566. info->vbios_info.type);
  567. return -EINVAL;
  568. }
  569. }
  570. case AMDGPU_INFO_NUM_HANDLES: {
  571. struct drm_amdgpu_info_num_handles handle;
  572. switch (info->query_hw_ip.type) {
  573. case AMDGPU_HW_IP_UVD:
  574. /* Starting Polaris, we support unlimited UVD handles */
  575. if (adev->asic_type < CHIP_POLARIS10) {
  576. handle.uvd_max_handles = adev->uvd.max_handles;
  577. handle.uvd_used_handles = amdgpu_uvd_used_handles(adev);
  578. return copy_to_user(out, &handle,
  579. min((size_t)size, sizeof(handle))) ? -EFAULT : 0;
  580. } else {
  581. return -ENODATA;
  582. }
  583. break;
  584. default:
  585. return -EINVAL;
  586. }
  587. }
  588. case AMDGPU_INFO_SENSOR: {
  589. struct pp_gpu_power query = {0};
  590. int query_size = sizeof(query);
  591. if (amdgpu_dpm == 0)
  592. return -ENOENT;
  593. switch (info->sensor_info.type) {
  594. case AMDGPU_INFO_SENSOR_GFX_SCLK:
  595. /* get sclk in Mhz */
  596. if (amdgpu_dpm_read_sensor(adev,
  597. AMDGPU_PP_SENSOR_GFX_SCLK,
  598. (void *)&ui32, &ui32_size)) {
  599. return -EINVAL;
  600. }
  601. ui32 /= 100;
  602. break;
  603. case AMDGPU_INFO_SENSOR_GFX_MCLK:
  604. /* get mclk in Mhz */
  605. if (amdgpu_dpm_read_sensor(adev,
  606. AMDGPU_PP_SENSOR_GFX_MCLK,
  607. (void *)&ui32, &ui32_size)) {
  608. return -EINVAL;
  609. }
  610. ui32 /= 100;
  611. break;
  612. case AMDGPU_INFO_SENSOR_GPU_TEMP:
  613. /* get temperature in millidegrees C */
  614. if (amdgpu_dpm_read_sensor(adev,
  615. AMDGPU_PP_SENSOR_GPU_TEMP,
  616. (void *)&ui32, &ui32_size)) {
  617. return -EINVAL;
  618. }
  619. break;
  620. case AMDGPU_INFO_SENSOR_GPU_LOAD:
  621. /* get GPU load */
  622. if (amdgpu_dpm_read_sensor(adev,
  623. AMDGPU_PP_SENSOR_GPU_LOAD,
  624. (void *)&ui32, &ui32_size)) {
  625. return -EINVAL;
  626. }
  627. break;
  628. case AMDGPU_INFO_SENSOR_GPU_AVG_POWER:
  629. /* get average GPU power */
  630. if (amdgpu_dpm_read_sensor(adev,
  631. AMDGPU_PP_SENSOR_GPU_POWER,
  632. (void *)&query, &query_size)) {
  633. return -EINVAL;
  634. }
  635. ui32 = query.average_gpu_power >> 8;
  636. break;
  637. case AMDGPU_INFO_SENSOR_VDDNB:
  638. /* get VDDNB in millivolts */
  639. if (amdgpu_dpm_read_sensor(adev,
  640. AMDGPU_PP_SENSOR_VDDNB,
  641. (void *)&ui32, &ui32_size)) {
  642. return -EINVAL;
  643. }
  644. break;
  645. case AMDGPU_INFO_SENSOR_VDDGFX:
  646. /* get VDDGFX in millivolts */
  647. if (amdgpu_dpm_read_sensor(adev,
  648. AMDGPU_PP_SENSOR_VDDGFX,
  649. (void *)&ui32, &ui32_size)) {
  650. return -EINVAL;
  651. }
  652. break;
  653. default:
  654. DRM_DEBUG_KMS("Invalid request %d\n",
  655. info->sensor_info.type);
  656. return -EINVAL;
  657. }
  658. return copy_to_user(out, &ui32, min(size, 4u)) ? -EFAULT : 0;
  659. }
  660. default:
  661. DRM_DEBUG_KMS("Invalid request %d\n", info->query);
  662. return -EINVAL;
  663. }
  664. return 0;
  665. }
  666. /*
  667. * Outdated mess for old drm with Xorg being in charge (void function now).
  668. */
  669. /**
  670. * amdgpu_driver_lastclose_kms - drm callback for last close
  671. *
  672. * @dev: drm dev pointer
  673. *
  674. * Switch vga_switcheroo state after last close (all asics).
  675. */
  676. void amdgpu_driver_lastclose_kms(struct drm_device *dev)
  677. {
  678. struct amdgpu_device *adev = dev->dev_private;
  679. amdgpu_fbdev_restore_mode(adev);
  680. vga_switcheroo_process_delayed_switch();
  681. }
  682. /**
  683. * amdgpu_driver_open_kms - drm callback for open
  684. *
  685. * @dev: drm dev pointer
  686. * @file_priv: drm file
  687. *
  688. * On device open, init vm on cayman+ (all asics).
  689. * Returns 0 on success, error on failure.
  690. */
  691. int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  692. {
  693. struct amdgpu_device *adev = dev->dev_private;
  694. struct amdgpu_fpriv *fpriv;
  695. int r;
  696. file_priv->driver_priv = NULL;
  697. r = pm_runtime_get_sync(dev->dev);
  698. if (r < 0)
  699. return r;
  700. fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
  701. if (unlikely(!fpriv)) {
  702. r = -ENOMEM;
  703. goto out_suspend;
  704. }
  705. r = amdgpu_vm_init(adev, &fpriv->vm);
  706. if (r) {
  707. kfree(fpriv);
  708. goto out_suspend;
  709. }
  710. fpriv->prt_va = amdgpu_vm_bo_add(adev, &fpriv->vm, NULL);
  711. if (!fpriv->prt_va) {
  712. r = -ENOMEM;
  713. amdgpu_vm_fini(adev, &fpriv->vm);
  714. kfree(fpriv);
  715. goto out_suspend;
  716. }
  717. if (amdgpu_sriov_vf(adev)) {
  718. r = amdgpu_map_static_csa(adev, &fpriv->vm);
  719. if (r)
  720. goto out_suspend;
  721. }
  722. mutex_init(&fpriv->bo_list_lock);
  723. idr_init(&fpriv->bo_list_handles);
  724. amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
  725. file_priv->driver_priv = fpriv;
  726. out_suspend:
  727. pm_runtime_mark_last_busy(dev->dev);
  728. pm_runtime_put_autosuspend(dev->dev);
  729. return r;
  730. }
  731. /**
  732. * amdgpu_driver_postclose_kms - drm callback for post close
  733. *
  734. * @dev: drm dev pointer
  735. * @file_priv: drm file
  736. *
  737. * On device post close, tear down vm on cayman+ (all asics).
  738. */
  739. void amdgpu_driver_postclose_kms(struct drm_device *dev,
  740. struct drm_file *file_priv)
  741. {
  742. struct amdgpu_device *adev = dev->dev_private;
  743. struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
  744. struct amdgpu_bo_list *list;
  745. int handle;
  746. if (!fpriv)
  747. return;
  748. pm_runtime_get_sync(dev->dev);
  749. amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr);
  750. amdgpu_uvd_free_handles(adev, file_priv);
  751. amdgpu_vce_free_handles(adev, file_priv);
  752. amdgpu_vm_bo_rmv(adev, fpriv->prt_va);
  753. if (amdgpu_sriov_vf(adev)) {
  754. /* TODO: how to handle reserve failure */
  755. BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, true));
  756. amdgpu_vm_bo_rmv(adev, fpriv->vm.csa_bo_va);
  757. fpriv->vm.csa_bo_va = NULL;
  758. amdgpu_bo_unreserve(adev->virt.csa_obj);
  759. }
  760. amdgpu_vm_fini(adev, &fpriv->vm);
  761. idr_for_each_entry(&fpriv->bo_list_handles, list, handle)
  762. amdgpu_bo_list_free(list);
  763. idr_destroy(&fpriv->bo_list_handles);
  764. mutex_destroy(&fpriv->bo_list_lock);
  765. kfree(fpriv);
  766. file_priv->driver_priv = NULL;
  767. pm_runtime_mark_last_busy(dev->dev);
  768. pm_runtime_put_autosuspend(dev->dev);
  769. }
  770. /*
  771. * VBlank related functions.
  772. */
  773. /**
  774. * amdgpu_get_vblank_counter_kms - get frame count
  775. *
  776. * @dev: drm dev pointer
  777. * @pipe: crtc to get the frame count from
  778. *
  779. * Gets the frame count on the requested crtc (all asics).
  780. * Returns frame count on success, -EINVAL on failure.
  781. */
  782. u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe)
  783. {
  784. struct amdgpu_device *adev = dev->dev_private;
  785. int vpos, hpos, stat;
  786. u32 count;
  787. if (pipe >= adev->mode_info.num_crtc) {
  788. DRM_ERROR("Invalid crtc %u\n", pipe);
  789. return -EINVAL;
  790. }
  791. /* The hw increments its frame counter at start of vsync, not at start
  792. * of vblank, as is required by DRM core vblank counter handling.
  793. * Cook the hw count here to make it appear to the caller as if it
  794. * incremented at start of vblank. We measure distance to start of
  795. * vblank in vpos. vpos therefore will be >= 0 between start of vblank
  796. * and start of vsync, so vpos >= 0 means to bump the hw frame counter
  797. * result by 1 to give the proper appearance to caller.
  798. */
  799. if (adev->mode_info.crtcs[pipe]) {
  800. /* Repeat readout if needed to provide stable result if
  801. * we cross start of vsync during the queries.
  802. */
  803. do {
  804. count = amdgpu_display_vblank_get_counter(adev, pipe);
  805. /* Ask amdgpu_get_crtc_scanoutpos to return vpos as
  806. * distance to start of vblank, instead of regular
  807. * vertical scanout pos.
  808. */
  809. stat = amdgpu_get_crtc_scanoutpos(
  810. dev, pipe, GET_DISTANCE_TO_VBLANKSTART,
  811. &vpos, &hpos, NULL, NULL,
  812. &adev->mode_info.crtcs[pipe]->base.hwmode);
  813. } while (count != amdgpu_display_vblank_get_counter(adev, pipe));
  814. if (((stat & (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE)) !=
  815. (DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE))) {
  816. DRM_DEBUG_VBL("Query failed! stat %d\n", stat);
  817. } else {
  818. DRM_DEBUG_VBL("crtc %d: dist from vblank start %d\n",
  819. pipe, vpos);
  820. /* Bump counter if we are at >= leading edge of vblank,
  821. * but before vsync where vpos would turn negative and
  822. * the hw counter really increments.
  823. */
  824. if (vpos >= 0)
  825. count++;
  826. }
  827. } else {
  828. /* Fallback to use value as is. */
  829. count = amdgpu_display_vblank_get_counter(adev, pipe);
  830. DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n");
  831. }
  832. return count;
  833. }
  834. /**
  835. * amdgpu_enable_vblank_kms - enable vblank interrupt
  836. *
  837. * @dev: drm dev pointer
  838. * @pipe: crtc to enable vblank interrupt for
  839. *
  840. * Enable the interrupt on the requested crtc (all asics).
  841. * Returns 0 on success, -EINVAL on failure.
  842. */
  843. int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe)
  844. {
  845. struct amdgpu_device *adev = dev->dev_private;
  846. int idx = amdgpu_crtc_idx_to_irq_type(adev, pipe);
  847. return amdgpu_irq_get(adev, &adev->crtc_irq, idx);
  848. }
  849. /**
  850. * amdgpu_disable_vblank_kms - disable vblank interrupt
  851. *
  852. * @dev: drm dev pointer
  853. * @pipe: crtc to disable vblank interrupt for
  854. *
  855. * Disable the interrupt on the requested crtc (all asics).
  856. */
  857. void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe)
  858. {
  859. struct amdgpu_device *adev = dev->dev_private;
  860. int idx = amdgpu_crtc_idx_to_irq_type(adev, pipe);
  861. amdgpu_irq_put(adev, &adev->crtc_irq, idx);
  862. }
  863. const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
  864. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_CREATE, amdgpu_gem_create_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  865. DRM_IOCTL_DEF_DRV(AMDGPU_CTX, amdgpu_ctx_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  866. DRM_IOCTL_DEF_DRV(AMDGPU_VM, amdgpu_vm_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  867. DRM_IOCTL_DEF_DRV(AMDGPU_BO_LIST, amdgpu_bo_list_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  868. /* KMS */
  869. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_MMAP, amdgpu_gem_mmap_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  870. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_WAIT_IDLE, amdgpu_gem_wait_idle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  871. DRM_IOCTL_DEF_DRV(AMDGPU_CS, amdgpu_cs_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  872. DRM_IOCTL_DEF_DRV(AMDGPU_INFO, amdgpu_info_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  873. DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_CS, amdgpu_cs_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  874. DRM_IOCTL_DEF_DRV(AMDGPU_WAIT_FENCES, amdgpu_cs_wait_fences_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  875. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_METADATA, amdgpu_gem_metadata_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  876. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  877. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  878. DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
  879. };
  880. const int amdgpu_max_kms_ioctl = ARRAY_SIZE(amdgpu_ioctls_kms);
  881. /*
  882. * Debugfs info
  883. */
  884. #if defined(CONFIG_DEBUG_FS)
  885. static int amdgpu_debugfs_firmware_info(struct seq_file *m, void *data)
  886. {
  887. struct drm_info_node *node = (struct drm_info_node *) m->private;
  888. struct drm_device *dev = node->minor->dev;
  889. struct amdgpu_device *adev = dev->dev_private;
  890. struct drm_amdgpu_info_firmware fw_info;
  891. struct drm_amdgpu_query_fw query_fw;
  892. int ret, i;
  893. /* VCE */
  894. query_fw.fw_type = AMDGPU_INFO_FW_VCE;
  895. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  896. if (ret)
  897. return ret;
  898. seq_printf(m, "VCE feature version: %u, firmware version: 0x%08x\n",
  899. fw_info.feature, fw_info.ver);
  900. /* UVD */
  901. query_fw.fw_type = AMDGPU_INFO_FW_UVD;
  902. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  903. if (ret)
  904. return ret;
  905. seq_printf(m, "UVD feature version: %u, firmware version: 0x%08x\n",
  906. fw_info.feature, fw_info.ver);
  907. /* GMC */
  908. query_fw.fw_type = AMDGPU_INFO_FW_GMC;
  909. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  910. if (ret)
  911. return ret;
  912. seq_printf(m, "MC feature version: %u, firmware version: 0x%08x\n",
  913. fw_info.feature, fw_info.ver);
  914. /* ME */
  915. query_fw.fw_type = AMDGPU_INFO_FW_GFX_ME;
  916. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  917. if (ret)
  918. return ret;
  919. seq_printf(m, "ME feature version: %u, firmware version: 0x%08x\n",
  920. fw_info.feature, fw_info.ver);
  921. /* PFP */
  922. query_fw.fw_type = AMDGPU_INFO_FW_GFX_PFP;
  923. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  924. if (ret)
  925. return ret;
  926. seq_printf(m, "PFP feature version: %u, firmware version: 0x%08x\n",
  927. fw_info.feature, fw_info.ver);
  928. /* CE */
  929. query_fw.fw_type = AMDGPU_INFO_FW_GFX_CE;
  930. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  931. if (ret)
  932. return ret;
  933. seq_printf(m, "CE feature version: %u, firmware version: 0x%08x\n",
  934. fw_info.feature, fw_info.ver);
  935. /* RLC */
  936. query_fw.fw_type = AMDGPU_INFO_FW_GFX_RLC;
  937. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  938. if (ret)
  939. return ret;
  940. seq_printf(m, "RLC feature version: %u, firmware version: 0x%08x\n",
  941. fw_info.feature, fw_info.ver);
  942. /* MEC */
  943. query_fw.fw_type = AMDGPU_INFO_FW_GFX_MEC;
  944. query_fw.index = 0;
  945. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  946. if (ret)
  947. return ret;
  948. seq_printf(m, "MEC feature version: %u, firmware version: 0x%08x\n",
  949. fw_info.feature, fw_info.ver);
  950. /* MEC2 */
  951. if (adev->asic_type == CHIP_KAVERI ||
  952. (adev->asic_type > CHIP_TOPAZ && adev->asic_type != CHIP_STONEY)) {
  953. query_fw.index = 1;
  954. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  955. if (ret)
  956. return ret;
  957. seq_printf(m, "MEC2 feature version: %u, firmware version: 0x%08x\n",
  958. fw_info.feature, fw_info.ver);
  959. }
  960. /* PSP SOS */
  961. query_fw.fw_type = AMDGPU_INFO_FW_SOS;
  962. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  963. if (ret)
  964. return ret;
  965. seq_printf(m, "SOS feature version: %u, firmware version: 0x%08x\n",
  966. fw_info.feature, fw_info.ver);
  967. /* PSP ASD */
  968. query_fw.fw_type = AMDGPU_INFO_FW_ASD;
  969. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  970. if (ret)
  971. return ret;
  972. seq_printf(m, "ASD feature version: %u, firmware version: 0x%08x\n",
  973. fw_info.feature, fw_info.ver);
  974. /* SMC */
  975. query_fw.fw_type = AMDGPU_INFO_FW_SMC;
  976. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  977. if (ret)
  978. return ret;
  979. seq_printf(m, "SMC feature version: %u, firmware version: 0x%08x\n",
  980. fw_info.feature, fw_info.ver);
  981. /* SDMA */
  982. query_fw.fw_type = AMDGPU_INFO_FW_SDMA;
  983. for (i = 0; i < adev->sdma.num_instances; i++) {
  984. query_fw.index = i;
  985. ret = amdgpu_firmware_info(&fw_info, &query_fw, adev);
  986. if (ret)
  987. return ret;
  988. seq_printf(m, "SDMA%d feature version: %u, firmware version: 0x%08x\n",
  989. i, fw_info.feature, fw_info.ver);
  990. }
  991. return 0;
  992. }
  993. static const struct drm_info_list amdgpu_firmware_info_list[] = {
  994. {"amdgpu_firmware_info", amdgpu_debugfs_firmware_info, 0, NULL},
  995. };
  996. #endif
  997. int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev)
  998. {
  999. #if defined(CONFIG_DEBUG_FS)
  1000. return amdgpu_debugfs_add_files(adev, amdgpu_firmware_info_list,
  1001. ARRAY_SIZE(amdgpu_firmware_info_list));
  1002. #else
  1003. return 0;
  1004. #endif
  1005. }