amdgpu_kms.c 36 KB

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