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

#ifndef _INTEL_GUC_H_
#define _INTEL_GUC_H_

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

19 20
struct __guc_ads_blob;

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

	/* intel_guc_recv interrupt related state */
32 33
	spinlock_t irq_lock;
	unsigned int msg_enabled_mask;
34

35 36
	struct {
		bool enabled;
37 38 39
		void (*reset)(struct intel_guc *guc);
		void (*enable)(struct intel_guc *guc);
		void (*disable)(struct intel_guc *guc);
40 41
	} interrupts;

42 43
	bool submission_supported;

44
	struct i915_vma *ads_vma;
45 46
	struct __guc_ads_blob *ads_blob;

47 48 49
	struct i915_vma *stage_desc_pool;
	void *stage_desc_pool_vaddr;

50 51 52 53 54 55
	struct i915_vma *workqueue;
	void *workqueue_vaddr;
	spinlock_t wq_lock;

	struct i915_vma *proc_desc;
	void *proc_desc_vaddr;
56

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

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

67 68 69
	/* Store msg (e.g. log flush) that we see while CTBs are disabled */
	u32 mmio_msg;

70 71 72 73
	/* To serialize the intel_guc_send actions */
	struct mutex send_mutex;

	/* GuC's FW specific send function */
74 75
	int (*send)(struct intel_guc *guc, const u32 *data, u32 len,
		    u32 *response_buf, u32 response_buf_size);
76

77 78 79
	/* GuC's FW specific event handler function */
	void (*handler)(struct intel_guc *guc);

80 81 82 83 84 85 86
	/* GuC's FW specific notify function */
	void (*notify)(struct intel_guc *guc);
};

static
inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
{
87 88 89 90 91 92 93 94
	return guc->send(guc, action, len, NULL, 0);
}

static inline int
intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
			   u32 *response_buf, u32 response_buf_size)
{
	return guc->send(guc, action, len, response_buf, response_buf_size);
95 96 97 98 99 100 101
}

static inline void intel_guc_notify(struct intel_guc *guc)
{
	guc->notify(guc);
}

102 103 104 105 106
static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
{
	guc->handler(guc);
}

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

128
	GEM_BUG_ON(offset < i915_ggtt_pin_bias(vma));
129 130 131 132 133 134 135
	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);
136
void intel_guc_write_params(struct intel_guc *guc);
137 138
int intel_guc_init(struct intel_guc *guc);
void intel_guc_fini(struct intel_guc *guc);
139 140 141 142
int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len,
		       u32 *response_buf, u32 response_buf_size);
int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len,
			u32 *response_buf, u32 response_buf_size);
143
void intel_guc_to_host_event_handler(struct intel_guc *guc);
144
void intel_guc_to_host_event_handler_nop(struct intel_guc *guc);
145 146
int intel_guc_to_host_process_recv_msg(struct intel_guc *guc,
				       const u32 *payload, u32 len);
147 148
int intel_guc_sample_forcewake(struct intel_guc *guc);
int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
149 150
int intel_guc_suspend(struct intel_guc *guc);
int intel_guc_resume(struct intel_guc *guc);
151
struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
152 153
int intel_guc_allocate_and_map_vma(struct intel_guc *guc, u32 size,
				   struct i915_vma **out_vma, void **out_vaddr);
154

155 156
static inline bool intel_guc_is_supported(struct intel_guc *guc)
{
157 158 159 160 161 162
	return intel_uc_fw_is_supported(&guc->fw);
}

static inline bool intel_guc_is_enabled(struct intel_guc *guc)
{
	return intel_uc_fw_is_enabled(&guc->fw);
163 164
}

165
static inline bool intel_guc_is_running(struct intel_guc *guc)
166
{
167
	return intel_uc_fw_is_running(&guc->fw);
168 169
}

170 171 172
static inline int intel_guc_sanitize(struct intel_guc *guc)
{
	intel_uc_fw_sanitize(&guc->fw);
173 174
	guc->mmio_msg = 0;

175 176 177
	return 0;
}

178 179 180 181 182
static inline bool intel_guc_is_submission_supported(struct intel_guc *guc)
{
	return guc->submission_supported;
}

183 184 185 186 187 188 189 190 191 192 193 194 195 196
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);
}

197 198 199
int intel_guc_reset_engine(struct intel_guc *guc,
			   struct intel_engine_cs *engine);

200
#endif