blob: a349dcdc69eec78ab11e6e1e9992eba27aa39629 [file] [log] [blame]
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001/*
2 * This file is part of the coreboot project.
3 *
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010013 */
14
15#include <stdint.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010016#include <console/console.h>
17#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010019#include <device/pci_def.h>
20#include <elog.h>
21#include <cpu/x86/msr.h>
22#include <cpu/intel/speedstep.h>
23#include <cpu/intel/turbo.h>
24#include <arch/cpu.h>
25
Angel Pons95de2312020-02-17 13:08:53 +010026#include "ironlake.h"
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010027
Angel Pons95de2312020-02-17 13:08:53 +010028static void ironlake_setup_bars(void)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010029{
30 /* Setting up Southbridge. In the northbridge code. */
31 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080032 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, (uintptr_t)DEFAULT_RCBA | 1);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010033
34 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
35 /* Enable ACPI BAR */
Elyes HAOUASa342f392018-10-17 10:56:26 +020036 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */, 0x80);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010037
38 printk(BIOS_DEBUG, " done.\n");
39
40 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
41 /* No reset */
42 RCBA32(GCS) = RCBA32(GCS) | (1 << 5);
43 /* halt timer */
44 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08);
45 /* halt timer */
46 outw(inw(DEFAULT_PMBASE | 0x60 | 0x06) | 2,
47 DEFAULT_PMBASE | 0x60 | 0x06);
48 printk(BIOS_DEBUG, " done.\n");
49
50 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
51 /* Set up all hardcoded northbridge BARs */
52 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
53 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4,
54 (0LL + DEFAULT_EPBAR) >> 32);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010056 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080057 (0LL + (uintptr_t)DEFAULT_MCHBAR) >> 32);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010058
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080059 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010060 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4,
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080061 (0LL + (uintptr_t)DEFAULT_DMIBAR) >> 32);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010062
63 /* Set C0000-FFFFF to access RAM on both reads and writes */
64 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(0), 0x30);
65 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(1), 0x33);
66 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(2), 0x33);
67 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(3), 0x33);
68 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(4), 0x33);
69 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(5), 0x33);
70 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(6), 0x33);
71
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010072 printk(BIOS_DEBUG, " done.\n");
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010073}
74
75static void early_cpu_init (void)
76{
77 msr_t m;
78
79 /* bit 0 = disable multicore,
80 bit 1 = disable quadcore,
81 bit 8 = disable hyperthreading. */
82 pci_write_config32(PCI_DEV(0xff, 0x00, 0), 0x80,
83 (pci_read_config32(PCI_DEV(0xff, 0x0, 0x0), 0x80) & 0xfffffefc) | 0x10000);
84
85 u8 reg8;
86 struct cpuid_result result;
87 result = cpuid_ext(0x6, 0x8b);
88 if (!(result.eax & 0x2)) {
89 m = rdmsr(MSR_FSB_CLOCK_VCC);
90 reg8 = ((m.lo & 0xff00) >> 8) + 1;
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +020091 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010092 m.lo = (m.lo & ~0xff) | reg8;
93 wrmsr(IA32_PERF_CTL, m);
94
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020095 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010096 m.hi &= ~0x00000040;
97 m.lo |= 0x10000;
98
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020099 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100100 }
101
102 m = rdmsr(MSR_FSB_CLOCK_VCC);
103 reg8 = ((m.lo & 0xff00) >> 8) + 1;
104
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +0200105 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100106 m.lo = (m.lo & ~0xff) | reg8;
107 wrmsr(IA32_PERF_CTL, m);
108
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200109 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100110 m.lo |= 0x10000;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200111 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100112}
113
Angel Pons95de2312020-02-17 13:08:53 +0100114void ironlake_early_initialization(int chipset_type)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100115{
116 u32 capid0_a;
117 u8 reg8;
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300118 int s3_resume;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100119
120 /* Device ID Override Enable should be done very early */
121 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
122 if (capid0_a & (1 << 10)) {
123 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
124 reg8 &= ~7; /* Clear 2:0 */
125
Angel Pons95de2312020-02-17 13:08:53 +0100126 if (chipset_type == IRONLAKE_MOBILE)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100127 reg8 |= 1; /* Set bit 0 */
128
129 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
130 }
131
132 /* Setup all BARs required for early PCIe and raminit */
Angel Pons95de2312020-02-17 13:08:53 +0100133 ironlake_setup_bars();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100134
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300135 s3_resume = (inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
136 (((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3);
137
Kyösti Mälkki7f50afb2019-09-11 17:12:26 +0300138 elog_boot_notify(s3_resume);
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300139
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100140 /* Device Enable */
Patrick Rudolph847f12b2018-06-14 16:00:19 +0200141 pci_write_config32(PCI_DEV(0, 0, 0), D0F0_DEVEN,
142 DEVEN_IGD | DEVEN_PEG10 | DEVEN_HOST);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100143
144 early_cpu_init();
145
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800146 pci_write_config32(PCI_DEV(0, 0x16, 0), 0x10, (uintptr_t)DEFAULT_HECIBAR);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100147 pci_write_config32(PCI_DEV(0, 0x16, 0), PCI_COMMAND,
148 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100149
150 /* Magic for S3 resume. Must be done early. */
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300151 if (s3_resume) {
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100152 MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~1) | 6;
153 MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~3) | 4;
154 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100155}