Merge tag 'kbuild-v5.1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / i915 / intel_guc.h
1 /*
2  * Copyright © 2014-2017 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
25 #ifndef _INTEL_GUC_H_
26 #define _INTEL_GUC_H_
27
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"
35 #include "i915_vma.h"
36
37 struct guc_preempt_work {
38         struct work_struct work;
39         struct intel_engine_cs *engine;
40 };
41
42 /*
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.
46  */
47 struct intel_guc {
48         struct intel_uc_fw fw;
49         struct intel_guc_log log;
50         struct intel_guc_ct ct;
51
52         /* Log snapshot if GuC errors during load */
53         struct drm_i915_gem_object *load_err_log;
54
55         /* intel_guc_recv interrupt related state */
56         spinlock_t irq_lock;
57         bool interrupts_enabled;
58         unsigned int msg_enabled_mask;
59
60         struct i915_vma *ads_vma;
61         struct i915_vma *stage_desc_pool;
62         void *stage_desc_pool_vaddr;
63         struct ida stage_ids;
64         struct i915_vma *shared_data;
65         void *shared_data_vaddr;
66
67         struct intel_guc_client *execbuf_client;
68         struct intel_guc_client *preempt_client;
69
70         struct guc_preempt_work preempt_work[I915_NUM_ENGINES];
71         struct workqueue_struct *preempt_wq;
72
73         DECLARE_BITMAP(doorbell_bitmap, GUC_NUM_DOORBELLS);
74         /* Cyclic counter mod pagesize  */
75         u32 db_cacheline;
76
77         /* GuC's FW specific registers used in MMIO send */
78         struct {
79                 u32 base;
80                 unsigned int count;
81                 enum forcewake_domains fw_domains;
82         } send_regs;
83
84         /* To serialize the intel_guc_send actions */
85         struct mutex send_mutex;
86
87         /* GuC's FW specific send function */
88         int (*send)(struct intel_guc *guc, const u32 *data, u32 len,
89                     u32 *response_buf, u32 response_buf_size);
90
91         /* GuC's FW specific event handler function */
92         void (*handler)(struct intel_guc *guc);
93
94         /* GuC's FW specific notify function */
95         void (*notify)(struct intel_guc *guc);
96 };
97
98 static inline bool intel_guc_is_alive(struct intel_guc *guc)
99 {
100         return intel_uc_fw_is_loaded(&guc->fw);
101 }
102
103 static
104 inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
105 {
106         return guc->send(guc, action, len, NULL, 0);
107 }
108
109 static inline int
110 intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
111                            u32 *response_buf, u32 response_buf_size)
112 {
113         return guc->send(guc, action, len, response_buf, response_buf_size);
114 }
115
116 static inline void intel_guc_notify(struct intel_guc *guc)
117 {
118         guc->notify(guc);
119 }
120
121 static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
122 {
123         guc->handler(guc);
124 }
125
126 /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
127 #define GUC_GGTT_TOP    0xFEE00000
128
129 /**
130  * intel_guc_ggtt_offset() - Get and validate the GGTT offset of @vma
131  * @guc: intel_guc structure.
132  * @vma: i915 graphics virtual memory area.
133  *
134  * GuC does not allow any gfx GGTT address that falls into range
135  * [0, ggtt.pin_bias), which is reserved for Boot ROM, SRAM and WOPCM.
136  * Currently, in order to exclude [0, ggtt.pin_bias) address space from
137  * GGTT, all gfx objects used by GuC are allocated with intel_guc_allocate_vma()
138  * and pinned with PIN_OFFSET_BIAS along with the value of ggtt.pin_bias.
139  *
140  * Return: GGTT offset of the @vma.
141  */
142 static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc,
143                                         struct i915_vma *vma)
144 {
145         u32 offset = i915_ggtt_offset(vma);
146
147         GEM_BUG_ON(offset < i915_ggtt_pin_bias(vma));
148         GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
149
150         return offset;
151 }
152
153 void intel_guc_init_early(struct intel_guc *guc);
154 void intel_guc_init_send_regs(struct intel_guc *guc);
155 void intel_guc_init_params(struct intel_guc *guc);
156 int intel_guc_init_misc(struct intel_guc *guc);
157 int intel_guc_init(struct intel_guc *guc);
158 void intel_guc_fini(struct intel_guc *guc);
159 void intel_guc_fini_misc(struct intel_guc *guc);
160 int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len,
161                        u32 *response_buf, u32 response_buf_size);
162 int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len,
163                         u32 *response_buf, u32 response_buf_size);
164 void intel_guc_to_host_event_handler(struct intel_guc *guc);
165 void intel_guc_to_host_event_handler_nop(struct intel_guc *guc);
166 void intel_guc_to_host_event_handler_mmio(struct intel_guc *guc);
167 void intel_guc_to_host_process_recv_msg(struct intel_guc *guc, u32 msg);
168 int intel_guc_sample_forcewake(struct intel_guc *guc);
169 int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
170 int intel_guc_suspend(struct intel_guc *guc);
171 int intel_guc_resume(struct intel_guc *guc);
172 struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
173 u32 intel_guc_reserved_gtt_size(struct intel_guc *guc);
174
175 static inline int intel_guc_sanitize(struct intel_guc *guc)
176 {
177         intel_uc_fw_sanitize(&guc->fw);
178         return 0;
179 }
180
181 static inline void intel_guc_enable_msg(struct intel_guc *guc, u32 mask)
182 {
183         spin_lock_irq(&guc->irq_lock);
184         guc->msg_enabled_mask |= mask;
185         spin_unlock_irq(&guc->irq_lock);
186 }
187
188 static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)
189 {
190         spin_lock_irq(&guc->irq_lock);
191         guc->msg_enabled_mask &= ~mask;
192         spin_unlock_irq(&guc->irq_lock);
193 }
194
195 int intel_guc_reset_engine(struct intel_guc *guc,
196                            struct intel_engine_cs *engine);
197
198 #endif