blob: f32af2f2091a626a092f79b79f8c102e6f724395 [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,
Alex Deucher08d33402016-02-05 10:34:28 -0500116 CGS_SYSTEM_INFO_CG_FLAGS,
117 CGS_SYSTEM_INFO_PG_FLAGS,
Eric Huangbacec892016-03-17 18:29:08 -0400118 CGS_SYSTEM_INFO_GFX_CU_INFO,
Rex Zhud826c982016-06-07 20:15:24 +0800119 CGS_SYSTEM_INFO_GFX_SE_INFO,
Rex Zhu5e618692015-09-23 20:11:54 +0800120 CGS_SYSTEM_INFO_ID_MAXIMUM,
121};
122
123struct cgs_system_info {
124 uint64_t size;
125 uint64_t info_id;
126 union {
127 void *ptr;
128 uint64_t value;
129 };
130 uint64_t padding[13];
131};
132
Alex Deucherba228ac2015-12-23 11:25:43 -0500133/*
134 * enum cgs_resource_type - GPU resource type
135 */
136enum cgs_resource_type {
137 CGS_RESOURCE_TYPE_MMIO = 0,
138 CGS_RESOURCE_TYPE_FB,
139 CGS_RESOURCE_TYPE_IO,
140 CGS_RESOURCE_TYPE_DOORBELL,
141 CGS_RESOURCE_TYPE_ROM,
142};
143
Chunming Zhoud03846a2015-07-28 14:20:03 -0400144/**
145 * struct cgs_clock_limits - Clock limits
146 *
147 * Clocks are specified in 10KHz units.
148 */
149struct cgs_clock_limits {
150 unsigned min; /**< Minimum supported frequency */
151 unsigned max; /**< Maxumim supported frequency */
152 unsigned sustainable; /**< Thermally sustainable frequency */
153};
154
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800155/**
156 * struct cgs_firmware_info - Firmware information
157 */
158struct cgs_firmware_info {
159 uint16_t version;
160 uint16_t feature_version;
161 uint32_t image_size;
162 uint64_t mc_addr;
Huang Rui340efe22016-06-19 23:55:14 +0800163
164 /* only for smc firmware */
165 uint32_t ucode_start_address;
166
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800167 void *kptr;
168};
169
Rex Zhu47bf18b2015-09-17 16:34:14 +0800170struct cgs_mode_info {
171 uint32_t refresh_rate;
172 uint32_t ref_clock;
173 uint32_t vblank_time_us;
174};
175
176struct cgs_display_info {
177 uint32_t display_count;
178 uint32_t active_display_mask;
179 struct cgs_mode_info *mode_info;
180};
181
Chunming Zhoud03846a2015-07-28 14:20:03 -0400182typedef unsigned long cgs_handle_t;
183
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800184#define CGS_ACPI_METHOD_ATCS 0x53435441
185#define CGS_ACPI_METHOD_ATIF 0x46495441
186#define CGS_ACPI_METHOD_ATPX 0x58505441
187#define CGS_ACPI_FIELD_METHOD_NAME 0x00000001
188#define CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT 0x00000002
189#define CGS_ACPI_MAX_BUFFER_SIZE 256
190#define CGS_ACPI_TYPE_ANY 0x00
191#define CGS_ACPI_TYPE_INTEGER 0x01
192#define CGS_ACPI_TYPE_STRING 0x02
193#define CGS_ACPI_TYPE_BUFFER 0x03
194#define CGS_ACPI_TYPE_PACKAGE 0x04
195
196struct cgs_acpi_method_argument {
197 uint32_t type;
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800198 uint32_t data_length;
199 union{
200 uint32_t value;
201 void *pointer;
202 };
203};
204
205struct cgs_acpi_method_info {
206 uint32_t size;
207 uint32_t field;
208 uint32_t input_count;
209 uint32_t name;
210 struct cgs_acpi_method_argument *pinput_argument;
211 uint32_t output_count;
212 struct cgs_acpi_method_argument *poutput_argument;
213 uint32_t padding[9];
214};
215
Chunming Zhoud03846a2015-07-28 14:20:03 -0400216/**
217 * cgs_gpu_mem_info() - Return information about memory heaps
218 * @cgs_device: opaque device handle
219 * @type: memory type
220 * @mc_start: Start MC address of the heap (output)
221 * @mc_size: MC address space size (output)
222 * @mem_size: maximum amount of memory available for allocation (output)
223 *
224 * This function returns information about memory heaps. The type
225 * parameter is used to select the memory heap. The mc_start and
226 * mc_size for GART heaps may be bigger than the memory available for
227 * allocation.
228 *
229 * mc_start and mc_size are undefined for non-contiguous FB memory
230 * types, since buffers allocated with these types may or may not be
231 * GART mapped.
232 *
233 * Return: 0 on success, -errno otherwise
234 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000235typedef int (*cgs_gpu_mem_info_t)(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400236 uint64_t *mc_start, uint64_t *mc_size,
237 uint64_t *mem_size);
238
239/**
240 * cgs_gmap_kmem() - map kernel memory to GART aperture
241 * @cgs_device: opaque device handle
242 * @kmem: pointer to kernel memory
243 * @size: size to map
244 * @min_offset: minimum offset from start of GART aperture
245 * @max_offset: maximum offset from start of GART aperture
246 * @kmem_handle: kernel memory handle (output)
247 * @mcaddr: MC address (output)
248 *
249 * Return: 0 on success, -errno otherwise
250 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000251typedef int (*cgs_gmap_kmem_t)(struct cgs_device *cgs_device, void *kmem, uint64_t size,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400252 uint64_t min_offset, uint64_t max_offset,
253 cgs_handle_t *kmem_handle, uint64_t *mcaddr);
254
255/**
256 * cgs_gunmap_kmem() - unmap kernel memory
257 * @cgs_device: opaque device handle
258 * @kmem_handle: kernel memory handle returned by gmap_kmem
259 *
260 * Return: 0 on success, -errno otherwise
261 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000262typedef int (*cgs_gunmap_kmem_t)(struct cgs_device *cgs_device, cgs_handle_t kmem_handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400263
264/**
265 * cgs_alloc_gpu_mem() - Allocate GPU memory
266 * @cgs_device: opaque device handle
267 * @type: memory type
268 * @size: size in bytes
269 * @align: alignment in bytes
270 * @min_offset: minimum offset from start of heap
271 * @max_offset: maximum offset from start of heap
272 * @handle: memory handle (output)
273 *
274 * The memory types CGS_GPU_MEM_TYPE_*_CONTIG_FB force contiguous
275 * memory allocation. This guarantees that the MC address returned by
276 * cgs_gmap_gpu_mem is not mapped through the GART. The non-contiguous
277 * FB memory types may be GART mapped depending on memory
278 * fragmentation and memory allocator policies.
279 *
280 * If min/max_offset are non-0, the allocation will be forced to
281 * reside between these offsets in its respective memory heap. The
282 * base address that the offset relates to, depends on the memory
283 * type.
284 *
285 * - CGS_GPU_MEM_TYPE__*_CONTIG_FB: FB MC base address
286 * - CGS_GPU_MEM_TYPE__GART_*: GART aperture base address
287 * - others: undefined, don't use with max_offset
288 *
289 * Return: 0 on success, -errno otherwise
290 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000291typedef int (*cgs_alloc_gpu_mem_t)(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400292 uint64_t size, uint64_t align,
293 uint64_t min_offset, uint64_t max_offset,
294 cgs_handle_t *handle);
295
296/**
297 * cgs_free_gpu_mem() - Free GPU memory
298 * @cgs_device: opaque device handle
299 * @handle: memory handle returned by alloc or import
300 *
301 * Return: 0 on success, -errno otherwise
302 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000303typedef int (*cgs_free_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400304
305/**
306 * cgs_gmap_gpu_mem() - GPU-map GPU memory
307 * @cgs_device: opaque device handle
308 * @handle: memory handle returned by alloc or import
309 * @mcaddr: MC address (output)
310 *
311 * Ensures that a buffer is GPU accessible and returns its MC address.
312 *
313 * Return: 0 on success, -errno otherwise
314 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000315typedef int (*cgs_gmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400316 uint64_t *mcaddr);
317
318/**
319 * cgs_gunmap_gpu_mem() - GPU-unmap GPU memory
320 * @cgs_device: opaque device handle
321 * @handle: memory handle returned by alloc or import
322 *
323 * Allows the buffer to be migrated while it's not used by the GPU.
324 *
325 * Return: 0 on success, -errno otherwise
326 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000327typedef int (*cgs_gunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400328
329/**
330 * cgs_kmap_gpu_mem() - Kernel-map GPU memory
331 *
332 * @cgs_device: opaque device handle
333 * @handle: memory handle returned by alloc or import
334 * @map: Kernel virtual address the memory was mapped to (output)
335 *
336 * Return: 0 on success, -errno otherwise
337 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000338typedef int (*cgs_kmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400339 void **map);
340
341/**
342 * cgs_kunmap_gpu_mem() - Kernel-unmap GPU memory
343 * @cgs_device: opaque device handle
344 * @handle: memory handle returned by alloc or import
345 *
346 * Return: 0 on success, -errno otherwise
347 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000348typedef int (*cgs_kunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400349
350/**
351 * cgs_read_register() - Read an MMIO register
352 * @cgs_device: opaque device handle
353 * @offset: register offset
354 *
355 * Return: register value
356 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000357typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400358
359/**
360 * cgs_write_register() - Write an MMIO register
361 * @cgs_device: opaque device handle
362 * @offset: register offset
363 * @value: register value
364 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000365typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400366 uint32_t value);
367
368/**
369 * cgs_read_ind_register() - Read an indirect register
370 * @cgs_device: opaque device handle
371 * @offset: register offset
372 *
373 * Return: register value
374 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000375typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400376 unsigned index);
377
378/**
379 * cgs_write_ind_register() - Write an indirect register
380 * @cgs_device: opaque device handle
381 * @offset: register offset
382 * @value: register value
383 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000384typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400385 unsigned index, uint32_t value);
386
387/**
388 * cgs_read_pci_config_byte() - Read byte from PCI configuration space
389 * @cgs_device: opaque device handle
390 * @addr: address
391 *
392 * Return: Value read
393 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000394typedef uint8_t (*cgs_read_pci_config_byte_t)(struct cgs_device *cgs_device, unsigned addr);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400395
396/**
397 * cgs_read_pci_config_word() - Read word from PCI configuration space
398 * @cgs_device: opaque device handle
399 * @addr: address, must be word-aligned
400 *
401 * Return: Value read
402 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000403typedef uint16_t (*cgs_read_pci_config_word_t)(struct cgs_device *cgs_device, unsigned addr);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400404
405/**
406 * cgs_read_pci_config_dword() - Read dword from PCI configuration space
407 * @cgs_device: opaque device handle
408 * @addr: address, must be dword-aligned
409 *
410 * Return: Value read
411 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000412typedef uint32_t (*cgs_read_pci_config_dword_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400413 unsigned addr);
414
415/**
416 * cgs_write_pci_config_byte() - Write byte to PCI configuration space
417 * @cgs_device: opaque device handle
418 * @addr: address
419 * @value: value to write
420 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000421typedef void (*cgs_write_pci_config_byte_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400422 uint8_t value);
423
424/**
425 * cgs_write_pci_config_word() - Write byte to PCI configuration space
426 * @cgs_device: opaque device handle
427 * @addr: address, must be word-aligned
428 * @value: value to write
429 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000430typedef void (*cgs_write_pci_config_word_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400431 uint16_t value);
432
433/**
434 * cgs_write_pci_config_dword() - Write byte to PCI configuration space
435 * @cgs_device: opaque device handle
436 * @addr: address, must be dword-aligned
437 * @value: value to write
438 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000439typedef void (*cgs_write_pci_config_dword_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400440 uint32_t value);
441
Alex Deucherba228ac2015-12-23 11:25:43 -0500442
443/**
444 * cgs_get_pci_resource() - provide access to a device resource (PCI BAR)
445 * @cgs_device: opaque device handle
446 * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL)
447 * @size: size of the region
448 * @offset: offset from the start of the region
449 * @resource_base: base address (not including offset) returned
450 *
451 * Return: 0 on success, -errno otherwise
452 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000453typedef int (*cgs_get_pci_resource_t)(struct cgs_device *cgs_device,
Alex Deucherba228ac2015-12-23 11:25:43 -0500454 enum cgs_resource_type resource_type,
455 uint64_t size,
456 uint64_t offset,
457 uint64_t *resource_base);
458
Chunming Zhoud03846a2015-07-28 14:20:03 -0400459/**
460 * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table
461 * @cgs_device: opaque device handle
462 * @table: data table index
463 * @size: size of the table (output, may be NULL)
464 * @frev: table format revision (output, may be NULL)
465 * @crev: table content revision (output, may be NULL)
466 *
467 * Return: Pointer to start of the table, or NULL on failure
468 */
469typedef const void *(*cgs_atom_get_data_table_t)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000470 struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400471 uint16_t *size, uint8_t *frev, uint8_t *crev);
472
473/**
474 * cgs_atom_get_cmd_table_revs() - Get ATOM BIOS command table revisions
475 * @cgs_device: opaque device handle
476 * @table: data table index
477 * @frev: table format revision (output, may be NULL)
478 * @crev: table content revision (output, may be NULL)
479 *
480 * Return: 0 on success, -errno otherwise
481 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000482typedef int (*cgs_atom_get_cmd_table_revs_t)(struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400483 uint8_t *frev, uint8_t *crev);
484
485/**
486 * cgs_atom_exec_cmd_table() - Execute an ATOM BIOS command table
487 * @cgs_device: opaque device handle
488 * @table: command table index
489 * @args: arguments
490 *
491 * Return: 0 on success, -errno otherwise
492 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000493typedef int (*cgs_atom_exec_cmd_table_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400494 unsigned table, void *args);
495
496/**
497 * cgs_create_pm_request() - Create a power management request
498 * @cgs_device: opaque device handle
499 * @request: handle of created PM request (output)
500 *
501 * Return: 0 on success, -errno otherwise
502 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000503typedef int (*cgs_create_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t *request);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400504
505/**
506 * cgs_destroy_pm_request() - Destroy a power management request
507 * @cgs_device: opaque device handle
508 * @request: handle of created PM request
509 *
510 * Return: 0 on success, -errno otherwise
511 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000512typedef int (*cgs_destroy_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t request);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400513
514/**
515 * cgs_set_pm_request() - Activate or deactiveate a PM request
516 * @cgs_device: opaque device handle
517 * @request: PM request handle
518 * @active: 0 = deactivate, non-0 = activate
519 *
520 * While a PM request is active, its minimum clock requests are taken
521 * into account as the requested engines are powered up. When the
522 * request is inactive, the engines may be powered down and clocks may
523 * be lower, depending on other PM requests by other driver
524 * components.
525 *
526 * Return: 0 on success, -errno otherwise
527 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000528typedef int (*cgs_set_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400529 int active);
530
531/**
532 * cgs_pm_request_clock() - Request a minimum frequency for a specific clock
533 * @cgs_device: opaque device handle
534 * @request: PM request handle
535 * @clock: which clock?
536 * @freq: requested min. frequency in 10KHz units (0 to clear request)
537 *
538 * Return: 0 on success, -errno otherwise
539 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000540typedef int (*cgs_pm_request_clock_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400541 enum cgs_clock clock, unsigned freq);
542
543/**
544 * cgs_pm_request_engine() - Request an engine to be powered up
545 * @cgs_device: opaque device handle
546 * @request: PM request handle
547 * @engine: which engine?
548 * @powered: 0 = powered down, non-0 = powered up
549 *
550 * Return: 0 on success, -errno otherwise
551 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000552typedef int (*cgs_pm_request_engine_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400553 enum cgs_engine engine, int powered);
554
555/**
556 * cgs_pm_query_clock_limits() - Query clock frequency limits
557 * @cgs_device: opaque device handle
558 * @clock: which clock?
559 * @limits: clock limits
560 *
561 * Return: 0 on success, -errno otherwise
562 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000563typedef int (*cgs_pm_query_clock_limits_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400564 enum cgs_clock clock,
565 struct cgs_clock_limits *limits);
566
567/**
568 * cgs_set_camera_voltages() - Apply specific voltages to PMIC voltage planes
569 * @cgs_device: opaque device handle
570 * @mask: bitmask of voltages to change (1<<CGS_VOLTAGE_PLANE__xyz|...)
571 * @voltages: pointer to array of voltage values in 1mV units
572 *
573 * Return: 0 on success, -errno otherwise
574 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000575typedef int (*cgs_set_camera_voltages_t)(struct cgs_device *cgs_device, uint32_t mask,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400576 const uint32_t *voltages);
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800577/**
578 * cgs_get_firmware_info - Get the firmware information from core driver
579 * @cgs_device: opaque device handle
580 * @type: the firmware type
581 * @info: returend firmware information
582 *
583 * Return: 0 on success, -errno otherwise
584 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000585typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800586 enum cgs_ucode_id type,
587 struct cgs_firmware_info *info);
588
Monk Liua3927462016-05-31 13:44:30 +0800589typedef int (*cgs_rel_firmware)(struct cgs_device *cgs_device,
590 enum cgs_ucode_id type);
591
Dave Airlie110e6f22016-04-12 13:25:48 +1000592typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800593 enum amd_ip_block_type block_type,
594 enum amd_powergating_state state);
595
Dave Airlie110e6f22016-04-12 13:25:48 +1000596typedef int(*cgs_set_clockgating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800597 enum amd_ip_block_type block_type,
598 enum amd_clockgating_state state);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400599
Rex Zhu47bf18b2015-09-17 16:34:14 +0800600typedef int(*cgs_get_active_displays_info)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000601 struct cgs_device *cgs_device,
Rex Zhu47bf18b2015-09-17 16:34:14 +0800602 struct cgs_display_info *info);
603
Dave Airlie110e6f22016-04-12 13:25:48 +1000604typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
Rex Zhu4c900802016-03-29 14:20:37 +0800605
Dave Airlie110e6f22016-04-12 13:25:48 +1000606typedef int (*cgs_call_acpi_method)(struct cgs_device *cgs_device,
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800607 uint32_t acpi_method,
608 uint32_t acpi_function,
609 void *pinput, void *poutput,
610 uint32_t output_count,
611 uint32_t input_size,
612 uint32_t output_size);
Rex Zhu5e618692015-09-23 20:11:54 +0800613
Dave Airlie110e6f22016-04-12 13:25:48 +1000614typedef int (*cgs_query_system_info)(struct cgs_device *cgs_device,
Rex Zhu5e618692015-09-23 20:11:54 +0800615 struct cgs_system_info *sys_info);
616
Chunming Zhoud03846a2015-07-28 14:20:03 -0400617struct cgs_ops {
618 /* memory management calls (similar to KFD interface) */
619 cgs_gpu_mem_info_t gpu_mem_info;
620 cgs_gmap_kmem_t gmap_kmem;
621 cgs_gunmap_kmem_t gunmap_kmem;
622 cgs_alloc_gpu_mem_t alloc_gpu_mem;
623 cgs_free_gpu_mem_t free_gpu_mem;
624 cgs_gmap_gpu_mem_t gmap_gpu_mem;
625 cgs_gunmap_gpu_mem_t gunmap_gpu_mem;
626 cgs_kmap_gpu_mem_t kmap_gpu_mem;
627 cgs_kunmap_gpu_mem_t kunmap_gpu_mem;
628 /* MMIO access */
629 cgs_read_register_t read_register;
630 cgs_write_register_t write_register;
631 cgs_read_ind_register_t read_ind_register;
632 cgs_write_ind_register_t write_ind_register;
633 /* PCI configuration space access */
634 cgs_read_pci_config_byte_t read_pci_config_byte;
635 cgs_read_pci_config_word_t read_pci_config_word;
636 cgs_read_pci_config_dword_t read_pci_config_dword;
637 cgs_write_pci_config_byte_t write_pci_config_byte;
638 cgs_write_pci_config_word_t write_pci_config_word;
639 cgs_write_pci_config_dword_t write_pci_config_dword;
Alex Deucherba228ac2015-12-23 11:25:43 -0500640 /* PCI resources */
641 cgs_get_pci_resource_t get_pci_resource;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400642 /* ATOM BIOS */
643 cgs_atom_get_data_table_t atom_get_data_table;
644 cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs;
645 cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
646 /* Power management */
647 cgs_create_pm_request_t create_pm_request;
648 cgs_destroy_pm_request_t destroy_pm_request;
649 cgs_set_pm_request_t set_pm_request;
650 cgs_pm_request_clock_t pm_request_clock;
651 cgs_pm_request_engine_t pm_request_engine;
652 cgs_pm_query_clock_limits_t pm_query_clock_limits;
653 cgs_set_camera_voltages_t set_camera_voltages;
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800654 /* Firmware Info */
655 cgs_get_firmware_info get_firmware_info;
Monk Liua3927462016-05-31 13:44:30 +0800656 cgs_rel_firmware rel_firmware;
rezhu404b2fa2015-08-07 13:37:56 +0800657 /* cg pg interface*/
658 cgs_set_powergating_state set_powergating_state;
659 cgs_set_clockgating_state set_clockgating_state;
Rex Zhu47bf18b2015-09-17 16:34:14 +0800660 /* display manager */
661 cgs_get_active_displays_info get_active_displays_info;
Rex Zhu4c900802016-03-29 14:20:37 +0800662 /* notify dpm enabled */
663 cgs_notify_dpm_enabled notify_dpm_enabled;
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800664 /* ACPI */
665 cgs_call_acpi_method call_acpi_method;
Rex Zhu5e618692015-09-23 20:11:54 +0800666 /* get system info */
667 cgs_query_system_info query_system_info;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400668};
669
670struct cgs_os_ops; /* To be define in OS-specific CGS header */
671
672struct cgs_device
673{
674 const struct cgs_ops *ops;
675 const struct cgs_os_ops *os_ops;
676 /* to be embedded at the start of driver private structure */
677};
678
679/* Convenience macros that make CGS indirect function calls look like
680 * normal function calls */
681#define CGS_CALL(func,dev,...) \
682 (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
683#define CGS_OS_CALL(func,dev,...) \
684 (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
685
686#define cgs_gpu_mem_info(dev,type,mc_start,mc_size,mem_size) \
687 CGS_CALL(gpu_mem_info,dev,type,mc_start,mc_size,mem_size)
688#define cgs_gmap_kmem(dev,kmem,size,min_off,max_off,kmem_handle,mcaddr) \
689 CGS_CALL(gmap_kmem,dev,kmem,size,min_off,max_off,kmem_handle,mcaddr)
Jammy Zhou97baee72015-07-21 17:02:44 +0800690#define cgs_gunmap_kmem(dev,kmem_handle) \
Chunming Zhoud03846a2015-07-28 14:20:03 -0400691 CGS_CALL(gunmap_kmem,dev,keme_handle)
692#define cgs_alloc_gpu_mem(dev,type,size,align,min_off,max_off,handle) \
693 CGS_CALL(alloc_gpu_mem,dev,type,size,align,min_off,max_off,handle)
694#define cgs_free_gpu_mem(dev,handle) \
695 CGS_CALL(free_gpu_mem,dev,handle)
696#define cgs_gmap_gpu_mem(dev,handle,mcaddr) \
697 CGS_CALL(gmap_gpu_mem,dev,handle,mcaddr)
Jammy Zhou97baee72015-07-21 17:02:44 +0800698#define cgs_gunmap_gpu_mem(dev,handle) \
Chunming Zhoud03846a2015-07-28 14:20:03 -0400699 CGS_CALL(gunmap_gpu_mem,dev,handle)
700#define cgs_kmap_gpu_mem(dev,handle,map) \
701 CGS_CALL(kmap_gpu_mem,dev,handle,map)
702#define cgs_kunmap_gpu_mem(dev,handle) \
703 CGS_CALL(kunmap_gpu_mem,dev,handle)
704
705#define cgs_read_register(dev,offset) \
706 CGS_CALL(read_register,dev,offset)
707#define cgs_write_register(dev,offset,value) \
708 CGS_CALL(write_register,dev,offset,value)
709#define cgs_read_ind_register(dev,space,index) \
710 CGS_CALL(read_ind_register,dev,space,index)
711#define cgs_write_ind_register(dev,space,index,value) \
712 CGS_CALL(write_ind_register,dev,space,index,value)
713
714#define cgs_read_pci_config_byte(dev,addr) \
715 CGS_CALL(read_pci_config_byte,dev,addr)
716#define cgs_read_pci_config_word(dev,addr) \
717 CGS_CALL(read_pci_config_word,dev,addr)
718#define cgs_read_pci_config_dword(dev,addr) \
719 CGS_CALL(read_pci_config_dword,dev,addr)
720#define cgs_write_pci_config_byte(dev,addr,value) \
721 CGS_CALL(write_pci_config_byte,dev,addr,value)
722#define cgs_write_pci_config_word(dev,addr,value) \
723 CGS_CALL(write_pci_config_word,dev,addr,value)
724#define cgs_write_pci_config_dword(dev,addr,value) \
725 CGS_CALL(write_pci_config_dword,dev,addr,value)
726
727#define cgs_atom_get_data_table(dev,table,size,frev,crev) \
728 CGS_CALL(atom_get_data_table,dev,table,size,frev,crev)
729#define cgs_atom_get_cmd_table_revs(dev,table,frev,crev) \
730 CGS_CALL(atom_get_cmd_table_revs,dev,table,frev,crev)
731#define cgs_atom_exec_cmd_table(dev,table,args) \
732 CGS_CALL(atom_exec_cmd_table,dev,table,args)
733
734#define cgs_create_pm_request(dev,request) \
735 CGS_CALL(create_pm_request,dev,request)
736#define cgs_destroy_pm_request(dev,request) \
737 CGS_CALL(destroy_pm_request,dev,request)
738#define cgs_set_pm_request(dev,request,active) \
739 CGS_CALL(set_pm_request,dev,request,active)
740#define cgs_pm_request_clock(dev,request,clock,freq) \
741 CGS_CALL(pm_request_clock,dev,request,clock,freq)
742#define cgs_pm_request_engine(dev,request,engine,powered) \
743 CGS_CALL(pm_request_engine,dev,request,engine,powered)
744#define cgs_pm_query_clock_limits(dev,clock,limits) \
745 CGS_CALL(pm_query_clock_limits,dev,clock,limits)
746#define cgs_set_camera_voltages(dev,mask,voltages) \
747 CGS_CALL(set_camera_voltages,dev,mask,voltages)
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800748#define cgs_get_firmware_info(dev, type, info) \
749 CGS_CALL(get_firmware_info, dev, type, info)
Monk Liua3927462016-05-31 13:44:30 +0800750#define cgs_rel_firmware(dev, type) \
751 CGS_CALL(rel_firmware, dev, type)
rezhu404b2fa2015-08-07 13:37:56 +0800752#define cgs_set_powergating_state(dev, block_type, state) \
753 CGS_CALL(set_powergating_state, dev, block_type, state)
754#define cgs_set_clockgating_state(dev, block_type, state) \
755 CGS_CALL(set_clockgating_state, dev, block_type, state)
Rex Zhu4c900802016-03-29 14:20:37 +0800756#define cgs_notify_dpm_enabled(dev, enabled) \
757 CGS_CALL(notify_dpm_enabled, dev, enabled)
758
Rex Zhu47bf18b2015-09-17 16:34:14 +0800759#define cgs_get_active_displays_info(dev, info) \
760 CGS_CALL(get_active_displays_info, dev, info)
Rex Zhu4c900802016-03-29 14:20:37 +0800761
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800762#define cgs_call_acpi_method(dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size) \
763 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 +0800764#define cgs_query_system_info(dev, sys_info) \
765 CGS_CALL(query_system_info, dev, sys_info)
Alex Deucherba228ac2015-12-23 11:25:43 -0500766#define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \
767 resource_base) \
768 CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
769 resource_base)
Chunming Zhoud03846a2015-07-28 14:20:03 -0400770
771#endif /* _CGS_COMMON_H */