coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_pch.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <device/pci_ops.h>
5 #include <cf9_reset.h>
6 #include <ip_checksum.h>
7 #include <device/pci_def.h>
8 #include <device/smbus_host.h>
12 
13 /* For DMI bar. */
15 
16 #include "pch.h"
17 #include "chip.h"
18 
19 #define SOUTHBRIDGE PCI_DEV(0, 0x1f, 0)
20 
21 static void wait_iobp(void)
22 {
23  while (RCBA8(IOBPS) & 1)
24  ; // implement timeout?
25 }
26 
28 {
29  u32 ret;
30 
32  RCBA16(IOBPS) = (RCBA16(IOBPS) & 0x1ff) | 0x600;
33  wait_iobp();
34  ret = RCBA32(IOBPD);
35  wait_iobp();
36  RCBA8(IOBPS); // call wait_iobp() instead here?
37  return ret;
38 }
39 
40 static void write_iobp(u32 address, u32 val)
41 {
42  /* this function was probably pch_iobp_update with the andvalue
43  * being 0. So either the IOBP read can be removed or this function
44  * and the pch_iobp_update function in ramstage could be merged */
46  RCBA16(IOBPS) = (RCBA16(IOBPS) & 0x1ff) | 0x600;
47  wait_iobp();
48 
49  RCBA32(IOBPD) = val;
50  wait_iobp();
51  RCBA16(IOBPS) = (RCBA16(IOBPS) & 0x1ff) | 0x600;
52 
53  RCBA8(IOBPS); // call wait_iobp() instead here?
54 }
55 
57 {
58  /* Link Capabilities Register */
59  RCBA32(LCAP) = (RCBA32(LCAP) & ~0x3fc00) |
60  (3 << 10) | // L0s and L1 entry supported
61  (2 << 12) | // L0s 128 ns to less than 256 ns
62  (2 << 15); // L1 2 us to less than 4 us
63 
64  RCBA32(0x2340) = (RCBA32(0x2340) & ~0xff0000) | (0x3a << 16);
65  RCBA8(DLCTL2) = (RCBA8(DLCTL2) & ~0xf) | 2;
66 }
67 
69 {
70  RCBA32(CIR0); // !!! = 0x01200654
71  RCBA32(CIR0) = 0x01200654;
72  RCBA32(CIR0); // !!! = 0x01200654
73  RCBA32(CIR0) = 0x012a0654;
74  RCBA32(CIR0); // !!! = 0x012a0654
75  RCBA8(UPDCR); // !!! = 0x00
76  RCBA8(UPDCR) = 0x05;
77 
78  /*
79  * Virtual Channel resources must match settings in DMIBAR!
80  *
81  * Some of the following settings are taken from
82  * "Intel Core i5-600, i3-500 Desktop Processor Series and Intel
83  * Pentium Desktop Processor 6000 Series Vol. 2" datasheet and
84  * serialice traces.
85  */
86 
87  /* Virtual Channel 0 Resource Control Register.
88  * Enable channel.
89  * Set Virtual Channel Identifier.
90  * Map TC0 and TC3 and TC4 to VC0.
91  */
92 
93  RCBA32(V0CTL) = (1 << 31) | (0 << 24) | (0x0c << 1) | 1;
94 
95  /* Virtual Channel 1 Resource Control Register.
96  * Enable channel.
97  * Set Virtual Channel Identifier.
98  * Map TC1 and TC5 to VC1.
99  */
100  RCBA32(V1CTL) = (1 << 31) | (1 << 24) | (0x11 << 1);
101  /* Read back register */
102  RCBA32(V1CTL);
103 
104  /* Virtual Channel private Resource Control Register.
105  * Enable channel.
106  * Set Virtual Channel Identifier.
107  * Map TC2 and TC6 to VCp.
108  */
109  RCBA32(CIR31) = (1 << 31) | (2 << 24) | (0x22 << 1);
110  /* Read back register */
111  RCBA32(CIR31);
112 
113  /* Virtual Channel ME Resource Control Register.
114  * Enable channel.
115  * Set Virtual Channel Identifier.
116  * Map TC7 to VCm.
117  */
118  RCBA32(CIR32) = (1 << 31) | (7 << 24) | (0x40 << 1);
119 
120  /* Lock Virtual Channel Resource control register. */
121  RCBA32(CIR0) |= TCLOCKDN;
122  /* Read back register */
123  RCBA32(CIR0);
124 
125  /* Wait for virtual channels negotiation pending */
126  while (RCBA16(V0STS) & VCNEGPND)
127  ;
128  while (RCBA16(V1STS) & VCNEGPND)
129  ;
130  while (RCBA16(0x2036) & VCNEGPND)
131  ;
132  while (RCBA16(0x2046) & VCNEGPND)
133  ;
134 }
135 
137 {
139 
140  RCBA32(CIR1) = 0x00109000;
141  RCBA32(REC); // !!! = 0x00000000
142  RCBA32(REC) = 0x40000000;
143  RCBA32(0x100c) = 0x01110000;
144  RCBA8(0x2340) = 0x1b;
145  RCBA32(CIR6); // !!! = 0x0a080000
146  RCBA32(CIR6) = 0x0a280000;
147  RCBA32(0x2310); // !!! = 0xc809605b
148  RCBA32(0x2310) = 0xa809605b;
149  RCBA32(DMC2) = 0x00854c74;
150  RCBA8(RPC); // !!! = 0x00
151  RCBA32(0x2310); // !!! = 0xa809605b
152  RCBA32(0x2310) = 0xa809605b;
153  RCBA32(0x2310); // !!! = 0xa809605b
154  RCBA32(0x2310) = 0xa809605b;
155 
156  write_iobp(0xea007f62, 0x00590133);
157  write_iobp(0xec007f62, 0x00590133);
158  write_iobp(0xec007f64, 0x59555588);
159  write_iobp(0xea0040b9, 0x0001051c);
160  write_iobp(0xeb0040a1, 0x800084ff);
161  write_iobp(0xec0040a1, 0x800084ff);
162  write_iobp(0xea004001, 0x00008400);
163  write_iobp(0xeb004002, 0x40201758);
164  write_iobp(0xec004002, 0x40201758);
165  write_iobp(0xea004002, 0x00601758);
166  write_iobp(0xea0040a1, 0x810084ff);
167  write_iobp(0xeb0040b1, 0x0001c598);
168  write_iobp(0xec0040b1, 0x0001c598);
169  write_iobp(0xeb0040b6, 0x0001c598);
170  write_iobp(0xea0000a9, 0x80ff969f);
171  write_iobp(0xea0001a9, 0x80ff969f);
172  write_iobp(0xeb0040b2, 0x0001c396);
173  write_iobp(0xeb0040b3, 0x0001c396);
174  write_iobp(0xec0040b2, 0x0001c396);
175  write_iobp(0xea0001a9, 0x80ff94ff);
176  write_iobp(SATA_IOBP_SP0G3IR, 0x0088037f);
177  write_iobp(0xea0000a9, 0x80ff94ff);
178  write_iobp(SATA_IOBP_SP1G3IR, 0x0088037f);
179 
180  write_iobp(0xea007f05, 0x00010642);
181  write_iobp(0xea0040b7, 0x0001c91c);
182  write_iobp(0xea0040b8, 0x0001c91c);
183  write_iobp(0xeb0040a1, 0x820084ff);
184  write_iobp(0xec0040a1, 0x820084ff);
185  write_iobp(0xea007f0a, 0xc2480000);
186 
187  write_iobp(0xec00404d, 0x1ff177f);
188  write_iobp(0xec000084, 0x5a600000);
189  write_iobp(0xec000184, 0x5a600000);
190  write_iobp(0xec000284, 0x5a600000);
191  write_iobp(0xec000384, 0x5a600000);
192  write_iobp(0xec000094, 0x000f0501);
193  write_iobp(0xec000194, 0x000f0501);
194  write_iobp(0xec000294, 0x000f0501);
195  write_iobp(0xec000394, 0x000f0501);
196  write_iobp(0xec000096, 0x00000001);
197  write_iobp(0xec000196, 0x00000001);
198  write_iobp(0xec000296, 0x00000001);
199  write_iobp(0xec000396, 0x00000001);
200  write_iobp(0xec000001, 0x00008c08);
201  write_iobp(0xec000101, 0x00008c08);
202  write_iobp(0xec000201, 0x00008c08);
203  write_iobp(0xec000301, 0x00008c08);
204  write_iobp(0xec0040b5, 0x0001c518);
205  write_iobp(0xec000087, 0x06077597);
206  write_iobp(0xec000187, 0x06077597);
207  write_iobp(0xec000287, 0x06077597);
208  write_iobp(0xec000387, 0x06077597);
209  write_iobp(0xea000050, 0x00bb0157);
210  write_iobp(0xea000150, 0x00bb0157);
211  write_iobp(0xec007f60, 0x77777d77);
212  write_iobp(0xea00008d, 0x01320000);
213  write_iobp(0xea00018d, 0x01320000);
214  write_iobp(0xec0007b2, 0x04514b5e);
215  write_iobp(0xec00078c, 0x40000200);
216  write_iobp(0xec000780, 0x02000020);
217 }
218 
219 static void pch_enable_bars(void)
220 {
221  pci_write_config32(PCH_LPC_DEV, RCBA, CONFIG_FIXED_RCBA_MMIO_BASE | 1);
222 
224 
226 
228 
229  /* Enable GPIO functionality. */
231 }
232 
233 static void pch_generic_setup(void)
234 {
235  RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */
236  write_pmbase16(TCO1_CNT, 1 << 11); /* halt timer */
237 }
238 
239 static void pch_enable_gbe(void)
240 {
241  uint8_t wanted_buc;
242 
243  /* Don't do this in the bootblock, it might be RO. So one
244  couldn't change the setting later in an updated romstage. */
245  if (ENV_BOOTBLOCK)
246  return;
247 
248  const struct device *const gbe = pcidev_on_root(0x19, 0);
249  if (gbe && gbe->enabled)
250  wanted_buc = RCBA8(BUC) & ~PCH_DISABLE_GBE;
251  else
252  wanted_buc = RCBA8(BUC) | PCH_DISABLE_GBE;
253 
254  if (RCBA8(BUC) != wanted_buc) {
255  RCBA8(BUC) = wanted_buc;
256  /* Be double sure not to reset for naught. */
257  if (RCBA8(BUC) != wanted_buc)
258  return;
259  full_reset();
260  }
261 }
262 
263 static void pch_enable_lpc_decode(void)
264 {
265  /*
266  * Enable some common LPC IO ranges:
267  * - 0x2e/0x2f, 0x4e/0x4f often SuperIO
268  * - 0x60/0x64, 0x62/0x66 often KBC/EC
269  * - 0x3f0-0x3f5/0x3f7 FDD
270  * - 0x378-0x37f and 0x778-0x77f LPT
271  * - 0x2f8-0x2ff COMB
272  * - 0x3f8-0x3ff COMA
273  */
277 
278  const struct device *dev = pcidev_on_root(0x1f, 0);
280 
281  /* Set up generic decode ranges */
282  if (!dev)
283  return;
284  if (dev->chip_info)
285  config = dev->chip_info;
286  if (!config)
287  return;
288 
293 }
294 
296 {
297 }
298 
299 void early_pch_init(void)
300 {
302 
304 
305  pch_enable_bars();
306 
308 
309  pch_enable_gbe();
310 
312 
313  if (ENV_ROMSTAGE)
314  enable_smbus();
315 }
void full_reset(void)
Definition: cf9_reset.c:45
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
uint64_t address
Definition: fw_cfg_if.h:0
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
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 ACPI_EN
Definition: pmc.h:146
#define LCAP
Definition: pcie.h:16
#define DEFAULT_PMBASE
Definition: iomap.h:14
const struct pch_gpio_map mainboard_gpio_map
Definition: gpio.c:87
enum board_config config
Definition: memory.c:448
void write_pmbase16(const u8 addr, const u16 val)
Definition: pmbase.c:43
#define ENV_BOOTBLOCK
Definition: rules.h:148
#define ENV_ROMSTAGE
Definition: rules.h:149
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
static void enable_smbus(void)
Definition: smbus_host.h:34
#define TCO1_CNT
Definition: smbus.h:12
#define RCBA
Definition: lpc.h:17
#define GCS
Definition: lpc.h:36
#define FDD_LPC_EN
Definition: lpc.h:43
#define LPT_LPC_EN
Definition: lpc.h:44
#define COMB_LPC_EN
Definition: lpc.h:45
#define KBC_LPC_EN
Definition: lpc.h:40
#define LPC_GEN1_DEC
Definition: lpc.h:47
#define MC_LPC_EN
Definition: lpc.h:39
#define COMA_LPC_EN
Definition: lpc.h:46
#define PMBASE
Definition: lpc.h:8
#define LPC_GEN2_DEC
Definition: lpc.h:48
#define LPC_GEN3_DEC
Definition: lpc.h:49
#define GPIO_CNTL
Definition: lpc.h:22
#define CNF2_LPC_EN
Definition: lpc.h:37
#define ACPI_CNTL
Definition: lpc.h:9
#define CNF1_LPC_EN
Definition: lpc.h:38
#define GPIO_BASE
Definition: lpc.h:21
#define LPC_GEN4_DEC
Definition: lpc.h:50
#define LPC_IO_DEC
Definition: lpc.h:35
#define LPC_EN
Definition: lpc.h:36
#define IOBPD
Definition: rcba.h:44
#define PCH_DISABLE_GBE
Definition: rcba.h:124
#define BUC
Definition: rcba.h:123
#define IOBPIRI
Definition: rcba.h:43
#define RPC
Definition: rcba.h:8
#define IOBPS
Definition: rcba.h:45
#define PCH_LPC_DEV
Definition: lpc.h:7
static void pch_enable_gbe(void)
Definition: early_pch.c:239
void early_pch_init(void)
Definition: early_pch.c:299
static void pch_enable_bars(void)
Definition: early_pch.c:219
void early_pch_init_native(void)
Definition: early_pch.c:136
static void wait_iobp(void)
Definition: early_pch.c:21
void early_pch_init_native_dmi_pre(void)
Definition: early_pch.c:56
void early_pch_init_native_dmi_post(void)
Definition: early_pch.c:68
#define SOUTHBRIDGE
Definition: early_pch.c:19
static void write_iobp(u32 address, u32 val)
Definition: early_pch.c:40
static void pch_enable_lpc_decode(void)
Definition: early_pch.c:263
__weak void mainboard_pch_lpc_setup(void)
Definition: early_pch.c:295
static u32 read_iobp(u32 address)
Definition: early_pch.c:27
static void pch_generic_setup(void)
Definition: early_pch.c:233
#define CIR32
Definition: pch.h:246
#define SATA_IOBP_SP0G3IR
Definition: pch.h:169
#define CIR31
Definition: pch.h:245
#define SATA_IOBP_SP1G3IR
Definition: pch.h:170
#define DMC2
Definition: pch.h:259
#define DLCTL2
Definition: pch.h:252
#define CIR6
Definition: pch.h:257
#define V0CTL
Definition: pch.h:241
#define CIR0
Definition: pch.h:188
#define UPDCR
Definition: pch.h:196
#define VCNEGPND
Definition: pch.h:216
#define REC
Definition: pch.h:248
#define V0STS
Definition: pch.h:242
#define V1STS
Definition: pch.h:244
#define V1CTL
Definition: pch.h:243
#define CIR1
Definition: pch.h:247
#define TCLOCKDN
Definition: pch.h:189
#define DEFAULT_GPIOBASE
Definition: pch.h:22
void setup_pch_gpios(const struct pch_gpio_map *gpio)
Definition: gpio.c:33
#define RCBA16(x)
Definition: rcba.h:13
#define RCBA8(x)
Definition: rcba.h:12
#define RCBA32(x)
Definition: rcba.h:14
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
unsigned char uint8_t
Definition: stdint.h:8
Definition: device.h:107
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int enabled
Definition: device.h:122
u8 val
Definition: sys.c:300