cgs_common.h 25 KB

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