cgs_common.h 25 KB

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