blob: 4f221bfe9cce0696e3a75562aecc8b7db573f74e [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01002
3#include <stdint.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01004#include <console/console.h>
5#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01007#include <device/pci_def.h>
8#include <elog.h>
9#include <cpu/x86/msr.h>
10#include <cpu/intel/speedstep.h>
11#include <cpu/intel/turbo.h>
12#include <arch/cpu.h>
13
Angel Pons95de2312020-02-17 13:08:53 +010014#include "ironlake.h"
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010015
Angel Pons95de2312020-02-17 13:08:53 +010016static void ironlake_setup_bars(void)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010017{
18 /* Setting up Southbridge. In the northbridge code. */
19 printk(BIOS_DEBUG, "Setting up static southbridge registers...");
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080020 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, (uintptr_t)DEFAULT_RCBA | 1);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010021
22 pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1);
23 /* Enable ACPI BAR */
Elyes HAOUASa342f392018-10-17 10:56:26 +020024 pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */, 0x80);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010025
26 printk(BIOS_DEBUG, " done.\n");
27
28 printk(BIOS_DEBUG, "Disabling Watchdog reboot...");
29 /* No reset */
30 RCBA32(GCS) = RCBA32(GCS) | (1 << 5);
31 /* halt timer */
32 outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08);
33 /* halt timer */
34 outw(inw(DEFAULT_PMBASE | 0x60 | 0x06) | 2,
35 DEFAULT_PMBASE | 0x60 | 0x06);
36 printk(BIOS_DEBUG, " done.\n");
37
38 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
39 /* Set up all hardcoded northbridge BARs */
40 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1);
Angel Pons68ab7452020-06-22 18:23:17 +020041 pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, 0);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080042 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1);
Angel Pons68ab7452020-06-22 18:23:17 +020043 pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, 0);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080044 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1);
Angel Pons68ab7452020-06-22 18:23:17 +020045 pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010046
47 /* Set C0000-FFFFF to access RAM on both reads and writes */
48 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(0), 0x30);
49 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(1), 0x33);
50 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(2), 0x33);
51 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(3), 0x33);
52 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(4), 0x33);
53 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(5), 0x33);
54 pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(6), 0x33);
55
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010056 printk(BIOS_DEBUG, " done.\n");
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010057}
58
59static void early_cpu_init (void)
60{
61 msr_t m;
62
63 /* bit 0 = disable multicore,
64 bit 1 = disable quadcore,
65 bit 8 = disable hyperthreading. */
Angel Pons8308e2b2020-06-22 18:34:51 +020066 pci_update_config32(PCI_DEV(0xff, 0x00, 0), 0x80, 0xfffffefc, 0x10000);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010067
68 u8 reg8;
69 struct cpuid_result result;
70 result = cpuid_ext(0x6, 0x8b);
71 if (!(result.eax & 0x2)) {
72 m = rdmsr(MSR_FSB_CLOCK_VCC);
73 reg8 = ((m.lo & 0xff00) >> 8) + 1;
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +020074 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010075 m.lo = (m.lo & ~0xff) | reg8;
76 wrmsr(IA32_PERF_CTL, m);
77
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020078 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010079 m.hi &= ~0x00000040;
80 m.lo |= 0x10000;
81
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020082 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010083 }
84
85 m = rdmsr(MSR_FSB_CLOCK_VCC);
86 reg8 = ((m.lo & 0xff00) >> 8) + 1;
87
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +020088 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010089 m.lo = (m.lo & ~0xff) | reg8;
90 wrmsr(IA32_PERF_CTL, m);
91
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020092 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010093 m.lo |= 0x10000;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020094 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010095}
96
Angel Pons95de2312020-02-17 13:08:53 +010097void ironlake_early_initialization(int chipset_type)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010098{
99 u32 capid0_a;
100 u8 reg8;
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300101 int s3_resume;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100102
103 /* Device ID Override Enable should be done very early */
104 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
105 if (capid0_a & (1 << 10)) {
106 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
107 reg8 &= ~7; /* Clear 2:0 */
108
Angel Pons95de2312020-02-17 13:08:53 +0100109 if (chipset_type == IRONLAKE_MOBILE)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100110 reg8 |= 1; /* Set bit 0 */
111
112 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
113 }
114
115 /* Setup all BARs required for early PCIe and raminit */
Angel Pons95de2312020-02-17 13:08:53 +0100116 ironlake_setup_bars();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100117
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300118 s3_resume = (inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
119 (((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3);
120
Kyösti Mälkki7f50afb2019-09-11 17:12:26 +0300121 elog_boot_notify(s3_resume);
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300122
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100123 /* Device Enable */
Patrick Rudolph847f12b2018-06-14 16:00:19 +0200124 pci_write_config32(PCI_DEV(0, 0, 0), D0F0_DEVEN,
125 DEVEN_IGD | DEVEN_PEG10 | DEVEN_HOST);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100126
127 early_cpu_init();
128
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800129 pci_write_config32(PCI_DEV(0, 0x16, 0), 0x10, (uintptr_t)DEFAULT_HECIBAR);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100130 pci_write_config32(PCI_DEV(0, 0x16, 0), PCI_COMMAND,
131 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100132
133 /* Magic for S3 resume. Must be done early. */
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300134 if (s3_resume) {
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100135 MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~1) | 6;
136 MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~3) | 4;
137 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100138}