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