amdgpu_kms.c 33 KB

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