summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_umsch_mm.h
blob: 2c771a753778861ccbe01085b06d375542b82738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/* SPDX-License-Identifier: MIT */
/*
 * Copyright 2023 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#ifndef __AMDGPU_UMSCH_MM_H__
#define __AMDGPU_UMSCH_MM_H__

enum UMSCH_SWIP_ENGINE_TYPE {
	UMSCH_SWIP_ENGINE_TYPE_VCN0 = 0,
	UMSCH_SWIP_ENGINE_TYPE_VCN1 = 1,
	UMSCH_SWIP_ENGINE_TYPE_VCN = 2,
	UMSCH_SWIP_ENGINE_TYPE_VPE = 3,
	UMSCH_SWIP_ENGINE_TYPE_MAX
};

enum UMSCH_CONTEXT_PRIORITY_LEVEL {
	CONTEXT_PRIORITY_LEVEL_IDLE = 0,
	CONTEXT_PRIORITY_LEVEL_NORMAL = 1,
	CONTEXT_PRIORITY_LEVEL_FOCUS = 2,
	CONTEXT_PRIORITY_LEVEL_REALTIME = 3,
	CONTEXT_PRIORITY_NUM_LEVELS
};

struct umsch_mm_set_resource_input {
	uint32_t vmid_mask_mm_vcn;
	uint32_t vmid_mask_mm_vpe;
	uint32_t collaboration_mask_vpe;
	uint32_t logging_vmid;
	uint32_t engine_mask;
	union {
		struct {
			uint32_t disable_reset : 1;
			uint32_t disable_umsch_mm_log : 1;
			uint32_t use_rs64mem_for_proc_ctx_csa : 1;
			uint32_t reserved : 29;
		};
		uint32_t uint32_all;
	};
};

struct amdgpu_umsch_fwlog {
	uint32_t rptr;
	uint32_t wptr;
	uint32_t buffer_size;
	uint32_t header_size;
	uint32_t wrapped;
};

struct umsch_mm_add_queue_input {
	uint32_t process_id;
	uint64_t page_table_base_addr;
	uint64_t process_va_start;
	uint64_t process_va_end;
	uint64_t process_quantum;
	uint64_t process_csa_addr;
	uint64_t context_quantum;
	uint64_t context_csa_addr;
	uint32_t inprocess_context_priority;
	enum UMSCH_CONTEXT_PRIORITY_LEVEL context_global_priority_level;
	uint32_t doorbell_offset_0;
	uint32_t doorbell_offset_1;
	enum UMSCH_SWIP_ENGINE_TYPE engine_type;
	uint32_t affinity;
	uint64_t mqd_addr;
	uint64_t h_context;
	uint64_t h_queue;
	uint32_t vm_context_cntl;

	uint32_t process_csa_array_index;
	uint32_t context_csa_array_index;

	struct {
		uint32_t is_context_suspended : 1;
		uint32_t collaboration_mode : 1;
		uint32_t reserved : 30;
	};
};

struct umsch_mm_remove_queue_input {
	uint32_t doorbell_offset_0;
	uint32_t doorbell_offset_1;
	uint64_t context_csa_addr;
	uint32_t context_csa_array_index;
};

struct MQD_INFO {
	uint32_t rb_base_hi;
	uint32_t rb_base_lo;
	uint32_t rb_size;
	uint32_t wptr_val;
	uint32_t rptr_val;
	uint32_t unmapped;
	uint32_t vmid;
};

struct amdgpu_umsch_mm;

struct umsch_mm_funcs {
	int (*set_hw_resources)(struct amdgpu_umsch_mm *umsch);
	int (*add_queue)(struct amdgpu_umsch_mm *umsch,
			 struct umsch_mm_add_queue_input *input);
	int (*remove_queue)(struct amdgpu_umsch_mm *umsch,
			    struct umsch_mm_remove_queue_input *input);
	int (*set_regs)(struct amdgpu_umsch_mm *umsch);
	int (*init_microcode)(struct amdgpu_umsch_mm *umsch);
	int (*load_microcode)(struct amdgpu_umsch_mm *umsch);
	int (*ring_init)(struct amdgpu_umsch_mm *umsch);
	int (*ring_start)(struct amdgpu_umsch_mm *umsch);
	int (*ring_stop)(struct amdgpu_umsch_mm *umsch);
	int (*ring_fini)(struct amdgpu_umsch_mm *umsch);
};

struct amdgpu_umsch_mm {
	struct amdgpu_ring		ring;

	uint32_t			rb_wptr;
	uint32_t			rb_rptr;

	const struct umsch_mm_funcs	*funcs;

	const struct firmware		*fw;
	uint32_t			fw_version;
	uint32_t			feature_version;

	struct amdgpu_bo		*ucode_fw_obj;
	uint64_t			ucode_fw_gpu_addr;
	uint32_t			*ucode_fw_ptr;
	uint64_t			irq_start_addr;
	uint64_t			uc_start_addr;
	uint32_t			ucode_size;

	struct amdgpu_bo		*data_fw_obj;
	uint64_t			data_fw_gpu_addr;
	uint32_t			*data_fw_ptr;
	uint64_t			data_start_addr;
	uint32_t			data_size;

	struct amdgpu_bo		*cmd_buf_obj;
	uint64_t			cmd_buf_gpu_addr;
	uint32_t			*cmd_buf_ptr;
	uint32_t			*cmd_buf_curr_ptr;

	uint32_t			wb_index;
	uint64_t			sch_ctx_gpu_addr;
	uint32_t			*sch_ctx_cpu_addr;

	uint32_t			vmid_mask_mm_vcn;
	uint32_t			vmid_mask_mm_vpe;
	uint32_t			engine_mask;
	uint32_t			vcn0_hqd_mask;
	uint32_t			vcn1_hqd_mask;
	uint32_t			vcn_hqd_mask[2];
	uint32_t			vpe_hqd_mask;
	uint32_t			agdb_index[CONTEXT_PRIORITY_NUM_LEVELS];

	struct mutex			mutex_hidden;
	struct amdgpu_bo		*dbglog_bo;
	void				*log_cpu_addr;
	uint64_t			log_gpu_addr;
	uint32_t			mem_size;
	uint32_t			log_offset;
};

int amdgpu_umsch_mm_submit_pkt(struct amdgpu_umsch_mm *umsch, void *pkt, int ndws);
int amdgpu_umsch_mm_query_fence(struct amdgpu_umsch_mm *umsch);

int amdgpu_umsch_mm_init_microcode(struct amdgpu_umsch_mm *umsch);
int amdgpu_umsch_mm_allocate_ucode_buffer(struct amdgpu_umsch_mm *umsch);
int amdgpu_umsch_mm_allocate_ucode_data_buffer(struct amdgpu_umsch_mm *umsch);

int amdgpu_umsch_mm_psp_execute_cmd_buf(struct amdgpu_umsch_mm *umsch);

int amdgpu_umsch_mm_ring_init(struct amdgpu_umsch_mm *umsch);

void amdgpu_debugfs_umsch_fwlog_init(struct amdgpu_device *adev,
			struct amdgpu_umsch_mm *umsch);

void amdgpu_umsch_fwlog_init(struct amdgpu_umsch_mm *umsch_mm);

#define WREG32_SOC15_UMSCH(reg, value)								\
	do {											\
		uint32_t reg_offset = adev->reg_offset[VCN_HWIP][0][reg##_BASE_IDX] + reg;	\
		if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {				\
			*adev->umsch_mm.cmd_buf_curr_ptr++ = (reg_offset << 2);			\
			*adev->umsch_mm.cmd_buf_curr_ptr++ = value;				\
		} else	{									\
			WREG32(reg_offset, value);						\
		}										\
	} while (0)

#define umsch_mm_set_hw_resources(umsch) \
	((umsch)->funcs->set_hw_resources ? (umsch)->funcs->set_hw_resources((umsch)) : 0)
#define umsch_mm_add_queue(umsch, input) \
	((umsch)->funcs->add_queue ? (umsch)->funcs->add_queue((umsch), (input)) : 0)
#define umsch_mm_remove_queue(umsch, input) \
	((umsch)->funcs->remove_queue ? (umsch)->funcs->remove_queue((umsch), (input)) : 0)

#define umsch_mm_set_regs(umsch) \
	((umsch)->funcs->set_regs ? (umsch)->funcs->set_regs((umsch)) : 0)
#define umsch_mm_init_microcode(umsch) \
	((umsch)->funcs->init_microcode ? (umsch)->funcs->init_microcode((umsch)) : 0)
#define umsch_mm_load_microcode(umsch) \
	((umsch)->funcs->load_microcode ? (umsch)->funcs->load_microcode((umsch)) : 0)

#define umsch_mm_ring_init(umsch) \
	((umsch)->funcs->ring_init ? (umsch)->funcs->ring_init((umsch)) : 0)
#define umsch_mm_ring_start(umsch) \
	((umsch)->funcs->ring_start ? (umsch)->funcs->ring_start((umsch)) : 0)
#define umsch_mm_ring_stop(umsch) \
	((umsch)->funcs->ring_stop ? (umsch)->funcs->ring_stop((umsch)) : 0)
#define umsch_mm_ring_fini(umsch) \
	((umsch)->funcs->ring_fini ? (umsch)->funcs->ring_fini((umsch)) : 0)

static inline void amdgpu_umsch_mm_lock(struct amdgpu_umsch_mm *umsch)
{
	mutex_lock(&umsch->mutex_hidden);
}

static inline void amdgpu_umsch_mm_unlock(struct amdgpu_umsch_mm *umsch)
{
	mutex_unlock(&umsch->mutex_hidden);
}

extern const struct amdgpu_ip_block_version umsch_mm_v4_0_ip_block;

#endif