coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
lpc.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <device/pci_ops.h>
8 #include <option.h>
9 #include <pc80/isa-dma.h>
10 #include <pc80/i8259.h>
11 #include <arch/io.h>
12 #include <arch/ioapic.h>
13 #include <acpi/acpi.h>
14 #include <cpu/x86/smm.h>
15 #include "chip.h"
16 #include "iobp.h"
17 #include "pch.h"
18 #include <acpi/acpigen.h>
23 #include <types.h>
24 
25 #define NMI_OFF 0
26 
27 /**
28  * Set miscellaneous static southbridge features.
29  *
30  * @param dev PCI device with I/O APIC control registers
31  */
32 static void pch_enable_ioapic(struct device *dev)
33 {
34  /* Assign unique bus/dev/fn for I/O APIC */
37 
38  /* affirm full set of redirection table entries ("write once") */
39  /* PCH-LP has 40 redirection entries */
40  if (pch_is_lp())
42  else
44 
46 
47 }
48 
49 static void pch_enable_serial_irqs(struct device *dev)
50 {
51  /* Set packet length and toggle silent mode bit for one frame. */
53  (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
54 #if !CONFIG(SERIRQ_CONTINUOUS_MODE)
56  (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
57 #endif
58 }
59 
60 static void enable_hpet(struct device *const dev)
61 {
62  u32 reg32;
63  size_t i;
64 
65  /* Assign unique bus/dev/fn for each HPET */
66  for (i = 0; i < 8; ++i)
68  PCH_HPET_PCI_BUS << 8 | PCH_HPET_PCI_SLOT << 3 | i);
69 
70  /* Move HPET to default address 0xfed00000 and enable it */
71  reg32 = RCBA32(HPTC);
72  reg32 |= (1 << 7); // HPET Address Enable
73  reg32 &= ~(3 << 0);
74  RCBA32(HPTC) = reg32;
75  /* Read it back to stick. It's affected by posted write syndrome. */
76  RCBA32(HPTC);
77 }
78 
79 /* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
80  * 0x00 - 0000 = Reserved
81  * 0x01 - 0001 = Reserved
82  * 0x02 - 0010 = Reserved
83  * 0x03 - 0011 = IRQ3
84  * 0x04 - 0100 = IRQ4
85  * 0x05 - 0101 = IRQ5
86  * 0x06 - 0110 = IRQ6
87  * 0x07 - 0111 = IRQ7
88  * 0x08 - 1000 = Reserved
89  * 0x09 - 1001 = IRQ9
90  * 0x0A - 1010 = IRQ10
91  * 0x0B - 1011 = IRQ11
92  * 0x0C - 1100 = IRQ12
93  * 0x0D - 1101 = Reserved
94  * 0x0E - 1110 = IRQ14
95  * 0x0F - 1111 = IRQ15
96  * PIRQ[n]_ROUT[7] - PIRQ Routing Control
97  * 0x80 - The PIRQ is not routed.
98  */
99 
100 static void pch_pirq_init(struct device *dev)
101 {
102  struct device *irq_dev;
103 
104  const uint8_t pirq = 0x80;
105 
110 
115 
116  /* Eric Biederman once said we should let the OS do this.
117  * I am not so sure anymore he was right.
118  */
119 
120  for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
121  u8 int_pin = 0, int_line = 0;
122 
123  if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
124  continue;
125 
126  int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
127 
128  switch (int_pin) {
129  case 1: /* INTA# */
130  case 2: /* INTB# */
131  case 3: /* INTC# */
132  case 4: /* INTD# */
133  int_line = pirq;
134  break;
135  }
136 
137  if (!int_line)
138  continue;
139 
140  pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
141  }
142 }
143 
144 static void pch_gpi_routing(struct device *dev,
146 {
147  u32 reg32 = 0;
148 
149  /* An array would be much nicer here, or some
150  * other method of doing this.
151  */
152  reg32 |= (config->gpi0_routing & 0x03) << 0;
153  reg32 |= (config->gpi1_routing & 0x03) << 2;
154  reg32 |= (config->gpi2_routing & 0x03) << 4;
155  reg32 |= (config->gpi3_routing & 0x03) << 6;
156  reg32 |= (config->gpi4_routing & 0x03) << 8;
157  reg32 |= (config->gpi5_routing & 0x03) << 10;
158  reg32 |= (config->gpi6_routing & 0x03) << 12;
159  reg32 |= (config->gpi7_routing & 0x03) << 14;
160  reg32 |= (config->gpi8_routing & 0x03) << 16;
161  reg32 |= (config->gpi9_routing & 0x03) << 18;
162  reg32 |= (config->gpi10_routing & 0x03) << 20;
163  reg32 |= (config->gpi11_routing & 0x03) << 22;
164  reg32 |= (config->gpi12_routing & 0x03) << 24;
165  reg32 |= (config->gpi13_routing & 0x03) << 26;
166  reg32 |= (config->gpi14_routing & 0x03) << 28;
167  reg32 |= (config->gpi15_routing & 0x03) << 30;
168 
169  pci_write_config32(dev, GPIO_ROUT, reg32);
170 }
171 
172 static void pch_power_options(struct device *dev)
173 {
174  u8 reg8;
175  u16 reg16;
176  u32 reg32;
177  const char *state;
178  u16 pmbase = get_pmbase();
179 
180  /* Which state do we want to goto after g3 (power restored)?
181  * 0 == S0 Full On
182  * 1 == S5 Soft Off
183  *
184  * If the option is not existent (Laptops), use Kconfig setting.
185  */
186  const unsigned int pwr_on = get_uint_option("power_on_after_fail",
187  CONFIG_MAINBOARD_POWER_FAILURE_STATE);
188 
189  reg16 = pci_read_config16(dev, GEN_PMCON_3);
190  reg16 &= 0xfffe;
191  switch (pwr_on) {
192  case MAINBOARD_POWER_OFF:
193  reg16 |= 1;
194  state = "off";
195  break;
196  case MAINBOARD_POWER_ON:
197  reg16 &= ~1;
198  state = "on";
199  break;
201  reg16 &= ~1;
202  state = "state keep";
203  break;
204  default:
205  state = "undefined";
206  }
207 
208  reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */
209  reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */
210 
211  reg16 &= ~(1 << 10);
212  reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */
213 
214  reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */
215 
216  pci_write_config16(dev, GEN_PMCON_3, reg16);
217  printk(BIOS_INFO, "Set power %s after power failure.\n", state);
218 
219  /* Set up NMI on errors. */
220  reg8 = inb(0x61);
221  reg8 &= 0x0f; /* Higher Nibble must be 0 */
222  reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
223  // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
224  reg8 |= (1 << 2); /* PCI SERR# Disable for now */
225  outb(reg8, 0x61);
226 
227  reg8 = inb(0x70);
228  const unsigned int nmi_option = get_uint_option("nmi", NMI_OFF);
229  if (nmi_option) {
230  printk(BIOS_INFO, "NMI sources enabled.\n");
231  reg8 &= ~(1 << 7); /* Set NMI. */
232  } else {
233  printk(BIOS_INFO, "NMI sources disabled.\n");
234  reg8 |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
235  }
236  outb(reg8, 0x70);
237 
238  /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
239  reg16 = pci_read_config16(dev, GEN_PMCON_1);
240  reg16 &= ~(3 << 0); // SMI# rate 1 minute
241  reg16 &= ~(1 << 10); // Disable BIOS_PCI_EXP_EN for native PME
242  pci_write_config16(dev, GEN_PMCON_1, reg16);
243 
244  if (dev->chip_info) {
246 
247  /*
248  * Set the board's GPI routing on LynxPoint-H.
249  * This is done as part of GPIO configuration on LynxPoint-LP.
250  */
251  if (!pch_is_lp())
252  pch_gpi_routing(dev, config);
253 
254  /* GPE setup based on device tree configuration */
255  enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
256  config->gpe0_en_3, config->gpe0_en_4);
257 
258  /* SMI setup based on device tree configuration */
259  enable_alt_smi(config->alt_gp_smi_en);
260  }
261 
262  /* Set up power management block and determine sleep mode */
263  reg32 = inl(pmbase + 0x04); // PM1_CNT
264  reg32 &= ~(7 << 10); // SLP_TYP
265  reg32 |= (1 << 0); // SCI_EN
266  outl(reg32, pmbase + 0x04);
267 
268  /* Clear magic status bits to prevent unexpected wake */
269  reg32 = RCBA32(0x3310);
270  reg32 |= (1 << 4) | (1 << 5) | (1 << 0);
271  RCBA32(0x3310) = reg32;
272 
273  reg16 = RCBA16(0x3f02);
274  reg16 &= ~0xf;
275  RCBA16(0x3f02) = reg16;
276 }
277 
278 static void configure_dmi_pm(struct device *dev)
279 {
280  struct device *const pcie_dev = pcidev_on_root(0x1c, 0);
281 
282  /* Additional PCH DMI programming steps */
283 
284  /* EL0 */
285  u32 reg32 = 3 << 12;
286 
287  /* EL1 */
288  if (pcie_dev && !(pci_read_config8(pcie_dev, 0xf5) & 1 << 0))
289  reg32 |= 2 << 15;
290  else
291  reg32 |= 4 << 15;
292 
293  RCBA32_AND_OR(0x21a4, ~(7 << 15 | 7 << 12), reg32);
294 
295  RCBA32_AND_OR(0x2348, ~0xf, 0);
296 
297  /* Clear prior to enabling DMI ASPM */
298  RCBA32_AND_OR(0x2304, ~(1 << 10), 0);
299 
300  RCBA32_OR(0x21a4, 3 << 10);
301 
302  RCBA16(0x21a8) |= 3 << 0;
303 
304  /* Set again after enabling DMI ASPM */
305  RCBA32_OR(0x2304, 1 << 10);
306 }
307 
308 /* LynxPoint PCH Power Management init */
309 static void lpt_pm_init(struct device *dev)
310 {
312 
313  struct device *const pcie_dev = pcidev_on_root(0x1c, 0);
314 
315  printk(BIOS_DEBUG, "LynxPoint H PM init\n");
316 
317  /* Configure additional PM */
318  pci_write_config8(dev, 0xa9, 0x46);
319 
321 
322  /* Step 3 is skipped */
323 
324  /* Program DMI Hardware Width Control (thermal throttling) */
325  u32 reg32 = 0;
326  reg32 |= 1 << 0; /* DMI Thermal Sensor Autonomous Width Enable */
327  reg32 |= 0 << 4; /* Thermal Sensor 0 Target Width */
328  reg32 |= 1 << 6; /* Thermal Sensor 1 Target Width */
329  reg32 |= 1 << 8; /* Thermal Sensor 2 Target Width */
330  reg32 |= 2 << 10; /* Thermal Sensor 3 Target Width */
331  RCBA32(0x2238) = reg32;
332 
333  RCBA32_OR(0x232c, 1 << 0);
334  RCBA32_OR(0x1100, 3 << 13); /* Assume trunk clock gating is to be enabled */
335 
336  RCBA32(0x2304) = 0xc07b8400; /* DMI misc control */
337 
338  RCBA32_OR(0x2314, 1 << 23 | 1 << 5);
339 
340  if (pcie_dev)
341  pci_update_config8(pcie_dev, 0xf5, ~0xf, 0x5);
342 
343  RCBA32_OR(0x2320, 1 << 1);
344 
345  RCBA32(0x3314) = 0x000007bf;
346 
347  /* NOTE: Preserve bit 5 */
348  RCBA32_OR(0x3318, 0x0dcf0000);
349 
350  RCBA32(0x3324) = 0x04000000;
351  RCBA32(0x3340) = 0x020ddbff;
352 
353  RCBA32_OR(0x3344, 1 << 0);
354 
355  RCBA32(0x3368) = 0x00041000;
356  RCBA32(0x3378) = 0x3f8ddbff;
357  RCBA32(0x337c) = 0x000001e1;
358  RCBA32(0x3388) = 0x00001000;
359  RCBA32(0x33a0) = 0x00000800;
360  RCBA32(0x33ac) = 0x00001000;
361  RCBA32(0x33b0) = 0x00001000;
362  RCBA32(0x33c0) = 0x00011900;
363  RCBA32(0x33d0) = 0x06000802;
364  RCBA32(0x3a28) = 0x01010000;
365  RCBA32(0x3a2c) = 0x01010404;
366 
367  RCBA32_OR(0x33a4, 1 << 0);
368 
369  /* DMI power optimizer */
370  RCBA32_OR(0x33d4, 1 << 27);
371  RCBA32_OR(0x33c8, 1 << 27);
372  RCBA32(0x2b14) = 0x1e0a0317;
373  RCBA32(0x2b24) = 0x4000000b;
374  RCBA32(0x2b28) = 0x00000002;
375  RCBA32(0x2b2c) = 0x00008813;
376 
377  RCBA32(0x3a80) = 0x01040000;
378  reg32 = 0x01041001;
379  /* Port 1 and 0 disabled */
380  if (config && (config->sata_port_map & ((1 << 1) | (1 << 0))) == 0)
381  reg32 |= (1 << 20) | (1 << 18);
382  /* Port 3 and 2 disabled */
383  if (config && (config->sata_port_map & ((1 << 3) | (1 << 2))) == 0)
384  reg32 |= (1 << 24) | (1 << 26);
385  RCBA32(0x3a84) = reg32;
386  RCBA32(0x3a88) = 0x00000001;
387  RCBA32(0x33d4) = 0xc80bc000;
388 
389  configure_dmi_pm(dev);
390 }
391 
392 /* LynxPoint LP PCH Power Management init */
393 static void lpt_lp_pm_init(struct device *dev)
394 {
396  u32 data;
397 
398  printk(BIOS_DEBUG, "LynxPoint LP PM init\n");
399 
400  pci_write_config8(dev, 0xa9, 0x46);
401 
402  RCBA32_AND_OR(0x232c, ~1, 0);
403 
404  RCBA32_AND_OR(0x1100, ~0xc000, 0xc000);
405  RCBA32_OR(0x1100, 0x00000100);
406  RCBA32_OR(0x1100, 0x0000003f);
407 
408  RCBA32_AND_OR(0x2320, ~0x60, 0x10);
409 
410  RCBA32(0x3314) = 0x00012fff;
411  RCBA32(0x3318) = 0x0dcf0400;
412  RCBA32(0x3324) = 0x04000000;
413  RCBA32(0x3368) = 0x00041400;
414  RCBA32(0x3388) = 0x3f8ddbff;
415  RCBA32(0x33ac) = 0x00007001;
416  RCBA32(0x33b0) = 0x00181900;
417  RCBA32(0x33c0) = 0x00060A00;
418  RCBA32(0x33d0) = 0x06200840;
419  RCBA32(0x3a28) = 0x01010101;
420  RCBA32(0x3a2c) = 0x04040404;
421  RCBA32(0x2b1c) = 0x03808033;
422  RCBA32(0x2b34) = 0x80000009;
423  RCBA32(0x3348) = 0x022ddfff;
424  RCBA32(0x334c) = 0x00000001;
425  RCBA32(0x3358) = 0x0001c000;
426  RCBA32(0x3380) = 0x3f8ddbff;
427  RCBA32(0x3384) = 0x0001c7e1;
428  RCBA32(0x338c) = 0x0001c7e1;
429  RCBA32(0x3398) = 0x0001c000;
430  RCBA32(0x33a8) = 0x00181900;
431  RCBA32(0x33dc) = 0x00080000;
432  RCBA32(0x33e0) = 0x00000001;
433  RCBA32(0x3a20) = 0x00000404;
434  RCBA32(0x3a24) = 0x01010101;
435  RCBA32(0x3a30) = 0x01010101;
436 
437  RCBA32_OR(0x0410, 0x00000003);
438  RCBA32_OR(0x2618, 0x08000000);
439  RCBA32_OR(0x2300, 0x00000002);
440  RCBA32_OR(0x2600, 0x00000008);
441 
442  RCBA32(0x33b4) = 0x00007001;
443  RCBA32(0x3350) = 0x022ddfff;
444  RCBA32(0x3354) = 0x00000001;
445 
446  /* Power Optimizer */
447  RCBA32_OR(0x33d4, 0x08000000);
448  RCBA32_OR(0x33c8, 0x00000080);
449 
450  RCBA32(0x2b10) = 0x0000883c;
451  RCBA32(0x2b14) = 0x1e0a4616;
452  RCBA32(0x2b24) = 0x40000005;
453  RCBA32(0x2b20) = 0x0005db01;
454  RCBA32(0x3a80) = 0x05145005;
455 
456  pci_or_config32(dev, 0xac, 1 << 21);
457 
458  pch_iobp_update(0xED00015C, ~(1 << 11), 0x00003700);
459  pch_iobp_update(0xED000118, ~0, 0x00c00000);
460  pch_iobp_update(0xED000120, ~0, 0x00240000);
461  pch_iobp_update(0xCA000000, ~0, 0x00000009);
462 
463  /* Set RCBA CIR28 0x3A84 based on SATA port enables */
464  data = 0x00001005;
465  /* Port 3 and 2 disabled */
466  if (config && (config->sata_port_map & ((1 << 3) | (1 << 2))) == 0)
467  data |= (1 << 24) | (1 << 26);
468  /* Port 1 and 0 disabled */
469  if (config && (config->sata_port_map & ((1 << 1) | (1 << 0))) == 0)
470  data |= (1 << 20) | (1 << 18);
471  RCBA32(0x3a84) = data;
472 
473  /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
474  if (RCBA32(FD) & PCH_DISABLE_ADSPD)
475  RCBA32_OR(0x2b1c, (1 << 29));
476 
477  /* Set RCBA 0x33D4 after other setup */
478  RCBA32_OR(0x33d4, 0x2fff2fb1);
479 
480  /* Set RCBA 0x33C8[15]=1 as last step */
481  RCBA32_OR(0x33c8, (1 << 15));
482 }
483 
484 static void enable_clock_gating(struct device *dev)
485 {
486  /* LynxPoint Mobile */
487  u32 reg32;
488  u16 reg16;
489 
490  /* DMI */
491  RCBA32_AND_OR(0x2234, ~0, 0xf);
492  reg16 = pci_read_config16(dev, GEN_PMCON_1);
493  reg16 |= (1 << 11) | (1 << 12) | (1 << 14);
494  reg16 |= (1 << 2); // PCI CLKRUN# Enable
495  pci_write_config16(dev, GEN_PMCON_1, reg16);
496  RCBA32_OR(0x900, (1 << 14));
497 
498  reg32 = RCBA32(CG);
499  reg32 |= (1 << 22); // HDA Dynamic
500  reg32 |= (1 << 31); // LPC Dynamic
501  reg32 |= (1 << 16); // PCIe Dynamic
502  reg32 |= (1 << 27); // HPET Dynamic
503  reg32 |= (1 << 28); // GPIO Dynamic
504  RCBA32(CG) = reg32;
505 
506  RCBA32_OR(0x38c0, 0x7); // SPI Dynamic
507 }
508 
509 static void enable_lp_clock_gating(struct device *dev)
510 {
511  /* LynxPoint LP */
512  u32 reg32;
513  u16 reg16;
514 
515  /* DMI */
516  RCBA32_AND_OR(0x2234, ~0, 0xf);
517  reg16 = pci_read_config16(dev, GEN_PMCON_1);
518  reg16 &= ~((1 << 11) | (1 << 14));
519  reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12) | (1 << 13);
520  reg16 |= (1 << 2); // PCI CLKRUN# Enable
521  pci_write_config16(dev, GEN_PMCON_1, reg16);
522 
523  pci_or_config32(dev, 0x64, 1 << 6);
524 
525  /*
526  * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
527  * RCBA + 0x2614[23:16] = 0x20
528  * RCBA + 0x2614[30:28] = 0x0
529  * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
530  */
531  RCBA32_AND_OR(0x2614, ~0x74000000, 0x0a206500);
532 
533  /* Check for LPT-LP B2 stepping and 0:31.0@0xFA > 4 */
534  struct device *const gma = pcidev_on_root(2, 0);
535  if (gma && pci_read_config8(gma, 0x8) >= 0x0b)
536  RCBA32_OR(0x2614, (1 << 26));
537 
538  RCBA32_OR(0x900, 0x0000031f);
539 
540  reg32 = RCBA32(CG);
541  if (RCBA32(0x3454) & (1 << 4))
542  reg32 &= ~(1 << 29); // LPC Dynamic
543  else
544  reg32 |= (1 << 29); // LPC Dynamic
545  reg32 |= (1 << 31); // LP LPC
546  reg32 |= (1 << 30); // LP BLA
547  reg32 |= (1 << 28); // GPIO Dynamic
548  reg32 |= (1 << 27); // HPET Dynamic
549  reg32 |= (1 << 26); // Generic Platform Event Clock
550  if (RCBA32(BUC) & PCH_DISABLE_GBE)
551  reg32 |= (1 << 23); // GbE Static
552  reg32 |= (1 << 22); // HDA Dynamic
553  reg32 |= (1 << 16); // PCI Dynamic
554  RCBA32(CG) = reg32;
555 
556  RCBA32_OR(0x3434, 0x7); // LP LPC
557 
558  RCBA32_OR(0x38c0, 0x3c07); // SPI Dynamic
559 
560  pch_iobp_update(0xCF000000, ~0, 0x00007001);
561  pch_iobp_update(0xCE00C000, ~1, 0x00000000); // bit0=0 in BWG 1.4.0
562 }
563 
564 static void pch_set_acpi_mode(void)
565 {
566  if (!acpi_is_wakeup_s3())
568 }
569 
570 static void lpc_init(struct device *dev)
571 {
572  printk(BIOS_DEBUG, "pch: %s\n", __func__);
573 
574  /* IO APIC initialization. */
575  pch_enable_ioapic(dev);
576 
578 
579  /* Setup the PIRQ. */
580  pch_pirq_init(dev);
581 
582  /* Setup power options. */
583  pch_power_options(dev);
584 
585  /* Initialize power management */
586  if (pch_is_lp()) {
587  lpt_lp_pm_init(dev);
589  } else {
590  lpt_pm_init(dev);
591  enable_clock_gating(dev);
592  }
593 
594  /* Initialize the real time clock. */
595  sb_rtc_init();
596 
597  /* Initialize ISA DMA. */
598  isa_dma_init();
599 
600  /* Initialize the High Precision Event Timers, if present. */
601  enable_hpet(dev);
602 
603  setup_i8259();
604 
605  /* Interrupt 9 should be level triggered (SCI) */
607 
609 
610  /* Indicate DRAM init done for MRC S3 to know it can resume */
611  pci_or_config8(dev, GEN_PMCON_2, 1 << 7);
612 }
613 
614 static void pch_lpc_add_mmio_resources(struct device *dev)
615 {
616  u32 reg;
617  struct resource *res;
618  const u32 default_decode_base = IO_APIC_ADDR;
619 
620  /*
621  * Just report all resources from IO-APIC base to 4GiB. Don't mark
622  * them reserved as that may upset the OS if this range is marked
623  * as reserved in the e820.
624  */
625  res = new_resource(dev, OIC);
626  res->base = default_decode_base;
627  res->size = 0 - default_decode_base;
629 
630  /* RCBA */
631  if (CONFIG_FIXED_RCBA_MMIO_BASE < default_decode_base) {
632  res = new_resource(dev, RCBA);
633  res->base = (resource_t)CONFIG_FIXED_RCBA_MMIO_BASE;
634  res->size = CONFIG_RCBA_LENGTH;
637  }
638 
639  /* Check LPC Memory Decode register. */
640  reg = pci_read_config32(dev, LGMR);
641  if (reg & 1) {
642  reg &= ~0xffff;
643  if (reg < default_decode_base) {
644  res = new_resource(dev, LGMR);
645  res->base = reg;
646  res->size = 16 * 1024;
649  }
650  }
651 }
652 
653 /* Default IO range claimed by the LPC device. The upper bound is exclusive. */
654 #define LPC_DEFAULT_IO_RANGE_LOWER 0
655 #define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
656 
657 static inline int pch_io_range_in_default(int base, int size)
658 {
659  /* Does it start above the range? */
661  return 0;
662 
663  /* Is it entirely contained? */
666  return 1;
667 
668  /* This will return not in range for partial overlaps. */
669  return 0;
670 }
671 
672 /*
673  * Note: this function assumes there is no overlap with the default LPC device's
674  * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
675  */
676 static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size,
677  int index)
678 {
679  struct resource *res;
680 
682  return;
683 
684  res = new_resource(dev, index);
685  res->base = base;
686  res->size = size;
688 }
689 
690 static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value,
691  int index)
692 {
693  /*
694  * Check if the register is enabled. If so, and the base exceeds the
695  * device's default claim range, add the resource.
696  */
697  if (reg_value & 1) {
698  u16 base = reg_value & 0xfffc;
699  u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
701  }
702 }
703 
704 static void pch_lpc_add_io_resources(struct device *dev)
705 {
706  struct resource *res;
707 
708  /* Add the default claimed IO range for the LPC device. */
709  res = new_resource(dev, 0);
713 
714  /* GPIOBASE */
716 
717  /* PMBASE */
719 
720  /* LPC Generic IO Decode range. */
721  if (dev->chip_info) {
727  }
728 }
729 
730 static void pch_lpc_read_resources(struct device *dev)
731 {
732  /* Get the normal PCI resources of this device. */
734 
735  /* Add non-standard MMIO resources. */
737 
738  /* Add IO resources. */
740 }
741 
742 static void pch_lpc_enable(struct device *dev)
743 {
744  /* Enable PCH Display Port */
745  RCBA16(DISPBDF) = 0x0010;
747 
748  pch_enable(dev);
749 }
750 
751 static const char *lpc_acpi_name(const struct device *dev)
752 {
753  return "LPCB";
754 }
755 
756 static void southbridge_fill_ssdt(const struct device *dev)
757 {
759 }
760 
761 static unsigned long southbridge_write_acpi_tables(const struct device *device,
762  unsigned long start,
763  struct acpi_rsdp *rsdp)
764 {
765  unsigned long current;
766 
767  current = start;
768 
769  /* Align ACPI tables to 16byte */
770  current = acpi_align_current(current);
771 
772  /*
773  * We explicitly add these tables later on:
774  */
775  current = acpi_write_hpet(device, current, rsdp);
776 
777  current = acpi_align_current(current);
778 
779  if (pch_is_lp()) {
780  printk(BIOS_DEBUG, "ACPI: * SSDT2\n");
781  acpi_header_t *ssdt = (acpi_header_t *)current;
783  current += ssdt->length;
784  acpi_add_table(rsdp, ssdt);
785  current = acpi_align_current(current);
786  }
787 
788  printk(BIOS_DEBUG, "current = %lx\n", current);
789  return current;
790 }
791 
792 static void lpc_final(struct device *dev)
793 {
795 
796  /* Lock */
797  RCBA32_OR(0x3a6c, 0x00000001);
798 
799  if (acpi_is_wakeup_s3() || CONFIG(INTEL_CHIPSET_LOCKDOWN))
801 }
802 
803 static struct device_operations device_ops = {
805  .set_resources = pci_dev_set_resources,
806  .enable_resources = pci_dev_enable_resources,
807  .acpi_fill_ssdt = southbridge_fill_ssdt,
808  .acpi_name = lpc_acpi_name,
809  .write_acpi_tables = southbridge_write_acpi_tables,
810  .init = lpc_init,
811  .final = lpc_final,
812  .enable = pch_lpc_enable,
813  .scan_bus = scan_static_bus,
814  .ops_pci = &pci_dev_ops_pci,
815 };
816 
817 /* IDs for LPC device of Intel 8 Series Chipset (Lynx Point) */
818 static const unsigned short pci_device_ids[] = {
838  0
839 };
840 
841 static const struct pci_driver pch_lpc __pci_driver = {
842  .ops = &device_ops,
843  .vendor = PCI_VID_INTEL,
844  .devices = pci_device_ids,
845 };
unsigned long acpi_write_hpet(const struct device *device, unsigned long current, acpi_rsdp_t *rsdp)
Definition: acpi.c:1141
void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Add an ACPI table to the RSDT (and XSDT) structure, recalculate length and checksum.
Definition: acpi.c:49
pirq
Definition: acpi_pirq_gen.h:20
uint16_t get_pmbase(void)
Definition: pmutil.c:254
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
#define VIO_APIC_VADDR
Definition: ioapic.h:7
#define IO_APIC_ADDR
Definition: ioapic.h:6
void setup_ioapic(void *ioapic_base, u8 ioapic_id)
Definition: ioapic.c:160
void ioapic_lock_max_vectors(void *ioapic_base)
Definition: ioapic.c:65
void ioapic_set_max_vectors(void *ioapic_base, int mre_count)
Definition: ioapic.c:51
#define GPIO_ROUT
Definition: pm.h:96
void enable_alt_smi(uint32_t mask)
Definition: pmutil.c:242
#define MAINBOARD_POWER_ON
Definition: pm.h:94
#define MAINBOARD_POWER_OFF
Definition: pm.h:93
#define MAINBOARD_POWER_KEEP
Definition: pm.h:95
void enable_all_gpe(uint32_t set1, uint32_t set2, uint32_t set3, uint32_t set4)
Definition: pmutil.c:385
#define printk(level,...)
Definition: stdlib.h:16
u8 inb(u16 port)
void outb(u8 val, u16 port)
u32 inl(u16 port)
void outl(u32 val, u16 port)
DEVTREE_CONST struct device *DEVTREE_CONST all_devices
Linked list of ALL devices.
Definition: device_const.c:13
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
@ CONFIG
Definition: dsi_common.h:201
void setup_i8259(void)
Definition: i8259.c:46
void i8259_configure_irq_trigger(int int_num, int is_level_triggered)
Configure IRQ triggering in the i8259 compatible Interrupt Controller.
Definition: i8259.c:99
static uintptr_t acpi_align_current(uintptr_t current)
Definition: acpi.h:1435
#define APM_CNT_ACPI_DISABLE
Definition: smm.h:21
#define APM_CNT_FINALIZE
Definition: smm.h:24
static __always_inline void pci_or_config32(const struct device *dev, u16 reg, u32 ormask)
Definition: pci_ops.h:191
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_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 void pci_or_config8(const struct device *dev, u16 reg, u8 ormask)
Definition: pci_ops.h:169
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
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
void isa_dma_init(void)
Definition: isa-dma.c:35
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
enum board_config config
Definition: memory.c:448
state
Definition: raminit.c:1787
unsigned int get_uint_option(const char *name, const unsigned int fallback)
Definition: option.c:116
@ DEVICE_PATH_PCI
Definition: path.h:9
#define PCI_INTERRUPT_PIN
Definition: pci_def.h:95
#define PCI_INTERRUPT_LINE
Definition: pci_def.h:94
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_LPT_Q87
Definition: pci_ids.h:2829
#define PCI_DID_INTEL_LPT_MOBILE_SAMPLE
Definition: pci_ids.h:2821
#define PCI_DID_INTEL_LPT_H81
Definition: pci_ids.h:2835
#define PCI_DID_INTEL_LPT_LP_PREMIUM
Definition: pci_ids.h:2837
#define PCI_DID_INTEL_LPT_C226
Definition: pci_ids.h:2834
#define PCI_DID_INTEL_LPT_DESKTOP_SAMPLE
Definition: pci_ids.h:2822
#define PCI_DID_INTEL_LPT_Q85
Definition: pci_ids.h:2828
#define PCI_DID_INTEL_LPT_C224
Definition: pci_ids.h:2833
#define PCI_DID_INTEL_LPT_C222
Definition: pci_ids.h:2832
#define PCI_DID_INTEL_LPT_LP_SAMPLE
Definition: pci_ids.h:2836
#define PCI_DID_INTEL_LPT_HM87
Definition: pci_ids.h:2827
#define PCI_DID_INTEL_LPT_QM87
Definition: pci_ids.h:2830
#define PCI_DID_INTEL_LPT_B85
Definition: pci_ids.h:2831
#define PCI_DID_INTEL_LPT_Z85
Definition: pci_ids.h:2824
#define PCI_DID_INTEL_LPT_LP_VALUE
Definition: pci_ids.h:2839
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define PCI_DID_INTEL_LPT_LP_MAINSTREAM
Definition: pci_ids.h:2838
#define PCI_DID_INTEL_LPT_Z87
Definition: pci_ids.h:2823
#define PCI_DID_INTEL_LPT_H87
Definition: pci_ids.h:2826
#define PCI_DID_INTEL_LPT_HM86
Definition: pci_ids.h:2825
void intel_acpi_gen_def_acpi_pirq(const struct device *lpc)
Definition: rcba_pirq.c:46
#define IORESOURCE_RESERVE
Definition: resource.h:30
#define IORESOURCE_MEM
Definition: resource.h:10
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
u64 resource_t
Definition: resource.h:43
#define IORESOURCE_FIXED
Definition: resource.h:36
void scan_static_bus(struct device *bus)
Definition: root_device.c:89
int apm_control(u8 cmd)
Definition: smi_trigger.c:31
uintptr_t base
Definition: uart.c:17
#define SERIRQ_CNTL
Definition: espi.h:21
#define LGMR
Definition: espi.h:29
#define RCBA
Definition: lpc.h:17
__weak void acpi_create_serialio_ssdt(acpi_header_t *ssdt)
Definition: acpi.c:371
#define PIRQE_ROUT
Definition: lpc.h:30
#define PMIR
Definition: lpc.h:72
#define PIRQG_ROUT
Definition: lpc.h:32
#define LPC_HnBDF(n)
Definition: lpc.h:77
#define LPC_GEN1_DEC
Definition: lpc.h:47
#define GEN_PMCON_3
Definition: lpc.h:63
#define PMIR_CF9LOCK
Definition: lpc.h:73
#define PMBASE
Definition: lpc.h:8
#define LPC_IBDF
Definition: lpc.h:76
#define LPC_GEN2_DEC
Definition: lpc.h:48
#define GEN_PMCON_2
Definition: lpc.h:58
#define LPC_GEN3_DEC
Definition: lpc.h:49
#define PIRQB_ROUT
Definition: lpc.h:27
#define GEN_PMCON_1
Definition: lpc.h:56
#define PIRQD_ROUT
Definition: lpc.h:29
#define PIRQC_ROUT
Definition: lpc.h:28
#define GPIO_BASE
Definition: lpc.h:21
#define LPC_GEN4_DEC
Definition: lpc.h:50
#define PIRQH_ROUT
Definition: lpc.h:33
#define PIRQA_ROUT
Definition: lpc.h:26
#define PIRQF_ROUT
Definition: lpc.h:31
#define PCH_IOAPIC_PCI_SLOT
Definition: pci_devs.h:81
#define PCH_HPET_PCI_SLOT
Definition: pci_devs.h:83
#define PCH_IOAPIC_PCI_BUS
Definition: pci_devs.h:80
#define PCH_HPET_PCI_BUS
Definition: pci_devs.h:82
#define CG
Definition: rcba.h:129
#define PCH_DISABLE_ADSPD
Definition: rcba.h:133
#define PCH_DISABLE_GBE
Definition: rcba.h:124
#define BUC
Definition: rcba.h:123
#define PCH_ENABLE_DBDF
Definition: rcba.h:150
#define OIC
Definition: rcba.h:100
#define FD2
Definition: rcba.h:128
#define HPTC
Definition: rcba.h:121
#define FD
Definition: rcba.h:125
#define DISPBDF
Definition: rcba.h:127
static uint16_t get_gpiobase(void)
Definition: pmutil.c:26
void pch_iobp_update(u32 address, u32 andvalue, u32 orvalue)
Definition: pch.c:86
void pch_enable(struct device *dev)
Definition: pch.c:404
#define RCBA32_OR(x, or)
Definition: rcba.h:22
#define RCBA32_AND_OR(x, and, or)
Definition: rcba.h:21
#define RCBA16(x)
Definition: rcba.h:13
#define RCBA32(x)
Definition: rcba.h:14
void sb_rtc_init(void)
Definition: rtc.c:21
void spi_finalize_ops(void)
Definition: spi.c:1039
static u16 pmbase
Definition: smi.c:27
static void pch_power_options(struct device *dev)
Definition: lpc.c:172
static void lpc_final(struct device *dev)
Definition: lpc.c:792
static const char * lpc_acpi_name(const struct device *dev)
Definition: lpc.c:751
static struct device_operations device_ops
Definition: lpc.c:803
static void configure_dmi_pm(struct device *dev)
Definition: lpc.c:278
static void pch_lpc_read_resources(struct device *dev)
Definition: lpc.c:730
static void southbridge_fill_ssdt(const struct device *dev)
Definition: lpc.c:756
static void pch_lpc_add_gen_io_resources(struct device *dev, int reg_value, int index)
Definition: lpc.c:690
static void pch_enable_serial_irqs(struct device *dev)
Definition: lpc.c:49
static int pch_io_range_in_default(int base, int size)
Definition: lpc.c:657
#define LPC_DEFAULT_IO_RANGE_LOWER
Definition: lpc.c:654
static void lpt_pm_init(struct device *dev)
Definition: lpc.c:309
static void enable_clock_gating(struct device *dev)
Definition: lpc.c:484
static void pch_gpi_routing(struct device *dev, struct southbridge_intel_lynxpoint_config *config)
Definition: lpc.c:144
static void enable_hpet(struct device *const dev)
Definition: lpc.c:60
static void pch_lpc_add_io_resources(struct device *dev)
Definition: lpc.c:704
static void pch_set_acpi_mode(void)
Definition: lpc.c:564
static void pch_lpc_add_io_resource(struct device *dev, u16 base, u16 size, int index)
Definition: lpc.c:676
static void lpc_init(struct device *dev)
Definition: lpc.c:570
static void lpt_lp_pm_init(struct device *dev)
Definition: lpc.c:393
static const struct pci_driver pch_lpc __pci_driver
Definition: lpc.c:841
static const unsigned short pci_device_ids[]
Definition: lpc.c:818
static void pch_lpc_enable(struct device *dev)
Definition: lpc.c:742
static void pch_enable_ioapic(struct device *dev)
Set miscellaneous static southbridge features.
Definition: lpc.c:32
static void pch_pirq_init(struct device *dev)
Definition: lpc.c:100
static void pch_lpc_add_mmio_resources(struct device *dev)
Definition: lpc.c:614
#define NMI_OFF
Definition: lpc.c:25
static unsigned long southbridge_write_acpi_tables(const struct device *device, unsigned long start, struct acpi_rsdp *rsdp)
Definition: lpc.c:761
#define LPC_DEFAULT_IO_RANGE_UPPER
Definition: lpc.c:655
static void enable_lp_clock_gating(struct device *dev)
Definition: lpc.c:509
static int pch_is_lp(void)
Definition: pch.h:104
#define DEFAULT_GPIOSIZE
Definition: pch.h:55
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
unsigned char uint8_t
Definition: stdint.h:8
Definition: acpi.h:82
void(* read_resources)(struct device *dev)
Definition: device.h:39
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
struct device_path path
Definition: device.h:115
DEVTREE_CONST struct device * next
Definition: device.h:113
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int enabled
Definition: device.h:122
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
unsigned long index
Definition: resource.h:50
resource_t size
Definition: resource.h:46