amdgpu_cgs.c 31 KB

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