Debian Codegraph @

src/soc/intel/common/block/graphics/graphics.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <acpi/acpi.h>
4 #include <bootmode.h>
5 #include <console/console.h>
6 #include <device/mmio.h>
7 #include <device/pci.h>
8 #include <device/pci_ids.h>
9 #include <drivers/intel/gma/i915.h>
10 #include <drivers/intel/gma/libgfxinit.h>
11 #include <drivers/intel/gma/opregion.h>
12 #include <intelblocks/cfg.h>
13 #include <intelblocks/graphics.h>
14 #include <fsp/graphics.h>
15 #include <fsp/util.h>
16 #include <soc/pci_devs.h>
17 #include <types.h>
18
19 /*
20 * This GUID is used to identify memory resources related to the memory bandwidth
21 * compression functionality for Intel Integrated Graphics Devices (IGD).
22 */
23 static const uint8_t memory_compression_guid[16] = {
24 0x79, 0x15, 0x9f, 0x8a, 0x72, 0xea, 0xb5, 0x4b,
25 0x90, 0x69, 0x54, 0x9a, 0x1b, 0xf7, 0xc4, 0xfd
26 };
27
28 /* Display Type:
29 * 0 - only internal display aka eDP attached
30 * 1 - only external display aka HDMI/USB-C attached
31 * 2 - dual display aka both internal and external display attached
32 */
33 enum display_type {
34 INTERNAL_DISPLAY_ONLY,
35 EXTERNAL_DISPLAY_ONLY,
36 DUAL_DISPLAY,
37 };
38
39 #define GFX_MBUS_CTL 0x4438C
40 #define GFX_MBUS_SEL(x) (GFX_MBUS_CTL + (x))
41 #define GFX_MBUS_JOIN BIT(31)
42 #define GFX_MBUS_HASHING_MODE BIT(30)
43 #define GFX_MBUS_JOIN_PIPE_SEL (BIT(28) | BIT(27) | BIT(26))
44
45 /* SoC Overrides */
46 __weak void graphics_soc_panel_init(struct device *dev)
47 {
48 /*
49 * User needs to implement SoC override in case wishes
50 * to perform certain specific graphics initialization
51 */
52 }
53
54 __weak const struct i915_gpu_controller_info *
55 intel_igd_get_controller_info(const struct device *device)
56 {
57 return NULL;
58 }
59
60 static uint32_t graphics_get_ddi_func_ctrl(unsigned long reg)
61 {
62 uint32_t ddi_func_ctrl = graphics_gtt_read(reg);
63 ddi_func_ctrl &= TRANS_DDI_PORT_MASK;
64
65 return ddi_func_ctrl;
66 }
67
68 /*
69 * Transcoders contain the timing generators for eDP, DP, and HDMI interfaces.
70 * Intel transcoders are based on Quick Sync Video, which offloads video
71 * encoding and decoding tasks from the CPU to the GPU.
72 *
73 * On Intel silicon, there are four display pipes (DDI-A to DDI-D) that support
74 * blending, color adjustments, scaling, and dithering.
75 *
76 * From the display block diagram perspective, the front end of the display
77 * contains the pipes. The pipes connect to the transcoder. The transcoder
78 * (except for wireless) connects to the DDIs to drive the IO/PHY.
79 *
80 * This logic checks if the DDI-A port is attached to the transcoder and
81 * enabled (bit 27). Traditionally, the on-board display (eDP) is attached to DDI-A.
82 * If the above conditions is met, then the on-board display is present and enabled.
83 *
84 * On platforms without an on-board display (i.e., value at bits 27-30 is between 2-9),
85 * meaning that DDI-A (eDP) is not enabled.
86 *
87 * Additionally, if bits 27-30 are all set to 0, this means that no DDI ports
88 * are enabled, and there is no display.
89 *
90 * Consider external display is present and enabled, if eDP/DDI-A is not enabled
91 * and transcoder is attached to any DDI port (bits 27-30 are not zero).
92 */
93 static enum display_type get_external_display_status(void)
94 {
95 /* Read the transcoder register for DDI-A (eDP) */
96 uint32_t ddi_a_func_ctrl = graphics_get_ddi_func_ctrl(TRANS_DDI_FUNC_CTL_A);
97 /* Read the transcoder register for DDI-B (HDMI) */
98 uint32_t ddi_b_func_ctrl = graphics_get_ddi_func_ctrl(TRANS_DDI_FUNC_CTL_B);
99
100 /*
101 * Check if transcoder is none or connected to DDI-A port (aka eDP).
102 * Report no external display in both cases.
103 */
104 if (ddi_a_func_ctrl == TRANS_DDI_PORT_NONE) {
105 return INTERNAL_DISPLAY_ONLY;
106 } else {
107 if (ddi_a_func_ctrl == TRANS_DDI_SELECT_PORT(PORT_A) &&
108 (ddi_b_func_ctrl == TRANS_DDI_SELECT_PORT(PORT_B)
109 #if CONFIG(INTEL_GMA_VERSION_2)
110 || ddi_b_func_ctrl == TRANS_DDI_SELECT_PORT(PORT_USB_C1)
111 || ddi_b_func_ctrl == TRANS_DDI_SELECT_PORT(PORT_USB_C2)
112 || ddi_b_func_ctrl == TRANS_DDI_SELECT_PORT(PORT_USB_C3)
113 || ddi_b_func_ctrl == TRANS_DDI_SELECT_PORT(PORT_USB_C4)
114 #endif
115 )) {
116 /*
117 * Dual display detected: both DDI-A(eDP) and
118 * DDI-B(HDMI) pipes are active
119 */
120 return DUAL_DISPLAY;
121 } else {
122 if (ddi_a_func_ctrl == TRANS_DDI_SELECT_PORT(PORT_A))
123 return INTERNAL_DISPLAY_ONLY;
124 else
125 return EXTERNAL_DISPLAY_ONLY;
126 }
127 }
128 }
129
130 /* Check and report if an external display is attached */
131 int fsp_soc_report_external_display(void)
132 {
133 return graphics_get_framebuffer_address() && get_external_display_status();
134 }
135
136 static void configure_ddi_a_bifurcation(void)
137 {
138 u32 ddi_buf_ctl = graphics_gtt_read(DDI_BUF_CTL_A);
139 /* Only program if the buffer is not enabled yet. */
140 if (ddi_buf_ctl & DDI_BUF_CTL_ENABLE)
141 return;
142
143 if (CONFIG(SOC_INTEL_GFX_ENABLE_DDI_E_BIFURCATION))
144 ddi_buf_ctl &= ~DDI_A_4_LANES;
145 else
146 ddi_buf_ctl |= DDI_A_4_LANES;
147
148 graphics_gtt_write(DDI_BUF_CTL_A, ddi_buf_ctl);
149 }
150
151 static void gma_init(struct device *const dev)
152 {
153 intel_gma_init_igd_opregion();
154
155 /* SoC specific panel init/configuration.
156 If FSP has already run/configured the IGD, we can assume the
157 panel/backlight control have already been set up sufficiently
158 and that we shouldn't attempt to reconfigure things. */
159 if (!CONFIG(RUN_FSP_GOP))
160 graphics_soc_panel_init(dev);
161
162 if (CONFIG(SOC_INTEL_GFX_HAVE_DDI_A_BIFURCATION) && !acpi_is_wakeup_s3())
163 configure_ddi_a_bifurcation();
164
165 /*
166 * GFX PEIM module inside FSP binary is taking care of graphics
167 * initialization based on RUN_FSP_GOP Kconfig option and input
168 * VBT file. Need to report the framebuffer info after PCI enumeration.
169 *
170 * In case of non-FSP solution, SoC need to select another
171 * Kconfig to perform GFX initialization.
172 */
173 if (CONFIG(RUN_FSP_GOP) && display_init_required()) {
174 const struct soc_intel_common_config *config = chip_get_common_soc_structure();
175 fsp_report_framebuffer_info(graphics_get_framebuffer_address(),
176 config->panel_orientation);
177 return;
178 }
179
180 if (!CONFIG(NO_GFX_INIT))
181 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
182
183 if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
184 if (!acpi_is_wakeup_s3() && display_init_required()) {
185 int lightup_ok;
186 gma_gfxinit(&lightup_ok);
187 gfx_set_init_done(lightup_ok);
188 }
189 } else {
190 /* Initialize PCI device, load/execute BIOS Option ROM */
191 pci_dev_init(dev);
192 }
193 }
194
195 static void gma_generate_ssdt(const struct device *device)
196 {
197 const struct i915_gpu_controller_info *gfx = intel_igd_get_controller_info(device);
198
199 if (gfx)
200 drivers_intel_gma_displays_ssdt_generate(gfx);
201 }
202
203 static int is_graphics_disabled(struct device *dev)
204 {
205 /* Check if Graphics PCI device is disabled */
206 if (!dev || !dev->enabled)
207 return 1;
208
209 return 0;
210 }
211
212 static uintptr_t graphics_get_bar(struct device *dev, unsigned long index)
213 {
214 struct resource *gm_res;
215
216 gm_res = probe_resource(dev, index);
217 if (!gm_res)
218 return 0;
219
220 return gm_res->base;
221 }
222
223 uintptr_t graphics_get_framebuffer_address(void)
224 {
225 uintptr_t memory_base;
226 struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
227
228 if (is_graphics_disabled(dev))
229 return 0;
230
231 memory_base = graphics_get_bar(dev, PCI_BASE_ADDRESS_2);
232 if (!memory_base)
233 die_with_post_code(POSTCODE_HW_INIT_FAILURE,
234 "Graphic memory bar2 is not programmed!");
235
236 memory_base += CONFIG_SOC_INTEL_GFX_FRAMEBUFFER_OFFSET;
237
238 return memory_base;
239 }
240
241 static uintptr_t graphics_get_gtt_base(void)
242 {
243 static uintptr_t gtt_base;
244 struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
245
246 if (is_graphics_disabled(dev))
247 die("IGD is disabled!");
248 /*
249 * GFX PCI config space offset 0x10 know as Graphics
250 * Translation Table Memory Mapped Range Address
251 * (GTTMMADR)
252 */
253 if (!gtt_base) {
254 gtt_base = graphics_get_bar(dev, PCI_BASE_ADDRESS_0);
255 if (!gtt_base)
256 die_with_post_code(POSTCODE_HW_INIT_FAILURE,
257 "GTTMMADR is not programmed!");
258 }
259 return gtt_base;
260 }
261
262 uint32_t graphics_gtt_read(unsigned long reg)
263 {
264 return read32p(graphics_get_gtt_base() + reg);
265 }
266
267 void graphics_gtt_write(unsigned long reg, uint32_t data)
268 {
269 write32p(graphics_get_gtt_base() + reg, data);
270 }
271
272 void graphics_gtt_rmw(unsigned long reg, uint32_t andmask, uint32_t ormask)
273 {
274 uint32_t val = graphics_gtt_read(reg);
275 val &= andmask;
276 val |= ormask;
277 graphics_gtt_write(reg, val);
278 }
279
280 static void graphics_dev_read_resources(struct device *dev)
281 {
282 pci_dev_read_resources(dev);
283
284 if (CONFIG(SOC_INTEL_GFX_NON_PREFETCHABLE_MMIO)) {
285 struct resource *res_bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
286 if (res_bar0->flags & IORESOURCE_PREFETCH)
287 res_bar0->flags &= ~IORESOURCE_PREFETCH;
288 }
289
290 /*
291 * If libhwbase static MMIO driver is used, IGD BAR 0 has to be set to
292 * CONFIG_GFX_GMA_DEFAULT_MMIO for the libgfxinit to operate properly.
293 */
294 if (CONFIG(MAINBOARD_USE_LIBGFXINIT) && CONFIG(HWBASE_STATIC_MMIO)) {
295 struct resource *res_bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
296 res_bar0->base = CONFIG_GFX_GMA_DEFAULT_MMIO;
297 res_bar0->flags |= IORESOURCE_ASSIGNED;
298 pci_dev_set_resources(dev);
299 res_bar0->flags |= IORESOURCE_FIXED;
300 }
301
302 const struct hob_resource *res =
303 fsp_find_resource_hob_by_guid(memory_compression_guid);
304 if (res) {
305 printk(BIOS_DEBUG,
306 "Memory Compression HOB found: base=0x%08llx length=0x%08llx\n",
307 res->addr, res->length);
308 reserved_ram_range(dev, 0, res->addr, res->length);
309 }
310 }
311
312 static void graphics_join_mbus(void)
313 {
314 enum display_type type = get_external_display_status();
315 uint32_t hashing_mode = 0; /* 2x2 */
316 if (type == INTERNAL_DISPLAY_ONLY) {
317 hashing_mode = GFX_MBUS_HASHING_MODE; /* 1x4 */
318 /* Only eDP pipes is joining the MBUS */
319 graphics_gtt_rmw(GFX_MBUS_SEL(PIPE_A), PIPE_A, GFX_MBUS_JOIN | hashing_mode);
320 } else if (type == DUAL_DISPLAY) {
321 /* All pipes are joining the MBUS */
322 graphics_gtt_rmw(GFX_MBUS_SEL(PIPE_A), PIPE_A, GFX_MBUS_JOIN | hashing_mode);
323 graphics_gtt_rmw(GFX_MBUS_SEL(PIPE_B), PIPE_B, GFX_MBUS_JOIN | hashing_mode);
324 graphics_gtt_rmw(GFX_MBUS_SEL(PIPE_C), PIPE_C, GFX_MBUS_JOIN | hashing_mode);
325 #if CONFIG(INTEL_GMA_VERSION_2)
326 graphics_gtt_rmw(GFX_MBUS_SEL(PIPE_D), PIPE_D, GFX_MBUS_JOIN | hashing_mode);
327 #endif
328 } else {
329 /* No pipe joins the MBUS */
330 graphics_gtt_rmw(GFX_MBUS_CTL, GFX_MBUS_JOIN_PIPE_SEL,
331 GFX_MBUS_JOIN | hashing_mode);
332 }
333 }
334
335 static void graphics_dev_final(struct device *dev)
336 {
337 pci_dev_request_bus_master(dev);
338
339 /*
340 * Call function to join the MBUS if GFX PEIM module inside FSP
341 * binary is taking care of graphics initialization based on
342 * RUN_FSP_GOP config option.
343 *
344 * Skip FW joining the MBUS in case of non-FSP solution.
345 */
346 if (CONFIG(RUN_FSP_GOP) && CONFIG(SOC_INTEL_GFX_MBUS_JOIN) && display_init_required())
347 graphics_join_mbus();
348 }
349
350 const struct device_operations graphics_ops = {
351 .read_resources = graphics_dev_read_resources,
352 .set_resources = pci_dev_set_resources,
353 .enable_resources = pci_dev_enable_resources,
354 .init = gma_init,
355 .final = graphics_dev_final,
356 .ops_pci = &pci_dev_ops_pci,
357 #if CONFIG(HAVE_ACPI_TABLES)
358 .acpi_fill_ssdt = gma_generate_ssdt,
359 #endif
360 .scan_bus = scan_generic_bus,
361 };
362
363 static const unsigned short pci_device_ids[] = {
364 PCI_DID_INTEL_WCL_GT2_1,
365 PCI_DID_INTEL_WCL_GT2_2,
366 PCI_DID_INTEL_PTL_U_GT2_1,
367 PCI_DID_INTEL_PTL_H_GT2_1,
368 PCI_DID_INTEL_PTL_H_GT2_2,
369 PCI_DID_INTEL_PTL_H_GT2_3,
370 PCI_DID_INTEL_PTL_H_GT2_4,
371 PCI_DID_INTEL_LNL_M_GT2,
372 PCI_DID_INTEL_RPL_U_GT1,
373 PCI_DID_INTEL_RPL_U_GT2,
374 PCI_DID_INTEL_RPL_U_GT3,
375 PCI_DID_INTEL_RPL_U_GT4,
376 PCI_DID_INTEL_RPL_U_GT5,
377 PCI_DID_INTEL_RPL_P_GT1,
378 PCI_DID_INTEL_RPL_P_GT2,
379 PCI_DID_INTEL_RPL_P_GT3,
380 PCI_DID_INTEL_RPL_P_GT4,
381 PCI_DID_INTEL_RPL_P_GT5,
382 PCI_DID_INTEL_MTL_M_GT2,
383 PCI_DID_INTEL_MTL_P_GT2_1,
384 PCI_DID_INTEL_MTL_P_GT2_2,
385 PCI_DID_INTEL_MTL_P_GT2_3,
386 PCI_DID_INTEL_MTL_P_GT2_4,
387 PCI_DID_INTEL_MTL_P_GT2_5,
388 PCI_DID_INTEL_ARL_H_GT2_1,
389 PCI_DID_INTEL_ARL_H_GT2_2,
390 PCI_DID_INTEL_APL_IGD_HD_505,
391 PCI_DID_INTEL_APL_IGD_HD_500,
392 PCI_DID_INTEL_CNL_GT2_ULX_1,
393 PCI_DID_INTEL_CNL_GT2_ULX_2,
394 PCI_DID_INTEL_CNL_GT2_ULX_3,
395 PCI_DID_INTEL_CNL_GT2_ULX_4,
396 PCI_DID_INTEL_CNL_GT2_ULT_1,
397 PCI_DID_INTEL_CNL_GT2_ULT_2,
398 PCI_DID_INTEL_CNL_GT2_ULT_3,
399 PCI_DID_INTEL_CNL_GT2_ULT_4,
400 PCI_DID_INTEL_GLK_IGD,
401 PCI_DID_INTEL_GLK_IGD_EU12,
402 PCI_DID_INTEL_WHL_GT1_ULT_1,
403 PCI_DID_INTEL_WHL_GT2_ULT_1,
404 PCI_DID_INTEL_AML_GT2_ULX,
405 PCI_DID_INTEL_CFL_H_GT2,
406 PCI_DID_INTEL_CFL_H_XEON_GT2,
407 PCI_DID_INTEL_CFL_S_GT1_1,
408 PCI_DID_INTEL_CFL_S_GT1_2,
409 PCI_DID_INTEL_CFL_S_GT2_1,
410 PCI_DID_INTEL_CFL_S_GT2_2,
411 PCI_DID_INTEL_CFL_S_GT2_3,
412 PCI_DID_INTEL_CFL_S_GT2_4,
413 PCI_DID_INTEL_CFL_S_GT2_5,
414 PCI_DID_INTEL_CML_GT1_ULT_1,
415 PCI_DID_INTEL_CML_GT1_ULT_2,
416 PCI_DID_INTEL_CML_GT2_ULT_1,
417 PCI_DID_INTEL_CML_GT2_ULT_2,
418 PCI_DID_INTEL_CML_GT1_ULT_3,
419 PCI_DID_INTEL_CML_GT1_ULT_4,
420 PCI_DID_INTEL_CML_GT2_ULT_5,
421 PCI_DID_INTEL_CML_GT2_ULT_6,
422 PCI_DID_INTEL_CML_GT2_ULT_7,
423 PCI_DID_INTEL_CML_GT2_ULT_8,
424 PCI_DID_INTEL_CML_GT2_ULT_3,
425 PCI_DID_INTEL_CML_GT2_ULT_4,
426 PCI_DID_INTEL_CML_GT1_ULX_1,
427 PCI_DID_INTEL_CML_GT2_ULX_1,
428 PCI_DID_INTEL_CML_GT1_S_1,
429 PCI_DID_INTEL_CML_GT1_S_2,
430 PCI_DID_INTEL_CML_GT1_H_1,
431 PCI_DID_INTEL_CML_GT1_H_2,
432 PCI_DID_INTEL_CML_GT2_S_G0,
433 PCI_DID_INTEL_CML_GT2_S_P0,
434 PCI_DID_INTEL_CML_GT2_H_R0,
435 PCI_DID_INTEL_CML_GT2_H_R1,
436 PCI_DID_INTEL_TGL_GT0,
437 PCI_DID_INTEL_TGL_GT1_H_32,
438 PCI_DID_INTEL_TGL_GT1_H_16,
439 PCI_DID_INTEL_TGL_GT2_ULT,
440 PCI_DID_INTEL_TGL_GT2_ULX,
441 PCI_DID_INTEL_TGL_GT3_ULT,
442 PCI_DID_INTEL_TGL_GT2_ULT_1,
443 PCI_DID_INTEL_EHL_GT1_1,
444 PCI_DID_INTEL_EHL_GT2_1,
445 PCI_DID_INTEL_EHL_GT1_2,
446 PCI_DID_INTEL_EHL_GT2_2,
447 PCI_DID_INTEL_EHL_GT1_2_1,
448 PCI_DID_INTEL_EHL_GT1_3,
449 PCI_DID_INTEL_EHL_GT2_3,
450 PCI_DID_INTEL_JSL_GT1,
451 PCI_DID_INTEL_JSL_GT2,
452 PCI_DID_INTEL_JSL_GT3,
453 PCI_DID_INTEL_JSL_GT4,
454 PCI_DID_INTEL_ADL_GT0,
455 PCI_DID_INTEL_ADL_GT1,
456 PCI_DID_INTEL_ADL_GT1_1,
457 PCI_DID_INTEL_ADL_GT1_2,
458 PCI_DID_INTEL_ADL_GT1_3,
459 PCI_DID_INTEL_ADL_GT1_4,
460 PCI_DID_INTEL_ADL_GT1_5,
461 PCI_DID_INTEL_ADL_GT1_6,
462 PCI_DID_INTEL_ADL_GT1_7,
463 PCI_DID_INTEL_ADL_GT1_8,
464 PCI_DID_INTEL_ADL_GT1_9,
465 PCI_DID_INTEL_ADL_P_GT2,
466 PCI_DID_INTEL_ADL_P_GT2_1,
467 PCI_DID_INTEL_ADL_P_GT2_2,
468 PCI_DID_INTEL_ADL_P_GT2_3,
469 PCI_DID_INTEL_ADL_P_GT2_4,
470 PCI_DID_INTEL_ADL_P_GT2_5,
471 PCI_DID_INTEL_ADL_P_GT2_6,
472 PCI_DID_INTEL_ADL_P_GT2_7,
473 PCI_DID_INTEL_ADL_P_GT2_8,
474 PCI_DID_INTEL_ADL_P_GT2_9,
475 PCI_DID_INTEL_ADL_S_GT1,
476 PCI_DID_INTEL_ADL_S_GT1_1,
477 PCI_DID_INTEL_ADL_S_GT2,
478 PCI_DID_INTEL_ADL_S_GT2_1,
479 PCI_DID_INTEL_ADL_S_GT2_2,
480 PCI_DID_INTEL_ADL_M_GT1,
481 PCI_DID_INTEL_ADL_M_GT2,
482 PCI_DID_INTEL_ADL_M_GT3,
483 PCI_DID_INTEL_ADL_N_GT1,
484 PCI_DID_INTEL_ADL_N_GT2,
485 PCI_DID_INTEL_ADL_N_GT3,
486 PCI_DID_INTEL_ADL_N_GT4,
487 PCI_DID_INTEL_ADL_N_GT5,
488 PCI_DID_INTEL_RPL_S_GT0,
489 PCI_DID_INTEL_RPL_S_GT1_1,
490 PCI_DID_INTEL_RPL_S_GT1_2,
491 PCI_DID_INTEL_RPL_S_GT1_3,
492 PCI_DID_INTEL_RPL_HX_GT1,
493 PCI_DID_INTEL_RPL_HX_GT2,
494 PCI_DID_INTEL_RPL_HX_GT3,
495 PCI_DID_INTEL_RPL_HX_GT4,
496 PCI_DID_INTEL_TWL_GT1_1,
497 PCI_DID_INTEL_TWL_GT1_2,
498 0,
499 };
500
501 static const struct pci_driver graphics_driver __pci_driver = {
502 .ops = &graphics_ops,
503 .vendor = PCI_VID_INTEL,
504 .devices = pci_device_ids,
505 };