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