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