blob: b765417274976e86e35dbba20e3daf2640728bb5 [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{
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010018 printk(BIOS_DEBUG, "Setting up static northbridge registers...");
19 /* Set up all hardcoded northbridge BARs */
Angel Ponsa8df6cf2021-01-20 01:32:17 +010020 pci_write_config32(PCI_DEV(0, 0, 0), EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1);
21 pci_write_config32(PCI_DEV(0, 0, 0), EPBAR + 4, 0);
22 pci_write_config32(PCI_DEV(0, 0, 0), MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1);
23 pci_write_config32(PCI_DEV(0, 0, 0), MCHBAR + 4, 0);
24 pci_write_config32(PCI_DEV(0, 0, 0), DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1);
25 pci_write_config32(PCI_DEV(0, 0, 0), DMIBAR + 4, 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010026
27 /* Set C0000-FFFFF to access RAM on both reads and writes */
Angel Pons3ab19b32020-07-22 16:29:54 +020028 pci_write_config8(QPI_SAD, QPD0F1_PAM(0), 0x30);
29 pci_write_config8(QPI_SAD, QPD0F1_PAM(1), 0x33);
30 pci_write_config8(QPI_SAD, QPD0F1_PAM(2), 0x33);
31 pci_write_config8(QPI_SAD, QPD0F1_PAM(3), 0x33);
32 pci_write_config8(QPI_SAD, QPD0F1_PAM(4), 0x33);
33 pci_write_config8(QPI_SAD, QPD0F1_PAM(5), 0x33);
34 pci_write_config8(QPI_SAD, QPD0F1_PAM(6), 0x33);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010035
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010036 printk(BIOS_DEBUG, " done.\n");
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010037}
38
Angel Pons43bcc7b2020-06-22 18:11:31 +020039static void early_cpu_init(void)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010040{
41 msr_t m;
42
43 /* bit 0 = disable multicore,
44 bit 1 = disable quadcore,
45 bit 8 = disable hyperthreading. */
Angel Pons9addda32020-07-22 18:37:32 +020046 pci_update_config32(QPI_NON_CORE, DESIRED_CORES, 0xfffffefc, 0x10000);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010047
48 u8 reg8;
49 struct cpuid_result result;
50 result = cpuid_ext(0x6, 0x8b);
51 if (!(result.eax & 0x2)) {
52 m = rdmsr(MSR_FSB_CLOCK_VCC);
53 reg8 = ((m.lo & 0xff00) >> 8) + 1;
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +020054 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010055 m.lo = (m.lo & ~0xff) | reg8;
56 wrmsr(IA32_PERF_CTL, m);
57
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020058 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010059 m.hi &= ~0x00000040;
60 m.lo |= 0x10000;
61
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020062 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010063 }
64
65 m = rdmsr(MSR_FSB_CLOCK_VCC);
66 reg8 = ((m.lo & 0xff00) >> 8) + 1;
67
Elyes HAOUAS4fe0cba2018-10-17 20:20:39 +020068 m = rdmsr(IA32_PERF_CTL);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010069 m.lo = (m.lo & ~0xff) | reg8;
70 wrmsr(IA32_PERF_CTL, m);
71
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020072 m = rdmsr(IA32_MISC_ENABLE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010073 m.lo |= 0x10000;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020074 wrmsr(IA32_MISC_ENABLE, m);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010075}
76
Angel Pons95de2312020-02-17 13:08:53 +010077void ironlake_early_initialization(int chipset_type)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010078{
79 u32 capid0_a;
80 u8 reg8;
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +030081 int s3_resume;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010082
83 /* Device ID Override Enable should be done very early */
84 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4);
85 if (capid0_a & (1 << 10)) {
86 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3);
87 reg8 &= ~7; /* Clear 2:0 */
88
Angel Pons95de2312020-02-17 13:08:53 +010089 if (chipset_type == IRONLAKE_MOBILE)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010090 reg8 |= 1; /* Set bit 0 */
91
92 pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8);
93 }
94
95 /* Setup all BARs required for early PCIe and raminit */
Angel Ponse4c05552020-07-22 00:40:21 +020096 ibexpeak_setup_bars();
Angel Pons95de2312020-02-17 13:08:53 +010097 ironlake_setup_bars();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010098
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +030099 s3_resume = (inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) &&
100 (((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3);
101
Kyösti Mälkki7f50afb2019-09-11 17:12:26 +0300102 elog_boot_notify(s3_resume);
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300103
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100104 /* Device Enable */
Angel Pons16fe1e02020-07-22 16:12:33 +0200105 pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, DEVEN_IGD | DEVEN_PEG10 | DEVEN_HOST);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100106
107 early_cpu_init();
108
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100109 /* Magic for S3 resume. Must be done early. */
Kyösti Mälkki2cce24d2019-09-11 10:47:39 +0300110 if (s3_resume) {
Angel Ponsdea722b2021-03-26 14:11:12 +0100111 mchbar_clrsetbits32(0x1e8, 1, 6);
112 mchbar_clrsetbits32(0x1e8, 3, 4);
Vladimir Serbinenkobca98552014-01-09 11:13:18 +0100113 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100114}