cgs_common.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. #ifndef _CGS_COMMON_H
  25. #define _CGS_COMMON_H
  26. #include "amd_shared.h"
  27. /**
  28. * enum cgs_gpu_mem_type - GPU memory types
  29. */
  30. enum cgs_gpu_mem_type {
  31. CGS_GPU_MEM_TYPE__VISIBLE_FB,
  32. CGS_GPU_MEM_TYPE__INVISIBLE_FB,
  33. CGS_GPU_MEM_TYPE__VISIBLE_CONTIG_FB,
  34. CGS_GPU_MEM_TYPE__INVISIBLE_CONTIG_FB,
  35. CGS_GPU_MEM_TYPE__GART_CACHEABLE,
  36. CGS_GPU_MEM_TYPE__GART_WRITECOMBINE
  37. };
  38. /**
  39. * enum cgs_ind_reg - Indirect register spaces
  40. */
  41. enum cgs_ind_reg {
  42. CGS_IND_REG__MMIO,
  43. CGS_IND_REG__PCIE,
  44. CGS_IND_REG__SMC,
  45. CGS_IND_REG__UVD_CTX,
  46. CGS_IND_REG__DIDT,
  47. CGS_IND_REG__AUDIO_ENDPT
  48. };
  49. /**
  50. * enum cgs_clock - Clocks controlled by the SMU
  51. */
  52. enum cgs_clock {
  53. CGS_CLOCK__SCLK,
  54. CGS_CLOCK__MCLK,
  55. CGS_CLOCK__VCLK,
  56. CGS_CLOCK__DCLK,
  57. CGS_CLOCK__ECLK,
  58. CGS_CLOCK__ACLK,
  59. CGS_CLOCK__ICLK,
  60. /* ... */
  61. };
  62. /**
  63. * enum cgs_engine - Engines that can be statically power-gated
  64. */
  65. enum cgs_engine {
  66. CGS_ENGINE__UVD,
  67. CGS_ENGINE__VCE,
  68. CGS_ENGINE__VP8,
  69. CGS_ENGINE__ACP_DMA,
  70. CGS_ENGINE__ACP_DSP0,
  71. CGS_ENGINE__ACP_DSP1,
  72. CGS_ENGINE__ISP,
  73. /* ... */
  74. };
  75. /**
  76. * enum cgs_voltage_planes - Voltage planes for external camera HW
  77. */
  78. enum cgs_voltage_planes {
  79. CGS_VOLTAGE_PLANE__SENSOR0,
  80. CGS_VOLTAGE_PLANE__SENSOR1,
  81. /* ... */
  82. };
  83. /*
  84. * enum cgs_ucode_id - Firmware types for different IPs
  85. */
  86. enum cgs_ucode_id {
  87. CGS_UCODE_ID_SMU = 0,
  88. CGS_UCODE_ID_SDMA0,
  89. CGS_UCODE_ID_SDMA1,
  90. CGS_UCODE_ID_CP_CE,
  91. CGS_UCODE_ID_CP_PFP,
  92. CGS_UCODE_ID_CP_ME,
  93. CGS_UCODE_ID_CP_MEC,
  94. CGS_UCODE_ID_CP_MEC_JT1,
  95. CGS_UCODE_ID_CP_MEC_JT2,
  96. CGS_UCODE_ID_GMCON_RENG,
  97. CGS_UCODE_ID_RLC_G,
  98. CGS_UCODE_ID_MAXIMUM,
  99. };
  100. enum cgs_system_info_id {
  101. CGS_SYSTEM_INFO_ADAPTER_BDF_ID = 1,
  102. CGS_SYSTEM_INFO_PCIE_GEN_INFO,
  103. CGS_SYSTEM_INFO_PCIE_MLW,
  104. CGS_SYSTEM_INFO_CG_FLAGS,
  105. CGS_SYSTEM_INFO_PG_FLAGS,
  106. CGS_SYSTEM_INFO_ID_MAXIMUM,
  107. };
  108. struct cgs_system_info {
  109. uint64_t size;
  110. uint64_t info_id;
  111. union {
  112. void *ptr;
  113. uint64_t value;
  114. };
  115. uint64_t padding[13];
  116. };
  117. /*
  118. * enum cgs_resource_type - GPU resource type
  119. */
  120. enum cgs_resource_type {
  121. CGS_RESOURCE_TYPE_MMIO = 0,
  122. CGS_RESOURCE_TYPE_FB,
  123. CGS_RESOURCE_TYPE_IO,
  124. CGS_RESOURCE_TYPE_DOORBELL,
  125. CGS_RESOURCE_TYPE_ROM,
  126. };
  127. /**
  128. * struct cgs_clock_limits - Clock limits
  129. *
  130. * Clocks are specified in 10KHz units.
  131. */
  132. struct cgs_clock_limits {
  133. unsigned min; /**< Minimum supported frequency */
  134. unsigned max; /**< Maxumim supported frequency */
  135. unsigned sustainable; /**< Thermally sustainable frequency */
  136. };
  137. /**
  138. * struct cgs_firmware_info - Firmware information
  139. */
  140. struct cgs_firmware_info {
  141. uint16_t version;
  142. uint16_t feature_version;
  143. uint32_t image_size;
  144. uint64_t mc_addr;
  145. void *kptr;
  146. };
  147. struct cgs_mode_info {
  148. uint32_t refresh_rate;
  149. uint32_t ref_clock;
  150. uint32_t vblank_time_us;
  151. };
  152. struct cgs_display_info {
  153. uint32_t display_count;
  154. uint32_t active_display_mask;
  155. struct cgs_mode_info *mode_info;
  156. };
  157. typedef unsigned long cgs_handle_t;
  158. #define CGS_ACPI_METHOD_ATCS 0x53435441
  159. #define CGS_ACPI_METHOD_ATIF 0x46495441
  160. #define CGS_ACPI_METHOD_ATPX 0x58505441
  161. #define CGS_ACPI_FIELD_METHOD_NAME 0x00000001
  162. #define CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT 0x00000002
  163. #define CGS_ACPI_MAX_BUFFER_SIZE 256
  164. #define CGS_ACPI_TYPE_ANY 0x00
  165. #define CGS_ACPI_TYPE_INTEGER 0x01
  166. #define CGS_ACPI_TYPE_STRING 0x02
  167. #define CGS_ACPI_TYPE_BUFFER 0x03
  168. #define CGS_ACPI_TYPE_PACKAGE 0x04
  169. struct cgs_acpi_method_argument {
  170. uint32_t type;
  171. uint32_t method_length;
  172. uint32_t data_length;
  173. union{
  174. uint32_t value;
  175. void *pointer;
  176. };
  177. };
  178. struct cgs_acpi_method_info {
  179. uint32_t size;
  180. uint32_t field;
  181. uint32_t input_count;
  182. uint32_t name;
  183. struct cgs_acpi_method_argument *pinput_argument;
  184. uint32_t output_count;
  185. struct cgs_acpi_method_argument *poutput_argument;
  186. uint32_t padding[9];
  187. };
  188. /**
  189. * cgs_gpu_mem_info() - Return information about memory heaps
  190. * @cgs_device: opaque device handle
  191. * @type: memory type
  192. * @mc_start: Start MC address of the heap (output)
  193. * @mc_size: MC address space size (output)
  194. * @mem_size: maximum amount of memory available for allocation (output)
  195. *
  196. * This function returns information about memory heaps. The type
  197. * parameter is used to select the memory heap. The mc_start and
  198. * mc_size for GART heaps may be bigger than the memory available for
  199. * allocation.
  200. *
  201. * mc_start and mc_size are undefined for non-contiguous FB memory
  202. * types, since buffers allocated with these types may or may not be
  203. * GART mapped.
  204. *
  205. * Return: 0 on success, -errno otherwise
  206. */
  207. typedef int (*cgs_gpu_mem_info_t)(void *cgs_device, enum cgs_gpu_mem_type type,
  208. uint64_t *mc_start, uint64_t *mc_size,
  209. uint64_t *mem_size);
  210. /**
  211. * cgs_gmap_kmem() - map kernel memory to GART aperture
  212. * @cgs_device: opaque device handle
  213. * @kmem: pointer to kernel memory
  214. * @size: size to map
  215. * @min_offset: minimum offset from start of GART aperture
  216. * @max_offset: maximum offset from start of GART aperture
  217. * @kmem_handle: kernel memory handle (output)
  218. * @mcaddr: MC address (output)
  219. *
  220. * Return: 0 on success, -errno otherwise
  221. */
  222. typedef int (*cgs_gmap_kmem_t)(void *cgs_device, void *kmem, uint64_t size,
  223. uint64_t min_offset, uint64_t max_offset,
  224. cgs_handle_t *kmem_handle, uint64_t *mcaddr);
  225. /**
  226. * cgs_gunmap_kmem() - unmap kernel memory
  227. * @cgs_device: opaque device handle
  228. * @kmem_handle: kernel memory handle returned by gmap_kmem
  229. *
  230. * Return: 0 on success, -errno otherwise
  231. */
  232. typedef int (*cgs_gunmap_kmem_t)(void *cgs_device, cgs_handle_t kmem_handle);
  233. /**
  234. * cgs_alloc_gpu_mem() - Allocate GPU memory
  235. * @cgs_device: opaque device handle
  236. * @type: memory type
  237. * @size: size in bytes
  238. * @align: alignment in bytes
  239. * @min_offset: minimum offset from start of heap
  240. * @max_offset: maximum offset from start of heap
  241. * @handle: memory handle (output)
  242. *
  243. * The memory types CGS_GPU_MEM_TYPE_*_CONTIG_FB force contiguous
  244. * memory allocation. This guarantees that the MC address returned by
  245. * cgs_gmap_gpu_mem is not mapped through the GART. The non-contiguous
  246. * FB memory types may be GART mapped depending on memory
  247. * fragmentation and memory allocator policies.
  248. *
  249. * If min/max_offset are non-0, the allocation will be forced to
  250. * reside between these offsets in its respective memory heap. The
  251. * base address that the offset relates to, depends on the memory
  252. * type.
  253. *
  254. * - CGS_GPU_MEM_TYPE__*_CONTIG_FB: FB MC base address
  255. * - CGS_GPU_MEM_TYPE__GART_*: GART aperture base address
  256. * - others: undefined, don't use with max_offset
  257. *
  258. * Return: 0 on success, -errno otherwise
  259. */
  260. typedef int (*cgs_alloc_gpu_mem_t)(void *cgs_device, enum cgs_gpu_mem_type type,
  261. uint64_t size, uint64_t align,
  262. uint64_t min_offset, uint64_t max_offset,
  263. cgs_handle_t *handle);
  264. /**
  265. * cgs_free_gpu_mem() - Free GPU memory
  266. * @cgs_device: opaque device handle
  267. * @handle: memory handle returned by alloc or import
  268. *
  269. * Return: 0 on success, -errno otherwise
  270. */
  271. typedef int (*cgs_free_gpu_mem_t)(void *cgs_device, cgs_handle_t handle);
  272. /**
  273. * cgs_gmap_gpu_mem() - GPU-map GPU memory
  274. * @cgs_device: opaque device handle
  275. * @handle: memory handle returned by alloc or import
  276. * @mcaddr: MC address (output)
  277. *
  278. * Ensures that a buffer is GPU accessible and returns its MC address.
  279. *
  280. * Return: 0 on success, -errno otherwise
  281. */
  282. typedef int (*cgs_gmap_gpu_mem_t)(void *cgs_device, cgs_handle_t handle,
  283. uint64_t *mcaddr);
  284. /**
  285. * cgs_gunmap_gpu_mem() - GPU-unmap GPU memory
  286. * @cgs_device: opaque device handle
  287. * @handle: memory handle returned by alloc or import
  288. *
  289. * Allows the buffer to be migrated while it's not used by the GPU.
  290. *
  291. * Return: 0 on success, -errno otherwise
  292. */
  293. typedef int (*cgs_gunmap_gpu_mem_t)(void *cgs_device, cgs_handle_t handle);
  294. /**
  295. * cgs_kmap_gpu_mem() - Kernel-map GPU memory
  296. *
  297. * @cgs_device: opaque device handle
  298. * @handle: memory handle returned by alloc or import
  299. * @map: Kernel virtual address the memory was mapped to (output)
  300. *
  301. * Return: 0 on success, -errno otherwise
  302. */
  303. typedef int (*cgs_kmap_gpu_mem_t)(void *cgs_device, cgs_handle_t handle,
  304. void **map);
  305. /**
  306. * cgs_kunmap_gpu_mem() - Kernel-unmap GPU memory
  307. * @cgs_device: opaque device handle
  308. * @handle: memory handle returned by alloc or import
  309. *
  310. * Return: 0 on success, -errno otherwise
  311. */
  312. typedef int (*cgs_kunmap_gpu_mem_t)(void *cgs_device, cgs_handle_t handle);
  313. /**
  314. * cgs_read_register() - Read an MMIO register
  315. * @cgs_device: opaque device handle
  316. * @offset: register offset
  317. *
  318. * Return: register value
  319. */
  320. typedef uint32_t (*cgs_read_register_t)(void *cgs_device, unsigned offset);
  321. /**
  322. * cgs_write_register() - Write an MMIO register
  323. * @cgs_device: opaque device handle
  324. * @offset: register offset
  325. * @value: register value
  326. */
  327. typedef void (*cgs_write_register_t)(void *cgs_device, unsigned offset,
  328. uint32_t value);
  329. /**
  330. * cgs_read_ind_register() - Read an indirect register
  331. * @cgs_device: opaque device handle
  332. * @offset: register offset
  333. *
  334. * Return: register value
  335. */
  336. typedef uint32_t (*cgs_read_ind_register_t)(void *cgs_device, enum cgs_ind_reg space,
  337. unsigned index);
  338. /**
  339. * cgs_write_ind_register() - Write an indirect register
  340. * @cgs_device: opaque device handle
  341. * @offset: register offset
  342. * @value: register value
  343. */
  344. typedef void (*cgs_write_ind_register_t)(void *cgs_device, enum cgs_ind_reg space,
  345. unsigned index, uint32_t value);
  346. /**
  347. * cgs_read_pci_config_byte() - Read byte from PCI configuration space
  348. * @cgs_device: opaque device handle
  349. * @addr: address
  350. *
  351. * Return: Value read
  352. */
  353. typedef uint8_t (*cgs_read_pci_config_byte_t)(void *cgs_device, unsigned addr);
  354. /**
  355. * cgs_read_pci_config_word() - Read word from PCI configuration space
  356. * @cgs_device: opaque device handle
  357. * @addr: address, must be word-aligned
  358. *
  359. * Return: Value read
  360. */
  361. typedef uint16_t (*cgs_read_pci_config_word_t)(void *cgs_device, unsigned addr);
  362. /**
  363. * cgs_read_pci_config_dword() - Read dword from PCI configuration space
  364. * @cgs_device: opaque device handle
  365. * @addr: address, must be dword-aligned
  366. *
  367. * Return: Value read
  368. */
  369. typedef uint32_t (*cgs_read_pci_config_dword_t)(void *cgs_device,
  370. unsigned addr);
  371. /**
  372. * cgs_write_pci_config_byte() - Write byte to PCI configuration space
  373. * @cgs_device: opaque device handle
  374. * @addr: address
  375. * @value: value to write
  376. */
  377. typedef void (*cgs_write_pci_config_byte_t)(void *cgs_device, unsigned addr,
  378. uint8_t value);
  379. /**
  380. * cgs_write_pci_config_word() - Write byte to PCI configuration space
  381. * @cgs_device: opaque device handle
  382. * @addr: address, must be word-aligned
  383. * @value: value to write
  384. */
  385. typedef void (*cgs_write_pci_config_word_t)(void *cgs_device, unsigned addr,
  386. uint16_t value);
  387. /**
  388. * cgs_write_pci_config_dword() - Write byte to PCI configuration space
  389. * @cgs_device: opaque device handle
  390. * @addr: address, must be dword-aligned
  391. * @value: value to write
  392. */
  393. typedef void (*cgs_write_pci_config_dword_t)(void *cgs_device, unsigned addr,
  394. uint32_t value);
  395. /**
  396. * cgs_get_pci_resource() - provide access to a device resource (PCI BAR)
  397. * @cgs_device: opaque device handle
  398. * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL)
  399. * @size: size of the region
  400. * @offset: offset from the start of the region
  401. * @resource_base: base address (not including offset) returned
  402. *
  403. * Return: 0 on success, -errno otherwise
  404. */
  405. typedef int (*cgs_get_pci_resource_t)(void *cgs_device,
  406. enum cgs_resource_type resource_type,
  407. uint64_t size,
  408. uint64_t offset,
  409. uint64_t *resource_base);
  410. /**
  411. * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table
  412. * @cgs_device: opaque device handle
  413. * @table: data table index
  414. * @size: size of the table (output, may be NULL)
  415. * @frev: table format revision (output, may be NULL)
  416. * @crev: table content revision (output, may be NULL)
  417. *
  418. * Return: Pointer to start of the table, or NULL on failure
  419. */
  420. typedef const void *(*cgs_atom_get_data_table_t)(
  421. void *cgs_device, unsigned table,
  422. uint16_t *size, uint8_t *frev, uint8_t *crev);
  423. /**
  424. * cgs_atom_get_cmd_table_revs() - Get ATOM BIOS command table revisions
  425. * @cgs_device: opaque device handle
  426. * @table: data table index
  427. * @frev: table format revision (output, may be NULL)
  428. * @crev: table content revision (output, may be NULL)
  429. *
  430. * Return: 0 on success, -errno otherwise
  431. */
  432. typedef int (*cgs_atom_get_cmd_table_revs_t)(void *cgs_device, unsigned table,
  433. uint8_t *frev, uint8_t *crev);
  434. /**
  435. * cgs_atom_exec_cmd_table() - Execute an ATOM BIOS command table
  436. * @cgs_device: opaque device handle
  437. * @table: command table index
  438. * @args: arguments
  439. *
  440. * Return: 0 on success, -errno otherwise
  441. */
  442. typedef int (*cgs_atom_exec_cmd_table_t)(void *cgs_device,
  443. unsigned table, void *args);
  444. /**
  445. * cgs_create_pm_request() - Create a power management request
  446. * @cgs_device: opaque device handle
  447. * @request: handle of created PM request (output)
  448. *
  449. * Return: 0 on success, -errno otherwise
  450. */
  451. typedef int (*cgs_create_pm_request_t)(void *cgs_device, cgs_handle_t *request);
  452. /**
  453. * cgs_destroy_pm_request() - Destroy a power management request
  454. * @cgs_device: opaque device handle
  455. * @request: handle of created PM request
  456. *
  457. * Return: 0 on success, -errno otherwise
  458. */
  459. typedef int (*cgs_destroy_pm_request_t)(void *cgs_device, cgs_handle_t request);
  460. /**
  461. * cgs_set_pm_request() - Activate or deactiveate a PM request
  462. * @cgs_device: opaque device handle
  463. * @request: PM request handle
  464. * @active: 0 = deactivate, non-0 = activate
  465. *
  466. * While a PM request is active, its minimum clock requests are taken
  467. * into account as the requested engines are powered up. When the
  468. * request is inactive, the engines may be powered down and clocks may
  469. * be lower, depending on other PM requests by other driver
  470. * components.
  471. *
  472. * Return: 0 on success, -errno otherwise
  473. */
  474. typedef int (*cgs_set_pm_request_t)(void *cgs_device, cgs_handle_t request,
  475. int active);
  476. /**
  477. * cgs_pm_request_clock() - Request a minimum frequency for a specific clock
  478. * @cgs_device: opaque device handle
  479. * @request: PM request handle
  480. * @clock: which clock?
  481. * @freq: requested min. frequency in 10KHz units (0 to clear request)
  482. *
  483. * Return: 0 on success, -errno otherwise
  484. */
  485. typedef int (*cgs_pm_request_clock_t)(void *cgs_device, cgs_handle_t request,
  486. enum cgs_clock clock, unsigned freq);
  487. /**
  488. * cgs_pm_request_engine() - Request an engine to be powered up
  489. * @cgs_device: opaque device handle
  490. * @request: PM request handle
  491. * @engine: which engine?
  492. * @powered: 0 = powered down, non-0 = powered up
  493. *
  494. * Return: 0 on success, -errno otherwise
  495. */
  496. typedef int (*cgs_pm_request_engine_t)(void *cgs_device, cgs_handle_t request,
  497. enum cgs_engine engine, int powered);
  498. /**
  499. * cgs_pm_query_clock_limits() - Query clock frequency limits
  500. * @cgs_device: opaque device handle
  501. * @clock: which clock?
  502. * @limits: clock limits
  503. *
  504. * Return: 0 on success, -errno otherwise
  505. */
  506. typedef int (*cgs_pm_query_clock_limits_t)(void *cgs_device,
  507. enum cgs_clock clock,
  508. struct cgs_clock_limits *limits);
  509. /**
  510. * cgs_set_camera_voltages() - Apply specific voltages to PMIC voltage planes
  511. * @cgs_device: opaque device handle
  512. * @mask: bitmask of voltages to change (1<<CGS_VOLTAGE_PLANE__xyz|...)
  513. * @voltages: pointer to array of voltage values in 1mV units
  514. *
  515. * Return: 0 on success, -errno otherwise
  516. */
  517. typedef int (*cgs_set_camera_voltages_t)(void *cgs_device, uint32_t mask,
  518. const uint32_t *voltages);
  519. /**
  520. * cgs_get_firmware_info - Get the firmware information from core driver
  521. * @cgs_device: opaque device handle
  522. * @type: the firmware type
  523. * @info: returend firmware information
  524. *
  525. * Return: 0 on success, -errno otherwise
  526. */
  527. typedef int (*cgs_get_firmware_info)(void *cgs_device,
  528. enum cgs_ucode_id type,
  529. struct cgs_firmware_info *info);
  530. typedef int(*cgs_set_powergating_state)(void *cgs_device,
  531. enum amd_ip_block_type block_type,
  532. enum amd_powergating_state state);
  533. typedef int(*cgs_set_clockgating_state)(void *cgs_device,
  534. enum amd_ip_block_type block_type,
  535. enum amd_clockgating_state state);
  536. typedef int(*cgs_get_active_displays_info)(
  537. void *cgs_device,
  538. struct cgs_display_info *info);
  539. typedef int (*cgs_call_acpi_method)(void *cgs_device,
  540. uint32_t acpi_method,
  541. uint32_t acpi_function,
  542. void *pinput, void *poutput,
  543. uint32_t output_count,
  544. uint32_t input_size,
  545. uint32_t output_size);
  546. typedef int (*cgs_query_system_info)(void *cgs_device,
  547. struct cgs_system_info *sys_info);
  548. struct cgs_ops {
  549. /* memory management calls (similar to KFD interface) */
  550. cgs_gpu_mem_info_t gpu_mem_info;
  551. cgs_gmap_kmem_t gmap_kmem;
  552. cgs_gunmap_kmem_t gunmap_kmem;
  553. cgs_alloc_gpu_mem_t alloc_gpu_mem;
  554. cgs_free_gpu_mem_t free_gpu_mem;
  555. cgs_gmap_gpu_mem_t gmap_gpu_mem;
  556. cgs_gunmap_gpu_mem_t gunmap_gpu_mem;
  557. cgs_kmap_gpu_mem_t kmap_gpu_mem;
  558. cgs_kunmap_gpu_mem_t kunmap_gpu_mem;
  559. /* MMIO access */
  560. cgs_read_register_t read_register;
  561. cgs_write_register_t write_register;
  562. cgs_read_ind_register_t read_ind_register;
  563. cgs_write_ind_register_t write_ind_register;
  564. /* PCI configuration space access */
  565. cgs_read_pci_config_byte_t read_pci_config_byte;
  566. cgs_read_pci_config_word_t read_pci_config_word;
  567. cgs_read_pci_config_dword_t read_pci_config_dword;
  568. cgs_write_pci_config_byte_t write_pci_config_byte;
  569. cgs_write_pci_config_word_t write_pci_config_word;
  570. cgs_write_pci_config_dword_t write_pci_config_dword;
  571. /* PCI resources */
  572. cgs_get_pci_resource_t get_pci_resource;
  573. /* ATOM BIOS */
  574. cgs_atom_get_data_table_t atom_get_data_table;
  575. cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs;
  576. cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
  577. /* Power management */
  578. cgs_create_pm_request_t create_pm_request;
  579. cgs_destroy_pm_request_t destroy_pm_request;
  580. cgs_set_pm_request_t set_pm_request;
  581. cgs_pm_request_clock_t pm_request_clock;
  582. cgs_pm_request_engine_t pm_request_engine;
  583. cgs_pm_query_clock_limits_t pm_query_clock_limits;
  584. cgs_set_camera_voltages_t set_camera_voltages;
  585. /* Firmware Info */
  586. cgs_get_firmware_info get_firmware_info;
  587. /* cg pg interface*/
  588. cgs_set_powergating_state set_powergating_state;
  589. cgs_set_clockgating_state set_clockgating_state;
  590. /* display manager */
  591. cgs_get_active_displays_info get_active_displays_info;
  592. /* ACPI */
  593. cgs_call_acpi_method call_acpi_method;
  594. /* get system info */
  595. cgs_query_system_info query_system_info;
  596. };
  597. struct cgs_os_ops; /* To be define in OS-specific CGS header */
  598. struct cgs_device
  599. {
  600. const struct cgs_ops *ops;
  601. const struct cgs_os_ops *os_ops;
  602. /* to be embedded at the start of driver private structure */
  603. };
  604. /* Convenience macros that make CGS indirect function calls look like
  605. * normal function calls */
  606. #define CGS_CALL(func,dev,...) \
  607. (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
  608. #define CGS_OS_CALL(func,dev,...) \
  609. (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
  610. #define cgs_gpu_mem_info(dev,type,mc_start,mc_size,mem_size) \
  611. CGS_CALL(gpu_mem_info,dev,type,mc_start,mc_size,mem_size)
  612. #define cgs_gmap_kmem(dev,kmem,size,min_off,max_off,kmem_handle,mcaddr) \
  613. CGS_CALL(gmap_kmem,dev,kmem,size,min_off,max_off,kmem_handle,mcaddr)
  614. #define cgs_gunmap_kmem(dev,kmem_handle) \
  615. CGS_CALL(gunmap_kmem,dev,keme_handle)
  616. #define cgs_alloc_gpu_mem(dev,type,size,align,min_off,max_off,handle) \
  617. CGS_CALL(alloc_gpu_mem,dev,type,size,align,min_off,max_off,handle)
  618. #define cgs_free_gpu_mem(dev,handle) \
  619. CGS_CALL(free_gpu_mem,dev,handle)
  620. #define cgs_gmap_gpu_mem(dev,handle,mcaddr) \
  621. CGS_CALL(gmap_gpu_mem,dev,handle,mcaddr)
  622. #define cgs_gunmap_gpu_mem(dev,handle) \
  623. CGS_CALL(gunmap_gpu_mem,dev,handle)
  624. #define cgs_kmap_gpu_mem(dev,handle,map) \
  625. CGS_CALL(kmap_gpu_mem,dev,handle,map)
  626. #define cgs_kunmap_gpu_mem(dev,handle) \
  627. CGS_CALL(kunmap_gpu_mem,dev,handle)
  628. #define cgs_read_register(dev,offset) \
  629. CGS_CALL(read_register,dev,offset)
  630. #define cgs_write_register(dev,offset,value) \
  631. CGS_CALL(write_register,dev,offset,value)
  632. #define cgs_read_ind_register(dev,space,index) \
  633. CGS_CALL(read_ind_register,dev,space,index)
  634. #define cgs_write_ind_register(dev,space,index,value) \
  635. CGS_CALL(write_ind_register,dev,space,index,value)
  636. #define cgs_read_pci_config_byte(dev,addr) \
  637. CGS_CALL(read_pci_config_byte,dev,addr)
  638. #define cgs_read_pci_config_word(dev,addr) \
  639. CGS_CALL(read_pci_config_word,dev,addr)
  640. #define cgs_read_pci_config_dword(dev,addr) \
  641. CGS_CALL(read_pci_config_dword,dev,addr)
  642. #define cgs_write_pci_config_byte(dev,addr,value) \
  643. CGS_CALL(write_pci_config_byte,dev,addr,value)
  644. #define cgs_write_pci_config_word(dev,addr,value) \
  645. CGS_CALL(write_pci_config_word,dev,addr,value)
  646. #define cgs_write_pci_config_dword(dev,addr,value) \
  647. CGS_CALL(write_pci_config_dword,dev,addr,value)
  648. #define cgs_atom_get_data_table(dev,table,size,frev,crev) \
  649. CGS_CALL(atom_get_data_table,dev,table,size,frev,crev)
  650. #define cgs_atom_get_cmd_table_revs(dev,table,frev,crev) \
  651. CGS_CALL(atom_get_cmd_table_revs,dev,table,frev,crev)
  652. #define cgs_atom_exec_cmd_table(dev,table,args) \
  653. CGS_CALL(atom_exec_cmd_table,dev,table,args)
  654. #define cgs_create_pm_request(dev,request) \
  655. CGS_CALL(create_pm_request,dev,request)
  656. #define cgs_destroy_pm_request(dev,request) \
  657. CGS_CALL(destroy_pm_request,dev,request)
  658. #define cgs_set_pm_request(dev,request,active) \
  659. CGS_CALL(set_pm_request,dev,request,active)
  660. #define cgs_pm_request_clock(dev,request,clock,freq) \
  661. CGS_CALL(pm_request_clock,dev,request,clock,freq)
  662. #define cgs_pm_request_engine(dev,request,engine,powered) \
  663. CGS_CALL(pm_request_engine,dev,request,engine,powered)
  664. #define cgs_pm_query_clock_limits(dev,clock,limits) \
  665. CGS_CALL(pm_query_clock_limits,dev,clock,limits)
  666. #define cgs_set_camera_voltages(dev,mask,voltages) \
  667. CGS_CALL(set_camera_voltages,dev,mask,voltages)
  668. #define cgs_get_firmware_info(dev, type, info) \
  669. CGS_CALL(get_firmware_info, dev, type, info)
  670. #define cgs_set_powergating_state(dev, block_type, state) \
  671. CGS_CALL(set_powergating_state, dev, block_type, state)
  672. #define cgs_set_clockgating_state(dev, block_type, state) \
  673. CGS_CALL(set_clockgating_state, dev, block_type, state)
  674. #define cgs_get_active_displays_info(dev, info) \
  675. CGS_CALL(get_active_displays_info, dev, info)
  676. #define cgs_call_acpi_method(dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size) \
  677. CGS_CALL(call_acpi_method, dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size)
  678. #define cgs_query_system_info(dev, sys_info) \
  679. CGS_CALL(query_system_info, dev, sys_info)
  680. #define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \
  681. resource_base) \
  682. CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
  683. resource_base)
  684. #endif /* _CGS_COMMON_H */