amdgpu_kms.c 35 KB

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