Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2010 coresystems GmbH |
| 5 | * Copyright (C) 2011 Google Inc |
| 6 | * Copyright (C) 2013 Vladimir Serbinenko |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <console/console.h> |
| 21 | #include <arch/io.h> |
| 22 | #include <device/pci_def.h> |
| 23 | #include <elog.h> |
| 24 | #include <cpu/x86/msr.h> |
| 25 | #include <cpu/intel/speedstep.h> |
| 26 | #include <cpu/intel/turbo.h> |
| 27 | #include <arch/cpu.h> |
| 28 | |
| 29 | #include "nehalem.h" |
| 30 | |
| 31 | static void nehalem_setup_bars(void) |
| 32 | { |
| 33 | /* Setting up Southbridge. In the northbridge code. */ |
| 34 | printk(BIOS_DEBUG, "Setting up static southbridge registers..."); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 35 | pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, (uintptr_t)DEFAULT_RCBA | 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 36 | |
| 37 | pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1); |
| 38 | /* Enable ACPI BAR */ |
| 39 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); |
| 40 | |
| 41 | printk(BIOS_DEBUG, " done.\n"); |
| 42 | |
| 43 | printk(BIOS_DEBUG, "Disabling Watchdog reboot..."); |
| 44 | /* No reset */ |
| 45 | RCBA32(GCS) = RCBA32(GCS) | (1 << 5); |
| 46 | /* halt timer */ |
| 47 | outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); |
| 48 | /* halt timer */ |
| 49 | outw(inw(DEFAULT_PMBASE | 0x60 | 0x06) | 2, |
| 50 | DEFAULT_PMBASE | 0x60 | 0x06); |
| 51 | printk(BIOS_DEBUG, " done.\n"); |
| 52 | |
| 53 | printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
| 54 | /* Set up all hardcoded northbridge BARs */ |
| 55 | pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1); |
| 56 | pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, |
| 57 | (0LL + DEFAULT_EPBAR) >> 32); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 58 | pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 59 | pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 60 | (0LL + (uintptr_t)DEFAULT_MCHBAR) >> 32); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 61 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 62 | pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 63 | pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 64 | (0LL + (uintptr_t)DEFAULT_DMIBAR) >> 32); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 65 | |
| 66 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
| 67 | pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(0), 0x30); |
| 68 | pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(1), 0x33); |
| 69 | pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(2), 0x33); |
| 70 | pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(3), 0x33); |
| 71 | pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(4), 0x33); |
| 72 | pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(5), 0x33); |
| 73 | pci_write_config8(PCI_DEV(0xff, 0x00, 1), QPD0F1_PAM(6), 0x33); |
| 74 | |
Martin Roth | 3323260 | 2017-06-24 14:48:50 -0600 | [diff] [blame] | 75 | #if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 76 | /* Increment Boot Counter for non-S3 resume */ |
| 77 | if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) && |
| 78 | ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) != SLP_TYP_S3) |
| 79 | boot_count_increment(); |
| 80 | #endif |
| 81 | |
| 82 | printk(BIOS_DEBUG, " done.\n"); |
| 83 | |
Martin Roth | 3323260 | 2017-06-24 14:48:50 -0600 | [diff] [blame] | 84 | #if IS_ENABLED(CONFIG_ELOG_BOOT_COUNT) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 85 | /* Increment Boot Counter except when resuming from S3 */ |
| 86 | if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) && |
| 87 | ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3) |
| 88 | return; |
| 89 | boot_count_increment(); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | static void early_cpu_init (void) |
| 94 | { |
| 95 | msr_t m; |
| 96 | |
| 97 | /* bit 0 = disable multicore, |
| 98 | bit 1 = disable quadcore, |
| 99 | bit 8 = disable hyperthreading. */ |
| 100 | pci_write_config32(PCI_DEV(0xff, 0x00, 0), 0x80, |
| 101 | (pci_read_config32(PCI_DEV(0xff, 0x0, 0x0), 0x80) & 0xfffffefc) | 0x10000); |
| 102 | |
| 103 | u8 reg8; |
| 104 | struct cpuid_result result; |
| 105 | result = cpuid_ext(0x6, 0x8b); |
| 106 | if (!(result.eax & 0x2)) { |
| 107 | m = rdmsr(MSR_FSB_CLOCK_VCC); |
| 108 | reg8 = ((m.lo & 0xff00) >> 8) + 1; |
Elyes HAOUAS | 4fe0cba | 2018-10-17 20:20:39 +0200 | [diff] [blame] | 109 | m = rdmsr(IA32_PERF_CTL); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 110 | m.lo = (m.lo & ~0xff) | reg8; |
| 111 | wrmsr(IA32_PERF_CTL, m); |
| 112 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 113 | m = rdmsr(IA32_MISC_ENABLE); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 114 | m.hi &= ~0x00000040; |
| 115 | m.lo |= 0x10000; |
| 116 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 117 | wrmsr(IA32_MISC_ENABLE, m); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | m = rdmsr(MSR_FSB_CLOCK_VCC); |
| 121 | reg8 = ((m.lo & 0xff00) >> 8) + 1; |
| 122 | |
Elyes HAOUAS | 4fe0cba | 2018-10-17 20:20:39 +0200 | [diff] [blame] | 123 | m = rdmsr(IA32_PERF_CTL); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 124 | m.lo = (m.lo & ~0xff) | reg8; |
| 125 | wrmsr(IA32_PERF_CTL, m); |
| 126 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 127 | m = rdmsr(IA32_MISC_ENABLE); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 128 | m.lo |= 0x10000; |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 129 | wrmsr(IA32_MISC_ENABLE, m); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void nehalem_early_initialization(int chipset_type) |
| 133 | { |
| 134 | u32 capid0_a; |
| 135 | u8 reg8; |
| 136 | |
| 137 | /* Device ID Override Enable should be done very early */ |
| 138 | capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4); |
| 139 | if (capid0_a & (1 << 10)) { |
| 140 | reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3); |
| 141 | reg8 &= ~7; /* Clear 2:0 */ |
| 142 | |
| 143 | if (chipset_type == NEHALEM_MOBILE) |
| 144 | reg8 |= 1; /* Set bit 0 */ |
| 145 | |
| 146 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8); |
| 147 | } |
| 148 | |
| 149 | /* Setup all BARs required for early PCIe and raminit */ |
| 150 | nehalem_setup_bars(); |
| 151 | |
| 152 | /* Device Enable */ |
Patrick Rudolph | 847f12b | 2018-06-14 16:00:19 +0200 | [diff] [blame] | 153 | pci_write_config32(PCI_DEV(0, 0, 0), D0F0_DEVEN, |
| 154 | DEVEN_IGD | DEVEN_PEG10 | DEVEN_HOST); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 155 | |
| 156 | early_cpu_init(); |
| 157 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 158 | pci_write_config32(PCI_DEV(0, 0x16, 0), 0x10, (uintptr_t)DEFAULT_HECIBAR); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 159 | pci_write_config32(PCI_DEV(0, 0x16, 0), PCI_COMMAND, |
| 160 | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
Vladimir Serbinenko | bca9855 | 2014-01-09 11:13:18 +0100 | [diff] [blame] | 161 | |
| 162 | /* Magic for S3 resume. Must be done early. */ |
| 163 | if (((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3) { |
| 164 | MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~1) | 6; |
| 165 | MCHBAR32 (0x1e8) = (MCHBAR32(0x1e8) & ~3) | 4; |
| 166 | } |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 167 | } |