blob: 7c522e005c8fed0e7bbd0d1dff9e1dd04a26cca3 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01003
4#include <stdint.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01005#include <console/console.h>
6#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01008#include <device/pci_def.h>
9#include <elog.h>
10#include <cpu/x86/msr.h>
11#include <cpu/intel/speedstep.h>
12#include <cpu/intel/turbo.h>
13#include <arch/cpu.h>
14
Angel Pons95de2312020-02-17 13:08:53 +010015#include "ironlake.h"
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010016
Angel Pons95de2312020-02-17 13:08:53 +010017static void ironlake_setup_bars(void)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010018{
19 /* Setting up Southbridge. In the northbridge code. */
20 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080021 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, (uintptr_t)DEFAULT_RCBA | 1);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010022
23 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
24 /* Enable ACPI BAR */
Elyes HAOUASa342f392018-10-17 10:56:26 +020025 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */, 0x80);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010026
27 printk(BIOS_DEBUG, " done.\n");
28
29 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
30 /* No reset */
31 RCBA32(GCS) = RCBA32(GCS) | (1 << 5);
32 /* halt timer */
33 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08);
34 /* halt timer */
35 outw(inw(DEFAULT_PMBASE | 0x60 | 0x06) | 2,
36 DEFAULT_PMBASE | 0x60 | 0x06);
37 printk(BIOS_DEBUG, " done.\n");
38
39 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
40 /* Set up all hardcoded northbridge BARs */
41 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
42 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4,
43 (0LL + DEFAULT_EPBAR) >> 32);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080044 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010045 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080046 (0LL + (uintptr_t)DEFAULT_MCHBAR) >> 32);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010047
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080048 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010049 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080050 (0LL + (uintptr_t)DEFAULT_DMIBAR) >> 32);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010051
52 /* Set C0000-FFFFF to access RAM on both reads and writes */
53 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(0), 0x30);
54 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(1), 0x33);
55 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(2), 0x33);
56 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(3), 0x33);
57 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(4), 0x33);
58 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(5), 0x33);
59 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(6), 0x33);
60
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010061 printk(BIOS_DEBUG, " done.\n");
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010062}
63
64static void early_cpu_init (void)
65{
66 msr_t m;
67
68 /* bit 0 = disable multicore,
69 bit 1 = disable quadcore,
70 bit 8 = disable hyperthreading. */
71 pci_write_config32(PCI_DEV(0xff, 0x00, 0), 0x80,
72 (pci_read_config32(PCI_DEV(0xff, 0x0, 0x0), 0x80) & 0xfffffefc) | 0x10000);
73
74 u8 reg8;
75 struct cpuid_result result;
76 result = cpuid_ext(0x6, 0x8b);
77 if (!(result.eax & 0x2)) {
78 m = rdmsr(MSR_FSB_CLOCK_VCC);
79 reg8 = ((m.lo & 0xff00) >> 8) + 1;
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +020080 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010081 m.lo = (m.lo & ~0xff) | reg8;
82 wrmsr(IA32_PERF_CTL, m);
83
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020084 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010085 m.hi &= ~0x00000040;
86 m.lo |= 0x10000;
87
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020088 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010089 }
90
91 m = rdmsr(MSR_FSB_CLOCK_VCC);
92 reg8 = ((m.lo & 0xff00) >> 8) + 1;
93
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +020094 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010095 m.lo = (m.lo & ~0xff) | reg8;
96 wrmsr(IA32_PERF_CTL, m);
97
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020098 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010099 m.lo |= 0x10000;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200100 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100101}
102
Angel Pons95de2312020-02-17 13:08:53 +0100103void ironlake_early_initialization(int chipset_type)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100104{
105 u32 capid0_a;
106 u8 reg8;
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300107 int s3_resume;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100108
109 /* Device ID Override Enable should be done very early */
110 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
111 if (capid0_a & (1 << 10)) {
112 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
113 reg8 &= ~7; /* Clear 2:0 */
114
Angel Pons95de2312020-02-17 13:08:53 +0100115 if (chipset_type == IRONLAKE_MOBILE)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100116 reg8 |= 1; /* Set bit 0 */
117
118 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
119 }
120
121 /* Setup all BARs required for early PCIe and raminit */
Angel Pons95de2312020-02-17 13:08:53 +0100122 ironlake_setup_bars();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100123
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300124 s3_resume = (inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
125 (((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3);
126
Kyösti Mälkki7f50afb2019-09-11 17:12:26 +0300127 elog_boot_notify(s3_resume);
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300128
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100129 /* Device Enable */
Patrick Rudolph847f12b2018-06-14 16:00:19 +0200130 pci_write_config32(PCI_DEV(0, 0, 0), D0F0_DEVEN,
131 DEVEN_IGD | DEVEN_PEG10 | DEVEN_HOST);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100132
133 early_cpu_init();
134
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800135 pci_write_config32(PCI_DEV(0, 0x16, 0), 0x10, (uintptr_t)DEFAULT_HECIBAR);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100136 pci_write_config32(PCI_DEV(0, 0x16, 0), PCI_COMMAND,
137 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100138
139 /* Magic for S3 resume. Must be done early. */
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300140 if (s3_resume) {
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100141 MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~1) | 6;
142 MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~3) | 4;
143 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100144}