Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 7 | #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 Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 14 | #include "ironlake.h" |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 15 | |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 16 | static void ironlake_setup_bars(void) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 17 | { |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 18 | printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
| 19 | /* Set up all hardcoded northbridge BARs */ |
Angel Pons | a8df6cf | 2021-01-20 01:32:17 +0100 | [diff] [blame] | 20 | 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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 26 | |
| 27 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
Angel Pons | 3ab19b3 | 2020-07-22 16:29:54 +0200 | [diff] [blame] | 28 | 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 Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 35 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 36 | printk(BIOS_DEBUG, " done.\n"); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Angel Pons | 43bcc7b | 2020-06-22 18:11:31 +0200 | [diff] [blame] | 39 | static void early_cpu_init(void) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 40 | { |
| 41 | msr_t m; |
| 42 | |
| 43 | /* bit 0 = disable multicore, |
| 44 | bit 1 = disable quadcore, |
| 45 | bit 8 = disable hyperthreading. */ |
Angel Pons | 9addda3 | 2020-07-22 18:37:32 +0200 | [diff] [blame] | 46 | pci_update_config32(QPI_NON_CORE, DESIRED_CORES, 0xfffffefc, 0x10000); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 47 | |
| 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 HAOUAS | 4fe0cba | 2018-10-17 20:20:39 +0200 | [diff] [blame] | 54 | m = rdmsr(IA32_PERF_CTL); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 55 | m.lo = (m.lo & ~0xff) | reg8; |
| 56 | wrmsr(IA32_PERF_CTL, m); |
| 57 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 58 | m = rdmsr(IA32_MISC_ENABLE); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 59 | m.hi &= ~0x00000040; |
| 60 | m.lo |= 0x10000; |
| 61 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 62 | wrmsr(IA32_MISC_ENABLE, m); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | m = rdmsr(MSR_FSB_CLOCK_VCC); |
| 66 | reg8 = ((m.lo & 0xff00) >> 8) + 1; |
| 67 | |
Elyes HAOUAS | 4fe0cba | 2018-10-17 20:20:39 +0200 | [diff] [blame] | 68 | m = rdmsr(IA32_PERF_CTL); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 69 | m.lo = (m.lo & ~0xff) | reg8; |
| 70 | wrmsr(IA32_PERF_CTL, m); |
| 71 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 72 | m = rdmsr(IA32_MISC_ENABLE); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 73 | m.lo |= 0x10000; |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 74 | wrmsr(IA32_MISC_ENABLE, m); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 77 | void ironlake_early_initialization(int chipset_type) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 78 | { |
| 79 | u32 capid0_a; |
| 80 | u8 reg8; |
Kyösti Mälkki | 2cce24d | 2019-09-11 10:47:39 +0300 | [diff] [blame] | 81 | int s3_resume; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 82 | |
| 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 Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 89 | if (chipset_type == IRONLAKE_MOBILE) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 90 | 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 Pons | e4c0555 | 2020-07-22 00:40:21 +0200 | [diff] [blame] | 96 | ibexpeak_setup_bars(); |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 97 | ironlake_setup_bars(); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 98 | |
Kyösti Mälkki | 2cce24d | 2019-09-11 10:47:39 +0300 | [diff] [blame] | 99 | s3_resume = (inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) && |
| 100 | (((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3); |
| 101 | |
Kyösti Mälkki | 7f50afb | 2019-09-11 17:12:26 +0300 | [diff] [blame] | 102 | elog_boot_notify(s3_resume); |
Kyösti Mälkki | 2cce24d | 2019-09-11 10:47:39 +0300 | [diff] [blame] | 103 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 104 | /* Device Enable */ |
Angel Pons | 16fe1e0 | 2020-07-22 16:12:33 +0200 | [diff] [blame] | 105 | pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, DEVEN_IGD | DEVEN_PEG10 | DEVEN_HOST); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 106 | |
| 107 | early_cpu_init(); |
| 108 | |
Vladimir Serbinenko | bca9855 | 2014-01-09 11:13:18 +0100 | [diff] [blame] | 109 | /* Magic for S3 resume. Must be done early. */ |
Kyösti Mälkki | 2cce24d | 2019-09-11 10:47:39 +0300 | [diff] [blame] | 110 | if (s3_resume) { |
Angel Pons | dea722b | 2021-03-26 14:11:12 +0100 | [diff] [blame] | 111 | mchbar_clrsetbits32(0x1e8, 1, 6); |
| 112 | mchbar_clrsetbits32(0x1e8, 3, 4); |
Vladimir Serbinenko | bca9855 | 2014-01-09 11:13:18 +0100 | [diff] [blame] | 113 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 114 | } |