amdgpu_cgs.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. *
  23. */
  24. #include <linux/list.h>
  25. #include <linux/slab.h>
  26. #include <linux/pci.h>
  27. #include <linux/acpi.h>
  28. #include <drm/drmP.h>
  29. #include <linux/firmware.h>
  30. #include <drm/amdgpu_drm.h>
  31. #include "amdgpu.h"
  32. #include "cgs_linux.h"
  33. #include "atom.h"
  34. #include "amdgpu_ucode.h"
  35. struct amdgpu_cgs_device {
  36. struct cgs_device base;
  37. struct amdgpu_device *adev;
  38. };
  39. #define CGS_FUNC_ADEV \
  40. struct amdgpu_device *adev = \
  41. ((struct amdgpu_cgs_device *)cgs_device)->adev
  42. static int amdgpu_cgs_alloc_gpu_mem(struct cgs_device *cgs_device,
  43. enum cgs_gpu_mem_type type,
  44. uint64_t size, uint64_t align,
  45. cgs_handle_t *handle)
  46. {
  47. CGS_FUNC_ADEV;
  48. uint16_t flags = 0;
  49. int ret = 0;
  50. uint32_t domain = 0;
  51. struct amdgpu_bo *obj;
  52. /* fail if the alignment is not a power of 2 */
  53. if (((align != 1) && (align & (align - 1)))
  54. || size == 0 || align == 0)
  55. return -EINVAL;
  56. switch(type) {
  57. case CGS_GPU_MEM_TYPE__VISIBLE_CONTIG_FB:
  58. case CGS_GPU_MEM_TYPE__VISIBLE_FB:
  59. flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
  60. AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
  61. domain = AMDGPU_GEM_DOMAIN_VRAM;
  62. break;
  63. case CGS_GPU_MEM_TYPE__INVISIBLE_CONTIG_FB:
  64. case CGS_GPU_MEM_TYPE__INVISIBLE_FB:
  65. flags = AMDGPU_GEM_CREATE_NO_CPU_ACCESS |
  66. AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
  67. domain = AMDGPU_GEM_DOMAIN_VRAM;
  68. break;
  69. case CGS_GPU_MEM_TYPE__GART_CACHEABLE:
  70. domain = AMDGPU_GEM_DOMAIN_GTT;
  71. break;
  72. case CGS_GPU_MEM_TYPE__GART_WRITECOMBINE:
  73. flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC;
  74. domain = AMDGPU_GEM_DOMAIN_GTT;
  75. break;
  76. default:
  77. return -EINVAL;
  78. }
  79. *handle = 0;
  80. ret = amdgpu_bo_create(adev, size, align, true, domain, flags,
  81. NULL, NULL, 0, &obj);
  82. if (ret) {
  83. DRM_ERROR("(%d) bo create failed\n", ret);
  84. return ret;
  85. }
  86. *handle = (cgs_handle_t)obj;
  87. return ret;
  88. }
  89. static int amdgpu_cgs_free_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
  90. {
  91. struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
  92. if (obj) {
  93. int r = amdgpu_bo_reserve(obj, true);
  94. if (likely(r == 0)) {
  95. amdgpu_bo_kunmap(obj);
  96. amdgpu_bo_unpin(obj);
  97. amdgpu_bo_unreserve(obj);
  98. }
  99. amdgpu_bo_unref(&obj);
  100. }
  101. return 0;
  102. }
  103. static int amdgpu_cgs_gmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle,
  104. uint64_t *mcaddr)
  105. {
  106. int r;
  107. struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
  108. WARN_ON_ONCE(obj->placement.num_placement > 1);
  109. r = amdgpu_bo_reserve(obj, true);
  110. if (unlikely(r != 0))
  111. return r;
  112. r = amdgpu_bo_pin(obj, obj->preferred_domains, mcaddr);
  113. amdgpu_bo_unreserve(obj);
  114. return r;
  115. }
  116. static int amdgpu_cgs_gunmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
  117. {
  118. int r;
  119. struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
  120. r = amdgpu_bo_reserve(obj, true);
  121. if (unlikely(r != 0))
  122. return r;
  123. r = amdgpu_bo_unpin(obj);
  124. amdgpu_bo_unreserve(obj);
  125. return r;
  126. }
  127. static int amdgpu_cgs_kmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle,
  128. void **map)
  129. {
  130. int r;
  131. struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
  132. r = amdgpu_bo_reserve(obj, true);
  133. if (unlikely(r != 0))
  134. return r;
  135. r = amdgpu_bo_kmap(obj, map);
  136. amdgpu_bo_unreserve(obj);
  137. return r;
  138. }
  139. static int amdgpu_cgs_kunmap_gpu_mem(struct cgs_device *cgs_device, cgs_handle_t handle)
  140. {
  141. int r;
  142. struct amdgpu_bo *obj = (struct amdgpu_bo *)handle;
  143. r = amdgpu_bo_reserve(obj, true);
  144. if (unlikely(r != 0))
  145. return r;
  146. amdgpu_bo_kunmap(obj);
  147. amdgpu_bo_unreserve(obj);
  148. return r;
  149. }
  150. static uint32_t amdgpu_cgs_read_register(struct cgs_device *cgs_device, unsigned offset)
  151. {
  152. CGS_FUNC_ADEV;
  153. return RREG32(offset);
  154. }
  155. static void amdgpu_cgs_write_register(struct cgs_device *cgs_device, unsigned offset,
  156. uint32_t value)
  157. {
  158. CGS_FUNC_ADEV;
  159. WREG32(offset, value);
  160. }
  161. static uint32_t amdgpu_cgs_read_ind_register(struct cgs_device *cgs_device,
  162. enum cgs_ind_reg space,
  163. unsigned index)
  164. {
  165. CGS_FUNC_ADEV;
  166. switch (space) {
  167. case CGS_IND_REG__MMIO:
  168. return RREG32_IDX(index);
  169. case CGS_IND_REG__PCIE:
  170. return RREG32_PCIE(index);
  171. case CGS_IND_REG__SMC:
  172. return RREG32_SMC(index);
  173. case CGS_IND_REG__UVD_CTX:
  174. return RREG32_UVD_CTX(index);
  175. case CGS_IND_REG__DIDT:
  176. return RREG32_DIDT(index);
  177. case CGS_IND_REG_GC_CAC:
  178. return RREG32_GC_CAC(index);
  179. case CGS_IND_REG_SE_CAC:
  180. return RREG32_SE_CAC(index);
  181. case CGS_IND_REG__AUDIO_ENDPT:
  182. DRM_ERROR("audio endpt register access not implemented.\n");
  183. return 0;
  184. }
  185. WARN(1, "Invalid indirect register space");
  186. return 0;
  187. }
  188. static void amdgpu_cgs_write_ind_register(struct cgs_device *cgs_device,
  189. enum cgs_ind_reg space,
  190. unsigned index, uint32_t value)
  191. {
  192. CGS_FUNC_ADEV;
  193. switch (space) {
  194. case CGS_IND_REG__MMIO:
  195. return WREG32_IDX(index, value);
  196. case CGS_IND_REG__PCIE:
  197. return WREG32_PCIE(index, value);
  198. case CGS_IND_REG__SMC:
  199. return WREG32_SMC(index, value);
  200. case CGS_IND_REG__UVD_CTX:
  201. return WREG32_UVD_CTX(index, value);
  202. case CGS_IND_REG__DIDT:
  203. return WREG32_DIDT(index, value);
  204. case CGS_IND_REG_GC_CAC:
  205. return WREG32_GC_CAC(index, value);
  206. case CGS_IND_REG_SE_CAC:
  207. return WREG32_SE_CAC(index, value);
  208. case CGS_IND_REG__AUDIO_ENDPT:
  209. DRM_ERROR("audio endpt register access not implemented.\n");
  210. return;
  211. }
  212. WARN(1, "Invalid indirect register space");
  213. }
  214. static int amdgpu_cgs_get_pci_resource(struct cgs_device *cgs_device,
  215. enum cgs_resource_type resource_type,
  216. uint64_t size,
  217. uint64_t offset,
  218. uint64_t *resource_base)
  219. {
  220. CGS_FUNC_ADEV;
  221. if (resource_base == NULL)
  222. return -EINVAL;
  223. switch (resource_type) {
  224. case CGS_RESOURCE_TYPE_MMIO:
  225. if (adev->rmmio_size == 0)
  226. return -ENOENT;
  227. if ((offset + size) > adev->rmmio_size)
  228. return -EINVAL;
  229. *resource_base = adev->rmmio_base;
  230. return 0;
  231. case CGS_RESOURCE_TYPE_DOORBELL:
  232. if (adev->doorbell.size == 0)
  233. return -ENOENT;
  234. if ((offset + size) > adev->doorbell.size)
  235. return -EINVAL;
  236. *resource_base = adev->doorbell.base;
  237. return 0;
  238. case CGS_RESOURCE_TYPE_FB:
  239. case CGS_RESOURCE_TYPE_IO:
  240. case CGS_RESOURCE_TYPE_ROM:
  241. default:
  242. return -EINVAL;
  243. }
  244. }
  245. static const void *amdgpu_cgs_atom_get_data_table(struct cgs_device *cgs_device,
  246. unsigned table, uint16_t *size,
  247. uint8_t *frev, uint8_t *crev)
  248. {
  249. CGS_FUNC_ADEV;
  250. uint16_t data_start;
  251. if (amdgpu_atom_parse_data_header(
  252. adev->mode_info.atom_context, table, size,
  253. frev, crev, &data_start))
  254. return (uint8_t*)adev->mode_info.atom_context->bios +
  255. data_start;
  256. return NULL;
  257. }
  258. static int amdgpu_cgs_atom_get_cmd_table_revs(struct cgs_device *cgs_device, unsigned table,
  259. uint8_t *frev, uint8_t *crev)
  260. {
  261. CGS_FUNC_ADEV;
  262. if (amdgpu_atom_parse_cmd_header(
  263. adev->mode_info.atom_context, table,
  264. frev, crev))
  265. return 0;
  266. return -EINVAL;
  267. }
  268. static int amdgpu_cgs_atom_exec_cmd_table(struct cgs_device *cgs_device, unsigned table,
  269. void *args)
  270. {
  271. CGS_FUNC_ADEV;
  272. return amdgpu_atom_execute_table(
  273. adev->mode_info.atom_context, table, args);
  274. }
  275. struct cgs_irq_params {
  276. unsigned src_id;
  277. cgs_irq_source_set_func_t set;
  278. cgs_irq_handler_func_t handler;
  279. void *private_data;
  280. };
  281. static int cgs_set_irq_state(struct amdgpu_device *adev,
  282. struct amdgpu_irq_src *src,
  283. unsigned type,
  284. enum amdgpu_interrupt_state state)
  285. {
  286. struct cgs_irq_params *irq_params =
  287. (struct cgs_irq_params *)src->data;
  288. if (!irq_params)
  289. return -EINVAL;
  290. if (!irq_params->set)
  291. return -EINVAL;
  292. return irq_params->set(irq_params->private_data,
  293. irq_params->src_id,
  294. type,
  295. (int)state);
  296. }
  297. static int cgs_process_irq(struct amdgpu_device *adev,
  298. struct amdgpu_irq_src *source,
  299. struct amdgpu_iv_entry *entry)
  300. {
  301. struct cgs_irq_params *irq_params =
  302. (struct cgs_irq_params *)source->data;
  303. if (!irq_params)
  304. return -EINVAL;
  305. if (!irq_params->handler)
  306. return -EINVAL;
  307. return irq_params->handler(irq_params->private_data,
  308. irq_params->src_id,
  309. entry->iv_entry);
  310. }
  311. static const struct amdgpu_irq_src_funcs cgs_irq_funcs = {
  312. .set = cgs_set_irq_state,
  313. .process = cgs_process_irq,
  314. };
  315. static int amdgpu_cgs_add_irq_source(void *cgs_device,
  316. unsigned client_id,
  317. unsigned src_id,
  318. unsigned num_types,
  319. cgs_irq_source_set_func_t set,
  320. cgs_irq_handler_func_t handler,
  321. void *private_data)
  322. {
  323. CGS_FUNC_ADEV;
  324. int ret = 0;
  325. struct cgs_irq_params *irq_params;
  326. struct amdgpu_irq_src *source =
  327. kzalloc(sizeof(struct amdgpu_irq_src), GFP_KERNEL);
  328. if (!source)
  329. return -ENOMEM;
  330. irq_params =
  331. kzalloc(sizeof(struct cgs_irq_params), GFP_KERNEL);
  332. if (!irq_params) {
  333. kfree(source);
  334. return -ENOMEM;
  335. }
  336. source->num_types = num_types;
  337. source->funcs = &cgs_irq_funcs;
  338. irq_params->src_id = src_id;
  339. irq_params->set = set;
  340. irq_params->handler = handler;
  341. irq_params->private_data = private_data;
  342. source->data = (void *)irq_params;
  343. ret = amdgpu_irq_add_id(adev, client_id, src_id, source);
  344. if (ret) {
  345. kfree(irq_params);
  346. kfree(source);
  347. }
  348. return ret;
  349. }
  350. static int amdgpu_cgs_irq_get(void *cgs_device, unsigned client_id,
  351. unsigned src_id, unsigned type)
  352. {
  353. CGS_FUNC_ADEV;
  354. if (!adev->irq.client[client_id].sources)
  355. return -EINVAL;
  356. return amdgpu_irq_get(adev, adev->irq.client[client_id].sources[src_id], type);
  357. }
  358. static int amdgpu_cgs_irq_put(void *cgs_device, unsigned client_id,
  359. unsigned src_id, unsigned type)
  360. {
  361. CGS_FUNC_ADEV;
  362. if (!adev->irq.client[client_id].sources)
  363. return -EINVAL;
  364. return amdgpu_irq_put(adev, adev->irq.client[client_id].sources[src_id], type);
  365. }
  366. static int amdgpu_cgs_set_clockgating_state(struct cgs_device *cgs_device,
  367. enum amd_ip_block_type block_type,
  368. enum amd_clockgating_state state)
  369. {
  370. CGS_FUNC_ADEV;
  371. int i, r = -1;
  372. for (i = 0; i < adev->num_ip_blocks; i++) {
  373. if (!adev->ip_blocks[i].status.valid)
  374. continue;
  375. if (adev->ip_blocks[i].version->type == block_type) {
  376. r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
  377. (void *)adev,
  378. state);
  379. break;
  380. }
  381. }
  382. return r;
  383. }
  384. static int amdgpu_cgs_set_powergating_state(struct cgs_device *cgs_device,
  385. enum amd_ip_block_type block_type,
  386. enum amd_powergating_state state)
  387. {
  388. CGS_FUNC_ADEV;
  389. int i, r = -1;
  390. for (i = 0; i < adev->num_ip_blocks; i++) {
  391. if (!adev->ip_blocks[i].status.valid)
  392. continue;
  393. if (adev->ip_blocks[i].version->type == block_type) {
  394. r = adev->ip_blocks[i].version->funcs->set_powergating_state(
  395. (void *)adev,
  396. state);
  397. break;
  398. }
  399. }
  400. return r;
  401. }
  402. static uint32_t fw_type_convert(struct cgs_device *cgs_device, uint32_t fw_type)
  403. {
  404. CGS_FUNC_ADEV;
  405. enum AMDGPU_UCODE_ID result = AMDGPU_UCODE_ID_MAXIMUM;
  406. switch (fw_type) {
  407. case CGS_UCODE_ID_SDMA0:
  408. result = AMDGPU_UCODE_ID_SDMA0;
  409. break;
  410. case CGS_UCODE_ID_SDMA1:
  411. result = AMDGPU_UCODE_ID_SDMA1;
  412. break;
  413. case CGS_UCODE_ID_CP_CE:
  414. result = AMDGPU_UCODE_ID_CP_CE;
  415. break;
  416. case CGS_UCODE_ID_CP_PFP:
  417. result = AMDGPU_UCODE_ID_CP_PFP;
  418. break;
  419. case CGS_UCODE_ID_CP_ME:
  420. result = AMDGPU_UCODE_ID_CP_ME;
  421. break;
  422. case CGS_UCODE_ID_CP_MEC:
  423. case CGS_UCODE_ID_CP_MEC_JT1:
  424. result = AMDGPU_UCODE_ID_CP_MEC1;
  425. break;
  426. case CGS_UCODE_ID_CP_MEC_JT2:
  427. /* for VI. JT2 should be the same as JT1, because:
  428. 1, MEC2 and MEC1 use exactly same FW.
  429. 2, JT2 is not pached but JT1 is.
  430. */
  431. if (adev->asic_type >= CHIP_TOPAZ)
  432. result = AMDGPU_UCODE_ID_CP_MEC1;
  433. else
  434. result = AMDGPU_UCODE_ID_CP_MEC2;
  435. break;
  436. case CGS_UCODE_ID_RLC_G:
  437. result = AMDGPU_UCODE_ID_RLC_G;
  438. break;
  439. case CGS_UCODE_ID_STORAGE:
  440. result = AMDGPU_UCODE_ID_STORAGE;
  441. break;
  442. default:
  443. DRM_ERROR("Firmware type not supported\n");
  444. }
  445. return result;
  446. }
  447. static int amdgpu_cgs_rel_firmware(struct cgs_device *cgs_device, enum cgs_ucode_id type)
  448. {
  449. CGS_FUNC_ADEV;
  450. if ((CGS_UCODE_ID_SMU == type) || (CGS_UCODE_ID_SMU_SK == type)) {
  451. release_firmware(adev->pm.fw);
  452. adev->pm.fw = NULL;
  453. return 0;
  454. }
  455. /* cannot release other firmware because they are not created by cgs */
  456. return -EINVAL;
  457. }
  458. static uint16_t amdgpu_get_firmware_version(struct cgs_device *cgs_device,
  459. enum cgs_ucode_id type)
  460. {
  461. CGS_FUNC_ADEV;
  462. uint16_t fw_version = 0;
  463. switch (type) {
  464. case CGS_UCODE_ID_SDMA0:
  465. fw_version = adev->sdma.instance[0].fw_version;
  466. break;
  467. case CGS_UCODE_ID_SDMA1:
  468. fw_version = adev->sdma.instance[1].fw_version;
  469. break;
  470. case CGS_UCODE_ID_CP_CE:
  471. fw_version = adev->gfx.ce_fw_version;
  472. break;
  473. case CGS_UCODE_ID_CP_PFP:
  474. fw_version = adev->gfx.pfp_fw_version;
  475. break;
  476. case CGS_UCODE_ID_CP_ME:
  477. fw_version = adev->gfx.me_fw_version;
  478. break;
  479. case CGS_UCODE_ID_CP_MEC:
  480. fw_version = adev->gfx.mec_fw_version;
  481. break;
  482. case CGS_UCODE_ID_CP_MEC_JT1:
  483. fw_version = adev->gfx.mec_fw_version;
  484. break;
  485. case CGS_UCODE_ID_CP_MEC_JT2:
  486. fw_version = adev->gfx.mec_fw_version;
  487. break;
  488. case CGS_UCODE_ID_RLC_G:
  489. fw_version = adev->gfx.rlc_fw_version;
  490. break;
  491. case CGS_UCODE_ID_STORAGE:
  492. break;
  493. default:
  494. DRM_ERROR("firmware type %d do not have version\n", type);
  495. break;
  496. }
  497. return fw_version;
  498. }
  499. static int amdgpu_cgs_enter_safe_mode(struct cgs_device *cgs_device,
  500. bool en)
  501. {
  502. CGS_FUNC_ADEV;
  503. if (adev->gfx.rlc.funcs->enter_safe_mode == NULL ||
  504. adev->gfx.rlc.funcs->exit_safe_mode == NULL)
  505. return 0;
  506. if (en)
  507. adev->gfx.rlc.funcs->enter_safe_mode(adev);
  508. else
  509. adev->gfx.rlc.funcs->exit_safe_mode(adev);
  510. return 0;
  511. }
  512. static void amdgpu_cgs_lock_grbm_idx(struct cgs_device *cgs_device,
  513. bool lock)
  514. {
  515. CGS_FUNC_ADEV;
  516. if (lock)
  517. mutex_lock(&adev->grbm_idx_mutex);
  518. else
  519. mutex_unlock(&adev->grbm_idx_mutex);
  520. }
  521. static int amdgpu_cgs_get_firmware_info(struct cgs_device *cgs_device,
  522. enum cgs_ucode_id type,
  523. struct cgs_firmware_info *info)
  524. {
  525. CGS_FUNC_ADEV;
  526. if ((CGS_UCODE_ID_SMU != type) && (CGS_UCODE_ID_SMU_SK != type)) {
  527. uint64_t gpu_addr;
  528. uint32_t data_size;
  529. const struct gfx_firmware_header_v1_0 *header;
  530. enum AMDGPU_UCODE_ID id;
  531. struct amdgpu_firmware_info *ucode;
  532. id = fw_type_convert(cgs_device, type);
  533. ucode = &adev->firmware.ucode[id];
  534. if (ucode->fw == NULL)
  535. return -EINVAL;
  536. gpu_addr = ucode->mc_addr;
  537. header = (const struct gfx_firmware_header_v1_0 *)ucode->fw->data;
  538. data_size = le32_to_cpu(header->header.ucode_size_bytes);
  539. if ((type == CGS_UCODE_ID_CP_MEC_JT1) ||
  540. (type == CGS_UCODE_ID_CP_MEC_JT2)) {
  541. gpu_addr += ALIGN(le32_to_cpu(header->header.ucode_size_bytes), PAGE_SIZE);
  542. data_size = le32_to_cpu(header->jt_size) << 2;
  543. }
  544. info->kptr = ucode->kaddr;
  545. info->image_size = data_size;
  546. info->mc_addr = gpu_addr;
  547. info->version = (uint16_t)le32_to_cpu(header->header.ucode_version);
  548. if (CGS_UCODE_ID_CP_MEC == type)
  549. info->image_size = le32_to_cpu(header->jt_offset) << 2;
  550. info->fw_version = amdgpu_get_firmware_version(cgs_device, type);
  551. info->feature_version = (uint16_t)le32_to_cpu(header->ucode_feature_version);
  552. } else {
  553. char fw_name[30] = {0};
  554. int err = 0;
  555. uint32_t ucode_size;
  556. uint32_t ucode_start_address;
  557. const uint8_t *src;
  558. const struct smc_firmware_header_v1_0 *hdr;
  559. const struct common_firmware_header *header;
  560. struct amdgpu_firmware_info *ucode = NULL;
  561. if (!adev->pm.fw) {
  562. switch (adev->asic_type) {
  563. case CHIP_TAHITI:
  564. strcpy(fw_name, "radeon/tahiti_smc.bin");
  565. break;
  566. case CHIP_PITCAIRN:
  567. if ((adev->pdev->revision == 0x81) &&
  568. ((adev->pdev->device == 0x6810) ||
  569. (adev->pdev->device == 0x6811))) {
  570. info->is_kicker = true;
  571. strcpy(fw_name, "radeon/pitcairn_k_smc.bin");
  572. } else {
  573. strcpy(fw_name, "radeon/pitcairn_smc.bin");
  574. }
  575. break;
  576. case CHIP_VERDE:
  577. if (((adev->pdev->device == 0x6820) &&
  578. ((adev->pdev->revision == 0x81) ||
  579. (adev->pdev->revision == 0x83))) ||
  580. ((adev->pdev->device == 0x6821) &&
  581. ((adev->pdev->revision == 0x83) ||
  582. (adev->pdev->revision == 0x87))) ||
  583. ((adev->pdev->revision == 0x87) &&
  584. ((adev->pdev->device == 0x6823) ||
  585. (adev->pdev->device == 0x682b)))) {
  586. info->is_kicker = true;
  587. strcpy(fw_name, "radeon/verde_k_smc.bin");
  588. } else {
  589. strcpy(fw_name, "radeon/verde_smc.bin");
  590. }
  591. break;
  592. case CHIP_OLAND:
  593. if (((adev->pdev->revision == 0x81) &&
  594. ((adev->pdev->device == 0x6600) ||
  595. (adev->pdev->device == 0x6604) ||
  596. (adev->pdev->device == 0x6605) ||
  597. (adev->pdev->device == 0x6610))) ||
  598. ((adev->pdev->revision == 0x83) &&
  599. (adev->pdev->device == 0x6610))) {
  600. info->is_kicker = true;
  601. strcpy(fw_name, "radeon/oland_k_smc.bin");
  602. } else {
  603. strcpy(fw_name, "radeon/oland_smc.bin");
  604. }
  605. break;
  606. case CHIP_HAINAN:
  607. if (((adev->pdev->revision == 0x81) &&
  608. (adev->pdev->device == 0x6660)) ||
  609. ((adev->pdev->revision == 0x83) &&
  610. ((adev->pdev->device == 0x6660) ||
  611. (adev->pdev->device == 0x6663) ||
  612. (adev->pdev->device == 0x6665) ||
  613. (adev->pdev->device == 0x6667)))) {
  614. info->is_kicker = true;
  615. strcpy(fw_name, "radeon/hainan_k_smc.bin");
  616. } else if ((adev->pdev->revision == 0xc3) &&
  617. (adev->pdev->device == 0x6665)) {
  618. info->is_kicker = true;
  619. strcpy(fw_name, "radeon/banks_k_2_smc.bin");
  620. } else {
  621. strcpy(fw_name, "radeon/hainan_smc.bin");
  622. }
  623. break;
  624. case CHIP_BONAIRE:
  625. if ((adev->pdev->revision == 0x80) ||
  626. (adev->pdev->revision == 0x81) ||
  627. (adev->pdev->device == 0x665f)) {
  628. info->is_kicker = true;
  629. strcpy(fw_name, "radeon/bonaire_k_smc.bin");
  630. } else {
  631. strcpy(fw_name, "radeon/bonaire_smc.bin");
  632. }
  633. break;
  634. case CHIP_HAWAII:
  635. if (adev->pdev->revision == 0x80) {
  636. info->is_kicker = true;
  637. strcpy(fw_name, "radeon/hawaii_k_smc.bin");
  638. } else {
  639. strcpy(fw_name, "radeon/hawaii_smc.bin");
  640. }
  641. break;
  642. case CHIP_TOPAZ:
  643. if (((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x81)) ||
  644. ((adev->pdev->device == 0x6900) && (adev->pdev->revision == 0x83)) ||
  645. ((adev->pdev->device == 0x6907) && (adev->pdev->revision == 0x87))) {
  646. info->is_kicker = true;
  647. strcpy(fw_name, "amdgpu/topaz_k_smc.bin");
  648. } else
  649. strcpy(fw_name, "amdgpu/topaz_smc.bin");
  650. break;
  651. case CHIP_TONGA:
  652. if (((adev->pdev->device == 0x6939) && (adev->pdev->revision == 0xf1)) ||
  653. ((adev->pdev->device == 0x6938) && (adev->pdev->revision == 0xf1))) {
  654. info->is_kicker = true;
  655. strcpy(fw_name, "amdgpu/tonga_k_smc.bin");
  656. } else
  657. strcpy(fw_name, "amdgpu/tonga_smc.bin");
  658. break;
  659. case CHIP_FIJI:
  660. strcpy(fw_name, "amdgpu/fiji_smc.bin");
  661. break;
  662. case CHIP_POLARIS11:
  663. if (type == CGS_UCODE_ID_SMU) {
  664. if (((adev->pdev->device == 0x67ef) &&
  665. ((adev->pdev->revision == 0xe0) ||
  666. (adev->pdev->revision == 0xe2) ||
  667. (adev->pdev->revision == 0xe5))) ||
  668. ((adev->pdev->device == 0x67ff) &&
  669. ((adev->pdev->revision == 0xcf) ||
  670. (adev->pdev->revision == 0xef) ||
  671. (adev->pdev->revision == 0xff)))) {
  672. info->is_kicker = true;
  673. strcpy(fw_name, "amdgpu/polaris11_k_smc.bin");
  674. } else
  675. strcpy(fw_name, "amdgpu/polaris11_smc.bin");
  676. } else if (type == CGS_UCODE_ID_SMU_SK) {
  677. strcpy(fw_name, "amdgpu/polaris11_smc_sk.bin");
  678. }
  679. break;
  680. case CHIP_POLARIS10:
  681. if (type == CGS_UCODE_ID_SMU) {
  682. if ((adev->pdev->device == 0x67df) &&
  683. ((adev->pdev->revision == 0xe0) ||
  684. (adev->pdev->revision == 0xe3) ||
  685. (adev->pdev->revision == 0xe4) ||
  686. (adev->pdev->revision == 0xe5) ||
  687. (adev->pdev->revision == 0xe7) ||
  688. (adev->pdev->revision == 0xef))) {
  689. info->is_kicker = true;
  690. strcpy(fw_name, "amdgpu/polaris10_k_smc.bin");
  691. } else
  692. strcpy(fw_name, "amdgpu/polaris10_smc.bin");
  693. } else if (type == CGS_UCODE_ID_SMU_SK) {
  694. strcpy(fw_name, "amdgpu/polaris10_smc_sk.bin");
  695. }
  696. break;
  697. case CHIP_POLARIS12:
  698. strcpy(fw_name, "amdgpu/polaris12_smc.bin");
  699. break;
  700. case CHIP_VEGA10:
  701. if ((adev->pdev->device == 0x687f) &&
  702. ((adev->pdev->revision == 0xc0) ||
  703. (adev->pdev->revision == 0xc1) ||
  704. (adev->pdev->revision == 0xc3)))
  705. strcpy(fw_name, "amdgpu/vega10_acg_smc.bin");
  706. else
  707. strcpy(fw_name, "amdgpu/vega10_smc.bin");
  708. break;
  709. default:
  710. DRM_ERROR("SMC firmware not supported\n");
  711. return -EINVAL;
  712. }
  713. err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
  714. if (err) {
  715. DRM_ERROR("Failed to request firmware\n");
  716. return err;
  717. }
  718. err = amdgpu_ucode_validate(adev->pm.fw);
  719. if (err) {
  720. DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
  721. release_firmware(adev->pm.fw);
  722. adev->pm.fw = NULL;
  723. return err;
  724. }
  725. if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
  726. ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
  727. ucode->ucode_id = AMDGPU_UCODE_ID_SMC;
  728. ucode->fw = adev->pm.fw;
  729. header = (const struct common_firmware_header *)ucode->fw->data;
  730. adev->firmware.fw_size +=
  731. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  732. }
  733. }
  734. hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
  735. amdgpu_ucode_print_smc_hdr(&hdr->header);
  736. adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
  737. ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes);
  738. ucode_start_address = le32_to_cpu(hdr->ucode_start_addr);
  739. src = (const uint8_t *)(adev->pm.fw->data +
  740. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  741. info->version = adev->pm.fw_version;
  742. info->image_size = ucode_size;
  743. info->ucode_start_address = ucode_start_address;
  744. info->kptr = (void *)src;
  745. }
  746. return 0;
  747. }
  748. static int amdgpu_cgs_is_virtualization_enabled(void *cgs_device)
  749. {
  750. CGS_FUNC_ADEV;
  751. return amdgpu_sriov_vf(adev);
  752. }
  753. static int amdgpu_cgs_query_system_info(struct cgs_device *cgs_device,
  754. struct cgs_system_info *sys_info)
  755. {
  756. CGS_FUNC_ADEV;
  757. if (NULL == sys_info)
  758. return -ENODEV;
  759. if (sizeof(struct cgs_system_info) != sys_info->size)
  760. return -ENODEV;
  761. switch (sys_info->info_id) {
  762. case CGS_SYSTEM_INFO_ADAPTER_BDF_ID:
  763. sys_info->value = adev->pdev->devfn | (adev->pdev->bus->number << 8);
  764. break;
  765. case CGS_SYSTEM_INFO_PCIE_GEN_INFO:
  766. sys_info->value = adev->pm.pcie_gen_mask;
  767. break;
  768. case CGS_SYSTEM_INFO_PCIE_MLW:
  769. sys_info->value = adev->pm.pcie_mlw_mask;
  770. break;
  771. case CGS_SYSTEM_INFO_PCIE_DEV:
  772. sys_info->value = adev->pdev->device;
  773. break;
  774. case CGS_SYSTEM_INFO_PCIE_REV:
  775. sys_info->value = adev->pdev->revision;
  776. break;
  777. case CGS_SYSTEM_INFO_CG_FLAGS:
  778. sys_info->value = adev->cg_flags;
  779. break;
  780. case CGS_SYSTEM_INFO_PG_FLAGS:
  781. sys_info->value = adev->pg_flags;
  782. break;
  783. case CGS_SYSTEM_INFO_GFX_CU_INFO:
  784. sys_info->value = adev->gfx.cu_info.number;
  785. break;
  786. case CGS_SYSTEM_INFO_GFX_SE_INFO:
  787. sys_info->value = adev->gfx.config.max_shader_engines;
  788. break;
  789. case CGS_SYSTEM_INFO_PCIE_SUB_SYS_ID:
  790. sys_info->value = adev->pdev->subsystem_device;
  791. break;
  792. case CGS_SYSTEM_INFO_PCIE_SUB_SYS_VENDOR_ID:
  793. sys_info->value = adev->pdev->subsystem_vendor;
  794. break;
  795. case CGS_SYSTEM_INFO_PCIE_BUS_DEVFN:
  796. sys_info->value = adev->pdev->devfn;
  797. break;
  798. default:
  799. return -ENODEV;
  800. }
  801. return 0;
  802. }
  803. static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
  804. struct cgs_display_info *info)
  805. {
  806. CGS_FUNC_ADEV;
  807. struct amdgpu_crtc *amdgpu_crtc;
  808. struct drm_device *ddev = adev->ddev;
  809. struct drm_crtc *crtc;
  810. uint32_t line_time_us, vblank_lines;
  811. struct cgs_mode_info *mode_info;
  812. if (info == NULL)
  813. return -EINVAL;
  814. mode_info = info->mode_info;
  815. if (mode_info) {
  816. /* if the displays are off, vblank time is max */
  817. mode_info->vblank_time_us = 0xffffffff;
  818. /* always set the reference clock */
  819. mode_info->ref_clock = adev->clock.spll.reference_freq;
  820. }
  821. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  822. list_for_each_entry(crtc,
  823. &ddev->mode_config.crtc_list, head) {
  824. amdgpu_crtc = to_amdgpu_crtc(crtc);
  825. if (crtc->enabled) {
  826. info->active_display_mask |= (1 << amdgpu_crtc->crtc_id);
  827. info->display_count++;
  828. }
  829. if (mode_info != NULL &&
  830. crtc->enabled && amdgpu_crtc->enabled &&
  831. amdgpu_crtc->hw_mode.clock) {
  832. line_time_us = (amdgpu_crtc->hw_mode.crtc_htotal * 1000) /
  833. amdgpu_crtc->hw_mode.clock;
  834. vblank_lines = amdgpu_crtc->hw_mode.crtc_vblank_end -
  835. amdgpu_crtc->hw_mode.crtc_vdisplay +
  836. (amdgpu_crtc->v_border * 2);
  837. mode_info->vblank_time_us = vblank_lines * line_time_us;
  838. mode_info->refresh_rate = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
  839. mode_info->ref_clock = adev->clock.spll.reference_freq;
  840. mode_info = NULL;
  841. }
  842. }
  843. }
  844. return 0;
  845. }
  846. static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool enabled)
  847. {
  848. CGS_FUNC_ADEV;
  849. adev->pm.dpm_enabled = enabled;
  850. return 0;
  851. }
  852. /** \brief evaluate acpi namespace object, handle or pathname must be valid
  853. * \param cgs_device
  854. * \param info input/output arguments for the control method
  855. * \return status
  856. */
  857. #if defined(CONFIG_ACPI)
  858. static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
  859. struct cgs_acpi_method_info *info)
  860. {
  861. CGS_FUNC_ADEV;
  862. acpi_handle handle;
  863. struct acpi_object_list input;
  864. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  865. union acpi_object *params, *obj;
  866. uint8_t name[5] = {'\0'};
  867. struct cgs_acpi_method_argument *argument;
  868. uint32_t i, count;
  869. acpi_status status;
  870. int result;
  871. handle = ACPI_HANDLE(&adev->pdev->dev);
  872. if (!handle)
  873. return -ENODEV;
  874. memset(&input, 0, sizeof(struct acpi_object_list));
  875. /* validate input info */
  876. if (info->size != sizeof(struct cgs_acpi_method_info))
  877. return -EINVAL;
  878. input.count = info->input_count;
  879. if (info->input_count > 0) {
  880. if (info->pinput_argument == NULL)
  881. return -EINVAL;
  882. argument = info->pinput_argument;
  883. for (i = 0; i < info->input_count; i++) {
  884. if (((argument->type == ACPI_TYPE_STRING) ||
  885. (argument->type == ACPI_TYPE_BUFFER)) &&
  886. (argument->pointer == NULL))
  887. return -EINVAL;
  888. argument++;
  889. }
  890. }
  891. if (info->output_count > 0) {
  892. if (info->poutput_argument == NULL)
  893. return -EINVAL;
  894. argument = info->poutput_argument;
  895. for (i = 0; i < info->output_count; i++) {
  896. if (((argument->type == ACPI_TYPE_STRING) ||
  897. (argument->type == ACPI_TYPE_BUFFER))
  898. && (argument->pointer == NULL))
  899. return -EINVAL;
  900. argument++;
  901. }
  902. }
  903. /* The path name passed to acpi_evaluate_object should be null terminated */
  904. if ((info->field & CGS_ACPI_FIELD_METHOD_NAME) != 0) {
  905. strncpy(name, (char *)&(info->name), sizeof(uint32_t));
  906. name[4] = '\0';
  907. }
  908. /* parse input parameters */
  909. if (input.count > 0) {
  910. input.pointer = params =
  911. kzalloc(sizeof(union acpi_object) * input.count, GFP_KERNEL);
  912. if (params == NULL)
  913. return -EINVAL;
  914. argument = info->pinput_argument;
  915. for (i = 0; i < input.count; i++) {
  916. params->type = argument->type;
  917. switch (params->type) {
  918. case ACPI_TYPE_INTEGER:
  919. params->integer.value = argument->value;
  920. break;
  921. case ACPI_TYPE_STRING:
  922. params->string.length = argument->data_length;
  923. params->string.pointer = argument->pointer;
  924. break;
  925. case ACPI_TYPE_BUFFER:
  926. params->buffer.length = argument->data_length;
  927. params->buffer.pointer = argument->pointer;
  928. break;
  929. default:
  930. break;
  931. }
  932. params++;
  933. argument++;
  934. }
  935. }
  936. /* parse output info */
  937. count = info->output_count;
  938. argument = info->poutput_argument;
  939. /* evaluate the acpi method */
  940. status = acpi_evaluate_object(handle, name, &input, &output);
  941. if (ACPI_FAILURE(status)) {
  942. result = -EIO;
  943. goto free_input;
  944. }
  945. /* return the output info */
  946. obj = output.pointer;
  947. if (count > 1) {
  948. if ((obj->type != ACPI_TYPE_PACKAGE) ||
  949. (obj->package.count != count)) {
  950. result = -EIO;
  951. goto free_obj;
  952. }
  953. params = obj->package.elements;
  954. } else
  955. params = obj;
  956. if (params == NULL) {
  957. result = -EIO;
  958. goto free_obj;
  959. }
  960. for (i = 0; i < count; i++) {
  961. if (argument->type != params->type) {
  962. result = -EIO;
  963. goto free_obj;
  964. }
  965. switch (params->type) {
  966. case ACPI_TYPE_INTEGER:
  967. argument->value = params->integer.value;
  968. break;
  969. case ACPI_TYPE_STRING:
  970. if ((params->string.length != argument->data_length) ||
  971. (params->string.pointer == NULL)) {
  972. result = -EIO;
  973. goto free_obj;
  974. }
  975. strncpy(argument->pointer,
  976. params->string.pointer,
  977. params->string.length);
  978. break;
  979. case ACPI_TYPE_BUFFER:
  980. if (params->buffer.pointer == NULL) {
  981. result = -EIO;
  982. goto free_obj;
  983. }
  984. memcpy(argument->pointer,
  985. params->buffer.pointer,
  986. argument->data_length);
  987. break;
  988. default:
  989. break;
  990. }
  991. argument++;
  992. params++;
  993. }
  994. result = 0;
  995. free_obj:
  996. kfree(obj);
  997. free_input:
  998. kfree((void *)input.pointer);
  999. return result;
  1000. }
  1001. #else
  1002. static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
  1003. struct cgs_acpi_method_info *info)
  1004. {
  1005. return -EIO;
  1006. }
  1007. #endif
  1008. static int amdgpu_cgs_call_acpi_method(struct cgs_device *cgs_device,
  1009. uint32_t acpi_method,
  1010. uint32_t acpi_function,
  1011. void *pinput, void *poutput,
  1012. uint32_t output_count,
  1013. uint32_t input_size,
  1014. uint32_t output_size)
  1015. {
  1016. struct cgs_acpi_method_argument acpi_input[2] = { {0}, {0} };
  1017. struct cgs_acpi_method_argument acpi_output = {0};
  1018. struct cgs_acpi_method_info info = {0};
  1019. acpi_input[0].type = CGS_ACPI_TYPE_INTEGER;
  1020. acpi_input[0].data_length = sizeof(uint32_t);
  1021. acpi_input[0].value = acpi_function;
  1022. acpi_input[1].type = CGS_ACPI_TYPE_BUFFER;
  1023. acpi_input[1].data_length = input_size;
  1024. acpi_input[1].pointer = pinput;
  1025. acpi_output.type = CGS_ACPI_TYPE_BUFFER;
  1026. acpi_output.data_length = output_size;
  1027. acpi_output.pointer = poutput;
  1028. info.size = sizeof(struct cgs_acpi_method_info);
  1029. info.field = CGS_ACPI_FIELD_METHOD_NAME | CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT;
  1030. info.input_count = 2;
  1031. info.name = acpi_method;
  1032. info.pinput_argument = acpi_input;
  1033. info.output_count = output_count;
  1034. info.poutput_argument = &acpi_output;
  1035. return amdgpu_cgs_acpi_eval_object(cgs_device, &info);
  1036. }
  1037. static const struct cgs_ops amdgpu_cgs_ops = {
  1038. .alloc_gpu_mem = amdgpu_cgs_alloc_gpu_mem,
  1039. .free_gpu_mem = amdgpu_cgs_free_gpu_mem,
  1040. .gmap_gpu_mem = amdgpu_cgs_gmap_gpu_mem,
  1041. .gunmap_gpu_mem = amdgpu_cgs_gunmap_gpu_mem,
  1042. .kmap_gpu_mem = amdgpu_cgs_kmap_gpu_mem,
  1043. .kunmap_gpu_mem = amdgpu_cgs_kunmap_gpu_mem,
  1044. .read_register = amdgpu_cgs_read_register,
  1045. .write_register = amdgpu_cgs_write_register,
  1046. .read_ind_register = amdgpu_cgs_read_ind_register,
  1047. .write_ind_register = amdgpu_cgs_write_ind_register,
  1048. .get_pci_resource = amdgpu_cgs_get_pci_resource,
  1049. .atom_get_data_table = amdgpu_cgs_atom_get_data_table,
  1050. .atom_get_cmd_table_revs = amdgpu_cgs_atom_get_cmd_table_revs,
  1051. .atom_exec_cmd_table = amdgpu_cgs_atom_exec_cmd_table,
  1052. .get_firmware_info = amdgpu_cgs_get_firmware_info,
  1053. .rel_firmware = amdgpu_cgs_rel_firmware,
  1054. .set_powergating_state = amdgpu_cgs_set_powergating_state,
  1055. .set_clockgating_state = amdgpu_cgs_set_clockgating_state,
  1056. .get_active_displays_info = amdgpu_cgs_get_active_displays_info,
  1057. .notify_dpm_enabled = amdgpu_cgs_notify_dpm_enabled,
  1058. .call_acpi_method = amdgpu_cgs_call_acpi_method,
  1059. .query_system_info = amdgpu_cgs_query_system_info,
  1060. .is_virtualization_enabled = amdgpu_cgs_is_virtualization_enabled,
  1061. .enter_safe_mode = amdgpu_cgs_enter_safe_mode,
  1062. .lock_grbm_idx = amdgpu_cgs_lock_grbm_idx,
  1063. };
  1064. static const struct cgs_os_ops amdgpu_cgs_os_ops = {
  1065. .add_irq_source = amdgpu_cgs_add_irq_source,
  1066. .irq_get = amdgpu_cgs_irq_get,
  1067. .irq_put = amdgpu_cgs_irq_put
  1068. };
  1069. struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev)
  1070. {
  1071. struct amdgpu_cgs_device *cgs_device =
  1072. kmalloc(sizeof(*cgs_device), GFP_KERNEL);
  1073. if (!cgs_device) {
  1074. DRM_ERROR("Couldn't allocate CGS device structure\n");
  1075. return NULL;
  1076. }
  1077. cgs_device->base.ops = &amdgpu_cgs_ops;
  1078. cgs_device->base.os_ops = &amdgpu_cgs_os_ops;
  1079. cgs_device->adev = adev;
  1080. return (struct cgs_device *)cgs_device;
  1081. }
  1082. void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device)
  1083. {
  1084. kfree(cgs_device);
  1085. }