amdgpu_kms.c 36 KB

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