Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007-2010 coresystems GmbH |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 16 | #include <stdint.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <console/console.h> |
Kyösti Mälkki | a969ed3 | 2016-06-15 06:08:15 +0300 | [diff] [blame^] | 19 | #include <arch/acpi.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 20 | #include <arch/io.h> |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 21 | #include <device/pci_def.h> |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 22 | #include <cbmem.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 23 | #include <halt.h> |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 24 | #include <string.h> |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 25 | #include "i945.h" |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 26 | |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 27 | int i945_silicon_revision(void) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 28 | { |
Stefan Reinauer | 779b3e3 | 2008-11-10 15:43:37 +0000 | [diff] [blame] | 29 | return pci_read_config8(PCI_DEV(0, 0x00, 0), PCI_CLASS_REVISION); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 32 | static void i945m_detect_chipset(void) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 33 | { |
| 34 | u8 reg8; |
| 35 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 36 | printk(BIOS_INFO, "\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 37 | reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) & 0x70) >> 4; |
| 38 | switch (reg8) { |
| 39 | case 1: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 40 | printk(BIOS_INFO, "Mobile Intel(R) 82945GM/GME Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 41 | break; |
| 42 | case 2: |
Stefan Reinauer | 7981b94 | 2011-04-01 22:33:25 +0200 | [diff] [blame] | 43 | printk(BIOS_INFO, "Mobile Intel(R) 82945GMS/GU/GSE Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 44 | break; |
| 45 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 46 | printk(BIOS_INFO, "Mobile Intel(R) 82945PM Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 47 | break; |
| 48 | case 5: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 49 | printk(BIOS_INFO, "Intel(R) 82945GT Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 50 | break; |
| 51 | case 6: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 52 | printk(BIOS_INFO, "Mobile Intel(R) 82943/82940GML Express"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 53 | break; |
| 54 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 55 | printk(BIOS_INFO, "Unknown (%02x)", reg8); /* Others reserved. */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 56 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 57 | printk(BIOS_INFO, " Chipset\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 58 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 59 | printk(BIOS_DEBUG, "(G)MCH capable of up to FSB "); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 60 | reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe3) & 0xe0) >> 5; |
| 61 | switch (reg8) { |
| 62 | case 2: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 63 | printk(BIOS_DEBUG, "800 MHz"); /* According to 965 spec */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 64 | break; |
| 65 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 66 | printk(BIOS_DEBUG, "667 MHz"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 67 | break; |
| 68 | case 4: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 69 | printk(BIOS_DEBUG, "533 MHz"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 70 | break; |
| 71 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 72 | printk(BIOS_DEBUG, "N/A MHz (%02x)", reg8); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 73 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 74 | printk(BIOS_DEBUG, "\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 75 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 76 | printk(BIOS_DEBUG, "(G)MCH capable of "); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 77 | reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07); |
| 78 | switch (reg8) { |
| 79 | case 2: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 80 | printk(BIOS_DEBUG, "up to DDR2-667"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 81 | break; |
| 82 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 83 | printk(BIOS_DEBUG, "up to DDR2-533"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 84 | break; |
| 85 | case 4: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 86 | printk(BIOS_DEBUG, "DDR2-400"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 87 | break; |
| 88 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 89 | printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 90 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 91 | printk(BIOS_DEBUG, "\n"); |
Kyösti Mälkki | eb5e28f | 2012-02-24 16:08:18 +0200 | [diff] [blame] | 92 | #if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GC |
Stefan Reinauer | 7981b94 | 2011-04-01 22:33:25 +0200 | [diff] [blame] | 93 | printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n"); |
| 94 | #endif |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 97 | static void i945_detect_chipset(void) |
| 98 | { |
| 99 | u8 reg8; |
| 100 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 101 | printk(BIOS_INFO, "\nIntel(R) "); |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 102 | |
| 103 | reg8 = ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe7) >> 5) & 4) | ((pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) >> 4) & 3); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 104 | switch (reg8) { |
| 105 | case 0: |
| 106 | case 1: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 107 | printk(BIOS_INFO, "82945G"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 108 | break; |
| 109 | case 2: |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 110 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 111 | printk(BIOS_INFO, "82945P"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 112 | break; |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 113 | case 4: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 114 | printk(BIOS_INFO, "82945GC"); |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 115 | break; |
| 116 | case 5: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 117 | printk(BIOS_INFO, "82945GZ"); |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 118 | break; |
| 119 | case 6: |
| 120 | case 7: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 121 | printk(BIOS_INFO, "82945PL"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 122 | break; |
| 123 | default: |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 124 | break; |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 125 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 126 | printk(BIOS_INFO, " Chipset\n"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 127 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 128 | printk(BIOS_DEBUG, "(G)MCH capable of "); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 129 | reg8 = (pci_read_config8(PCI_DEV(0, 0x00, 0), 0xe4) & 0x07); |
| 130 | switch (reg8) { |
| 131 | case 0: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 132 | printk(BIOS_DEBUG, "up to DDR2-667"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 133 | break; |
| 134 | case 3: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 135 | printk(BIOS_DEBUG, "up to DDR2-533"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 136 | break; |
| 137 | default: |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 138 | printk(BIOS_INFO, "unknown max. RAM clock (%02x).", reg8); /* Others reserved. */ |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 139 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 140 | printk(BIOS_DEBUG, "\n"); |
Kyösti Mälkki | eb5e28f | 2012-02-24 16:08:18 +0200 | [diff] [blame] | 141 | #if CONFIG_NORTHBRIDGE_INTEL_SUBTYPE_I945GM |
Stefan Reinauer | 7981b94 | 2011-04-01 22:33:25 +0200 | [diff] [blame] | 142 | printk(BIOS_ERR, "coreboot is compiled for the wrong chipset.\n"); |
| 143 | #endif |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 146 | static void i945_setup_bars(void) |
| 147 | { |
| 148 | u8 reg8; |
| 149 | |
| 150 | /* As of now, we don't have all the A0 workarounds implemented */ |
| 151 | if (i945_silicon_revision() == 0) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 152 | printk(BIOS_INFO, "Warning: i945 silicon revision A0 might not work correctly.\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 153 | |
| 154 | /* Setting up Southbridge. In the northbridge code. */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 155 | printk(BIOS_DEBUG, "Setting up static southbridge registers..."); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 156 | pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA, (uintptr_t)DEFAULT_RCBA | 1); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 157 | |
| 158 | pci_write_config32(PCI_DEV(0, 0x1f, 0), PMBASE, DEFAULT_PMBASE | 1); |
| 159 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x44 /* ACPI_CNTL */ , 0x80); /* Enable ACPI BAR */ |
| 160 | |
| 161 | pci_write_config32(PCI_DEV(0, 0x1f, 0), GPIOBASE, DEFAULT_GPIOBASE | 1); |
| 162 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0x4c /* GC */ , 0x10); /* Enable GPIOs */ |
| 163 | setup_ich7_gpios(); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 164 | printk(BIOS_DEBUG, " done.\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 165 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 166 | printk(BIOS_DEBUG, "Disabling Watchdog reboot..."); |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 167 | RCBA32(GCS) = RCBA32(GCS) | (1 << 5); /* No reset */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 168 | outw((1 << 11), DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 169 | printk(BIOS_DEBUG, " done.\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 170 | |
Vladimir Serbinenko | 4aad743 | 2014-11-22 20:36:58 +0100 | [diff] [blame] | 171 | /* Enable upper 128bytes of CMOS */ |
| 172 | RCBA32(0x3400) = (1 << 2); |
| 173 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 174 | printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 175 | /* Set up all hardcoded northbridge BARs */ |
| 176 | pci_write_config32(PCI_DEV(0, 0x00, 0), EPBAR, DEFAULT_EPBAR | 1); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 177 | pci_write_config32(PCI_DEV(0, 0x00, 0), MCHBAR, (uintptr_t)DEFAULT_MCHBAR | 1); |
| 178 | pci_write_config32(PCI_DEV(0, 0x00, 0), DMIBAR, (uintptr_t)DEFAULT_DMIBAR | 1); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 179 | pci_write_config32(PCI_DEV(0, 0x00, 0), X60BAR, DEFAULT_X60BAR | 1); |
| 180 | |
| 181 | /* Hardware default is 8MB UMA. If someone wants to make this a |
| 182 | * CMOS or compile time option, send a patch. |
| 183 | * pci_write_config16(PCI_DEV(0, 0x00, 0), GGC, 0x30); |
| 184 | */ |
| 185 | |
| 186 | /* Set C0000-FFFFF to access RAM on both reads and writes */ |
| 187 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM0, 0x30); |
| 188 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM1, 0x33); |
| 189 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM2, 0x33); |
| 190 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM3, 0x33); |
| 191 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM4, 0x33); |
| 192 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM5, 0x33); |
| 193 | pci_write_config8(PCI_DEV(0, 0x00, 0), PAM6, 0x33); |
| 194 | |
Sven Schnelle | d8c68a9 | 2011-06-15 09:26:34 +0200 | [diff] [blame] | 195 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, SKPAD_NORMAL_BOOT_MAGIC); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 196 | printk(BIOS_DEBUG, " done.\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 197 | |
| 198 | /* Wait for MCH BAR to come up */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 199 | printk(BIOS_DEBUG, "Waiting for MCHBAR to come up..."); |
Elyes HAOUAS | a3ea1e4 | 2014-11-27 13:23:32 +0100 | [diff] [blame] | 200 | if ((pci_read_config32(PCI_DEV(0, 0x00, 0), 0xe4) & 0x20000) == 0x00) { /* Bit 49 of CAPID0 */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 201 | do { |
| 202 | reg8 = *(volatile u8 *)0xfed40000; |
| 203 | } while (!(reg8 & 0x80)); |
| 204 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 205 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void i945_setup_egress_port(void) |
| 209 | { |
| 210 | u32 reg32; |
| 211 | u32 timeout; |
| 212 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 213 | printk(BIOS_DEBUG, "Setting up Egress Port RCRB\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 214 | |
| 215 | /* Egress Port Virtual Channel 0 Configuration */ |
| 216 | |
| 217 | /* map only TC0 to VC0 */ |
| 218 | reg32 = EPBAR32(EPVC0RCTL); |
| 219 | reg32 &= 0xffffff01; |
| 220 | EPBAR32(EPVC0RCTL) = reg32; |
| 221 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 222 | reg32 = EPBAR32(EPPVCCAP1); |
| 223 | reg32 &= ~(7 << 0); |
| 224 | reg32 |= 1; |
| 225 | EPBAR32(EPPVCCAP1) = reg32; |
| 226 | |
| 227 | /* Egress Port Virtual Channel 1 Configuration */ |
| 228 | reg32 = EPBAR32(0x2c); |
| 229 | reg32 &= 0xffffff00; |
| 230 | if ((MCHBAR32(CLKCFG) & 7) == 1) |
| 231 | reg32 |= 0x0d; /* 533MHz */ |
| 232 | if ((MCHBAR32(CLKCFG) & 7) == 3) |
| 233 | reg32 |= 0x10; /* 667MHz */ |
| 234 | EPBAR32(0x2c) = reg32; |
| 235 | |
| 236 | EPBAR32(EPVC1MTS) = 0x0a0a0a0a; |
| 237 | |
| 238 | reg32 = EPBAR32(EPVC1RCAP); |
| 239 | reg32 &= ~(0x7f << 16); |
| 240 | reg32 |= (0x0a << 16); |
| 241 | EPBAR32(EPVC1RCAP) = reg32; |
| 242 | |
| 243 | if ((MCHBAR32(CLKCFG) & 7) == 1) { /* 533MHz */ |
| 244 | EPBAR32(EPVC1IST + 0) = 0x009c009c; |
| 245 | EPBAR32(EPVC1IST + 4) = 0x009c009c; |
| 246 | } |
| 247 | |
| 248 | if ((MCHBAR32(CLKCFG) & 7) == 3) { /* 667MHz */ |
| 249 | EPBAR32(EPVC1IST + 0) = 0x00c000c0; |
| 250 | EPBAR32(EPVC1IST + 4) = 0x00c000c0; |
| 251 | } |
| 252 | |
| 253 | /* Is internal graphics enabled? */ |
Kyösti Mälkki | 3c3e34d | 2014-05-31 11:32:54 +0300 | [diff] [blame] | 254 | if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) { |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 255 | MCHBAR32(MMARB1) |= (1 << 17); |
| 256 | } |
| 257 | |
| 258 | /* Assign Virtual Channel ID 1 to VC1 */ |
| 259 | reg32 = EPBAR32(EPVC1RCTL); |
| 260 | reg32 &= ~(7 << 24); |
| 261 | reg32 |= (1 << 24); |
| 262 | EPBAR32(EPVC1RCTL) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 263 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 264 | reg32 = EPBAR32(EPVC1RCTL); |
| 265 | reg32 &= 0xffffff01; |
| 266 | reg32 |= (1 << 7); |
| 267 | EPBAR32(EPVC1RCTL) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 268 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 269 | EPBAR32(PORTARB + 0x00) = 0x01000001; |
| 270 | EPBAR32(PORTARB + 0x04) = 0x00040000; |
| 271 | EPBAR32(PORTARB + 0x08) = 0x00001000; |
| 272 | EPBAR32(PORTARB + 0x0c) = 0x00000040; |
| 273 | EPBAR32(PORTARB + 0x10) = 0x01000001; |
| 274 | EPBAR32(PORTARB + 0x14) = 0x00040000; |
| 275 | EPBAR32(PORTARB + 0x18) = 0x00001000; |
| 276 | EPBAR32(PORTARB + 0x1c) = 0x00000040; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 277 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 278 | EPBAR32(EPVC1RCTL) |= (1 << 16); |
| 279 | EPBAR32(EPVC1RCTL) |= (1 << 16); |
| 280 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 281 | printk(BIOS_DEBUG, "Loading port arbitration table ..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 282 | /* Loop until bit 0 becomes 0 */ |
| 283 | timeout = 0x7fffff; |
| 284 | while ((EPBAR16(EPVC1RSTS) & 1) && --timeout) ; |
| 285 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 286 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 287 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 288 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 289 | |
| 290 | /* Now enable VC1 */ |
| 291 | EPBAR32(EPVC1RCTL) |= (1 << 31); |
| 292 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 293 | printk(BIOS_DEBUG, "Wait for VC1 negotiation ..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 294 | /* Wait for VC1 negotiation pending */ |
| 295 | timeout = 0x7fff; |
| 296 | while ((EPBAR16(EPVC1RSTS) & (1 << 1)) && --timeout) ; |
| 297 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 298 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 299 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 300 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 301 | |
| 302 | } |
| 303 | |
| 304 | static void ich7_setup_dmi_rcrb(void) |
| 305 | { |
| 306 | u16 reg16; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 307 | u32 reg32; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 308 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 309 | reg16 = RCBA16(LCTL); |
| 310 | reg16 &= ~(3 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 311 | reg16 |= 3; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 312 | RCBA16(LCTL) = reg16; |
| 313 | |
| 314 | RCBA32(V0CTL) = 0x80000001; |
| 315 | RCBA32(V1CAP) = 0x03128010; |
| 316 | RCBA32(ESD) = 0x00000810; |
| 317 | RCBA32(RP1D) = 0x01000003; |
| 318 | RCBA32(RP2D) = 0x02000002; |
| 319 | RCBA32(RP3D) = 0x03000002; |
| 320 | RCBA32(RP4D) = 0x04000002; |
| 321 | RCBA32(HDD) = 0x0f000003; |
| 322 | RCBA32(RP5D) = 0x05000002; |
| 323 | |
| 324 | RCBA32(RPFN) = 0x00543210; |
| 325 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 326 | pci_write_config16(PCI_DEV(0, 0x1c, 0), 0x42, 0x0141); |
| 327 | pci_write_config16(PCI_DEV(0, 0x1c, 4), 0x42, 0x0141); |
| 328 | pci_write_config16(PCI_DEV(0, 0x1c, 5), 0x42, 0x0141); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 329 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 330 | pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0); |
| 331 | pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0); |
| 332 | |
| 333 | reg32 = RCBA32(V1CTL); |
| 334 | reg32 &= ~( (0x7f << 1) | (7 << 17) | (7 << 24) ); |
| 335 | reg32 |= (0x40 << 1) | (4 << 17) | (1 << 24) | (1 << 31); |
| 336 | RCBA32(V1CTL) = reg32; |
| 337 | |
| 338 | RCBA32(ESD) |= (2 << 16); |
| 339 | |
| 340 | RCBA32(ULD) |= (1 << 24) | (1 << 16); |
| 341 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 342 | RCBA32(ULBA) = (uintptr_t)DEFAULT_DMIBAR; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 343 | |
| 344 | RCBA32(RP1D) |= (2 << 16); |
| 345 | RCBA32(RP2D) |= (2 << 16); |
| 346 | RCBA32(RP3D) |= (2 << 16); |
| 347 | RCBA32(RP4D) |= (2 << 16); |
| 348 | RCBA32(HDD) |= (2 << 16); |
| 349 | RCBA32(RP5D) |= (2 << 16); |
| 350 | RCBA32(RP6D) |= (2 << 16); |
| 351 | |
| 352 | RCBA32(LCAP) |= (3 << 10); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static void i945_setup_dmi_rcrb(void) |
| 356 | { |
| 357 | u32 reg32; |
| 358 | u32 timeout; |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 359 | int activate_aspm = 1; /* hardcode ASPM for now */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 360 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 361 | printk(BIOS_DEBUG, "Setting up DMI RCRB\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 362 | |
| 363 | /* Virtual Channel 0 Configuration */ |
| 364 | reg32 = DMIBAR32(DMIVC0RCTL0); |
| 365 | reg32 &= 0xffffff01; |
| 366 | DMIBAR32(DMIVC0RCTL0) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 367 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 368 | reg32 = DMIBAR32(DMIPVCCAP1); |
| 369 | reg32 &= ~(7 << 0); |
| 370 | reg32 |= 1; |
| 371 | DMIBAR32(DMIPVCCAP1) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 372 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 373 | reg32 = DMIBAR32(DMIVC1RCTL); |
| 374 | reg32 &= ~(7 << 24); |
| 375 | reg32 |= (1 << 24); /* NOTE: This ID must match ICH7 side */ |
| 376 | DMIBAR32(DMIVC1RCTL) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 377 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 378 | reg32 = DMIBAR32(DMIVC1RCTL); |
| 379 | reg32 &= 0xffffff01; |
| 380 | reg32 |= (1 << 7); |
| 381 | DMIBAR32(DMIVC1RCTL) = reg32; |
| 382 | |
| 383 | /* Now enable VC1 */ |
| 384 | DMIBAR32(DMIVC1RCTL) |= (1 << 31); |
| 385 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 386 | printk(BIOS_DEBUG, "Wait for VC1 negotiation ..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 387 | /* Wait for VC1 negotiation pending */ |
| 388 | timeout = 0x7ffff; |
| 389 | while ((DMIBAR16(DMIVC1RSTS) & (1 << 1)) && --timeout) ; |
| 390 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 391 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 392 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 393 | printk(BIOS_DEBUG, "done..\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 394 | #if 1 |
| 395 | /* Enable Active State Power Management (ASPM) L0 state */ |
| 396 | |
| 397 | reg32 = DMIBAR32(DMILCAP); |
| 398 | reg32 &= ~(7 << 12); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 399 | reg32 |= (2 << 12); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 400 | |
| 401 | reg32 &= ~(7 << 15); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 402 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 403 | reg32 |= (2 << 15); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 404 | DMIBAR32(DMILCAP) = reg32; |
| 405 | |
| 406 | reg32 = DMIBAR32(DMICC); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 407 | reg32 &= 0x00ffffff; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 408 | reg32 &= ~(3 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 409 | reg32 |= (1 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 410 | reg32 &= ~(3 << 20); |
| 411 | reg32 |= (1 << 20); |
| 412 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 413 | DMIBAR32(DMICC) = reg32; |
| 414 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 415 | if (activate_aspm) { |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 416 | DMIBAR32(DMILCTL) |= (3 << 0); |
| 417 | } |
| 418 | #endif |
| 419 | |
| 420 | /* Last but not least, some additional steps */ |
| 421 | reg32 = MCHBAR32(FSBSNPCTL); |
| 422 | reg32 &= ~(0xff << 2); |
| 423 | reg32 |= (0xaa << 2); |
| 424 | MCHBAR32(FSBSNPCTL) = reg32; |
| 425 | |
| 426 | DMIBAR32(0x2c) = 0x86000040; |
| 427 | |
| 428 | reg32 = DMIBAR32(0x204); |
| 429 | reg32 &= ~0x3ff; |
| 430 | #if 1 |
| 431 | reg32 |= 0x13f; /* for x4 DMI only */ |
| 432 | #else |
| 433 | reg32 |= 0x1e4; /* for x2 DMI only */ |
| 434 | #endif |
| 435 | DMIBAR32(0x204) = reg32; |
| 436 | |
Kyösti Mälkki | 3c3e34d | 2014-05-31 11:32:54 +0300 | [diff] [blame] | 437 | if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 438 | printk(BIOS_DEBUG, "Internal graphics: enabled\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 439 | DMIBAR32(0x200) |= (1 << 21); |
| 440 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 441 | printk(BIOS_DEBUG, "Internal graphics: disabled\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 442 | DMIBAR32(0x200) &= ~(1 << 21); |
| 443 | } |
| 444 | |
| 445 | reg32 = DMIBAR32(0x204); |
| 446 | reg32 &= ~((1 << 11) | (1 << 10)); |
| 447 | DMIBAR32(0x204) = reg32; |
| 448 | |
| 449 | reg32 = DMIBAR32(0x204); |
| 450 | reg32 &= ~(0xff << 12); |
| 451 | reg32 |= (0x0d << 12); |
| 452 | DMIBAR32(0x204) = reg32; |
| 453 | |
| 454 | DMIBAR32(DMICTL1) |= (3 << 24); |
| 455 | |
| 456 | reg32 = DMIBAR32(0x200); |
| 457 | reg32 &= ~(0x3 << 26); |
| 458 | reg32 |= (0x02 << 26); |
| 459 | DMIBAR32(0x200) = reg32; |
| 460 | |
| 461 | DMIBAR32(DMIDRCCFG) &= ~(1 << 31); |
| 462 | DMIBAR32(DMICTL2) |= (1 << 31); |
| 463 | |
| 464 | if (i945_silicon_revision() >= 3) { |
| 465 | reg32 = DMIBAR32(0xec0); |
| 466 | reg32 &= 0x0fffffff; |
| 467 | reg32 |= (2 << 28); |
| 468 | DMIBAR32(0xec0) = reg32; |
| 469 | |
| 470 | reg32 = DMIBAR32(0xed4); |
| 471 | reg32 &= 0x0fffffff; |
| 472 | reg32 |= (2 << 28); |
| 473 | DMIBAR32(0xed4) = reg32; |
| 474 | |
| 475 | reg32 = DMIBAR32(0xee8); |
| 476 | reg32 &= 0x0fffffff; |
| 477 | reg32 |= (2 << 28); |
| 478 | DMIBAR32(0xee8) = reg32; |
| 479 | |
| 480 | reg32 = DMIBAR32(0xefc); |
| 481 | reg32 &= 0x0fffffff; |
| 482 | reg32 |= (2 << 28); |
| 483 | DMIBAR32(0xefc) = reg32; |
| 484 | } |
| 485 | |
| 486 | /* wait for bit toggle to 0 */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 487 | printk(BIOS_DEBUG, "Waiting for DMI hardware..."); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 488 | timeout = 0x7fffff; |
| 489 | while ((DMIBAR8(0x32) & (1 << 1)) && --timeout) ; |
| 490 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 491 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 492 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 493 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 494 | |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 495 | /* Clear Error Status Bits! */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 496 | DMIBAR32(0x1c4) = 0xffffffff; |
| 497 | DMIBAR32(0x1d0) = 0xffffffff; |
| 498 | DMIBAR32(0x228) = 0xffffffff; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 499 | |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 500 | /* Program Read-Only Write-Once Registers */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 501 | DMIBAR32(0x308) = DMIBAR32(0x308); |
| 502 | DMIBAR32(0x314) = DMIBAR32(0x314); |
| 503 | DMIBAR32(0x324) = DMIBAR32(0x324); |
| 504 | DMIBAR32(0x328) = DMIBAR32(0x328); |
| 505 | DMIBAR32(0x338) = DMIBAR32(0x334); |
| 506 | DMIBAR32(0x338) = DMIBAR32(0x338); |
| 507 | |
Patrick Georgi | a341a77 | 2014-09-29 19:51:21 +0200 | [diff] [blame] | 508 | if (i945_silicon_revision() == 1 && (MCHBAR8(DFT_STRAP1) & (1 << 5))) { |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 509 | if ((MCHBAR32(0x214) & 0xf) != 0x3) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 510 | printk(BIOS_INFO, "DMI link requires A1 stepping workaround. Rebooting.\n"); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 511 | reg32 = DMIBAR32(0x224); |
| 512 | reg32 &= ~(7 << 0); |
| 513 | reg32 |= (3 << 0); |
| 514 | DMIBAR32(0x224) = reg32; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 515 | outb(0x06, 0xcf9); |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 516 | halt(); /* wait for reset */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | static void i945_setup_pci_express_x16(void) |
| 522 | { |
| 523 | u32 timeout; |
| 524 | u32 reg32; |
| 525 | u16 reg16; |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 526 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 527 | u8 reg8; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 528 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 529 | printk(BIOS_DEBUG, "Enabling PCI Express x16 Link\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 530 | |
| 531 | reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN); |
| 532 | reg16 |= DEVEN_D1F0; |
| 533 | pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16); |
| 534 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 535 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x208); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 536 | reg32 &= ~(1 << 8); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 537 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x208, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 538 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 539 | /* We have no success with querying the usual PCIe registers |
| 540 | * for link setup success on the i945. Hence we assign a temporary |
| 541 | * PCI bus 0x0a and check whether we find a device on 0:a.0 |
| 542 | */ |
| 543 | |
| 544 | /* First we reset the secondary bus */ |
| 545 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e); |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 546 | reg16 |= (1 << 6); /* SRESET */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 547 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16); |
| 548 | /* Read back and clear reset bit. */ |
| 549 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e); |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 550 | reg16 &= ~(1 << 6); /* SRESET */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 551 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16); |
| 552 | |
| 553 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xba); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 554 | printk(BIOS_DEBUG, "SLOTSTS: %04x\n", reg16); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 555 | if (!(reg16 & 0x48)) { |
| 556 | goto disable_pciexpress_x16_link; |
| 557 | } |
| 558 | reg16 |= (1 << 4) | (1 << 0); |
| 559 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0xba, reg16); |
| 560 | |
| 561 | pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x00); |
| 562 | pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x00); |
| 563 | pci_write_config8(PCI_DEV(0, 0x01, 0), 0x19, 0x0a); |
| 564 | pci_write_config8(PCI_DEV(0, 0x01, 0), 0x1a, 0x0a); |
| 565 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 566 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 567 | reg32 &= ~(1 << 8); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 568 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 569 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 570 | MCHBAR16(UPMC1) &= ~( (1 << 5) | (1 << 0) ); |
| 571 | |
| 572 | /* Initialze PEG_CAP */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 573 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xa2); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 574 | reg16 |= (1 << 8); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 575 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0xa2, reg16); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 576 | |
| 577 | /* Setup SLOTCAP */ |
| 578 | /* TODO: These values are mainboard dependent and should |
Uwe Hermann | 607614d | 2010-11-18 20:12:13 +0000 | [diff] [blame] | 579 | * be set from devicetree.cb. |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 580 | */ |
| 581 | /* NOTE: SLOTCAP becomes RO after the first write! */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 582 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xb4); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 583 | reg32 &= 0x0007ffff; |
| 584 | |
| 585 | reg32 &= 0xfffe007f; |
| 586 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 587 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xb4, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 588 | |
| 589 | /* Wait for training to succeed */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 590 | printk(BIOS_DEBUG, "PCIe link training ..."); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 591 | timeout = 0x7ffff; |
Patrick Georgi | d3060ed | 2014-08-10 15:19:45 +0200 | [diff] [blame] | 592 | while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS) >> 16) & 3) != 3) && --timeout) ; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 593 | |
| 594 | reg32 = pci_read_config32(PCI_DEV(0x0a, 0x0, 0), 0); |
| 595 | if (reg32 != 0x00000000 && reg32 != 0xffffffff) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 596 | printk(BIOS_DEBUG, " Detected PCIe device %04x:%04x\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 597 | reg32 & 0xffff, reg32 >> 16); |
| 598 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 599 | printk(BIOS_DEBUG, " timeout!\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 600 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 601 | printk(BIOS_DEBUG, "Restrain PCIe port to x1\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 602 | |
Patrick Georgi | d3060ed | 2014-08-10 15:19:45 +0200 | [diff] [blame] | 603 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 604 | reg32 &= ~(0xf << 1); |
| 605 | reg32 |=1; |
Patrick Georgi | d3060ed | 2014-08-10 15:19:45 +0200 | [diff] [blame] | 606 | pci_write_config32(PCI_DEV(0, 0x01, 0), PEGSTS, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 607 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 608 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0x3e); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 609 | |
| 610 | reg16 |= (1 << 6); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 611 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 612 | reg16 &= ~(1 << 6); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 613 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0x3e, reg16); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 614 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 615 | printk(BIOS_DEBUG, "PCIe link training ..."); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 616 | timeout = 0x7ffff; |
Patrick Georgi | d3060ed | 2014-08-10 15:19:45 +0200 | [diff] [blame] | 617 | while ((((pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS) >> 16) & 3) != 3) && --timeout) ; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 618 | |
| 619 | reg32 = pci_read_config32(PCI_DEV(0xa, 0x00, 0), 0); |
| 620 | if (reg32 != 0x00000000 && reg32 != 0xffffffff) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 621 | printk(BIOS_DEBUG, " Detected PCIe x1 device %04x:%04x\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 622 | reg32 & 0xffff, reg32 >> 16); |
| 623 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 624 | printk(BIOS_DEBUG, " timeout!\n"); |
| 625 | printk(BIOS_DEBUG, "Disabling PCIe x16 port completely.\n"); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 626 | goto disable_pciexpress_x16_link; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 627 | } |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 630 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), 0xb2); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 631 | reg16 >>= 4; |
| 632 | reg16 &= 0x3f; |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 633 | /* reg16 == 1 -> x1; reg16 == 16 -> x16 */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 634 | printk(BIOS_DEBUG, "PCIe x%d link training succeeded.\n", reg16); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 635 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 636 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x204); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 637 | reg32 &= 0xfffffc00; /* clear [9:0] */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 638 | if (reg16 == 1) { |
| 639 | reg32 |= 0x32b; |
| 640 | // TODO |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 641 | /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 642 | } else if (reg16 == 16) { |
| 643 | reg32 |= 0x0f4; |
| 644 | // TODO |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 645 | /* pci_write_config32(PCI_DEV(0, 0x01, 0), 0x204, reg32); */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 648 | reg32 = (pci_read_config32(PCI_DEV(0xa, 0, 0), 0x8) >> 8); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 649 | printk(BIOS_DEBUG, "PCIe device class: %06x\n", reg32); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 650 | if (reg32 == 0x030000) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 651 | printk(BIOS_DEBUG, "PCIe device is VGA. Disabling IGD.\n"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 652 | reg16 = (1 << 1); |
| 653 | pci_write_config16(PCI_DEV(0, 0x0, 0), 0x52, reg16); |
| 654 | |
Kyösti Mälkki | 3c3e34d | 2014-05-31 11:32:54 +0300 | [diff] [blame] | 655 | reg32 = pci_read_config32(PCI_DEV(0, 0x0, 0), DEVEN); |
| 656 | reg32 &= ~(DEVEN_D2F0 | DEVEN_D2F1); |
| 657 | pci_write_config32(PCI_DEV(0, 0x0, 0), DEVEN, reg32); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 658 | |
| 659 | /* Set VGA enable bit in PCIe bridge */ |
| 660 | reg16 = pci_read_config16(PCI_DEV(0, 0x1, 0), 0x3e); |
| 661 | reg16 |= (1 << 3); |
| 662 | pci_write_config16(PCI_DEV(0, 0x1, 0), 0x3e, reg16); |
| 663 | } |
| 664 | |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 665 | /* Enable GPEs */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 666 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xec); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 667 | reg32 |= (1 << 2) | (1 << 1) | (1 << 0); /* PMEGPE, HPGPE, GENGPE */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 668 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 669 | |
| 670 | /* Virtual Channel Configuration: Only VC0 on PCIe x16 */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 671 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x114); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 672 | reg32 &= 0xffffff01; |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 673 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x114, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 674 | |
| 675 | /* Extended VC count */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 676 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x104); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 677 | reg32 &= ~(7 << 0); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 678 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x104, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 679 | |
| 680 | /* Active State Power Management ASPM */ |
| 681 | |
| 682 | /* TODO */ |
| 683 | |
| 684 | /* Clear error bits */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 685 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0x06, 0xffff); |
| 686 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0x1e, 0xffff); |
| 687 | pci_write_config16(PCI_DEV(0, 0x01, 0), 0xaa, 0xffff); |
| 688 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1c4, 0xffffffff); |
| 689 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1d0, 0xffffffff); |
| 690 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x1f0, 0xffffffff); |
| 691 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x228, 0xffffffff); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 692 | |
| 693 | /* Program R/WO registers */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 694 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x308); |
| 695 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x308, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 696 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 697 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x314); |
| 698 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x314, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 699 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 700 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x324); |
| 701 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x324, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 702 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 703 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x328); |
| 704 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x328, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 705 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 706 | reg8 = pci_read_config8(PCI_DEV(0, 0x01, 0), 0xb4); |
| 707 | pci_write_config8(PCI_DEV(0, 0x01, 0), 0xb4, reg8); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 708 | |
| 709 | /* Additional PCIe graphics setup */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 710 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 711 | reg32 |= (3 << 26); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 712 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 713 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 714 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 715 | reg32 |= (3 << 24); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 716 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 717 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 718 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xf0); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 719 | reg32 |= (1 << 5); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 720 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xf0, reg32); |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 721 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 722 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x200); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 723 | reg32 &= ~(3 << 26); |
| 724 | reg32 |= (2 << 26); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 725 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x200, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 726 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 727 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 728 | if (i945_silicon_revision() >= 2) { |
| 729 | reg32 |= (1 << 12); |
| 730 | } else { |
| 731 | reg32 &= ~(1 << 12); |
| 732 | } |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 733 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 734 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 735 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xeb4); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 736 | reg32 &= ~(1 << 31); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 737 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xeb4, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 738 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 739 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xfc); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 740 | reg32 |= (1 << 31); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 741 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xfc, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 742 | |
| 743 | if (i945_silicon_revision() >= 3) { |
| 744 | static const u32 reglist[] = { |
| 745 | 0xec0, 0xed4, 0xee8, 0xefc, 0xf10, 0xf24, |
| 746 | 0xf38, 0xf4c, 0xf60, 0xf74, 0xf88, 0xf9c, |
| 747 | 0xfb0, 0xfc4, 0xfd8, 0xfec |
| 748 | }; |
| 749 | |
| 750 | int i; |
| 751 | for (i=0; i<ARRAY_SIZE(reglist); i++) { |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 752 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), reglist[i]); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 753 | reg32 &= 0x0fffffff; |
| 754 | reg32 |= (2 << 28); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 755 | pci_write_config32(PCI_DEV(0, 0x01, 0), reglist[i], reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | if (i945_silicon_revision() <= 2 ) { |
| 760 | /* Set voltage specific parameters */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 761 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0xe80); |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 762 | reg32 &= (0xf << 4); /* Default case 1.05V */ |
Patrick Georgi | 3cb86de | 2014-09-29 20:42:33 +0200 | [diff] [blame] | 763 | if ((MCHBAR32(DFT_STRAP1) & (1 << 20)) == 0) { /* 1.50V */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 764 | reg32 |= (7 << 4); |
| 765 | } |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 766 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0xe80, reg32); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | return; |
| 770 | |
| 771 | disable_pciexpress_x16_link: |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 772 | /* For now we just disable the x16 link */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 773 | printk(BIOS_DEBUG, "Disabling PCI Express x16 Link\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 774 | |
| 775 | MCHBAR16(UPMC1) |= (1 << 5) | (1 << 0); |
| 776 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 777 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1); |
Stefan Reinauer | 779b3e3 | 2008-11-10 15:43:37 +0000 | [diff] [blame] | 778 | reg16 |= (1 << 6); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 779 | pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 780 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 781 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x224); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 782 | reg32 |= (1 << 8); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 783 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x224, reg32); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 784 | |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 785 | reg16 = pci_read_config16(PCI_DEV(0, 0x01, 0), BCTRL1); |
Stefan Reinauer | 779b3e3 | 2008-11-10 15:43:37 +0000 | [diff] [blame] | 786 | reg16 &= ~(1 << 6); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 787 | pci_write_config16(PCI_DEV(0, 0x01, 0), BCTRL1, reg16); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 788 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 789 | printk(BIOS_DEBUG, "Wait for link to enter detect state... "); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 790 | timeout = 0x7fffff; |
Patrick Georgi | d3060ed | 2014-08-10 15:19:45 +0200 | [diff] [blame] | 791 | for (reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), PEGSTS); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 792 | (reg32 & 0x000f0000) && --timeout;) ; |
| 793 | if (!timeout) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 794 | printk(BIOS_DEBUG, "timeout!\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 795 | else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 796 | printk(BIOS_DEBUG, "ok\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 797 | |
| 798 | /* Finally: Disable the PCI config header */ |
| 799 | reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), DEVEN); |
| 800 | reg16 &= ~DEVEN_D1F0; |
| 801 | pci_write_config16(PCI_DEV(0, 0x00, 0), DEVEN, reg16); |
| 802 | } |
| 803 | |
| 804 | static void i945_setup_root_complex_topology(void) |
| 805 | { |
| 806 | u32 reg32; |
| 807 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 808 | printk(BIOS_DEBUG, "Setting up Root Complex Topology\n"); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 809 | /* Egress Port Root Topology */ |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 810 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 811 | reg32 = EPBAR32(EPESD); |
| 812 | reg32 &= 0xff00ffff; |
| 813 | reg32 |= (1 << 16); |
| 814 | EPBAR32(EPESD) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 815 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 816 | EPBAR32(EPLE1D) |= (1 << 16) | (1 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 817 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 818 | EPBAR32(EPLE1A) = (uintptr_t)DEFAULT_DMIBAR; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 819 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 820 | EPBAR32(EPLE2D) |= (1 << 16) | (1 << 0); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 821 | |
| 822 | /* DMI Port Root Topology */ |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 823 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 824 | reg32 = DMIBAR32(DMILE1D); |
| 825 | reg32 &= 0x00ffffff; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 826 | |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 827 | reg32 &= 0xff00ffff; |
| 828 | reg32 |= (2 << 16); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 829 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 830 | reg32 |= (1 << 0); |
| 831 | DMIBAR32(DMILE1D) = reg32; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 832 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 833 | DMIBAR32(DMILE1A) = (uintptr_t)DEFAULT_RCBA; |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 834 | |
Stefan Reinauer | 24b4df5 | 2010-01-17 13:47:35 +0000 | [diff] [blame] | 835 | DMIBAR32(DMILE2D) |= (1 << 16) | (1 << 0); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 836 | |
| 837 | DMIBAR32(DMILE2A) = DEFAULT_EPBAR; |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 838 | |
| 839 | /* PCI Express x16 Port Root Topology */ |
| 840 | if (pci_read_config8(PCI_DEV(0, 0x00, 0), DEVEN) & DEVEN_D1F0) { |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 841 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x158, DEFAULT_EPBAR); |
| 842 | reg32 = pci_read_config32(PCI_DEV(0, 0x01, 0), 0x150); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 843 | reg32 |= (1 << 0); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 844 | pci_write_config32(PCI_DEV(0, 0x01, 0), 0x150, reg32); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 845 | } |
| 846 | } |
| 847 | |
| 848 | static void ich7_setup_root_complex_topology(void) |
| 849 | { |
| 850 | RCBA32(0x104) = 0x00000802; |
| 851 | RCBA32(0x110) = 0x00000001; |
| 852 | RCBA32(0x114) = 0x00000000; |
| 853 | RCBA32(0x118) = 0x00000000; |
| 854 | } |
| 855 | |
| 856 | static void ich7_setup_pci_express(void) |
| 857 | { |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 858 | RCBA32(CG) |= (1 << 0); |
| 859 | |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 860 | /* Initialize slot power limit for root ports */ |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 861 | pci_write_config32(PCI_DEV(0, 0x1c, 0), 0x54, 0x00000060); |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 862 | #if 0 |
| 863 | pci_write_config32(PCI_DEV(0, 0x1c, 4), 0x54, 0x00480ce0); |
| 864 | pci_write_config32(PCI_DEV(0, 0x1c, 5), 0x54, 0x00500ce0); |
| 865 | #endif |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 866 | |
| 867 | pci_write_config32(PCI_DEV(0, 0x1c, 0), 0xd8, 0x00110000); |
| 868 | } |
| 869 | |
Patrick Georgi | d083595 | 2010-10-05 09:07:10 +0000 | [diff] [blame] | 870 | void i945_early_initialization(void) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 871 | { |
| 872 | /* Print some chipset specific information */ |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 873 | switch (pci_read_config32(PCI_DEV(0, 0x00, 0), 0)) { |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 874 | case 0x27708086: /* 82945G/GZ/GC/P/PL */ |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 875 | i945_detect_chipset(); |
| 876 | break; |
Stefan Reinauer | bf264e9 | 2010-05-14 19:09:20 +0000 | [diff] [blame] | 877 | case 0x27a08086: /* 945GME/GSE */ |
| 878 | case 0x27ac8086: /* 945GM/PM/GMS/GU/GT, 943/940GML */ |
Stefan Reinauer | 71a3d96 | 2009-07-21 21:44:24 +0000 | [diff] [blame] | 879 | i945m_detect_chipset(); |
| 880 | break; |
| 881 | } |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 882 | |
| 883 | /* Setup all BARs required for early PCIe and raminit */ |
| 884 | i945_setup_bars(); |
| 885 | |
| 886 | /* Change port80 to LPC */ |
| 887 | RCBA32(GCS) &= (~0x04); |
Stefan Reinauer | 30140a5 | 2009-03-11 16:20:39 +0000 | [diff] [blame] | 888 | |
| 889 | /* Just do it that way */ |
| 890 | RCBA32(0x2010) |= (1 << 10); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 893 | static void i945_prepare_resume(int s3resume) |
| 894 | { |
| 895 | int cbmem_was_initted; |
| 896 | |
| 897 | cbmem_was_initted = !cbmem_recovery(s3resume); |
| 898 | |
| 899 | /* If there is no high memory area, we didn't boot before, so |
| 900 | * this is not a resume. In that case we just create the cbmem toc. |
| 901 | */ |
| 902 | if (s3resume && cbmem_was_initted) { |
| 903 | void *resume_backup_memory = cbmem_find(CBMEM_ID_RESUME); |
| 904 | |
| 905 | /* copy 1MB - 64K to high tables ram_base to prevent memory corruption |
| 906 | * through stage 2. We could keep stuff like stack and heap in high tables |
| 907 | * memory completely, but that's a wonderful clean up task for another |
| 908 | * day. |
| 909 | */ |
| 910 | if (resume_backup_memory) |
| 911 | memcpy(resume_backup_memory, (void *)CONFIG_RAMBASE, |
| 912 | HIGH_MEMORY_SAVE); |
| 913 | |
| 914 | /* Magic for S3 resume */ |
| 915 | pci_write_config32(PCI_DEV(0, 0x00, 0), SKPAD, |
| 916 | SKPAD_ACPI_S3_MAGIC); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | void i945_late_initialization(int s3resume) |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 921 | { |
| 922 | i945_setup_egress_port(); |
| 923 | |
| 924 | ich7_setup_root_complex_topology(); |
| 925 | |
| 926 | ich7_setup_pci_express(); |
| 927 | |
| 928 | ich7_setup_dmi_rcrb(); |
| 929 | |
| 930 | i945_setup_dmi_rcrb(); |
| 931 | |
| 932 | i945_setup_pci_express_x16(); |
| 933 | |
| 934 | i945_setup_root_complex_topology(); |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 935 | |
| 936 | #if !CONFIG_HAVE_ACPI_RESUME |
| 937 | #if CONFIG_DEFAULT_CONSOLE_LOGLEVEL > 8 |
| 938 | #if CONFIG_DEBUG_RAM_SETUP |
| 939 | sdram_dump_mchbar_registers(); |
| 940 | |
| 941 | { |
| 942 | /* This will not work if TSEG is in place! */ |
Paul Menzel | 9d3e131 | 2014-06-05 08:50:17 +0200 | [diff] [blame] | 943 | u32 tom = pci_read_config32(PCI_DEV(0, 2, 0), BSM); |
Vladimir Serbinenko | 5560188 | 2014-10-15 20:17:51 +0200 | [diff] [blame] | 944 | |
| 945 | printk(BIOS_DEBUG, "TOM: 0x%08x\n", tom); |
| 946 | ram_check(0x00000000, 0x000a0000); |
| 947 | ram_check(0x00100000, tom); |
| 948 | } |
| 949 | #endif |
| 950 | #endif |
| 951 | #endif |
| 952 | |
| 953 | MCHBAR16(SSKPD) = 0xCAFE; |
| 954 | |
| 955 | i945_prepare_resume(s3resume); |
Stefan Reinauer | 278534d | 2008-10-29 04:51:07 +0000 | [diff] [blame] | 956 | } |