1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #ifndef _CGS_COMMON_H
25 #define _CGS_COMMON_H
26
27 #include "amd_shared.h"
28
29 struct cgs_device;
30
31
32
33
34 enum 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,
40 CGS_IND_REG_GC_CAC,
41 CGS_IND_REG_SE_CAC,
42 CGS_IND_REG__AUDIO_ENDPT
43 };
44
45
46
47
48 enum cgs_ucode_id {
49 CGS_UCODE_ID_SMU = 0,
50 CGS_UCODE_ID_SMU_SK,
51 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,
61 CGS_UCODE_ID_STORAGE,
62 CGS_UCODE_ID_MAXIMUM,
63 };
64
65
66
67
68 struct cgs_firmware_info {
69 uint16_t version;
70 uint16_t fw_version;
71 uint16_t feature_version;
72 uint32_t image_size;
73 uint64_t mc_addr;
74
75
76 uint32_t ucode_start_address;
77
78 void *kptr;
79 bool is_kicker;
80 };
81
82 typedef unsigned long cgs_handle_t;
83
84
85
86
87
88
89
90
91 typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
92
93
94
95
96
97
98
99 typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
100 uint32_t value);
101
102
103
104
105
106
107
108
109 typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
110 unsigned index);
111
112
113
114
115
116
117
118 typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
119 unsigned index, uint32_t value);
120
121 #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
137 typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
138 enum cgs_ucode_id type,
139 struct cgs_firmware_info *info);
140
141 struct cgs_ops {
142
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;
147
148 cgs_get_firmware_info get_firmware_info;
149 };
150
151 struct cgs_os_ops;
152
153 struct cgs_device
154 {
155 const struct cgs_ops *ops;
156
157 };
158
159
160
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
166 #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
175 #define cgs_get_firmware_info(dev, type, info) \
176 CGS_CALL(get_firmware_info, dev, type, info)
177
178 #endif