blob: 6aa8938fd826f4510c71329c54f78a88fd5a913b [file] [log] [blame]
Chunming Zhoud03846a2015-07-28 14:20:03 -04001/*
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
rezhu404b2fa2015-08-07 13:37:56 +080027#include "amd_shared.h"
Jammy Zhoubf3911b02015-05-13 18:58:05 +080028
Dave Airlie110e6f22016-04-12 13:25:48 +100029struct cgs_device;
30
Chunming Zhoud03846a2015-07-28 14:20:03 -040031/**
32 * enum cgs_gpu_mem_type - GPU memory types
33 */
34enum cgs_gpu_mem_type {
35 CGS_GPU_MEM_TYPE__VISIBLE_FB,
36 CGS_GPU_MEM_TYPE__INVISIBLE_FB,
37 CGS_GPU_MEM_TYPE__VISIBLE_CONTIG_FB,
38 CGS_GPU_MEM_TYPE__INVISIBLE_CONTIG_FB,
39 CGS_GPU_MEM_TYPE__GART_CACHEABLE,
40 CGS_GPU_MEM_TYPE__GART_WRITECOMBINE
41};
42
43/**
44 * enum cgs_ind_reg - Indirect register spaces
45 */
46enum cgs_ind_reg {
47 CGS_IND_REG__MMIO,
48 CGS_IND_REG__PCIE,
49 CGS_IND_REG__SMC,
50 CGS_IND_REG__UVD_CTX,
51 CGS_IND_REG__DIDT,
Rex Zhuccdbb202016-06-08 12:47:41 +080052 CGS_IND_REG_GC_CAC,
Chunming Zhoud03846a2015-07-28 14:20:03 -040053 CGS_IND_REG__AUDIO_ENDPT
54};
55
56/**
57 * enum cgs_clock - Clocks controlled by the SMU
58 */
59enum cgs_clock {
60 CGS_CLOCK__SCLK,
61 CGS_CLOCK__MCLK,
62 CGS_CLOCK__VCLK,
63 CGS_CLOCK__DCLK,
64 CGS_CLOCK__ECLK,
65 CGS_CLOCK__ACLK,
66 CGS_CLOCK__ICLK,
67 /* ... */
68};
69
70/**
71 * enum cgs_engine - Engines that can be statically power-gated
72 */
73enum cgs_engine {
74 CGS_ENGINE__UVD,
75 CGS_ENGINE__VCE,
76 CGS_ENGINE__VP8,
77 CGS_ENGINE__ACP_DMA,
78 CGS_ENGINE__ACP_DSP0,
79 CGS_ENGINE__ACP_DSP1,
80 CGS_ENGINE__ISP,
81 /* ... */
82};
83
84/**
85 * enum cgs_voltage_planes - Voltage planes for external camera HW
86 */
87enum cgs_voltage_planes {
88 CGS_VOLTAGE_PLANE__SENSOR0,
89 CGS_VOLTAGE_PLANE__SENSOR1,
90 /* ... */
91};
92
Jammy Zhoubf3911b02015-05-13 18:58:05 +080093/*
94 * enum cgs_ucode_id - Firmware types for different IPs
95 */
96enum cgs_ucode_id {
97 CGS_UCODE_ID_SMU = 0,
yanyang1735f0022016-02-05 17:39:37 +080098 CGS_UCODE_ID_SMU_SK,
Jammy Zhoubf3911b02015-05-13 18:58:05 +080099 CGS_UCODE_ID_SDMA0,
100 CGS_UCODE_ID_SDMA1,
101 CGS_UCODE_ID_CP_CE,
102 CGS_UCODE_ID_CP_PFP,
103 CGS_UCODE_ID_CP_ME,
104 CGS_UCODE_ID_CP_MEC,
105 CGS_UCODE_ID_CP_MEC_JT1,
106 CGS_UCODE_ID_CP_MEC_JT2,
107 CGS_UCODE_ID_GMCON_RENG,
108 CGS_UCODE_ID_RLC_G,
109 CGS_UCODE_ID_MAXIMUM,
110};
111
Rex Zhu5e618692015-09-23 20:11:54 +0800112enum cgs_system_info_id {
113 CGS_SYSTEM_INFO_ADAPTER_BDF_ID = 1,
Alex Deuchercfd316d2015-11-11 20:35:32 -0500114 CGS_SYSTEM_INFO_PCIE_GEN_INFO,
115 CGS_SYSTEM_INFO_PCIE_MLW,
Huang Rui09fc7ef2016-07-12 13:54:05 +0800116 CGS_SYSTEM_INFO_PCIE_DEV,
117 CGS_SYSTEM_INFO_PCIE_REV,
Alex Deucher08d33402016-02-05 10:34:28 -0500118 CGS_SYSTEM_INFO_CG_FLAGS,
119 CGS_SYSTEM_INFO_PG_FLAGS,
Eric Huangbacec892016-03-17 18:29:08 -0400120 CGS_SYSTEM_INFO_GFX_CU_INFO,
Rex Zhud826c982016-06-07 20:15:24 +0800121 CGS_SYSTEM_INFO_GFX_SE_INFO,
Rex Zhu2fef37c2016-08-22 20:48:13 +0800122 CGS_SYSTEM_INFO_PCIE_SUB_SYS_ID,
123 CGS_SYSTEM_INFO_PCIE_SUB_SYS_VENDOR_ID,
Rex Zhu5e618692015-09-23 20:11:54 +0800124 CGS_SYSTEM_INFO_ID_MAXIMUM,
125};
126
127struct cgs_system_info {
Huang Rui11f55a32016-07-16 13:24:45 +0800128 uint64_t size;
129 enum cgs_system_info_id info_id;
Rex Zhu5e618692015-09-23 20:11:54 +0800130 union {
Huang Rui11f55a32016-07-16 13:24:45 +0800131 void *ptr;
132 uint64_t value;
Rex Zhu5e618692015-09-23 20:11:54 +0800133 };
Huang Rui11f55a32016-07-16 13:24:45 +0800134 uint64_t padding[13];
Rex Zhu5e618692015-09-23 20:11:54 +0800135};
136
Alex Deucherba228ac2015-12-23 11:25:43 -0500137/*
138 * enum cgs_resource_type - GPU resource type
139 */
140enum cgs_resource_type {
141 CGS_RESOURCE_TYPE_MMIO = 0,
142 CGS_RESOURCE_TYPE_FB,
143 CGS_RESOURCE_TYPE_IO,
144 CGS_RESOURCE_TYPE_DOORBELL,
145 CGS_RESOURCE_TYPE_ROM,
146};
147
Chunming Zhoud03846a2015-07-28 14:20:03 -0400148/**
149 * struct cgs_clock_limits - Clock limits
150 *
151 * Clocks are specified in 10KHz units.
152 */
153struct cgs_clock_limits {
154 unsigned min; /**< Minimum supported frequency */
155 unsigned max; /**< Maxumim supported frequency */
156 unsigned sustainable; /**< Thermally sustainable frequency */
157};
158
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800159/**
160 * struct cgs_firmware_info - Firmware information
161 */
162struct cgs_firmware_info {
163 uint16_t version;
164 uint16_t feature_version;
165 uint32_t image_size;
166 uint64_t mc_addr;
Huang Rui340efe22016-06-19 23:55:14 +0800167
168 /* only for smc firmware */
169 uint32_t ucode_start_address;
170
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800171 void *kptr;
172};
173
Rex Zhu47bf18b2015-09-17 16:34:14 +0800174struct cgs_mode_info {
175 uint32_t refresh_rate;
176 uint32_t ref_clock;
177 uint32_t vblank_time_us;
178};
179
180struct cgs_display_info {
181 uint32_t display_count;
182 uint32_t active_display_mask;
183 struct cgs_mode_info *mode_info;
184};
185
Chunming Zhoud03846a2015-07-28 14:20:03 -0400186typedef unsigned long cgs_handle_t;
187
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800188#define CGS_ACPI_METHOD_ATCS 0x53435441
189#define CGS_ACPI_METHOD_ATIF 0x46495441
190#define CGS_ACPI_METHOD_ATPX 0x58505441
191#define CGS_ACPI_FIELD_METHOD_NAME 0x00000001
192#define CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT 0x00000002
193#define CGS_ACPI_MAX_BUFFER_SIZE 256
194#define CGS_ACPI_TYPE_ANY 0x00
195#define CGS_ACPI_TYPE_INTEGER 0x01
196#define CGS_ACPI_TYPE_STRING 0x02
197#define CGS_ACPI_TYPE_BUFFER 0x03
198#define CGS_ACPI_TYPE_PACKAGE 0x04
199
200struct cgs_acpi_method_argument {
201 uint32_t type;
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800202 uint32_t data_length;
203 union{
204 uint32_t value;
205 void *pointer;
206 };
207};
208
209struct cgs_acpi_method_info {
210 uint32_t size;
211 uint32_t field;
212 uint32_t input_count;
213 uint32_t name;
214 struct cgs_acpi_method_argument *pinput_argument;
215 uint32_t output_count;
216 struct cgs_acpi_method_argument *poutput_argument;
217 uint32_t padding[9];
218};
219
Chunming Zhoud03846a2015-07-28 14:20:03 -0400220/**
221 * cgs_gpu_mem_info() - Return information about memory heaps
222 * @cgs_device: opaque device handle
223 * @type: memory type
224 * @mc_start: Start MC address of the heap (output)
225 * @mc_size: MC address space size (output)
226 * @mem_size: maximum amount of memory available for allocation (output)
227 *
228 * This function returns information about memory heaps. The type
229 * parameter is used to select the memory heap. The mc_start and
230 * mc_size for GART heaps may be bigger than the memory available for
231 * allocation.
232 *
233 * mc_start and mc_size are undefined for non-contiguous FB memory
234 * types, since buffers allocated with these types may or may not be
235 * GART mapped.
236 *
237 * Return: 0 on success, -errno otherwise
238 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000239typedef int (*cgs_gpu_mem_info_t)(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400240 uint64_t *mc_start, uint64_t *mc_size,
241 uint64_t *mem_size);
242
243/**
244 * cgs_gmap_kmem() - map kernel memory to GART aperture
245 * @cgs_device: opaque device handle
246 * @kmem: pointer to kernel memory
247 * @size: size to map
248 * @min_offset: minimum offset from start of GART aperture
249 * @max_offset: maximum offset from start of GART aperture
250 * @kmem_handle: kernel memory handle (output)
251 * @mcaddr: MC address (output)
252 *
253 * Return: 0 on success, -errno otherwise
254 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000255typedef int (*cgs_gmap_kmem_t)(struct cgs_device *cgs_device, void *kmem, uint64_t size,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400256 uint64_t min_offset, uint64_t max_offset,
257 cgs_handle_t *kmem_handle, uint64_t *mcaddr);
258
259/**
260 * cgs_gunmap_kmem() - unmap kernel memory
261 * @cgs_device: opaque device handle
262 * @kmem_handle: kernel memory handle returned by gmap_kmem
263 *
264 * Return: 0 on success, -errno otherwise
265 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000266typedef int (*cgs_gunmap_kmem_t)(struct cgs_device *cgs_device, cgs_handle_t kmem_handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400267
268/**
269 * cgs_alloc_gpu_mem() - Allocate GPU memory
270 * @cgs_device: opaque device handle
271 * @type: memory type
272 * @size: size in bytes
273 * @align: alignment in bytes
274 * @min_offset: minimum offset from start of heap
275 * @max_offset: maximum offset from start of heap
276 * @handle: memory handle (output)
277 *
278 * The memory types CGS_GPU_MEM_TYPE_*_CONTIG_FB force contiguous
279 * memory allocation. This guarantees that the MC address returned by
280 * cgs_gmap_gpu_mem is not mapped through the GART. The non-contiguous
281 * FB memory types may be GART mapped depending on memory
282 * fragmentation and memory allocator policies.
283 *
284 * If min/max_offset are non-0, the allocation will be forced to
285 * reside between these offsets in its respective memory heap. The
286 * base address that the offset relates to, depends on the memory
287 * type.
288 *
289 * - CGS_GPU_MEM_TYPE__*_CONTIG_FB: FB MC base address
290 * - CGS_GPU_MEM_TYPE__GART_*: GART aperture base address
291 * - others: undefined, don't use with max_offset
292 *
293 * Return: 0 on success, -errno otherwise
294 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000295typedef int (*cgs_alloc_gpu_mem_t)(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400296 uint64_t size, uint64_t align,
297 uint64_t min_offset, uint64_t max_offset,
298 cgs_handle_t *handle);
299
300/**
301 * cgs_free_gpu_mem() - Free GPU memory
302 * @cgs_device: opaque device handle
303 * @handle: memory handle returned by alloc or import
304 *
305 * Return: 0 on success, -errno otherwise
306 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000307typedef int (*cgs_free_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400308
309/**
310 * cgs_gmap_gpu_mem() - GPU-map GPU memory
311 * @cgs_device: opaque device handle
312 * @handle: memory handle returned by alloc or import
313 * @mcaddr: MC address (output)
314 *
315 * Ensures that a buffer is GPU accessible and returns its MC address.
316 *
317 * Return: 0 on success, -errno otherwise
318 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000319typedef int (*cgs_gmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400320 uint64_t *mcaddr);
321
322/**
323 * cgs_gunmap_gpu_mem() - GPU-unmap GPU memory
324 * @cgs_device: opaque device handle
325 * @handle: memory handle returned by alloc or import
326 *
327 * Allows the buffer to be migrated while it's not used by the GPU.
328 *
329 * Return: 0 on success, -errno otherwise
330 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000331typedef int (*cgs_gunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400332
333/**
334 * cgs_kmap_gpu_mem() - Kernel-map GPU memory
335 *
336 * @cgs_device: opaque device handle
337 * @handle: memory handle returned by alloc or import
338 * @map: Kernel virtual address the memory was mapped to (output)
339 *
340 * Return: 0 on success, -errno otherwise
341 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000342typedef int (*cgs_kmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400343 void **map);
344
345/**
346 * cgs_kunmap_gpu_mem() - Kernel-unmap GPU memory
347 * @cgs_device: opaque device handle
348 * @handle: memory handle returned by alloc or import
349 *
350 * Return: 0 on success, -errno otherwise
351 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000352typedef int (*cgs_kunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400353
354/**
355 * cgs_read_register() - Read an MMIO register
356 * @cgs_device: opaque device handle
357 * @offset: register offset
358 *
359 * Return: register value
360 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000361typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400362
363/**
364 * cgs_write_register() - Write an MMIO register
365 * @cgs_device: opaque device handle
366 * @offset: register offset
367 * @value: register value
368 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000369typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400370 uint32_t value);
371
372/**
373 * cgs_read_ind_register() - Read an indirect register
374 * @cgs_device: opaque device handle
375 * @offset: register offset
376 *
377 * Return: register value
378 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000379typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400380 unsigned index);
381
382/**
383 * cgs_write_ind_register() - Write an indirect register
384 * @cgs_device: opaque device handle
385 * @offset: register offset
386 * @value: register value
387 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000388typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400389 unsigned index, uint32_t value);
390
391/**
392 * cgs_read_pci_config_byte() - Read byte from PCI configuration space
393 * @cgs_device: opaque device handle
394 * @addr: address
395 *
396 * Return: Value read
397 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000398typedef uint8_t (*cgs_read_pci_config_byte_t)(struct cgs_device *cgs_device, unsigned addr);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400399
400/**
401 * cgs_read_pci_config_word() - Read word from PCI configuration space
402 * @cgs_device: opaque device handle
403 * @addr: address, must be word-aligned
404 *
405 * Return: Value read
406 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000407typedef uint16_t (*cgs_read_pci_config_word_t)(struct cgs_device *cgs_device, unsigned addr);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400408
409/**
410 * cgs_read_pci_config_dword() - Read dword from PCI configuration space
411 * @cgs_device: opaque device handle
412 * @addr: address, must be dword-aligned
413 *
414 * Return: Value read
415 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000416typedef uint32_t (*cgs_read_pci_config_dword_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400417 unsigned addr);
418
419/**
420 * cgs_write_pci_config_byte() - Write byte to PCI configuration space
421 * @cgs_device: opaque device handle
422 * @addr: address
423 * @value: value to write
424 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000425typedef void (*cgs_write_pci_config_byte_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400426 uint8_t value);
427
428/**
429 * cgs_write_pci_config_word() - Write byte to PCI configuration space
430 * @cgs_device: opaque device handle
431 * @addr: address, must be word-aligned
432 * @value: value to write
433 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000434typedef void (*cgs_write_pci_config_word_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400435 uint16_t value);
436
437/**
438 * cgs_write_pci_config_dword() - Write byte to PCI configuration space
439 * @cgs_device: opaque device handle
440 * @addr: address, must be dword-aligned
441 * @value: value to write
442 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000443typedef void (*cgs_write_pci_config_dword_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400444 uint32_t value);
445
Alex Deucherba228ac2015-12-23 11:25:43 -0500446
447/**
448 * cgs_get_pci_resource() - provide access to a device resource (PCI BAR)
449 * @cgs_device: opaque device handle
450 * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL)
451 * @size: size of the region
452 * @offset: offset from the start of the region
453 * @resource_base: base address (not including offset) returned
454 *
455 * Return: 0 on success, -errno otherwise
456 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000457typedef int (*cgs_get_pci_resource_t)(struct cgs_device *cgs_device,
Alex Deucherba228ac2015-12-23 11:25:43 -0500458 enum cgs_resource_type resource_type,
459 uint64_t size,
460 uint64_t offset,
461 uint64_t *resource_base);
462
Chunming Zhoud03846a2015-07-28 14:20:03 -0400463/**
464 * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table
465 * @cgs_device: opaque device handle
466 * @table: data table index
467 * @size: size of the table (output, may be NULL)
468 * @frev: table format revision (output, may be NULL)
469 * @crev: table content revision (output, may be NULL)
470 *
471 * Return: Pointer to start of the table, or NULL on failure
472 */
473typedef const void *(*cgs_atom_get_data_table_t)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000474 struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400475 uint16_t *size, uint8_t *frev, uint8_t *crev);
476
477/**
478 * cgs_atom_get_cmd_table_revs() - Get ATOM BIOS command table revisions
479 * @cgs_device: opaque device handle
480 * @table: data table index
481 * @frev: table format revision (output, may be NULL)
482 * @crev: table content revision (output, may be NULL)
483 *
484 * Return: 0 on success, -errno otherwise
485 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000486typedef int (*cgs_atom_get_cmd_table_revs_t)(struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400487 uint8_t *frev, uint8_t *crev);
488
489/**
490 * cgs_atom_exec_cmd_table() - Execute an ATOM BIOS command table
491 * @cgs_device: opaque device handle
492 * @table: command table index
493 * @args: arguments
494 *
495 * Return: 0 on success, -errno otherwise
496 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000497typedef int (*cgs_atom_exec_cmd_table_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400498 unsigned table, void *args);
499
500/**
501 * cgs_create_pm_request() - Create a power management request
502 * @cgs_device: opaque device handle
503 * @request: handle of created PM request (output)
504 *
505 * Return: 0 on success, -errno otherwise
506 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000507typedef int (*cgs_create_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t *request);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400508
509/**
510 * cgs_destroy_pm_request() - Destroy a power management request
511 * @cgs_device: opaque device handle
512 * @request: handle of created PM request
513 *
514 * Return: 0 on success, -errno otherwise
515 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000516typedef int (*cgs_destroy_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t request);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400517
518/**
519 * cgs_set_pm_request() - Activate or deactiveate a PM request
520 * @cgs_device: opaque device handle
521 * @request: PM request handle
522 * @active: 0 = deactivate, non-0 = activate
523 *
524 * While a PM request is active, its minimum clock requests are taken
525 * into account as the requested engines are powered up. When the
526 * request is inactive, the engines may be powered down and clocks may
527 * be lower, depending on other PM requests by other driver
528 * components.
529 *
530 * Return: 0 on success, -errno otherwise
531 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000532typedef int (*cgs_set_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400533 int active);
534
535/**
536 * cgs_pm_request_clock() - Request a minimum frequency for a specific clock
537 * @cgs_device: opaque device handle
538 * @request: PM request handle
539 * @clock: which clock?
540 * @freq: requested min. frequency in 10KHz units (0 to clear request)
541 *
542 * Return: 0 on success, -errno otherwise
543 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000544typedef int (*cgs_pm_request_clock_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400545 enum cgs_clock clock, unsigned freq);
546
547/**
548 * cgs_pm_request_engine() - Request an engine to be powered up
549 * @cgs_device: opaque device handle
550 * @request: PM request handle
551 * @engine: which engine?
552 * @powered: 0 = powered down, non-0 = powered up
553 *
554 * Return: 0 on success, -errno otherwise
555 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000556typedef int (*cgs_pm_request_engine_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400557 enum cgs_engine engine, int powered);
558
559/**
560 * cgs_pm_query_clock_limits() - Query clock frequency limits
561 * @cgs_device: opaque device handle
562 * @clock: which clock?
563 * @limits: clock limits
564 *
565 * Return: 0 on success, -errno otherwise
566 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000567typedef int (*cgs_pm_query_clock_limits_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400568 enum cgs_clock clock,
569 struct cgs_clock_limits *limits);
570
571/**
572 * cgs_set_camera_voltages() - Apply specific voltages to PMIC voltage planes
573 * @cgs_device: opaque device handle
574 * @mask: bitmask of voltages to change (1<<CGS_VOLTAGE_PLANE__xyz|...)
575 * @voltages: pointer to array of voltage values in 1mV units
576 *
577 * Return: 0 on success, -errno otherwise
578 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000579typedef int (*cgs_set_camera_voltages_t)(struct cgs_device *cgs_device, uint32_t mask,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400580 const uint32_t *voltages);
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800581/**
582 * cgs_get_firmware_info - Get the firmware information from core driver
583 * @cgs_device: opaque device handle
584 * @type: the firmware type
585 * @info: returend firmware information
586 *
587 * Return: 0 on success, -errno otherwise
588 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000589typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800590 enum cgs_ucode_id type,
591 struct cgs_firmware_info *info);
592
Monk Liua3927462016-05-31 13:44:30 +0800593typedef int (*cgs_rel_firmware)(struct cgs_device *cgs_device,
594 enum cgs_ucode_id type);
595
Dave Airlie110e6f22016-04-12 13:25:48 +1000596typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800597 enum amd_ip_block_type block_type,
598 enum amd_powergating_state state);
599
Dave Airlie110e6f22016-04-12 13:25:48 +1000600typedef int(*cgs_set_clockgating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800601 enum amd_ip_block_type block_type,
602 enum amd_clockgating_state state);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400603
Rex Zhu47bf18b2015-09-17 16:34:14 +0800604typedef int(*cgs_get_active_displays_info)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000605 struct cgs_device *cgs_device,
Rex Zhu47bf18b2015-09-17 16:34:14 +0800606 struct cgs_display_info *info);
607
Dave Airlie110e6f22016-04-12 13:25:48 +1000608typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
Rex Zhu4c900802016-03-29 14:20:37 +0800609
Dave Airlie110e6f22016-04-12 13:25:48 +1000610typedef int (*cgs_call_acpi_method)(struct cgs_device *cgs_device,
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800611 uint32_t acpi_method,
612 uint32_t acpi_function,
613 void *pinput, void *poutput,
614 uint32_t output_count,
615 uint32_t input_size,
616 uint32_t output_size);
Rex Zhu5e618692015-09-23 20:11:54 +0800617
Dave Airlie110e6f22016-04-12 13:25:48 +1000618typedef int (*cgs_query_system_info)(struct cgs_device *cgs_device,
Rex Zhu5e618692015-09-23 20:11:54 +0800619 struct cgs_system_info *sys_info);
620
Chunming Zhoud03846a2015-07-28 14:20:03 -0400621struct cgs_ops {
622 /* memory management calls (similar to KFD interface) */
623 cgs_gpu_mem_info_t gpu_mem_info;
624 cgs_gmap_kmem_t gmap_kmem;
625 cgs_gunmap_kmem_t gunmap_kmem;
626 cgs_alloc_gpu_mem_t alloc_gpu_mem;
627 cgs_free_gpu_mem_t free_gpu_mem;
628 cgs_gmap_gpu_mem_t gmap_gpu_mem;
629 cgs_gunmap_gpu_mem_t gunmap_gpu_mem;
630 cgs_kmap_gpu_mem_t kmap_gpu_mem;
631 cgs_kunmap_gpu_mem_t kunmap_gpu_mem;
632 /* MMIO access */
633 cgs_read_register_t read_register;
634 cgs_write_register_t write_register;
635 cgs_read_ind_register_t read_ind_register;
636 cgs_write_ind_register_t write_ind_register;
637 /* PCI configuration space access */
638 cgs_read_pci_config_byte_t read_pci_config_byte;
639 cgs_read_pci_config_word_t read_pci_config_word;
640 cgs_read_pci_config_dword_t read_pci_config_dword;
641 cgs_write_pci_config_byte_t write_pci_config_byte;
642 cgs_write_pci_config_word_t write_pci_config_word;
643 cgs_write_pci_config_dword_t write_pci_config_dword;
Alex Deucherba228ac2015-12-23 11:25:43 -0500644 /* PCI resources */
645 cgs_get_pci_resource_t get_pci_resource;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400646 /* ATOM BIOS */
647 cgs_atom_get_data_table_t atom_get_data_table;
648 cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs;
649 cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
650 /* Power management */
651 cgs_create_pm_request_t create_pm_request;
652 cgs_destroy_pm_request_t destroy_pm_request;
653 cgs_set_pm_request_t set_pm_request;
654 cgs_pm_request_clock_t pm_request_clock;
655 cgs_pm_request_engine_t pm_request_engine;
656 cgs_pm_query_clock_limits_t pm_query_clock_limits;
657 cgs_set_camera_voltages_t set_camera_voltages;
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800658 /* Firmware Info */
659 cgs_get_firmware_info get_firmware_info;
Monk Liua3927462016-05-31 13:44:30 +0800660 cgs_rel_firmware rel_firmware;
rezhu404b2fa2015-08-07 13:37:56 +0800661 /* cg pg interface*/
662 cgs_set_powergating_state set_powergating_state;
663 cgs_set_clockgating_state set_clockgating_state;
Rex Zhu47bf18b2015-09-17 16:34:14 +0800664 /* display manager */
665 cgs_get_active_displays_info get_active_displays_info;
Rex Zhu4c900802016-03-29 14:20:37 +0800666 /* notify dpm enabled */
667 cgs_notify_dpm_enabled notify_dpm_enabled;
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800668 /* ACPI */
669 cgs_call_acpi_method call_acpi_method;
Rex Zhu5e618692015-09-23 20:11:54 +0800670 /* get system info */
671 cgs_query_system_info query_system_info;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400672};
673
674struct cgs_os_ops; /* To be define in OS-specific CGS header */
675
676struct cgs_device
677{
678 const struct cgs_ops *ops;
679 const struct cgs_os_ops *os_ops;
680 /* to be embedded at the start of driver private structure */
681};
682
683/* Convenience macros that make CGS indirect function calls look like
684 * normal function calls */
685#define CGS_CALL(func,dev,...) \
686 (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
687#define CGS_OS_CALL(func,dev,...) \
688 (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
689
690#define cgs_gpu_mem_info(dev,type,mc_start,mc_size,mem_size) \
691 CGS_CALL(gpu_mem_info,dev,type,mc_start,mc_size,mem_size)
692#define cgs_gmap_kmem(dev,kmem,size,min_off,max_off,kmem_handle,mcaddr) \
693 CGS_CALL(gmap_kmem,dev,kmem,size,min_off,max_off,kmem_handle,mcaddr)
Jammy Zhou97baee72015-07-21 17:02:44 +0800694#define cgs_gunmap_kmem(dev,kmem_handle) \
Chunming Zhoud03846a2015-07-28 14:20:03 -0400695 CGS_CALL(gunmap_kmem,dev,keme_handle)
696#define cgs_alloc_gpu_mem(dev,type,size,align,min_off,max_off,handle) \
697 CGS_CALL(alloc_gpu_mem,dev,type,size,align,min_off,max_off,handle)
698#define cgs_free_gpu_mem(dev,handle) \
699 CGS_CALL(free_gpu_mem,dev,handle)
700#define cgs_gmap_gpu_mem(dev,handle,mcaddr) \
701 CGS_CALL(gmap_gpu_mem,dev,handle,mcaddr)
Jammy Zhou97baee72015-07-21 17:02:44 +0800702#define cgs_gunmap_gpu_mem(dev,handle) \
Chunming Zhoud03846a2015-07-28 14:20:03 -0400703 CGS_CALL(gunmap_gpu_mem,dev,handle)
704#define cgs_kmap_gpu_mem(dev,handle,map) \
705 CGS_CALL(kmap_gpu_mem,dev,handle,map)
706#define cgs_kunmap_gpu_mem(dev,handle) \
707 CGS_CALL(kunmap_gpu_mem,dev,handle)
708
709#define cgs_read_register(dev,offset) \
710 CGS_CALL(read_register,dev,offset)
711#define cgs_write_register(dev,offset,value) \
712 CGS_CALL(write_register,dev,offset,value)
713#define cgs_read_ind_register(dev,space,index) \
714 CGS_CALL(read_ind_register,dev,space,index)
715#define cgs_write_ind_register(dev,space,index,value) \
716 CGS_CALL(write_ind_register,dev,space,index,value)
717
718#define cgs_read_pci_config_byte(dev,addr) \
719 CGS_CALL(read_pci_config_byte,dev,addr)
720#define cgs_read_pci_config_word(dev,addr) \
721 CGS_CALL(read_pci_config_word,dev,addr)
722#define cgs_read_pci_config_dword(dev,addr) \
723 CGS_CALL(read_pci_config_dword,dev,addr)
724#define cgs_write_pci_config_byte(dev,addr,value) \
725 CGS_CALL(write_pci_config_byte,dev,addr,value)
726#define cgs_write_pci_config_word(dev,addr,value) \
727 CGS_CALL(write_pci_config_word,dev,addr,value)
728#define cgs_write_pci_config_dword(dev,addr,value) \
729 CGS_CALL(write_pci_config_dword,dev,addr,value)
730
731#define cgs_atom_get_data_table(dev,table,size,frev,crev) \
732 CGS_CALL(atom_get_data_table,dev,table,size,frev,crev)
733#define cgs_atom_get_cmd_table_revs(dev,table,frev,crev) \
734 CGS_CALL(atom_get_cmd_table_revs,dev,table,frev,crev)
735#define cgs_atom_exec_cmd_table(dev,table,args) \
736 CGS_CALL(atom_exec_cmd_table,dev,table,args)
737
738#define cgs_create_pm_request(dev,request) \
739 CGS_CALL(create_pm_request,dev,request)
740#define cgs_destroy_pm_request(dev,request) \
741 CGS_CALL(destroy_pm_request,dev,request)
742#define cgs_set_pm_request(dev,request,active) \
743 CGS_CALL(set_pm_request,dev,request,active)
744#define cgs_pm_request_clock(dev,request,clock,freq) \
745 CGS_CALL(pm_request_clock,dev,request,clock,freq)
746#define cgs_pm_request_engine(dev,request,engine,powered) \
747 CGS_CALL(pm_request_engine,dev,request,engine,powered)
748#define cgs_pm_query_clock_limits(dev,clock,limits) \
749 CGS_CALL(pm_query_clock_limits,dev,clock,limits)
750#define cgs_set_camera_voltages(dev,mask,voltages) \
751 CGS_CALL(set_camera_voltages,dev,mask,voltages)
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800752#define cgs_get_firmware_info(dev, type, info) \
753 CGS_CALL(get_firmware_info, dev, type, info)
Monk Liua3927462016-05-31 13:44:30 +0800754#define cgs_rel_firmware(dev, type) \
755 CGS_CALL(rel_firmware, dev, type)
rezhu404b2fa2015-08-07 13:37:56 +0800756#define cgs_set_powergating_state(dev, block_type, state) \
757 CGS_CALL(set_powergating_state, dev, block_type, state)
758#define cgs_set_clockgating_state(dev, block_type, state) \
759 CGS_CALL(set_clockgating_state, dev, block_type, state)
Rex Zhu4c900802016-03-29 14:20:37 +0800760#define cgs_notify_dpm_enabled(dev, enabled) \
761 CGS_CALL(notify_dpm_enabled, dev, enabled)
762
Rex Zhu47bf18b2015-09-17 16:34:14 +0800763#define cgs_get_active_displays_info(dev, info) \
764 CGS_CALL(get_active_displays_info, dev, info)
Rex Zhu4c900802016-03-29 14:20:37 +0800765
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800766#define cgs_call_acpi_method(dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size) \
767 CGS_CALL(call_acpi_method, dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size)
Rex Zhu5e618692015-09-23 20:11:54 +0800768#define cgs_query_system_info(dev, sys_info) \
769 CGS_CALL(query_system_info, dev, sys_info)
Alex Deucherba228ac2015-12-23 11:25:43 -0500770#define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \
771 resource_base) \
772 CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
773 resource_base)
Chunming Zhoud03846a2015-07-28 14:20:03 -0400774
775#endif /* _CGS_COMMON_H */