coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
graphics.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <acpi/acpi.h>
4 #include <assert.h>
5 #include <bootmode.h>
6 #include <console/console.h>
7 #include <device/mmio.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <drivers/intel/gma/i915.h>
13 #include <intelblocks/cfg.h>
14 #include <intelblocks/graphics.h>
15 #include <fsp/graphics.h>
16 #include <soc/pci_devs.h>
17 #include <types.h>
18 
19 /* SoC Overrides */
21 {
22  /*
23  * User needs to implement SoC override in case wishes
24  * to perform certain specific graphics initialization
25  */
26 }
27 
28 __weak const struct i915_gpu_controller_info *
30 {
31  return NULL;
32 }
33 
34 static void gma_init(struct device *const dev)
35 {
37 
38  /* SoC specific panel init/configuration.
39  If FSP has already run/configured the IGD, we can assume the
40  panel/backlight control have already been set up sufficiently
41  and that we shouldn't attempt to reconfigure things. */
42  if (!CONFIG(RUN_FSP_GOP))
44 
45  if (CONFIG(SOC_INTEL_CONFIGURE_DDI_A_4_LANES) && !acpi_is_wakeup_s3()) {
46  const u32 ddi_buf_ctl = graphics_gtt_read(DDI_BUF_CTL_A);
47  /* Only program if the buffer is not enabled yet. */
48  if (!(ddi_buf_ctl & DDI_BUF_CTL_ENABLE))
50  }
51 
52  /*
53  * GFX PEIM module inside FSP binary is taking care of graphics
54  * initialization based on RUN_FSP_GOP Kconfig option and input
55  * VBT file. Need to report the framebuffer info after PCI enumeration.
56  *
57  * In case of non-FSP solution, SoC need to select another
58  * Kconfig to perform GFX initialization.
59  */
60  if (CONFIG(RUN_FSP_GOP)) {
63  config->panel_orientation);
64  return;
65  }
66 
67  if (!CONFIG(NO_GFX_INIT))
69 
70  if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
72  int lightup_ok;
73  gma_gfxinit(&lightup_ok);
74  gfx_set_init_done(lightup_ok);
75  }
76  } else {
77  /* Initialize PCI device, load/execute BIOS Option ROM */
78  pci_dev_init(dev);
79  }
80 }
81 
82 static void gma_generate_ssdt(const struct device *device)
83 {
85 
86  if (gfx)
88 }
89 
90 static int is_graphics_disabled(struct device *dev)
91 {
92  /* Check if Graphics PCI device is disabled */
93  if (!dev || !dev->enabled)
94  return 1;
95 
96  return 0;
97 }
98 
99 static uintptr_t graphics_get_bar(struct device *dev, unsigned long index)
100 {
101  struct resource *gm_res;
102 
103  gm_res = probe_resource(dev, index);
104  if (!gm_res)
105  return 0;
106 
107  return gm_res->base;
108 }
109 
111 {
112  uintptr_t memory_base;
113  struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
114 
115  if (is_graphics_disabled(dev))
116  return 0;
117 
118  memory_base = graphics_get_bar(dev, PCI_BASE_ADDRESS_2);
119  if (!memory_base)
121  "Graphic memory bar2 is not programmed!");
122 
123  memory_base += CONFIG_SOC_INTEL_GFX_FRAMEBUFFER_OFFSET;
124 
125  return memory_base;
126 }
127 
129 {
130  static uintptr_t gtt_base;
131  struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
132 
133  if (is_graphics_disabled(dev))
134  die("IGD is disabled!");
135  /*
136  * GFX PCI config space offset 0x10 know as Graphics
137  * Translation Table Memory Mapped Range Address
138  * (GTTMMADR)
139  */
140  if (!gtt_base) {
141  gtt_base = graphics_get_bar(dev, PCI_BASE_ADDRESS_0);
142  if (!gtt_base)
144  "GTTMMADR is not programmed!");
145  }
146  return gtt_base;
147 }
148 
149 uint32_t graphics_gtt_read(unsigned long reg)
150 {
151  return read32((void *)(graphics_get_gtt_base() + reg));
152 }
153 
154 void graphics_gtt_write(unsigned long reg, uint32_t data)
155 {
156  write32((void *)(graphics_get_gtt_base() + reg), data);
157 }
158 
159 void graphics_gtt_rmw(unsigned long reg, uint32_t andmask, uint32_t ormask)
160 {
162  val &= andmask;
163  val |= ormask;
164  graphics_gtt_write(reg, val);
165 }
166 
167 static const struct device_operations graphics_ops = {
169  .set_resources = pci_dev_set_resources,
170  .enable_resources = pci_dev_enable_resources,
171  .init = gma_init,
172  .ops_pci = &pci_dev_ops_pci,
173 #if CONFIG(HAVE_ACPI_TABLES)
174  .acpi_fill_ssdt = gma_generate_ssdt,
175 #endif
176  .scan_bus = scan_generic_bus,
177 };
178 
179 static const unsigned short pci_device_ids[] = {
322  0,
323 };
324 
325 static const struct pci_driver graphics_driver __pci_driver = {
326  .ops = &graphics_ops,
327  .vendor = PCI_VID_INTEL,
328  .devices = pci_device_ids,
329 };
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
int display_init_required(void)
Definition: bootmode.c:22
void gfx_set_init_done(int done)
Definition: bootmode.c:17
void __noreturn die(const char *fmt,...)
Definition: die.c:17
#define die_with_post_code(value, fmt,...)
Definition: console.h:21
DEVTREE_CONST struct device * pcidev_path_on_root(pci_devfn_t devfn)
Definition: device_const.c:255
struct resource * probe_resource(const struct device *dev, unsigned int index)
See if a resource structure already exists for a given index.
Definition: device_util.c:323
void fsp_report_framebuffer_info(const uintptr_t framebuffer_bar, enum lb_fb_orientation orientation)
Definition: graphics.c:52
void drivers_intel_gma_displays_ssdt_generate(const struct i915_gpu_controller_info *conf)
Definition: acpi.c:8
@ CONFIG
Definition: dsi_common.h:201
#define DDI_BUF_CTL_ENABLE
Definition: i915_reg.h:4234
#define DDI_BUF_CTL_A
Definition: i915_reg.h:4231
#define DDI_A_4_LANES
Definition: i915_reg.h:4246
static __always_inline void pci_or_config16(const struct device *dev, u16 reg, u16 ormask)
Definition: pci_ops.h:180
void gma_gfxinit(int *lightup_ok)
enum board_config config
Definition: memory.c:448
enum cb_err intel_gma_init_igd_opregion(void)
Definition: opregion.c:310
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#define PCI_BASE_ADDRESS_2
Definition: pci_def.h:65
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_COMMAND
Definition: pci_def.h:10
void pci_dev_init(struct device *dev)
Default handler: only runs the relevant PCI BIOS.
Definition: pci_device.c:873
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
struct pci_operations pci_dev_ops_pci
Default device operation for PCI devices.
Definition: pci_device.c:911
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_DID_INTEL_SKL_GT2_SHALM
Definition: pci_ids.h:3817
#define PCI_DID_INTEL_ICL_GT2_ULT_1
Definition: pci_ids.h:3873
#define PCI_DID_INTEL_SKL_GT3_SULTM
Definition: pci_ids.h:3820
#define PCI_DID_INTEL_ADL_P_GT2_5
Definition: pci_ids.h:3947
#define PCI_DID_INTEL_ICL_GT3_ULT
Definition: pci_ids.h:3883
#define PCI_DID_INTEL_CML_GT2_ULT_6
Definition: pci_ids.h:3891
#define PCI_DID_INTEL_CML_GT1_S_1
Definition: pci_ids.h:3896
#define PCI_DID_INTEL_ADL_N_GT1
Definition: pci_ids.h:3956
#define PCI_DID_INTEL_JSL_GT3
Definition: pci_ids.h:3928
#define PCI_DID_INTEL_CML_GT1_ULT_1
Definition: pci_ids.h:3884
#define PCI_DID_INTEL_ADL_GT1_6
Definition: pci_ids.h:3938
#define PCI_DID_INTEL_ADL_GT1_8
Definition: pci_ids.h:3940
#define PCI_DID_INTEL_CFL_H_GT2
Definition: pci_ids.h:3859
#define PCI_DID_INTEL_EHL_GT1_2
Definition: pci_ids.h:3921
#define PCI_DID_INTEL_ADL_GT1_3
Definition: pci_ids.h:3935
#define PCI_DID_INTEL_CNL_GT2_ULT_4
Definition: pci_ids.h:3857
#define PCI_DID_INTEL_SKL_GT4_SHALM
Definition: pci_ids.h:3824
#define PCI_DID_INTEL_SKL_GT4E_SWSTM
Definition: pci_ids.h:3825
#define PCI_DID_INTEL_CML_GT2_ULT_4
Definition: pci_ids.h:3893
#define PCI_DID_INTEL_SKL_GT3FE_SSRVM
Definition: pci_ids.h:3823
#define PCI_DID_INTEL_ADL_P_GT2_2
Definition: pci_ids.h:3944
#define PCI_DID_INTEL_ADL_GT1_5
Definition: pci_ids.h:3937
#define PCI_DID_INTEL_ICL_GT2_ULX_3
Definition: pci_ids.h:3876
#define PCI_DID_INTEL_ADL_M_GT1
Definition: pci_ids.h:3953
#define PCI_DID_INTEL_JSL_GT2
Definition: pci_ids.h:3927
#define PCI_DID_INTEL_ICL_GT2_ULT_4
Definition: pci_ids.h:3879
#define PCI_DID_INTEL_WHL_GT2_ULT_1
Definition: pci_ids.h:3849
#define PCI_DID_INTEL_CNL_GT2_ULX_2
Definition: pci_ids.h:3851
#define PCI_DID_INTEL_AML_GT2_ULX
Definition: pci_ids.h:3843
#define PCI_DID_INTEL_CML_GT2_S_1
Definition: pci_ids.h:3898
#define PCI_DID_INTEL_KBL_GT1_SULTM
Definition: pci_ids.h:3827
#define PCI_DID_INTEL_KBL_GT1_SSRVM
Definition: pci_ids.h:3829
#define PCI_DID_INTEL_CML_GT2_ULT_2
Definition: pci_ids.h:3887
#define PCI_DID_INTEL_EHL_GT2_1
Definition: pci_ids.h:3920
#define PCI_DID_INTEL_ICL_GT2_ULT_5
Definition: pci_ids.h:3881
#define PCI_DID_INTEL_SKL_GT2_SULTM
Definition: pci_ids.h:3816
#define PCI_DID_INTEL_TGL_GT0
Definition: pci_ids.h:3912
#define PCI_DID_INTEL_KBL_GT2_DT2P2
Definition: pci_ids.h:3831
#define PCI_DID_INTEL_CFL_S_GT2_4
Definition: pci_ids.h:3866
#define PCI_DID_INTEL_CML_GT1_ULX_1
Definition: pci_ids.h:3894
#define PCI_DID_INTEL_CML_GT2_ULX_1
Definition: pci_ids.h:3895
#define PCI_DID_INTEL_ADL_P_GT2
Definition: pci_ids.h:3942
#define PCI_DID_INTEL_ADL_P_GT2_7
Definition: pci_ids.h:3949
#define PCI_DID_INTEL_KBL_GT2_SULTM
Definition: pci_ids.h:3832
#define PCI_DID_INTEL_ADL_P_GT2_3
Definition: pci_ids.h:3945
#define PCI_DID_INTEL_CNL_GT2_ULX_3
Definition: pci_ids.h:3852
#define PCI_DID_INTEL_KBL_GT2_SHALM
Definition: pci_ids.h:3836
#define PCI_DID_INTEL_KBL_GT4_SHALM
Definition: pci_ids.h:3841
#define PCI_DID_INTEL_ADL_P_GT2_8
Definition: pci_ids.h:3950
#define PCI_DID_INTEL_ADL_P_GT2_1
Definition: pci_ids.h:3943
#define PCI_DID_INTEL_TGL_GT3_ULT
Definition: pci_ids.h:3916
#define PCI_DID_INTEL_KBL_GT3E_SULTM_1
Definition: pci_ids.h:3839
#define PCI_DID_INTEL_CML_GT2_S_2
Definition: pci_ids.h:3899
#define PCI_DID_INTEL_CFL_S_GT2_2
Definition: pci_ids.h:3864
#define PCI_DID_INTEL_CML_GT2_S_G0
Definition: pci_ids.h:3904
#define PCI_DID_INTEL_CML_GT2_ULT_1
Definition: pci_ids.h:3886
#define PCI_DID_INTEL_ADL_GT1_4
Definition: pci_ids.h:3936
#define PCI_DID_INTEL_KBL_GT1_SHALM_2
Definition: pci_ids.h:3830
#define PCI_DID_INTEL_KBL_GT2_SWSTM
Definition: pci_ids.h:3837
#define PCI_DID_INTEL_CML_GT2_H_R1
Definition: pci_ids.h:3907
#define PCI_DID_INTEL_CFL_S_GT2_3
Definition: pci_ids.h:3865
#define PCI_DID_INTEL_ICL_GT2_ULX_0
Definition: pci_ids.h:3871
#define PCI_DID_INTEL_CFL_S_GT1_1
Definition: pci_ids.h:3861
#define PCI_DID_INTEL_CNL_GT2_ULT_3
Definition: pci_ids.h:3856
#define PCI_DID_INTEL_ADL_GT1_9
Definition: pci_ids.h:3941
#define PCI_DID_INTEL_GLK_IGD_EU12
Definition: pci_ids.h:3847
#define PCI_DID_INTEL_ADL_M_GT2
Definition: pci_ids.h:3954
#define PCI_DID_INTEL_TGL_GT2_ULT_1
Definition: pci_ids.h:3918
#define PCI_DID_INTEL_CNL_GT2_ULT_2
Definition: pci_ids.h:3855
#define PCI_DID_INTEL_CML_GT1_ULT_3
Definition: pci_ids.h:3888
#define PCI_DID_INTEL_CML_GT1_ULT_4
Definition: pci_ids.h:3889
#define PCI_DID_INTEL_CML_GT2_H_1
Definition: pci_ids.h:3902
#define PCI_DID_INTEL_CML_GT1_H_2
Definition: pci_ids.h:3901
#define PCI_DID_INTEL_ICL_GT2_ULX_4
Definition: pci_ids.h:3878
#define PCI_DID_INTEL_ADL_P_GT2_4
Definition: pci_ids.h:3946
#define PCI_DID_INTEL_KBL_GT2_SSRVM
Definition: pci_ids.h:3835
#define PCI_DID_INTEL_MTL_M_GT2
Definition: pci_ids.h:3959
#define PCI_DID_INTEL_KBL_GT3E_SULTM_2
Definition: pci_ids.h:3840
#define PCI_DID_INTEL_TGL_GT1_H_16
Definition: pci_ids.h:3914
#define PCI_DID_INTEL_ADL_N_GT2
Definition: pci_ids.h:3957
#define PCI_DID_INTEL_KBL_GT1F_DT2
Definition: pci_ids.h:3826
#define PCI_DID_INTEL_CML_GT2_S_P0
Definition: pci_ids.h:3905
#define PCI_DID_INTEL_ADL_P_GT2_6
Definition: pci_ids.h:3948
#define PCI_DID_INTEL_KBL_GT2_SULTMR
Definition: pci_ids.h:3833
#define PCI_DID_INTEL_ADL_P_GT2_9
Definition: pci_ids.h:3951
#define PCI_DID_INTEL_SKL_GT2_SULXM
Definition: pci_ids.h:3819
#define PCI_DID_INTEL_CNL_GT2_ULX_4
Definition: pci_ids.h:3853
#define PCI_DID_INTEL_TGL_GT1_H_32
Definition: pci_ids.h:3913
#define PCI_DID_INTEL_ADL_GT1_7
Definition: pci_ids.h:3939
#define PCI_DID_INTEL_ICL_GT2_ULX_2
Definition: pci_ids.h:3874
#define PCI_DID_INTEL_APL_IGD_HD_505
Definition: pci_ids.h:3844
#define PCI_DID_INTEL_ADL_GT1_1
Definition: pci_ids.h:3933
#define PCI_DID_INTEL_TGL_GT2_ULX
Definition: pci_ids.h:3917
#define PCI_DID_INTEL_ADL_GT1
Definition: pci_ids.h:3932
#define PCI_DID_INTEL_ICL_GT2_ULX_6
Definition: pci_ids.h:3882
#define PCI_DID_INTEL_ADL_GT0
Definition: pci_ids.h:3931
#define PCI_DID_INTEL_KBL_GT1_SHALM_1
Definition: pci_ids.h:3828
#define PCI_DID_INTEL_SKL_GT2_DT2P1
Definition: pci_ids.h:3815
#define PCI_DID_INTEL_EHL_GT1_2_1
Definition: pci_ids.h:3922
#define PCI_DID_INTEL_ICL_GT2_ULT_2
Definition: pci_ids.h:3875
#define PCI_DID_INTEL_JSL_GT1
Definition: pci_ids.h:3926
#define PCI_DID_INTEL_GLK_IGD
Definition: pci_ids.h:3846
#define PCI_DID_INTEL_MTL_P_GT2_2
Definition: pci_ids.h:3961
#define PCI_DID_INTEL_SKL_GT3E_SULTM_2
Definition: pci_ids.h:3822
#define PCI_DID_INTEL_WHL_GT1_ULT_1
Definition: pci_ids.h:3848
#define PCI_DID_INTEL_SKL_GT1F_DT2
Definition: pci_ids.h:3812
#define PCI_DID_INTEL_CML_GT1_ULT_2
Definition: pci_ids.h:3885
#define PCI_DID_INTEL_EHL_GT2_3
Definition: pci_ids.h:3925
#define PCI_DID_INTEL_EHL_GT2_2
Definition: pci_ids.h:3923
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define PCI_DID_INTEL_ADL_M_GT3
Definition: pci_ids.h:3955
#define PCI_DID_INTEL_SKL_GT3E_SULTM_1
Definition: pci_ids.h:3821
#define PCI_DID_INTEL_CML_GT2_ULT_3
Definition: pci_ids.h:3892
#define PCI_DID_INTEL_ADL_N_GT3
Definition: pci_ids.h:3958
#define PCI_DID_INTEL_ADL_S_GT1
Definition: pci_ids.h:3952
#define PCI_DID_INTEL_ICL_GT0_ULT
Definition: pci_ids.h:3868
#define PCI_DID_INTEL_ICL_GT2_ULX_1
Definition: pci_ids.h:3872
#define PCI_DID_INTEL_CML_GT2_H_2
Definition: pci_ids.h:3903
#define PCI_DID_INTEL_CFL_H_XEON_GT2
Definition: pci_ids.h:3860
#define PCI_DID_INTEL_ICL_GT1_ULT
Definition: pci_ids.h:3870
#define PCI_DID_INTEL_KBL_GT2_SULXM
Definition: pci_ids.h:3838
#define PCI_DID_INTEL_EHL_GT1_3
Definition: pci_ids.h:3924
#define PCI_DID_INTEL_CNL_GT2_ULX_1
Definition: pci_ids.h:3850
#define PCI_DID_INTEL_CFL_S_GT1_2
Definition: pci_ids.h:3862
#define PCI_DID_INTEL_EHL_GT1_1
Definition: pci_ids.h:3919
#define PCI_DID_INTEL_CML_GT2_H_R0
Definition: pci_ids.h:3906
#define PCI_DID_INTEL_ICL_GT2_ULX_5
Definition: pci_ids.h:3880
#define PCI_DID_INTEL_APL_IGD_HD_500
Definition: pci_ids.h:3845
#define PCI_DID_INTEL_ADL_GT1_2
Definition: pci_ids.h:3934
#define PCI_DID_INTEL_KBL_GT2F_SULTM
Definition: pci_ids.h:3834
#define PCI_DID_INTEL_CML_GT1_H_1
Definition: pci_ids.h:3900
#define PCI_DID_INTEL_JSL_GT4
Definition: pci_ids.h:3929
#define PCI_DID_INTEL_ICL_GT0_5_ULT
Definition: pci_ids.h:3869
#define PCI_DID_INTEL_CFL_S_GT2_5
Definition: pci_ids.h:3867
#define PCI_DID_INTEL_CML_GT1_S_2
Definition: pci_ids.h:3897
#define PCI_DID_INTEL_SKL_GT1_SULTM
Definition: pci_ids.h:3813
#define PCI_DID_INTEL_SKL_GT2_SWKSM
Definition: pci_ids.h:3818
#define PCI_DID_INTEL_CFL_S_GT2_1
Definition: pci_ids.h:3863
#define PCI_DID_INTEL_TGL_GT2_ULT
Definition: pci_ids.h:3915
#define PCI_DID_INTEL_ICL_GT2_ULT_3
Definition: pci_ids.h:3877
#define PCI_DID_INTEL_MTL_P_GT2_1
Definition: pci_ids.h:3960
#define PCI_DID_INTEL_CNL_GT2_ULT_1
Definition: pci_ids.h:3854
#define PCI_DID_INTEL_CML_GT2_ULT_5
Definition: pci_ids.h:3890
#define POST_HW_INIT_FAILURE
Hardware initialization failure.
Definition: post_codes.h:353
void scan_generic_bus(struct device *bus)
Definition: root_device.c:52
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
#define SA_DEVFN_IGD
Definition: pci_devs.h:32
const struct i915_gpu_controller_info * intel_igd_get_controller_info(const struct device *device)
Definition: graphics.c:79
void graphics_soc_panel_init(struct device *const dev)
Definition: graphics.c:54
const struct soc_intel_common_config * chip_get_common_soc_structure(void)
Definition: chip.c:5
uint32_t graphics_gtt_read(unsigned long reg)
Definition: graphics.c:149
static uintptr_t graphics_get_gtt_base(void)
Definition: graphics.c:128
static const struct pci_driver graphics_driver __pci_driver
Definition: graphics.c:325
uintptr_t graphics_get_framebuffer_address(void)
Definition: graphics.c:110
static const unsigned short pci_device_ids[]
Definition: graphics.c:179
static uintptr_t graphics_get_bar(struct device *dev, unsigned long index)
Definition: graphics.c:99
void graphics_gtt_write(unsigned long reg, uint32_t data)
Definition: graphics.c:154
void graphics_gtt_rmw(unsigned long reg, uint32_t andmask, uint32_t ormask)
Definition: graphics.c:159
static void gma_init(struct device *const dev)
Definition: graphics.c:34
static int is_graphics_disabled(struct device *dev)
Definition: graphics.c:90
static const struct device_operations graphics_ops
Definition: graphics.c:167
static void gma_generate_ssdt(const struct device *device)
Definition: graphics.c:82
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
unsigned int enabled
Definition: device.h:122
resource_t base
Definition: resource.h:45
unsigned long index
Definition: resource.h:50
u8 val
Definition: sys.c:300