cgs_common.h 24 KB

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