amdgpu_cgs.c 33 KB

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