xref: /linux/drivers/gpu/drm/amd/include/cgs_common.h (revision b7e1e969c887c897947fdc3754fe9b0c24acb155)
1d03846afSChunming Zhou /*
2d03846afSChunming Zhou  * Copyright 2015 Advanced Micro Devices, Inc.
3d03846afSChunming Zhou  *
4d03846afSChunming Zhou  * Permission is hereby granted, free of charge, to any person obtaining a
5d03846afSChunming Zhou  * copy of this software and associated documentation files (the "Software"),
6d03846afSChunming Zhou  * to deal in the Software without restriction, including without limitation
7d03846afSChunming Zhou  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8d03846afSChunming Zhou  * and/or sell copies of the Software, and to permit persons to whom the
9d03846afSChunming Zhou  * Software is furnished to do so, subject to the following conditions:
10d03846afSChunming Zhou  *
11d03846afSChunming Zhou  * The above copyright notice and this permission notice shall be included in
12d03846afSChunming Zhou  * all copies or substantial portions of the Software.
13d03846afSChunming Zhou  *
14d03846afSChunming Zhou  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15d03846afSChunming Zhou  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16d03846afSChunming Zhou  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17d03846afSChunming Zhou  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18d03846afSChunming Zhou  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19d03846afSChunming Zhou  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20d03846afSChunming Zhou  * OTHER DEALINGS IN THE SOFTWARE.
21d03846afSChunming Zhou  *
22d03846afSChunming Zhou  *
23d03846afSChunming Zhou  */
24d03846afSChunming Zhou #ifndef _CGS_COMMON_H
25d03846afSChunming Zhou #define _CGS_COMMON_H
26d03846afSChunming Zhou 
27404b2fa3Srezhu #include "amd_shared.h"
28bf3911b0SJammy Zhou 
29110e6f26SDave Airlie struct cgs_device;
30110e6f26SDave Airlie 
31d03846afSChunming Zhou /**
32d03846afSChunming Zhou  * enum cgs_ind_reg - Indirect register spaces
33d03846afSChunming Zhou  */
34d03846afSChunming Zhou enum cgs_ind_reg {
35d03846afSChunming Zhou 	CGS_IND_REG__PCIE,
36d03846afSChunming Zhou 	CGS_IND_REG__SMC,
37d03846afSChunming Zhou 	CGS_IND_REG__UVD_CTX,
38d03846afSChunming Zhou 	CGS_IND_REG__DIDT,
39ccdbb20aSRex Zhu 	CGS_IND_REG_GC_CAC,
40c62a59d0SEvan Quan 	CGS_IND_REG_SE_CAC,
41d03846afSChunming Zhou 	CGS_IND_REG__AUDIO_ENDPT
42d03846afSChunming Zhou };
43d03846afSChunming Zhou 
44bf3911b0SJammy Zhou /*
45bf3911b0SJammy Zhou  * enum cgs_ucode_id - Firmware types for different IPs
46bf3911b0SJammy Zhou  */
47bf3911b0SJammy Zhou enum cgs_ucode_id {
48bf3911b0SJammy Zhou 	CGS_UCODE_ID_SMU = 0,
49735f002bSyanyang1 	CGS_UCODE_ID_SMU_SK,
50bf3911b0SJammy Zhou 	CGS_UCODE_ID_SDMA0,
51bf3911b0SJammy Zhou 	CGS_UCODE_ID_SDMA1,
52bf3911b0SJammy Zhou 	CGS_UCODE_ID_CP_CE,
53bf3911b0SJammy Zhou 	CGS_UCODE_ID_CP_PFP,
54bf3911b0SJammy Zhou 	CGS_UCODE_ID_CP_ME,
55bf3911b0SJammy Zhou 	CGS_UCODE_ID_CP_MEC,
56bf3911b0SJammy Zhou 	CGS_UCODE_ID_CP_MEC_JT1,
57bf3911b0SJammy Zhou 	CGS_UCODE_ID_CP_MEC_JT2,
58bf3911b0SJammy Zhou 	CGS_UCODE_ID_GMCON_RENG,
59bf3911b0SJammy Zhou 	CGS_UCODE_ID_RLC_G,
60bed5712eSMonk Liu 	CGS_UCODE_ID_STORAGE,
61bf3911b0SJammy Zhou 	CGS_UCODE_ID_MAXIMUM,
62bf3911b0SJammy Zhou };
63bf3911b0SJammy Zhou 
64d03846afSChunming Zhou /**
65bf3911b0SJammy Zhou  * struct cgs_firmware_info - Firmware information
66bf3911b0SJammy Zhou  */
67bf3911b0SJammy Zhou struct cgs_firmware_info {
68bf3911b0SJammy Zhou 	uint16_t		version;
69fc76cbf4SFrank Min 	uint16_t		fw_version;
70bf3911b0SJammy Zhou 	uint16_t		feature_version;
71bf3911b0SJammy Zhou 	uint32_t		image_size;
72bf3911b0SJammy Zhou 	uint64_t		mc_addr;
73340efe28SHuang Rui 
74340efe28SHuang Rui 	/* only for smc firmware */
75340efe28SHuang Rui 	uint32_t		ucode_start_address;
76340efe28SHuang Rui 
77bf3911b0SJammy Zhou 	void			*kptr;
785d7213b0SHuang Rui 	bool			is_kicker;
79bf3911b0SJammy Zhou };
80bf3911b0SJammy Zhou 
81d03846afSChunming Zhou typedef unsigned long cgs_handle_t;
82d03846afSChunming Zhou 
83d03846afSChunming Zhou /**
84d03846afSChunming Zhou  * cgs_read_register() - Read an MMIO register
85d03846afSChunming Zhou  * @cgs_device:	opaque device handle
86d03846afSChunming Zhou  * @offset:	register offset
87d03846afSChunming Zhou  *
88d03846afSChunming Zhou  * Return:  register value
89d03846afSChunming Zhou  */
90110e6f26SDave Airlie typedef uint32_t (*cgs_read_register_t)(struct cgs_device *cgs_device, unsigned offset);
91d03846afSChunming Zhou 
92d03846afSChunming Zhou /**
93d03846afSChunming Zhou  * cgs_write_register() - Write an MMIO register
94d03846afSChunming Zhou  * @cgs_device:	opaque device handle
95d03846afSChunming Zhou  * @offset:	register offset
96d03846afSChunming Zhou  * @value:	register value
97d03846afSChunming Zhou  */
98110e6f26SDave Airlie typedef void (*cgs_write_register_t)(struct cgs_device *cgs_device, unsigned offset,
99d03846afSChunming Zhou 				     uint32_t value);
100d03846afSChunming Zhou 
101d03846afSChunming Zhou /**
102d03846afSChunming Zhou  * cgs_read_ind_register() - Read an indirect register
103d03846afSChunming Zhou  * @cgs_device:	opaque device handle
104d03846afSChunming Zhou  * @offset:	register offset
105d03846afSChunming Zhou  *
106d03846afSChunming Zhou  * Return:  register value
107d03846afSChunming Zhou  */
108110e6f26SDave Airlie typedef uint32_t (*cgs_read_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
109d03846afSChunming Zhou 					    unsigned index);
110d03846afSChunming Zhou 
111d03846afSChunming Zhou /**
112d03846afSChunming Zhou  * cgs_write_ind_register() - Write an indirect register
113d03846afSChunming Zhou  * @cgs_device:	opaque device handle
114d03846afSChunming Zhou  * @offset:	register offset
115d03846afSChunming Zhou  * @value:	register value
116d03846afSChunming Zhou  */
117110e6f26SDave Airlie typedef void (*cgs_write_ind_register_t)(struct cgs_device *cgs_device, enum cgs_ind_reg space,
118d03846afSChunming Zhou 					 unsigned index, uint32_t value);
119d03846afSChunming Zhou 
12038e40d9cSTom St Denis #define CGS_REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
12138e40d9cSTom St Denis #define CGS_REG_FIELD_MASK(reg, field) reg##__##field##_MASK
12238e40d9cSTom St Denis 
12338e40d9cSTom St Denis #define CGS_REG_SET_FIELD(orig_val, reg, field, field_val)			\
12438e40d9cSTom St Denis 	(((orig_val) & ~CGS_REG_FIELD_MASK(reg, field)) |			\
12538e40d9cSTom St Denis 	 (CGS_REG_FIELD_MASK(reg, field) & ((field_val) << CGS_REG_FIELD_SHIFT(reg, field))))
12638e40d9cSTom St Denis 
12738e40d9cSTom St Denis #define CGS_REG_GET_FIELD(value, reg, field)				\
12838e40d9cSTom St Denis 	(((value) & CGS_REG_FIELD_MASK(reg, field)) >> CGS_REG_FIELD_SHIFT(reg, field))
12938e40d9cSTom St Denis 
13038e40d9cSTom St Denis #define CGS_WREG32_FIELD(device, reg, field, val)	\
13138e40d9cSTom St Denis 	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))
13238e40d9cSTom St Denis 
13338e40d9cSTom St Denis #define CGS_WREG32_FIELD_IND(device, space, reg, field, val)	\
13438e40d9cSTom St Denis 	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))
13538e40d9cSTom St Denis 
136110e6f26SDave Airlie typedef int (*cgs_get_firmware_info)(struct cgs_device *cgs_device,
137bf3911b0SJammy Zhou 				     enum cgs_ucode_id type,
138bf3911b0SJammy Zhou 				     struct cgs_firmware_info *info);
139bf3911b0SJammy Zhou 
140d03846afSChunming Zhou struct cgs_ops {
141d03846afSChunming Zhou 	/* MMIO access */
142d03846afSChunming Zhou 	cgs_read_register_t read_register;
143d03846afSChunming Zhou 	cgs_write_register_t write_register;
144d03846afSChunming Zhou 	cgs_read_ind_register_t read_ind_register;
145d03846afSChunming Zhou 	cgs_write_ind_register_t write_ind_register;
146bf3911b0SJammy Zhou 	/* Firmware Info */
147bf3911b0SJammy Zhou 	cgs_get_firmware_info get_firmware_info;
148d03846afSChunming Zhou };
149d03846afSChunming Zhou 
150d03846afSChunming Zhou struct cgs_os_ops; /* To be define in OS-specific CGS header */
151d03846afSChunming Zhou 
152*a0caeabbSchenxuebing struct cgs_device {
153d03846afSChunming Zhou 	const struct cgs_ops *ops;
154d03846afSChunming Zhou 	/* to be embedded at the start of driver private structure */
155d03846afSChunming Zhou };
156d03846afSChunming Zhou 
157d03846afSChunming Zhou /* Convenience macros that make CGS indirect function calls look like
158d03846afSChunming Zhou  * normal function calls */
159d03846afSChunming Zhou #define CGS_CALL(func, dev, ...) \
160d03846afSChunming Zhou 	(((struct cgs_device *)dev)->ops->func(dev, ##__VA_ARGS__))
161d03846afSChunming Zhou #define CGS_OS_CALL(func, dev, ...) \
162d03846afSChunming Zhou 	(((struct cgs_device *)dev)->os_ops->func(dev, ##__VA_ARGS__))
163d03846afSChunming Zhou 
164d03846afSChunming Zhou #define cgs_read_register(dev, offset)		\
165d03846afSChunming Zhou 	CGS_CALL(read_register, dev, offset)
166d03846afSChunming Zhou #define cgs_write_register(dev, offset, value)		\
167d03846afSChunming Zhou 	CGS_CALL(write_register, dev, offset, value)
168d03846afSChunming Zhou #define cgs_read_ind_register(dev, space, index)		\
169d03846afSChunming Zhou 	CGS_CALL(read_ind_register, dev, space, index)
170d03846afSChunming Zhou #define cgs_write_ind_register(dev, space, index, value)		\
171d03846afSChunming Zhou 	CGS_CALL(write_ind_register, dev, space, index, value)
172d03846afSChunming Zhou 
173bf3911b0SJammy Zhou #define cgs_get_firmware_info(dev, type, info)	\
174bf3911b0SJammy Zhou 	CGS_CALL(get_firmware_info, dev, type, info)
1751357f0c5SEvan Quan 
176d03846afSChunming Zhou #endif /* _CGS_COMMON_H */
177