blob: a69deb3a2ac07a8b3e0db851dc0ccdec6b00d351 [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/**
Chunming Zhoud03846a2015-07-28 14:20:03 -040032 * enum cgs_ind_reg - Indirect register spaces
33 */
34enum cgs_ind_reg {
35 CGS_IND_REG__MMIO,
36 CGS_IND_REG__PCIE,
37 CGS_IND_REG__SMC,
38 CGS_IND_REG__UVD_CTX,
39 CGS_IND_REG__DIDT,
Rex Zhuccdbb202016-06-08 12:47:41 +080040 CGS_IND_REG_GC_CAC,
Evan Quanc62a59d2017-07-04 09:24:34 +080041 CGS_IND_REG_SE_CAC,
Chunming Zhoud03846a2015-07-28 14:20:03 -040042 CGS_IND_REG__AUDIO_ENDPT
43};
44
Jammy Zhoubf3911b02015-05-13 18:58:05 +080045/*
46 * enum cgs_ucode_id - Firmware types for different IPs
47 */
48enum cgs_ucode_id {
49 CGS_UCODE_ID_SMU = 0,
yanyang1735f0022016-02-05 17:39:37 +080050 CGS_UCODE_ID_SMU_SK,
Jammy Zhoubf3911b02015-05-13 18:58:05 +080051 CGS_UCODE_ID_SDMA0,
52 CGS_UCODE_ID_SDMA1,
53 CGS_UCODE_ID_CP_CE,
54 CGS_UCODE_ID_CP_PFP,
55 CGS_UCODE_ID_CP_ME,
56 CGS_UCODE_ID_CP_MEC,
57 CGS_UCODE_ID_CP_MEC_JT1,
58 CGS_UCODE_ID_CP_MEC_JT2,
59 CGS_UCODE_ID_GMCON_RENG,
60 CGS_UCODE_ID_RLC_G,
Monk Liubed57122016-09-26 16:35:03 +080061 CGS_UCODE_ID_STORAGE,
Jammy Zhoubf3911b02015-05-13 18:58:05 +080062 CGS_UCODE_ID_MAXIMUM,
63};
64
Chunming Zhoud03846a2015-07-28 14:20:03 -040065/**
Jammy Zhoubf3911b02015-05-13 18:58:05 +080066 * struct cgs_firmware_info - Firmware information
67 */
68struct cgs_firmware_info {
69 uint16_t version;
Frank Minfc76cbf2016-04-27 18:53:29 +080070 uint16_t fw_version;
Jammy Zhoubf3911b02015-05-13 18:58:05 +080071 uint16_t feature_version;
72 uint32_t image_size;
73 uint64_t mc_addr;
Huang Rui340efe22016-06-19 23:55:14 +080074
75 /* only for smc firmware */
76 uint32_t ucode_start_address;
77
Jammy Zhoubf3911b02015-05-13 18:58:05 +080078 void *kptr;
Huang Rui5d7213b2017-02-10 16:42:19 +080079 bool is_kicker;
Jammy Zhoubf3911b02015-05-13 18:58:05 +080080};
81
Chunming Zhoud03846a2015-07-28 14:20:03 -040082typedef unsigned long cgs_handle_t;
83
84/**
Chunming Zhoud03846a2015-07-28 14:20:03 -040085 * cgs_read_register() - Read an MMIO register
86 * @cgs_device: opaque device handle
87 * @offset: register offset
88 *
89 * Return: register value
90 */
Dave Airlie110e6f22016-04-12 13:25:48 +100091typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
Chunming Zhoud03846a2015-07-28 14:20:03 -040092
93/**
94 * cgs_write_register() - Write an MMIO register
95 * @cgs_device: opaque device handle
96 * @offset: register offset
97 * @value: register value
98 */
Dave Airlie110e6f22016-04-12 13:25:48 +100099typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400100 uint32_t value);
101
102/**
103 * cgs_read_ind_register() - Read an indirect register
104 * @cgs_device: opaque device handle
105 * @offset: register offset
106 *
107 * Return: register value
108 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000109typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400110 unsigned index);
111
112/**
113 * cgs_write_ind_register() - Write an indirect register
114 * @cgs_device: opaque device handle
115 * @offset: register offset
116 * @value: register value
117 */
Dave Airlie110e6f22016-04-12 13:25:48 +1000118typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
Chunming Zhoud03846a2015-07-28 14:20:03 -0400119 unsigned index, uint32_t value);
120
Tom St Denis38e40d92017-09-06 08:04:10 -0400121#define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
122#define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK
123
124#define CGS_REG_SET_FIELD(orig_val, reg, field, field_val) \
125 (((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) | \
126 (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field))))
127
128#define CGS_REG_GET_FIELD(value, reg, field) \
129 (((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field))
130
131#define CGS_WREG32_FIELD(device, reg, field, val) \
132 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))
133
134#define CGS_WREG32_FIELD_IND(device, space, reg, field, val) \
135 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))
136
Dave Airlie110e6f22016-04-12 13:25:48 +1000137typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800138 enum cgs_ucode_id type,
139 struct cgs_firmware_info *info);
140
Chunming Zhoud03846a2015-07-28 14:20:03 -0400141struct cgs_ops {
Chunming Zhoud03846a2015-07-28 14:20:03 -0400142 /* MMIO access */
143 cgs_read_register_t read_register;
144 cgs_write_register_t write_register;
145 cgs_read_ind_register_t read_ind_register;
146 cgs_write_ind_register_t write_ind_register;
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800147 /* Firmware Info */
148 cgs_get_firmware_info get_firmware_info;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400149};
150
151struct cgs_os_ops; /* To be define in OS-specific CGS header */
152
153struct cgs_device
154{
155 const struct cgs_ops *ops;
Chunming Zhoud03846a2015-07-28 14:20:03 -0400156 /* to be embedded at the start of driver private structure */
157};
158
159/* Convenience macros that make CGS indirect function calls look like
160 * normal function calls */
161#define CGS_CALL(func,dev,...) \
162 (((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
163#define CGS_OS_CALL(func,dev,...) \
164 (((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
165
Chunming Zhoud03846a2015-07-28 14:20:03 -0400166#define cgs_read_register(dev,offset) \
167 CGS_CALL(read_register,dev,offset)
168#define cgs_write_register(dev,offset,value) \
169 CGS_CALL(write_register,dev,offset,value)
170#define cgs_read_ind_register(dev,space,index) \
171 CGS_CALL(read_ind_register,dev,space,index)
172#define cgs_write_ind_register(dev,space,index,value) \
173 CGS_CALL(write_ind_register,dev,space,index,value)
174
Jammy Zhoubf3911b02015-05-13 18:58:05 +0800175#define cgs_get_firmware_info(dev, type, info) \
176 CGS_CALL(get_firmware_info, dev, type, info)
Evan Quan1357f0c2017-12-28 14:14:08 +0800177
Chunming Zhoud03846a2015-07-28 14:20:03 -0400178#endif /* _CGS_COMMON_H */