intel_guc.h 5.6 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 10
#include <linux/xarray.h>

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

21 22
struct __guc_ads_blob;

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

33 34 35 36
	/* Global engine used to submit requests to GuC */
	struct i915_sched_engine *sched_engine;
	struct i915_request *stalled_request;

37
	/* intel_guc_recv interrupt related state */
38 39
	spinlock_t irq_lock;
	unsigned int msg_enabled_mask;
40

41
	struct {
42 43 44
		void (*reset)(struct intel_guc *guc);
		void (*enable)(struct intel_guc *guc);
		void (*disable)(struct intel_guc *guc);
45 46
	} interrupts;

47
	bool submission_selected;
48

49
	struct i915_vma *ads_vma;
50 51
	struct __guc_ads_blob *ads_blob;

52 53
	struct i915_vma *lrc_desc_pool;
	void *lrc_desc_pool_vaddr;
54

55 56 57
	/* guc_id to intel_context lookup */
	struct xarray context_lookup;

58 59 60
	/* Control params for fw initialization */
	u32 params[GUC_CTL_MAX_DWORDS];

61 62 63 64 65 66 67
	/* GuC's FW specific registers used in MMIO send */
	struct {
		u32 base;
		unsigned int count;
		enum forcewake_domains fw_domains;
	} send_regs;

68 69 70
	/* register used to send interrupts to the GuC FW */
	i915_reg_t notify_reg;

71 72 73
	/* Store msg (e.g. log flush) that we see while CTBs are disabled */
	u32 mmio_msg;

74 75 76 77
	/* To serialize the intel_guc_send actions */
	struct mutex send_mutex;
};

78 79 80 81 82
static inline struct intel_guc *log_to_guc(struct intel_guc_log *log)
{
	return container_of(log, struct intel_guc, log);
}

83 84 85
static
inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
{
86 87 88 89 90 91 92 93
	return intel_guc_ct_send(&guc->ct, action, len, NULL, 0, 0);
}

static
inline int intel_guc_send_nb(struct intel_guc *guc, const u32 *action, u32 len)
{
	return intel_guc_ct_send(&guc->ct, action, len, NULL, 0,
				 INTEL_GUC_CT_SEND_NB);
94 95 96 97 98 99
}

static inline int
intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
			   u32 *response_buf, u32 response_buf_size)
{
100
	return intel_guc_ct_send(&guc->ct, action, len,
101
				 response_buf, response_buf_size, 0);
102 103
}

104 105
static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
{
106
	intel_guc_ct_event_handler(&guc->ct);
107 108
}

109 110 111 112 113 114 115 116
/* 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.
 *
117
 * GuC does not allow any gfx GGTT address that falls into range
118 119
 * [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
120
 * GGTT, all gfx objects used by GuC are allocated with intel_guc_allocate_vma()
121
 * and pinned with PIN_OFFSET_BIAS along with the value of ggtt.pin_bias.
122
 *
123
 * Return: GGTT offset of the @vma.
124
 */
125 126
static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc,
					struct i915_vma *vma)
127 128 129
{
	u32 offset = i915_ggtt_offset(vma);

130
	GEM_BUG_ON(offset < i915_ggtt_pin_bias(vma));
131 132 133 134 135 136 137
	GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));

	return offset;
}

void intel_guc_init_early(struct intel_guc *guc);
void intel_guc_init_send_regs(struct intel_guc *guc);
138
void intel_guc_write_params(struct intel_guc *guc);
139 140
int intel_guc_init(struct intel_guc *guc);
void intel_guc_fini(struct intel_guc *guc);
141
void intel_guc_notify(struct intel_guc *guc);
142 143
int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len,
			u32 *response_buf, u32 response_buf_size);
144 145
int intel_guc_to_host_process_recv_msg(struct intel_guc *guc,
				       const u32 *payload, u32 len);
146
int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
147 148
int intel_guc_suspend(struct intel_guc *guc);
int intel_guc_resume(struct intel_guc *guc);
149
struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
150 151
int intel_guc_allocate_and_map_vma(struct intel_guc *guc, u32 size,
				   struct i915_vma **out_vma, void **out_vaddr);
152

153 154
static inline bool intel_guc_is_supported(struct intel_guc *guc)
{
155 156 157
	return intel_uc_fw_is_supported(&guc->fw);
}

158
static inline bool intel_guc_is_wanted(struct intel_guc *guc)
159 160
{
	return intel_uc_fw_is_enabled(&guc->fw);
161 162
}

163 164 165 166 167 168
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);
}

169
static inline bool intel_guc_is_fw_running(struct intel_guc *guc)
170
{
171
	return intel_uc_fw_is_running(&guc->fw);
172 173
}

174 175 176 177 178
static inline bool intel_guc_is_ready(struct intel_guc *guc)
{
	return intel_guc_is_fw_running(guc) && intel_guc_ct_enabled(&guc->ct);
}

179 180 181
static inline int intel_guc_sanitize(struct intel_guc *guc)
{
	intel_uc_fw_sanitize(&guc->fw);
182
	intel_guc_ct_sanitize(&guc->ct);
183 184
	guc->mmio_msg = 0;

185 186 187
	return 0;
}

188 189 190 191 192 193 194 195 196 197 198 199 200 201
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);
}

202 203 204
int intel_guc_reset_engine(struct intel_guc *guc,
			   struct intel_engine_cs *engine);

205 206
void intel_guc_load_status(struct intel_guc *guc, struct drm_printer *p);

207
#endif