xref: /openbsd-src/sys/dev/pci/drm/i915/i915_pci.c (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 /*
2  * Copyright © 2016 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24 
25 #include <linux/console.h>
26 #include <linux/vga_switcheroo.h>
27 
28 #include <drm/drm_drv.h>
29 #include <drm/i915_pciids.h>
30 
31 #include "display/intel_fbdev.h"
32 
33 #include "i915_drv.h"
34 #include "i915_perf.h"
35 #include "i915_globals.h"
36 #include "i915_selftest.h"
37 
38 #define PLATFORM(x) .platform = (x)
39 #define GEN(x) .gen = (x), .gen_mask = BIT((x) - 1)
40 
41 #define I845_PIPE_OFFSETS \
42 	.pipe_offsets = { \
43 		[TRANSCODER_A] = PIPE_A_OFFSET,	\
44 	}, \
45 	.trans_offsets = { \
46 		[TRANSCODER_A] = TRANSCODER_A_OFFSET, \
47 	}
48 
49 #define I9XX_PIPE_OFFSETS \
50 	.pipe_offsets = { \
51 		[TRANSCODER_A] = PIPE_A_OFFSET,	\
52 		[TRANSCODER_B] = PIPE_B_OFFSET, \
53 	}, \
54 	.trans_offsets = { \
55 		[TRANSCODER_A] = TRANSCODER_A_OFFSET, \
56 		[TRANSCODER_B] = TRANSCODER_B_OFFSET, \
57 	}
58 
59 #define IVB_PIPE_OFFSETS \
60 	.pipe_offsets = { \
61 		[TRANSCODER_A] = PIPE_A_OFFSET,	\
62 		[TRANSCODER_B] = PIPE_B_OFFSET, \
63 		[TRANSCODER_C] = PIPE_C_OFFSET, \
64 	}, \
65 	.trans_offsets = { \
66 		[TRANSCODER_A] = TRANSCODER_A_OFFSET, \
67 		[TRANSCODER_B] = TRANSCODER_B_OFFSET, \
68 		[TRANSCODER_C] = TRANSCODER_C_OFFSET, \
69 	}
70 
71 #define HSW_PIPE_OFFSETS \
72 	.pipe_offsets = { \
73 		[TRANSCODER_A] = PIPE_A_OFFSET,	\
74 		[TRANSCODER_B] = PIPE_B_OFFSET, \
75 		[TRANSCODER_C] = PIPE_C_OFFSET, \
76 		[TRANSCODER_EDP] = PIPE_EDP_OFFSET, \
77 	}, \
78 	.trans_offsets = { \
79 		[TRANSCODER_A] = TRANSCODER_A_OFFSET, \
80 		[TRANSCODER_B] = TRANSCODER_B_OFFSET, \
81 		[TRANSCODER_C] = TRANSCODER_C_OFFSET, \
82 		[TRANSCODER_EDP] = TRANSCODER_EDP_OFFSET, \
83 	}
84 
85 #define CHV_PIPE_OFFSETS \
86 	.pipe_offsets = { \
87 		[TRANSCODER_A] = PIPE_A_OFFSET, \
88 		[TRANSCODER_B] = PIPE_B_OFFSET, \
89 		[TRANSCODER_C] = CHV_PIPE_C_OFFSET, \
90 	}, \
91 	.trans_offsets = { \
92 		[TRANSCODER_A] = TRANSCODER_A_OFFSET, \
93 		[TRANSCODER_B] = TRANSCODER_B_OFFSET, \
94 		[TRANSCODER_C] = CHV_TRANSCODER_C_OFFSET, \
95 	}
96 
97 #define I845_CURSOR_OFFSETS \
98 	.cursor_offsets = { \
99 		[PIPE_A] = CURSOR_A_OFFSET, \
100 	}
101 
102 #define I9XX_CURSOR_OFFSETS \
103 	.cursor_offsets = { \
104 		[PIPE_A] = CURSOR_A_OFFSET, \
105 		[PIPE_B] = CURSOR_B_OFFSET, \
106 	}
107 
108 #define CHV_CURSOR_OFFSETS \
109 	.cursor_offsets = { \
110 		[PIPE_A] = CURSOR_A_OFFSET, \
111 		[PIPE_B] = CURSOR_B_OFFSET, \
112 		[PIPE_C] = CHV_CURSOR_C_OFFSET, \
113 	}
114 
115 #define IVB_CURSOR_OFFSETS \
116 	.cursor_offsets = { \
117 		[PIPE_A] = CURSOR_A_OFFSET, \
118 		[PIPE_B] = IVB_CURSOR_B_OFFSET, \
119 		[PIPE_C] = IVB_CURSOR_C_OFFSET, \
120 	}
121 
122 #define TGL_CURSOR_OFFSETS \
123 	.cursor_offsets = { \
124 		[PIPE_A] = CURSOR_A_OFFSET, \
125 		[PIPE_B] = IVB_CURSOR_B_OFFSET, \
126 		[PIPE_C] = IVB_CURSOR_C_OFFSET, \
127 		[PIPE_D] = TGL_CURSOR_D_OFFSET, \
128 	}
129 
130 #define I9XX_COLORS \
131 	.color = { .gamma_lut_size = 256 }
132 #define I965_COLORS \
133 	.color = { .gamma_lut_size = 129, \
134 		   .gamma_lut_tests = DRM_COLOR_LUT_NON_DECREASING, \
135 	}
136 #define ILK_COLORS \
137 	.color = { .gamma_lut_size = 1024 }
138 #define IVB_COLORS \
139 	.color = { .degamma_lut_size = 1024, .gamma_lut_size = 1024 }
140 #define CHV_COLORS \
141 	.color = { .degamma_lut_size = 65, .gamma_lut_size = 257, \
142 		   .degamma_lut_tests = DRM_COLOR_LUT_NON_DECREASING, \
143 		   .gamma_lut_tests = DRM_COLOR_LUT_NON_DECREASING, \
144 	}
145 #define GLK_COLORS \
146 	.color = { .degamma_lut_size = 33, .gamma_lut_size = 1024, \
147 		   .degamma_lut_tests = DRM_COLOR_LUT_NON_DECREASING | \
148 					DRM_COLOR_LUT_EQUAL_CHANNELS, \
149 	}
150 
151 /* Keep in gen based order, and chronological order within a gen */
152 
153 #define GEN_DEFAULT_PAGE_SIZES \
154 	.page_sizes = I915_GTT_PAGE_SIZE_4K
155 
156 #define GEN_DEFAULT_REGIONS \
157 	.memory_regions = REGION_SMEM | REGION_STOLEN
158 
159 #define I830_FEATURES \
160 	GEN(2), \
161 	.is_mobile = 1, \
162 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B), \
163 	.display.has_overlay = 1, \
164 	.display.cursor_needs_physical = 1, \
165 	.display.overlay_needs_physical = 1, \
166 	.display.has_gmch = 1, \
167 	.gpu_reset_clobbers_display = true, \
168 	.hws_needs_physical = 1, \
169 	.unfenced_needs_alignment = 1, \
170 	.engine_mask = BIT(RCS0), \
171 	.has_snoop = true, \
172 	.has_coherent_ggtt = false, \
173 	I9XX_PIPE_OFFSETS, \
174 	I9XX_CURSOR_OFFSETS, \
175 	I9XX_COLORS, \
176 	GEN_DEFAULT_PAGE_SIZES, \
177 	GEN_DEFAULT_REGIONS
178 
179 #define I845_FEATURES \
180 	GEN(2), \
181 	.pipe_mask = BIT(PIPE_A), \
182 	.display.has_overlay = 1, \
183 	.display.overlay_needs_physical = 1, \
184 	.display.has_gmch = 1, \
185 	.gpu_reset_clobbers_display = true, \
186 	.hws_needs_physical = 1, \
187 	.unfenced_needs_alignment = 1, \
188 	.engine_mask = BIT(RCS0), \
189 	.has_snoop = true, \
190 	.has_coherent_ggtt = false, \
191 	I845_PIPE_OFFSETS, \
192 	I845_CURSOR_OFFSETS, \
193 	I9XX_COLORS, \
194 	GEN_DEFAULT_PAGE_SIZES, \
195 	GEN_DEFAULT_REGIONS
196 
197 static const struct intel_device_info i830_info = {
198 	I830_FEATURES,
199 	PLATFORM(INTEL_I830),
200 };
201 
202 static const struct intel_device_info i845g_info = {
203 	I845_FEATURES,
204 	PLATFORM(INTEL_I845G),
205 };
206 
207 static const struct intel_device_info i85x_info = {
208 	I830_FEATURES,
209 	PLATFORM(INTEL_I85X),
210 	.display.has_fbc = 1,
211 };
212 
213 static const struct intel_device_info i865g_info = {
214 	I845_FEATURES,
215 	PLATFORM(INTEL_I865G),
216 };
217 
218 #define GEN3_FEATURES \
219 	GEN(3), \
220 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B), \
221 	.display.has_gmch = 1, \
222 	.gpu_reset_clobbers_display = true, \
223 	.engine_mask = BIT(RCS0), \
224 	.has_snoop = true, \
225 	.has_coherent_ggtt = true, \
226 	I9XX_PIPE_OFFSETS, \
227 	I9XX_CURSOR_OFFSETS, \
228 	I9XX_COLORS, \
229 	GEN_DEFAULT_PAGE_SIZES, \
230 	GEN_DEFAULT_REGIONS
231 
232 static const struct intel_device_info i915g_info = {
233 	GEN3_FEATURES,
234 	PLATFORM(INTEL_I915G),
235 	.has_coherent_ggtt = false,
236 	.display.cursor_needs_physical = 1,
237 	.display.has_overlay = 1,
238 	.display.overlay_needs_physical = 1,
239 	.hws_needs_physical = 1,
240 	.unfenced_needs_alignment = 1,
241 };
242 
243 static const struct intel_device_info i915gm_info = {
244 	GEN3_FEATURES,
245 	PLATFORM(INTEL_I915GM),
246 	.is_mobile = 1,
247 	.display.cursor_needs_physical = 1,
248 	.display.has_overlay = 1,
249 	.display.overlay_needs_physical = 1,
250 	.display.supports_tv = 1,
251 	.display.has_fbc = 1,
252 	.hws_needs_physical = 1,
253 	.unfenced_needs_alignment = 1,
254 };
255 
256 static const struct intel_device_info i945g_info = {
257 	GEN3_FEATURES,
258 	PLATFORM(INTEL_I945G),
259 	.display.has_hotplug = 1,
260 	.display.cursor_needs_physical = 1,
261 	.display.has_overlay = 1,
262 	.display.overlay_needs_physical = 1,
263 	.hws_needs_physical = 1,
264 	.unfenced_needs_alignment = 1,
265 };
266 
267 static const struct intel_device_info i945gm_info = {
268 	GEN3_FEATURES,
269 	PLATFORM(INTEL_I945GM),
270 	.is_mobile = 1,
271 	.display.has_hotplug = 1,
272 	.display.cursor_needs_physical = 1,
273 	.display.has_overlay = 1,
274 	.display.overlay_needs_physical = 1,
275 	.display.supports_tv = 1,
276 	.display.has_fbc = 1,
277 	.hws_needs_physical = 1,
278 	.unfenced_needs_alignment = 1,
279 };
280 
281 static const struct intel_device_info g33_info = {
282 	GEN3_FEATURES,
283 	PLATFORM(INTEL_G33),
284 	.display.has_hotplug = 1,
285 	.display.has_overlay = 1,
286 };
287 
288 static const struct intel_device_info pnv_g_info = {
289 	GEN3_FEATURES,
290 	PLATFORM(INTEL_PINEVIEW),
291 	.display.has_hotplug = 1,
292 	.display.has_overlay = 1,
293 };
294 
295 static const struct intel_device_info pnv_m_info = {
296 	GEN3_FEATURES,
297 	PLATFORM(INTEL_PINEVIEW),
298 	.is_mobile = 1,
299 	.display.has_hotplug = 1,
300 	.display.has_overlay = 1,
301 };
302 
303 #define GEN4_FEATURES \
304 	GEN(4), \
305 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B), \
306 	.display.has_hotplug = 1, \
307 	.display.has_gmch = 1, \
308 	.gpu_reset_clobbers_display = true, \
309 	.engine_mask = BIT(RCS0), \
310 	.has_snoop = true, \
311 	.has_coherent_ggtt = true, \
312 	I9XX_PIPE_OFFSETS, \
313 	I9XX_CURSOR_OFFSETS, \
314 	I965_COLORS, \
315 	GEN_DEFAULT_PAGE_SIZES, \
316 	GEN_DEFAULT_REGIONS
317 
318 static const struct intel_device_info i965g_info = {
319 	GEN4_FEATURES,
320 	PLATFORM(INTEL_I965G),
321 	.display.has_overlay = 1,
322 	.hws_needs_physical = 1,
323 	.has_snoop = false,
324 };
325 
326 static const struct intel_device_info i965gm_info = {
327 	GEN4_FEATURES,
328 	PLATFORM(INTEL_I965GM),
329 	.is_mobile = 1,
330 	.display.has_fbc = 1,
331 	.display.has_overlay = 1,
332 	.display.supports_tv = 1,
333 	.hws_needs_physical = 1,
334 	.has_snoop = false,
335 };
336 
337 static const struct intel_device_info g45_info = {
338 	GEN4_FEATURES,
339 	PLATFORM(INTEL_G45),
340 	.engine_mask = BIT(RCS0) | BIT(VCS0),
341 	.gpu_reset_clobbers_display = false,
342 };
343 
344 static const struct intel_device_info gm45_info = {
345 	GEN4_FEATURES,
346 	PLATFORM(INTEL_GM45),
347 	.is_mobile = 1,
348 	.display.has_fbc = 1,
349 	.display.supports_tv = 1,
350 	.engine_mask = BIT(RCS0) | BIT(VCS0),
351 	.gpu_reset_clobbers_display = false,
352 };
353 
354 #define GEN5_FEATURES \
355 	GEN(5), \
356 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B), \
357 	.display.has_hotplug = 1, \
358 	.engine_mask = BIT(RCS0) | BIT(VCS0), \
359 	.has_snoop = true, \
360 	.has_coherent_ggtt = true, \
361 	/* ilk does support rc6, but we do not implement [power] contexts */ \
362 	.has_rc6 = 0, \
363 	I9XX_PIPE_OFFSETS, \
364 	I9XX_CURSOR_OFFSETS, \
365 	ILK_COLORS, \
366 	GEN_DEFAULT_PAGE_SIZES, \
367 	GEN_DEFAULT_REGIONS
368 
369 static const struct intel_device_info ilk_d_info = {
370 	GEN5_FEATURES,
371 	PLATFORM(INTEL_IRONLAKE),
372 };
373 
374 static const struct intel_device_info ilk_m_info = {
375 	GEN5_FEATURES,
376 	PLATFORM(INTEL_IRONLAKE),
377 	.is_mobile = 1,
378 	.display.has_fbc = 1,
379 };
380 
381 #define GEN6_FEATURES \
382 	GEN(6), \
383 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B), \
384 	.display.has_hotplug = 1, \
385 	.display.has_fbc = 1, \
386 	.engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), \
387 	.has_coherent_ggtt = true, \
388 	.has_llc = 1, \
389 	.has_rc6 = 1, \
390 	.has_rc6p = 1, \
391 	.has_rps = true, \
392 	.ppgtt_type = INTEL_PPGTT_ALIASING, \
393 	.ppgtt_size = 31, \
394 	I9XX_PIPE_OFFSETS, \
395 	I9XX_CURSOR_OFFSETS, \
396 	ILK_COLORS, \
397 	GEN_DEFAULT_PAGE_SIZES, \
398 	GEN_DEFAULT_REGIONS
399 
400 #define SNB_D_PLATFORM \
401 	GEN6_FEATURES, \
402 	PLATFORM(INTEL_SANDYBRIDGE)
403 
404 static const struct intel_device_info snb_d_gt1_info = {
405 	SNB_D_PLATFORM,
406 	.gt = 1,
407 };
408 
409 static const struct intel_device_info snb_d_gt2_info = {
410 	SNB_D_PLATFORM,
411 	.gt = 2,
412 };
413 
414 #define SNB_M_PLATFORM \
415 	GEN6_FEATURES, \
416 	PLATFORM(INTEL_SANDYBRIDGE), \
417 	.is_mobile = 1
418 
419 
420 static const struct intel_device_info snb_m_gt1_info = {
421 	SNB_M_PLATFORM,
422 	.gt = 1,
423 };
424 
425 static const struct intel_device_info snb_m_gt2_info = {
426 	SNB_M_PLATFORM,
427 	.gt = 2,
428 };
429 
430 #define GEN7_FEATURES  \
431 	GEN(7), \
432 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), \
433 	.display.has_hotplug = 1, \
434 	.display.has_fbc = 1, \
435 	.engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0), \
436 	.has_coherent_ggtt = true, \
437 	.has_llc = 1, \
438 	.has_rc6 = 1, \
439 	.has_rc6p = 1, \
440 	.has_rps = true, \
441 	.ppgtt_type = INTEL_PPGTT_ALIASING, \
442 	.ppgtt_size = 31, \
443 	IVB_PIPE_OFFSETS, \
444 	IVB_CURSOR_OFFSETS, \
445 	IVB_COLORS, \
446 	GEN_DEFAULT_PAGE_SIZES, \
447 	GEN_DEFAULT_REGIONS
448 
449 #define IVB_D_PLATFORM \
450 	GEN7_FEATURES, \
451 	PLATFORM(INTEL_IVYBRIDGE), \
452 	.has_l3_dpf = 1
453 
454 static const struct intel_device_info ivb_d_gt1_info = {
455 	IVB_D_PLATFORM,
456 	.gt = 1,
457 };
458 
459 static const struct intel_device_info ivb_d_gt2_info = {
460 	IVB_D_PLATFORM,
461 	.gt = 2,
462 };
463 
464 #define IVB_M_PLATFORM \
465 	GEN7_FEATURES, \
466 	PLATFORM(INTEL_IVYBRIDGE), \
467 	.is_mobile = 1, \
468 	.has_l3_dpf = 1
469 
470 static const struct intel_device_info ivb_m_gt1_info = {
471 	IVB_M_PLATFORM,
472 	.gt = 1,
473 };
474 
475 static const struct intel_device_info ivb_m_gt2_info = {
476 	IVB_M_PLATFORM,
477 	.gt = 2,
478 };
479 
480 static const struct intel_device_info ivb_q_info = {
481 	GEN7_FEATURES,
482 	PLATFORM(INTEL_IVYBRIDGE),
483 	.gt = 2,
484 	.pipe_mask = 0, /* legal, last one wins */
485 	.has_l3_dpf = 1,
486 };
487 
488 static const struct intel_device_info vlv_info = {
489 	PLATFORM(INTEL_VALLEYVIEW),
490 	GEN(7),
491 	.is_lp = 1,
492 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B),
493 	.has_runtime_pm = 1,
494 	.has_rc6 = 1,
495 	.has_rps = true,
496 	.display.has_gmch = 1,
497 	.display.has_hotplug = 1,
498 	.ppgtt_type = INTEL_PPGTT_ALIASING,
499 	.ppgtt_size = 31,
500 	.has_snoop = true,
501 	.has_coherent_ggtt = false,
502 	.engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0),
503 	.display_mmio_offset = VLV_DISPLAY_BASE,
504 	I9XX_PIPE_OFFSETS,
505 	I9XX_CURSOR_OFFSETS,
506 	I965_COLORS,
507 	GEN_DEFAULT_PAGE_SIZES,
508 	GEN_DEFAULT_REGIONS,
509 };
510 
511 #define G75_FEATURES  \
512 	GEN7_FEATURES, \
513 	.engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0), \
514 	.display.has_ddi = 1, \
515 	.has_fpga_dbg = 1, \
516 	.display.has_psr = 1, \
517 	.display.has_dp_mst = 1, \
518 	.has_rc6p = 0 /* RC6p removed-by HSW */, \
519 	HSW_PIPE_OFFSETS, \
520 	.has_runtime_pm = 1
521 
522 #define HSW_PLATFORM \
523 	G75_FEATURES, \
524 	PLATFORM(INTEL_HASWELL), \
525 	.has_l3_dpf = 1
526 
527 static const struct intel_device_info hsw_gt1_info = {
528 	HSW_PLATFORM,
529 	.gt = 1,
530 };
531 
532 static const struct intel_device_info hsw_gt2_info = {
533 	HSW_PLATFORM,
534 	.gt = 2,
535 };
536 
537 static const struct intel_device_info hsw_gt3_info = {
538 	HSW_PLATFORM,
539 	.gt = 3,
540 };
541 
542 #define GEN8_FEATURES \
543 	G75_FEATURES, \
544 	GEN(8), \
545 	.has_logical_ring_contexts = 1, \
546 	.ppgtt_type = INTEL_PPGTT_FULL, \
547 	.ppgtt_size = 48, \
548 	.has_64bit_reloc = 1, \
549 	.has_reset_engine = 1
550 
551 #define BDW_PLATFORM \
552 	GEN8_FEATURES, \
553 	PLATFORM(INTEL_BROADWELL)
554 
555 static const struct intel_device_info bdw_gt1_info = {
556 	BDW_PLATFORM,
557 	.gt = 1,
558 };
559 
560 static const struct intel_device_info bdw_gt2_info = {
561 	BDW_PLATFORM,
562 	.gt = 2,
563 };
564 
565 static const struct intel_device_info bdw_rsvd_info = {
566 	BDW_PLATFORM,
567 	.gt = 3,
568 	/* According to the device ID those devices are GT3, they were
569 	 * previously treated as not GT3, keep it like that.
570 	 */
571 };
572 
573 static const struct intel_device_info bdw_gt3_info = {
574 	BDW_PLATFORM,
575 	.gt = 3,
576 	.engine_mask =
577 		BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1),
578 };
579 
580 static const struct intel_device_info chv_info = {
581 	PLATFORM(INTEL_CHERRYVIEW),
582 	GEN(8),
583 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C),
584 	.display.has_hotplug = 1,
585 	.is_lp = 1,
586 	.engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0),
587 	.has_64bit_reloc = 1,
588 	.has_runtime_pm = 1,
589 	.has_rc6 = 1,
590 	.has_rps = true,
591 #ifdef __linux__
592 	.has_logical_ring_contexts = 1,
593 #else
594 	/*
595 	 * avoid 'Resetting rcs0 for stopped heartbeat on rcs0' GPU hang
596 	 * when starting X
597 	 */
598 	.has_logical_ring_contexts = 0,
599 #endif
600 	.display.has_gmch = 1,
601 	.ppgtt_type = INTEL_PPGTT_ALIASING,
602 	.ppgtt_size = 32,
603 	.has_reset_engine = 1,
604 	.has_snoop = true,
605 	.has_coherent_ggtt = false,
606 	.display_mmio_offset = VLV_DISPLAY_BASE,
607 	CHV_PIPE_OFFSETS,
608 	CHV_CURSOR_OFFSETS,
609 	CHV_COLORS,
610 	GEN_DEFAULT_PAGE_SIZES,
611 	GEN_DEFAULT_REGIONS,
612 };
613 
614 #define GEN9_DEFAULT_PAGE_SIZES \
615 	.page_sizes = I915_GTT_PAGE_SIZE_4K | \
616 		      I915_GTT_PAGE_SIZE_64K
617 
618 #define GEN9_FEATURES \
619 	GEN8_FEATURES, \
620 	GEN(9), \
621 	GEN9_DEFAULT_PAGE_SIZES, \
622 	.has_logical_ring_preemption = 1, \
623 	.display.has_csr = 1, \
624 	.has_gt_uc = 1, \
625 	.display.has_hdcp = 1, \
626 	.display.has_ipc = 1, \
627 	.ddb_size = 896, \
628 	.num_supported_dbuf_slices = 1
629 
630 #define SKL_PLATFORM \
631 	GEN9_FEATURES, \
632 	PLATFORM(INTEL_SKYLAKE)
633 
634 static const struct intel_device_info skl_gt1_info = {
635 	SKL_PLATFORM,
636 	.gt = 1,
637 };
638 
639 static const struct intel_device_info skl_gt2_info = {
640 	SKL_PLATFORM,
641 	.gt = 2,
642 };
643 
644 #define SKL_GT3_PLUS_PLATFORM \
645 	SKL_PLATFORM, \
646 	.engine_mask = \
647 		BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1)
648 
649 
650 static const struct intel_device_info skl_gt3_info = {
651 	SKL_GT3_PLUS_PLATFORM,
652 	.gt = 3,
653 };
654 
655 static const struct intel_device_info skl_gt4_info = {
656 	SKL_GT3_PLUS_PLATFORM,
657 	.gt = 4,
658 };
659 
660 #define GEN9_LP_FEATURES \
661 	GEN(9), \
662 	.is_lp = 1, \
663 	.num_supported_dbuf_slices = 1, \
664 	.display.has_hotplug = 1, \
665 	.engine_mask = BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0), \
666 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C), \
667 	.has_64bit_reloc = 1, \
668 	.display.has_ddi = 1, \
669 	.has_fpga_dbg = 1, \
670 	.display.has_fbc = 1, \
671 	.display.has_hdcp = 1, \
672 	.display.has_psr = 1, \
673 	.has_runtime_pm = 1, \
674 	.display.has_csr = 1, \
675 	.has_rc6 = 1, \
676 	.has_rps = true, \
677 	.display.has_dp_mst = 1, \
678 	.has_logical_ring_contexts = 1, \
679 	.has_logical_ring_preemption = 1, \
680 	.has_gt_uc = 1, \
681 	.ppgtt_type = INTEL_PPGTT_FULL, \
682 	.ppgtt_size = 48, \
683 	.has_reset_engine = 1, \
684 	.has_snoop = true, \
685 	.has_coherent_ggtt = false, \
686 	.display.has_ipc = 1, \
687 	HSW_PIPE_OFFSETS, \
688 	IVB_CURSOR_OFFSETS, \
689 	IVB_COLORS, \
690 	GEN9_DEFAULT_PAGE_SIZES, \
691 	GEN_DEFAULT_REGIONS
692 
693 static const struct intel_device_info bxt_info = {
694 	GEN9_LP_FEATURES,
695 	PLATFORM(INTEL_BROXTON),
696 	.ddb_size = 512,
697 };
698 
699 static const struct intel_device_info glk_info = {
700 	GEN9_LP_FEATURES,
701 	PLATFORM(INTEL_GEMINILAKE),
702 	.ddb_size = 1024,
703 	GLK_COLORS,
704 };
705 
706 #define KBL_PLATFORM \
707 	GEN9_FEATURES, \
708 	PLATFORM(INTEL_KABYLAKE)
709 
710 static const struct intel_device_info kbl_gt1_info = {
711 	KBL_PLATFORM,
712 	.gt = 1,
713 };
714 
715 static const struct intel_device_info kbl_gt2_info = {
716 	KBL_PLATFORM,
717 	.gt = 2,
718 };
719 
720 static const struct intel_device_info kbl_gt3_info = {
721 	KBL_PLATFORM,
722 	.gt = 3,
723 	.engine_mask =
724 		BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1),
725 };
726 
727 #define CFL_PLATFORM \
728 	GEN9_FEATURES, \
729 	PLATFORM(INTEL_COFFEELAKE)
730 
731 static const struct intel_device_info cfl_gt1_info = {
732 	CFL_PLATFORM,
733 	.gt = 1,
734 };
735 
736 static const struct intel_device_info cfl_gt2_info = {
737 	CFL_PLATFORM,
738 	.gt = 2,
739 };
740 
741 static const struct intel_device_info cfl_gt3_info = {
742 	CFL_PLATFORM,
743 	.gt = 3,
744 	.engine_mask =
745 		BIT(RCS0) | BIT(VCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS1),
746 };
747 
748 #define GEN10_FEATURES \
749 	GEN9_FEATURES, \
750 	GEN(10), \
751 	.ddb_size = 1024, \
752 	.display.has_dsc = 1, \
753 	.has_coherent_ggtt = false, \
754 	GLK_COLORS
755 
756 static const struct intel_device_info cnl_info = {
757 	GEN10_FEATURES,
758 	PLATFORM(INTEL_CANNONLAKE),
759 	.gt = 2,
760 };
761 
762 #define GEN11_DEFAULT_PAGE_SIZES \
763 	.page_sizes = I915_GTT_PAGE_SIZE_4K | \
764 		      I915_GTT_PAGE_SIZE_64K | \
765 		      I915_GTT_PAGE_SIZE_2M
766 
767 #define GEN11_FEATURES \
768 	GEN10_FEATURES, \
769 	GEN11_DEFAULT_PAGE_SIZES, \
770 	.pipe_offsets = { \
771 		[TRANSCODER_A] = PIPE_A_OFFSET, \
772 		[TRANSCODER_B] = PIPE_B_OFFSET, \
773 		[TRANSCODER_C] = PIPE_C_OFFSET, \
774 		[TRANSCODER_EDP] = PIPE_EDP_OFFSET, \
775 		[TRANSCODER_DSI_0] = PIPE_DSI0_OFFSET, \
776 		[TRANSCODER_DSI_1] = PIPE_DSI1_OFFSET, \
777 	}, \
778 	.trans_offsets = { \
779 		[TRANSCODER_A] = TRANSCODER_A_OFFSET, \
780 		[TRANSCODER_B] = TRANSCODER_B_OFFSET, \
781 		[TRANSCODER_C] = TRANSCODER_C_OFFSET, \
782 		[TRANSCODER_EDP] = TRANSCODER_EDP_OFFSET, \
783 		[TRANSCODER_DSI_0] = TRANSCODER_DSI0_OFFSET, \
784 		[TRANSCODER_DSI_1] = TRANSCODER_DSI1_OFFSET, \
785 	}, \
786 	GEN(11), \
787 	.ddb_size = 2048, \
788 	.num_supported_dbuf_slices = 2, \
789 	.has_logical_ring_elsq = 1, \
790 	.color = { .degamma_lut_size = 33, .gamma_lut_size = 262145 }
791 
792 static const struct intel_device_info icl_info = {
793 	GEN11_FEATURES,
794 	PLATFORM(INTEL_ICELAKE),
795 	.engine_mask =
796 		BIT(RCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS0) | BIT(VCS2),
797 };
798 
799 static const struct intel_device_info ehl_info = {
800 	GEN11_FEATURES,
801 	PLATFORM(INTEL_ELKHARTLAKE),
802 	.require_force_probe = 1,
803 	.engine_mask = BIT(RCS0) | BIT(BCS0) | BIT(VCS0) | BIT(VECS0),
804 	.ppgtt_size = 36,
805 };
806 
807 #define GEN12_FEATURES \
808 	GEN11_FEATURES, \
809 	GEN(12), \
810 	.pipe_offsets = { \
811 		[TRANSCODER_A] = PIPE_A_OFFSET, \
812 		[TRANSCODER_B] = PIPE_B_OFFSET, \
813 		[TRANSCODER_C] = PIPE_C_OFFSET, \
814 		[TRANSCODER_D] = PIPE_D_OFFSET, \
815 		[TRANSCODER_DSI_0] = PIPE_DSI0_OFFSET, \
816 		[TRANSCODER_DSI_1] = PIPE_DSI1_OFFSET, \
817 	}, \
818 	.trans_offsets = { \
819 		[TRANSCODER_A] = TRANSCODER_A_OFFSET, \
820 		[TRANSCODER_B] = TRANSCODER_B_OFFSET, \
821 		[TRANSCODER_C] = TRANSCODER_C_OFFSET, \
822 		[TRANSCODER_D] = TRANSCODER_D_OFFSET, \
823 		[TRANSCODER_DSI_0] = TRANSCODER_DSI0_OFFSET, \
824 		[TRANSCODER_DSI_1] = TRANSCODER_DSI1_OFFSET, \
825 	}, \
826 	TGL_CURSOR_OFFSETS, \
827 	.has_global_mocs = 1, \
828 	.display.has_dsb = 1
829 
830 static const struct intel_device_info tgl_info = {
831 	GEN12_FEATURES,
832 	PLATFORM(INTEL_TIGERLAKE),
833 	.pipe_mask = BIT(PIPE_A) | BIT(PIPE_B) | BIT(PIPE_C) | BIT(PIPE_D),
834 	.display.has_modular_fia = 1,
835 	.engine_mask =
836 		BIT(RCS0) | BIT(BCS0) | BIT(VECS0) | BIT(VCS0) | BIT(VCS2),
837 };
838 
839 #define GEN12_DGFX_FEATURES \
840 	GEN12_FEATURES, \
841 	.is_dgfx = 1
842 
843 #undef GEN
844 #undef PLATFORM
845 
846 /*
847  * Make sure any device matches here are from most specific to most
848  * general.  For example, since the Quanta match is based on the subsystem
849  * and subvendor IDs, we need it to come before the more general IVB
850  * PCI ID matches, otherwise we'll use the wrong info struct above.
851  */
852 const struct pci_device_id pciidlist[] = {
853 	INTEL_I830_IDS(&i830_info),
854 	INTEL_I845G_IDS(&i845g_info),
855 	INTEL_I85X_IDS(&i85x_info),
856 	INTEL_I865G_IDS(&i865g_info),
857 	INTEL_I915G_IDS(&i915g_info),
858 	INTEL_I915GM_IDS(&i915gm_info),
859 	INTEL_I945G_IDS(&i945g_info),
860 	INTEL_I945GM_IDS(&i945gm_info),
861 	INTEL_I965G_IDS(&i965g_info),
862 	INTEL_G33_IDS(&g33_info),
863 	INTEL_I965GM_IDS(&i965gm_info),
864 	INTEL_GM45_IDS(&gm45_info),
865 	INTEL_G45_IDS(&g45_info),
866 	INTEL_PINEVIEW_G_IDS(&pnv_g_info),
867 	INTEL_PINEVIEW_M_IDS(&pnv_m_info),
868 	INTEL_IRONLAKE_D_IDS(&ilk_d_info),
869 	INTEL_IRONLAKE_M_IDS(&ilk_m_info),
870 	INTEL_SNB_D_GT1_IDS(&snb_d_gt1_info),
871 	INTEL_SNB_D_GT2_IDS(&snb_d_gt2_info),
872 	INTEL_SNB_M_GT1_IDS(&snb_m_gt1_info),
873 	INTEL_SNB_M_GT2_IDS(&snb_m_gt2_info),
874 	INTEL_IVB_Q_IDS(&ivb_q_info), /* must be first IVB */
875 	INTEL_IVB_M_GT1_IDS(&ivb_m_gt1_info),
876 	INTEL_IVB_M_GT2_IDS(&ivb_m_gt2_info),
877 	INTEL_IVB_D_GT1_IDS(&ivb_d_gt1_info),
878 	INTEL_IVB_D_GT2_IDS(&ivb_d_gt2_info),
879 	INTEL_HSW_GT1_IDS(&hsw_gt1_info),
880 	INTEL_HSW_GT2_IDS(&hsw_gt2_info),
881 	INTEL_HSW_GT3_IDS(&hsw_gt3_info),
882 	INTEL_VLV_IDS(&vlv_info),
883 	INTEL_BDW_GT1_IDS(&bdw_gt1_info),
884 	INTEL_BDW_GT2_IDS(&bdw_gt2_info),
885 	INTEL_BDW_GT3_IDS(&bdw_gt3_info),
886 	INTEL_BDW_RSVD_IDS(&bdw_rsvd_info),
887 	INTEL_CHV_IDS(&chv_info),
888 	INTEL_SKL_GT1_IDS(&skl_gt1_info),
889 	INTEL_SKL_GT2_IDS(&skl_gt2_info),
890 	INTEL_SKL_GT3_IDS(&skl_gt3_info),
891 	INTEL_SKL_GT4_IDS(&skl_gt4_info),
892 	INTEL_BXT_IDS(&bxt_info),
893 	INTEL_GLK_IDS(&glk_info),
894 	INTEL_KBL_GT1_IDS(&kbl_gt1_info),
895 	INTEL_KBL_GT2_IDS(&kbl_gt2_info),
896 	INTEL_KBL_GT3_IDS(&kbl_gt3_info),
897 	INTEL_KBL_GT4_IDS(&kbl_gt3_info),
898 	INTEL_AML_KBL_GT2_IDS(&kbl_gt2_info),
899 	INTEL_CFL_S_GT1_IDS(&cfl_gt1_info),
900 	INTEL_CFL_S_GT2_IDS(&cfl_gt2_info),
901 	INTEL_CFL_H_GT1_IDS(&cfl_gt1_info),
902 	INTEL_CFL_H_GT2_IDS(&cfl_gt2_info),
903 	INTEL_CFL_U_GT2_IDS(&cfl_gt2_info),
904 	INTEL_CFL_U_GT3_IDS(&cfl_gt3_info),
905 	INTEL_WHL_U_GT1_IDS(&cfl_gt1_info),
906 	INTEL_WHL_U_GT2_IDS(&cfl_gt2_info),
907 	INTEL_AML_CFL_GT2_IDS(&cfl_gt2_info),
908 	INTEL_WHL_U_GT3_IDS(&cfl_gt3_info),
909 	INTEL_CML_GT1_IDS(&cfl_gt1_info),
910 	INTEL_CML_GT2_IDS(&cfl_gt2_info),
911 	INTEL_CML_U_GT1_IDS(&cfl_gt1_info),
912 	INTEL_CML_U_GT2_IDS(&cfl_gt2_info),
913 	INTEL_CNL_IDS(&cnl_info),
914 	INTEL_ICL_11_IDS(&icl_info),
915 	INTEL_EHL_IDS(&ehl_info),
916 	INTEL_TGL_12_IDS(&tgl_info),
917 	{0, 0, 0}
918 };
919 MODULE_DEVICE_TABLE(pci, pciidlist);
920 
921 #ifdef __linux__
922 static void i915_pci_remove(struct pci_dev *pdev)
923 {
924 	struct drm_i915_private *i915;
925 
926 	i915 = pci_get_drvdata(pdev);
927 	if (!i915) /* driver load aborted, nothing to cleanup */
928 		return;
929 
930 	i915_driver_remove(i915);
931 	pci_set_drvdata(pdev, NULL);
932 
933 	drm_dev_put(&i915->drm);
934 }
935 
936 /* is device_id present in comma separated list of ids */
937 static bool force_probe(u16 device_id, const char *devices)
938 {
939 	char *s, *p, *tok;
940 	bool ret;
941 
942 	if (!devices || !*devices)
943 		return false;
944 
945 	/* match everything */
946 	if (strcmp(devices, "*") == 0)
947 		return true;
948 
949 	s = kstrdup(devices, GFP_KERNEL);
950 	if (!s)
951 		return false;
952 
953 	for (p = s, ret = false; (tok = strsep(&p, ",")) != NULL; ) {
954 		u16 val;
955 
956 		if (kstrtou16(tok, 16, &val) == 0 && val == device_id) {
957 			ret = true;
958 			break;
959 		}
960 	}
961 
962 	kfree(s);
963 
964 	return ret;
965 }
966 
967 static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
968 {
969 	struct intel_device_info *intel_info =
970 		(struct intel_device_info *) ent->driver_data;
971 	int err;
972 
973 	if (intel_info->require_force_probe &&
974 	    !force_probe(pdev->device, i915_modparams.force_probe)) {
975 		dev_info(&pdev->dev,
976 			 "Your graphics device %04x is not properly supported by the driver in this\n"
977 			 "kernel version. To force driver probe anyway, use i915.force_probe=%04x\n"
978 			 "module parameter or CONFIG_DRM_I915_FORCE_PROBE=%04x configuration option,\n"
979 			 "or (recommended) check for kernel updates.\n",
980 			 pdev->device, pdev->device, pdev->device);
981 		return -ENODEV;
982 	}
983 
984 	/* Only bind to function 0 of the device. Early generations
985 	 * used function 1 as a placeholder for multi-head. This causes
986 	 * us confusion instead, especially on the systems where both
987 	 * functions have the same PCI-ID!
988 	 */
989 	if (PCI_FUNC(pdev->devfn))
990 		return -ENODEV;
991 
992 	/*
993 	 * apple-gmux is needed on dual GPU MacBook Pro
994 	 * to probe the panel if we're the inactive GPU.
995 	 */
996 	if (vga_switcheroo_client_probe_defer(pdev))
997 		return -EPROBE_DEFER;
998 
999 	err = i915_driver_probe(pdev, ent);
1000 	if (err)
1001 		return err;
1002 
1003 	if (i915_inject_probe_failure(pci_get_drvdata(pdev))) {
1004 		i915_pci_remove(pdev);
1005 		return -ENODEV;
1006 	}
1007 
1008 	err = i915_live_selftests(pdev);
1009 	if (err) {
1010 		i915_pci_remove(pdev);
1011 		return err > 0 ? -ENOTTY : err;
1012 	}
1013 
1014 	err = i915_perf_selftests(pdev);
1015 	if (err) {
1016 		i915_pci_remove(pdev);
1017 		return err > 0 ? -ENOTTY : err;
1018 	}
1019 
1020 	return 0;
1021 }
1022 
1023 static struct pci_driver i915_pci_driver = {
1024 	.name = DRIVER_NAME,
1025 	.id_table = pciidlist,
1026 	.probe = i915_pci_probe,
1027 	.remove = i915_pci_remove,
1028 	.driver.pm = &i915_pm_ops,
1029 };
1030 
1031 static int __init i915_init(void)
1032 {
1033 	bool use_kms = true;
1034 	int err;
1035 
1036 	err = i915_globals_init();
1037 	if (err)
1038 		return err;
1039 
1040 	err = i915_mock_selftests();
1041 	if (err)
1042 		return err > 0 ? 0 : err;
1043 
1044 	/*
1045 	 * Enable KMS by default, unless explicitly overriden by
1046 	 * either the i915.modeset prarameter or by the
1047 	 * vga_text_mode_force boot option.
1048 	 */
1049 
1050 	if (i915_modparams.modeset == 0)
1051 		use_kms = false;
1052 
1053 	if (vgacon_text_force() && i915_modparams.modeset == -1)
1054 		use_kms = false;
1055 
1056 	if (!use_kms) {
1057 		/* Silently fail loading to not upset userspace. */
1058 		DRM_DEBUG_DRIVER("KMS disabled.\n");
1059 		return 0;
1060 	}
1061 
1062 	err = pci_register_driver(&i915_pci_driver);
1063 	if (err)
1064 		return err;
1065 
1066 	i915_perf_sysctl_register();
1067 	return 0;
1068 }
1069 
1070 static void __exit i915_exit(void)
1071 {
1072 	if (!i915_pci_driver.driver.owner)
1073 		return;
1074 
1075 	i915_perf_sysctl_unregister();
1076 	pci_unregister_driver(&i915_pci_driver);
1077 	i915_globals_exit();
1078 }
1079 #endif
1080 
1081 module_init(i915_init);
1082 module_exit(i915_exit);
1083 
1084 MODULE_AUTHOR("Tungsten Graphics, Inc.");
1085 MODULE_AUTHOR("Intel Corporation");
1086 
1087 MODULE_DESCRIPTION(DRIVER_DESC);
1088 MODULE_LICENSE("GPL and additional rights");
1089