]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/i915/i915_drv.h
drm/i915: Complete kerneldoc for struct i915_gem_context
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / i915 / i915_drv.h
CommitLineData
1da177e4
LT
1/* i915_drv.h -- Private header for the I915 driver -*- linux-c -*-
2 */
0d6aa60b 3/*
bc54fd1a 4 *
1da177e4
LT
5 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * All Rights Reserved.
bc54fd1a
DA
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
0d6aa60b 28 */
1da177e4
LT
29
30#ifndef _I915_DRV_H_
31#define _I915_DRV_H_
32
e9b73c67 33#include <uapi/drm/i915_drm.h>
93b81f51 34#include <uapi/drm/drm_fourcc.h>
e9b73c67 35
0839ccb8 36#include <linux/io-mapping.h>
f899fc64 37#include <linux/i2c.h>
c167a6fc 38#include <linux/i2c-algo-bit.h>
aaa6fd2a 39#include <linux/backlight.h>
5cc9ed4b 40#include <linux/hashtable.h>
2911a35b 41#include <linux/intel-iommu.h>
742cbee8 42#include <linux/kref.h>
9ee32fea 43#include <linux/pm_qos.h>
d07f0e59 44#include <linux/reservation.h>
e73bdd20
CW
45#include <linux/shmem_fs.h>
46
47#include <drm/drmP.h>
48#include <drm/intel-gtt.h>
49#include <drm/drm_legacy.h> /* for struct drm_dma_handle */
50#include <drm/drm_gem.h>
3b96a0b1 51#include <drm/drm_auth.h>
e73bdd20
CW
52
53#include "i915_params.h"
54#include "i915_reg.h"
55
56#include "intel_bios.h"
ac7f11c6 57#include "intel_dpll_mgr.h"
8c4f24f9 58#include "intel_uc.h"
e73bdd20
CW
59#include "intel_lrc.h"
60#include "intel_ringbuffer.h"
61
d501b1d2 62#include "i915_gem.h"
6095868a 63#include "i915_gem_context.h"
b42fe9ca
JL
64#include "i915_gem_fence_reg.h"
65#include "i915_gem_object.h"
e73bdd20
CW
66#include "i915_gem_gtt.h"
67#include "i915_gem_render_state.h"
05235c53 68#include "i915_gem_request.h"
73cb9701 69#include "i915_gem_timeline.h"
585fb111 70
b42fe9ca
JL
71#include "i915_vma.h"
72
0ad35fed
ZW
73#include "intel_gvt.h"
74
1da177e4
LT
75/* General customization:
76 */
77
1da177e4
LT
78#define DRIVER_NAME "i915"
79#define DRIVER_DESC "Intel Graphics"
f061ff07
DV
80#define DRIVER_DATE "20161226"
81#define DRIVER_TIMESTAMP 1482767304
1da177e4 82
c883ef1b 83#undef WARN_ON
5f77eeb0
DV
84/* Many gcc seem to no see through this and fall over :( */
85#if 0
86#define WARN_ON(x) ({ \
87 bool __i915_warn_cond = (x); \
88 if (__builtin_constant_p(__i915_warn_cond)) \
89 BUILD_BUG_ON(__i915_warn_cond); \
90 WARN(__i915_warn_cond, "WARN_ON(" #x ")"); })
91#else
152b2262 92#define WARN_ON(x) WARN((x), "%s", "WARN_ON(" __stringify(x) ")")
5f77eeb0
DV
93#endif
94
cd9bfacb 95#undef WARN_ON_ONCE
152b2262 96#define WARN_ON_ONCE(x) WARN_ONCE((x), "%s", "WARN_ON_ONCE(" __stringify(x) ")")
cd9bfacb 97
5f77eeb0
DV
98#define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \
99 (long) (x), __func__);
c883ef1b 100
e2c719b7
RC
101/* Use I915_STATE_WARN(x) and I915_STATE_WARN_ON() (rather than WARN() and
102 * WARN_ON()) for hw state sanity checks to check for unexpected conditions
103 * which may not necessarily be a user visible problem. This will either
104 * WARN() or DRM_ERROR() depending on the verbose_checks moduleparam, to
105 * enable distros and users to tailor their preferred amount of i915 abrt
106 * spam.
107 */
108#define I915_STATE_WARN(condition, format...) ({ \
109 int __ret_warn_on = !!(condition); \
32753cb8
JL
110 if (unlikely(__ret_warn_on)) \
111 if (!WARN(i915.verbose_state_checks, format)) \
e2c719b7 112 DRM_ERROR(format); \
e2c719b7
RC
113 unlikely(__ret_warn_on); \
114})
115
152b2262
JL
116#define I915_STATE_WARN_ON(x) \
117 I915_STATE_WARN((x), "%s", "WARN_ON(" __stringify(x) ")")
c883ef1b 118
4fec15d1
ID
119bool __i915_inject_load_failure(const char *func, int line);
120#define i915_inject_load_failure() \
121 __i915_inject_load_failure(__func__, __LINE__)
122
b95320bd
MK
123typedef struct {
124 uint32_t val;
125} uint_fixed_16_16_t;
126
127#define FP_16_16_MAX ({ \
128 uint_fixed_16_16_t fp; \
129 fp.val = UINT_MAX; \
130 fp; \
131})
132
133static inline uint_fixed_16_16_t u32_to_fixed_16_16(uint32_t val)
134{
135 uint_fixed_16_16_t fp;
136
137 WARN_ON(val >> 16);
138
139 fp.val = val << 16;
140 return fp;
141}
142
143static inline uint32_t fixed_16_16_to_u32_round_up(uint_fixed_16_16_t fp)
144{
145 return DIV_ROUND_UP(fp.val, 1 << 16);
146}
147
148static inline uint32_t fixed_16_16_to_u32(uint_fixed_16_16_t fp)
149{
150 return fp.val >> 16;
151}
152
153static inline uint_fixed_16_16_t min_fixed_16_16(uint_fixed_16_16_t min1,
154 uint_fixed_16_16_t min2)
155{
156 uint_fixed_16_16_t min;
157
158 min.val = min(min1.val, min2.val);
159 return min;
160}
161
162static inline uint_fixed_16_16_t max_fixed_16_16(uint_fixed_16_16_t max1,
163 uint_fixed_16_16_t max2)
164{
165 uint_fixed_16_16_t max;
166
167 max.val = max(max1.val, max2.val);
168 return max;
169}
170
171static inline uint_fixed_16_16_t fixed_16_16_div_round_up(uint32_t val,
172 uint32_t d)
173{
174 uint_fixed_16_16_t fp, res;
175
176 fp = u32_to_fixed_16_16(val);
177 res.val = DIV_ROUND_UP(fp.val, d);
178 return res;
179}
180
181static inline uint_fixed_16_16_t fixed_16_16_div_round_up_u64(uint32_t val,
182 uint32_t d)
183{
184 uint_fixed_16_16_t res;
185 uint64_t interm_val;
186
187 interm_val = (uint64_t)val << 16;
188 interm_val = DIV_ROUND_UP_ULL(interm_val, d);
189 WARN_ON(interm_val >> 32);
190 res.val = (uint32_t) interm_val;
191
192 return res;
193}
194
195static inline uint_fixed_16_16_t mul_u32_fixed_16_16(uint32_t val,
196 uint_fixed_16_16_t mul)
197{
198 uint64_t intermediate_val;
199 uint_fixed_16_16_t fp;
200
201 intermediate_val = (uint64_t) val * mul.val;
202 WARN_ON(intermediate_val >> 32);
203 fp.val = (uint32_t) intermediate_val;
204 return fp;
205}
206
42a8ca4c
JN
207static inline const char *yesno(bool v)
208{
209 return v ? "yes" : "no";
210}
211
87ad3212
JN
212static inline const char *onoff(bool v)
213{
214 return v ? "on" : "off";
215}
216
08c4d7fc
TU
217static inline const char *enableddisabled(bool v)
218{
219 return v ? "enabled" : "disabled";
220}
221
86e61735
MA
222#define range_overflows(start, size, max) ({ \
223 typeof(start) start__ = (start); \
224 typeof(size) size__ = (size); \
225 typeof(max) max__ = (max); \
226 (void)(&start__ == &size__); \
227 (void)(&start__ == &max__); \
228 start__ > max__ || size__ > max__ - start__; \
229})
230
231#define range_overflows_t(type, start, size, max) \
232 range_overflows((type)(start), (type)(size), (type)(max))
233
317c35d1 234enum pipe {
752aa88a 235 INVALID_PIPE = -1,
317c35d1
JB
236 PIPE_A = 0,
237 PIPE_B,
9db4a9c7 238 PIPE_C,
a57c774a
AK
239 _PIPE_EDP,
240 I915_MAX_PIPES = _PIPE_EDP
317c35d1 241};
9db4a9c7 242#define pipe_name(p) ((p) + 'A')
317c35d1 243
a5c961d1
PZ
244enum transcoder {
245 TRANSCODER_A = 0,
246 TRANSCODER_B,
247 TRANSCODER_C,
a57c774a 248 TRANSCODER_EDP,
4d1de975
JN
249 TRANSCODER_DSI_A,
250 TRANSCODER_DSI_C,
a57c774a 251 I915_MAX_TRANSCODERS
a5c961d1 252};
da205630
JN
253
254static inline const char *transcoder_name(enum transcoder transcoder)
255{
256 switch (transcoder) {
257 case TRANSCODER_A:
258 return "A";
259 case TRANSCODER_B:
260 return "B";
261 case TRANSCODER_C:
262 return "C";
263 case TRANSCODER_EDP:
264 return "EDP";
4d1de975
JN
265 case TRANSCODER_DSI_A:
266 return "DSI A";
267 case TRANSCODER_DSI_C:
268 return "DSI C";
da205630
JN
269 default:
270 return "<invalid>";
271 }
272}
a5c961d1 273
4d1de975
JN
274static inline bool transcoder_is_dsi(enum transcoder transcoder)
275{
276 return transcoder == TRANSCODER_DSI_A || transcoder == TRANSCODER_DSI_C;
277}
278
84139d1e 279/*
b14e5848
VS
280 * Global legacy plane identifier. Valid only for primary/sprite
281 * planes on pre-g4x, and only for primary planes on g4x+.
84139d1e 282 */
80824003 283enum plane {
b14e5848 284 PLANE_A,
80824003 285 PLANE_B,
9db4a9c7 286 PLANE_C,
80824003 287};
9db4a9c7 288#define plane_name(p) ((p) + 'A')
52440211 289
580503c7 290#define sprite_name(p, s) ((p) * INTEL_INFO(dev_priv)->num_sprites[(p)] + (s) + 'A')
06da8da2 291
b14e5848
VS
292/*
293 * Per-pipe plane identifier.
294 * I915_MAX_PLANES in the enum below is the maximum (across all platforms)
295 * number of planes per CRTC. Not all platforms really have this many planes,
296 * which means some arrays of size I915_MAX_PLANES may have unused entries
297 * between the topmost sprite plane and the cursor plane.
298 *
299 * This is expected to be passed to various register macros
300 * (eg. PLANE_CTL(), PS_PLANE_SEL(), etc.) so adjust with care.
301 */
302enum plane_id {
303 PLANE_PRIMARY,
304 PLANE_SPRITE0,
305 PLANE_SPRITE1,
306 PLANE_CURSOR,
307 I915_MAX_PLANES,
308};
309
d97d7b48
VS
310#define for_each_plane_id_on_crtc(__crtc, __p) \
311 for ((__p) = PLANE_PRIMARY; (__p) < I915_MAX_PLANES; (__p)++) \
312 for_each_if ((__crtc)->plane_ids_mask & BIT(__p))
313
2b139522 314enum port {
03cdc1d4 315 PORT_NONE = -1,
2b139522
ED
316 PORT_A = 0,
317 PORT_B,
318 PORT_C,
319 PORT_D,
320 PORT_E,
321 I915_MAX_PORTS
322};
323#define port_name(p) ((p) + 'A')
324
a09caddd 325#define I915_NUM_PHYS_VLV 2
e4607fcf
CML
326
327enum dpio_channel {
328 DPIO_CH0,
329 DPIO_CH1
330};
331
332enum dpio_phy {
333 DPIO_PHY0,
0a116ce8
ACO
334 DPIO_PHY1,
335 DPIO_PHY2,
e4607fcf
CML
336};
337
b97186f0
PZ
338enum intel_display_power_domain {
339 POWER_DOMAIN_PIPE_A,
340 POWER_DOMAIN_PIPE_B,
341 POWER_DOMAIN_PIPE_C,
342 POWER_DOMAIN_PIPE_A_PANEL_FITTER,
343 POWER_DOMAIN_PIPE_B_PANEL_FITTER,
344 POWER_DOMAIN_PIPE_C_PANEL_FITTER,
345 POWER_DOMAIN_TRANSCODER_A,
346 POWER_DOMAIN_TRANSCODER_B,
347 POWER_DOMAIN_TRANSCODER_C,
f52e353e 348 POWER_DOMAIN_TRANSCODER_EDP,
4d1de975
JN
349 POWER_DOMAIN_TRANSCODER_DSI_A,
350 POWER_DOMAIN_TRANSCODER_DSI_C,
6331a704
PJ
351 POWER_DOMAIN_PORT_DDI_A_LANES,
352 POWER_DOMAIN_PORT_DDI_B_LANES,
353 POWER_DOMAIN_PORT_DDI_C_LANES,
354 POWER_DOMAIN_PORT_DDI_D_LANES,
355 POWER_DOMAIN_PORT_DDI_E_LANES,
319be8ae
ID
356 POWER_DOMAIN_PORT_DSI,
357 POWER_DOMAIN_PORT_CRT,
358 POWER_DOMAIN_PORT_OTHER,
cdf8dd7f 359 POWER_DOMAIN_VGA,
fbeeaa23 360 POWER_DOMAIN_AUDIO,
bd2bb1b9 361 POWER_DOMAIN_PLLS,
1407121a
S
362 POWER_DOMAIN_AUX_A,
363 POWER_DOMAIN_AUX_B,
364 POWER_DOMAIN_AUX_C,
365 POWER_DOMAIN_AUX_D,
f0ab43e6 366 POWER_DOMAIN_GMBUS,
dfa57627 367 POWER_DOMAIN_MODESET,
baa70707 368 POWER_DOMAIN_INIT,
bddc7645
ID
369
370 POWER_DOMAIN_NUM,
b97186f0
PZ
371};
372
373#define POWER_DOMAIN_PIPE(pipe) ((pipe) + POWER_DOMAIN_PIPE_A)
374#define POWER_DOMAIN_PIPE_PANEL_FITTER(pipe) \
375 ((pipe) + POWER_DOMAIN_PIPE_A_PANEL_FITTER)
f52e353e
ID
376#define POWER_DOMAIN_TRANSCODER(tran) \
377 ((tran) == TRANSCODER_EDP ? POWER_DOMAIN_TRANSCODER_EDP : \
378 (tran) + POWER_DOMAIN_TRANSCODER_A)
b97186f0 379
1d843f9d
EE
380enum hpd_pin {
381 HPD_NONE = 0,
1d843f9d
EE
382 HPD_TV = HPD_NONE, /* TV is known to be unreliable */
383 HPD_CRT,
384 HPD_SDVO_B,
385 HPD_SDVO_C,
cc24fcdc 386 HPD_PORT_A,
1d843f9d
EE
387 HPD_PORT_B,
388 HPD_PORT_C,
389 HPD_PORT_D,
26951caf 390 HPD_PORT_E,
1d843f9d
EE
391 HPD_NUM_PINS
392};
393
c91711f9
JN
394#define for_each_hpd_pin(__pin) \
395 for ((__pin) = (HPD_NONE + 1); (__pin) < HPD_NUM_PINS; (__pin)++)
396
5fcece80
JN
397struct i915_hotplug {
398 struct work_struct hotplug_work;
399
400 struct {
401 unsigned long last_jiffies;
402 int count;
403 enum {
404 HPD_ENABLED = 0,
405 HPD_DISABLED = 1,
406 HPD_MARK_DISABLED = 2
407 } state;
408 } stats[HPD_NUM_PINS];
409 u32 event_bits;
410 struct delayed_work reenable_work;
411
412 struct intel_digital_port *irq_port[I915_MAX_PORTS];
413 u32 long_port_mask;
414 u32 short_port_mask;
415 struct work_struct dig_port_work;
416
19625e85
L
417 struct work_struct poll_init_work;
418 bool poll_enabled;
419
5fcece80
JN
420 /*
421 * if we get a HPD irq from DP and a HPD irq from non-DP
422 * the non-DP HPD could block the workqueue on a mode config
423 * mutex getting, that userspace may have taken. However
424 * userspace is waiting on the DP workqueue to run which is
425 * blocked behind the non-DP one.
426 */
427 struct workqueue_struct *dp_wq;
428};
429
2a2d5482
CW
430#define I915_GEM_GPU_DOMAINS \
431 (I915_GEM_DOMAIN_RENDER | \
432 I915_GEM_DOMAIN_SAMPLER | \
433 I915_GEM_DOMAIN_COMMAND | \
434 I915_GEM_DOMAIN_INSTRUCTION | \
435 I915_GEM_DOMAIN_VERTEX)
62fdfeaf 436
055e393f
DL
437#define for_each_pipe(__dev_priv, __p) \
438 for ((__p) = 0; (__p) < INTEL_INFO(__dev_priv)->num_pipes; (__p)++)
6831f3e3
VS
439#define for_each_pipe_masked(__dev_priv, __p, __mask) \
440 for ((__p) = 0; (__p) < INTEL_INFO(__dev_priv)->num_pipes; (__p)++) \
441 for_each_if ((__mask) & (1 << (__p)))
8b364b41 442#define for_each_universal_plane(__dev_priv, __pipe, __p) \
dd740780
DL
443 for ((__p) = 0; \
444 (__p) < INTEL_INFO(__dev_priv)->num_sprites[(__pipe)] + 1; \
445 (__p)++)
3bdcfc0c
DL
446#define for_each_sprite(__dev_priv, __p, __s) \
447 for ((__s) = 0; \
448 (__s) < INTEL_INFO(__dev_priv)->num_sprites[(__p)]; \
449 (__s)++)
9db4a9c7 450
c3aeadc8
JN
451#define for_each_port_masked(__port, __ports_mask) \
452 for ((__port) = PORT_A; (__port) < I915_MAX_PORTS; (__port)++) \
453 for_each_if ((__ports_mask) & (1 << (__port)))
454
d79b814d 455#define for_each_crtc(dev, crtc) \
91c8a326 456 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
d79b814d 457
27321ae8
ML
458#define for_each_intel_plane(dev, intel_plane) \
459 list_for_each_entry(intel_plane, \
91c8a326 460 &(dev)->mode_config.plane_list, \
27321ae8
ML
461 base.head)
462
c107acfe 463#define for_each_intel_plane_mask(dev, intel_plane, plane_mask) \
91c8a326
CW
464 list_for_each_entry(intel_plane, \
465 &(dev)->mode_config.plane_list, \
c107acfe
MR
466 base.head) \
467 for_each_if ((plane_mask) & \
468 (1 << drm_plane_index(&intel_plane->base)))
469
262cd2e1
VS
470#define for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) \
471 list_for_each_entry(intel_plane, \
472 &(dev)->mode_config.plane_list, \
473 base.head) \
95150bdf 474 for_each_if ((intel_plane)->pipe == (intel_crtc)->pipe)
262cd2e1 475
91c8a326
CW
476#define for_each_intel_crtc(dev, intel_crtc) \
477 list_for_each_entry(intel_crtc, \
478 &(dev)->mode_config.crtc_list, \
479 base.head)
d063ae48 480
91c8a326
CW
481#define for_each_intel_crtc_mask(dev, intel_crtc, crtc_mask) \
482 list_for_each_entry(intel_crtc, \
483 &(dev)->mode_config.crtc_list, \
484 base.head) \
98d39494
MR
485 for_each_if ((crtc_mask) & (1 << drm_crtc_index(&intel_crtc->base)))
486
b2784e15
DL
487#define for_each_intel_encoder(dev, intel_encoder) \
488 list_for_each_entry(intel_encoder, \
489 &(dev)->mode_config.encoder_list, \
490 base.head)
491
3a3371ff
ACO
492#define for_each_intel_connector(dev, intel_connector) \
493 list_for_each_entry(intel_connector, \
91c8a326 494 &(dev)->mode_config.connector_list, \
3a3371ff
ACO
495 base.head)
496
6c2b7c12
DV
497#define for_each_encoder_on_crtc(dev, __crtc, intel_encoder) \
498 list_for_each_entry((intel_encoder), &(dev)->mode_config.encoder_list, base.head) \
95150bdf 499 for_each_if ((intel_encoder)->base.crtc == (__crtc))
6c2b7c12 500
53f5e3ca
JB
501#define for_each_connector_on_encoder(dev, __encoder, intel_connector) \
502 list_for_each_entry((intel_connector), &(dev)->mode_config.connector_list, base.head) \
95150bdf 503 for_each_if ((intel_connector)->base.encoder == (__encoder))
53f5e3ca 504
b04c5bd6
BF
505#define for_each_power_domain(domain, mask) \
506 for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \
95150bdf 507 for_each_if ((1 << (domain)) & (mask))
b04c5bd6 508
e7b903d2 509struct drm_i915_private;
ad46cb53 510struct i915_mm_struct;
5cc9ed4b 511struct i915_mmu_object;
e7b903d2 512
a6f766f3
CW
513struct drm_i915_file_private {
514 struct drm_i915_private *dev_priv;
515 struct drm_file *file;
516
517 struct {
518 spinlock_t lock;
519 struct list_head request_list;
d0bc54f2
CW
520/* 20ms is a fairly arbitrary limit (greater than the average frame time)
521 * chosen to prevent the CPU getting more than a frame ahead of the GPU
522 * (when using lax throttling for the frontbuffer). We also use it to
523 * offer free GPU waitboosts for severely congested workloads.
524 */
525#define DRM_I915_THROTTLE_JIFFIES msecs_to_jiffies(20)
a6f766f3
CW
526 } mm;
527 struct idr context_idr;
528
2e1b8730
CW
529 struct intel_rps_client {
530 struct list_head link;
531 unsigned boosts;
532 } rps;
a6f766f3 533
c80ff16e 534 unsigned int bsd_engine;
b083a087
MK
535
536/* Client can have a maximum of 3 contexts banned before
537 * it is denied of creating new contexts. As one context
538 * ban needs 4 consecutive hangs, and more if there is
539 * progress in between, this is a last resort stop gap measure
540 * to limit the badly behaving clients access to gpu.
541 */
542#define I915_MAX_CLIENT_CONTEXT_BANS 3
543 int context_bans;
a6f766f3
CW
544};
545
e69d0bc1
DV
546/* Used by dp and fdi links */
547struct intel_link_m_n {
548 uint32_t tu;
549 uint32_t gmch_m;
550 uint32_t gmch_n;
551 uint32_t link_m;
552 uint32_t link_n;
553};
554
555void intel_link_compute_m_n(int bpp, int nlanes,
556 int pixel_clock, int link_clock,
557 struct intel_link_m_n *m_n);
558
1da177e4
LT
559/* Interface history:
560 *
561 * 1.1: Original.
0d6aa60b
DA
562 * 1.2: Add Power Management
563 * 1.3: Add vblank support
de227f5f 564 * 1.4: Fix cmdbuffer path, add heap destroy
702880f2 565 * 1.5: Add vblank pipe configuration
2228ed67
MD
566 * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
567 * - Support vertical blank on secondary display pipe
1da177e4
LT
568 */
569#define DRIVER_MAJOR 1
2228ed67 570#define DRIVER_MINOR 6
1da177e4
LT
571#define DRIVER_PATCHLEVEL 0
572
0a3e67a4
JB
573struct opregion_header;
574struct opregion_acpi;
575struct opregion_swsci;
576struct opregion_asle;
577
8ee1c3db 578struct intel_opregion {
115719fc
WD
579 struct opregion_header *header;
580 struct opregion_acpi *acpi;
581 struct opregion_swsci *swsci;
ebde53c7
JN
582 u32 swsci_gbda_sub_functions;
583 u32 swsci_sbcb_sub_functions;
115719fc 584 struct opregion_asle *asle;
04ebaadb 585 void *rvda;
82730385 586 const void *vbt;
ada8f955 587 u32 vbt_size;
115719fc 588 u32 *lid_state;
91a60f20 589 struct work_struct asle_work;
8ee1c3db 590};
44834a67 591#define OPREGION_SIZE (8*1024)
8ee1c3db 592
6ef3d427
CW
593struct intel_overlay;
594struct intel_overlay_error_state;
595
9b9d172d 596struct sdvo_device_mapping {
e957d772 597 u8 initialized;
9b9d172d 598 u8 dvo_port;
599 u8 slave_addr;
600 u8 dvo_wiring;
e957d772 601 u8 i2c_pin;
b1083333 602 u8 ddc_pin;
9b9d172d 603};
604
7bd688cd 605struct intel_connector;
820d2d77 606struct intel_encoder;
ccf010fb 607struct intel_atomic_state;
5cec258b 608struct intel_crtc_state;
5724dbd1 609struct intel_initial_plane_config;
0e8ffe1b 610struct intel_crtc;
ee9300bb
DV
611struct intel_limit;
612struct dpll;
b8cecdf5 613
e70236a8 614struct drm_i915_display_funcs {
1353c4fb 615 int (*get_display_clock_speed)(struct drm_i915_private *dev_priv);
ef0f5e93 616 int (*get_fifo_size)(struct drm_i915_private *dev_priv, int plane);
e3bddded 617 int (*compute_pipe_wm)(struct intel_crtc_state *cstate);
ed4a6a7c
MR
618 int (*compute_intermediate_wm)(struct drm_device *dev,
619 struct intel_crtc *intel_crtc,
620 struct intel_crtc_state *newstate);
ccf010fb
ML
621 void (*initial_watermarks)(struct intel_atomic_state *state,
622 struct intel_crtc_state *cstate);
623 void (*atomic_update_watermarks)(struct intel_atomic_state *state,
624 struct intel_crtc_state *cstate);
625 void (*optimize_watermarks)(struct intel_atomic_state *state,
626 struct intel_crtc_state *cstate);
98d39494 627 int (*compute_global_watermarks)(struct drm_atomic_state *state);
432081bc 628 void (*update_wm)(struct intel_crtc *crtc);
27c329ed
ML
629 int (*modeset_calc_cdclk)(struct drm_atomic_state *state);
630 void (*modeset_commit_cdclk)(struct drm_atomic_state *state);
0e8ffe1b
DV
631 /* Returns the active state of the crtc, and if the crtc is active,
632 * fills out the pipe-config with the hw state. */
633 bool (*get_pipe_config)(struct intel_crtc *,
5cec258b 634 struct intel_crtc_state *);
5724dbd1
DL
635 void (*get_initial_plane_config)(struct intel_crtc *,
636 struct intel_initial_plane_config *);
190f68c5
ACO
637 int (*crtc_compute_clock)(struct intel_crtc *crtc,
638 struct intel_crtc_state *crtc_state);
4a806558
ML
639 void (*crtc_enable)(struct intel_crtc_state *pipe_config,
640 struct drm_atomic_state *old_state);
641 void (*crtc_disable)(struct intel_crtc_state *old_crtc_state,
642 struct drm_atomic_state *old_state);
896e5bb0
L
643 void (*update_crtcs)(struct drm_atomic_state *state,
644 unsigned int *crtc_vblank_mask);
69bfe1a9
JN
645 void (*audio_codec_enable)(struct drm_connector *connector,
646 struct intel_encoder *encoder,
5e7234c9 647 const struct drm_display_mode *adjusted_mode);
69bfe1a9 648 void (*audio_codec_disable)(struct intel_encoder *encoder);
674cf967 649 void (*fdi_link_train)(struct drm_crtc *crtc);
46f16e63 650 void (*init_clock_gating)(struct drm_i915_private *dev_priv);
5a21b665
DV
651 int (*queue_flip)(struct drm_device *dev, struct drm_crtc *crtc,
652 struct drm_framebuffer *fb,
653 struct drm_i915_gem_object *obj,
654 struct drm_i915_gem_request *req,
655 uint32_t flags);
91d14251 656 void (*hpd_irq_setup)(struct drm_i915_private *dev_priv);
e70236a8
JB
657 /* clock updates for mode set */
658 /* cursor updates */
659 /* render clock increase/decrease */
660 /* display clock increase/decrease */
661 /* pll clock increase/decrease */
8563b1e8 662
b95c5321
ML
663 void (*load_csc_matrix)(struct drm_crtc_state *crtc_state);
664 void (*load_luts)(struct drm_crtc_state *crtc_state);
e70236a8
JB
665};
666
48c1026a
MK
667enum forcewake_domain_id {
668 FW_DOMAIN_ID_RENDER = 0,
669 FW_DOMAIN_ID_BLITTER,
670 FW_DOMAIN_ID_MEDIA,
671
672 FW_DOMAIN_ID_COUNT
673};
674
675enum forcewake_domains {
676 FORCEWAKE_RENDER = (1 << FW_DOMAIN_ID_RENDER),
677 FORCEWAKE_BLITTER = (1 << FW_DOMAIN_ID_BLITTER),
678 FORCEWAKE_MEDIA = (1 << FW_DOMAIN_ID_MEDIA),
679 FORCEWAKE_ALL = (FORCEWAKE_RENDER |
680 FORCEWAKE_BLITTER |
681 FORCEWAKE_MEDIA)
682};
683
3756685a
TU
684#define FW_REG_READ (1)
685#define FW_REG_WRITE (2)
686
85ee17eb
PP
687enum decoupled_power_domain {
688 GEN9_DECOUPLED_PD_BLITTER = 0,
689 GEN9_DECOUPLED_PD_RENDER,
690 GEN9_DECOUPLED_PD_MEDIA,
691 GEN9_DECOUPLED_PD_ALL
692};
693
694enum decoupled_ops {
695 GEN9_DECOUPLED_OP_WRITE = 0,
696 GEN9_DECOUPLED_OP_READ
697};
698
3756685a
TU
699enum forcewake_domains
700intel_uncore_forcewake_for_reg(struct drm_i915_private *dev_priv,
701 i915_reg_t reg, unsigned int op);
702
907b28c5 703struct intel_uncore_funcs {
c8d9a590 704 void (*force_wake_get)(struct drm_i915_private *dev_priv,
48c1026a 705 enum forcewake_domains domains);
c8d9a590 706 void (*force_wake_put)(struct drm_i915_private *dev_priv,
48c1026a 707 enum forcewake_domains domains);
0b274481 708
f0f59a00
VS
709 uint8_t (*mmio_readb)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
710 uint16_t (*mmio_readw)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
711 uint32_t (*mmio_readl)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
712 uint64_t (*mmio_readq)(struct drm_i915_private *dev_priv, i915_reg_t r, bool trace);
0b274481 713
f0f59a00 714 void (*mmio_writeb)(struct drm_i915_private *dev_priv, i915_reg_t r,
0b274481 715 uint8_t val, bool trace);
f0f59a00 716 void (*mmio_writew)(struct drm_i915_private *dev_priv, i915_reg_t r,
0b274481 717 uint16_t val, bool trace);
f0f59a00 718 void (*mmio_writel)(struct drm_i915_private *dev_priv, i915_reg_t r,
0b274481 719 uint32_t val, bool trace);
990bbdad
CW
720};
721
15157970
TU
722struct intel_forcewake_range {
723 u32 start;
724 u32 end;
725
726 enum forcewake_domains domains;
727};
728
907b28c5
CW
729struct intel_uncore {
730 spinlock_t lock; /** lock is also taken in irq contexts. */
731
15157970
TU
732 const struct intel_forcewake_range *fw_domains_table;
733 unsigned int fw_domains_table_entries;
734
907b28c5
CW
735 struct intel_uncore_funcs funcs;
736
737 unsigned fifo_count;
003342a5 738
48c1026a 739 enum forcewake_domains fw_domains;
003342a5 740 enum forcewake_domains fw_domains_active;
b2cff0db
CW
741
742 struct intel_uncore_forcewake_domain {
743 struct drm_i915_private *i915;
48c1026a 744 enum forcewake_domain_id id;
33c582c1 745 enum forcewake_domains mask;
b2cff0db 746 unsigned wake_count;
a57a4a67 747 struct hrtimer timer;
f0f59a00 748 i915_reg_t reg_set;
05a2fb15
MK
749 u32 val_set;
750 u32 val_clear;
f0f59a00
VS
751 i915_reg_t reg_ack;
752 i915_reg_t reg_post;
05a2fb15 753 u32 val_reset;
b2cff0db 754 } fw_domain[FW_DOMAIN_ID_COUNT];
75714940
MK
755
756 int unclaimed_mmio_check;
b2cff0db
CW
757};
758
759/* Iterate over initialised fw domains */
33c582c1
TU
760#define for_each_fw_domain_masked(domain__, mask__, dev_priv__) \
761 for ((domain__) = &(dev_priv__)->uncore.fw_domain[0]; \
762 (domain__) < &(dev_priv__)->uncore.fw_domain[FW_DOMAIN_ID_COUNT]; \
763 (domain__)++) \
764 for_each_if ((mask__) & (domain__)->mask)
765
766#define for_each_fw_domain(domain__, dev_priv__) \
767 for_each_fw_domain_masked(domain__, FORCEWAKE_ALL, dev_priv__)
907b28c5 768
b6e7d894
DL
769#define CSR_VERSION(major, minor) ((major) << 16 | (minor))
770#define CSR_VERSION_MAJOR(version) ((version) >> 16)
771#define CSR_VERSION_MINOR(version) ((version) & 0xffff)
772
eb805623 773struct intel_csr {
8144ac59 774 struct work_struct work;
eb805623 775 const char *fw_path;
a7f749f9 776 uint32_t *dmc_payload;
eb805623 777 uint32_t dmc_fw_size;
b6e7d894 778 uint32_t version;
eb805623 779 uint32_t mmio_count;
f0f59a00 780 i915_reg_t mmioaddr[8];
eb805623 781 uint32_t mmiodata[8];
832dba88 782 uint32_t dc_state;
a37baf3b 783 uint32_t allowed_dc_mask;
eb805623
DV
784};
785
604db650
JL
786#define DEV_INFO_FOR_EACH_FLAG(func) \
787 func(is_mobile); \
3e4274f8 788 func(is_lp); \
c007fb4a 789 func(is_alpha_support); \
566c56a4 790 /* Keep has_* in alphabetical order */ \
dfc5148f 791 func(has_64bit_reloc); \
9e1d0e60 792 func(has_aliasing_ppgtt); \
604db650 793 func(has_csr); \
566c56a4 794 func(has_ddi); \
70821af6 795 func(has_decoupled_mmio); \
604db650 796 func(has_dp_mst); \
566c56a4
JL
797 func(has_fbc); \
798 func(has_fpga_dbg); \
9e1d0e60
MT
799 func(has_full_ppgtt); \
800 func(has_full_48bit_ppgtt); \
604db650 801 func(has_gmbus_irq); \
604db650
JL
802 func(has_gmch_display); \
803 func(has_guc); \
604db650 804 func(has_hotplug); \
566c56a4
JL
805 func(has_hw_contexts); \
806 func(has_l3_dpf); \
604db650 807 func(has_llc); \
566c56a4
JL
808 func(has_logical_ring_contexts); \
809 func(has_overlay); \
810 func(has_pipe_cxsr); \
811 func(has_pooled_eu); \
812 func(has_psr); \
813 func(has_rc6); \
814 func(has_rc6p); \
815 func(has_resource_streamer); \
816 func(has_runtime_pm); \
604db650 817 func(has_snoop); \
566c56a4
JL
818 func(cursor_needs_physical); \
819 func(hws_needs_physical); \
820 func(overlay_needs_physical); \
70821af6 821 func(supports_tv);
c96ea64e 822
915490d5 823struct sseu_dev_info {
f08a0c92 824 u8 slice_mask;
57ec171e 825 u8 subslice_mask;
915490d5
ID
826 u8 eu_total;
827 u8 eu_per_subslice;
43b67998
ID
828 u8 min_eu_in_pool;
829 /* For each slice, which subslice(s) has(have) 7 EUs (bitfield)? */
830 u8 subslice_7eu[3];
831 u8 has_slice_pg:1;
832 u8 has_subslice_pg:1;
833 u8 has_eu_pg:1;
915490d5
ID
834};
835
57ec171e
ID
836static inline unsigned int sseu_subslice_total(const struct sseu_dev_info *sseu)
837{
838 return hweight8(sseu->slice_mask) * hweight8(sseu->subslice_mask);
839}
840
2e0d26f8
JN
841/* Keep in gen based order, and chronological order within a gen */
842enum intel_platform {
843 INTEL_PLATFORM_UNINITIALIZED = 0,
844 INTEL_I830,
845 INTEL_I845G,
846 INTEL_I85X,
847 INTEL_I865G,
848 INTEL_I915G,
849 INTEL_I915GM,
850 INTEL_I945G,
851 INTEL_I945GM,
852 INTEL_G33,
853 INTEL_PINEVIEW,
c0f86832
JN
854 INTEL_I965G,
855 INTEL_I965GM,
f69c11ae
JN
856 INTEL_G45,
857 INTEL_GM45,
2e0d26f8
JN
858 INTEL_IRONLAKE,
859 INTEL_SANDYBRIDGE,
860 INTEL_IVYBRIDGE,
861 INTEL_VALLEYVIEW,
862 INTEL_HASWELL,
863 INTEL_BROADWELL,
864 INTEL_CHERRYVIEW,
865 INTEL_SKYLAKE,
866 INTEL_BROXTON,
867 INTEL_KABYLAKE,
868 INTEL_GEMINILAKE,
869};
870
cfdf1fa2 871struct intel_device_info {
10fce67a 872 u32 display_mmio_offset;
87f1f465 873 u16 device_id;
ac208a8b 874 u8 num_pipes;
d615a166 875 u8 num_sprites[I915_MAX_PIPES];
c96c3a8c 876 u8 gen;
ae5702d2 877 u16 gen_mask;
2e0d26f8 878 enum intel_platform platform;
73ae478c 879 u8 ring_mask; /* Rings supported by the HW */
c1bb1145 880 u8 num_rings;
604db650
JL
881#define DEFINE_FLAG(name) u8 name:1
882 DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG);
883#undef DEFINE_FLAG
6f3fff60 884 u16 ddb_size; /* in blocks */
a57c774a
AK
885 /* Register offsets for the various display pipes and transcoders */
886 int pipe_offsets[I915_MAX_TRANSCODERS];
887 int trans_offsets[I915_MAX_TRANSCODERS];
a57c774a 888 int palette_offsets[I915_MAX_PIPES];
5efb3e28 889 int cursor_offsets[I915_MAX_PIPES];
3873218f
JM
890
891 /* Slice/subslice/EU info */
43b67998 892 struct sseu_dev_info sseu;
82cf435b
LL
893
894 struct color_luts {
895 u16 degamma_lut_size;
896 u16 gamma_lut_size;
897 } color;
cfdf1fa2
KH
898};
899
2bd160a1
CW
900struct intel_display_error_state;
901
902struct drm_i915_error_state {
903 struct kref ref;
904 struct timeval time;
de867c20
CW
905 struct timeval boottime;
906 struct timeval uptime;
2bd160a1 907
9f267eb8
CW
908 struct drm_i915_private *i915;
909
2bd160a1
CW
910 char error_msg[128];
911 bool simulated;
912 int iommu;
913 u32 reset_count;
914 u32 suspend_count;
915 struct intel_device_info device_info;
916
917 /* Generic register state */
918 u32 eir;
919 u32 pgtbl_er;
920 u32 ier;
921 u32 gtier[4];
922 u32 ccid;
923 u32 derrmr;
924 u32 forcewake;
925 u32 error; /* gen6+ */
926 u32 err_int; /* gen7 */
927 u32 fault_data0; /* gen8, gen9 */
928 u32 fault_data1; /* gen8, gen9 */
929 u32 done_reg;
930 u32 gac_eco;
931 u32 gam_ecochk;
932 u32 gab_ctl;
933 u32 gfx_mode;
d636951e 934
2bd160a1
CW
935 u64 fence[I915_MAX_NUM_FENCES];
936 struct intel_overlay_error_state *overlay;
937 struct intel_display_error_state *display;
51d545d0 938 struct drm_i915_error_object *semaphore;
27b85bea 939 struct drm_i915_error_object *guc_log;
2bd160a1
CW
940
941 struct drm_i915_error_engine {
942 int engine_id;
943 /* Software tracked state */
944 bool waiting;
945 int num_waiters;
3fe3b030
MK
946 unsigned long hangcheck_timestamp;
947 bool hangcheck_stalled;
2bd160a1
CW
948 enum intel_engine_hangcheck_action hangcheck_action;
949 struct i915_address_space *vm;
950 int num_requests;
951
cdb324bd
CW
952 /* position of active request inside the ring */
953 u32 rq_head, rq_post, rq_tail;
954
2bd160a1
CW
955 /* our own tracking of ring head and tail */
956 u32 cpu_ring_head;
957 u32 cpu_ring_tail;
958
959 u32 last_seqno;
2bd160a1
CW
960
961 /* Register state */
962 u32 start;
963 u32 tail;
964 u32 head;
965 u32 ctl;
21a2c58a 966 u32 mode;
2bd160a1
CW
967 u32 hws;
968 u32 ipeir;
969 u32 ipehr;
2bd160a1
CW
970 u32 bbstate;
971 u32 instpm;
972 u32 instps;
973 u32 seqno;
974 u64 bbaddr;
975 u64 acthd;
976 u32 fault_reg;
977 u64 faddr;
978 u32 rc_psmi; /* sleep state */
979 u32 semaphore_mboxes[I915_NUM_ENGINES - 1];
d636951e 980 struct intel_instdone instdone;
2bd160a1
CW
981
982 struct drm_i915_error_object {
2bd160a1 983 u64 gtt_offset;
03382dfb 984 u64 gtt_size;
0a97015d
CW
985 int page_count;
986 int unused;
2bd160a1
CW
987 u32 *pages[0];
988 } *ringbuffer, *batchbuffer, *wa_batchbuffer, *ctx, *hws_page;
989
990 struct drm_i915_error_object *wa_ctx;
991
992 struct drm_i915_error_request {
993 long jiffies;
c84455b4 994 pid_t pid;
35ca039e 995 u32 context;
84102171 996 int ban_score;
2bd160a1
CW
997 u32 seqno;
998 u32 head;
999 u32 tail;
35ca039e 1000 } *requests, execlist[2];
2bd160a1
CW
1001
1002 struct drm_i915_error_waiter {
1003 char comm[TASK_COMM_LEN];
1004 pid_t pid;
1005 u32 seqno;
1006 } *waiters;
1007
1008 struct {
1009 u32 gfx_mode;
1010 union {
1011 u64 pdp[4];
1012 u32 pp_dir_base;
1013 };
1014 } vm_info;
1015
1016 pid_t pid;
1017 char comm[TASK_COMM_LEN];
b083a087 1018 int context_bans;
2bd160a1
CW
1019 } engine[I915_NUM_ENGINES];
1020
1021 struct drm_i915_error_buffer {
1022 u32 size;
1023 u32 name;
1024 u32 rseqno[I915_NUM_ENGINES], wseqno;
1025 u64 gtt_offset;
1026 u32 read_domains;
1027 u32 write_domain;
1028 s32 fence_reg:I915_MAX_NUM_FENCE_BITS;
1029 u32 tiling:2;
1030 u32 dirty:1;
1031 u32 purgeable:1;
1032 u32 userptr:1;
1033 s32 engine:4;
1034 u32 cache_level:3;
1035 } *active_bo[I915_NUM_ENGINES], *pinned_bo;
1036 u32 active_bo_count[I915_NUM_ENGINES], pinned_bo_count;
1037 struct i915_address_space *active_vm[I915_NUM_ENGINES];
1038};
1039
7faf1ab2
DV
1040enum i915_cache_level {
1041 I915_CACHE_NONE = 0,
350ec881
CW
1042 I915_CACHE_LLC, /* also used for snoopable memory on non-LLC */
1043 I915_CACHE_L3_LLC, /* gen7+, L3 sits between the domain specifc
1044 caches, eg sampler/render caches, and the
1045 large Last-Level-Cache. LLC is coherent with
1046 the CPU, but L3 is only visible to the GPU. */
651d794f 1047 I915_CACHE_WT, /* hsw:gt3e WriteThrough for scanouts */
7faf1ab2
DV
1048};
1049
85fd4f58
CW
1050#define I915_COLOR_UNEVICTABLE (-1) /* a non-vma sharing the address space */
1051
a4001f1b
PZ
1052enum fb_op_origin {
1053 ORIGIN_GTT,
1054 ORIGIN_CPU,
1055 ORIGIN_CS,
1056 ORIGIN_FLIP,
74b4ea1e 1057 ORIGIN_DIRTYFB,
a4001f1b
PZ
1058};
1059
ab34a7e8 1060struct intel_fbc {
25ad93fd
PZ
1061 /* This is always the inner lock when overlapping with struct_mutex and
1062 * it's the outer lock when overlapping with stolen_lock. */
1063 struct mutex lock;
5e59f717 1064 unsigned threshold;
dbef0f15
PZ
1065 unsigned int possible_framebuffer_bits;
1066 unsigned int busy_bits;
010cf73d 1067 unsigned int visible_pipes_mask;
e35fef21 1068 struct intel_crtc *crtc;
5c3fe8b0 1069
c4213885 1070 struct drm_mm_node compressed_fb;
5c3fe8b0
BW
1071 struct drm_mm_node *compressed_llb;
1072
da46f936
RV
1073 bool false_color;
1074
d029bcad 1075 bool enabled;
0e631adc 1076 bool active;
9adccc60 1077
61a585d6
PZ
1078 bool underrun_detected;
1079 struct work_struct underrun_work;
1080
aaf78d27
PZ
1081 struct intel_fbc_state_cache {
1082 struct {
1083 unsigned int mode_flags;
1084 uint32_t hsw_bdw_pixel_rate;
1085 } crtc;
1086
1087 struct {
1088 unsigned int rotation;
1089 int src_w;
1090 int src_h;
1091 bool visible;
1092 } plane;
1093
1094 struct {
1095 u64 ilk_ggtt_offset;
aaf78d27
PZ
1096 uint32_t pixel_format;
1097 unsigned int stride;
1098 int fence_reg;
1099 unsigned int tiling_mode;
1100 } fb;
1101 } state_cache;
1102
b183b3f1
PZ
1103 struct intel_fbc_reg_params {
1104 struct {
1105 enum pipe pipe;
1106 enum plane plane;
1107 unsigned int fence_y_offset;
1108 } crtc;
1109
1110 struct {
1111 u64 ggtt_offset;
b183b3f1
PZ
1112 uint32_t pixel_format;
1113 unsigned int stride;
1114 int fence_reg;
1115 } fb;
1116
1117 int cfb_size;
1118 } params;
1119
5c3fe8b0 1120 struct intel_fbc_work {
128d7356 1121 bool scheduled;
ca18d51d 1122 u32 scheduled_vblank;
128d7356 1123 struct work_struct work;
128d7356 1124 } work;
5c3fe8b0 1125
bf6189c6 1126 const char *no_fbc_reason;
b5e50c3f
JB
1127};
1128
96178eeb
VK
1129/**
1130 * HIGH_RR is the highest eDP panel refresh rate read from EDID
1131 * LOW_RR is the lowest eDP panel refresh rate found from EDID
1132 * parsing for same resolution.
1133 */
1134enum drrs_refresh_rate_type {
1135 DRRS_HIGH_RR,
1136 DRRS_LOW_RR,
1137 DRRS_MAX_RR, /* RR count */
1138};
1139
1140enum drrs_support_type {
1141 DRRS_NOT_SUPPORTED = 0,
1142 STATIC_DRRS_SUPPORT = 1,
1143 SEAMLESS_DRRS_SUPPORT = 2
439d7ac0
PB
1144};
1145
2807cf69 1146struct intel_dp;
96178eeb
VK
1147struct i915_drrs {
1148 struct mutex mutex;
1149 struct delayed_work work;
1150 struct intel_dp *dp;
1151 unsigned busy_frontbuffer_bits;
1152 enum drrs_refresh_rate_type refresh_rate_type;
1153 enum drrs_support_type type;
1154};
1155
a031d709 1156struct i915_psr {
f0355c4a 1157 struct mutex lock;
a031d709
RV
1158 bool sink_support;
1159 bool source_ok;
2807cf69 1160 struct intel_dp *enabled;
7c8f8a70
RV
1161 bool active;
1162 struct delayed_work work;
9ca15301 1163 unsigned busy_frontbuffer_bits;
474d1ec4
SJ
1164 bool psr2_support;
1165 bool aux_frame_sync;
60e5ffe3 1166 bool link_standby;
3f51e471 1167};
5c3fe8b0 1168
3bad0781 1169enum intel_pch {
f0350830 1170 PCH_NONE = 0, /* No PCH present */
3bad0781
ZW
1171 PCH_IBX, /* Ibexpeak PCH */
1172 PCH_CPT, /* Cougarpoint PCH */
eb877ebf 1173 PCH_LPT, /* Lynxpoint PCH */
e7e7ea20 1174 PCH_SPT, /* Sunrisepoint PCH */
22dea0be 1175 PCH_KBP, /* Kabypoint PCH */
40c7ead9 1176 PCH_NOP,
3bad0781
ZW
1177};
1178
988d6ee8
PZ
1179enum intel_sbi_destination {
1180 SBI_ICLK,
1181 SBI_MPHY,
1182};
1183
b690e96c 1184#define QUIRK_PIPEA_FORCE (1<<0)
435793df 1185#define QUIRK_LVDS_SSC_DISABLE (1<<1)
4dca20ef 1186#define QUIRK_INVERT_BRIGHTNESS (1<<2)
9c72cc6f 1187#define QUIRK_BACKLIGHT_PRESENT (1<<3)
b6b5d049 1188#define QUIRK_PIPEB_FORCE (1<<4)
656bfa3a 1189#define QUIRK_PIN_SWIZZLED_PAGES (1<<5)
b690e96c 1190
8be48d92 1191struct intel_fbdev;
1630fe75 1192struct intel_fbc_work;
38651674 1193
c2b9152f
DV
1194struct intel_gmbus {
1195 struct i2c_adapter adapter;
3e4d44e0 1196#define GMBUS_FORCE_BIT_RETRY (1U << 31)
f2ce9faf 1197 u32 force_bit;
c2b9152f 1198 u32 reg0;
f0f59a00 1199 i915_reg_t gpio_reg;
c167a6fc 1200 struct i2c_algo_bit_data bit_algo;
c2b9152f
DV
1201 struct drm_i915_private *dev_priv;
1202};
1203
f4c956ad 1204struct i915_suspend_saved_registers {
e948e994 1205 u32 saveDSPARB;
ba8bbcf6 1206 u32 saveFBC_CONTROL;
1f84e550 1207 u32 saveCACHE_MODE_0;
1f84e550 1208 u32 saveMI_ARB_STATE;
ba8bbcf6
JB
1209 u32 saveSWF0[16];
1210 u32 saveSWF1[16];
85fa792b 1211 u32 saveSWF3[3];
4b9de737 1212 uint64_t saveFENCE[I915_MAX_NUM_FENCES];
cda2bb78 1213 u32 savePCH_PORT_HOTPLUG;
9f49c376 1214 u16 saveGCDGMBUS;
f4c956ad 1215};
c85aa885 1216
ddeea5b0
ID
1217struct vlv_s0ix_state {
1218 /* GAM */
1219 u32 wr_watermark;
1220 u32 gfx_prio_ctrl;
1221 u32 arb_mode;
1222 u32 gfx_pend_tlb0;
1223 u32 gfx_pend_tlb1;
1224 u32 lra_limits[GEN7_LRA_LIMITS_REG_NUM];
1225 u32 media_max_req_count;
1226 u32 gfx_max_req_count;
1227 u32 render_hwsp;
1228 u32 ecochk;
1229 u32 bsd_hwsp;
1230 u32 blt_hwsp;
1231 u32 tlb_rd_addr;
1232
1233 /* MBC */
1234 u32 g3dctl;
1235 u32 gsckgctl;
1236 u32 mbctl;
1237
1238 /* GCP */
1239 u32 ucgctl1;
1240 u32 ucgctl3;
1241 u32 rcgctl1;
1242 u32 rcgctl2;
1243 u32 rstctl;
1244 u32 misccpctl;
1245
1246 /* GPM */
1247 u32 gfxpause;
1248 u32 rpdeuhwtc;
1249 u32 rpdeuc;
1250 u32 ecobus;
1251 u32 pwrdwnupctl;
1252 u32 rp_down_timeout;
1253 u32 rp_deucsw;
1254 u32 rcubmabdtmr;
1255 u32 rcedata;
1256 u32 spare2gh;
1257
1258 /* Display 1 CZ domain */
1259 u32 gt_imr;
1260 u32 gt_ier;
1261 u32 pm_imr;
1262 u32 pm_ier;
1263 u32 gt_scratch[GEN7_GT_SCRATCH_REG_NUM];
1264
1265 /* GT SA CZ domain */
1266 u32 tilectl;
1267 u32 gt_fifoctl;
1268 u32 gtlc_wake_ctrl;
1269 u32 gtlc_survive;
1270 u32 pmwgicz;
1271
1272 /* Display 2 CZ domain */
1273 u32 gu_ctl0;
1274 u32 gu_ctl1;
9c25210f 1275 u32 pcbr;
ddeea5b0
ID
1276 u32 clock_gate_dis2;
1277};
1278
bf225f20
CW
1279struct intel_rps_ei {
1280 u32 cz_clock;
1281 u32 render_c0;
1282 u32 media_c0;
31685c25
D
1283};
1284
c85aa885 1285struct intel_gen6_power_mgmt {
d4d70aa5
ID
1286 /*
1287 * work, interrupts_enabled and pm_iir are protected by
1288 * dev_priv->irq_lock
1289 */
c85aa885 1290 struct work_struct work;
d4d70aa5 1291 bool interrupts_enabled;
c85aa885 1292 u32 pm_iir;
59cdb63d 1293
b20e3cfe 1294 /* PM interrupt bits that should never be masked */
1800ad25
SAK
1295 u32 pm_intr_keep;
1296
b39fb297
BW
1297 /* Frequencies are stored in potentially platform dependent multiples.
1298 * In other words, *_freq needs to be multiplied by X to be interesting.
1299 * Soft limits are those which are used for the dynamic reclocking done
1300 * by the driver (raise frequencies under heavy loads, and lower for
1301 * lighter loads). Hard limits are those imposed by the hardware.
1302 *
1303 * A distinction is made for overclocking, which is never enabled by
1304 * default, and is considered to be above the hard limit if it's
1305 * possible at all.
1306 */
1307 u8 cur_freq; /* Current frequency (cached, may not == HW) */
1308 u8 min_freq_softlimit; /* Minimum frequency permitted by the driver */
1309 u8 max_freq_softlimit; /* Max frequency permitted by the driver */
1310 u8 max_freq; /* Maximum frequency, RP0 if not overclocking */
1311 u8 min_freq; /* AKA RPn. Minimum frequency */
29ecd78d 1312 u8 boost_freq; /* Frequency to request when wait boosting */
aed242ff 1313 u8 idle_freq; /* Frequency to request when we are idle */
b39fb297
BW
1314 u8 efficient_freq; /* AKA RPe. Pre-determined balanced frequency */
1315 u8 rp1_freq; /* "less than" RP0 power/freqency */
1316 u8 rp0_freq; /* Non-overclocked max frequency. */
c30fec65 1317 u16 gpll_ref_freq; /* vlv/chv GPLL reference frequency */
1a01ab3b 1318
8fb55197
CW
1319 u8 up_threshold; /* Current %busy required to uplock */
1320 u8 down_threshold; /* Current %busy required to downclock */
1321
dd75fdc8
CW
1322 int last_adj;
1323 enum { LOW_POWER, BETWEEN, HIGH_POWER } power;
1324
8d3afd7d
CW
1325 spinlock_t client_lock;
1326 struct list_head clients;
1327 bool client_boost;
1328
c0951f0c 1329 bool enabled;
54b4f68f 1330 struct delayed_work autoenable_work;
1854d5ca 1331 unsigned boosts;
4fc688ce 1332
bf225f20
CW
1333 /* manual wa residency calculations */
1334 struct intel_rps_ei up_ei, down_ei;
1335
4fc688ce
JB
1336 /*
1337 * Protects RPS/RC6 register access and PCU communication.
8d3afd7d
CW
1338 * Must be taken after struct_mutex if nested. Note that
1339 * this lock may be held for long periods of time when
1340 * talking to hw - so only take it when talking to hw!
4fc688ce
JB
1341 */
1342 struct mutex hw_lock;
c85aa885
DV
1343};
1344
1a240d4d
DV
1345/* defined intel_pm.c */
1346extern spinlock_t mchdev_lock;
1347
c85aa885
DV
1348struct intel_ilk_power_mgmt {
1349 u8 cur_delay;
1350 u8 min_delay;
1351 u8 max_delay;
1352 u8 fmax;
1353 u8 fstart;
1354
1355 u64 last_count1;
1356 unsigned long last_time1;
1357 unsigned long chipset_power;
1358 u64 last_count2;
5ed0bdf2 1359 u64 last_time2;
c85aa885
DV
1360 unsigned long gfx_power;
1361 u8 corr;
1362
1363 int c_m;
1364 int r_t;
1365};
1366
c6cb582e
ID
1367struct drm_i915_private;
1368struct i915_power_well;
1369
1370struct i915_power_well_ops {
1371 /*
1372 * Synchronize the well's hw state to match the current sw state, for
1373 * example enable/disable it based on the current refcount. Called
1374 * during driver init and resume time, possibly after first calling
1375 * the enable/disable handlers.
1376 */
1377 void (*sync_hw)(struct drm_i915_private *dev_priv,
1378 struct i915_power_well *power_well);
1379 /*
1380 * Enable the well and resources that depend on it (for example
1381 * interrupts located on the well). Called after the 0->1 refcount
1382 * transition.
1383 */
1384 void (*enable)(struct drm_i915_private *dev_priv,
1385 struct i915_power_well *power_well);
1386 /*
1387 * Disable the well and resources that depend on it. Called after
1388 * the 1->0 refcount transition.
1389 */
1390 void (*disable)(struct drm_i915_private *dev_priv,
1391 struct i915_power_well *power_well);
1392 /* Returns the hw enabled state. */
1393 bool (*is_enabled)(struct drm_i915_private *dev_priv,
1394 struct i915_power_well *power_well);
1395};
1396
a38911a3
WX
1397/* Power well structure for haswell */
1398struct i915_power_well {
c1ca727f 1399 const char *name;
6f3ef5dd 1400 bool always_on;
a38911a3
WX
1401 /* power well enable/disable usage count */
1402 int count;
bfafe93a
ID
1403 /* cached hw enabled state */
1404 bool hw_enabled;
c1ca727f 1405 unsigned long domains;
01c3faa7
ACO
1406 /* unique identifier for this power well */
1407 unsigned long id;
362624c9
ACO
1408 /*
1409 * Arbitraty data associated with this power well. Platform and power
1410 * well specific.
1411 */
1412 unsigned long data;
c6cb582e 1413 const struct i915_power_well_ops *ops;
a38911a3
WX
1414};
1415
83c00f55 1416struct i915_power_domains {
baa70707
ID
1417 /*
1418 * Power wells needed for initialization at driver init and suspend
1419 * time are on. They are kept on until after the first modeset.
1420 */
1421 bool init_power_on;
0d116a29 1422 bool initializing;
c1ca727f 1423 int power_well_count;
baa70707 1424
83c00f55 1425 struct mutex lock;
1da51581 1426 int domain_use_count[POWER_DOMAIN_NUM];
c1ca727f 1427 struct i915_power_well *power_wells;
83c00f55
ID
1428};
1429
35a85ac6 1430#define MAX_L3_SLICES 2
a4da4fa4 1431struct intel_l3_parity {
35a85ac6 1432 u32 *remap_info[MAX_L3_SLICES];
a4da4fa4 1433 struct work_struct error_work;
35a85ac6 1434 int which_slice;
a4da4fa4
DV
1435};
1436
4b5aed62 1437struct i915_gem_mm {
4b5aed62
DV
1438 /** Memory allocator for GTT stolen memory */
1439 struct drm_mm stolen;
92e97d2f
PZ
1440 /** Protects the usage of the GTT stolen memory allocator. This is
1441 * always the inner lock when overlapping with struct_mutex. */
1442 struct mutex stolen_lock;
1443
4b5aed62
DV
1444 /** List of all objects in gtt_space. Used to restore gtt
1445 * mappings on resume */
1446 struct list_head bound_list;
1447 /**
1448 * List of objects which are not bound to the GTT (thus
fbbd37b3
CW
1449 * are idle and not used by the GPU). These objects may or may
1450 * not actually have any pages attached.
4b5aed62
DV
1451 */
1452 struct list_head unbound_list;
1453
275f039d
CW
1454 /** List of all objects in gtt_space, currently mmaped by userspace.
1455 * All objects within this list must also be on bound_list.
1456 */
1457 struct list_head userfault_list;
1458
fbbd37b3
CW
1459 /**
1460 * List of objects which are pending destruction.
1461 */
1462 struct llist_head free_list;
1463 struct work_struct free_work;
1464
4b5aed62
DV
1465 /** Usable portion of the GTT for GEM */
1466 unsigned long stolen_base; /* limited to low memory (32-bit) */
1467
4b5aed62
DV
1468 /** PPGTT used for aliasing the PPGTT with the GTT */
1469 struct i915_hw_ppgtt *aliasing_ppgtt;
1470
2cfcd32a 1471 struct notifier_block oom_notifier;
e87666b5 1472 struct notifier_block vmap_notifier;
ceabbba5 1473 struct shrinker shrinker;
4b5aed62 1474
4b5aed62
DV
1475 /** LRU list of objects with fence regs on them. */
1476 struct list_head fence_list;
1477
4b5aed62
DV
1478 /**
1479 * Are we in a non-interruptible section of code like
1480 * modesetting?
1481 */
1482 bool interruptible;
1483
bdf1e7e3 1484 /* the indicator for dispatch video commands on two BSD rings */
6f633402 1485 atomic_t bsd_engine_dispatch_index;
bdf1e7e3 1486
4b5aed62
DV
1487 /** Bit 6 swizzling required for X tiling */
1488 uint32_t bit_6_swizzle_x;
1489 /** Bit 6 swizzling required for Y tiling */
1490 uint32_t bit_6_swizzle_y;
1491
4b5aed62 1492 /* accounting, useful for userland debugging */
c20e8355 1493 spinlock_t object_stat_lock;
3ef7f228 1494 u64 object_memory;
4b5aed62
DV
1495 u32 object_count;
1496};
1497
edc3d884 1498struct drm_i915_error_state_buf {
0a4cd7c8 1499 struct drm_i915_private *i915;
edc3d884
MK
1500 unsigned bytes;
1501 unsigned size;
1502 int err;
1503 u8 *buf;
1504 loff_t start;
1505 loff_t pos;
1506};
1507
fc16b48b 1508struct i915_error_state_file_priv {
12ff05e7 1509 struct drm_i915_private *i915;
fc16b48b
MK
1510 struct drm_i915_error_state *error;
1511};
1512
b52992c0
CW
1513#define I915_RESET_TIMEOUT (10 * HZ) /* 10s */
1514#define I915_FENCE_TIMEOUT (10 * HZ) /* 10s */
1515
3fe3b030
MK
1516#define I915_ENGINE_DEAD_TIMEOUT (4 * HZ) /* Seqno, head and subunits dead */
1517#define I915_SEQNO_DEAD_TIMEOUT (12 * HZ) /* Seqno dead with active head */
1518
99584db3
DV
1519struct i915_gpu_error {
1520 /* For hangcheck timer */
1521#define DRM_I915_HANGCHECK_PERIOD 1500 /* in ms */
1522#define DRM_I915_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD)
be62acb4 1523
737b1506 1524 struct delayed_work hangcheck_work;
99584db3
DV
1525
1526 /* For reset and error_state handling. */
1527 spinlock_t lock;
1528 /* Protected by the above dev->gpu_error.lock. */
1529 struct drm_i915_error_state *first_error;
094f9a54
CW
1530
1531 unsigned long missed_irq_rings;
1532
1f83fee0 1533 /**
2ac0f450 1534 * State variable controlling the reset flow and count
1f83fee0 1535 *
2ac0f450 1536 * This is a counter which gets incremented when reset is triggered,
8af29b0c
CW
1537 *
1538 * Before the reset commences, the I915_RESET_IN_PROGRESS bit is set
1539 * meaning that any waiters holding onto the struct_mutex should
1540 * relinquish the lock immediately in order for the reset to start.
2ac0f450
MK
1541 *
1542 * If reset is not completed succesfully, the I915_WEDGE bit is
1543 * set meaning that hardware is terminally sour and there is no
1544 * recovery. All waiters on the reset_queue will be woken when
1545 * that happens.
1546 *
1547 * This counter is used by the wait_seqno code to notice that reset
1548 * event happened and it needs to restart the entire ioctl (since most
1549 * likely the seqno it waited for won't ever signal anytime soon).
f69061be
DV
1550 *
1551 * This is important for lock-free wait paths, where no contended lock
1552 * naturally enforces the correct ordering between the bail-out of the
1553 * waiter and the gpu reset work code.
1f83fee0 1554 */
8af29b0c 1555 unsigned long reset_count;
1f83fee0 1556
8af29b0c
CW
1557 unsigned long flags;
1558#define I915_RESET_IN_PROGRESS 0
1559#define I915_WEDGED (BITS_PER_LONG - 1)
1f83fee0 1560
1f15b76f
CW
1561 /**
1562 * Waitqueue to signal when a hang is detected. Used to for waiters
1563 * to release the struct_mutex for the reset to procede.
1564 */
1565 wait_queue_head_t wait_queue;
1566
1f83fee0
DV
1567 /**
1568 * Waitqueue to signal when the reset has completed. Used by clients
1569 * that wait for dev_priv->mm.wedged to settle.
1570 */
1571 wait_queue_head_t reset_queue;
33196ded 1572
094f9a54 1573 /* For missed irq/seqno simulation. */
688e6c72 1574 unsigned long test_irq_rings;
99584db3
DV
1575};
1576
b8efb17b
ZR
1577enum modeset_restore {
1578 MODESET_ON_LID_OPEN,
1579 MODESET_DONE,
1580 MODESET_SUSPENDED,
1581};
1582
500ea70d
RV
1583#define DP_AUX_A 0x40
1584#define DP_AUX_B 0x10
1585#define DP_AUX_C 0x20
1586#define DP_AUX_D 0x30
1587
11c1b657
XZ
1588#define DDC_PIN_B 0x05
1589#define DDC_PIN_C 0x04
1590#define DDC_PIN_D 0x06
1591
6acab15a 1592struct ddi_vbt_port_info {
ce4dd49e
DL
1593 /*
1594 * This is an index in the HDMI/DVI DDI buffer translation table.
1595 * The special value HDMI_LEVEL_SHIFT_UNKNOWN means the VBT didn't
1596 * populate this field.
1597 */
1598#define HDMI_LEVEL_SHIFT_UNKNOWN 0xff
6acab15a 1599 uint8_t hdmi_level_shift;
311a2094
PZ
1600
1601 uint8_t supports_dvi:1;
1602 uint8_t supports_hdmi:1;
1603 uint8_t supports_dp:1;
a98d9c1d 1604 uint8_t supports_edp:1;
500ea70d
RV
1605
1606 uint8_t alternate_aux_channel;
11c1b657 1607 uint8_t alternate_ddc_pin;
75067dde
AK
1608
1609 uint8_t dp_boost_level;
1610 uint8_t hdmi_boost_level;
6acab15a
PZ
1611};
1612
bfd7ebda
RV
1613enum psr_lines_to_wait {
1614 PSR_0_LINES_TO_WAIT = 0,
1615 PSR_1_LINE_TO_WAIT,
1616 PSR_4_LINES_TO_WAIT,
1617 PSR_8_LINES_TO_WAIT
83a7280e
PB
1618};
1619
41aa3448
RV
1620struct intel_vbt_data {
1621 struct drm_display_mode *lfp_lvds_vbt_mode; /* if any */
1622 struct drm_display_mode *sdvo_lvds_vbt_mode; /* if any */
1623
1624 /* Feature bits */
1625 unsigned int int_tv_support:1;
1626 unsigned int lvds_dither:1;
1627 unsigned int lvds_vbt:1;
1628 unsigned int int_crt_support:1;
1629 unsigned int lvds_use_ssc:1;
1630 unsigned int display_clock_mode:1;
1631 unsigned int fdi_rx_polarity_inverted:1;
3e845c7a 1632 unsigned int panel_type:4;
41aa3448
RV
1633 int lvds_ssc_freq;
1634 unsigned int bios_lvds_val; /* initial [PCH_]LVDS reg val in VBIOS */
1635
83a7280e
PB
1636 enum drrs_support_type drrs_type;
1637
6aa23e65
JN
1638 struct {
1639 int rate;
1640 int lanes;
1641 int preemphasis;
1642 int vswing;
06411f08 1643 bool low_vswing;
6aa23e65
JN
1644 bool initialized;
1645 bool support;
1646 int bpp;
1647 struct edp_power_seq pps;
1648 } edp;
41aa3448 1649
bfd7ebda
RV
1650 struct {
1651 bool full_link;
1652 bool require_aux_wakeup;
1653 int idle_frames;
1654 enum psr_lines_to_wait lines_to_wait;
1655 int tp1_wakeup_time;
1656 int tp2_tp3_wakeup_time;
1657 } psr;
1658
f00076d2
JN
1659 struct {
1660 u16 pwm_freq_hz;
39fbc9c8 1661 bool present;
f00076d2 1662 bool active_low_pwm;
1de6068e 1663 u8 min_brightness; /* min_brightness/255 of max */
add03379 1664 u8 controller; /* brightness controller number */
9a41e17d 1665 enum intel_backlight_type type;
f00076d2
JN
1666 } backlight;
1667
d17c5443
SK
1668 /* MIPI DSI */
1669 struct {
1670 u16 panel_id;
d3b542fc
SK
1671 struct mipi_config *config;
1672 struct mipi_pps_data *pps;
1673 u8 seq_version;
1674 u32 size;
1675 u8 *data;
8d3ed2f3 1676 const u8 *sequence[MIPI_SEQ_MAX];
d17c5443
SK
1677 } dsi;
1678
41aa3448
RV
1679 int crt_ddc_pin;
1680
1681 int child_dev_num;
768f69c9 1682 union child_device_config *child_dev;
6acab15a
PZ
1683
1684 struct ddi_vbt_port_info ddi_port_info[I915_MAX_PORTS];
9d6c875d 1685 struct sdvo_device_mapping sdvo_mappings[2];
41aa3448
RV
1686};
1687
77c122bc
VS
1688enum intel_ddb_partitioning {
1689 INTEL_DDB_PART_1_2,
1690 INTEL_DDB_PART_5_6, /* IVB+ */
1691};
1692
1fd527cc
VS
1693struct intel_wm_level {
1694 bool enable;
1695 uint32_t pri_val;
1696 uint32_t spr_val;
1697 uint32_t cur_val;
1698 uint32_t fbc_val;
1699};
1700
820c1980 1701struct ilk_wm_values {
609cedef
VS
1702 uint32_t wm_pipe[3];
1703 uint32_t wm_lp[3];
1704 uint32_t wm_lp_spr[3];
1705 uint32_t wm_linetime[3];
1706 bool enable_fbc_wm;
1707 enum intel_ddb_partitioning partitioning;
1708};
1709
262cd2e1 1710struct vlv_pipe_wm {
1b31389c 1711 uint16_t plane[I915_MAX_PLANES];
262cd2e1 1712};
ae80152d 1713
262cd2e1
VS
1714struct vlv_sr_wm {
1715 uint16_t plane;
1b31389c
VS
1716 uint16_t cursor;
1717};
1718
1719struct vlv_wm_ddl_values {
1720 uint8_t plane[I915_MAX_PLANES];
262cd2e1 1721};
ae80152d 1722
262cd2e1
VS
1723struct vlv_wm_values {
1724 struct vlv_pipe_wm pipe[3];
1725 struct vlv_sr_wm sr;
1b31389c 1726 struct vlv_wm_ddl_values ddl[3];
6eb1a681
VS
1727 uint8_t level;
1728 bool cxsr;
0018fda1
VS
1729};
1730
c193924e 1731struct skl_ddb_entry {
16160e3d 1732 uint16_t start, end; /* in number of blocks, 'end' is exclusive */
c193924e
DL
1733};
1734
1735static inline uint16_t skl_ddb_entry_size(const struct skl_ddb_entry *entry)
1736{
16160e3d 1737 return entry->end - entry->start;
c193924e
DL
1738}
1739
08db6652
DL
1740static inline bool skl_ddb_entry_equal(const struct skl_ddb_entry *e1,
1741 const struct skl_ddb_entry *e2)
1742{
1743 if (e1->start == e2->start && e1->end == e2->end)
1744 return true;
1745
1746 return false;
1747}
1748
c193924e 1749struct skl_ddb_allocation {
2cd601c6 1750 struct skl_ddb_entry plane[I915_MAX_PIPES][I915_MAX_PLANES]; /* packed/uv */
4969d33e 1751 struct skl_ddb_entry y_plane[I915_MAX_PIPES][I915_MAX_PLANES];
c193924e
DL
1752};
1753
2ac96d2a 1754struct skl_wm_values {
2b4b9f35 1755 unsigned dirty_pipes;
c193924e 1756 struct skl_ddb_allocation ddb;
2ac96d2a
PB
1757};
1758
1759struct skl_wm_level {
a62163e9
L
1760 bool plane_en;
1761 uint16_t plane_res_b;
1762 uint8_t plane_res_l;
2ac96d2a
PB
1763};
1764
c67a470b 1765/*
765dab67
PZ
1766 * This struct helps tracking the state needed for runtime PM, which puts the
1767 * device in PCI D3 state. Notice that when this happens, nothing on the
1768 * graphics device works, even register access, so we don't get interrupts nor
1769 * anything else.
c67a470b 1770 *
765dab67
PZ
1771 * Every piece of our code that needs to actually touch the hardware needs to
1772 * either call intel_runtime_pm_get or call intel_display_power_get with the
1773 * appropriate power domain.
a8a8bd54 1774 *
765dab67
PZ
1775 * Our driver uses the autosuspend delay feature, which means we'll only really
1776 * suspend if we stay with zero refcount for a certain amount of time. The
f458ebbc 1777 * default value is currently very conservative (see intel_runtime_pm_enable), but
765dab67 1778 * it can be changed with the standard runtime PM files from sysfs.
c67a470b
PZ
1779 *
1780 * The irqs_disabled variable becomes true exactly after we disable the IRQs and
1781 * goes back to false exactly before we reenable the IRQs. We use this variable
1782 * to check if someone is trying to enable/disable IRQs while they're supposed
1783 * to be disabled. This shouldn't happen and we'll print some error messages in
730488b2 1784 * case it happens.
c67a470b 1785 *
765dab67 1786 * For more, read the Documentation/power/runtime_pm.txt.
c67a470b 1787 */
5d584b2e 1788struct i915_runtime_pm {
1f814dac 1789 atomic_t wakeref_count;
5d584b2e 1790 bool suspended;
2aeb7d3a 1791 bool irqs_enabled;
c67a470b
PZ
1792};
1793
926321d5
DV
1794enum intel_pipe_crc_source {
1795 INTEL_PIPE_CRC_SOURCE_NONE,
1796 INTEL_PIPE_CRC_SOURCE_PLANE1,
1797 INTEL_PIPE_CRC_SOURCE_PLANE2,
1798 INTEL_PIPE_CRC_SOURCE_PF,
5b3a856b 1799 INTEL_PIPE_CRC_SOURCE_PIPE,
3d099a05
DV
1800 /* TV/DP on pre-gen5/vlv can't use the pipe source. */
1801 INTEL_PIPE_CRC_SOURCE_TV,
1802 INTEL_PIPE_CRC_SOURCE_DP_B,
1803 INTEL_PIPE_CRC_SOURCE_DP_C,
1804 INTEL_PIPE_CRC_SOURCE_DP_D,
46a19188 1805 INTEL_PIPE_CRC_SOURCE_AUTO,
926321d5
DV
1806 INTEL_PIPE_CRC_SOURCE_MAX,
1807};
1808
8bf1e9f1 1809struct intel_pipe_crc_entry {
ac2300d4 1810 uint32_t frame;
8bf1e9f1
SH
1811 uint32_t crc[5];
1812};
1813
b2c88f5b 1814#define INTEL_PIPE_CRC_ENTRIES_NR 128
8bf1e9f1 1815struct intel_pipe_crc {
d538bbdf
DL
1816 spinlock_t lock;
1817 bool opened; /* exclusive access to the result file */
e5f75aca 1818 struct intel_pipe_crc_entry *entries;
926321d5 1819 enum intel_pipe_crc_source source;
d538bbdf 1820 int head, tail;
07144428 1821 wait_queue_head_t wq;
8bf1e9f1
SH
1822};
1823
f99d7069 1824struct i915_frontbuffer_tracking {
b5add959 1825 spinlock_t lock;
f99d7069
DV
1826
1827 /*
1828 * Tracking bits for delayed frontbuffer flushing du to gpu activity or
1829 * scheduled flips.
1830 */
1831 unsigned busy_bits;
1832 unsigned flip_bits;
1833};
1834
7225342a 1835struct i915_wa_reg {
f0f59a00 1836 i915_reg_t addr;
7225342a
MK
1837 u32 value;
1838 /* bitmask representing WA bits */
1839 u32 mask;
1840};
1841
33136b06
AS
1842/*
1843 * RING_MAX_NONPRIV_SLOTS is per-engine but at this point we are only
1844 * allowing it for RCS as we don't foresee any requirement of having
1845 * a whitelist for other engines. When it is really required for
1846 * other engines then the limit need to be increased.
1847 */
1848#define I915_MAX_WA_REGS (16 + RING_MAX_NONPRIV_SLOTS)
7225342a
MK
1849
1850struct i915_workarounds {
1851 struct i915_wa_reg reg[I915_MAX_WA_REGS];
1852 u32 count;
666796da 1853 u32 hw_whitelist_count[I915_NUM_ENGINES];
7225342a
MK
1854};
1855
cf9d2890
YZ
1856struct i915_virtual_gpu {
1857 bool active;
1858};
1859
aa363136
MR
1860/* used in computing the new watermarks state */
1861struct intel_wm_config {
1862 unsigned int num_pipes_active;
1863 bool sprites_enabled;
1864 bool sprites_scaled;
1865};
1866
d7965152
RB
1867struct i915_oa_format {
1868 u32 format;
1869 int size;
1870};
1871
8a3003dd
RB
1872struct i915_oa_reg {
1873 i915_reg_t addr;
1874 u32 value;
1875};
1876
eec688e1
RB
1877struct i915_perf_stream;
1878
16d98b31
RB
1879/**
1880 * struct i915_perf_stream_ops - the OPs to support a specific stream type
1881 */
eec688e1 1882struct i915_perf_stream_ops {
16d98b31
RB
1883 /**
1884 * @enable: Enables the collection of HW samples, either in response to
1885 * `I915_PERF_IOCTL_ENABLE` or implicitly called when stream is opened
1886 * without `I915_PERF_FLAG_DISABLED`.
eec688e1
RB
1887 */
1888 void (*enable)(struct i915_perf_stream *stream);
1889
16d98b31
RB
1890 /**
1891 * @disable: Disables the collection of HW samples, either in response
1892 * to `I915_PERF_IOCTL_DISABLE` or implicitly called before destroying
1893 * the stream.
eec688e1
RB
1894 */
1895 void (*disable)(struct i915_perf_stream *stream);
1896
16d98b31
RB
1897 /**
1898 * @poll_wait: Call poll_wait, passing a wait queue that will be woken
eec688e1
RB
1899 * once there is something ready to read() for the stream
1900 */
1901 void (*poll_wait)(struct i915_perf_stream *stream,
1902 struct file *file,
1903 poll_table *wait);
1904
16d98b31
RB
1905 /**
1906 * @wait_unlocked: For handling a blocking read, wait until there is
1907 * something to ready to read() for the stream. E.g. wait on the same
d7965152 1908 * wait queue that would be passed to poll_wait().
eec688e1
RB
1909 */
1910 int (*wait_unlocked)(struct i915_perf_stream *stream);
1911
16d98b31
RB
1912 /**
1913 * @read: Copy buffered metrics as records to userspace
1914 * **buf**: the userspace, destination buffer
1915 * **count**: the number of bytes to copy, requested by userspace
1916 * **offset**: zero at the start of the read, updated as the read
1917 * proceeds, it represents how many bytes have been copied so far and
1918 * the buffer offset for copying the next record.
eec688e1 1919 *
16d98b31
RB
1920 * Copy as many buffered i915 perf samples and records for this stream
1921 * to userspace as will fit in the given buffer.
eec688e1 1922 *
16d98b31
RB
1923 * Only write complete records; returning -%ENOSPC if there isn't room
1924 * for a complete record.
eec688e1 1925 *
16d98b31
RB
1926 * Return any error condition that results in a short read such as
1927 * -%ENOSPC or -%EFAULT, even though these may be squashed before
1928 * returning to userspace.
eec688e1
RB
1929 */
1930 int (*read)(struct i915_perf_stream *stream,
1931 char __user *buf,
1932 size_t count,
1933 size_t *offset);
1934
16d98b31
RB
1935 /**
1936 * @destroy: Cleanup any stream specific resources.
eec688e1
RB
1937 *
1938 * The stream will always be disabled before this is called.
1939 */
1940 void (*destroy)(struct i915_perf_stream *stream);
1941};
1942
16d98b31
RB
1943/**
1944 * struct i915_perf_stream - state for a single open stream FD
1945 */
eec688e1 1946struct i915_perf_stream {
16d98b31
RB
1947 /**
1948 * @dev_priv: i915 drm device
1949 */
eec688e1
RB
1950 struct drm_i915_private *dev_priv;
1951
16d98b31
RB
1952 /**
1953 * @link: Links the stream into ``&drm_i915_private->streams``
1954 */
eec688e1
RB
1955 struct list_head link;
1956
16d98b31
RB
1957 /**
1958 * @sample_flags: Flags representing the `DRM_I915_PERF_PROP_SAMPLE_*`
1959 * properties given when opening a stream, representing the contents
1960 * of a single sample as read() by userspace.
1961 */
eec688e1 1962 u32 sample_flags;
16d98b31
RB
1963
1964 /**
1965 * @sample_size: Considering the configured contents of a sample
1966 * combined with the required header size, this is the total size
1967 * of a single sample record.
1968 */
d7965152 1969 int sample_size;
eec688e1 1970
16d98b31
RB
1971 /**
1972 * @ctx: %NULL if measuring system-wide across all contexts or a
1973 * specific context that is being monitored.
1974 */
eec688e1 1975 struct i915_gem_context *ctx;
16d98b31
RB
1976
1977 /**
1978 * @enabled: Whether the stream is currently enabled, considering
1979 * whether the stream was opened in a disabled state and based
1980 * on `I915_PERF_IOCTL_ENABLE` and `I915_PERF_IOCTL_DISABLE` calls.
1981 */
eec688e1
RB
1982 bool enabled;
1983
16d98b31
RB
1984 /**
1985 * @ops: The callbacks providing the implementation of this specific
1986 * type of configured stream.
1987 */
d7965152
RB
1988 const struct i915_perf_stream_ops *ops;
1989};
1990
16d98b31
RB
1991/**
1992 * struct i915_oa_ops - Gen specific implementation of an OA unit stream
1993 */
d7965152 1994struct i915_oa_ops {
16d98b31
RB
1995 /**
1996 * @init_oa_buffer: Resets the head and tail pointers of the
1997 * circular buffer for periodic OA reports.
1998 *
1999 * Called when first opening a stream for OA metrics, but also may be
2000 * called in response to an OA buffer overflow or other error
2001 * condition.
2002 *
2003 * Note it may be necessary to clear the full OA buffer here as part of
2004 * maintaining the invariable that new reports must be written to
2005 * zeroed memory for us to be able to reliable detect if an expected
2006 * report has not yet landed in memory. (At least on Haswell the OA
2007 * buffer tail pointer is not synchronized with reports being visible
2008 * to the CPU)
2009 */
d7965152 2010 void (*init_oa_buffer)(struct drm_i915_private *dev_priv);
16d98b31
RB
2011
2012 /**
2013 * @enable_metric_set: Applies any MUX configuration to set up the
2014 * Boolean and Custom (B/C) counters that are part of the counter
2015 * reports being sampled. May apply system constraints such as
2016 * disabling EU clock gating as required.
2017 */
d7965152 2018 int (*enable_metric_set)(struct drm_i915_private *dev_priv);
16d98b31
RB
2019
2020 /**
2021 * @disable_metric_set: Remove system constraints associated with using
2022 * the OA unit.
2023 */
d7965152 2024 void (*disable_metric_set)(struct drm_i915_private *dev_priv);
16d98b31
RB
2025
2026 /**
2027 * @oa_enable: Enable periodic sampling
2028 */
d7965152 2029 void (*oa_enable)(struct drm_i915_private *dev_priv);
16d98b31
RB
2030
2031 /**
2032 * @oa_disable: Disable periodic sampling
2033 */
d7965152 2034 void (*oa_disable)(struct drm_i915_private *dev_priv);
16d98b31
RB
2035
2036 /**
2037 * @read: Copy data from the circular OA buffer into a given userspace
2038 * buffer.
2039 */
d7965152
RB
2040 int (*read)(struct i915_perf_stream *stream,
2041 char __user *buf,
2042 size_t count,
2043 size_t *offset);
16d98b31
RB
2044
2045 /**
2046 * @oa_buffer_is_empty: Check if OA buffer empty (false positives OK)
2047 *
2048 * This is either called via fops or the poll check hrtimer (atomic
2049 * ctx) without any locks taken.
2050 *
2051 * It's safe to read OA config state here unlocked, assuming that this
2052 * is only called while the stream is enabled, while the global OA
2053 * configuration can't be modified.
2054 *
2055 * Efficiency is more important than avoiding some false positives
2056 * here, which will be handled gracefully - likely resulting in an
2057 * %EAGAIN error for userspace.
2058 */
d7965152 2059 bool (*oa_buffer_is_empty)(struct drm_i915_private *dev_priv);
eec688e1
RB
2060};
2061
77fec556 2062struct drm_i915_private {
8f460e2c
CW
2063 struct drm_device drm;
2064
efab6d8d 2065 struct kmem_cache *objects;
e20d2ab7 2066 struct kmem_cache *vmas;
efab6d8d 2067 struct kmem_cache *requests;
52e54209 2068 struct kmem_cache *dependencies;
f4c956ad 2069
5c969aa7 2070 const struct intel_device_info info;
f4c956ad
DV
2071
2072 int relative_constants_mode;
2073
2074 void __iomem *regs;
2075
907b28c5 2076 struct intel_uncore uncore;
f4c956ad 2077
cf9d2890
YZ
2078 struct i915_virtual_gpu vgpu;
2079
feddf6e8 2080 struct intel_gvt *gvt;
0ad35fed 2081
33a732f4
AD
2082 struct intel_guc guc;
2083
eb805623
DV
2084 struct intel_csr csr;
2085
5ea6e5e3 2086 struct intel_gmbus gmbus[GMBUS_NUM_PINS];
28c70f16 2087
f4c956ad
DV
2088 /** gmbus_mutex protects against concurrent usage of the single hw gmbus
2089 * controller on different i2c buses. */
2090 struct mutex gmbus_mutex;
2091
2092 /**
2093 * Base address of the gmbus and gpio block.
2094 */
2095 uint32_t gpio_mmio_base;
2096
b6fdd0f2
SS
2097 /* MMIO base address for MIPI regs */
2098 uint32_t mipi_mmio_base;
2099
443a389f
VS
2100 uint32_t psr_mmio_base;
2101
44cb734c
ID
2102 uint32_t pps_mmio_base;
2103
28c70f16
DV
2104 wait_queue_head_t gmbus_wait_queue;
2105
f4c956ad 2106 struct pci_dev *bridge_dev;
0ca5fa3a 2107 struct i915_gem_context *kernel_context;
3b3f1650 2108 struct intel_engine_cs *engine[I915_NUM_ENGINES];
51d545d0 2109 struct i915_vma *semaphore;
f4c956ad 2110
ba8286fa 2111 struct drm_dma_handle *status_page_dmah;
f4c956ad
DV
2112 struct resource mch_res;
2113
f4c956ad
DV
2114 /* protects the irq masks */
2115 spinlock_t irq_lock;
2116
84c33a64
SG
2117 /* protects the mmio flip data */
2118 spinlock_t mmio_flip_lock;
2119
f8b79e58
ID
2120 bool display_irqs_enabled;
2121
9ee32fea
DV
2122 /* To control wakeup latency, e.g. for irq-driven dp aux transfers. */
2123 struct pm_qos_request pm_qos;
2124
a580516d
VS
2125 /* Sideband mailbox protection */
2126 struct mutex sb_lock;
f4c956ad
DV
2127
2128 /** Cached value of IMR to avoid reads in updating the bitfield */
abd58f01
BW
2129 union {
2130 u32 irq_mask;
2131 u32 de_irq_mask[I915_MAX_PIPES];
2132 };
f4c956ad 2133 u32 gt_irq_mask;
f4e9af4f
AG
2134 u32 pm_imr;
2135 u32 pm_ier;
a6706b45 2136 u32 pm_rps_events;
26705e20 2137 u32 pm_guc_events;
91d181dd 2138 u32 pipestat_irq_mask[I915_MAX_PIPES];
f4c956ad 2139
5fcece80 2140 struct i915_hotplug hotplug;
ab34a7e8 2141 struct intel_fbc fbc;
439d7ac0 2142 struct i915_drrs drrs;
f4c956ad 2143 struct intel_opregion opregion;
41aa3448 2144 struct intel_vbt_data vbt;
f4c956ad 2145
d9ceb816
JB
2146 bool preserve_bios_swizzle;
2147
f4c956ad
DV
2148 /* overlay */
2149 struct intel_overlay *overlay;
f4c956ad 2150
58c68779 2151 /* backlight registers and fields in struct intel_panel */
07f11d49 2152 struct mutex backlight_lock;
31ad8ec6 2153
f4c956ad 2154 /* LVDS info */
f4c956ad
DV
2155 bool no_aux_handshake;
2156
e39b999a
VS
2157 /* protects panel power sequencer state */
2158 struct mutex pps_mutex;
2159
f4c956ad 2160 struct drm_i915_fence_reg fence_regs[I915_MAX_NUM_FENCES]; /* assume 965 */
f4c956ad
DV
2161 int num_fence_regs; /* 8 on pre-965, 16 otherwise */
2162
2163 unsigned int fsb_freq, mem_freq, is_ddr3;
b2045352 2164 unsigned int skl_preferred_vco_freq;
8d96561a
VS
2165 unsigned int cdclk_freq, max_cdclk_freq;
2166
2167 /*
2168 * For reading holding any crtc lock is sufficient,
2169 * for writing must hold all of them.
2170 */
2171 unsigned int atomic_cdclk_freq;
2172
adafdc6f 2173 unsigned int max_dotclk_freq;
e7dc33f3 2174 unsigned int rawclk_freq;
6bcda4f0 2175 unsigned int hpll_freq;
bfa7df01 2176 unsigned int czclk_freq;
f4c956ad 2177
63911d72 2178 struct {
709e05c3 2179 unsigned int vco, ref;
63911d72
VS
2180 } cdclk_pll;
2181
645416f5
DV
2182 /**
2183 * wq - Driver workqueue for GEM.
2184 *
2185 * NOTE: Work items scheduled here are not allowed to grab any modeset
2186 * locks, for otherwise the flushing done in the pageflip code will
2187 * result in deadlocks.
2188 */
f4c956ad
DV
2189 struct workqueue_struct *wq;
2190
2191 /* Display functions */
2192 struct drm_i915_display_funcs display;
2193
2194 /* PCH chipset type */
2195 enum intel_pch pch_type;
17a303ec 2196 unsigned short pch_id;
f4c956ad
DV
2197
2198 unsigned long quirks;
2199
b8efb17b
ZR
2200 enum modeset_restore modeset_restore;
2201 struct mutex modeset_restore_lock;
e2c8b870 2202 struct drm_atomic_state *modeset_restore_state;
73974893 2203 struct drm_modeset_acquire_ctx reset_ctx;
673a394b 2204
a7bbbd63 2205 struct list_head vm_list; /* Global list of all address spaces */
62106b4f 2206 struct i915_ggtt ggtt; /* VM representing the global address space */
5d4545ae 2207
4b5aed62 2208 struct i915_gem_mm mm;
ad46cb53
CW
2209 DECLARE_HASHTABLE(mm_structs, 7);
2210 struct mutex mm_lock;
8781342d 2211
5d1808ec
CW
2212 /* The hw wants to have a stable context identifier for the lifetime
2213 * of the context (for OA, PASID, faults, etc). This is limited
2214 * in execlists to 21 bits.
2215 */
2216 struct ida context_hw_ida;
2217#define MAX_CONTEXT_HW_ID (1<<21) /* exclusive */
2218
8781342d
DV
2219 /* Kernel Modesetting */
2220
e2af48c6
VS
2221 struct intel_crtc *plane_to_crtc_mapping[I915_MAX_PIPES];
2222 struct intel_crtc *pipe_to_crtc_mapping[I915_MAX_PIPES];
6b95a207
KH
2223 wait_queue_head_t pending_flip_queue;
2224
c4597872
DV
2225#ifdef CONFIG_DEBUG_FS
2226 struct intel_pipe_crc pipe_crc[I915_MAX_PIPES];
2227#endif
2228
565602d7 2229 /* dpll and cdclk state is protected by connection_mutex */
e72f9fbf
DV
2230 int num_shared_dpll;
2231 struct intel_shared_dpll shared_dplls[I915_NUM_PLLS];
f9476a6c 2232 const struct intel_dpll_mgr *dpll_mgr;
565602d7 2233
fbf6d879
ML
2234 /*
2235 * dpll_lock serializes intel_{prepare,enable,disable}_shared_dpll.
2236 * Must be global rather than per dpll, because on some platforms
2237 * plls share registers.
2238 */
2239 struct mutex dpll_lock;
2240
565602d7
ML
2241 unsigned int active_crtcs;
2242 unsigned int min_pixclk[I915_MAX_PIPES];
2243
e4607fcf 2244 int dpio_phy_iosf_port[I915_NUM_PHYS_VLV];
ee7b9f93 2245
7225342a 2246 struct i915_workarounds workarounds;
888b5995 2247
f99d7069
DV
2248 struct i915_frontbuffer_tracking fb_tracking;
2249
652c393a 2250 u16 orig_clock;
f97108d1 2251
c4804411 2252 bool mchbar_need_disable;
f97108d1 2253
a4da4fa4
DV
2254 struct intel_l3_parity l3_parity;
2255
59124506 2256 /* Cannot be determined by PCIID. You must always read a register. */
3accaf7e 2257 u32 edram_cap;
59124506 2258
c6a828d3 2259 /* gen6+ rps state */
c85aa885 2260 struct intel_gen6_power_mgmt rps;
c6a828d3 2261
20e4d407
DV
2262 /* ilk-only ips/rps state. Everything in here is protected by the global
2263 * mchdev_lock in intel_pm.c */
c85aa885 2264 struct intel_ilk_power_mgmt ips;
b5e50c3f 2265
83c00f55 2266 struct i915_power_domains power_domains;
a38911a3 2267
a031d709 2268 struct i915_psr psr;
3f51e471 2269
99584db3 2270 struct i915_gpu_error gpu_error;
ae681d96 2271
c9cddffc
JB
2272 struct drm_i915_gem_object *vlv_pctx;
2273
0695726e 2274#ifdef CONFIG_DRM_FBDEV_EMULATION
8be48d92
DA
2275 /* list of fbdev register on this device */
2276 struct intel_fbdev *fbdev;
82e3b8c1 2277 struct work_struct fbdev_suspend_work;
4520f53a 2278#endif
e953fd7b
CW
2279
2280 struct drm_property *broadcast_rgb_property;
3f43c48d 2281 struct drm_property *force_audio_property;
e3689190 2282
58fddc28 2283 /* hda/i915 audio component */
51e1d83c 2284 struct i915_audio_component *audio_component;
58fddc28 2285 bool audio_component_registered;
4a21ef7d
LY
2286 /**
2287 * av_mutex - mutex for audio/video sync
2288 *
2289 */
2290 struct mutex av_mutex;
58fddc28 2291
254f965c 2292 uint32_t hw_context_size;
a33afea5 2293 struct list_head context_list;
f4c956ad 2294
3e68320e 2295 u32 fdi_rx_config;
68d18ad7 2296
c231775c 2297 /* Shadow for DISPLAY_PHY_CONTROL which can't be safely read */
70722468 2298 u32 chv_phy_control;
c231775c
VS
2299 /*
2300 * Shadows for CHV DPLL_MD regs to keep the state
2301 * checker somewhat working in the presence hardware
2302 * crappiness (can't read out DPLL_MD for pipes B & C).
2303 */
2304 u32 chv_dpll_md[I915_MAX_PIPES];
adc7f04b 2305 u32 bxt_phy_grc;
70722468 2306
842f1c8b 2307 u32 suspend_count;
bc87229f 2308 bool suspended_to_idle;
f4c956ad 2309 struct i915_suspend_saved_registers regfile;
ddeea5b0 2310 struct vlv_s0ix_state vlv_s0ix_state;
231f42a4 2311
656d1b89 2312 enum {
16dcdc4e
PZ
2313 I915_SAGV_UNKNOWN = 0,
2314 I915_SAGV_DISABLED,
2315 I915_SAGV_ENABLED,
2316 I915_SAGV_NOT_CONTROLLED
2317 } sagv_status;
656d1b89 2318
53615a5e 2319 struct {
467a14d9
VS
2320 /* protects DSPARB registers on pre-g4x/vlv/chv */
2321 spinlock_t dsparb_lock;
2322
53615a5e
VS
2323 /*
2324 * Raw watermark latency values:
2325 * in 0.1us units for WM0,
2326 * in 0.5us units for WM1+.
2327 */
2328 /* primary */
2329 uint16_t pri_latency[5];
2330 /* sprite */
2331 uint16_t spr_latency[5];
2332 /* cursor */
2333 uint16_t cur_latency[5];
2af30a5c
PB
2334 /*
2335 * Raw watermark memory latency values
2336 * for SKL for all 8 levels
2337 * in 1us units.
2338 */
2339 uint16_t skl_latency[8];
609cedef
VS
2340
2341 /* current hardware state */
2d41c0b5
PB
2342 union {
2343 struct ilk_wm_values hw;
2344 struct skl_wm_values skl_hw;
0018fda1 2345 struct vlv_wm_values vlv;
2d41c0b5 2346 };
58590c14
VS
2347
2348 uint8_t max_level;
ed4a6a7c
MR
2349
2350 /*
2351 * Should be held around atomic WM register writing; also
2352 * protects * intel_crtc->wm.active and
2353 * cstate->wm.need_postvbl_update.
2354 */
2355 struct mutex wm_mutex;
279e99d7
MR
2356
2357 /*
2358 * Set during HW readout of watermarks/DDB. Some platforms
2359 * need to know when we're still using BIOS-provided values
2360 * (which we don't fully trust).
2361 */
2362 bool distrust_bios_wm;
53615a5e
VS
2363 } wm;
2364
8a187455
PZ
2365 struct i915_runtime_pm pm;
2366
eec688e1
RB
2367 struct {
2368 bool initialized;
d7965152 2369
442b8c06 2370 struct kobject *metrics_kobj;
ccdf6341 2371 struct ctl_table_header *sysctl_header;
442b8c06 2372
eec688e1
RB
2373 struct mutex lock;
2374 struct list_head streams;
8a3003dd 2375
d7965152
RB
2376 spinlock_t hook_lock;
2377
8a3003dd 2378 struct {
d7965152
RB
2379 struct i915_perf_stream *exclusive_stream;
2380
2381 u32 specific_ctx_id;
d7965152
RB
2382
2383 struct hrtimer poll_check_timer;
2384 wait_queue_head_t poll_wq;
2385 bool pollin;
2386
2387 bool periodic;
2388 int period_exponent;
2389 int timestamp_frequency;
2390
2391 int tail_margin;
2392
2393 int metrics_set;
8a3003dd
RB
2394
2395 const struct i915_oa_reg *mux_regs;
2396 int mux_regs_len;
2397 const struct i915_oa_reg *b_counter_regs;
2398 int b_counter_regs_len;
d7965152
RB
2399
2400 struct {
2401 struct i915_vma *vma;
2402 u8 *vaddr;
2403 int format;
2404 int format_size;
2405 } oa_buffer;
2406
2407 u32 gen7_latched_oastatus1;
2408
2409 struct i915_oa_ops ops;
2410 const struct i915_oa_format *oa_formats;
2411 int n_builtin_sets;
8a3003dd 2412 } oa;
eec688e1
RB
2413 } perf;
2414
a83014d3
OM
2415 /* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
2416 struct {
821ed7df 2417 void (*resume)(struct drm_i915_private *);
117897f4 2418 void (*cleanup_engine)(struct intel_engine_cs *engine);
67d97da3 2419
73cb9701
CW
2420 struct list_head timelines;
2421 struct i915_gem_timeline global_timeline;
28176ef4 2422 u32 active_requests;
73cb9701 2423
67d97da3
CW
2424 /**
2425 * Is the GPU currently considered idle, or busy executing
2426 * userspace requests? Whilst idle, we allow runtime power
2427 * management to power down the hardware and display clocks.
2428 * In order to reduce the effect on performance, there
2429 * is a slight delay before we do so.
2430 */
67d97da3
CW
2431 bool awake;
2432
2433 /**
2434 * We leave the user IRQ off as much as possible,
2435 * but this means that requests will finish and never
2436 * be retired once the system goes idle. Set a timer to
2437 * fire periodically while the ring is running. When it
2438 * fires, go retire requests.
2439 */
2440 struct delayed_work retire_work;
2441
2442 /**
2443 * When we detect an idle GPU, we want to turn on
2444 * powersaving features. So once we see that there
2445 * are no more requests outstanding and no more
2446 * arrive within a small period of time, we fire
2447 * off the idle_work.
2448 */
2449 struct delayed_work idle_work;
de867c20
CW
2450
2451 ktime_t last_init_time;
a83014d3
OM
2452 } gt;
2453
3be60de9
VS
2454 /* perform PHY state sanity checks? */
2455 bool chv_phy_assert[2];
2456
a3a8986c
MK
2457 bool ipc_enabled;
2458
f9318941
PD
2459 /* Used to save the pipe-to-encoder mapping for audio */
2460 struct intel_encoder *av_enc_map[I915_MAX_PIPES];
0bdf5a05 2461
bdf1e7e3
DV
2462 /*
2463 * NOTE: This is the dri1/ums dungeon, don't add stuff here. Your patch
2464 * will be rejected. Instead look for a better place.
2465 */
77fec556 2466};
1da177e4 2467
2c1792a1
CW
2468static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
2469{
091387c1 2470 return container_of(dev, struct drm_i915_private, drm);
2c1792a1
CW
2471}
2472
c49d13ee 2473static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
888d0d42 2474{
c49d13ee 2475 return to_i915(dev_get_drvdata(kdev));
888d0d42
ID
2476}
2477
33a732f4
AD
2478static inline struct drm_i915_private *guc_to_i915(struct intel_guc *guc)
2479{
2480 return container_of(guc, struct drm_i915_private, guc);
2481}
2482
b4ac5afc 2483/* Simple iterator over all initialised engines */
3b3f1650
AG
2484#define for_each_engine(engine__, dev_priv__, id__) \
2485 for ((id__) = 0; \
2486 (id__) < I915_NUM_ENGINES; \
2487 (id__)++) \
2488 for_each_if ((engine__) = (dev_priv__)->engine[(id__)])
c3232b18 2489
bafb0fce
CW
2490#define __mask_next_bit(mask) ({ \
2491 int __idx = ffs(mask) - 1; \
2492 mask &= ~BIT(__idx); \
2493 __idx; \
2494})
2495
c3232b18 2496/* Iterator over subset of engines selected by mask */
bafb0fce
CW
2497#define for_each_engine_masked(engine__, dev_priv__, mask__, tmp__) \
2498 for (tmp__ = mask__ & INTEL_INFO(dev_priv__)->ring_mask; \
3b3f1650 2499 tmp__ ? (engine__ = (dev_priv__)->engine[__mask_next_bit(tmp__)]), 1 : 0; )
ee4b6faf 2500
b1d7e4b4
WF
2501enum hdmi_force_audio {
2502 HDMI_AUDIO_OFF_DVI = -2, /* no aux data for HDMI-DVI converter */
2503 HDMI_AUDIO_OFF, /* force turn off HDMI audio */
2504 HDMI_AUDIO_AUTO, /* trust EDID */
2505 HDMI_AUDIO_ON, /* force turn on HDMI audio */
2506};
2507
190d6cd5 2508#define I915_GTT_OFFSET_NONE ((u32)-1)
ed2f3452 2509
a071fa00
DV
2510/*
2511 * Frontbuffer tracking bits. Set in obj->frontbuffer_bits while a gem bo is
d1b9d039 2512 * considered to be the frontbuffer for the given plane interface-wise. This
a071fa00
DV
2513 * doesn't mean that the hw necessarily already scans it out, but that any
2514 * rendering (by the cpu or gpu) will land in the frontbuffer eventually.
2515 *
2516 * We have one bit per pipe and per scanout plane type.
2517 */
d1b9d039
SAK
2518#define INTEL_MAX_SPRITE_BITS_PER_PIPE 5
2519#define INTEL_FRONTBUFFER_BITS_PER_PIPE 8
a071fa00
DV
2520#define INTEL_FRONTBUFFER_PRIMARY(pipe) \
2521 (1 << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
2522#define INTEL_FRONTBUFFER_CURSOR(pipe) \
d1b9d039
SAK
2523 (1 << (1 + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
2524#define INTEL_FRONTBUFFER_SPRITE(pipe, plane) \
2525 (1 << (2 + plane + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
a071fa00 2526#define INTEL_FRONTBUFFER_OVERLAY(pipe) \
d1b9d039 2527 (1 << (2 + INTEL_MAX_SPRITE_BITS_PER_PIPE + (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe))))
cc36513c 2528#define INTEL_FRONTBUFFER_ALL_MASK(pipe) \
d1b9d039 2529 (0xff << (INTEL_FRONTBUFFER_BITS_PER_PIPE * (pipe)))
a071fa00 2530
85d1225e
DG
2531/*
2532 * Optimised SGL iterator for GEM objects
2533 */
2534static __always_inline struct sgt_iter {
2535 struct scatterlist *sgp;
2536 union {
2537 unsigned long pfn;
2538 dma_addr_t dma;
2539 };
2540 unsigned int curr;
2541 unsigned int max;
2542} __sgt_iter(struct scatterlist *sgl, bool dma) {
2543 struct sgt_iter s = { .sgp = sgl };
2544
2545 if (s.sgp) {
2546 s.max = s.curr = s.sgp->offset;
2547 s.max += s.sgp->length;
2548 if (dma)
2549 s.dma = sg_dma_address(s.sgp);
2550 else
2551 s.pfn = page_to_pfn(sg_page(s.sgp));
2552 }
2553
2554 return s;
2555}
2556
96d77634
CW
2557static inline struct scatterlist *____sg_next(struct scatterlist *sg)
2558{
2559 ++sg;
2560 if (unlikely(sg_is_chain(sg)))
2561 sg = sg_chain_ptr(sg);
2562 return sg;
2563}
2564
63d15326
DG
2565/**
2566 * __sg_next - return the next scatterlist entry in a list
2567 * @sg: The current sg entry
2568 *
2569 * Description:
2570 * If the entry is the last, return NULL; otherwise, step to the next
2571 * element in the array (@sg@+1). If that's a chain pointer, follow it;
2572 * otherwise just return the pointer to the current element.
2573 **/
2574static inline struct scatterlist *__sg_next(struct scatterlist *sg)
2575{
2576#ifdef CONFIG_DEBUG_SG
2577 BUG_ON(sg->sg_magic != SG_MAGIC);
2578#endif
96d77634 2579 return sg_is_last(sg) ? NULL : ____sg_next(sg);
63d15326
DG
2580}
2581
85d1225e
DG
2582/**
2583 * for_each_sgt_dma - iterate over the DMA addresses of the given sg_table
2584 * @__dmap: DMA address (output)
2585 * @__iter: 'struct sgt_iter' (iterator state, internal)
2586 * @__sgt: sg_table to iterate over (input)
2587 */
2588#define for_each_sgt_dma(__dmap, __iter, __sgt) \
2589 for ((__iter) = __sgt_iter((__sgt)->sgl, true); \
2590 ((__dmap) = (__iter).dma + (__iter).curr); \
2591 (((__iter).curr += PAGE_SIZE) < (__iter).max) || \
63d15326 2592 ((__iter) = __sgt_iter(__sg_next((__iter).sgp), true), 0))
85d1225e
DG
2593
2594/**
2595 * for_each_sgt_page - iterate over the pages of the given sg_table
2596 * @__pp: page pointer (output)
2597 * @__iter: 'struct sgt_iter' (iterator state, internal)
2598 * @__sgt: sg_table to iterate over (input)
2599 */
2600#define for_each_sgt_page(__pp, __iter, __sgt) \
2601 for ((__iter) = __sgt_iter((__sgt)->sgl, false); \
2602 ((__pp) = (__iter).pfn == 0 ? NULL : \
2603 pfn_to_page((__iter).pfn + ((__iter).curr >> PAGE_SHIFT))); \
2604 (((__iter).curr += PAGE_SIZE) < (__iter).max) || \
63d15326 2605 ((__iter) = __sgt_iter(__sg_next((__iter).sgp), false), 0))
a071fa00 2606
5ca43ef0
TU
2607static inline const struct intel_device_info *
2608intel_info(const struct drm_i915_private *dev_priv)
2609{
2610 return &dev_priv->info;
2611}
2612
2613#define INTEL_INFO(dev_priv) intel_info((dev_priv))
50a0bc90 2614
55b8f2a7 2615#define INTEL_GEN(dev_priv) ((dev_priv)->info.gen)
50a0bc90 2616#define INTEL_DEVID(dev_priv) ((dev_priv)->info.device_id)
cae5852d 2617
e87a005d 2618#define REVID_FOREVER 0xff
4805fe82 2619#define INTEL_REVID(dev_priv) ((dev_priv)->drm.pdev->revision)
ac657f64
TU
2620
2621#define GEN_FOREVER (0)
2622/*
2623 * Returns true if Gen is in inclusive range [Start, End].
2624 *
2625 * Use GEN_FOREVER for unbound start and or end.
2626 */
c1812bdb 2627#define IS_GEN(dev_priv, s, e) ({ \
ac657f64
TU
2628 unsigned int __s = (s), __e = (e); \
2629 BUILD_BUG_ON(!__builtin_constant_p(s)); \
2630 BUILD_BUG_ON(!__builtin_constant_p(e)); \
2631 if ((__s) != GEN_FOREVER) \
2632 __s = (s) - 1; \
2633 if ((__e) == GEN_FOREVER) \
2634 __e = BITS_PER_LONG - 1; \
2635 else \
2636 __e = (e) - 1; \
c1812bdb 2637 !!((dev_priv)->info.gen_mask & GENMASK((__e), (__s))); \
ac657f64
TU
2638})
2639
e87a005d
JN
2640/*
2641 * Return true if revision is in range [since,until] inclusive.
2642 *
2643 * Use 0 for open-ended since, and REVID_FOREVER for open-ended until.
2644 */
2645#define IS_REVID(p, since, until) \
2646 (INTEL_REVID(p) >= (since) && INTEL_REVID(p) <= (until))
2647
06bcd848
JN
2648#define IS_I830(dev_priv) ((dev_priv)->info.platform == INTEL_I830)
2649#define IS_I845G(dev_priv) ((dev_priv)->info.platform == INTEL_I845G)
2e0d26f8 2650#define IS_I85X(dev_priv) ((dev_priv)->info.platform == INTEL_I85X)
06bcd848 2651#define IS_I865G(dev_priv) ((dev_priv)->info.platform == INTEL_I865G)
2e0d26f8 2652#define IS_I915G(dev_priv) ((dev_priv)->info.platform == INTEL_I915G)
06bcd848
JN
2653#define IS_I915GM(dev_priv) ((dev_priv)->info.platform == INTEL_I915GM)
2654#define IS_I945G(dev_priv) ((dev_priv)->info.platform == INTEL_I945G)
2e0d26f8 2655#define IS_I945GM(dev_priv) ((dev_priv)->info.platform == INTEL_I945GM)
c0f86832
JN
2656#define IS_I965G(dev_priv) ((dev_priv)->info.platform == INTEL_I965G)
2657#define IS_I965GM(dev_priv) ((dev_priv)->info.platform == INTEL_I965GM)
f69c11ae
JN
2658#define IS_G45(dev_priv) ((dev_priv)->info.platform == INTEL_G45)
2659#define IS_GM45(dev_priv) ((dev_priv)->info.platform == INTEL_GM45)
2660#define IS_G4X(dev_priv) (IS_G45(dev_priv) || IS_GM45(dev_priv))
50a0bc90
TU
2661#define IS_PINEVIEW_G(dev_priv) (INTEL_DEVID(dev_priv) == 0xa001)
2662#define IS_PINEVIEW_M(dev_priv) (INTEL_DEVID(dev_priv) == 0xa011)
73f67aa8 2663#define IS_PINEVIEW(dev_priv) ((dev_priv)->info.platform == INTEL_PINEVIEW)
2e0d26f8 2664#define IS_G33(dev_priv) ((dev_priv)->info.platform == INTEL_G33)
50a0bc90 2665#define IS_IRONLAKE_M(dev_priv) (INTEL_DEVID(dev_priv) == 0x0046)
2e0d26f8 2666#define IS_IVYBRIDGE(dev_priv) ((dev_priv)->info.platform == INTEL_IVYBRIDGE)
50a0bc90
TU
2667#define IS_IVB_GT1(dev_priv) (INTEL_DEVID(dev_priv) == 0x0156 || \
2668 INTEL_DEVID(dev_priv) == 0x0152 || \
2669 INTEL_DEVID(dev_priv) == 0x015a)
2e0d26f8
JN
2670#define IS_VALLEYVIEW(dev_priv) ((dev_priv)->info.platform == INTEL_VALLEYVIEW)
2671#define IS_CHERRYVIEW(dev_priv) ((dev_priv)->info.platform == INTEL_CHERRYVIEW)
2672#define IS_HASWELL(dev_priv) ((dev_priv)->info.platform == INTEL_HASWELL)
2673#define IS_BROADWELL(dev_priv) ((dev_priv)->info.platform == INTEL_BROADWELL)
2674#define IS_SKYLAKE(dev_priv) ((dev_priv)->info.platform == INTEL_SKYLAKE)
2675#define IS_BROXTON(dev_priv) ((dev_priv)->info.platform == INTEL_BROXTON)
2676#define IS_KABYLAKE(dev_priv) ((dev_priv)->info.platform == INTEL_KABYLAKE)
2677#define IS_GEMINILAKE(dev_priv) ((dev_priv)->info.platform == INTEL_GEMINILAKE)
646d5772 2678#define IS_MOBILE(dev_priv) ((dev_priv)->info.is_mobile)
50a0bc90
TU
2679#define IS_HSW_EARLY_SDV(dev_priv) (IS_HASWELL(dev_priv) && \
2680 (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0C00)
2681#define IS_BDW_ULT(dev_priv) (IS_BROADWELL(dev_priv) && \
2682 ((INTEL_DEVID(dev_priv) & 0xf) == 0x6 || \
2683 (INTEL_DEVID(dev_priv) & 0xf) == 0xb || \
2684 (INTEL_DEVID(dev_priv) & 0xf) == 0xe))
ebb72aad 2685/* ULX machines are also considered ULT. */
50a0bc90
TU
2686#define IS_BDW_ULX(dev_priv) (IS_BROADWELL(dev_priv) && \
2687 (INTEL_DEVID(dev_priv) & 0xf) == 0xe)
2688#define IS_BDW_GT3(dev_priv) (IS_BROADWELL(dev_priv) && \
2689 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0020)
2690#define IS_HSW_ULT(dev_priv) (IS_HASWELL(dev_priv) && \
2691 (INTEL_DEVID(dev_priv) & 0xFF00) == 0x0A00)
2692#define IS_HSW_GT3(dev_priv) (IS_HASWELL(dev_priv) && \
2693 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0020)
9bbfd20a 2694/* ULX machines are also considered ULT. */
50a0bc90
TU
2695#define IS_HSW_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x0A0E || \
2696 INTEL_DEVID(dev_priv) == 0x0A1E)
2697#define IS_SKL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x1906 || \
2698 INTEL_DEVID(dev_priv) == 0x1913 || \
2699 INTEL_DEVID(dev_priv) == 0x1916 || \
2700 INTEL_DEVID(dev_priv) == 0x1921 || \
2701 INTEL_DEVID(dev_priv) == 0x1926)
2702#define IS_SKL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x190E || \
2703 INTEL_DEVID(dev_priv) == 0x1915 || \
2704 INTEL_DEVID(dev_priv) == 0x191E)
2705#define IS_KBL_ULT(dev_priv) (INTEL_DEVID(dev_priv) == 0x5906 || \
2706 INTEL_DEVID(dev_priv) == 0x5913 || \
2707 INTEL_DEVID(dev_priv) == 0x5916 || \
2708 INTEL_DEVID(dev_priv) == 0x5921 || \
2709 INTEL_DEVID(dev_priv) == 0x5926)
2710#define IS_KBL_ULX(dev_priv) (INTEL_DEVID(dev_priv) == 0x590E || \
2711 INTEL_DEVID(dev_priv) == 0x5915 || \
2712 INTEL_DEVID(dev_priv) == 0x591E)
2713#define IS_SKL_GT3(dev_priv) (IS_SKYLAKE(dev_priv) && \
2714 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0020)
2715#define IS_SKL_GT4(dev_priv) (IS_SKYLAKE(dev_priv) && \
2716 (INTEL_DEVID(dev_priv) & 0x00F0) == 0x0030)
7a58bad0 2717
c007fb4a 2718#define IS_ALPHA_SUPPORT(intel_info) ((intel_info)->is_alpha_support)
cae5852d 2719
ef712bb4
JN
2720#define SKL_REVID_A0 0x0
2721#define SKL_REVID_B0 0x1
2722#define SKL_REVID_C0 0x2
2723#define SKL_REVID_D0 0x3
2724#define SKL_REVID_E0 0x4
2725#define SKL_REVID_F0 0x5
4ba9c1f7
MK
2726#define SKL_REVID_G0 0x6
2727#define SKL_REVID_H0 0x7
ef712bb4 2728
e87a005d
JN
2729#define IS_SKL_REVID(p, since, until) (IS_SKYLAKE(p) && IS_REVID(p, since, until))
2730
ef712bb4 2731#define BXT_REVID_A0 0x0
fffda3f4 2732#define BXT_REVID_A1 0x1
ef712bb4 2733#define BXT_REVID_B0 0x3
a3f79ca6 2734#define BXT_REVID_B_LAST 0x8
ef712bb4 2735#define BXT_REVID_C0 0x9
6c74c87f 2736
e2d214ae
TU
2737#define IS_BXT_REVID(dev_priv, since, until) \
2738 (IS_BROXTON(dev_priv) && IS_REVID(dev_priv, since, until))
e87a005d 2739
c033a37c
MK
2740#define KBL_REVID_A0 0x0
2741#define KBL_REVID_B0 0x1
fe905819
MK
2742#define KBL_REVID_C0 0x2
2743#define KBL_REVID_D0 0x3
2744#define KBL_REVID_E0 0x4
c033a37c 2745
0853723b
TU
2746#define IS_KBL_REVID(dev_priv, since, until) \
2747 (IS_KABYLAKE(dev_priv) && IS_REVID(dev_priv, since, until))
c033a37c 2748
85436696
JB
2749/*
2750 * The genX designation typically refers to the render engine, so render
2751 * capability related checks should use IS_GEN, while display and other checks
2752 * have their own (e.g. HAS_PCH_SPLIT for ILK+ display, IS_foo for particular
2753 * chips, etc.).
2754 */
5db94019
TU
2755#define IS_GEN2(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(1)))
2756#define IS_GEN3(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(2)))
2757#define IS_GEN4(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(3)))
2758#define IS_GEN5(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(4)))
2759#define IS_GEN6(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(5)))
2760#define IS_GEN7(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(6)))
2761#define IS_GEN8(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(7)))
2762#define IS_GEN9(dev_priv) (!!((dev_priv)->info.gen_mask & BIT(8)))
cae5852d 2763
3e4274f8 2764#define IS_GEN9_LP(dev_priv) (IS_GEN9(dev_priv) && INTEL_INFO(dev_priv)->is_lp)
8727dc09 2765#define IS_LP(dev_priv) (INTEL_INFO(dev_priv)->is_lp)
3e4274f8 2766
a19d6ff2
TU
2767#define ENGINE_MASK(id) BIT(id)
2768#define RENDER_RING ENGINE_MASK(RCS)
2769#define BSD_RING ENGINE_MASK(VCS)
2770#define BLT_RING ENGINE_MASK(BCS)
2771#define VEBOX_RING ENGINE_MASK(VECS)
2772#define BSD2_RING ENGINE_MASK(VCS2)
2773#define ALL_ENGINES (~0)
2774
2775#define HAS_ENGINE(dev_priv, id) \
0031fb96 2776 (!!((dev_priv)->info.ring_mask & ENGINE_MASK(id)))
a19d6ff2
TU
2777
2778#define HAS_BSD(dev_priv) HAS_ENGINE(dev_priv, VCS)
2779#define HAS_BSD2(dev_priv) HAS_ENGINE(dev_priv, VCS2)
2780#define HAS_BLT(dev_priv) HAS_ENGINE(dev_priv, BCS)
2781#define HAS_VEBOX(dev_priv) HAS_ENGINE(dev_priv, VECS)
2782
0031fb96
TU
2783#define HAS_LLC(dev_priv) ((dev_priv)->info.has_llc)
2784#define HAS_SNOOP(dev_priv) ((dev_priv)->info.has_snoop)
2785#define HAS_EDRAM(dev_priv) (!!((dev_priv)->edram_cap & EDRAM_ENABLED))
8652744b
TU
2786#define HAS_WT(dev_priv) ((IS_HASWELL(dev_priv) || \
2787 IS_BROADWELL(dev_priv)) && HAS_EDRAM(dev_priv))
cae5852d 2788
0031fb96 2789#define HWS_NEEDS_PHYSICAL(dev_priv) ((dev_priv)->info.hws_needs_physical)
1d2a314c 2790
0031fb96
TU
2791#define HAS_HW_CONTEXTS(dev_priv) ((dev_priv)->info.has_hw_contexts)
2792#define HAS_LOGICAL_RING_CONTEXTS(dev_priv) \
2793 ((dev_priv)->info.has_logical_ring_contexts)
2794#define USES_PPGTT(dev_priv) (i915.enable_ppgtt)
2795#define USES_FULL_PPGTT(dev_priv) (i915.enable_ppgtt >= 2)
2796#define USES_FULL_48BIT_PPGTT(dev_priv) (i915.enable_ppgtt == 3)
2797
2798#define HAS_OVERLAY(dev_priv) ((dev_priv)->info.has_overlay)
2799#define OVERLAY_NEEDS_PHYSICAL(dev_priv) \
2800 ((dev_priv)->info.overlay_needs_physical)
cae5852d 2801
b45305fc 2802/* Early gen2 have a totally busted CS tlb and require pinned batches. */
2a307c2e 2803#define HAS_BROKEN_CS_TLB(dev_priv) (IS_I830(dev_priv) || IS_I845G(dev_priv))
06e668ac
MK
2804
2805/* WaRsDisableCoarsePowerGating:skl,bxt */
61251512
TU
2806#define NEEDS_WaRsDisableCoarsePowerGating(dev_priv) \
2807 (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1) || \
2808 IS_SKL_GT3(dev_priv) || \
2809 IS_SKL_GT4(dev_priv))
185c66e5 2810
4e6b788c
DV
2811/*
2812 * dp aux and gmbus irq on gen4 seems to be able to generate legacy interrupts
2813 * even when in MSI mode. This results in spurious interrupt warnings if the
2814 * legacy irq no. is shared with another device. The kernel then disables that
2815 * interrupt source and so prevents the other device from working properly.
2816 */
0031fb96
TU
2817#define HAS_AUX_IRQ(dev_priv) ((dev_priv)->info.gen >= 5)
2818#define HAS_GMBUS_IRQ(dev_priv) ((dev_priv)->info.has_gmbus_irq)
b45305fc 2819
cae5852d
ZN
2820/* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte
2821 * rows, which changed the alignment requirements and fence programming.
2822 */
50a0bc90
TU
2823#define HAS_128_BYTE_Y_TILING(dev_priv) (!IS_GEN2(dev_priv) && \
2824 !(IS_I915G(dev_priv) || \
2825 IS_I915GM(dev_priv)))
56b857a5
TU
2826#define SUPPORTS_TV(dev_priv) ((dev_priv)->info.supports_tv)
2827#define I915_HAS_HOTPLUG(dev_priv) ((dev_priv)->info.has_hotplug)
cae5852d 2828
56b857a5
TU
2829#define HAS_FW_BLC(dev_priv) (INTEL_GEN(dev_priv) > 2)
2830#define HAS_PIPE_CXSR(dev_priv) ((dev_priv)->info.has_pipe_cxsr)
2831#define HAS_FBC(dev_priv) ((dev_priv)->info.has_fbc)
cae5852d 2832
50a0bc90 2833#define HAS_IPS(dev_priv) (IS_HSW_ULT(dev_priv) || IS_BROADWELL(dev_priv))
f5adf94e 2834
56b857a5 2835#define HAS_DP_MST(dev_priv) ((dev_priv)->info.has_dp_mst)
0c9b3715 2836
56b857a5
TU
2837#define HAS_DDI(dev_priv) ((dev_priv)->info.has_ddi)
2838#define HAS_FPGA_DBG_UNCLAIMED(dev_priv) ((dev_priv)->info.has_fpga_dbg)
2839#define HAS_PSR(dev_priv) ((dev_priv)->info.has_psr)
2840#define HAS_RC6(dev_priv) ((dev_priv)->info.has_rc6)
2841#define HAS_RC6p(dev_priv) ((dev_priv)->info.has_rc6p)
affa9354 2842
56b857a5 2843#define HAS_CSR(dev_priv) ((dev_priv)->info.has_csr)
eb805623 2844
6772ffe0 2845#define HAS_RUNTIME_PM(dev_priv) ((dev_priv)->info.has_runtime_pm)
dfc5148f
JL
2846#define HAS_64BIT_RELOC(dev_priv) ((dev_priv)->info.has_64bit_reloc)
2847
1a3d1898
DG
2848/*
2849 * For now, anything with a GuC requires uCode loading, and then supports
2850 * command submission once loaded. But these are logically independent
2851 * properties, so we have separate macros to test them.
2852 */
4805fe82
TU
2853#define HAS_GUC(dev_priv) ((dev_priv)->info.has_guc)
2854#define HAS_GUC_UCODE(dev_priv) (HAS_GUC(dev_priv))
2855#define HAS_GUC_SCHED(dev_priv) (HAS_GUC(dev_priv))
33a732f4 2856
4805fe82 2857#define HAS_RESOURCE_STREAMER(dev_priv) ((dev_priv)->info.has_resource_streamer)
a9ed33ca 2858
4805fe82 2859#define HAS_POOLED_EU(dev_priv) ((dev_priv)->info.has_pooled_eu)
33e141ed 2860
17a303ec
PZ
2861#define INTEL_PCH_DEVICE_ID_MASK 0xff00
2862#define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00
2863#define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00
2864#define INTEL_PCH_PPT_DEVICE_ID_TYPE 0x1e00
2865#define INTEL_PCH_LPT_DEVICE_ID_TYPE 0x8c00
2866#define INTEL_PCH_LPT_LP_DEVICE_ID_TYPE 0x9c00
e7e7ea20
S
2867#define INTEL_PCH_SPT_DEVICE_ID_TYPE 0xA100
2868#define INTEL_PCH_SPT_LP_DEVICE_ID_TYPE 0x9D00
22dea0be 2869#define INTEL_PCH_KBP_DEVICE_ID_TYPE 0xA200
30c964a6 2870#define INTEL_PCH_P2X_DEVICE_ID_TYPE 0x7100
1844a66b 2871#define INTEL_PCH_P3X_DEVICE_ID_TYPE 0x7000
39bfcd52 2872#define INTEL_PCH_QEMU_DEVICE_ID_TYPE 0x2900 /* qemu q35 has 2918 */
17a303ec 2873
6e266956
TU
2874#define INTEL_PCH_TYPE(dev_priv) ((dev_priv)->pch_type)
2875#define HAS_PCH_KBP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_KBP)
2876#define HAS_PCH_SPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_SPT)
2877#define HAS_PCH_LPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_LPT)
4f8036a2
TU
2878#define HAS_PCH_LPT_LP(dev_priv) \
2879 ((dev_priv)->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE)
2880#define HAS_PCH_LPT_H(dev_priv) \
2881 ((dev_priv)->pch_id == INTEL_PCH_LPT_DEVICE_ID_TYPE)
6e266956
TU
2882#define HAS_PCH_CPT(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_CPT)
2883#define HAS_PCH_IBX(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_IBX)
2884#define HAS_PCH_NOP(dev_priv) (INTEL_PCH_TYPE(dev_priv) == PCH_NOP)
2885#define HAS_PCH_SPLIT(dev_priv) (INTEL_PCH_TYPE(dev_priv) != PCH_NONE)
cae5852d 2886
49cff963 2887#define HAS_GMCH_DISPLAY(dev_priv) ((dev_priv)->info.has_gmch_display)
5fafe292 2888
6389dd83
SS
2889#define HAS_LSPCON(dev_priv) (IS_GEN9(dev_priv))
2890
040d2baa 2891/* DPF == dynamic parity feature */
3c9192bc 2892#define HAS_L3_DPF(dev_priv) ((dev_priv)->info.has_l3_dpf)
50a0bc90
TU
2893#define NUM_L3_SLICES(dev_priv) (IS_HSW_GT3(dev_priv) ? \
2894 2 : HAS_L3_DPF(dev_priv))
e1ef7cc2 2895
c8735b0c 2896#define GT_FREQUENCY_MULTIPLIER 50
de43ae9d 2897#define GEN9_FREQ_SCALER 3
c8735b0c 2898
85ee17eb
PP
2899#define HAS_DECOUPLED_MMIO(dev_priv) (INTEL_INFO(dev_priv)->has_decoupled_mmio)
2900
05394f39
CW
2901#include "i915_trace.h"
2902
48f112fe
CW
2903static inline bool intel_scanout_needs_vtd_wa(struct drm_i915_private *dev_priv)
2904{
2905#ifdef CONFIG_INTEL_IOMMU
2906 if (INTEL_GEN(dev_priv) >= 6 && intel_iommu_gfx_mapped)
2907 return true;
2908#endif
2909 return false;
2910}
2911
c033666a 2912int intel_sanitize_enable_ppgtt(struct drm_i915_private *dev_priv,
351c3b53 2913 int enable_ppgtt);
0e4ca100 2914
39df9190
CW
2915bool intel_sanitize_semaphores(struct drm_i915_private *dev_priv, int value);
2916
0673ad47 2917/* i915_drv.c */
d15d7538
ID
2918void __printf(3, 4)
2919__i915_printk(struct drm_i915_private *dev_priv, const char *level,
2920 const char *fmt, ...);
2921
2922#define i915_report_error(dev_priv, fmt, ...) \
2923 __i915_printk(dev_priv, KERN_ERR, fmt, ##__VA_ARGS__)
2924
c43b5634 2925#ifdef CONFIG_COMPAT
0d6aa60b
DA
2926extern long i915_compat_ioctl(struct file *filp, unsigned int cmd,
2927 unsigned long arg);
55edf41b
JN
2928#else
2929#define i915_compat_ioctl NULL
c43b5634 2930#endif
efab0698
JN
2931extern const struct dev_pm_ops i915_pm_ops;
2932
2933extern int i915_driver_load(struct pci_dev *pdev,
2934 const struct pci_device_id *ent);
2935extern void i915_driver_unload(struct drm_device *dev);
dc97997a
CW
2936extern int intel_gpu_reset(struct drm_i915_private *dev_priv, u32 engine_mask);
2937extern bool intel_has_gpu_reset(struct drm_i915_private *dev_priv);
780f262a 2938extern void i915_reset(struct drm_i915_private *dev_priv);
6b332fa2 2939extern int intel_guc_reset(struct drm_i915_private *dev_priv);
fc0768ce 2940extern void intel_engine_init_hangcheck(struct intel_engine_cs *engine);
3ac168a7 2941extern void intel_hangcheck_init(struct drm_i915_private *dev_priv);
7648fa99
JB
2942extern unsigned long i915_chipset_val(struct drm_i915_private *dev_priv);
2943extern unsigned long i915_mch_val(struct drm_i915_private *dev_priv);
2944extern unsigned long i915_gfx_val(struct drm_i915_private *dev_priv);
2945extern void i915_update_gfx_val(struct drm_i915_private *dev_priv);
650ad970 2946int vlv_force_gfx_clock(struct drm_i915_private *dev_priv, bool on);
7648fa99 2947
77913b39 2948/* intel_hotplug.c */
91d14251
TU
2949void intel_hpd_irq_handler(struct drm_i915_private *dev_priv,
2950 u32 pin_mask, u32 long_mask);
77913b39
JN
2951void intel_hpd_init(struct drm_i915_private *dev_priv);
2952void intel_hpd_init_work(struct drm_i915_private *dev_priv);
2953void intel_hpd_cancel_work(struct drm_i915_private *dev_priv);
cc24fcdc 2954bool intel_hpd_pin_to_port(enum hpd_pin pin, enum port *port);
b236d7c8
L
2955bool intel_hpd_disable(struct drm_i915_private *dev_priv, enum hpd_pin pin);
2956void intel_hpd_enable(struct drm_i915_private *dev_priv, enum hpd_pin pin);
77913b39 2957
1da177e4 2958/* i915_irq.c */
26a02b8f
CW
2959static inline void i915_queue_hangcheck(struct drm_i915_private *dev_priv)
2960{
2961 unsigned long delay;
2962
2963 if (unlikely(!i915.enable_hangcheck))
2964 return;
2965
2966 /* Don't continually defer the hangcheck so that it is always run at
2967 * least once after work has been scheduled on any ring. Otherwise,
2968 * we will ignore a hung ring if a second ring is kept busy.
2969 */
2970
2971 delay = round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES);
2972 queue_delayed_work(system_long_wq,
2973 &dev_priv->gpu_error.hangcheck_work, delay);
2974}
2975
58174462 2976__printf(3, 4)
c033666a
CW
2977void i915_handle_error(struct drm_i915_private *dev_priv,
2978 u32 engine_mask,
58174462 2979 const char *fmt, ...);
1da177e4 2980
b963291c 2981extern void intel_irq_init(struct drm_i915_private *dev_priv);
2aeb7d3a
DV
2982int intel_irq_install(struct drm_i915_private *dev_priv);
2983void intel_irq_uninstall(struct drm_i915_private *dev_priv);
907b28c5 2984
dc97997a
CW
2985extern void intel_uncore_sanitize(struct drm_i915_private *dev_priv);
2986extern void intel_uncore_early_sanitize(struct drm_i915_private *dev_priv,
10018603 2987 bool restore_forcewake);
dc97997a 2988extern void intel_uncore_init(struct drm_i915_private *dev_priv);
fc97618b 2989extern bool intel_uncore_unclaimed_mmio(struct drm_i915_private *dev_priv);
bc3b9346 2990extern bool intel_uncore_arm_unclaimed_mmio_detection(struct drm_i915_private *dev_priv);
dc97997a
CW
2991extern void intel_uncore_fini(struct drm_i915_private *dev_priv);
2992extern void intel_uncore_forcewake_reset(struct drm_i915_private *dev_priv,
2993 bool restore);
48c1026a 2994const char *intel_uncore_forcewake_domain_to_str(const enum forcewake_domain_id id);
59bad947 2995void intel_uncore_forcewake_get(struct drm_i915_private *dev_priv,
48c1026a 2996 enum forcewake_domains domains);
59bad947 2997void intel_uncore_forcewake_put(struct drm_i915_private *dev_priv,
48c1026a 2998 enum forcewake_domains domains);
a6111f7b
CW
2999/* Like above but the caller must manage the uncore.lock itself.
3000 * Must be used with I915_READ_FW and friends.
3001 */
3002void intel_uncore_forcewake_get__locked(struct drm_i915_private *dev_priv,
3003 enum forcewake_domains domains);
3004void intel_uncore_forcewake_put__locked(struct drm_i915_private *dev_priv,
3005 enum forcewake_domains domains);
3accaf7e
MK
3006u64 intel_uncore_edram_size(struct drm_i915_private *dev_priv);
3007
59bad947 3008void assert_forcewakes_inactive(struct drm_i915_private *dev_priv);
0ad35fed 3009
1758b90e
CW
3010int intel_wait_for_register(struct drm_i915_private *dev_priv,
3011 i915_reg_t reg,
3012 const u32 mask,
3013 const u32 value,
3014 const unsigned long timeout_ms);
3015int intel_wait_for_register_fw(struct drm_i915_private *dev_priv,
3016 i915_reg_t reg,
3017 const u32 mask,
3018 const u32 value,
3019 const unsigned long timeout_ms);
3020
0ad35fed
ZW
3021static inline bool intel_gvt_active(struct drm_i915_private *dev_priv)
3022{
feddf6e8 3023 return dev_priv->gvt;
0ad35fed
ZW
3024}
3025
c033666a 3026static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv)
cf9d2890 3027{
c033666a 3028 return dev_priv->vgpu.active;
cf9d2890 3029}
b1f14ad0 3030
7c463586 3031void
50227e1c 3032i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
755e9019 3033 u32 status_mask);
7c463586
KP
3034
3035void
50227e1c 3036i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
755e9019 3037 u32 status_mask);
7c463586 3038
f8b79e58
ID
3039void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv);
3040void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv);
0706f17c
EE
3041void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
3042 uint32_t mask,
3043 uint32_t bits);
fbdedaea
VS
3044void ilk_update_display_irq(struct drm_i915_private *dev_priv,
3045 uint32_t interrupt_mask,
3046 uint32_t enabled_irq_mask);
3047static inline void
3048ilk_enable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
3049{
3050 ilk_update_display_irq(dev_priv, bits, bits);
3051}
3052static inline void
3053ilk_disable_display_irq(struct drm_i915_private *dev_priv, uint32_t bits)
3054{
3055 ilk_update_display_irq(dev_priv, bits, 0);
3056}
013d3752
VS
3057void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
3058 enum pipe pipe,
3059 uint32_t interrupt_mask,
3060 uint32_t enabled_irq_mask);
3061static inline void bdw_enable_pipe_irq(struct drm_i915_private *dev_priv,
3062 enum pipe pipe, uint32_t bits)
3063{
3064 bdw_update_pipe_irq(dev_priv, pipe, bits, bits);
3065}
3066static inline void bdw_disable_pipe_irq(struct drm_i915_private *dev_priv,
3067 enum pipe pipe, uint32_t bits)
3068{
3069 bdw_update_pipe_irq(dev_priv, pipe, bits, 0);
3070}
47339cd9
DV
3071void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
3072 uint32_t interrupt_mask,
3073 uint32_t enabled_irq_mask);
14443261
VS
3074static inline void
3075ibx_enable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
3076{
3077 ibx_display_interrupt_update(dev_priv, bits, bits);
3078}
3079static inline void
3080ibx_disable_display_interrupt(struct drm_i915_private *dev_priv, uint32_t bits)
3081{
3082 ibx_display_interrupt_update(dev_priv, bits, 0);
3083}
3084
673a394b 3085/* i915_gem.c */
673a394b
EA
3086int i915_gem_create_ioctl(struct drm_device *dev, void *data,
3087 struct drm_file *file_priv);
3088int i915_gem_pread_ioctl(struct drm_device *dev, void *data,
3089 struct drm_file *file_priv);
3090int i915_gem_pwrite_ioctl(struct drm_device *dev, void *data,
3091 struct drm_file *file_priv);
3092int i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
3093 struct drm_file *file_priv);
de151cf6
JB
3094int i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data,
3095 struct drm_file *file_priv);
673a394b
EA
3096int i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
3097 struct drm_file *file_priv);
3098int i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data,
3099 struct drm_file *file_priv);
3100int i915_gem_execbuffer(struct drm_device *dev, void *data,
3101 struct drm_file *file_priv);
76446cac
JB
3102int i915_gem_execbuffer2(struct drm_device *dev, void *data,
3103 struct drm_file *file_priv);
673a394b
EA
3104int i915_gem_busy_ioctl(struct drm_device *dev, void *data,
3105 struct drm_file *file_priv);
199adf40
BW
3106int i915_gem_get_caching_ioctl(struct drm_device *dev, void *data,
3107 struct drm_file *file);
3108int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
3109 struct drm_file *file);
673a394b
EA
3110int i915_gem_throttle_ioctl(struct drm_device *dev, void *data,
3111 struct drm_file *file_priv);
3ef94daa
CW
3112int i915_gem_madvise_ioctl(struct drm_device *dev, void *data,
3113 struct drm_file *file_priv);
673a394b
EA
3114int i915_gem_set_tiling(struct drm_device *dev, void *data,
3115 struct drm_file *file_priv);
3116int i915_gem_get_tiling(struct drm_device *dev, void *data,
3117 struct drm_file *file_priv);
72778cb2 3118void i915_gem_init_userptr(struct drm_i915_private *dev_priv);
5cc9ed4b
CW
3119int i915_gem_userptr_ioctl(struct drm_device *dev, void *data,
3120 struct drm_file *file);
5a125c3c
EA
3121int i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
3122 struct drm_file *file_priv);
23ba4fd0
BW
3123int i915_gem_wait_ioctl(struct drm_device *dev, void *data,
3124 struct drm_file *file_priv);
cb15d9f8
TU
3125int i915_gem_load_init(struct drm_i915_private *dev_priv);
3126void i915_gem_load_cleanup(struct drm_i915_private *dev_priv);
40ae4e16 3127void i915_gem_load_init_fences(struct drm_i915_private *dev_priv);
6a800eab 3128int i915_gem_freeze(struct drm_i915_private *dev_priv);
461fb99c
CW
3129int i915_gem_freeze_late(struct drm_i915_private *dev_priv);
3130
187685cb 3131void *i915_gem_object_alloc(struct drm_i915_private *dev_priv);
42dcedd4 3132void i915_gem_object_free(struct drm_i915_gem_object *obj);
37e680a1
CW
3133void i915_gem_object_init(struct drm_i915_gem_object *obj,
3134 const struct drm_i915_gem_object_ops *ops);
12d79d78
TU
3135struct drm_i915_gem_object *
3136i915_gem_object_create(struct drm_i915_private *dev_priv, u64 size);
3137struct drm_i915_gem_object *
3138i915_gem_object_create_from_data(struct drm_i915_private *dev_priv,
3139 const void *data, size_t size);
b1f788c6 3140void i915_gem_close_object(struct drm_gem_object *gem, struct drm_file *file);
673a394b 3141void i915_gem_free_object(struct drm_gem_object *obj);
42dcedd4 3142
bdeb9785
CW
3143static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915)
3144{
3145 /* A single pass should suffice to release all the freed objects (along
3146 * most call paths) , but be a little more paranoid in that freeing
3147 * the objects does take a little amount of time, during which the rcu
3148 * callbacks could have added new objects into the freed list, and
3149 * armed the work again.
3150 */
3151 do {
3152 rcu_barrier();
3153 } while (flush_work(&i915->mm.free_work));
3154}
3155
058d88c4 3156struct i915_vma * __must_check
ec7adb6e
JL
3157i915_gem_object_ggtt_pin(struct drm_i915_gem_object *obj,
3158 const struct i915_ggtt_view *view,
91b2db6f 3159 u64 size,
2ffffd0f
CW
3160 u64 alignment,
3161 u64 flags);
fe14d5f4 3162
aa653a68 3163int i915_gem_object_unbind(struct drm_i915_gem_object *obj);
05394f39 3164void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
f787a5f5 3165
7c108fd8
CW
3166void i915_gem_runtime_suspend(struct drm_i915_private *dev_priv);
3167
a4f5ea64 3168static inline int __sg_page_count(const struct scatterlist *sg)
9da3da66 3169{
ee286370
CW
3170 return sg->length >> PAGE_SHIFT;
3171}
67d5a50c 3172
96d77634
CW
3173struct scatterlist *
3174i915_gem_object_get_sg(struct drm_i915_gem_object *obj,
3175 unsigned int n, unsigned int *offset);
341be1cd 3176
96d77634
CW
3177struct page *
3178i915_gem_object_get_page(struct drm_i915_gem_object *obj,
3179 unsigned int n);
67d5a50c 3180
96d77634
CW
3181struct page *
3182i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj,
3183 unsigned int n);
67d5a50c 3184
96d77634
CW
3185dma_addr_t
3186i915_gem_object_get_dma_address(struct drm_i915_gem_object *obj,
3187 unsigned long n);
ee286370 3188
03ac84f1
CW
3189void __i915_gem_object_set_pages(struct drm_i915_gem_object *obj,
3190 struct sg_table *pages);
a4f5ea64
CW
3191int __i915_gem_object_get_pages(struct drm_i915_gem_object *obj);
3192
3193static inline int __must_check
3194i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
3195{
1233e2db 3196 might_lock(&obj->mm.lock);
a4f5ea64 3197
1233e2db 3198 if (atomic_inc_not_zero(&obj->mm.pages_pin_count))
a4f5ea64
CW
3199 return 0;
3200
3201 return __i915_gem_object_get_pages(obj);
3202}
3203
3204static inline void
3205__i915_gem_object_pin_pages(struct drm_i915_gem_object *obj)
a5570178 3206{
a4f5ea64
CW
3207 GEM_BUG_ON(!obj->mm.pages);
3208
1233e2db 3209 atomic_inc(&obj->mm.pages_pin_count);
a4f5ea64
CW
3210}
3211
3212static inline bool
3213i915_gem_object_has_pinned_pages(struct drm_i915_gem_object *obj)
3214{
1233e2db 3215 return atomic_read(&obj->mm.pages_pin_count);
a4f5ea64
CW
3216}
3217
3218static inline void
3219__i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
3220{
a4f5ea64
CW
3221 GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj));
3222 GEM_BUG_ON(!obj->mm.pages);
3223
1233e2db 3224 atomic_dec(&obj->mm.pages_pin_count);
a5570178 3225}
0a798eb9 3226
1233e2db
CW
3227static inline void
3228i915_gem_object_unpin_pages(struct drm_i915_gem_object *obj)
a5570178 3229{
a4f5ea64 3230 __i915_gem_object_unpin_pages(obj);
a5570178
CW
3231}
3232
548625ee
CW
3233enum i915_mm_subclass { /* lockdep subclass for obj->mm.lock */
3234 I915_MM_NORMAL = 0,
3235 I915_MM_SHRINKER
3236};
3237
3238void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj,
3239 enum i915_mm_subclass subclass);
03ac84f1 3240void __i915_gem_object_invalidate(struct drm_i915_gem_object *obj);
a4f5ea64 3241
d31d7cb1
CW
3242enum i915_map_type {
3243 I915_MAP_WB = 0,
3244 I915_MAP_WC,
3245};
3246
0a798eb9
CW
3247/**
3248 * i915_gem_object_pin_map - return a contiguous mapping of the entire object
a73c7a44
CW
3249 * @obj: the object to map into kernel address space
3250 * @type: the type of mapping, used to select pgprot_t
0a798eb9
CW
3251 *
3252 * Calls i915_gem_object_pin_pages() to prevent reaping of the object's
3253 * pages and then returns a contiguous mapping of the backing storage into
d31d7cb1
CW
3254 * the kernel address space. Based on the @type of mapping, the PTE will be
3255 * set to either WriteBack or WriteCombine (via pgprot_t).
0a798eb9 3256 *
1233e2db
CW
3257 * The caller is responsible for calling i915_gem_object_unpin_map() when the
3258 * mapping is no longer required.
0a798eb9 3259 *
8305216f
DG
3260 * Returns the pointer through which to access the mapped object, or an
3261 * ERR_PTR() on error.
0a798eb9 3262 */
d31d7cb1
CW
3263void *__must_check i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
3264 enum i915_map_type type);
0a798eb9
CW
3265
3266/**
3267 * i915_gem_object_unpin_map - releases an earlier mapping
a73c7a44 3268 * @obj: the object to unmap
0a798eb9
CW
3269 *
3270 * After pinning the object and mapping its pages, once you are finished
3271 * with your access, call i915_gem_object_unpin_map() to release the pin
3272 * upon the mapping. Once the pin count reaches zero, that mapping may be
3273 * removed.
0a798eb9
CW
3274 */
3275static inline void i915_gem_object_unpin_map(struct drm_i915_gem_object *obj)
3276{
0a798eb9
CW
3277 i915_gem_object_unpin_pages(obj);
3278}
3279
43394c7d
CW
3280int i915_gem_obj_prepare_shmem_read(struct drm_i915_gem_object *obj,
3281 unsigned int *needs_clflush);
3282int i915_gem_obj_prepare_shmem_write(struct drm_i915_gem_object *obj,
3283 unsigned int *needs_clflush);
3284#define CLFLUSH_BEFORE 0x1
3285#define CLFLUSH_AFTER 0x2
3286#define CLFLUSH_FLAGS (CLFLUSH_BEFORE | CLFLUSH_AFTER)
3287
3288static inline void
3289i915_gem_obj_finish_shmem_access(struct drm_i915_gem_object *obj)
3290{
3291 i915_gem_object_unpin_pages(obj);
3292}
3293
54cf91dc 3294int __must_check i915_mutex_lock_interruptible(struct drm_device *dev);
e2d05a8b 3295void i915_vma_move_to_active(struct i915_vma *vma,
5cf3d280
CW
3296 struct drm_i915_gem_request *req,
3297 unsigned int flags);
ff72145b
DA
3298int i915_gem_dumb_create(struct drm_file *file_priv,
3299 struct drm_device *dev,
3300 struct drm_mode_create_dumb *args);
da6b51d0
DA
3301int i915_gem_mmap_gtt(struct drm_file *file_priv, struct drm_device *dev,
3302 uint32_t handle, uint64_t *offset);
4cc69075 3303int i915_gem_mmap_gtt_version(void);
85d1225e
DG
3304
3305void i915_gem_track_fb(struct drm_i915_gem_object *old,
3306 struct drm_i915_gem_object *new,
3307 unsigned frontbuffer_bits);
3308
73cb9701 3309int __must_check i915_gem_set_global_seqno(struct drm_device *dev, u32 seqno);
1690e1eb 3310
8d9fc7fd 3311struct drm_i915_gem_request *
0bc40be8 3312i915_gem_find_active_request(struct intel_engine_cs *engine);
8d9fc7fd 3313
67d97da3 3314void i915_gem_retire_requests(struct drm_i915_private *dev_priv);
84c33a64 3315
1f83fee0
DV
3316static inline bool i915_reset_in_progress(struct i915_gpu_error *error)
3317{
8af29b0c 3318 return unlikely(test_bit(I915_RESET_IN_PROGRESS, &error->flags));
c19ae989
CW
3319}
3320
8af29b0c 3321static inline bool i915_terminally_wedged(struct i915_gpu_error *error)
c19ae989 3322{
8af29b0c 3323 return unlikely(test_bit(I915_WEDGED, &error->flags));
1f83fee0
DV
3324}
3325
8af29b0c 3326static inline bool i915_reset_in_progress_or_wedged(struct i915_gpu_error *error)
1f83fee0 3327{
8af29b0c 3328 return i915_reset_in_progress(error) | i915_terminally_wedged(error);
2ac0f450
MK
3329}
3330
3331static inline u32 i915_reset_count(struct i915_gpu_error *error)
3332{
8af29b0c 3333 return READ_ONCE(error->reset_count);
1f83fee0 3334}
a71d8d94 3335
821ed7df
CW
3336void i915_gem_reset(struct drm_i915_private *dev_priv);
3337void i915_gem_set_wedged(struct drm_i915_private *dev_priv);
d0da48cf 3338void i915_gem_clflush_object(struct drm_i915_gem_object *obj, bool force);
bf9e8429
TU
3339int __must_check i915_gem_init(struct drm_i915_private *dev_priv);
3340int __must_check i915_gem_init_hw(struct drm_i915_private *dev_priv);
c6be607a 3341void i915_gem_init_swizzling(struct drm_i915_private *dev_priv);
cb15d9f8 3342void i915_gem_cleanup_engines(struct drm_i915_private *dev_priv);
dcff85c8 3343int __must_check i915_gem_wait_for_idle(struct drm_i915_private *dev_priv,
ea746f36 3344 unsigned int flags);
bf9e8429
TU
3345int __must_check i915_gem_suspend(struct drm_i915_private *dev_priv);
3346void i915_gem_resume(struct drm_i915_private *dev_priv);
de151cf6 3347int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
e95433c7
CW
3348int i915_gem_object_wait(struct drm_i915_gem_object *obj,
3349 unsigned int flags,
3350 long timeout,
3351 struct intel_rps_client *rps);
6b5e90f5
CW
3352int i915_gem_object_wait_priority(struct drm_i915_gem_object *obj,
3353 unsigned int flags,
3354 int priority);
3355#define I915_PRIORITY_DISPLAY I915_PRIORITY_MAX
3356
2e2f351d 3357int __must_check
2021746e
CW
3358i915_gem_object_set_to_gtt_domain(struct drm_i915_gem_object *obj,
3359 bool write);
3360int __must_check
dabdfe02 3361i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj, bool write);
058d88c4 3362struct i915_vma * __must_check
2da3b9b9
CW
3363i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
3364 u32 alignment,
e6617330 3365 const struct i915_ggtt_view *view);
058d88c4 3366void i915_gem_object_unpin_from_display_plane(struct i915_vma *vma);
00731155 3367int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj,
6eeefaf3 3368 int align);
b29c19b6 3369int i915_gem_open(struct drm_device *dev, struct drm_file *file);
05394f39 3370void i915_gem_release(struct drm_device *dev, struct drm_file *file);
673a394b 3371
a9f1481f
CW
3372u64 i915_gem_get_ggtt_size(struct drm_i915_private *dev_priv, u64 size,
3373 int tiling_mode);
3374u64 i915_gem_get_ggtt_alignment(struct drm_i915_private *dev_priv, u64 size,
ad1a7d20 3375 int tiling_mode, bool fenced);
467cffba 3376
e4ffd173
CW
3377int i915_gem_object_set_cache_level(struct drm_i915_gem_object *obj,
3378 enum i915_cache_level cache_level);
3379
1286ff73
DV
3380struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
3381 struct dma_buf *dma_buf);
3382
3383struct dma_buf *i915_gem_prime_export(struct drm_device *dev,
3384 struct drm_gem_object *gem_obj, int flags);
3385
fe14d5f4 3386struct i915_vma *
ec7adb6e 3387i915_gem_obj_to_vma(struct drm_i915_gem_object *obj,
058d88c4
CW
3388 struct i915_address_space *vm,
3389 const struct i915_ggtt_view *view);
fe14d5f4 3390
accfef2e
BW
3391struct i915_vma *
3392i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj,
058d88c4
CW
3393 struct i915_address_space *vm,
3394 const struct i915_ggtt_view *view);
5c2abbea 3395
841cd773
DV
3396static inline struct i915_hw_ppgtt *
3397i915_vm_to_ppgtt(struct i915_address_space *vm)
3398{
841cd773
DV
3399 return container_of(vm, struct i915_hw_ppgtt, base);
3400}
3401
058d88c4
CW
3402static inline struct i915_vma *
3403i915_gem_object_to_ggtt(struct drm_i915_gem_object *obj,
3404 const struct i915_ggtt_view *view)
a70a3148 3405{
058d88c4 3406 return i915_gem_obj_to_vma(obj, &to_i915(obj->base.dev)->ggtt.base, view);
a70a3148
BW
3407}
3408
058d88c4
CW
3409static inline unsigned long
3410i915_gem_object_ggtt_offset(struct drm_i915_gem_object *o,
3411 const struct i915_ggtt_view *view)
e6617330 3412{
bde13ebd 3413 return i915_ggtt_offset(i915_gem_object_to_ggtt(o, view));
e6617330 3414}
b287110e 3415
b42fe9ca 3416/* i915_gem_fence_reg.c */
49ef5294
CW
3417int __must_check i915_vma_get_fence(struct i915_vma *vma);
3418int __must_check i915_vma_put_fence(struct i915_vma *vma);
3419
4362f4f6 3420void i915_gem_restore_fences(struct drm_i915_private *dev_priv);
41a36b73 3421
4362f4f6 3422void i915_gem_detect_bit_6_swizzle(struct drm_i915_private *dev_priv);
03ac84f1
CW
3423void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj,
3424 struct sg_table *pages);
3425void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj,
3426 struct sg_table *pages);
7f96ecaf 3427
ca585b5d
CW
3428static inline struct i915_gem_context *
3429i915_gem_context_lookup(struct drm_i915_file_private *file_priv, u32 id)
3430{
3431 struct i915_gem_context *ctx;
3432
091387c1 3433 lockdep_assert_held(&file_priv->dev_priv->drm.struct_mutex);
ca585b5d
CW
3434
3435 ctx = idr_find(&file_priv->context_idr, id);
3436 if (!ctx)
3437 return ERR_PTR(-ENOENT);
3438
3439 return ctx;
3440}
3441
9a6feaf0
CW
3442static inline struct i915_gem_context *
3443i915_gem_context_get(struct i915_gem_context *ctx)
dce3271b 3444{
691e6415 3445 kref_get(&ctx->ref);
9a6feaf0 3446 return ctx;
dce3271b
MK
3447}
3448
9a6feaf0 3449static inline void i915_gem_context_put(struct i915_gem_context *ctx)
dce3271b 3450{
091387c1 3451 lockdep_assert_held(&ctx->i915->drm.struct_mutex);
691e6415 3452 kref_put(&ctx->ref, i915_gem_context_free);
dce3271b
MK
3453}
3454
69df05e1
CW
3455static inline void i915_gem_context_put_unlocked(struct i915_gem_context *ctx)
3456{
bf51997c
CW
3457 struct mutex *lock = &ctx->i915->drm.struct_mutex;
3458
3459 if (kref_put_mutex(&ctx->ref, i915_gem_context_free, lock))
3460 mutex_unlock(lock);
69df05e1
CW
3461}
3462
80b204bc
CW
3463static inline struct intel_timeline *
3464i915_gem_context_lookup_timeline(struct i915_gem_context *ctx,
3465 struct intel_engine_cs *engine)
3466{
3467 struct i915_address_space *vm;
3468
3469 vm = ctx->ppgtt ? &ctx->ppgtt->base : &ctx->i915->ggtt.base;
3470 return &vm->timeline.engine[engine->id];
3471}
3472
eec688e1
RB
3473int i915_perf_open_ioctl(struct drm_device *dev, void *data,
3474 struct drm_file *file);
3475
679845ed 3476/* i915_gem_evict.c */
e522ac23 3477int __must_check i915_gem_evict_something(struct i915_address_space *vm,
2ffffd0f 3478 u64 min_size, u64 alignment,
679845ed 3479 unsigned cache_level,
2ffffd0f 3480 u64 start, u64 end,
1ec9e26d 3481 unsigned flags);
172ae5b4
CW
3482int __must_check i915_gem_evict_for_vma(struct i915_vma *vma,
3483 unsigned int flags);
679845ed 3484int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
1d2a314c 3485
0260c420 3486/* belongs in i915_gem_gtt.h */
c033666a 3487static inline void i915_gem_chipset_flush(struct drm_i915_private *dev_priv)
e76e9aeb 3488{
600f4368 3489 wmb();
c033666a 3490 if (INTEL_GEN(dev_priv) < 6)
e76e9aeb
BW
3491 intel_gtt_chipset_flush();
3492}
246cbfb5 3493
9797fbfb 3494/* i915_gem_stolen.c */
d713fd49
PZ
3495int i915_gem_stolen_insert_node(struct drm_i915_private *dev_priv,
3496 struct drm_mm_node *node, u64 size,
3497 unsigned alignment);
a9da512b
PZ
3498int i915_gem_stolen_insert_node_in_range(struct drm_i915_private *dev_priv,
3499 struct drm_mm_node *node, u64 size,
3500 unsigned alignment, u64 start,
3501 u64 end);
d713fd49
PZ
3502void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv,
3503 struct drm_mm_node *node);
7ace3d30 3504int i915_gem_init_stolen(struct drm_i915_private *dev_priv);
9797fbfb 3505void i915_gem_cleanup_stolen(struct drm_device *dev);
0104fdbb 3506struct drm_i915_gem_object *
187685cb 3507i915_gem_object_create_stolen(struct drm_i915_private *dev_priv, u32 size);
866d12b4 3508struct drm_i915_gem_object *
187685cb 3509i915_gem_object_create_stolen_for_preallocated(struct drm_i915_private *dev_priv,
866d12b4
CW
3510 u32 stolen_offset,
3511 u32 gtt_offset,
3512 u32 size);
9797fbfb 3513
920cf419
CW
3514/* i915_gem_internal.c */
3515struct drm_i915_gem_object *
3516i915_gem_object_create_internal(struct drm_i915_private *dev_priv,
3517 unsigned int size);
3518
be6a0376
DV
3519/* i915_gem_shrinker.c */
3520unsigned long i915_gem_shrink(struct drm_i915_private *dev_priv,
14387540 3521 unsigned long target,
be6a0376
DV
3522 unsigned flags);
3523#define I915_SHRINK_PURGEABLE 0x1
3524#define I915_SHRINK_UNBOUND 0x2
3525#define I915_SHRINK_BOUND 0x4
5763ff04 3526#define I915_SHRINK_ACTIVE 0x8
eae2c43b 3527#define I915_SHRINK_VMAPS 0x10
be6a0376
DV
3528unsigned long i915_gem_shrink_all(struct drm_i915_private *dev_priv);
3529void i915_gem_shrinker_init(struct drm_i915_private *dev_priv);
a8a40589 3530void i915_gem_shrinker_cleanup(struct drm_i915_private *dev_priv);
be6a0376
DV
3531
3532
673a394b 3533/* i915_gem_tiling.c */
2c1792a1 3534static inline bool i915_gem_object_needs_bit17_swizzle(struct drm_i915_gem_object *obj)
e9b73c67 3535{
091387c1 3536 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
e9b73c67
CW
3537
3538 return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 &&
3e510a8e 3539 i915_gem_object_is_tiled(obj);
e9b73c67
CW
3540}
3541
2017263e 3542/* i915_debugfs.c */
f8c168fa 3543#ifdef CONFIG_DEBUG_FS
1dac891c
CW
3544int i915_debugfs_register(struct drm_i915_private *dev_priv);
3545void i915_debugfs_unregister(struct drm_i915_private *dev_priv);
249e87de 3546int i915_debugfs_connector_add(struct drm_connector *connector);
36cdd013 3547void intel_display_crc_init(struct drm_i915_private *dev_priv);
07144428 3548#else
8d35acba
CW
3549static inline int i915_debugfs_register(struct drm_i915_private *dev_priv) {return 0;}
3550static inline void i915_debugfs_unregister(struct drm_i915_private *dev_priv) {}
101057fa
DV
3551static inline int i915_debugfs_connector_add(struct drm_connector *connector)
3552{ return 0; }
ce5e2ac1 3553static inline void intel_display_crc_init(struct drm_i915_private *dev_priv) {}
07144428 3554#endif
84734a04
MK
3555
3556/* i915_gpu_error.c */
98a2f411
CW
3557#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
3558
edc3d884
MK
3559__printf(2, 3)
3560void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
fc16b48b
MK
3561int i915_error_state_to_str(struct drm_i915_error_state_buf *estr,
3562 const struct i915_error_state_file_priv *error);
4dc955f7 3563int i915_error_state_buf_init(struct drm_i915_error_state_buf *eb,
0a4cd7c8 3564 struct drm_i915_private *i915,
4dc955f7
MK
3565 size_t count, loff_t pos);
3566static inline void i915_error_state_buf_release(
3567 struct drm_i915_error_state_buf *eb)
3568{
3569 kfree(eb->buf);
3570}
c033666a
CW
3571void i915_capture_error_state(struct drm_i915_private *dev_priv,
3572 u32 engine_mask,
58174462 3573 const char *error_msg);
84734a04
MK
3574void i915_error_state_get(struct drm_device *dev,
3575 struct i915_error_state_file_priv *error_priv);
3576void i915_error_state_put(struct i915_error_state_file_priv *error_priv);
12ff05e7 3577void i915_destroy_error_state(struct drm_i915_private *dev_priv);
84734a04 3578
98a2f411
CW
3579#else
3580
3581static inline void i915_capture_error_state(struct drm_i915_private *dev_priv,
3582 u32 engine_mask,
3583 const char *error_msg)
3584{
3585}
3586
12ff05e7 3587static inline void i915_destroy_error_state(struct drm_i915_private *dev_priv)
98a2f411
CW
3588{
3589}
3590
3591#endif
3592
0a4cd7c8 3593const char *i915_cache_level_str(struct drm_i915_private *i915, int type);
2017263e 3594
351e3db2 3595/* i915_cmd_parser.c */
1ca3712c 3596int i915_cmd_parser_get_version(struct drm_i915_private *dev_priv);
7756e454 3597void intel_engine_init_cmd_parser(struct intel_engine_cs *engine);
33a051a5 3598void intel_engine_cleanup_cmd_parser(struct intel_engine_cs *engine);
33a051a5
CW
3599int intel_engine_cmd_parser(struct intel_engine_cs *engine,
3600 struct drm_i915_gem_object *batch_obj,
3601 struct drm_i915_gem_object *shadow_batch_obj,
3602 u32 batch_start_offset,
3603 u32 batch_len,
3604 bool is_master);
351e3db2 3605
eec688e1
RB
3606/* i915_perf.c */
3607extern void i915_perf_init(struct drm_i915_private *dev_priv);
3608extern void i915_perf_fini(struct drm_i915_private *dev_priv);
442b8c06
RB
3609extern void i915_perf_register(struct drm_i915_private *dev_priv);
3610extern void i915_perf_unregister(struct drm_i915_private *dev_priv);
eec688e1 3611
317c35d1 3612/* i915_suspend.c */
af6dc742
TU
3613extern int i915_save_state(struct drm_i915_private *dev_priv);
3614extern int i915_restore_state(struct drm_i915_private *dev_priv);
0a3e67a4 3615
0136db58 3616/* i915_sysfs.c */
694c2828
DW
3617void i915_setup_sysfs(struct drm_i915_private *dev_priv);
3618void i915_teardown_sysfs(struct drm_i915_private *dev_priv);
0136db58 3619
f899fc64 3620/* intel_i2c.c */
40196446
TU
3621extern int intel_setup_gmbus(struct drm_i915_private *dev_priv);
3622extern void intel_teardown_gmbus(struct drm_i915_private *dev_priv);
88ac7939
JN
3623extern bool intel_gmbus_is_valid_pin(struct drm_i915_private *dev_priv,
3624 unsigned int pin);
3bd7d909 3625
0184df46
JN
3626extern struct i2c_adapter *
3627intel_gmbus_get_adapter(struct drm_i915_private *dev_priv, unsigned int pin);
e957d772
CW
3628extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
3629extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
8f375e10 3630static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
b8232e90
CW
3631{
3632 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
3633}
af6dc742 3634extern void intel_i2c_reset(struct drm_i915_private *dev_priv);
f899fc64 3635
8b8e1a89 3636/* intel_bios.c */
98f3a1dc 3637int intel_bios_init(struct drm_i915_private *dev_priv);
f0067a31 3638bool intel_bios_is_valid_vbt(const void *buf, size_t size);
3bdd14d5 3639bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
5a69d13d 3640bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
22f35042 3641bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port);
951d9efe 3642bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
d6199256 3643bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
7137aec1 3644bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
d252bf68
SS
3645bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
3646 enum port port);
6389dd83
SS
3647bool intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv,
3648 enum port port);
3649
8b8e1a89 3650
3b617967 3651/* intel_opregion.c */
44834a67 3652#ifdef CONFIG_ACPI
6f9f4b7a 3653extern int intel_opregion_setup(struct drm_i915_private *dev_priv);
03d92e47
CW
3654extern void intel_opregion_register(struct drm_i915_private *dev_priv);
3655extern void intel_opregion_unregister(struct drm_i915_private *dev_priv);
91d14251 3656extern void intel_opregion_asle_intr(struct drm_i915_private *dev_priv);
9c4b0a68
JN
3657extern int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
3658 bool enable);
6f9f4b7a 3659extern int intel_opregion_notify_adapter(struct drm_i915_private *dev_priv,
ecbc5cf3 3660 pci_power_t state);
6f9f4b7a 3661extern int intel_opregion_get_panel_type(struct drm_i915_private *dev_priv);
65e082c9 3662#else
6f9f4b7a 3663static inline int intel_opregion_setup(struct drm_i915_private *dev) { return 0; }
bdaa2dfb
RD
3664static inline void intel_opregion_register(struct drm_i915_private *dev_priv) { }
3665static inline void intel_opregion_unregister(struct drm_i915_private *dev_priv) { }
91d14251
TU
3666static inline void intel_opregion_asle_intr(struct drm_i915_private *dev_priv)
3667{
3668}
9c4b0a68
JN
3669static inline int
3670intel_opregion_notify_encoder(struct intel_encoder *intel_encoder, bool enable)
3671{
3672 return 0;
3673}
ecbc5cf3 3674static inline int
6f9f4b7a 3675intel_opregion_notify_adapter(struct drm_i915_private *dev, pci_power_t state)
ecbc5cf3
JN
3676{
3677 return 0;
3678}
6f9f4b7a 3679static inline int intel_opregion_get_panel_type(struct drm_i915_private *dev)
a0562819
VS
3680{
3681 return -ENODEV;
3682}
65e082c9 3683#endif
8ee1c3db 3684
723bfd70
JB
3685/* intel_acpi.c */
3686#ifdef CONFIG_ACPI
3687extern void intel_register_dsm_handler(void);
3688extern void intel_unregister_dsm_handler(void);
3689#else
3690static inline void intel_register_dsm_handler(void) { return; }
3691static inline void intel_unregister_dsm_handler(void) { return; }
3692#endif /* CONFIG_ACPI */
3693
94b4f3ba
CW
3694/* intel_device_info.c */
3695static inline struct intel_device_info *
3696mkwrite_device_info(struct drm_i915_private *dev_priv)
3697{
3698 return (struct intel_device_info *)&dev_priv->info;
3699}
3700
2e0d26f8 3701const char *intel_platform_name(enum intel_platform platform);
94b4f3ba
CW
3702void intel_device_info_runtime_init(struct drm_i915_private *dev_priv);
3703void intel_device_info_dump(struct drm_i915_private *dev_priv);
3704
79e53945 3705/* modesetting */
f817586c 3706extern void intel_modeset_init_hw(struct drm_device *dev);
b079bd17 3707extern int intel_modeset_init(struct drm_device *dev);
2c7111db 3708extern void intel_modeset_gem_init(struct drm_device *dev);
79e53945 3709extern void intel_modeset_cleanup(struct drm_device *dev);
1ebaa0b9 3710extern int intel_connector_register(struct drm_connector *);
c191eca1 3711extern void intel_connector_unregister(struct drm_connector *);
6315b5d3
TU
3712extern int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv,
3713 bool state);
043e9bda 3714extern void intel_display_resume(struct drm_device *dev);
29b74b7f
TU
3715extern void i915_redisable_vga(struct drm_i915_private *dev_priv);
3716extern void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv);
91d14251 3717extern bool ironlake_set_drps(struct drm_i915_private *dev_priv, u8 val);
c39055b0 3718extern void intel_init_pch_refclk(struct drm_i915_private *dev_priv);
dc97997a 3719extern void intel_set_rps(struct drm_i915_private *dev_priv, u8 val);
11a85d6a 3720extern bool intel_set_memory_cxsr(struct drm_i915_private *dev_priv,
5209b1f4 3721 bool enable);
3bad0781 3722
c0c7babc
BW
3723int i915_reg_read_ioctl(struct drm_device *dev, void *data,
3724 struct drm_file *file);
575155a9 3725
6ef3d427 3726/* overlay */
c033666a
CW
3727extern struct intel_overlay_error_state *
3728intel_overlay_capture_error_state(struct drm_i915_private *dev_priv);
edc3d884
MK
3729extern void intel_overlay_print_error_state(struct drm_i915_error_state_buf *e,
3730 struct intel_overlay_error_state *error);
c4a1d9e4 3731
c033666a
CW
3732extern struct intel_display_error_state *
3733intel_display_capture_error_state(struct drm_i915_private *dev_priv);
edc3d884 3734extern void intel_display_print_error_state(struct drm_i915_error_state_buf *e,
5f56d5f9 3735 struct drm_i915_private *dev_priv,
c4a1d9e4 3736 struct intel_display_error_state *error);
6ef3d427 3737
151a49d0
TR
3738int sandybridge_pcode_read(struct drm_i915_private *dev_priv, u32 mbox, u32 *val);
3739int sandybridge_pcode_write(struct drm_i915_private *dev_priv, u32 mbox, u32 val);
a0b8a1fe
ID
3740int skl_pcode_request(struct drm_i915_private *dev_priv, u32 mbox, u32 request,
3741 u32 reply_mask, u32 reply, int timeout_base_ms);
59de0813
JN
3742
3743/* intel_sideband.c */
707b6e3d
D
3744u32 vlv_punit_read(struct drm_i915_private *dev_priv, u32 addr);
3745void vlv_punit_write(struct drm_i915_private *dev_priv, u32 addr, u32 val);
64936258 3746u32 vlv_nc_read(struct drm_i915_private *dev_priv, u8 addr);
dfb19ed2
D
3747u32 vlv_iosf_sb_read(struct drm_i915_private *dev_priv, u8 port, u32 reg);
3748void vlv_iosf_sb_write(struct drm_i915_private *dev_priv, u8 port, u32 reg, u32 val);
e9f882a3
JN
3749u32 vlv_cck_read(struct drm_i915_private *dev_priv, u32 reg);
3750void vlv_cck_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
3751u32 vlv_ccu_read(struct drm_i915_private *dev_priv, u32 reg);
3752void vlv_ccu_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
f3419158
JB
3753u32 vlv_bunit_read(struct drm_i915_private *dev_priv, u32 reg);
3754void vlv_bunit_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
5e69f97f
CML
3755u32 vlv_dpio_read(struct drm_i915_private *dev_priv, enum pipe pipe, int reg);
3756void vlv_dpio_write(struct drm_i915_private *dev_priv, enum pipe pipe, int reg, u32 val);
59de0813
JN
3757u32 intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
3758 enum intel_sbi_destination destination);
3759void intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
3760 enum intel_sbi_destination destination);
e9fe51c6
SK
3761u32 vlv_flisdsi_read(struct drm_i915_private *dev_priv, u32 reg);
3762void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
0a073b84 3763
b7fa22d8 3764/* intel_dpio_phy.c */
0a116ce8 3765void bxt_port_to_phy_channel(struct drm_i915_private *dev_priv, enum port port,
ed37892e 3766 enum dpio_phy *phy, enum dpio_channel *ch);
b6e08203
ACO
3767void bxt_ddi_phy_set_signal_level(struct drm_i915_private *dev_priv,
3768 enum port port, u32 margin, u32 scale,
3769 u32 enable, u32 deemphasis);
47a6bc61
ACO
3770void bxt_ddi_phy_init(struct drm_i915_private *dev_priv, enum dpio_phy phy);
3771void bxt_ddi_phy_uninit(struct drm_i915_private *dev_priv, enum dpio_phy phy);
3772bool bxt_ddi_phy_is_enabled(struct drm_i915_private *dev_priv,
3773 enum dpio_phy phy);
3774bool bxt_ddi_phy_verify_state(struct drm_i915_private *dev_priv,
3775 enum dpio_phy phy);
3776uint8_t bxt_ddi_phy_calc_lane_lat_optim_mask(struct intel_encoder *encoder,
3777 uint8_t lane_count);
3778void bxt_ddi_phy_set_lane_optim_mask(struct intel_encoder *encoder,
3779 uint8_t lane_lat_optim_mask);
3780uint8_t bxt_ddi_phy_get_lane_lat_optim_mask(struct intel_encoder *encoder);
3781
b7fa22d8
ACO
3782void chv_set_phy_signal_level(struct intel_encoder *encoder,
3783 u32 deemph_reg_value, u32 margin_reg_value,
3784 bool uniq_trans_scale);
844b2f9a
ACO
3785void chv_data_lane_soft_reset(struct intel_encoder *encoder,
3786 bool reset);
419b1b7a 3787void chv_phy_pre_pll_enable(struct intel_encoder *encoder);
e7d2a717
ACO
3788void chv_phy_pre_encoder_enable(struct intel_encoder *encoder);
3789void chv_phy_release_cl2_override(struct intel_encoder *encoder);
204970b5 3790void chv_phy_post_pll_disable(struct intel_encoder *encoder);
b7fa22d8 3791
53d98725
ACO
3792void vlv_set_phy_signal_level(struct intel_encoder *encoder,
3793 u32 demph_reg_value, u32 preemph_reg_value,
3794 u32 uniqtranscale_reg_value, u32 tx3_demph);
6da2e616 3795void vlv_phy_pre_pll_enable(struct intel_encoder *encoder);
5f68c275 3796void vlv_phy_pre_encoder_enable(struct intel_encoder *encoder);
0f572ebe 3797void vlv_phy_reset_lanes(struct intel_encoder *encoder);
53d98725 3798
616bc820
VS
3799int intel_gpu_freq(struct drm_i915_private *dev_priv, int val);
3800int intel_freq_opcode(struct drm_i915_private *dev_priv, int val);
c8d9a590 3801
0b274481
BW
3802#define I915_READ8(reg) dev_priv->uncore.funcs.mmio_readb(dev_priv, (reg), true)
3803#define I915_WRITE8(reg, val) dev_priv->uncore.funcs.mmio_writeb(dev_priv, (reg), (val), true)
3804
3805#define I915_READ16(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), true)
3806#define I915_WRITE16(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), true)
3807#define I915_READ16_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readw(dev_priv, (reg), false)
3808#define I915_WRITE16_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writew(dev_priv, (reg), (val), false)
3809
3810#define I915_READ(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), true)
3811#define I915_WRITE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), true)
3812#define I915_READ_NOTRACE(reg) dev_priv->uncore.funcs.mmio_readl(dev_priv, (reg), false)
3813#define I915_WRITE_NOTRACE(reg, val) dev_priv->uncore.funcs.mmio_writel(dev_priv, (reg), (val), false)
3814
698b3135
CW
3815/* Be very careful with read/write 64-bit values. On 32-bit machines, they
3816 * will be implemented using 2 32-bit writes in an arbitrary order with
3817 * an arbitrary delay between them. This can cause the hardware to
3818 * act upon the intermediate value, possibly leading to corruption and
b18c1bb4
CW
3819 * machine death. For this reason we do not support I915_WRITE64, or
3820 * dev_priv->uncore.funcs.mmio_writeq.
3821 *
3822 * When reading a 64-bit value as two 32-bit values, the delay may cause
3823 * the two reads to mismatch, e.g. a timestamp overflowing. Also note that
3824 * occasionally a 64-bit register does not actualy support a full readq
3825 * and must be read using two 32-bit reads.
3826 *
3827 * You have been warned.
698b3135 3828 */
0b274481 3829#define I915_READ64(reg) dev_priv->uncore.funcs.mmio_readq(dev_priv, (reg), true)
cae5852d 3830
50877445 3831#define I915_READ64_2x32(lower_reg, upper_reg) ({ \
acd29f7b
CW
3832 u32 upper, lower, old_upper, loop = 0; \
3833 upper = I915_READ(upper_reg); \
ee0a227b 3834 do { \
acd29f7b 3835 old_upper = upper; \
ee0a227b 3836 lower = I915_READ(lower_reg); \
acd29f7b
CW
3837 upper = I915_READ(upper_reg); \
3838 } while (upper != old_upper && loop++ < 2); \
ee0a227b 3839 (u64)upper << 32 | lower; })
50877445 3840
cae5852d
ZN
3841#define POSTING_READ(reg) (void)I915_READ_NOTRACE(reg)
3842#define POSTING_READ16(reg) (void)I915_READ16_NOTRACE(reg)
3843
75aa3f63
VS
3844#define __raw_read(x, s) \
3845static inline uint##x##_t __raw_i915_read##x(struct drm_i915_private *dev_priv, \
f0f59a00 3846 i915_reg_t reg) \
75aa3f63 3847{ \
f0f59a00 3848 return read##s(dev_priv->regs + i915_mmio_reg_offset(reg)); \
75aa3f63
VS
3849}
3850
3851#define __raw_write(x, s) \
3852static inline void __raw_i915_write##x(struct drm_i915_private *dev_priv, \
f0f59a00 3853 i915_reg_t reg, uint##x##_t val) \
75aa3f63 3854{ \
f0f59a00 3855 write##s(val, dev_priv->regs + i915_mmio_reg_offset(reg)); \
75aa3f63
VS
3856}
3857__raw_read(8, b)
3858__raw_read(16, w)
3859__raw_read(32, l)
3860__raw_read(64, q)
3861
3862__raw_write(8, b)
3863__raw_write(16, w)
3864__raw_write(32, l)
3865__raw_write(64, q)
3866
3867#undef __raw_read
3868#undef __raw_write
3869
a6111f7b 3870/* These are untraced mmio-accessors that are only valid to be used inside
aafee2eb 3871 * critical sections, such as inside IRQ handlers, where forcewake is explicitly
a6111f7b 3872 * controlled.
aafee2eb 3873 *
a6111f7b 3874 * Think twice, and think again, before using these.
aafee2eb
AH
3875 *
3876 * As an example, these accessors can possibly be used between:
3877 *
3878 * spin_lock_irq(&dev_priv->uncore.lock);
3879 * intel_uncore_forcewake_get__locked();
3880 *
3881 * and
3882 *
3883 * intel_uncore_forcewake_put__locked();
3884 * spin_unlock_irq(&dev_priv->uncore.lock);
3885 *
3886 *
3887 * Note: some registers may not need forcewake held, so
3888 * intel_uncore_forcewake_{get,put} can be omitted, see
3889 * intel_uncore_forcewake_for_reg().
3890 *
3891 * Certain architectures will die if the same cacheline is concurrently accessed
3892 * by different clients (e.g. on Ivybridge). Access to registers should
3893 * therefore generally be serialised, by either the dev_priv->uncore.lock or
3894 * a more localised lock guarding all access to that bank of registers.
a6111f7b 3895 */
75aa3f63
VS
3896#define I915_READ_FW(reg__) __raw_i915_read32(dev_priv, (reg__))
3897#define I915_WRITE_FW(reg__, val__) __raw_i915_write32(dev_priv, (reg__), (val__))
76f8421f 3898#define I915_WRITE64_FW(reg__, val__) __raw_i915_write64(dev_priv, (reg__), (val__))
a6111f7b
CW
3899#define POSTING_READ_FW(reg__) (void)I915_READ_FW(reg__)
3900
55bc60db
VS
3901/* "Broadcast RGB" property */
3902#define INTEL_BROADCAST_RGB_AUTO 0
3903#define INTEL_BROADCAST_RGB_FULL 1
3904#define INTEL_BROADCAST_RGB_LIMITED 2
ba4f01a3 3905
920a14b2 3906static inline i915_reg_t i915_vgacntrl_reg(struct drm_i915_private *dev_priv)
766aa1c4 3907{
920a14b2 3908 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
766aa1c4 3909 return VLV_VGACNTRL;
920a14b2 3910 else if (INTEL_GEN(dev_priv) >= 5)
92e23b99 3911 return CPU_VGACNTRL;
766aa1c4
VS
3912 else
3913 return VGACNTRL;
3914}
3915
df97729f
ID
3916static inline unsigned long msecs_to_jiffies_timeout(const unsigned int m)
3917{
3918 unsigned long j = msecs_to_jiffies(m);
3919
3920 return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
3921}
3922
7bd0e226
DV
3923static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
3924{
3925 return min_t(u64, MAX_JIFFY_OFFSET, nsecs_to_jiffies64(n) + 1);
3926}
3927
df97729f
ID
3928static inline unsigned long
3929timespec_to_jiffies_timeout(const struct timespec *value)
3930{
3931 unsigned long j = timespec_to_jiffies(value);
3932
3933 return min_t(unsigned long, MAX_JIFFY_OFFSET, j + 1);
3934}
3935
dce56b3c
PZ
3936/*
3937 * If you need to wait X milliseconds between events A and B, but event B
3938 * doesn't happen exactly after event A, you record the timestamp (jiffies) of
3939 * when event A happened, then just before event B you call this function and
3940 * pass the timestamp as the first argument, and X as the second argument.
3941 */
3942static inline void
3943wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
3944{
ec5e0cfb 3945 unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
dce56b3c
PZ
3946
3947 /*
3948 * Don't re-read the value of "jiffies" every time since it may change
3949 * behind our back and break the math.
3950 */
3951 tmp_jiffies = jiffies;
3952 target_jiffies = timestamp_jiffies +
3953 msecs_to_jiffies_timeout(to_wait_ms);
3954
3955 if (time_after(target_jiffies, tmp_jiffies)) {
ec5e0cfb
ID
3956 remaining_jiffies = target_jiffies - tmp_jiffies;
3957 while (remaining_jiffies)
3958 remaining_jiffies =
3959 schedule_timeout_uninterruptible(remaining_jiffies);
dce56b3c
PZ
3960 }
3961}
221fe799
CW
3962
3963static inline bool
3964__i915_request_irq_complete(struct drm_i915_gem_request *req)
688e6c72 3965{
f69a02c9
CW
3966 struct intel_engine_cs *engine = req->engine;
3967
7ec2c73b
CW
3968 /* Before we do the heavier coherent read of the seqno,
3969 * check the value (hopefully) in the CPU cacheline.
3970 */
65e4760e 3971 if (__i915_gem_request_completed(req))
7ec2c73b
CW
3972 return true;
3973
688e6c72
CW
3974 /* Ensure our read of the seqno is coherent so that we
3975 * do not "miss an interrupt" (i.e. if this is the last
3976 * request and the seqno write from the GPU is not visible
3977 * by the time the interrupt fires, we will see that the
3978 * request is incomplete and go back to sleep awaiting
3979 * another interrupt that will never come.)
3980 *
3981 * Strictly, we only need to do this once after an interrupt,
3982 * but it is easier and safer to do it every time the waiter
3983 * is woken.
3984 */
3d5564e9 3985 if (engine->irq_seqno_barrier &&
dbd6ef29 3986 rcu_access_pointer(engine->breadcrumbs.irq_seqno_bh) == current &&
aca34b6e 3987 cmpxchg_relaxed(&engine->breadcrumbs.irq_posted, 1, 0)) {
99fe4a5f
CW
3988 struct task_struct *tsk;
3989
3d5564e9
CW
3990 /* The ordering of irq_posted versus applying the barrier
3991 * is crucial. The clearing of the current irq_posted must
3992 * be visible before we perform the barrier operation,
3993 * such that if a subsequent interrupt arrives, irq_posted
3994 * is reasserted and our task rewoken (which causes us to
3995 * do another __i915_request_irq_complete() immediately
3996 * and reapply the barrier). Conversely, if the clear
3997 * occurs after the barrier, then an interrupt that arrived
3998 * whilst we waited on the barrier would not trigger a
3999 * barrier on the next pass, and the read may not see the
4000 * seqno update.
4001 */
f69a02c9 4002 engine->irq_seqno_barrier(engine);
99fe4a5f
CW
4003
4004 /* If we consume the irq, but we are no longer the bottom-half,
4005 * the real bottom-half may not have serialised their own
4006 * seqno check with the irq-barrier (i.e. may have inspected
4007 * the seqno before we believe it coherent since they see
4008 * irq_posted == false but we are still running).
4009 */
4010 rcu_read_lock();
dbd6ef29 4011 tsk = rcu_dereference(engine->breadcrumbs.irq_seqno_bh);
99fe4a5f
CW
4012 if (tsk && tsk != current)
4013 /* Note that if the bottom-half is changed as we
4014 * are sending the wake-up, the new bottom-half will
4015 * be woken by whomever made the change. We only have
4016 * to worry about when we steal the irq-posted for
4017 * ourself.
4018 */
4019 wake_up_process(tsk);
4020 rcu_read_unlock();
4021
65e4760e 4022 if (__i915_gem_request_completed(req))
7ec2c73b
CW
4023 return true;
4024 }
688e6c72 4025
688e6c72
CW
4026 return false;
4027}
4028
0b1de5d5
CW
4029void i915_memcpy_init_early(struct drm_i915_private *dev_priv);
4030bool i915_memcpy_from_wc(void *dst, const void *src, unsigned long len);
4031
c58305af
CW
4032/* i915_mm.c */
4033int remap_io_mapping(struct vm_area_struct *vma,
4034 unsigned long addr, unsigned long pfn, unsigned long size,
4035 struct io_mapping *iomap);
4036
4b30cb23
CW
4037#define ptr_mask_bits(ptr) ({ \
4038 unsigned long __v = (unsigned long)(ptr); \
4039 (typeof(ptr))(__v & PAGE_MASK); \
4040})
4041
d31d7cb1
CW
4042#define ptr_unpack_bits(ptr, bits) ({ \
4043 unsigned long __v = (unsigned long)(ptr); \
4044 (bits) = __v & ~PAGE_MASK; \
4045 (typeof(ptr))(__v & PAGE_MASK); \
4046})
4047
4048#define ptr_pack_bits(ptr, bits) \
4049 ((typeof(ptr))((unsigned long)(ptr) | (bits)))
4050
78ef2d9a
CW
4051#define fetch_and_zero(ptr) ({ \
4052 typeof(*ptr) __T = *(ptr); \
4053 *(ptr) = (typeof(*ptr))0; \
4054 __T; \
4055})
4056
1da177e4 4057#endif