cgs_common.h 25 KB

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