Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [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 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <console/console.h> |
| 24 | #include <arch/io.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 25 | #include <device/pci_def.h> |
Duncan Laurie | f4d3623 | 2012-06-23 16:37:45 -0700 | [diff] [blame] | 26 | #include <elog.h> |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 27 | #include <cbmem.h> |
Vladimir Serbinenko | 5fc04d1 | 2014-08-03 01:59:38 +0200 | [diff] [blame] | 28 | #include <pc80/mc146818rtc.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 29 | #include "sandybridge.h" |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 30 | |
| 31 | static void sandybridge_setup_bars(void) |
| 32 | { |
| 33 | /* Setting up Southbridge. In the northbridge code. */ |
| 34 | printk(BIOS_DEBUG, "Setting up static southbridge registers..."); |
| 35 | pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, DEFAULT_RCBA | 1); |
| 36 | |
| 37 | pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1); |
| 38 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */ |
| 39 | |
| 40 | printk(BIOS_DEBUG, " done.\n"); |
| 41 | |
| 42 | printk(BIOS_DEBUG, "Disabling Watchdog reboot..."); |
| 43 | RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */ |
| 44 | outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */ |
| 45 | printk(BIOS_DEBUG, " done.\n"); |
| 46 | |
| 47 | printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
| 48 | /* Set up all hardcoded northbridge BARs */ |
| 49 | pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1); |
| 50 | pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, (0LL+DEFAULT_EPBAR) >> 32); |
| 51 | pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1); |
| 52 | pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+DEFAULT_MCHBAR) >> 32); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 53 | pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, DEFAULT_DMIBAR | 1); |
| 54 | pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+DEFAULT_DMIBAR) >> 32); |
| 55 | |
| 56 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
| 57 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30); |
| 58 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33); |
| 59 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33); |
| 60 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33); |
| 61 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33); |
| 62 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33); |
| 63 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33); |
| 64 | |
Duncan Laurie | f4d3623 | 2012-06-23 16:37:45 -0700 | [diff] [blame] | 65 | #if CONFIG_ELOG_BOOT_COUNT |
| 66 | /* Increment Boot Counter for non-S3 resume */ |
| 67 | if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) && |
| 68 | ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) != SLP_TYP_S3) |
| 69 | boot_count_increment(); |
| 70 | #endif |
| 71 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 72 | printk(BIOS_DEBUG, " done.\n"); |
Duncan Laurie | 9c4c6ab | 2012-06-29 15:38:02 -0700 | [diff] [blame] | 73 | |
| 74 | #if CONFIG_ELOG_BOOT_COUNT |
| 75 | /* Increment Boot Counter except when resuming from S3 */ |
| 76 | if ((inw(DEFAULT_PMBASE + PM1_STS) & WAK_STS) && |
| 77 | ((inl(DEFAULT_PMBASE + PM1_CNT) >> 10) & 7) == SLP_TYP_S3) |
| 78 | return; |
| 79 | boot_count_increment(); |
| 80 | #endif |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void sandybridge_setup_graphics(void) |
| 84 | { |
| 85 | u32 reg32; |
| 86 | u16 reg16; |
| 87 | u8 reg8; |
Vladimir Serbinenko | 5fc04d1 | 2014-08-03 01:59:38 +0200 | [diff] [blame] | 88 | u8 gfxsize; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 89 | |
| 90 | reg16 = pci_read_config16(PCI_DEV(0,2,0), PCI_DEVICE_ID); |
| 91 | switch (reg16) { |
| 92 | case 0x0102: /* GT1 Desktop */ |
| 93 | case 0x0106: /* GT1 Mobile */ |
| 94 | case 0x010a: /* GT1 Server */ |
| 95 | case 0x0112: /* GT2 Desktop */ |
| 96 | case 0x0116: /* GT2 Mobile */ |
| 97 | case 0x0122: /* GT2 Desktop >=1.3GHz */ |
| 98 | case 0x0126: /* GT2 Mobile >=1.3GHz */ |
Stefan Reinauer | 816e9d1 | 2013-01-14 10:25:43 -0800 | [diff] [blame] | 99 | case 0x0156: /* IvyBridge */ |
Damien Zammit | a10bde9 | 2014-10-23 13:29:32 +1100 | [diff] [blame^] | 100 | case 0x0162: /* IvyBridge */ |
Stefan Reinauer | 816e9d1 | 2013-01-14 10:25:43 -0800 | [diff] [blame] | 101 | case 0x0166: /* IvyBridge */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 102 | break; |
| 103 | default: |
| 104 | printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n"); |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | printk(BIOS_DEBUG, "Initializing Graphics...\n"); |
| 109 | |
Vladimir Serbinenko | 5fc04d1 | 2014-08-03 01:59:38 +0200 | [diff] [blame] | 110 | if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) { |
| 111 | /* Setup IGD memory by setting GGC[7:3] = 1 for 32MB */ |
| 112 | gfxsize = 0; |
| 113 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 114 | reg16 = pci_read_config16(PCI_DEV(0,0,0), GGC); |
| 115 | reg16 &= ~0x00f8; |
Vladimir Serbinenko | 5fc04d1 | 2014-08-03 01:59:38 +0200 | [diff] [blame] | 116 | reg16 |= (gfxsize + 1) << 3; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 117 | /* Program GTT memory by setting GGC[9:8] = 2MB */ |
| 118 | reg16 &= ~0x0300; |
| 119 | reg16 |= 2 << 8; |
| 120 | /* Enable VGA decode */ |
| 121 | reg16 &= ~0x0002; |
| 122 | pci_write_config16(PCI_DEV(0,0,0), GGC, reg16); |
| 123 | |
| 124 | /* Enable 256MB aperture */ |
| 125 | reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC); |
| 126 | reg8 &= ~0x06; |
| 127 | reg8 |= 0x02; |
| 128 | pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8); |
| 129 | |
| 130 | /* Erratum workarounds */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 131 | reg32 = MCHBAR32(0x5f00); |
| 132 | reg32 |= (1 << 9)|(1 << 10); |
| 133 | MCHBAR32(0x5f00) = reg32; |
| 134 | |
| 135 | /* Enable SA Clock Gating */ |
| 136 | reg32 = MCHBAR32(0x5f00); |
| 137 | MCHBAR32(0x5f00) = reg32 | 1; |
| 138 | |
| 139 | /* GPU RC6 workaround for sighting 366252 */ |
| 140 | reg32 = MCHBAR32(0x5d14); |
| 141 | reg32 |= (1 << 31); |
| 142 | MCHBAR32(0x5d14) = reg32; |
| 143 | |
| 144 | /* VLW */ |
| 145 | reg32 = MCHBAR32(0x6120); |
| 146 | reg32 &= ~(1 << 0); |
| 147 | MCHBAR32(0x6120) = reg32; |
| 148 | |
| 149 | reg32 = MCHBAR32(0x5418); |
| 150 | reg32 |= (1 << 4) | (1 << 5); |
| 151 | MCHBAR32(0x5418) = reg32; |
| 152 | } |
| 153 | |
| 154 | void sandybridge_early_initialization(int chipset_type) |
| 155 | { |
| 156 | u32 capid0_a; |
| 157 | u8 reg8; |
| 158 | |
| 159 | /* Device ID Override Enable should be done very early */ |
| 160 | capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), 0xe4); |
| 161 | if (capid0_a & (1 << 10)) { |
| 162 | reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf3); |
| 163 | reg8 &= ~7; /* Clear 2:0 */ |
| 164 | |
| 165 | if (chipset_type == SANDYBRIDGE_MOBILE) |
| 166 | reg8 |= 1; /* Set bit 0 */ |
| 167 | |
| 168 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf3, reg8); |
| 169 | } |
| 170 | |
| 171 | /* Setup all BARs required for early PCIe and raminit */ |
| 172 | sandybridge_setup_bars(); |
| 173 | |
| 174 | /* Device Enable */ |
| 175 | pci_write_config32(PCI_DEV(0, 0, 0), DEVEN, DEVEN_HOST | DEVEN_IGD); |
| 176 | |
| 177 | sandybridge_setup_graphics(); |
| 178 | } |
Vladimir Serbinenko | c845b43 | 2014-09-05 03:37:44 +0200 | [diff] [blame] | 179 | |
| 180 | void northbridge_romstage_finalize(int s3resume) |
| 181 | { |
| 182 | MCHBAR16(SSKPD) = 0xCAFE; |
| 183 | |
| 184 | #if CONFIG_HAVE_ACPI_RESUME |
| 185 | /* If there is no high memory area, we didn't boot before, so |
| 186 | * this is not a resume. In that case we just create the cbmem toc. |
| 187 | */ |
| 188 | |
| 189 | *(u32 *)CBMEM_BOOT_MODE = 0; |
| 190 | *(u32 *)CBMEM_RESUME_BACKUP = 0; |
| 191 | |
| 192 | if (s3resume) { |
| 193 | void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME); |
| 194 | if (resume_backup_memory) { |
| 195 | *(u32 *)CBMEM_BOOT_MODE = 2; |
| 196 | *(u32 *)CBMEM_RESUME_BACKUP = (u32)resume_backup_memory; |
| 197 | } |
| 198 | /* Magic for S3 resume */ |
| 199 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafed00d); |
| 200 | } else { |
| 201 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, 0xcafebabe); |
| 202 | } |
| 203 | #endif |
| 204 | } |