]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/i915/intel_uc.h
Merge tag 'gvt-next-2017-06-08' of https://github.com/01org/gvt-linux into drm-intel...
[linux.git] / drivers / gpu / drm / i915 / intel_uc.h
1 /*
2  * Copyright © 2014 Intel Corporation
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  *
23  */
24 #ifndef _INTEL_UC_H_
25 #define _INTEL_UC_H_
26
27 #include "intel_guc_fwif.h"
28 #include "i915_guc_reg.h"
29 #include "intel_ringbuffer.h"
30 #include "intel_guc_ct.h"
31 #include "i915_vma.h"
32
33 struct drm_i915_gem_request;
34
35 /*
36  * This structure primarily describes the GEM object shared with the GuC.
37  * The specs sometimes refer to this object as a "GuC context", but we use
38  * the term "client" to avoid confusion with hardware contexts. This
39  * GEM object is held for the entire lifetime of our interaction with
40  * the GuC, being allocated before the GuC is loaded with its firmware.
41  * Because there's no way to update the address used by the GuC after
42  * initialisation, the shared object must stay pinned into the GGTT as
43  * long as the GuC is in use. We also keep the first page (only) mapped
44  * into kernel address space, as it includes shared data that must be
45  * updated on every request submission.
46  *
47  * The single GEM object described here is actually made up of several
48  * separate areas, as far as the GuC is concerned. The first page (kept
49  * kmap'd) includes the "process descriptor" which holds sequence data for
50  * the doorbell, and one cacheline which actually *is* the doorbell; a
51  * write to this will "ring the doorbell" (i.e. send an interrupt to the
52  * GuC). The subsequent  pages of the client object constitute the work
53  * queue (a circular array of work items), again described in the process
54  * descriptor. Work queue pages are mapped momentarily as required.
55  *
56  * We also keep a few statistics on failures. Ideally, these should all
57  * be zero!
58  *   no_wq_space: times that the submission pre-check found no space was
59  *                available in the work queue (note, the queue is shared,
60  *                not per-engine). It is OK for this to be nonzero, but
61  *                it should not be huge!
62  */
63 struct i915_guc_client {
64         struct i915_vma *vma;
65         void *vaddr;
66         struct i915_gem_context *owner;
67         struct intel_guc *guc;
68
69         uint32_t engines;               /* bitmap of (host) engine ids  */
70         uint32_t priority;
71         u32 stage_id;
72         uint32_t proc_desc_offset;
73
74         u16 doorbell_id;
75         unsigned long doorbell_offset;
76         u32 doorbell_cookie;
77
78         spinlock_t wq_lock;
79         uint32_t wq_offset;
80         uint32_t wq_size;
81         uint32_t wq_tail;
82         uint32_t wq_rsvd;
83         uint32_t no_wq_space;
84
85         /* Per-engine counts of GuC submissions */
86         uint64_t submissions[I915_NUM_ENGINES];
87 };
88
89 enum intel_uc_fw_status {
90         INTEL_UC_FIRMWARE_FAIL = -1,
91         INTEL_UC_FIRMWARE_NONE = 0,
92         INTEL_UC_FIRMWARE_PENDING,
93         INTEL_UC_FIRMWARE_SUCCESS
94 };
95
96 /* User-friendly representation of an enum */
97 static inline
98 const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status)
99 {
100         switch (status) {
101         case INTEL_UC_FIRMWARE_FAIL:
102                 return "FAIL";
103         case INTEL_UC_FIRMWARE_NONE:
104                 return "NONE";
105         case INTEL_UC_FIRMWARE_PENDING:
106                 return "PENDING";
107         case INTEL_UC_FIRMWARE_SUCCESS:
108                 return "SUCCESS";
109         }
110         return "<invalid>";
111 }
112
113 enum intel_uc_fw_type {
114         INTEL_UC_FW_TYPE_GUC,
115         INTEL_UC_FW_TYPE_HUC
116 };
117
118 /* User-friendly representation of an enum */
119 static inline const char *intel_uc_fw_type_repr(enum intel_uc_fw_type type)
120 {
121         switch (type) {
122         case INTEL_UC_FW_TYPE_GUC:
123                 return "GuC";
124         case INTEL_UC_FW_TYPE_HUC:
125                 return "HuC";
126         }
127         return "uC";
128 }
129
130 /*
131  * This structure encapsulates all the data needed during the process
132  * of fetching, caching, and loading the firmware image into the GuC.
133  */
134 struct intel_uc_fw {
135         const char *path;
136         size_t size;
137         struct drm_i915_gem_object *obj;
138         enum intel_uc_fw_status fetch_status;
139         enum intel_uc_fw_status load_status;
140
141         uint16_t major_ver_wanted;
142         uint16_t minor_ver_wanted;
143         uint16_t major_ver_found;
144         uint16_t minor_ver_found;
145
146         enum intel_uc_fw_type type;
147         uint32_t header_size;
148         uint32_t header_offset;
149         uint32_t rsa_size;
150         uint32_t rsa_offset;
151         uint32_t ucode_size;
152         uint32_t ucode_offset;
153 };
154
155 struct intel_guc_log {
156         uint32_t flags;
157         struct i915_vma *vma;
158         /* The runtime stuff gets created only when GuC logging gets enabled */
159         struct {
160                 void *buf_addr;
161                 struct workqueue_struct *flush_wq;
162                 struct work_struct flush_work;
163                 struct rchan *relay_chan;
164         } runtime;
165         /* logging related stats */
166         u32 capture_miss_count;
167         u32 flush_interrupt_count;
168         u32 prev_overflow_count[GUC_MAX_LOG_BUFFER];
169         u32 total_overflow_count[GUC_MAX_LOG_BUFFER];
170         u32 flush_count[GUC_MAX_LOG_BUFFER];
171 };
172
173 struct intel_guc {
174         struct intel_uc_fw fw;
175         struct intel_guc_log log;
176         struct intel_guc_ct ct;
177
178         /* Log snapshot if GuC errors during load */
179         struct drm_i915_gem_object *load_err_log;
180
181         /* intel_guc_recv interrupt related state */
182         bool interrupts_enabled;
183
184         struct i915_vma *ads_vma;
185         struct i915_vma *stage_desc_pool;
186         void *stage_desc_pool_vaddr;
187         struct ida stage_ids;
188
189         struct i915_guc_client *execbuf_client;
190
191         DECLARE_BITMAP(doorbell_bitmap, GUC_NUM_DOORBELLS);
192         uint32_t db_cacheline;          /* Cyclic counter mod pagesize  */
193
194         /* GuC's FW specific registers used in MMIO send */
195         struct {
196                 u32 base;
197                 unsigned int count;
198                 enum forcewake_domains fw_domains;
199         } send_regs;
200
201         /* To serialize the intel_guc_send actions */
202         struct mutex send_mutex;
203
204         /* GuC's FW specific send function */
205         int (*send)(struct intel_guc *guc, const u32 *data, u32 len);
206
207         /* GuC's FW specific notify function */
208         void (*notify)(struct intel_guc *guc);
209 };
210
211 struct intel_huc {
212         /* Generic uC firmware management */
213         struct intel_uc_fw fw;
214
215         /* HuC-specific additions */
216 };
217
218 /* intel_uc.c */
219 void intel_uc_sanitize_options(struct drm_i915_private *dev_priv);
220 void intel_uc_init_early(struct drm_i915_private *dev_priv);
221 void intel_uc_init_fw(struct drm_i915_private *dev_priv);
222 void intel_uc_fini_fw(struct drm_i915_private *dev_priv);
223 int intel_uc_init_hw(struct drm_i915_private *dev_priv);
224 void intel_uc_fini_hw(struct drm_i915_private *dev_priv);
225 int intel_guc_sample_forcewake(struct intel_guc *guc);
226 int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len);
227 int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len);
228
229 static inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
230 {
231         return guc->send(guc, action, len);
232 }
233
234 static inline void intel_guc_notify(struct intel_guc *guc)
235 {
236         guc->notify(guc);
237 }
238
239 /* intel_guc_loader.c */
240 int intel_guc_select_fw(struct intel_guc *guc);
241 int intel_guc_init_hw(struct intel_guc *guc);
242 int intel_guc_suspend(struct drm_i915_private *dev_priv);
243 int intel_guc_resume(struct drm_i915_private *dev_priv);
244 u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
245
246 /* i915_guc_submission.c */
247 int i915_guc_submission_init(struct drm_i915_private *dev_priv);
248 int i915_guc_submission_enable(struct drm_i915_private *dev_priv);
249 int i915_guc_wq_reserve(struct drm_i915_gem_request *rq);
250 void i915_guc_wq_unreserve(struct drm_i915_gem_request *request);
251 void i915_guc_submission_disable(struct drm_i915_private *dev_priv);
252 void i915_guc_submission_fini(struct drm_i915_private *dev_priv);
253 struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
254
255 /* intel_guc_log.c */
256 int intel_guc_log_create(struct intel_guc *guc);
257 void intel_guc_log_destroy(struct intel_guc *guc);
258 int i915_guc_log_control(struct drm_i915_private *dev_priv, u64 control_val);
259 void i915_guc_log_register(struct drm_i915_private *dev_priv);
260 void i915_guc_log_unregister(struct drm_i915_private *dev_priv);
261
262 static inline u32 guc_ggtt_offset(struct i915_vma *vma)
263 {
264         u32 offset = i915_ggtt_offset(vma);
265         GEM_BUG_ON(offset < GUC_WOPCM_TOP);
266         GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
267         return offset;
268 }
269
270 /* intel_huc.c */
271 void intel_huc_select_fw(struct intel_huc *huc);
272 void intel_huc_init_hw(struct intel_huc *huc);
273 void intel_guc_auth_huc(struct drm_i915_private *dev_priv);
274
275 #endif