Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [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. |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <console/console.h> |
| 20 | #include <arch/io.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 21 | #include <device/pci_def.h> |
| 22 | #include <elog.h> |
| 23 | #include "haswell.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 24 | |
| 25 | static void haswell_setup_bars(void) |
| 26 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 27 | printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
| 28 | /* Set up all hardcoded northbridge BARs */ |
| 29 | pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1); |
| 30 | pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR + 4, (0LL+DEFAULT_EPBAR) >> 32); |
| 31 | pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, DEFAULT_MCHBAR | 1); |
| 32 | pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR + 4, (0LL+DEFAULT_MCHBAR) >> 32); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 33 | pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1); |
| 34 | pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR + 4, (0LL+(uintptr_t)DEFAULT_DMIBAR) >> 32); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 35 | |
| 36 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
| 37 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30); |
| 38 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33); |
| 39 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33); |
| 40 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33); |
| 41 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33); |
| 42 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33); |
| 43 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33); |
| 44 | |
| 45 | printk(BIOS_DEBUG, " done.\n"); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static void haswell_setup_graphics(void) |
| 49 | { |
Tristan Corrick | c5d367b | 2018-12-17 22:10:07 +1300 | [diff] [blame] | 50 | bool igd_enabled; |
| 51 | u16 ggc; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 52 | u8 reg8; |
| 53 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 54 | printk(BIOS_DEBUG, "Initializing Graphics...\n"); |
| 55 | |
Tristan Corrick | c5d367b | 2018-12-17 22:10:07 +1300 | [diff] [blame] | 56 | igd_enabled = !!(pci_read_config32(PCI_DEV(0, 0, 0), DEVEN) |
| 57 | & DEVEN_D2EN); |
| 58 | |
| 59 | ggc = pci_read_config16(PCI_DEV(0, 0, 0), GGC); |
| 60 | ggc &= ~0x3f8; |
| 61 | if (igd_enabled) { |
| 62 | ggc |= GGC_GTT_2MB | GGC_IGD_MEM_IN_32MB_UNITS(1); |
| 63 | ggc &= ~GGC_DISABLE_VGA_IO_DECODE; |
| 64 | } else { |
| 65 | ggc |= GGC_GTT_0MB | GGC_IGD_MEM_IN_32MB_UNITS(0) | |
| 66 | GGC_DISABLE_VGA_IO_DECODE; |
| 67 | } |
| 68 | pci_write_config16(PCI_DEV(0, 0, 0), GGC, ggc); |
| 69 | |
| 70 | if (!igd_enabled) { |
| 71 | printk(BIOS_DEBUG, "IGD is disabled.\n"); |
| 72 | return; |
| 73 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 74 | |
| 75 | /* Enable 256MB aperture */ |
| 76 | reg8 = pci_read_config8(PCI_DEV(0, 2, 0), MSAC); |
| 77 | reg8 &= ~0x06; |
| 78 | reg8 |= 0x02; |
| 79 | pci_write_config8(PCI_DEV(0, 2, 0), MSAC, reg8); |
Tristan Corrick | c5d367b | 2018-12-17 22:10:07 +1300 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void haswell_setup_misc(void) |
| 83 | { |
| 84 | u32 reg32; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 85 | |
| 86 | /* Erratum workarounds */ |
| 87 | reg32 = MCHBAR32(0x5f00); |
| 88 | reg32 |= (1 << 9)|(1 << 10); |
| 89 | MCHBAR32(0x5f00) = reg32; |
| 90 | |
| 91 | /* Enable SA Clock Gating */ |
| 92 | reg32 = MCHBAR32(0x5f00); |
| 93 | MCHBAR32(0x5f00) = reg32 | 1; |
| 94 | |
| 95 | /* GPU RC6 workaround for sighting 366252 */ |
| 96 | reg32 = MCHBAR32(0x5d14); |
Ryan Salsamendi | b9bc257 | 2017-07-04 13:35:06 -0700 | [diff] [blame] | 97 | reg32 |= (1UL << 31); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 98 | MCHBAR32(0x5d14) = reg32; |
| 99 | |
| 100 | /* VLW */ |
| 101 | reg32 = MCHBAR32(0x6120); |
| 102 | reg32 &= ~(1 << 0); |
| 103 | MCHBAR32(0x6120) = reg32; |
| 104 | |
| 105 | reg32 = MCHBAR32(0x5418); |
| 106 | reg32 |= (1 << 4) | (1 << 5); |
| 107 | MCHBAR32(0x5418) = reg32; |
| 108 | } |
| 109 | |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 110 | static void haswell_setup_iommu(void) |
| 111 | { |
| 112 | const u32 capid0_a = pci_read_config32(PCI_DEV(0, 0, 0), CAPID0_A); |
| 113 | |
| 114 | if (capid0_a & VTD_DISABLE) |
| 115 | return; |
| 116 | |
| 117 | /* setup BARs: zeroize top 32 bits; set enable bit */ |
| 118 | MCHBAR32(GFXVTBAR + 4) = GFXVT_BASE_ADDRESS >> 32; |
| 119 | MCHBAR32(GFXVTBAR) = GFXVT_BASE_ADDRESS | 1; |
| 120 | MCHBAR32(VTVC0BAR + 4) = VTVC0_BASE_ADDRESS >> 32; |
| 121 | MCHBAR32(VTVC0BAR) = VTVC0_BASE_ADDRESS | 1; |
| 122 | |
| 123 | /* set L3HIT2PEND_DIS, lock GFXVTBAR policy cfg registers */ |
| 124 | u32 reg32; |
| 125 | reg32 = read32((void *)(GFXVT_BASE_ADDRESS + ARCHDIS)); |
| 126 | write32((void *)(GFXVT_BASE_ADDRESS + ARCHDIS), |
| 127 | reg32 | DMAR_LCKDN | L3HIT2PEND_DIS); |
| 128 | /* clear SPCAPCTRL */ |
| 129 | reg32 = read32((void *)(VTVC0_BASE_ADDRESS + ARCHDIS)) & ~SPCAPCTRL; |
| 130 | /* set GLBIOTLBINV, GLBCTXTINV; lock VTVC0BAR policy cfg registers */ |
| 131 | write32((void *)(VTVC0_BASE_ADDRESS + ARCHDIS), |
| 132 | reg32 | DMAR_LCKDN | GLBIOTLBINV | GLBCTXTINV); |
| 133 | } |
| 134 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 135 | void haswell_early_initialization(int chipset_type) |
| 136 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 137 | /* Setup all BARs required for early PCIe and raminit */ |
| 138 | haswell_setup_bars(); |
| 139 | |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 140 | /* Setup IOMMU BARs */ |
| 141 | haswell_setup_iommu(); |
| 142 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 143 | haswell_setup_graphics(); |
Tristan Corrick | c5d367b | 2018-12-17 22:10:07 +1300 | [diff] [blame] | 144 | |
| 145 | haswell_setup_misc(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 146 | } |