intel_guc.h 8.1 KB
Newer Older
1
/* SPDX-License-Identifier: MIT */
2
/*
3
 * Copyright © 2014-2019 Intel Corporation
4 5 6 7 8
 */

#ifndef _INTEL_GUC_H_
#define _INTEL_GUC_H_

9
#include <linux/xarray.h>
10
#include <linux/delay.h>
11

12
#include "intel_uncore.h"
13
#include "intel_guc_fw.h"
14 15 16
#include "intel_guc_fwif.h"
#include "intel_guc_ct.h"
#include "intel_guc_log.h"
17
#include "intel_guc_reg.h"
18
#include "intel_guc_slpc_types.h"
19
#include "intel_uc_fw.h"
20
#include "i915_utils.h"
21 22
#include "i915_vma.h"

23 24
struct __guc_ads_blob;

25 26
/*
 * Top level structure of GuC. It handles firmware loading and manages client
27 28
 * pool. intel_guc owns a intel_guc_client to replace the legacy ExecList
 * submission.
29
 */
30 31 32 33
struct intel_guc {
	struct intel_uc_fw fw;
	struct intel_guc_log log;
	struct intel_guc_ct ct;
34
	struct intel_guc_slpc slpc;
35

36 37 38 39
	/* Global engine used to submit requests to GuC */
	struct i915_sched_engine *sched_engine;
	struct i915_request *stalled_request;

40
	/* intel_guc_recv interrupt related state */
41 42
	spinlock_t irq_lock;
	unsigned int msg_enabled_mask;
43

44 45
	atomic_t outstanding_submission_g2h;

46
	struct {
47 48 49
		void (*reset)(struct intel_guc *guc);
		void (*enable)(struct intel_guc *guc);
		void (*disable)(struct intel_guc *guc);
50 51
	} interrupts;

52 53 54 55 56 57 58 59
	/*
	 * contexts_lock protects the pool of free guc ids and a linked list of
	 * guc ids available to be stolen
	 */
	spinlock_t contexts_lock;
	struct ida guc_ids;
	struct list_head guc_id_list;

60
	bool submission_supported;
61
	bool submission_selected;
62

63
	struct i915_vma *ads_vma;
64
	struct __guc_ads_blob *ads_blob;
65
	u32 ads_regset_size;
66
	u32 ads_golden_ctxt_size;
67

68 69
	struct i915_vma *lrc_desc_pool;
	void *lrc_desc_pool_vaddr;
70

71 72 73
	/* guc_id to intel_context lookup */
	struct xarray context_lookup;

74 75 76
	/* Control params for fw initialization */
	u32 params[GUC_CTL_MAX_DWORDS];

77 78 79 80 81 82 83
	/* GuC's FW specific registers used in MMIO send */
	struct {
		u32 base;
		unsigned int count;
		enum forcewake_domains fw_domains;
	} send_regs;

84 85 86
	/* register used to send interrupts to the GuC FW */
	i915_reg_t notify_reg;

87 88 89
	/* Store msg (e.g. log flush) that we see while CTBs are disabled */
	u32 mmio_msg;

90 91 92 93
	/* To serialize the intel_guc_send actions */
	struct mutex send_mutex;
};

94 95 96 97 98
static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)
{
	return container_of(log, struct intel_guc, log);
}

99 100 101
static
inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
{
102 103 104 105
	return intel_guc_ct_send(&guc->ct, action, len, NULL, 0, 0);
}

static
106 107
inline int intel_guc_send_nb(struct intel_guc *guc, const u32 *action, u32 len,
			     u32 g2h_len_dw)
108 109
{
	return intel_guc_ct_send(&guc->ct, action, len, NULL, 0,
110
				 MAKE_SEND_FLAGS(g2h_len_dw));
111 112 113 114 115 116
}

static inline int
intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
			   u32 *response_buf, u32 response_buf_size)
{
117
	return intel_guc_ct_send(&guc->ct, action, len,
118
				 response_buf, response_buf_size, 0);
119 120
}

121 122 123
static inline int intel_guc_send_busy_loop(struct intel_guc *guc,
					   const u32 *action,
					   u32 len,
124
					   u32 g2h_len_dw,
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
					   bool loop)
{
	int err;
	unsigned int sleep_period_ms = 1;
	bool not_atomic = !in_atomic() && !irqs_disabled();

	/*
	 * FIXME: Have caller pass in if we are in an atomic context to avoid
	 * using in_atomic(). It is likely safe here as we check for irqs
	 * disabled which basically all the spin locks in the i915 do but
	 * regardless this should be cleaned up.
	 */

	/* No sleeping with spin locks, just busy loop */
	might_sleep_if(loop && not_atomic);

retry:
142
	err = intel_guc_send_nb(guc, action, len, g2h_len_dw);
143 144 145 146 147 148 149 150 151 152 153 154 155 156
	if (unlikely(err == -EBUSY && loop)) {
		if (likely(not_atomic)) {
			if (msleep_interruptible(sleep_period_ms))
				return -EINTR;
			sleep_period_ms = sleep_period_ms << 1;
		} else {
			cpu_relax();
		}
		goto retry;
	}

	return err;
}

157 158
static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
{
159
	intel_guc_ct_event_handler(&guc->ct);
160 161
}

162 163 164 165 166 167 168 169
/* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
#define GUC_GGTT_TOP	0xFEE00000

/**
 * intel_guc_ggtt_offset() - Get and validate the GGTT offset of @vma
 * @guc: intel_guc structure.
 * @vma: i915 graphics virtual memory area.
 *
170
 * GuC does not allow any gfx GGTT address that falls into range
171 172
 * [0, ggtt.pin_bias), which is reserved for Boot ROM, SRAM and WOPCM.
 * Currently, in order to exclude [0, ggtt.pin_bias) address space from
173
 * GGTT, all gfx objects used by GuC are allocated with intel_guc_allocate_vma()
174
 * and pinned with PIN_OFFSET_BIAS along with the value of ggtt.pin_bias.
175
 *
176
 * Return: GGTT offset of the @vma.
177
 */
178 179
static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc,
					struct i915_vma *vma)
180 181 182
{
	u32 offset = i915_ggtt_offset(vma);

183
	GEM_BUG_ON(offset < i915_ggtt_pin_bias(vma));
184 185 186 187 188 189
	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));

	return offset;
}

void intel_guc_init_early(struct intel_guc *guc);
190
void intel_guc_init_late(struct intel_guc *guc);
191
void intel_guc_init_send_regs(struct intel_guc *guc);
192
void intel_guc_write_params(struct intel_guc *guc);
193 194
int intel_guc_init(struct intel_guc *guc);
void intel_guc_fini(struct intel_guc *guc);
195
void intel_guc_notify(struct intel_guc *guc);
196 197
int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len,
			u32 *response_buf, u32 response_buf_size);
198 199
int intel_guc_to_host_process_recv_msg(struct intel_guc *guc,
				       const u32 *payload, u32 len);
200
int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
201 202
int intel_guc_suspend(struct intel_guc *guc);
int intel_guc_resume(struct intel_guc *guc);
203
struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
204 205
int intel_guc_allocate_and_map_vma(struct intel_guc *guc, u32 size,
				   struct i915_vma **out_vma, void **out_vaddr);
206

207 208
static inline bool intel_guc_is_supported(struct intel_guc *guc)
{
209 210 211
	return intel_uc_fw_is_supported(&guc->fw);
}

212
static inline bool intel_guc_is_wanted(struct intel_guc *guc)
213 214
{
	return intel_uc_fw_is_enabled(&guc->fw);
215 216
}

217 218 219 220 221 222
static inline bool intel_guc_is_used(struct intel_guc *guc)
{
	GEM_BUG_ON(__intel_uc_fw_status(&guc->fw) == INTEL_UC_FIRMWARE_SELECTED);
	return intel_uc_fw_is_available(&guc->fw);
}

223
static inline bool intel_guc_is_fw_running(struct intel_guc *guc)
224
{
225
	return intel_uc_fw_is_running(&guc->fw);
226 227
}

228 229 230 231 232
static inline bool intel_guc_is_ready(struct intel_guc *guc)
{
	return intel_guc_is_fw_running(guc) && intel_guc_ct_enabled(&guc->ct);
}

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
static inline void intel_guc_reset_interrupts(struct intel_guc *guc)
{
	guc->interrupts.reset(guc);
}

static inline void intel_guc_enable_interrupts(struct intel_guc *guc)
{
	guc->interrupts.enable(guc);
}

static inline void intel_guc_disable_interrupts(struct intel_guc *guc)
{
	guc->interrupts.disable(guc);
}

248 249 250
static inline int intel_guc_sanitize(struct intel_guc *guc)
{
	intel_uc_fw_sanitize(&guc->fw);
251
	intel_guc_disable_interrupts(guc);
252
	intel_guc_ct_sanitize(&guc->ct);
253 254
	guc->mmio_msg = 0;

255 256 257
	return 0;
}

258 259 260 261 262 263 264 265 266 267 268 269 270 271
static inline void intel_guc_enable_msg(struct intel_guc *guc, u32 mask)
{
	spin_lock_irq(&guc->irq_lock);
	guc->msg_enabled_mask |= mask;
	spin_unlock_irq(&guc->irq_lock);
}

static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)
{
	spin_lock_irq(&guc->irq_lock);
	guc->msg_enabled_mask &= ~mask;
	spin_unlock_irq(&guc->irq_lock);
}

272 273
int intel_guc_wait_for_idle(struct intel_guc *guc, long timeout);

274 275
int intel_guc_deregister_done_process_msg(struct intel_guc *guc,
					  const u32 *msg, u32 len);
276 277
int intel_guc_sched_done_process_msg(struct intel_guc *guc,
				     const u32 *msg, u32 len);
278 279
int intel_guc_context_reset_process_msg(struct intel_guc *guc,
					const u32 *msg, u32 len);
280 281
int intel_guc_engine_failure_process_msg(struct intel_guc *guc,
					 const u32 *msg, u32 len);
282

283 284
void intel_guc_find_hung_context(struct intel_engine_cs *engine);

285 286
int intel_guc_global_policies_update(struct intel_guc *guc);

287 288
void intel_guc_context_ban(struct intel_context *ce, struct i915_request *rq);

289 290 291 292 293
void intel_guc_submission_reset_prepare(struct intel_guc *guc);
void intel_guc_submission_reset(struct intel_guc *guc, bool stalled);
void intel_guc_submission_reset_finish(struct intel_guc *guc);
void intel_guc_submission_cancel_requests(struct intel_guc *guc);

294 295
void intel_guc_load_status(struct intel_guc *guc, struct drm_printer *p);

296
#endif