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