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