2 * Copyright © 2014-2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include "intel_uncore.h"
29 #include "intel_guc_fw.h"
30 #include "intel_guc_fwif.h"
31 #include "intel_guc_ct.h"
32 #include "intel_guc_log.h"
33 #include "intel_guc_reg.h"
34 #include "intel_uc_fw.h"
37 struct guc_preempt_work {
38 struct work_struct work;
39 struct intel_engine_cs *engine;
43 * Top level structure of GuC. It handles firmware loading and manages client
44 * pool and doorbells. intel_guc owns a intel_guc_client to replace the legacy
45 * ExecList submission.
48 struct intel_uc_fw fw;
49 struct intel_guc_log log;
50 struct intel_guc_ct ct;
52 /* Offset where Non-WOPCM memory starts. */
55 /* Log snapshot if GuC errors during load */
56 struct drm_i915_gem_object *load_err_log;
58 /* intel_guc_recv interrupt related state */
60 bool interrupts_enabled;
61 unsigned int msg_enabled_mask;
63 struct i915_vma *ads_vma;
64 struct i915_vma *stage_desc_pool;
65 void *stage_desc_pool_vaddr;
67 struct i915_vma *shared_data;
68 void *shared_data_vaddr;
70 struct intel_guc_client *execbuf_client;
71 struct intel_guc_client *preempt_client;
73 struct guc_preempt_work preempt_work[I915_NUM_ENGINES];
74 struct workqueue_struct *preempt_wq;
76 DECLARE_BITMAP(doorbell_bitmap, GUC_NUM_DOORBELLS);
77 /* Cyclic counter mod pagesize */
80 /* GuC's FW specific registers used in MMIO send */
84 enum forcewake_domains fw_domains;
87 /* To serialize the intel_guc_send actions */
88 struct mutex send_mutex;
90 /* GuC's FW specific send function */
91 int (*send)(struct intel_guc *guc, const u32 *data, u32 len,
92 u32 *response_buf, u32 response_buf_size);
94 /* GuC's FW specific event handler function */
95 void (*handler)(struct intel_guc *guc);
97 /* GuC's FW specific notify function */
98 void (*notify)(struct intel_guc *guc);
102 inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
104 return guc->send(guc, action, len, NULL, 0);
108 intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
109 u32 *response_buf, u32 response_buf_size)
111 return guc->send(guc, action, len, response_buf, response_buf_size);
114 static inline void intel_guc_notify(struct intel_guc *guc)
119 static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
124 /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
125 #define GUC_GGTT_TOP 0xFEE00000
128 * intel_guc_ggtt_offset() - Get and validate the GGTT offset of @vma
129 * @guc: intel_guc structure.
130 * @vma: i915 graphics virtual memory area.
132 * GuC does not allow any gfx GGTT address that falls into range
133 * [0, GuC ggtt_pin_bias), which is reserved for Boot ROM, SRAM and WOPCM.
134 * Currently, in order to exclude [0, GuC ggtt_pin_bias) address space from
135 * GGTT, all gfx objects used by GuC are allocated with intel_guc_allocate_vma()
136 * and pinned with PIN_OFFSET_BIAS along with the value of GuC ggtt_pin_bias.
138 * Return: GGTT offset of the @vma.
140 static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc,
141 struct i915_vma *vma)
143 u32 offset = i915_ggtt_offset(vma);
145 GEM_BUG_ON(offset < guc->ggtt_pin_bias);
146 GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
151 void intel_guc_init_early(struct intel_guc *guc);
152 void intel_guc_init_send_regs(struct intel_guc *guc);
153 void intel_guc_init_params(struct intel_guc *guc);
154 void intel_guc_init_ggtt_pin_bias(struct intel_guc *guc);
155 int intel_guc_init_wq(struct intel_guc *guc);
156 void intel_guc_fini_wq(struct intel_guc *guc);
157 int intel_guc_init(struct intel_guc *guc);
158 void intel_guc_fini(struct intel_guc *guc);
159 int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len,
160 u32 *response_buf, u32 response_buf_size);
161 int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len,
162 u32 *response_buf, u32 response_buf_size);
163 void intel_guc_to_host_event_handler(struct intel_guc *guc);
164 void intel_guc_to_host_event_handler_nop(struct intel_guc *guc);
165 void intel_guc_to_host_event_handler_mmio(struct intel_guc *guc);
166 void intel_guc_to_host_process_recv_msg(struct intel_guc *guc, u32 msg);
167 int intel_guc_sample_forcewake(struct intel_guc *guc);
168 int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
169 int intel_guc_suspend(struct intel_guc *guc);
170 int intel_guc_resume(struct intel_guc *guc);
171 struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
173 static inline int intel_guc_sanitize(struct intel_guc *guc)
175 intel_uc_fw_sanitize(&guc->fw);
179 static inline void intel_guc_enable_msg(struct intel_guc *guc, u32 mask)
181 spin_lock_irq(&guc->irq_lock);
182 guc->msg_enabled_mask |= mask;
183 spin_unlock_irq(&guc->irq_lock);
186 static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)
188 spin_lock_irq(&guc->irq_lock);
189 guc->msg_enabled_mask &= ~mask;
190 spin_unlock_irq(&guc->irq_lock);