blob: 7a3714b8b45cb5f40e94ef2f5e892cbc90194cbc [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,
52 CGS_IND_REG__AUDIO_ENDPT
53};
54
55/**
56 * enum cgs_clock - Clocks controlled by the SMU
57 */
58enum cgs_clock {
59 CGS_CLOCK__SCLK,
60 CGS_CLOCK__MCLK,
61 CGS_CLOCK__VCLK,
62 CGS_CLOCK__DCLK,
63 CGS_CLOCK__ECLK,
64 CGS_CLOCK__ACLK,
65 CGS_CLOCK__ICLK,
66 /* ... */
67};
68
69/**
70 * enum cgs_engine - Engines that can be statically power-gated
71 */
72enum cgs_engine {
73 CGS_ENGINE__UVD,
74 CGS_ENGINE__VCE,
75 CGS_ENGINE__VP8,
76 CGS_ENGINE__ACP_DMA,
77 CGS_ENGINE__ACP_DSP0,
78 CGS_ENGINE__ACP_DSP1,
79 CGS_ENGINE__ISP,
80 /* ... */
81};
82
83/**
84 * enum cgs_voltage_planes - Voltage planes for external camera HW
85 */
86enum cgs_voltage_planes {
87 CGS_VOLTAGE_PLANE__SENSOR0,
88 CGS_VOLTAGE_PLANE__SENSOR1,
89 /* ... */
90};
91
Jammy Zhoubf3911b02015-05-13 18:58:05 +080092/*
93 * enum cgs_ucode_id - Firmware types for different IPs
94 */
95enum cgs_ucode_id {
96 CGS_UCODE_ID_SMU = 0,
yanyang1735f0022016-02-05 17:39:37 +080097 CGS_UCODE_ID_SMU_SK,
Jammy Zhoubf3911b02015-05-13 18:58:05 +080098 CGS_UCODE_ID_SDMA0,
99 CGS_UCODE_ID_SDMA1,
100 CGS_UCODE_ID_CP_CE,
101 CGS_UCODE_ID_CP_PFP,
102 CGS_UCODE_ID_CP_ME,
103 CGS_UCODE_ID_CP_MEC,
104 CGS_UCODE_ID_CP_MEC_JT1,
105 CGS_UCODE_ID_CP_MEC_JT2,
106 CGS_UCODE_ID_GMCON_RENG,
107 CGS_UCODE_ID_RLC_G,
108 CGS_UCODE_ID_MAXIMUM,
109};
110
Rex Zhu5e618692015-09-23 20:11:54 +0800111enum cgs_system_info_id {
112 CGS_SYSTEM_INFO_ADAPTER_BDF_ID = 1,
Alex Deuchercfd316d2015-11-11 20:35:32 -0500113 CGS_SYSTEM_INFO_PCIE_GEN_INFO,
114 CGS_SYSTEM_INFO_PCIE_MLW,
Alex Deucher08d33402016-02-05 10:34:28 -0500115 CGS_SYSTEM_INFO_CG_FLAGS,
116 CGS_SYSTEM_INFO_PG_FLAGS,
Rex Zhu5e618692015-09-23 20:11:54 +0800117 CGS_SYSTEM_INFO_ID_MAXIMUM,
118};
119
120struct cgs_system_info {
121 uint64_t size;
122 uint64_t info_id;
123 union {
124 void *ptr;
125 uint64_t value;
126 };
127 uint64_t padding[13];
128};
129
Alex Deucherba228ac2015-12-23 11:25:43 -0500130/*
131 * enum cgs_resource_type - GPU resource type
132 */
133enum cgs_resource_type {
134 CGS_RESOURCE_TYPE_MMIO = 0,
135 CGS_RESOURCE_TYPE_FB,
136 CGS_RESOURCE_TYPE_IO,
137 CGS_RESOURCE_TYPE_DOORBELL,
138 CGS_RESOURCE_TYPE_ROM,
139};
140
Chunming Zhoud03846a2015-07-28 14:20:03 -0400141/**
142 * struct cgs_clock_limits - Clock limits
143 *
144 * Clocks are specified in 10KHz units.
145 */
146struct cgs_clock_limits {
147 unsigned min; /**< Minimum supported frequency */
148 unsigned max; /**< Maxumim supported frequency */
149 unsigned sustainable; /**< Thermally sustainable frequency */
150};
151
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800152/**
153 * struct cgs_firmware_info - Firmware information
154 */
155struct cgs_firmware_info {
156 uint16_t version;
157 uint16_t feature_version;
158 uint32_t image_size;
159 uint64_t mc_addr;
160 void *kptr;
161};
162
Rex Zhu47bf18b2015-09-17 16:34:14 +0800163struct cgs_mode_info {
164 uint32_t refresh_rate;
165 uint32_t ref_clock;
166 uint32_t vblank_time_us;
167};
168
169struct cgs_display_info {
170 uint32_t display_count;
171 uint32_t active_display_mask;
172 struct cgs_mode_info *mode_info;
173};
174
Chunming Zhoud03846a2015-07-28 14:20:03 -0400175typedef unsigned long cgs_handle_t;
176
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800177#define CGS_ACPI_METHOD_ATCS 0x53435441
178#define CGS_ACPI_METHOD_ATIF 0x46495441
179#define CGS_ACPI_METHOD_ATPX 0x58505441
180#define CGS_ACPI_FIELD_METHOD_NAME 0x00000001
181#define CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT 0x00000002
182#define CGS_ACPI_MAX_BUFFER_SIZE 256
183#define CGS_ACPI_TYPE_ANY 0x00
184#define CGS_ACPI_TYPE_INTEGER 0x01
185#define CGS_ACPI_TYPE_STRING 0x02
186#define CGS_ACPI_TYPE_BUFFER 0x03
187#define CGS_ACPI_TYPE_PACKAGE 0x04
188
189struct cgs_acpi_method_argument {
190 uint32_t type;
191 uint32_t method_length;
192 uint32_t data_length;
193 union{
194 uint32_t value;
195 void *pointer;
196 };
197};
198
199struct cgs_acpi_method_info {
200 uint32_t size;
201 uint32_t field;
202 uint32_t input_count;
203 uint32_t name;
204 struct cgs_acpi_method_argument *pinput_argument;
205 uint32_t output_count;
206 struct cgs_acpi_method_argument *poutput_argument;
207 uint32_t padding[9];
208};
209
Chunming Zhoud03846a2015-07-28 14:20:03 -0400210/**
211 * cgs_gpu_mem_info() - Return information about memory heaps
212 * @cgs_device: opaque device handle
213 * @type: memory type
214 * @mc_start: Start MC address of the heap (output)
215 * @mc_size: MC address space size (output)
216 * @mem_size: maximum amount of memory available for allocation (output)
217 *
218 * This function returns information about memory heaps. The type
219 * parameter is used to select the memory heap. The mc_start and
220 * mc_size for GART heaps may be bigger than the memory available for
221 * allocation.
222 *
223 * mc_start and mc_size are undefined for non-contiguous FB memory
224 * types, since buffers allocated with these types may or may not be
225 * GART mapped.
226 *
227 * Return: 0 on success, -errno otherwise
228 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000229typedef int (*cgs_gpu_mem_info_t)(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400230 uint64_t *mc_start, uint64_t *mc_size,
231 uint64_t *mem_size);
232
233/**
234 * cgs_gmap_kmem() - map kernel memory to GART aperture
235 * @cgs_device: opaque device handle
236 * @kmem: pointer to kernel memory
237 * @size: size to map
238 * @min_offset: minimum offset from start of GART aperture
239 * @max_offset: maximum offset from start of GART aperture
240 * @kmem_handle: kernel memory handle (output)
241 * @mcaddr: MC address (output)
242 *
243 * Return: 0 on success, -errno otherwise
244 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000245typedef int (*cgs_gmap_kmem_t)(struct cgs_device *cgs_device, void *kmem, uint64_t size,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400246 uint64_t min_offset, uint64_t max_offset,
247 cgs_handle_t *kmem_handle, uint64_t *mcaddr);
248
249/**
250 * cgs_gunmap_kmem() - unmap kernel memory
251 * @cgs_device: opaque device handle
252 * @kmem_handle: kernel memory handle returned by gmap_kmem
253 *
254 * Return: 0 on success, -errno otherwise
255 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000256typedef int (*cgs_gunmap_kmem_t)(struct cgs_device *cgs_device, cgs_handle_t kmem_handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400257
258/**
259 * cgs_alloc_gpu_mem() - Allocate GPU memory
260 * @cgs_device: opaque device handle
261 * @type: memory type
262 * @size: size in bytes
263 * @align: alignment in bytes
264 * @min_offset: minimum offset from start of heap
265 * @max_offset: maximum offset from start of heap
266 * @handle: memory handle (output)
267 *
268 * The memory types CGS_GPU_MEM_TYPE_*_CONTIG_FB force contiguous
269 * memory allocation. This guarantees that the MC address returned by
270 * cgs_gmap_gpu_mem is not mapped through the GART. The non-contiguous
271 * FB memory types may be GART mapped depending on memory
272 * fragmentation and memory allocator policies.
273 *
274 * If min/max_offset are non-0, the allocation will be forced to
275 * reside between these offsets in its respective memory heap. The
276 * base address that the offset relates to, depends on the memory
277 * type.
278 *
279 * - CGS_GPU_MEM_TYPE__*_CONTIG_FB: FB MC base address
280 * - CGS_GPU_MEM_TYPE__GART_*: GART aperture base address
281 * - others: undefined, don't use with max_offset
282 *
283 * Return: 0 on success, -errno otherwise
284 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000285typedef int (*cgs_alloc_gpu_mem_t)(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400286 uint64_t size, uint64_t align,
287 uint64_t min_offset, uint64_t max_offset,
288 cgs_handle_t *handle);
289
290/**
291 * cgs_free_gpu_mem() - Free GPU memory
292 * @cgs_device: opaque device handle
293 * @handle: memory handle returned by alloc or import
294 *
295 * Return: 0 on success, -errno otherwise
296 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000297typedef int (*cgs_free_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400298
299/**
300 * cgs_gmap_gpu_mem() - GPU-map GPU memory
301 * @cgs_device: opaque device handle
302 * @handle: memory handle returned by alloc or import
303 * @mcaddr: MC address (output)
304 *
305 * Ensures that a buffer is GPU accessible and returns its MC address.
306 *
307 * Return: 0 on success, -errno otherwise
308 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000309typedef int (*cgs_gmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400310 uint64_t *mcaddr);
311
312/**
313 * cgs_gunmap_gpu_mem() - GPU-unmap GPU memory
314 * @cgs_device: opaque device handle
315 * @handle: memory handle returned by alloc or import
316 *
317 * Allows the buffer to be migrated while it's not used by the GPU.
318 *
319 * Return: 0 on success, -errno otherwise
320 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000321typedef int (*cgs_gunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400322
323/**
324 * cgs_kmap_gpu_mem() - Kernel-map GPU memory
325 *
326 * @cgs_device: opaque device handle
327 * @handle: memory handle returned by alloc or import
328 * @map: Kernel virtual address the memory was mapped to (output)
329 *
330 * Return: 0 on success, -errno otherwise
331 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000332typedef int (*cgs_kmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400333 void **map);
334
335/**
336 * cgs_kunmap_gpu_mem() - Kernel-unmap GPU memory
337 * @cgs_device: opaque device handle
338 * @handle: memory handle returned by alloc or import
339 *
340 * Return: 0 on success, -errno otherwise
341 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000342typedef int (*cgs_kunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400343
344/**
345 * cgs_read_register() - Read an MMIO register
346 * @cgs_device: opaque device handle
347 * @offset: register offset
348 *
349 * Return: register value
350 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000351typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400352
353/**
354 * cgs_write_register() - Write an MMIO register
355 * @cgs_device: opaque device handle
356 * @offset: register offset
357 * @value: register value
358 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000359typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400360 uint32_t value);
361
362/**
363 * cgs_read_ind_register() - Read an indirect register
364 * @cgs_device: opaque device handle
365 * @offset: register offset
366 *
367 * Return: register value
368 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000369typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400370 unsigned index);
371
372/**
373 * cgs_write_ind_register() - Write an indirect register
374 * @cgs_device: opaque device handle
375 * @offset: register offset
376 * @value: register value
377 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000378typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400379 unsigned index, uint32_t value);
380
381/**
382 * cgs_read_pci_config_byte() - Read byte from PCI configuration space
383 * @cgs_device: opaque device handle
384 * @addr: address
385 *
386 * Return: Value read
387 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000388typedef uint8_t (*cgs_read_pci_config_byte_t)(struct cgs_device *cgs_device, unsigned addr);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400389
390/**
391 * cgs_read_pci_config_word() - Read word from PCI configuration space
392 * @cgs_device: opaque device handle
393 * @addr: address, must be word-aligned
394 *
395 * Return: Value read
396 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000397typedef uint16_t (*cgs_read_pci_config_word_t)(struct cgs_device *cgs_device, unsigned addr);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400398
399/**
400 * cgs_read_pci_config_dword() - Read dword from PCI configuration space
401 * @cgs_device: opaque device handle
402 * @addr: address, must be dword-aligned
403 *
404 * Return: Value read
405 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000406typedef uint32_t (*cgs_read_pci_config_dword_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400407 unsigned addr);
408
409/**
410 * cgs_write_pci_config_byte() - Write byte to PCI configuration space
411 * @cgs_device: opaque device handle
412 * @addr: address
413 * @value: value to write
414 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000415typedef void (*cgs_write_pci_config_byte_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400416 uint8_t value);
417
418/**
419 * cgs_write_pci_config_word() - Write byte to PCI configuration space
420 * @cgs_device: opaque device handle
421 * @addr: address, must be word-aligned
422 * @value: value to write
423 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000424typedef void (*cgs_write_pci_config_word_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400425 uint16_t value);
426
427/**
428 * cgs_write_pci_config_dword() - Write byte to PCI configuration space
429 * @cgs_device: opaque device handle
430 * @addr: address, must be dword-aligned
431 * @value: value to write
432 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000433typedef void (*cgs_write_pci_config_dword_t)(struct cgs_device *cgs_device, unsigned addr,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400434 uint32_t value);
435
Alex Deucherba228ac2015-12-23 11:25:43 -0500436
437/**
438 * cgs_get_pci_resource() - provide access to a device resource (PCI BAR)
439 * @cgs_device: opaque device handle
440 * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL)
441 * @size: size of the region
442 * @offset: offset from the start of the region
443 * @resource_base: base address (not including offset) returned
444 *
445 * Return: 0 on success, -errno otherwise
446 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000447typedef int (*cgs_get_pci_resource_t)(struct cgs_device *cgs_device,
Alex Deucherba228ac2015-12-23 11:25:43 -0500448 enum cgs_resource_type resource_type,
449 uint64_t size,
450 uint64_t offset,
451 uint64_t *resource_base);
452
Chunming Zhoud03846a2015-07-28 14:20:03 -0400453/**
454 * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table
455 * @cgs_device: opaque device handle
456 * @table: data table index
457 * @size: size of the table (output, may be NULL)
458 * @frev: table format revision (output, may be NULL)
459 * @crev: table content revision (output, may be NULL)
460 *
461 * Return: Pointer to start of the table, or NULL on failure
462 */
463typedef const void *(*cgs_atom_get_data_table_t)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000464 struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400465 uint16_t *size, uint8_t *frev, uint8_t *crev);
466
467/**
468 * cgs_atom_get_cmd_table_revs() - Get ATOM BIOS command table revisions
469 * @cgs_device: opaque device handle
470 * @table: data table index
471 * @frev: table format revision (output, may be NULL)
472 * @crev: table content revision (output, may be NULL)
473 *
474 * Return: 0 on success, -errno otherwise
475 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000476typedef int (*cgs_atom_get_cmd_table_revs_t)(struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400477 uint8_t *frev, uint8_t *crev);
478
479/**
480 * cgs_atom_exec_cmd_table() - Execute an ATOM BIOS command table
481 * @cgs_device: opaque device handle
482 * @table: command table index
483 * @args: arguments
484 *
485 * Return: 0 on success, -errno otherwise
486 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000487typedef int (*cgs_atom_exec_cmd_table_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400488 unsigned table, void *args);
489
490/**
491 * cgs_create_pm_request() - Create a power management request
492 * @cgs_device: opaque device handle
493 * @request: handle of created PM request (output)
494 *
495 * Return: 0 on success, -errno otherwise
496 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000497typedef int (*cgs_create_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t *request);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400498
499/**
500 * cgs_destroy_pm_request() - Destroy a power management request
501 * @cgs_device: opaque device handle
502 * @request: handle of created PM request
503 *
504 * Return: 0 on success, -errno otherwise
505 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000506typedef int (*cgs_destroy_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t request);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400507
508/**
509 * cgs_set_pm_request() - Activate or deactiveate a PM request
510 * @cgs_device: opaque device handle
511 * @request: PM request handle
512 * @active: 0 = deactivate, non-0 = activate
513 *
514 * While a PM request is active, its minimum clock requests are taken
515 * into account as the requested engines are powered up. When the
516 * request is inactive, the engines may be powered down and clocks may
517 * be lower, depending on other PM requests by other driver
518 * components.
519 *
520 * Return: 0 on success, -errno otherwise
521 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000522typedef int (*cgs_set_pm_request_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400523 int active);
524
525/**
526 * cgs_pm_request_clock() - Request a minimum frequency for a specific clock
527 * @cgs_device: opaque device handle
528 * @request: PM request handle
529 * @clock: which clock?
530 * @freq: requested min. frequency in 10KHz units (0 to clear request)
531 *
532 * Return: 0 on success, -errno otherwise
533 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000534typedef int (*cgs_pm_request_clock_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400535 enum cgs_clock clock, unsigned freq);
536
537/**
538 * cgs_pm_request_engine() - Request an engine to be powered up
539 * @cgs_device: opaque device handle
540 * @request: PM request handle
541 * @engine: which engine?
542 * @powered: 0 = powered down, non-0 = powered up
543 *
544 * Return: 0 on success, -errno otherwise
545 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000546typedef int (*cgs_pm_request_engine_t)(struct cgs_device *cgs_device, cgs_handle_t request,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400547 enum cgs_engine engine, int powered);
548
549/**
550 * cgs_pm_query_clock_limits() - Query clock frequency limits
551 * @cgs_device: opaque device handle
552 * @clock: which clock?
553 * @limits: clock limits
554 *
555 * Return: 0 on success, -errno otherwise
556 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000557typedef int (*cgs_pm_query_clock_limits_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400558 enum cgs_clock clock,
559 struct cgs_clock_limits *limits);
560
561/**
562 * cgs_set_camera_voltages() - Apply specific voltages to PMIC voltage planes
563 * @cgs_device: opaque device handle
564 * @mask: bitmask of voltages to change (1<<CGS_VOLTAGE_PLANE__xyz|...)
565 * @voltages: pointer to array of voltage values in 1mV units
566 *
567 * Return: 0 on success, -errno otherwise
568 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000569typedef int (*cgs_set_camera_voltages_t)(struct cgs_device *cgs_device, uint32_t mask,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400570 const uint32_t *voltages);
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800571/**
572 * cgs_get_firmware_info - Get the firmware information from core driver
573 * @cgs_device: opaque device handle
574 * @type: the firmware type
575 * @info: returend firmware information
576 *
577 * Return: 0 on success, -errno otherwise
578 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000579typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800580 enum cgs_ucode_id type,
581 struct cgs_firmware_info *info);
582
Dave Airlie110e6f22016-04-12 13:25:48 +1000583typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800584 enum amd_ip_block_type block_type,
585 enum amd_powergating_state state);
586
Dave Airlie110e6f22016-04-12 13:25:48 +1000587typedef int(*cgs_set_clockgating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800588 enum amd_ip_block_type block_type,
589 enum amd_clockgating_state state);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400590
Rex Zhu47bf18b2015-09-17 16:34:14 +0800591typedef int(*cgs_get_active_displays_info)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000592 struct cgs_device *cgs_device,
Rex Zhu47bf18b2015-09-17 16:34:14 +0800593 struct cgs_display_info *info);
594
Dave Airlie110e6f22016-04-12 13:25:48 +1000595typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
Rex Zhu4c900802016-03-29 14:20:37 +0800596
Dave Airlie110e6f22016-04-12 13:25:48 +1000597typedef int (*cgs_call_acpi_method)(struct cgs_device *cgs_device,
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800598 uint32_t acpi_method,
599 uint32_t acpi_function,
600 void *pinput, void *poutput,
601 uint32_t output_count,
602 uint32_t input_size,
603 uint32_t output_size);
Rex Zhu5e618692015-09-23 20:11:54 +0800604
Dave Airlie110e6f22016-04-12 13:25:48 +1000605typedef int (*cgs_query_system_info)(struct cgs_device *cgs_device,
Rex Zhu5e618692015-09-23 20:11:54 +0800606 struct cgs_system_info *sys_info);
607
Chunming Zhoud03846a2015-07-28 14:20:03 -0400608struct cgs_ops {
609 /* memory management calls (similar to KFD interface) */
610 cgs_gpu_mem_info_t gpu_mem_info;
611 cgs_gmap_kmem_t gmap_kmem;
612 cgs_gunmap_kmem_t gunmap_kmem;
613 cgs_alloc_gpu_mem_t alloc_gpu_mem;
614 cgs_free_gpu_mem_t free_gpu_mem;
615 cgs_gmap_gpu_mem_t gmap_gpu_mem;
616 cgs_gunmap_gpu_mem_t gunmap_gpu_mem;
617 cgs_kmap_gpu_mem_t kmap_gpu_mem;
618 cgs_kunmap_gpu_mem_t kunmap_gpu_mem;
619 /* MMIO access */
620 cgs_read_register_t read_register;
621 cgs_write_register_t write_register;
622 cgs_read_ind_register_t read_ind_register;
623 cgs_write_ind_register_t write_ind_register;
624 /* PCI configuration space access */
625 cgs_read_pci_config_byte_t read_pci_config_byte;
626 cgs_read_pci_config_word_t read_pci_config_word;
627 cgs_read_pci_config_dword_t read_pci_config_dword;
628 cgs_write_pci_config_byte_t write_pci_config_byte;
629 cgs_write_pci_config_word_t write_pci_config_word;
630 cgs_write_pci_config_dword_t write_pci_config_dword;
Alex Deucherba228ac2015-12-23 11:25:43 -0500631 /* PCI resources */
632 cgs_get_pci_resource_t get_pci_resource;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400633 /* ATOM BIOS */
634 cgs_atom_get_data_table_t atom_get_data_table;
635 cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs;
636 cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
637 /* Power management */
638 cgs_create_pm_request_t create_pm_request;
639 cgs_destroy_pm_request_t destroy_pm_request;
640 cgs_set_pm_request_t set_pm_request;
641 cgs_pm_request_clock_t pm_request_clock;
642 cgs_pm_request_engine_t pm_request_engine;
643 cgs_pm_query_clock_limits_t pm_query_clock_limits;
644 cgs_set_camera_voltages_t set_camera_voltages;
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800645 /* Firmware Info */
646 cgs_get_firmware_info get_firmware_info;
rezhu404b2fa2015-08-07 13:37:56 +0800647 /* cg pg interface*/
648 cgs_set_powergating_state set_powergating_state;
649 cgs_set_clockgating_state set_clockgating_state;
Rex Zhu47bf18b2015-09-17 16:34:14 +0800650 /* display manager */
651 cgs_get_active_displays_info get_active_displays_info;
Rex Zhu4c900802016-03-29 14:20:37 +0800652 /* notify dpm enabled */
653 cgs_notify_dpm_enabled notify_dpm_enabled;
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800654 /* ACPI */
655 cgs_call_acpi_method call_acpi_method;
Rex Zhu5e618692015-09-23 20:11:54 +0800656 /* get system info */
657 cgs_query_system_info query_system_info;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400658};
659
660struct cgs_os_ops; /* To be define in OS-specific CGS header */
661
662struct cgs_device
663{
664 const struct cgs_ops *ops;
665 const struct cgs_os_ops *os_ops;
666 /* to be embedded at the start of driver private structure */
667};
668
669/* Convenience macros that make CGS indirect function calls look like
670 * normal function calls */
671#define CGS_CALL(func,dev,...) \
672 (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
673#define CGS_OS_CALL(func,dev,...) \
674 (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
675
676#define cgs_gpu_mem_info(dev,type,mc_start,mc_size,mem_size) \
677 CGS_CALL(gpu_mem_info,dev,type,mc_start,mc_size,mem_size)
678#define cgs_gmap_kmem(dev,kmem,size,min_off,max_off,kmem_handle,mcaddr) \
679 CGS_CALL(gmap_kmem,dev,kmem,size,min_off,max_off,kmem_handle,mcaddr)
Jammy Zhou97baee72015-07-21 17:02:44 +0800680#define cgs_gunmap_kmem(dev,kmem_handle) \
Chunming Zhoud03846a2015-07-28 14:20:03 -0400681 CGS_CALL(gunmap_kmem,dev,keme_handle)
682#define cgs_alloc_gpu_mem(dev,type,size,align,min_off,max_off,handle) \
683 CGS_CALL(alloc_gpu_mem,dev,type,size,align,min_off,max_off,handle)
684#define cgs_free_gpu_mem(dev,handle) \
685 CGS_CALL(free_gpu_mem,dev,handle)
686#define cgs_gmap_gpu_mem(dev,handle,mcaddr) \
687 CGS_CALL(gmap_gpu_mem,dev,handle,mcaddr)
Jammy Zhou97baee72015-07-21 17:02:44 +0800688#define cgs_gunmap_gpu_mem(dev,handle) \
Chunming Zhoud03846a2015-07-28 14:20:03 -0400689 CGS_CALL(gunmap_gpu_mem,dev,handle)
690#define cgs_kmap_gpu_mem(dev,handle,map) \
691 CGS_CALL(kmap_gpu_mem,dev,handle,map)
692#define cgs_kunmap_gpu_mem(dev,handle) \
693 CGS_CALL(kunmap_gpu_mem,dev,handle)
694
695#define cgs_read_register(dev,offset) \
696 CGS_CALL(read_register,dev,offset)
697#define cgs_write_register(dev,offset,value) \
698 CGS_CALL(write_register,dev,offset,value)
699#define cgs_read_ind_register(dev,space,index) \
700 CGS_CALL(read_ind_register,dev,space,index)
701#define cgs_write_ind_register(dev,space,index,value) \
702 CGS_CALL(write_ind_register,dev,space,index,value)
703
704#define cgs_read_pci_config_byte(dev,addr) \
705 CGS_CALL(read_pci_config_byte,dev,addr)
706#define cgs_read_pci_config_word(dev,addr) \
707 CGS_CALL(read_pci_config_word,dev,addr)
708#define cgs_read_pci_config_dword(dev,addr) \
709 CGS_CALL(read_pci_config_dword,dev,addr)
710#define cgs_write_pci_config_byte(dev,addr,value) \
711 CGS_CALL(write_pci_config_byte,dev,addr,value)
712#define cgs_write_pci_config_word(dev,addr,value) \
713 CGS_CALL(write_pci_config_word,dev,addr,value)
714#define cgs_write_pci_config_dword(dev,addr,value) \
715 CGS_CALL(write_pci_config_dword,dev,addr,value)
716
717#define cgs_atom_get_data_table(dev,table,size,frev,crev) \
718 CGS_CALL(atom_get_data_table,dev,table,size,frev,crev)
719#define cgs_atom_get_cmd_table_revs(dev,table,frev,crev) \
720 CGS_CALL(atom_get_cmd_table_revs,dev,table,frev,crev)
721#define cgs_atom_exec_cmd_table(dev,table,args) \
722 CGS_CALL(atom_exec_cmd_table,dev,table,args)
723
724#define cgs_create_pm_request(dev,request) \
725 CGS_CALL(create_pm_request,dev,request)
726#define cgs_destroy_pm_request(dev,request) \
727 CGS_CALL(destroy_pm_request,dev,request)
728#define cgs_set_pm_request(dev,request,active) \
729 CGS_CALL(set_pm_request,dev,request,active)
730#define cgs_pm_request_clock(dev,request,clock,freq) \
731 CGS_CALL(pm_request_clock,dev,request,clock,freq)
732#define cgs_pm_request_engine(dev,request,engine,powered) \
733 CGS_CALL(pm_request_engine,dev,request,engine,powered)
734#define cgs_pm_query_clock_limits(dev,clock,limits) \
735 CGS_CALL(pm_query_clock_limits,dev,clock,limits)
736#define cgs_set_camera_voltages(dev,mask,voltages) \
737 CGS_CALL(set_camera_voltages,dev,mask,voltages)
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800738#define cgs_get_firmware_info(dev, type, info) \
739 CGS_CALL(get_firmware_info, dev, type, info)
rezhu404b2fa2015-08-07 13:37:56 +0800740#define cgs_set_powergating_state(dev, block_type, state) \
741 CGS_CALL(set_powergating_state, dev, block_type, state)
742#define cgs_set_clockgating_state(dev, block_type, state) \
743 CGS_CALL(set_clockgating_state, dev, block_type, state)
Rex Zhu4c900802016-03-29 14:20:37 +0800744#define cgs_notify_dpm_enabled(dev, enabled) \
745 CGS_CALL(notify_dpm_enabled, dev, enabled)
746
Rex Zhu47bf18b2015-09-17 16:34:14 +0800747#define cgs_get_active_displays_info(dev, info) \
748 CGS_CALL(get_active_displays_info, dev, info)
Rex Zhu4c900802016-03-29 14:20:37 +0800749
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800750#define cgs_call_acpi_method(dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size) \
751 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 +0800752#define cgs_query_system_info(dev, sys_info) \
753 CGS_CALL(query_system_info, dev, sys_info)
Alex Deucherba228ac2015-12-23 11:25:43 -0500754#define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \
755 resource_base) \
756 CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
757 resource_base)
Chunming Zhoud03846a2015-07-28 14:20:03 -0400758
759#endif /* _CGS_COMMON_H */