blob: f5c73970ab886d8ce9445789f6df835608e0e068 [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,
Evan Quanc62a59d2017-07-04 09:24:34 +080053 CGS_IND_REG_SE_CAC,
Chunming Zhoud03846a2015-07-28 14:20:03 -040054 CGS_IND_REG__AUDIO_ENDPT
55};
56
57/**
Chunming Zhoud03846a2015-07-28 14:20:03 -040058 * enum cgs_engine - Engines that can be statically power-gated
59 */
60enum cgs_engine {
61 CGS_ENGINE__UVD,
62 CGS_ENGINE__VCE,
63 CGS_ENGINE__VP8,
64 CGS_ENGINE__ACP_DMA,
65 CGS_ENGINE__ACP_DSP0,
66 CGS_ENGINE__ACP_DSP1,
67 CGS_ENGINE__ISP,
68 /* ... */
69};
70
Jammy Zhoubf3911b02015-05-13 18:58:05 +080071/*
72 * enum cgs_ucode_id - Firmware types for different IPs
73 */
74enum cgs_ucode_id {
75 CGS_UCODE_ID_SMU = 0,
yanyang1735f0022016-02-05 17:39:37 +080076 CGS_UCODE_ID_SMU_SK,
Jammy Zhoubf3911b02015-05-13 18:58:05 +080077 CGS_UCODE_ID_SDMA0,
78 CGS_UCODE_ID_SDMA1,
79 CGS_UCODE_ID_CP_CE,
80 CGS_UCODE_ID_CP_PFP,
81 CGS_UCODE_ID_CP_ME,
82 CGS_UCODE_ID_CP_MEC,
83 CGS_UCODE_ID_CP_MEC_JT1,
84 CGS_UCODE_ID_CP_MEC_JT2,
85 CGS_UCODE_ID_GMCON_RENG,
86 CGS_UCODE_ID_RLC_G,
Monk Liubed57122016-09-26 16:35:03 +080087 CGS_UCODE_ID_STORAGE,
Jammy Zhoubf3911b02015-05-13 18:58:05 +080088 CGS_UCODE_ID_MAXIMUM,
89};
90
Rex Zhu5e618692015-09-23 20:11:54 +080091enum cgs_system_info_id {
92 CGS_SYSTEM_INFO_ADAPTER_BDF_ID = 1,
Alex Deuchercfd316d2015-11-11 20:35:32 -050093 CGS_SYSTEM_INFO_PCIE_GEN_INFO,
94 CGS_SYSTEM_INFO_PCIE_MLW,
Huang Rui09fc7ef2016-07-12 13:54:05 +080095 CGS_SYSTEM_INFO_PCIE_DEV,
96 CGS_SYSTEM_INFO_PCIE_REV,
Alex Deucher08d33402016-02-05 10:34:28 -050097 CGS_SYSTEM_INFO_CG_FLAGS,
98 CGS_SYSTEM_INFO_PG_FLAGS,
Eric Huangbacec892016-03-17 18:29:08 -040099 CGS_SYSTEM_INFO_GFX_CU_INFO,
Rex Zhud826c982016-06-07 20:15:24 +0800100 CGS_SYSTEM_INFO_GFX_SE_INFO,
Rex Zhu2fef37c2016-08-22 20:48:13 +0800101 CGS_SYSTEM_INFO_PCIE_SUB_SYS_ID,
102 CGS_SYSTEM_INFO_PCIE_SUB_SYS_VENDOR_ID,
Eric Huang4d1f9fb2017-09-15 16:33:38 -0400103 CGS_SYSTEM_INFO_PCIE_BUS_DEVFN,
Rex Zhu5e618692015-09-23 20:11:54 +0800104 CGS_SYSTEM_INFO_ID_MAXIMUM,
105};
106
107struct cgs_system_info {
Huang Rui11f55a32016-07-16 13:24:45 +0800108 uint64_t size;
109 enum cgs_system_info_id info_id;
Rex Zhu5e618692015-09-23 20:11:54 +0800110 union {
Huang Rui11f55a32016-07-16 13:24:45 +0800111 void *ptr;
112 uint64_t value;
Rex Zhu5e618692015-09-23 20:11:54 +0800113 };
Huang Rui11f55a32016-07-16 13:24:45 +0800114 uint64_t padding[13];
Rex Zhu5e618692015-09-23 20:11:54 +0800115};
116
Alex Deucherba228ac2015-12-23 11:25:43 -0500117/*
118 * enum cgs_resource_type - GPU resource type
119 */
120enum cgs_resource_type {
121 CGS_RESOURCE_TYPE_MMIO = 0,
122 CGS_RESOURCE_TYPE_FB,
123 CGS_RESOURCE_TYPE_IO,
124 CGS_RESOURCE_TYPE_DOORBELL,
125 CGS_RESOURCE_TYPE_ROM,
126};
127
Chunming Zhoud03846a2015-07-28 14:20:03 -0400128/**
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800129 * struct cgs_firmware_info - Firmware information
130 */
131struct cgs_firmware_info {
132 uint16_t version;
Frank Minfc76cbf2016-04-27 18:53:29 +0800133 uint16_t fw_version;
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800134 uint16_t feature_version;
135 uint32_t image_size;
136 uint64_t mc_addr;
Huang Rui340efe22016-06-19 23:55:14 +0800137
138 /* only for smc firmware */
139 uint32_t ucode_start_address;
140
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800141 void *kptr;
Huang Rui5d7213b2017-02-10 16:42:19 +0800142 bool is_kicker;
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800143};
144
Rex Zhu47bf18b2015-09-17 16:34:14 +0800145struct cgs_mode_info {
146 uint32_t refresh_rate;
147 uint32_t ref_clock;
148 uint32_t vblank_time_us;
149};
150
151struct cgs_display_info {
152 uint32_t display_count;
153 uint32_t active_display_mask;
154 struct cgs_mode_info *mode_info;
155};
156
Chunming Zhoud03846a2015-07-28 14:20:03 -0400157typedef unsigned long cgs_handle_t;
158
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800159#define CGS_ACPI_METHOD_ATCS 0x53435441
160#define CGS_ACPI_METHOD_ATIF 0x46495441
161#define CGS_ACPI_METHOD_ATPX 0x58505441
162#define CGS_ACPI_FIELD_METHOD_NAME 0x00000001
163#define CGS_ACPI_FIELD_INPUT_ARGUMENT_COUNT 0x00000002
164#define CGS_ACPI_MAX_BUFFER_SIZE 256
165#define CGS_ACPI_TYPE_ANY 0x00
166#define CGS_ACPI_TYPE_INTEGER 0x01
167#define CGS_ACPI_TYPE_STRING 0x02
168#define CGS_ACPI_TYPE_BUFFER 0x03
169#define CGS_ACPI_TYPE_PACKAGE 0x04
170
171struct cgs_acpi_method_argument {
172 uint32_t type;
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800173 uint32_t data_length;
174 union{
175 uint32_t value;
176 void *pointer;
177 };
178};
179
180struct cgs_acpi_method_info {
181 uint32_t size;
182 uint32_t field;
183 uint32_t input_count;
184 uint32_t name;
185 struct cgs_acpi_method_argument *pinput_argument;
186 uint32_t output_count;
187 struct cgs_acpi_method_argument *poutput_argument;
188 uint32_t padding[9];
189};
190
Chunming Zhoud03846a2015-07-28 14:20:03 -0400191/**
Chunming Zhoud03846a2015-07-28 14:20:03 -0400192 * cgs_alloc_gpu_mem() - Allocate GPU memory
193 * @cgs_device: opaque device handle
194 * @type: memory type
195 * @size: size in bytes
196 * @align: alignment in bytes
Chunming Zhoud03846a2015-07-28 14:20:03 -0400197 * @handle: memory handle (output)
198 *
199 * The memory types CGS_GPU_MEM_TYPE_*_CONTIG_FB force contiguous
200 * memory allocation. This guarantees that the MC address returned by
201 * cgs_gmap_gpu_mem is not mapped through the GART. The non-contiguous
202 * FB memory types may be GART mapped depending on memory
203 * fragmentation and memory allocator policies.
204 *
205 * If min/max_offset are non-0, the allocation will be forced to
206 * reside between these offsets in its respective memory heap. The
207 * base address that the offset relates to, depends on the memory
208 * type.
209 *
210 * - CGS_GPU_MEM_TYPE__*_CONTIG_FB: FB MC base address
211 * - CGS_GPU_MEM_TYPE__GART_*: GART aperture base address
212 * - others: undefined, don't use with max_offset
213 *
214 * Return: 0 on success, -errno otherwise
215 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000216typedef int (*cgs_alloc_gpu_mem_t)(struct cgs_device *cgs_device, enum cgs_gpu_mem_type type,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400217 uint64_t size, uint64_t align,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400218 cgs_handle_t *handle);
219
220/**
221 * cgs_free_gpu_mem() - Free GPU memory
222 * @cgs_device: opaque device handle
223 * @handle: memory handle returned by alloc or import
224 *
225 * Return: 0 on success, -errno otherwise
226 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000227typedef int (*cgs_free_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400228
229/**
230 * cgs_gmap_gpu_mem() - GPU-map GPU memory
231 * @cgs_device: opaque device handle
232 * @handle: memory handle returned by alloc or import
233 * @mcaddr: MC address (output)
234 *
235 * Ensures that a buffer is GPU accessible and returns its MC address.
236 *
237 * Return: 0 on success, -errno otherwise
238 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000239typedef int (*cgs_gmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400240 uint64_t *mcaddr);
241
242/**
243 * cgs_gunmap_gpu_mem() - GPU-unmap GPU memory
244 * @cgs_device: opaque device handle
245 * @handle: memory handle returned by alloc or import
246 *
247 * Allows the buffer to be migrated while it's not used by the GPU.
248 *
249 * Return: 0 on success, -errno otherwise
250 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000251typedef int (*cgs_gunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400252
253/**
254 * cgs_kmap_gpu_mem() - Kernel-map GPU memory
255 *
256 * @cgs_device: opaque device handle
257 * @handle: memory handle returned by alloc or import
258 * @map: Kernel virtual address the memory was mapped to (output)
259 *
260 * Return: 0 on success, -errno otherwise
261 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000262typedef int (*cgs_kmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400263 void **map);
264
265/**
266 * cgs_kunmap_gpu_mem() - Kernel-unmap GPU memory
267 * @cgs_device: opaque device handle
268 * @handle: memory handle returned by alloc or import
269 *
270 * Return: 0 on success, -errno otherwise
271 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000272typedef int (*cgs_kunmap_gpu_mem_t)(struct cgs_device *cgs_device, cgs_handle_t handle);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400273
274/**
275 * cgs_read_register() - Read an MMIO register
276 * @cgs_device: opaque device handle
277 * @offset: register offset
278 *
279 * Return: register value
280 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000281typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400282
283/**
284 * cgs_write_register() - Write an MMIO register
285 * @cgs_device: opaque device handle
286 * @offset: register offset
287 * @value: register value
288 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000289typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400290 uint32_t value);
291
292/**
293 * cgs_read_ind_register() - Read an indirect register
294 * @cgs_device: opaque device handle
295 * @offset: register offset
296 *
297 * Return: register value
298 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000299typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400300 unsigned index);
301
302/**
303 * cgs_write_ind_register() - Write an indirect register
304 * @cgs_device: opaque device handle
305 * @offset: register offset
306 * @value: register value
307 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000308typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400309 unsigned index, uint32_t value);
310
Tom St Denis38e40d92017-09-06 08:04:10 -0400311#define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
312#define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK
313
314#define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \
315 (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \
316 (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field))))
317
318#define CGS_REG_GET_FIELD(value, reg, field) \
319 (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field))
320
321#define CGS_WREG32_FIELD(device, reg, field, val) \
322 cgs_write_register(device, mm##reg, (cgs_read_register(device, mm##reg) & ~CGS_REG_FIELD_MASK(reg, field)) | (val) << CGS_REG_FIELD_SHIFT(reg, field))
323
324#define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \
325 cgs_write_ind_register(device, space, ix##reg, (cgs_read_ind_register(device, space, ix##reg) & ~CGS_REG_FIELD_MASK(reg, field)) | (val) << CGS_REG_FIELD_SHIFT(reg, field))
326
Chunming Zhoud03846a2015-07-28 14:20:03 -0400327/**
Alex Deucherba228ac2015-12-23 11:25:43 -0500328 * cgs_get_pci_resource() - provide access to a device resource (PCI BAR)
329 * @cgs_device: opaque device handle
330 * @resource_type: Type of Resource (MMIO, IO, ROM, FB, DOORBELL)
331 * @size: size of the region
332 * @offset: offset from the start of the region
333 * @resource_base: base address (not including offset) returned
334 *
335 * Return: 0 on success, -errno otherwise
336 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000337typedef int (*cgs_get_pci_resource_t)(struct cgs_device *cgs_device,
Alex Deucherba228ac2015-12-23 11:25:43 -0500338 enum cgs_resource_type resource_type,
339 uint64_t size,
340 uint64_t offset,
341 uint64_t *resource_base);
342
Chunming Zhoud03846a2015-07-28 14:20:03 -0400343/**
344 * cgs_atom_get_data_table() - Get a pointer to an ATOM BIOS data table
345 * @cgs_device: opaque device handle
346 * @table: data table index
347 * @size: size of the table (output, may be NULL)
348 * @frev: table format revision (output, may be NULL)
349 * @crev: table content revision (output, may be NULL)
350 *
351 * Return: Pointer to start of the table, or NULL on failure
352 */
353typedef const void *(*cgs_atom_get_data_table_t)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000354 struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400355 uint16_t *size, uint8_t *frev, uint8_t *crev);
356
357/**
358 * cgs_atom_get_cmd_table_revs() - Get ATOM BIOS command table revisions
359 * @cgs_device: opaque device handle
360 * @table: data table index
361 * @frev: table format revision (output, may be NULL)
362 * @crev: table content revision (output, may be NULL)
363 *
364 * Return: 0 on success, -errno otherwise
365 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000366typedef int (*cgs_atom_get_cmd_table_revs_t)(struct cgs_device *cgs_device, unsigned table,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400367 uint8_t *frev, uint8_t *crev);
368
369/**
370 * cgs_atom_exec_cmd_table() - Execute an ATOM BIOS command table
371 * @cgs_device: opaque device handle
372 * @table: command table index
373 * @args: arguments
374 *
375 * Return: 0 on success, -errno otherwise
376 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000377typedef int (*cgs_atom_exec_cmd_table_t)(struct cgs_device *cgs_device,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400378 unsigned table, void *args);
379
380/**
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800381 * cgs_get_firmware_info - Get the firmware information from core driver
382 * @cgs_device: opaque device handle
383 * @type: the firmware type
384 * @info: returend firmware information
385 *
386 * Return: 0 on success, -errno otherwise
387 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000388typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800389 enum cgs_ucode_id type,
390 struct cgs_firmware_info *info);
391
Monk Liua3927462016-05-31 13:44:30 +0800392typedef int (*cgs_rel_firmware)(struct cgs_device *cgs_device,
393 enum cgs_ucode_id type);
394
Dave Airlie110e6f22016-04-12 13:25:48 +1000395typedef int(*cgs_set_powergating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800396 enum amd_ip_block_type block_type,
397 enum amd_powergating_state state);
398
Dave Airlie110e6f22016-04-12 13:25:48 +1000399typedef int(*cgs_set_clockgating_state)(struct cgs_device *cgs_device,
rezhu404b2fa2015-08-07 13:37:56 +0800400 enum amd_ip_block_type block_type,
401 enum amd_clockgating_state state);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400402
Rex Zhu47bf18b2015-09-17 16:34:14 +0800403typedef int(*cgs_get_active_displays_info)(
Dave Airlie110e6f22016-04-12 13:25:48 +1000404 struct cgs_device *cgs_device,
Rex Zhu47bf18b2015-09-17 16:34:14 +0800405 struct cgs_display_info *info);
406
Dave Airlie110e6f22016-04-12 13:25:48 +1000407typedef int (*cgs_notify_dpm_enabled)(struct cgs_device *cgs_device, bool enabled);
Rex Zhu4c900802016-03-29 14:20:37 +0800408
Dave Airlie110e6f22016-04-12 13:25:48 +1000409typedef int (*cgs_call_acpi_method)(struct cgs_device *cgs_device,
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800410 uint32_t acpi_method,
411 uint32_t acpi_function,
412 void *pinput, void *poutput,
413 uint32_t output_count,
414 uint32_t input_size,
415 uint32_t output_size);
Rex Zhu5e618692015-09-23 20:11:54 +0800416
Dave Airlie110e6f22016-04-12 13:25:48 +1000417typedef int (*cgs_query_system_info)(struct cgs_device *cgs_device,
Rex Zhu5e618692015-09-23 20:11:54 +0800418 struct cgs_system_info *sys_info);
419
Frank Minac00bbf2016-04-27 20:04:58 +0800420typedef int (*cgs_is_virtualization_enabled_t)(void *cgs_device);
421
Rex Zhue8a95b22016-12-21 20:30:58 +0800422typedef int (*cgs_enter_safe_mode)(struct cgs_device *cgs_device, bool en);
423
Evan Quan209ee272017-07-04 15:37:09 +0800424typedef void (*cgs_lock_grbm_idx)(struct cgs_device *cgs_device, bool lock);
425
Rex Zhuba89a3e2017-09-25 20:45:52 +0800426struct amd_pp_init;
427typedef void* (*cgs_register_pp_handle)(struct cgs_device *cgs_device,
428 int (*call_back_func)(struct amd_pp_init *, void **));
429
Evan Quan1357f0c2017-12-28 14:14:08 +0800430typedef int (*cgs_set_temperature_range)(struct cgs_device *cgs_device,
431 int min_temperature,
432 int max_temperature);
Chunming Zhoud03846a2015-07-28 14:20:03 -0400433struct cgs_ops {
434 /* memory management calls (similar to KFD interface) */
Chunming Zhoud03846a2015-07-28 14:20:03 -0400435 cgs_alloc_gpu_mem_t alloc_gpu_mem;
436 cgs_free_gpu_mem_t free_gpu_mem;
437 cgs_gmap_gpu_mem_t gmap_gpu_mem;
438 cgs_gunmap_gpu_mem_t gunmap_gpu_mem;
439 cgs_kmap_gpu_mem_t kmap_gpu_mem;
440 cgs_kunmap_gpu_mem_t kunmap_gpu_mem;
441 /* MMIO access */
442 cgs_read_register_t read_register;
443 cgs_write_register_t write_register;
444 cgs_read_ind_register_t read_ind_register;
445 cgs_write_ind_register_t write_ind_register;
Alex Deucherba228ac2015-12-23 11:25:43 -0500446 /* PCI resources */
447 cgs_get_pci_resource_t get_pci_resource;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400448 /* ATOM BIOS */
449 cgs_atom_get_data_table_t atom_get_data_table;
450 cgs_atom_get_cmd_table_revs_t atom_get_cmd_table_revs;
451 cgs_atom_exec_cmd_table_t atom_exec_cmd_table;
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800452 /* Firmware Info */
453 cgs_get_firmware_info get_firmware_info;
Monk Liua3927462016-05-31 13:44:30 +0800454 cgs_rel_firmware rel_firmware;
rezhu404b2fa2015-08-07 13:37:56 +0800455 /* cg pg interface*/
456 cgs_set_powergating_state set_powergating_state;
457 cgs_set_clockgating_state set_clockgating_state;
Rex Zhu47bf18b2015-09-17 16:34:14 +0800458 /* display manager */
459 cgs_get_active_displays_info get_active_displays_info;
Rex Zhu4c900802016-03-29 14:20:37 +0800460 /* notify dpm enabled */
461 cgs_notify_dpm_enabled notify_dpm_enabled;
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800462 /* ACPI */
463 cgs_call_acpi_method call_acpi_method;
Rex Zhu5e618692015-09-23 20:11:54 +0800464 /* get system info */
465 cgs_query_system_info query_system_info;
Frank Minac00bbf2016-04-27 20:04:58 +0800466 cgs_is_virtualization_enabled_t is_virtualization_enabled;
Rex Zhue8a95b22016-12-21 20:30:58 +0800467 cgs_enter_safe_mode enter_safe_mode;
Evan Quan209ee272017-07-04 15:37:09 +0800468 cgs_lock_grbm_idx lock_grbm_idx;
Rex Zhuba89a3e2017-09-25 20:45:52 +0800469 cgs_register_pp_handle register_pp_handle;
Evan Quan1357f0c2017-12-28 14:14:08 +0800470 cgs_set_temperature_range set_temperature_range;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400471};
472
473struct cgs_os_ops; /* To be define in OS-specific CGS header */
474
475struct cgs_device
476{
477 const struct cgs_ops *ops;
478 const struct cgs_os_ops *os_ops;
479 /* to be embedded at the start of driver private structure */
480};
481
482/* Convenience macros that make CGS indirect function calls look like
483 * normal function calls */
484#define CGS_CALL(func,dev,...) \
485 (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
486#define CGS_OS_CALL(func,dev,...) \
487 (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
488
Christian König88531912017-09-11 17:10:26 +0200489#define cgs_alloc_gpu_mem(dev,type,size,align,handle) \
490 CGS_CALL(alloc_gpu_mem,dev,type,size,align,handle)
Chunming Zhoud03846a2015-07-28 14:20:03 -0400491#define cgs_free_gpu_mem(dev,handle) \
492 CGS_CALL(free_gpu_mem,dev,handle)
493#define cgs_gmap_gpu_mem(dev,handle,mcaddr) \
494 CGS_CALL(gmap_gpu_mem,dev,handle,mcaddr)
Jammy Zhou97baee72015-07-21 17:02:44 +0800495#define cgs_gunmap_gpu_mem(dev,handle) \
Chunming Zhoud03846a2015-07-28 14:20:03 -0400496 CGS_CALL(gunmap_gpu_mem,dev,handle)
497#define cgs_kmap_gpu_mem(dev,handle,map) \
498 CGS_CALL(kmap_gpu_mem,dev,handle,map)
499#define cgs_kunmap_gpu_mem(dev,handle) \
500 CGS_CALL(kunmap_gpu_mem,dev,handle)
501
502#define cgs_read_register(dev,offset) \
503 CGS_CALL(read_register,dev,offset)
504#define cgs_write_register(dev,offset,value) \
505 CGS_CALL(write_register,dev,offset,value)
506#define cgs_read_ind_register(dev,space,index) \
507 CGS_CALL(read_ind_register,dev,space,index)
508#define cgs_write_ind_register(dev,space,index,value) \
509 CGS_CALL(write_ind_register,dev,space,index,value)
510
Chunming Zhoud03846a2015-07-28 14:20:03 -0400511#define cgs_atom_get_data_table(dev,table,size,frev,crev) \
512 CGS_CALL(atom_get_data_table,dev,table,size,frev,crev)
513#define cgs_atom_get_cmd_table_revs(dev,table,frev,crev) \
514 CGS_CALL(atom_get_cmd_table_revs,dev,table,frev,crev)
515#define cgs_atom_exec_cmd_table(dev,table,args) \
516 CGS_CALL(atom_exec_cmd_table,dev,table,args)
517
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800518#define cgs_get_firmware_info(dev, type, info) \
519 CGS_CALL(get_firmware_info, dev, type, info)
Monk Liua3927462016-05-31 13:44:30 +0800520#define cgs_rel_firmware(dev, type) \
521 CGS_CALL(rel_firmware, dev, type)
rezhu404b2fa2015-08-07 13:37:56 +0800522#define cgs_set_powergating_state(dev, block_type, state) \
523 CGS_CALL(set_powergating_state, dev, block_type, state)
524#define cgs_set_clockgating_state(dev, block_type, state) \
525 CGS_CALL(set_clockgating_state, dev, block_type, state)
Rex Zhu4c900802016-03-29 14:20:37 +0800526#define cgs_notify_dpm_enabled(dev, enabled) \
527 CGS_CALL(notify_dpm_enabled, dev, enabled)
528
Rex Zhu47bf18b2015-09-17 16:34:14 +0800529#define cgs_get_active_displays_info(dev, info) \
530 CGS_CALL(get_active_displays_info, dev, info)
Rex Zhu4c900802016-03-29 14:20:37 +0800531
Rex Zhu3f1d35a2015-09-15 14:44:44 +0800532#define cgs_call_acpi_method(dev, acpi_method, acpi_function, pintput, poutput, output_count, input_size, output_size) \
533 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 +0800534#define cgs_query_system_info(dev, sys_info) \
535 CGS_CALL(query_system_info, dev, sys_info)
Alex Deucherba228ac2015-12-23 11:25:43 -0500536#define cgs_get_pci_resource(cgs_device, resource_type, size, offset, \
537 resource_base) \
538 CGS_CALL(get_pci_resource, cgs_device, resource_type, size, offset, \
539 resource_base)
Chunming Zhoud03846a2015-07-28 14:20:03 -0400540
Frank Minac00bbf2016-04-27 20:04:58 +0800541#define cgs_is_virtualization_enabled(cgs_device) \
542 CGS_CALL(is_virtualization_enabled, cgs_device)
Rex Zhue8a95b22016-12-21 20:30:58 +0800543
544#define cgs_enter_safe_mode(cgs_device, en) \
545 CGS_CALL(enter_safe_mode, cgs_device, en)
546
Evan Quan209ee272017-07-04 15:37:09 +0800547#define cgs_lock_grbm_idx(cgs_device, lock) \
548 CGS_CALL(lock_grbm_idx, cgs_device, lock)
Rex Zhuba89a3e2017-09-25 20:45:52 +0800549#define cgs_register_pp_handle(cgs_device, call_back_func) \
550 CGS_CALL(register_pp_handle, cgs_device, call_back_func)
551
Evan Quan1357f0c2017-12-28 14:14:08 +0800552#define cgs_set_temperature_range(dev, min_temp, max_temp) \
553 CGS_CALL(set_temperature_range, dev, min_temp, max_temp)
554
Chunming Zhoud03846a2015-07-28 14:20:03 -0400555#endif /* _CGS_COMMON_H */