amdgpu_kms.c 36 KB

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