amdgpu_cgs.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. case CHIP_CARRIZO:
  728. case CHIP_STONEY:
  729. case CHIP_RAVEN:
  730. adev->pm.fw_version = info->version;
  731. return 0;
  732. default:
  733. DRM_ERROR("SMC firmware not supported\n");
  734. return -EINVAL;
  735. }
  736. err = request_firmware(&adev->pm.fw, fw_name, adev->dev);
  737. if (err) {
  738. DRM_ERROR("Failed to request firmware\n");
  739. return err;
  740. }
  741. err = amdgpu_ucode_validate(adev->pm.fw);
  742. if (err) {
  743. DRM_ERROR("Failed to load firmware \"%s\"", fw_name);
  744. release_firmware(adev->pm.fw);
  745. adev->pm.fw = NULL;
  746. return err;
  747. }
  748. if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
  749. ucode = &adev->firmware.ucode[AMDGPU_UCODE_ID_SMC];
  750. ucode->ucode_id = AMDGPU_UCODE_ID_SMC;
  751. ucode->fw = adev->pm.fw;
  752. header = (const struct common_firmware_header *)ucode->fw->data;
  753. adev->firmware.fw_size +=
  754. ALIGN(le32_to_cpu(header->ucode_size_bytes), PAGE_SIZE);
  755. }
  756. }
  757. hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
  758. amdgpu_ucode_print_smc_hdr(&hdr->header);
  759. adev->pm.fw_version = le32_to_cpu(hdr->header.ucode_version);
  760. ucode_size = le32_to_cpu(hdr->header.ucode_size_bytes);
  761. ucode_start_address = le32_to_cpu(hdr->ucode_start_addr);
  762. src = (const uint8_t *)(adev->pm.fw->data +
  763. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  764. info->version = adev->pm.fw_version;
  765. info->image_size = ucode_size;
  766. info->ucode_start_address = ucode_start_address;
  767. info->kptr = (void *)src;
  768. }
  769. return 0;
  770. }
  771. static int amdgpu_cgs_is_virtualization_enabled(void *cgs_device)
  772. {
  773. CGS_FUNC_ADEV;
  774. return amdgpu_sriov_vf(adev);
  775. }
  776. static int amdgpu_cgs_query_system_info(struct cgs_device *cgs_device,
  777. struct cgs_system_info *sys_info)
  778. {
  779. CGS_FUNC_ADEV;
  780. if (NULL == sys_info)
  781. return -ENODEV;
  782. if (sizeof(struct cgs_system_info) != sys_info->size)
  783. return -ENODEV;
  784. switch (sys_info->info_id) {
  785. case CGS_SYSTEM_INFO_ADAPTER_BDF_ID:
  786. sys_info->value = adev->pdev->devfn | (adev->pdev->bus->number << 8);
  787. break;
  788. case CGS_SYSTEM_INFO_PCIE_GEN_INFO:
  789. sys_info->value = adev->pm.pcie_gen_mask;
  790. break;
  791. case CGS_SYSTEM_INFO_PCIE_MLW:
  792. sys_info->value = adev->pm.pcie_mlw_mask;
  793. break;
  794. case CGS_SYSTEM_INFO_PCIE_DEV:
  795. sys_info->value = adev->pdev->device;
  796. break;
  797. case CGS_SYSTEM_INFO_PCIE_REV:
  798. sys_info->value = adev->pdev->revision;
  799. break;
  800. case CGS_SYSTEM_INFO_CG_FLAGS:
  801. sys_info->value = adev->cg_flags;
  802. break;
  803. case CGS_SYSTEM_INFO_PG_FLAGS:
  804. sys_info->value = adev->pg_flags;
  805. break;
  806. case CGS_SYSTEM_INFO_GFX_CU_INFO:
  807. sys_info->value = adev->gfx.cu_info.number;
  808. break;
  809. case CGS_SYSTEM_INFO_GFX_SE_INFO:
  810. sys_info->value = adev->gfx.config.max_shader_engines;
  811. break;
  812. case CGS_SYSTEM_INFO_PCIE_SUB_SYS_ID:
  813. sys_info->value = adev->pdev->subsystem_device;
  814. break;
  815. case CGS_SYSTEM_INFO_PCIE_SUB_SYS_VENDOR_ID:
  816. sys_info->value = adev->pdev->subsystem_vendor;
  817. break;
  818. case CGS_SYSTEM_INFO_PCIE_BUS_DEVFN:
  819. sys_info->value = adev->pdev->devfn;
  820. break;
  821. default:
  822. return -ENODEV;
  823. }
  824. return 0;
  825. }
  826. static int amdgpu_cgs_get_active_displays_info(struct cgs_device *cgs_device,
  827. struct cgs_display_info *info)
  828. {
  829. CGS_FUNC_ADEV;
  830. struct cgs_mode_info *mode_info;
  831. if (info == NULL)
  832. return -EINVAL;
  833. mode_info = info->mode_info;
  834. if (mode_info) {
  835. /* if the displays are off, vblank time is max */
  836. mode_info->vblank_time_us = 0xffffffff;
  837. /* always set the reference clock */
  838. mode_info->ref_clock = adev->clock.spll.reference_freq;
  839. }
  840. if (!amdgpu_device_has_dc_support(adev)) {
  841. struct amdgpu_crtc *amdgpu_crtc;
  842. struct drm_device *ddev = adev->ddev;
  843. struct drm_crtc *crtc;
  844. uint32_t line_time_us, vblank_lines;
  845. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  846. list_for_each_entry(crtc,
  847. &ddev->mode_config.crtc_list, head) {
  848. amdgpu_crtc = to_amdgpu_crtc(crtc);
  849. if (crtc->enabled) {
  850. info->active_display_mask |= (1 << amdgpu_crtc->crtc_id);
  851. info->display_count++;
  852. }
  853. if (mode_info != NULL &&
  854. crtc->enabled && amdgpu_crtc->enabled &&
  855. amdgpu_crtc->hw_mode.clock) {
  856. line_time_us = (amdgpu_crtc->hw_mode.crtc_htotal * 1000) /
  857. amdgpu_crtc->hw_mode.clock;
  858. vblank_lines = amdgpu_crtc->hw_mode.crtc_vblank_end -
  859. amdgpu_crtc->hw_mode.crtc_vdisplay +
  860. (amdgpu_crtc->v_border * 2);
  861. mode_info->vblank_time_us = vblank_lines * line_time_us;
  862. mode_info->refresh_rate = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
  863. mode_info = NULL;
  864. }
  865. }
  866. }
  867. } else {
  868. info->display_count = adev->pm.pm_display_cfg.num_display;
  869. if (mode_info != NULL) {
  870. mode_info->vblank_time_us = adev->pm.pm_display_cfg.min_vblank_time;
  871. mode_info->refresh_rate = adev->pm.pm_display_cfg.vrefresh;
  872. }
  873. }
  874. return 0;
  875. }
  876. static int amdgpu_cgs_notify_dpm_enabled(struct cgs_device *cgs_device, bool enabled)
  877. {
  878. CGS_FUNC_ADEV;
  879. adev->pm.dpm_enabled = enabled;
  880. return 0;
  881. }
  882. /** \brief evaluate acpi namespace object, handle or pathname must be valid
  883. * \param cgs_device
  884. * \param info input/output arguments for the control method
  885. * \return status
  886. */
  887. #if defined(CONFIG_ACPI)
  888. static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
  889. struct cgs_acpi_method_info *info)
  890. {
  891. CGS_FUNC_ADEV;
  892. acpi_handle handle;
  893. struct acpi_object_list input;
  894. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  895. union acpi_object *params, *obj;
  896. uint8_t name[5] = {'\0'};
  897. struct cgs_acpi_method_argument *argument;
  898. uint32_t i, count;
  899. acpi_status status;
  900. int result;
  901. handle = ACPI_HANDLE(&adev->pdev->dev);
  902. if (!handle)
  903. return -ENODEV;
  904. memset(&input, 0, sizeof(struct acpi_object_list));
  905. /* validate input info */
  906. if (info->size != sizeof(struct cgs_acpi_method_info))
  907. return -EINVAL;
  908. input.count = info->input_count;
  909. if (info->input_count > 0) {
  910. if (info->pinput_argument == NULL)
  911. return -EINVAL;
  912. argument = info->pinput_argument;
  913. for (i = 0; i < info->input_count; i++) {
  914. if (((argument->type == ACPI_TYPE_STRING) ||
  915. (argument->type == ACPI_TYPE_BUFFER)) &&
  916. (argument->pointer == NULL))
  917. return -EINVAL;
  918. argument++;
  919. }
  920. }
  921. if (info->output_count > 0) {
  922. if (info->poutput_argument == NULL)
  923. return -EINVAL;
  924. argument = info->poutput_argument;
  925. for (i = 0; i < info->output_count; i++) {
  926. if (((argument->type == ACPI_TYPE_STRING) ||
  927. (argument->type == ACPI_TYPE_BUFFER))
  928. && (argument->pointer == NULL))
  929. return -EINVAL;
  930. argument++;
  931. }
  932. }
  933. /* The path name passed to acpi_evaluate_object should be null terminated */
  934. if ((info->field & CGS_ACPI_FIELD_METHOD_NAME) != 0) {
  935. strncpy(name, (char *)&(info->name), sizeof(uint32_t));
  936. name[4] = '\0';
  937. }
  938. /* parse input parameters */
  939. if (input.count > 0) {
  940. input.pointer = params =
  941. kzalloc(sizeof(union acpi_object) * input.count, GFP_KERNEL);
  942. if (params == NULL)
  943. return -EINVAL;
  944. argument = info->pinput_argument;
  945. for (i = 0; i < input.count; i++) {
  946. params->type = argument->type;
  947. switch (params->type) {
  948. case ACPI_TYPE_INTEGER:
  949. params->integer.value = argument->value;
  950. break;
  951. case ACPI_TYPE_STRING:
  952. params->string.length = argument->data_length;
  953. params->string.pointer = argument->pointer;
  954. break;
  955. case ACPI_TYPE_BUFFER:
  956. params->buffer.length = argument->data_length;
  957. params->buffer.pointer = argument->pointer;
  958. break;
  959. default:
  960. break;
  961. }
  962. params++;
  963. argument++;
  964. }
  965. }
  966. /* parse output info */
  967. count = info->output_count;
  968. argument = info->poutput_argument;
  969. /* evaluate the acpi method */
  970. status = acpi_evaluate_object(handle, name, &input, &output);
  971. if (ACPI_FAILURE(status)) {
  972. result = -EIO;
  973. goto free_input;
  974. }
  975. /* return the output info */
  976. obj = output.pointer;
  977. if (count > 1) {
  978. if ((obj->type != ACPI_TYPE_PACKAGE) ||
  979. (obj->package.count != count)) {
  980. result = -EIO;
  981. goto free_obj;
  982. }
  983. params = obj->package.elements;
  984. } else
  985. params = obj;
  986. if (params == NULL) {
  987. result = -EIO;
  988. goto free_obj;
  989. }
  990. for (i = 0; i < count; i++) {
  991. if (argument->type != params->type) {
  992. result = -EIO;
  993. goto free_obj;
  994. }
  995. switch (params->type) {
  996. case ACPI_TYPE_INTEGER:
  997. argument->value = params->integer.value;
  998. break;
  999. case ACPI_TYPE_STRING:
  1000. if ((params->string.length != argument->data_length) ||
  1001. (params->string.pointer == NULL)) {
  1002. result = -EIO;
  1003. goto free_obj;
  1004. }
  1005. strncpy(argument->pointer,
  1006. params->string.pointer,
  1007. params->string.length);
  1008. break;
  1009. case ACPI_TYPE_BUFFER:
  1010. if (params->buffer.pointer == NULL) {
  1011. result = -EIO;
  1012. goto free_obj;
  1013. }
  1014. memcpy(argument->pointer,
  1015. params->buffer.pointer,
  1016. argument->data_length);
  1017. break;
  1018. default:
  1019. break;
  1020. }
  1021. argument++;
  1022. params++;
  1023. }
  1024. result = 0;
  1025. free_obj:
  1026. kfree(obj);
  1027. free_input:
  1028. kfree((void *)input.pointer);
  1029. return result;
  1030. }
  1031. #else
  1032. static int amdgpu_cgs_acpi_eval_object(struct cgs_device *cgs_device,
  1033. struct cgs_acpi_method_info *info)
  1034. {
  1035. return -EIO;
  1036. }
  1037. #endif
  1038. static int amdgpu_cgs_call_acpi_method(struct cgs_device *cgs_device,
  1039. uint32_t acpi_method,
  1040. uint32_t acpi_function,
  1041. void *pinput, void *poutput,
  1042. uint32_t output_count,
  1043. uint32_t input_size,
  1044. uint32_t output_size)
  1045. {
  1046. struct cgs_acpi_method_argument acpi_input[2] = { {0}, {0} };
  1047. struct cgs_acpi_method_argument acpi_output = {0};
  1048. struct cgs_acpi_method_info info = {0};
  1049. acpi_input[0].type = CGS_ACPI_TYPE_INTEGER;
  1050. acpi_input[0].data_length = sizeof(uint32_t);
  1051. acpi_input[0].value = acpi_function;
  1052. acpi_input[1].type = CGS_ACPI_TYPE_BUFFER;
  1053. acpi_input[1].data_length = input_size;
  1054. acpi_input[1].pointer = pinput;
  1055. acpi_output.type = CGS_ACPI_TYPE_BUFFER;
  1056. acpi_output.data_length = output_size;
  1057. acpi_output.pointer = poutput;
  1058. info.size = sizeof(struct cgs_acpi_method_info);
  1059. info.field = CGS_ACPI_FIELD_METHOD_NAME | CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT;
  1060. info.input_count = 2;
  1061. info.name = acpi_method;
  1062. info.pinput_argument = acpi_input;
  1063. info.output_count = output_count;
  1064. info.poutput_argument = &acpi_output;
  1065. return amdgpu_cgs_acpi_eval_object(cgs_device, &info);
  1066. }
  1067. static const struct cgs_ops amdgpu_cgs_ops = {
  1068. .alloc_gpu_mem = amdgpu_cgs_alloc_gpu_mem,
  1069. .free_gpu_mem = amdgpu_cgs_free_gpu_mem,
  1070. .gmap_gpu_mem = amdgpu_cgs_gmap_gpu_mem,
  1071. .gunmap_gpu_mem = amdgpu_cgs_gunmap_gpu_mem,
  1072. .kmap_gpu_mem = amdgpu_cgs_kmap_gpu_mem,
  1073. .kunmap_gpu_mem = amdgpu_cgs_kunmap_gpu_mem,
  1074. .read_register = amdgpu_cgs_read_register,
  1075. .write_register = amdgpu_cgs_write_register,
  1076. .read_ind_register = amdgpu_cgs_read_ind_register,
  1077. .write_ind_register = amdgpu_cgs_write_ind_register,
  1078. .get_pci_resource = amdgpu_cgs_get_pci_resource,
  1079. .atom_get_data_table = amdgpu_cgs_atom_get_data_table,
  1080. .atom_get_cmd_table_revs = amdgpu_cgs_atom_get_cmd_table_revs,
  1081. .atom_exec_cmd_table = amdgpu_cgs_atom_exec_cmd_table,
  1082. .get_firmware_info = amdgpu_cgs_get_firmware_info,
  1083. .rel_firmware = amdgpu_cgs_rel_firmware,
  1084. .set_powergating_state = amdgpu_cgs_set_powergating_state,
  1085. .set_clockgating_state = amdgpu_cgs_set_clockgating_state,
  1086. .get_active_displays_info = amdgpu_cgs_get_active_displays_info,
  1087. .notify_dpm_enabled = amdgpu_cgs_notify_dpm_enabled,
  1088. .call_acpi_method = amdgpu_cgs_call_acpi_method,
  1089. .query_system_info = amdgpu_cgs_query_system_info,
  1090. .is_virtualization_enabled = amdgpu_cgs_is_virtualization_enabled,
  1091. .enter_safe_mode = amdgpu_cgs_enter_safe_mode,
  1092. .lock_grbm_idx = amdgpu_cgs_lock_grbm_idx,
  1093. .register_pp_handle = amdgpu_cgs_register_pp_handle,
  1094. };
  1095. static const struct cgs_os_ops amdgpu_cgs_os_ops = {
  1096. .add_irq_source = amdgpu_cgs_add_irq_source,
  1097. .irq_get = amdgpu_cgs_irq_get,
  1098. .irq_put = amdgpu_cgs_irq_put
  1099. };
  1100. struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev)
  1101. {
  1102. struct amdgpu_cgs_device *cgs_device =
  1103. kmalloc(sizeof(*cgs_device), GFP_KERNEL);
  1104. if (!cgs_device) {
  1105. DRM_ERROR("Couldn't allocate CGS device structure\n");
  1106. return NULL;
  1107. }
  1108. cgs_device->base.ops = &amdgpu_cgs_ops;
  1109. cgs_device->base.os_ops = &amdgpu_cgs_os_ops;
  1110. cgs_device->adev = adev;
  1111. return (struct cgs_device *)cgs_device;
  1112. }
  1113. void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device)
  1114. {
  1115. kfree(cgs_device);
  1116. }