coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <stdint.h>
4 #include <console/console.h>
5 #include <device/mmio.h>
6 #include <device/pci_def.h>
7 #include <device/pci_ops.h>
8 
9 #include "haswell.h"
10 
11 static bool peg_hidden[3];
12 
13 static void haswell_setup_bars(void)
14 {
15  printk(BIOS_DEBUG, "Setting up static northbridge registers...");
16  /* Set up all hardcoded northbridge BARs */
17  pci_write_config32(HOST_BRIDGE, EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1);
19  pci_write_config32(HOST_BRIDGE, MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1);
21  pci_write_config32(HOST_BRIDGE, DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1);
23 
26 
27  /* Set C0000-FFFFF to access RAM on both reads and writes */
35 
36  printk(BIOS_DEBUG, " done.\n");
37 }
38 
39 static void haswell_setup_igd(void)
40 {
41  bool igd_enabled;
42  u16 ggc;
43 
44  printk(BIOS_DEBUG, "Initializing IGD...\n");
45 
46  igd_enabled = !!(pci_read_config32(HOST_BRIDGE, DEVEN) & DEVEN_D2EN);
47 
49  ggc &= ~0x3f8;
50  if (igd_enabled) {
53  } else {
55  }
57 
58  if (!igd_enabled) {
59  printk(BIOS_DEBUG, "IGD is disabled.\n");
60  return;
61  }
62 
63  /* Enable 256MB aperture */
64  pci_update_config8(PCI_DEV(0, 2, 0), MSAC, ~0x06, 0x02);
65 }
66 
67 static void start_peg2_link_training(const pci_devfn_t dev)
68 {
69  u32 mask;
70 
71  switch (dev) {
72  case PCI_DEV(0, 1, 2):
74  break;
75  case PCI_DEV(0, 1, 1):
77  break;
78  case PCI_DEV(0, 1, 0):
80  break;
81  default:
82  printk(BIOS_ERR, "Link training tried on a non-PEG device!\n");
83  return;
84  }
85 
86  pci_update_config32(dev, 0xc24, ~(1 << 16), 1 << 5);
87  printk(BIOS_DEBUG, "Started PEG1%d link training.\n", PCI_FUNC(PCI_DEV2DEVFN(dev)));
88 
89  /*
90  * The MRC will perform PCI enumeration, and if it detects a VGA
91  * device in a PEG slot, it will disable the IGD and not reserve
92  * any memory for it. Since the memory map is locked by the time
93  * MRC finishes, the IGD can't be enabled afterwards. Wonderful.
94  *
95  * If one really wants to enable the Intel iGPU as primary, hide
96  * all PEG devices during MRC execution. This will trick the MRC
97  * into thinking there aren't any, and will enable the IGD. Note
98  * that PEG AFE settings will not be programmed, which may cause
99  * stability problems at higher PCIe link speeds. The most ideal
100  * way to fix this problem for good is to implement native init.
101  */
102  if (CONFIG(HASWELL_HIDE_PEG_FROM_MRC)) {
104  peg_hidden[PCI_FUNC(PCI_DEV2DEVFN(dev))] = true;
105  printk(BIOS_DEBUG, "Temporarily hiding PEG1%d.\n",
106  PCI_FUNC(PCI_DEV2DEVFN(dev)));
107  }
108 }
109 
111 {
113 
114  for (u8 fn = 0; fn <= 2; fn++) {
115  if (peg_hidden[fn]) {
116  deven |= DEVEN_D1F0EN >> fn;
117  peg_hidden[fn] = false;
118  printk(BIOS_DEBUG, "Unhiding PEG1%d.\n", fn);
119  }
120  }
121 
123 }
124 
125 static void haswell_setup_peg(void)
126 {
128 
129  if (deven & DEVEN_D1F2EN)
131 
132  if (deven & DEVEN_D1F1EN)
134 
135  if (deven & DEVEN_D1F0EN)
137 }
138 
139 static void haswell_setup_misc(void)
140 {
141  u32 reg32;
142 
143  /* Erratum workarounds */
144  reg32 = mchbar_read32(SAPMCTL);
145  reg32 |= (1 << 9) | (1 << 10);
146  mchbar_write32(SAPMCTL, reg32);
147 
148  /* Enable SA Clock Gating */
149  reg32 = mchbar_read32(SAPMCTL);
150  mchbar_write32(SAPMCTL, reg32 | 1);
151 
152  reg32 = mchbar_read32(INTRDIRCTL);
153  reg32 |= (1 << 4) | (1 << 5);
154  mchbar_write32(INTRDIRCTL, reg32);
155 }
156 
157 static void haswell_setup_iommu(void)
158 {
159  const u32 capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A);
160 
161  if (capid0_a & VTD_DISABLE)
162  return;
163 
164  /* Setup BARs: zeroize top 32 bits; set enable bit */
169 
170  /* Set L3HIT2PEND_DIS, lock GFXVTBAR policy config registers */
171  u32 reg32;
172  reg32 = read32((void *)(GFXVT_BASE_ADDRESS + ARCHDIS));
174 
175  /* Clear SPCAPCTRL */
176  reg32 = read32((void *)(VTVC0_BASE_ADDRESS + ARCHDIS)) & ~SPCAPCTRL;
177 
178  /* Set GLBIOTLBINV, GLBCTXTINV; lock VTVC0BAR policy config registers */
179  write32((void *)(VTVC0_BASE_ADDRESS + ARCHDIS),
180  reg32 | DMAR_LCKDN | GLBIOTLBINV | GLBCTXTINV);
181 }
182 
184 {
185  /* Setup all BARs required for early PCIe and raminit */
187 
188  /* Setup IOMMU BARs */
190 
193 
195 }
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
static __always_inline void mchbar_write32(const uintptr_t offset, const uint32_t value)
Definition: fixed_bars.h:36
static __always_inline uint32_t mchbar_read32(const uintptr_t offset)
Definition: fixed_bars.h:21
#define PAM0
Definition: host_bridge.h:38
#define PAM6
Definition: host_bridge.h:44
#define GGC
Definition: host_bridge.h:9
#define PAM5
Definition: host_bridge.h:43
#define DEVEN_D2EN
Definition: host_bridge.h:20
#define DEVEN_D1F1EN
Definition: host_bridge.h:22
#define DEVEN_D1F0EN
Definition: host_bridge.h:21
#define CAPID0_A
Definition: host_bridge.h:65
#define MCHBAR
Definition: host_bridge.h:7
#define PAM2
Definition: host_bridge.h:40
#define GGC_GTT_2MB
Definition: host_bridge.h:14
#define GGC_GTT_0MB
Definition: host_bridge.h:12
#define DEVEN_D1F2EN
Definition: host_bridge.h:23
#define GGC_IGD_MEM_IN_32MB_UNITS(x)
Definition: host_bridge.h:11
#define VTD_DISABLE
Definition: host_bridge.h:67
#define PAM1
Definition: host_bridge.h:39
#define DMIBAR
Definition: host_bridge.h:33
#define GGC_DISABLE_VGA_IO_DECODE
Definition: host_bridge.h:10
#define EPBAR
Definition: host_bridge.h:6
#define DEVEN
Definition: host_bridge.h:16
#define PAM3
Definition: host_bridge.h:41
#define PAM4
Definition: host_bridge.h:42
#define SAPMCTL
Definition: mchbar.h:65
#define EDRAMBAR
Definition: mchbar.h:19
#define INTRDIRCTL
Definition: mchbar.h:21
#define VTVC0BAR
Definition: mchbar.h:20
#define GFXVTBAR
Definition: mchbar.h:18
#define GDXCBAR
Definition: mchbar.h:22
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline void pci_update_config32(const struct device *dev, u16 reg, u32 mask, u32 or)
Definition: pci_ops.h:120
static __always_inline void pci_update_config8(const struct device *dev, u16 reg, u8 mask, u8 or)
Definition: pci_ops.h:88
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val)
Definition: pci_ops.h:70
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
static void haswell_setup_peg(void)
Definition: early_init.c:125
static void haswell_setup_iommu(void)
Definition: early_init.c:157
static void start_peg2_link_training(const pci_devfn_t dev)
Definition: early_init.c:67
void haswell_early_initialization(void)
Definition: early_init.c:183
static void haswell_setup_misc(void)
Definition: early_init.c:139
void haswell_unhide_peg(void)
Definition: early_init.c:110
static void haswell_setup_bars(void)
Definition: early_init.c:13
static void haswell_setup_igd(void)
Definition: early_init.c:39
static bool peg_hidden[3]
Definition: early_init.c:11
#define ARCHDIS
Definition: haswell.h:23
#define GLBIOTLBINV
Definition: haswell.h:28
#define SPCAPCTRL
Definition: haswell.h:25
#define GLBCTXTINV
Definition: haswell.h:29
#define L3HIT2PEND_DIS
Definition: haswell.h:26
#define MSAC
Definition: haswell.h:21
#define DMAR_LCKDN
Definition: haswell.h:24
#define GFXVT_BASE_ADDRESS
Definition: memmap.h:18
#define EDRAM_BASE_ADDRESS
Definition: memmap.h:12
#define VTVC0_BASE_ADDRESS
Definition: memmap.h:21
#define GDXC_BASE_ADDRESS
Definition: memmap.h:15
#define PCI_FUNC(devfn)
Definition: pci_def.h:550
#define PCI_DEV2DEVFN(sdev)
Definition: pci_def.h:553
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
u32 pci_devfn_t
Definition: pci_type.h:8
static const int mask[4]
Definition: gpio.c:308
@ HOST_BRIDGE
Definition: reg_access.h:23
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45