Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Chromium OS Authors |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <arch/io.h> |
| 21 | #include <console/console.h> |
Kyösti Mälkki | ab56b3b | 2013-11-28 16:44:51 +0200 | [diff] [blame] | 22 | #include <bootmode.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 23 | #include <delay.h> |
Vladimir Serbinenko | f2e206a | 2014-02-23 00:13:56 +0100 | [diff] [blame] | 24 | #include <string.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 25 | #include <device/device.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <device/pci_ids.h> |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 28 | #include <device/pci_ops.h> |
| 29 | #include <cpu/x86/msr.h> |
| 30 | #include <cpu/x86/mtrr.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 31 | |
| 32 | #include "chip.h" |
| 33 | #include "sandybridge.h" |
| 34 | |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 35 | struct gt_powermeter { |
| 36 | u16 reg; |
| 37 | u32 value; |
| 38 | }; |
| 39 | |
Stefan Reinauer | 4c8027a | 2012-09-07 10:53:56 -0700 | [diff] [blame] | 40 | static const struct gt_powermeter snb_pm_gt1[] = { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 41 | { 0xa200, 0xcc000000 }, |
| 42 | { 0xa204, 0x07000040 }, |
| 43 | { 0xa208, 0x0000fe00 }, |
| 44 | { 0xa20c, 0x00000000 }, |
| 45 | { 0xa210, 0x17000000 }, |
| 46 | { 0xa214, 0x00000021 }, |
| 47 | { 0xa218, 0x0817fe19 }, |
| 48 | { 0xa21c, 0x00000000 }, |
| 49 | { 0xa220, 0x00000000 }, |
| 50 | { 0xa224, 0xcc000000 }, |
| 51 | { 0xa228, 0x07000040 }, |
| 52 | { 0xa22c, 0x0000fe00 }, |
| 53 | { 0xa230, 0x00000000 }, |
| 54 | { 0xa234, 0x17000000 }, |
| 55 | { 0xa238, 0x00000021 }, |
| 56 | { 0xa23c, 0x0817fe19 }, |
| 57 | { 0xa240, 0x00000000 }, |
| 58 | { 0xa244, 0x00000000 }, |
| 59 | { 0xa248, 0x8000421e }, |
| 60 | { 0 } |
| 61 | }; |
| 62 | |
Stefan Reinauer | 4c8027a | 2012-09-07 10:53:56 -0700 | [diff] [blame] | 63 | static const struct gt_powermeter snb_pm_gt2[] = { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 64 | { 0xa200, 0x330000a6 }, |
| 65 | { 0xa204, 0x402d0031 }, |
| 66 | { 0xa208, 0x00165f83 }, |
| 67 | { 0xa20c, 0xf1000000 }, |
| 68 | { 0xa210, 0x00000000 }, |
| 69 | { 0xa214, 0x00160016 }, |
| 70 | { 0xa218, 0x002a002b }, |
| 71 | { 0xa21c, 0x00000000 }, |
| 72 | { 0xa220, 0x00000000 }, |
| 73 | { 0xa224, 0x330000a6 }, |
| 74 | { 0xa228, 0x402d0031 }, |
| 75 | { 0xa22c, 0x00165f83 }, |
| 76 | { 0xa230, 0xf1000000 }, |
| 77 | { 0xa234, 0x00000000 }, |
| 78 | { 0xa238, 0x00160016 }, |
| 79 | { 0xa23c, 0x002a002b }, |
| 80 | { 0xa240, 0x00000000 }, |
| 81 | { 0xa244, 0x00000000 }, |
| 82 | { 0xa248, 0x8000421e }, |
| 83 | { 0 } |
| 84 | }; |
| 85 | |
Stefan Reinauer | 4c8027a | 2012-09-07 10:53:56 -0700 | [diff] [blame] | 86 | static const struct gt_powermeter ivb_pm_gt1[] = { |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 87 | { 0xa800, 0x00000000 }, |
| 88 | { 0xa804, 0x00021c00 }, |
| 89 | { 0xa808, 0x00000403 }, |
| 90 | { 0xa80c, 0x02001700 }, |
| 91 | { 0xa810, 0x05000200 }, |
| 92 | { 0xa814, 0x00000000 }, |
| 93 | { 0xa818, 0x00690500 }, |
| 94 | { 0xa81c, 0x0000007f }, |
| 95 | { 0xa820, 0x01002501 }, |
| 96 | { 0xa824, 0x00000300 }, |
| 97 | { 0xa828, 0x01000331 }, |
| 98 | { 0xa82c, 0x0000000c }, |
| 99 | { 0xa830, 0x00010016 }, |
| 100 | { 0xa834, 0x01100101 }, |
| 101 | { 0xa838, 0x00010103 }, |
| 102 | { 0xa83c, 0x00041300 }, |
| 103 | { 0xa840, 0x00000b30 }, |
| 104 | { 0xa844, 0x00000000 }, |
| 105 | { 0xa848, 0x7f000000 }, |
| 106 | { 0xa84c, 0x05000008 }, |
| 107 | { 0xa850, 0x00000001 }, |
| 108 | { 0xa854, 0x00000004 }, |
| 109 | { 0xa858, 0x00000007 }, |
| 110 | { 0xa85c, 0x00000000 }, |
| 111 | { 0xa860, 0x00010000 }, |
| 112 | { 0xa248, 0x0000221e }, |
| 113 | { 0xa900, 0x00000000 }, |
| 114 | { 0xa904, 0x00001c00 }, |
| 115 | { 0xa908, 0x00000000 }, |
| 116 | { 0xa90c, 0x06000000 }, |
| 117 | { 0xa910, 0x09000200 }, |
| 118 | { 0xa914, 0x00000000 }, |
| 119 | { 0xa918, 0x00590000 }, |
| 120 | { 0xa91c, 0x00000000 }, |
| 121 | { 0xa920, 0x04002501 }, |
| 122 | { 0xa924, 0x00000100 }, |
| 123 | { 0xa928, 0x03000410 }, |
| 124 | { 0xa92c, 0x00000000 }, |
| 125 | { 0xa930, 0x00020000 }, |
| 126 | { 0xa934, 0x02070106 }, |
| 127 | { 0xa938, 0x00010100 }, |
| 128 | { 0xa93c, 0x00401c00 }, |
| 129 | { 0xa940, 0x00000000 }, |
| 130 | { 0xa944, 0x00000000 }, |
| 131 | { 0xa948, 0x10000e00 }, |
| 132 | { 0xa94c, 0x02000004 }, |
| 133 | { 0xa950, 0x00000001 }, |
| 134 | { 0xa954, 0x00000004 }, |
| 135 | { 0xa960, 0x00060000 }, |
| 136 | { 0xaa3c, 0x00001c00 }, |
| 137 | { 0xaa54, 0x00000004 }, |
| 138 | { 0xaa60, 0x00060000 }, |
| 139 | { 0 } |
| 140 | }; |
| 141 | |
Stefan Reinauer | 4c8027a | 2012-09-07 10:53:56 -0700 | [diff] [blame] | 142 | static const struct gt_powermeter ivb_pm_gt2_17w[] = { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 143 | { 0xa800, 0x20000000 }, |
| 144 | { 0xa804, 0x000e3800 }, |
| 145 | { 0xa808, 0x00000806 }, |
| 146 | { 0xa80c, 0x0c002f00 }, |
| 147 | { 0xa810, 0x0c000800 }, |
| 148 | { 0xa814, 0x00000000 }, |
| 149 | { 0xa818, 0x00d20d00 }, |
| 150 | { 0xa81c, 0x000000ff }, |
| 151 | { 0xa820, 0x03004b02 }, |
| 152 | { 0xa824, 0x00000600 }, |
| 153 | { 0xa828, 0x07000773 }, |
| 154 | { 0xa82c, 0x00000000 }, |
| 155 | { 0xa830, 0x00020032 }, |
| 156 | { 0xa834, 0x1520040d }, |
| 157 | { 0xa838, 0x00020105 }, |
| 158 | { 0xa83c, 0x00083700 }, |
| 159 | { 0xa840, 0x000016ff }, |
| 160 | { 0xa844, 0x00000000 }, |
| 161 | { 0xa848, 0xff000000 }, |
| 162 | { 0xa84c, 0x0a000010 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 163 | { 0xa850, 0x00000002 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 164 | { 0xa854, 0x00000008 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 165 | { 0xa858, 0x0000000f }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 166 | { 0xa85c, 0x00000000 }, |
| 167 | { 0xa860, 0x00020000 }, |
| 168 | { 0xa248, 0x0000221e }, |
| 169 | { 0xa900, 0x00000000 }, |
| 170 | { 0xa904, 0x00003800 }, |
| 171 | { 0xa908, 0x00000000 }, |
| 172 | { 0xa90c, 0x0c000000 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 173 | { 0xa910, 0x12000800 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 174 | { 0xa914, 0x00000000 }, |
| 175 | { 0xa918, 0x00b20000 }, |
| 176 | { 0xa91c, 0x00000000 }, |
| 177 | { 0xa920, 0x08004b02 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 178 | { 0xa924, 0x00000300 }, |
| 179 | { 0xa928, 0x01000820 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 180 | { 0xa92c, 0x00000000 }, |
| 181 | { 0xa930, 0x00030000 }, |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 182 | { 0xa934, 0x15150406 }, |
| 183 | { 0xa938, 0x00020300 }, |
| 184 | { 0xa93c, 0x00903900 }, |
| 185 | { 0xa940, 0x00000000 }, |
| 186 | { 0xa944, 0x00000000 }, |
| 187 | { 0xa948, 0x20001b00 }, |
| 188 | { 0xa94c, 0x0a000010 }, |
| 189 | { 0xa950, 0x00000000 }, |
| 190 | { 0xa954, 0x00000008 }, |
| 191 | { 0xa960, 0x00110000 }, |
| 192 | { 0xaa3c, 0x00003900 }, |
| 193 | { 0xaa54, 0x00000008 }, |
| 194 | { 0xaa60, 0x00110000 }, |
| 195 | { 0 } |
| 196 | }; |
| 197 | |
Stefan Reinauer | 4c8027a | 2012-09-07 10:53:56 -0700 | [diff] [blame] | 198 | static const struct gt_powermeter ivb_pm_gt2_35w[] = { |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 199 | { 0xa800, 0x00000000 }, |
| 200 | { 0xa804, 0x00030400 }, |
| 201 | { 0xa808, 0x00000806 }, |
| 202 | { 0xa80c, 0x0c002f00 }, |
| 203 | { 0xa810, 0x0c000300 }, |
| 204 | { 0xa814, 0x00000000 }, |
| 205 | { 0xa818, 0x00d20d00 }, |
| 206 | { 0xa81c, 0x000000ff }, |
| 207 | { 0xa820, 0x03004b02 }, |
| 208 | { 0xa824, 0x00000600 }, |
| 209 | { 0xa828, 0x07000773 }, |
| 210 | { 0xa82c, 0x00000000 }, |
| 211 | { 0xa830, 0x00020032 }, |
| 212 | { 0xa834, 0x1520040d }, |
| 213 | { 0xa838, 0x00020105 }, |
| 214 | { 0xa83c, 0x00083700 }, |
| 215 | { 0xa840, 0x000016ff }, |
| 216 | { 0xa844, 0x00000000 }, |
| 217 | { 0xa848, 0xff000000 }, |
| 218 | { 0xa84c, 0x0a000010 }, |
| 219 | { 0xa850, 0x00000001 }, |
| 220 | { 0xa854, 0x00000008 }, |
| 221 | { 0xa858, 0x00000008 }, |
| 222 | { 0xa85c, 0x00000000 }, |
| 223 | { 0xa860, 0x00020000 }, |
| 224 | { 0xa248, 0x0000221e }, |
| 225 | { 0xa900, 0x00000000 }, |
| 226 | { 0xa904, 0x00003800 }, |
| 227 | { 0xa908, 0x00000000 }, |
| 228 | { 0xa90c, 0x0c000000 }, |
| 229 | { 0xa910, 0x12000800 }, |
| 230 | { 0xa914, 0x00000000 }, |
| 231 | { 0xa918, 0x00b20000 }, |
| 232 | { 0xa91c, 0x00000000 }, |
| 233 | { 0xa920, 0x08004b02 }, |
| 234 | { 0xa924, 0x00000300 }, |
| 235 | { 0xa928, 0x01000820 }, |
| 236 | { 0xa92c, 0x00000000 }, |
| 237 | { 0xa930, 0x00030000 }, |
| 238 | { 0xa934, 0x15150406 }, |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 239 | { 0xa938, 0x00020300 }, |
| 240 | { 0xa93c, 0x00903900 }, |
| 241 | { 0xa940, 0x00000000 }, |
| 242 | { 0xa944, 0x00000000 }, |
| 243 | { 0xa948, 0x20001b00 }, |
| 244 | { 0xa94c, 0x0a000010 }, |
| 245 | { 0xa950, 0x00000000 }, |
| 246 | { 0xa954, 0x00000008 }, |
| 247 | { 0xa960, 0x00110000 }, |
| 248 | { 0xaa3c, 0x00003900 }, |
| 249 | { 0xaa54, 0x00000008 }, |
| 250 | { 0xaa60, 0x00110000 }, |
| 251 | { 0 } |
| 252 | }; |
| 253 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 254 | /* some vga option roms are used for several chipsets but they only have one |
| 255 | * PCI ID in their header. If we encounter such an option rom, we need to do |
| 256 | * the mapping ourselfes |
| 257 | */ |
| 258 | |
| 259 | u32 map_oprom_vendev(u32 vendev) |
| 260 | { |
| 261 | u32 new_vendev=vendev; |
| 262 | |
| 263 | switch (vendev) { |
Martin Roth | e9dfdd9 | 2012-04-26 16:04:18 -0600 | [diff] [blame] | 264 | case 0x80860102: /* GT1 Desktop */ |
| 265 | case 0x8086010a: /* GT1 Server */ |
| 266 | case 0x80860112: /* GT2 Desktop */ |
| 267 | case 0x80860116: /* GT2 Mobile */ |
| 268 | case 0x80860122: /* GT2 Desktop >=1.3GHz */ |
| 269 | case 0x80860126: /* GT2 Mobile >=1.3GHz */ |
Stefan Reinauer | 816e9d1 | 2013-01-14 10:25:43 -0800 | [diff] [blame] | 270 | case 0x80860156: /* IVB */ |
Martin Roth | e9dfdd9 | 2012-04-26 16:04:18 -0600 | [diff] [blame] | 271 | case 0x80860166: /* IVB */ |
| 272 | new_vendev=0x80860106; /* GT1 Mobile */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 273 | break; |
| 274 | } |
| 275 | |
| 276 | return new_vendev; |
| 277 | } |
| 278 | |
| 279 | static struct resource *gtt_res = NULL; |
| 280 | |
Vladimir Serbinenko | a71bdc3 | 2014-08-30 00:35:39 +0200 | [diff] [blame] | 281 | u32 gtt_read(u32 reg) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 282 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 283 | return read32(res2mmio(gtt_res, reg, 0)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Vladimir Serbinenko | a71bdc3 | 2014-08-30 00:35:39 +0200 | [diff] [blame] | 286 | void gtt_write(u32 reg, u32 data) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 287 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 288 | write32(res2mmio(gtt_res, reg, 0), data); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Stefan Reinauer | 4c8027a | 2012-09-07 10:53:56 -0700 | [diff] [blame] | 291 | static inline void gtt_write_powermeter(const struct gt_powermeter *pm) |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 292 | { |
| 293 | for (; pm && pm->reg; pm++) |
| 294 | gtt_write(pm->reg, pm->value); |
| 295 | } |
| 296 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 297 | #define GTT_RETRY 1000 |
Vladimir Serbinenko | a71bdc3 | 2014-08-30 00:35:39 +0200 | [diff] [blame] | 298 | int gtt_poll(u32 reg, u32 mask, u32 value) |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 299 | { |
| 300 | unsigned try = GTT_RETRY; |
| 301 | u32 data; |
| 302 | |
| 303 | while (try--) { |
| 304 | data = gtt_read(reg); |
| 305 | if ((data & mask) == value) |
| 306 | return 1; |
| 307 | udelay(10); |
| 308 | } |
| 309 | |
| 310 | printk(BIOS_ERR, "GT init timeout\n"); |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static void gma_pm_init_pre_vbios(struct device *dev) |
| 315 | { |
| 316 | u32 reg32; |
| 317 | |
| 318 | printk(BIOS_DEBUG, "GT Power Management Init\n"); |
| 319 | |
| 320 | gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 321 | if (!gtt_res || !gtt_res->base) |
| 322 | return; |
| 323 | |
| 324 | if (bridge_silicon_revision() < IVB_STEP_C0) { |
| 325 | /* 1: Enable force wake */ |
| 326 | gtt_write(0xa18c, 0x00000001); |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 327 | gtt_poll(0x130090, (1 << 0), (1 << 0)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 328 | } else { |
| 329 | gtt_write(0xa180, 1 << 5); |
| 330 | gtt_write(0xa188, 0xffff0001); |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 331 | gtt_poll(0x130040, (1 << 0), (1 << 0)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
| 335 | /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */ |
| 336 | reg32 = gtt_read(0x42004); |
| 337 | reg32 |= (1 << 14) | (1 << 15); |
| 338 | gtt_write(0x42004, reg32); |
| 339 | } |
| 340 | |
| 341 | if (bridge_silicon_revision() >= IVB_STEP_A0) { |
| 342 | /* Display Reset Acknowledge Settings */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 343 | reg32 = gtt_read(0x45010); |
| 344 | reg32 |= (1 << 1) | (1 << 0); |
| 345 | gtt_write(0x45010, reg32); |
| 346 | } |
| 347 | |
| 348 | /* 2: Get GT SKU from GTT+0x911c[13] */ |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 349 | reg32 = gtt_read(0x911c); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 350 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 351 | if (reg32 & (1 << 13)) { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 352 | printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n"); |
| 353 | gtt_write_powermeter(snb_pm_gt1); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 354 | } else { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 355 | printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n"); |
| 356 | gtt_write_powermeter(snb_pm_gt2); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 357 | } |
| 358 | } else { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 359 | u32 unit = MCHBAR32(0x5938) & 0xf; |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 360 | |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 361 | if (reg32 & (1 << 13)) { |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 362 | /* GT1 SKU */ |
| 363 | printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n"); |
| 364 | gtt_write_powermeter(ivb_pm_gt1); |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 365 | } else { |
| 366 | /* GT2 SKU */ |
| 367 | u32 tdp = MCHBAR32(0x5930) & 0x7fff; |
| 368 | tdp /= (1 << unit); |
| 369 | |
| 370 | if (tdp <= 17) { |
| 371 | /* <=17W ULV */ |
| 372 | printk(BIOS_DEBUG, "IVB GT2 17W " |
| 373 | "Power Meter Weights\n"); |
| 374 | gtt_write_powermeter(ivb_pm_gt2_17w); |
| 375 | } else if ((tdp >= 25) && (tdp <= 35)) { |
| 376 | /* 25W-35W */ |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 377 | printk(BIOS_DEBUG, "IVB GT2 25W-35W " |
Duncan Laurie | 8508cff | 2012-04-12 16:02:43 -0700 | [diff] [blame] | 378 | "Power Meter Weights\n"); |
| 379 | gtt_write_powermeter(ivb_pm_gt2_35w); |
| 380 | } else { |
| 381 | /* All others */ |
| 382 | printk(BIOS_DEBUG, "IVB GT2 35W " |
| 383 | "Power Meter Weights\n"); |
| 384 | gtt_write_powermeter(ivb_pm_gt2_35w); |
| 385 | } |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 386 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /* 3: Gear ratio map */ |
| 390 | gtt_write(0xa004, 0x00000010); |
| 391 | |
| 392 | /* 4: GFXPAUSE */ |
| 393 | gtt_write(0xa000, 0x00070020); |
| 394 | |
| 395 | /* 5: Dynamic EU trip control */ |
| 396 | gtt_write(0xa080, 0x00000004); |
| 397 | |
| 398 | /* 6: ECO bits */ |
| 399 | reg32 = gtt_read(0xa180); |
| 400 | reg32 |= (1 << 26) | (1 << 31); |
| 401 | /* (bit 20=1 for SNB step D1+ / IVB A0+) */ |
| 402 | if (bridge_silicon_revision() >= SNB_STEP_D1) |
| 403 | reg32 |= (1 << 20); |
| 404 | gtt_write(0xa180, reg32); |
| 405 | |
| 406 | /* 6a: for SnB step D2+ only */ |
| 407 | if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) && |
| 408 | (bridge_silicon_revision() >= SNB_STEP_D2)) { |
| 409 | reg32 = gtt_read(0x9400); |
| 410 | reg32 |= (1 << 7); |
| 411 | gtt_write(0x9400, reg32); |
| 412 | |
| 413 | reg32 = gtt_read(0x941c); |
| 414 | reg32 &= 0xf; |
| 415 | reg32 |= (1 << 1); |
| 416 | gtt_write(0x941c, reg32); |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 417 | gtt_poll(0x941c, (1 << 1), (0 << 1)); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) { |
| 421 | reg32 = gtt_read(0x907c); |
| 422 | reg32 |= (1 << 16); |
| 423 | gtt_write(0x907c, reg32); |
| 424 | |
| 425 | /* 6b: Clocking reset controls */ |
| 426 | gtt_write(0x9424, 0x00000001); |
| 427 | } else { |
| 428 | /* 6b: Clocking reset controls */ |
| 429 | gtt_write(0x9424, 0x00000000); |
| 430 | } |
| 431 | |
| 432 | /* 7 */ |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 433 | if (gtt_poll(0x138124, (1 << 31), (0 << 31))) { |
| 434 | gtt_write(0x138128, 0x00000029); /* Mailbox Data */ |
| 435 | gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */ |
| 436 | if (gtt_poll(0x138124, (1 << 31), (0 << 31))) |
| 437 | gtt_write(0x138124, 0x8000000a); |
| 438 | gtt_poll(0x138124, (1 << 31), (0 << 31)); |
| 439 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 440 | |
| 441 | /* 8 */ |
| 442 | gtt_write(0xa090, 0x00000000); /* RC Control */ |
| 443 | gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */ |
| 444 | gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */ |
| 445 | gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */ |
| 446 | gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */ |
| 447 | gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */ |
| 448 | |
| 449 | /* 9 */ |
| 450 | gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */ |
| 451 | gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */ |
| 452 | gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */ |
| 453 | |
| 454 | /* 10 */ |
| 455 | gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */ |
| 456 | gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */ |
| 457 | gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */ |
| 458 | gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */ |
| 459 | gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */ |
| 460 | |
| 461 | /* 11 */ |
| 462 | gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */ |
| 463 | gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */ |
| 464 | gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */ |
| 465 | gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */ |
| 466 | gtt_write(0xa068, 0x000186a0); /* RP Up EI */ |
| 467 | gtt_write(0xa06c, 0x000493e0); /* RP Down EI */ |
| 468 | gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */ |
| 469 | |
| 470 | /* 11a: Enable Render Standby (RC6) */ |
| 471 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) { |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 472 | /* |
| 473 | * IvyBridge should also support DeepRenderStandby. |
| 474 | * |
| 475 | * Unfortunately it does not work reliably on all SKUs so |
| 476 | * disable it here and it can be enabled by the kernel. |
| 477 | */ |
| 478 | gtt_write(0xa090, 0x88040000); /* HW RC Control */ |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 479 | } else { |
| 480 | gtt_write(0xa090, 0x88040000); /* HW RC Control */ |
| 481 | } |
| 482 | |
| 483 | /* 12: Normal Frequency Request */ |
| 484 | /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */ |
| 485 | reg32 = MCHBAR32(0x5998); |
| 486 | reg32 >>= 16; |
| 487 | reg32 &= 0xef; |
| 488 | reg32 <<= 25; |
| 489 | gtt_write(0xa008, reg32); |
| 490 | |
| 491 | /* 13: RP Control */ |
| 492 | gtt_write(0xa024, 0x00000592); |
| 493 | |
| 494 | /* 14: Enable PM Interrupts */ |
| 495 | gtt_write(0x4402c, 0x03000076); |
| 496 | |
| 497 | /* Clear 0x6c024 [8:6] */ |
| 498 | reg32 = gtt_read(0x6c024); |
| 499 | reg32 &= ~0x000001c0; |
| 500 | gtt_write(0x6c024, reg32); |
| 501 | } |
| 502 | |
| 503 | static void gma_pm_init_post_vbios(struct device *dev) |
| 504 | { |
| 505 | struct northbridge_intel_sandybridge_config *conf = dev->chip_info; |
| 506 | u32 reg32; |
| 507 | |
| 508 | printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n"); |
| 509 | |
| 510 | /* 15: Deassert Force Wake */ |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 511 | if (bridge_silicon_revision() < IVB_STEP_C0) { |
| 512 | gtt_write(0xa18c, gtt_read(0xa18c) & ~1); |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 513 | gtt_poll(0x130090, (1 << 0), (0 << 0)); |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 514 | } else { |
| 515 | gtt_write(0xa188, 0x1fffe); |
Duncan Laurie | da83a5f | 2012-05-25 10:04:17 -0700 | [diff] [blame] | 516 | if (gtt_poll(0x130040, (1 << 0), (0 << 0))) |
| 517 | gtt_write(0xa188, gtt_read(0xa188) | 1); |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 518 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 519 | |
| 520 | /* 16: SW RC Control */ |
| 521 | gtt_write(0xa094, 0x00060000); |
| 522 | |
| 523 | /* Setup Digital Port Hotplug */ |
| 524 | reg32 = gtt_read(0xc4030); |
| 525 | if (!reg32) { |
| 526 | reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2; |
| 527 | reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10; |
| 528 | reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18; |
| 529 | gtt_write(0xc4030, reg32); |
| 530 | } |
| 531 | |
| 532 | /* Setup Panel Power On Delays */ |
| 533 | reg32 = gtt_read(0xc7208); |
| 534 | if (!reg32) { |
| 535 | reg32 = (conf->gpu_panel_port_select & 0x3) << 30; |
| 536 | reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16; |
| 537 | reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff); |
| 538 | gtt_write(0xc7208, reg32); |
| 539 | } |
| 540 | |
| 541 | /* Setup Panel Power Off Delays */ |
| 542 | reg32 = gtt_read(0xc720c); |
| 543 | if (!reg32) { |
| 544 | reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16; |
| 545 | reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff); |
| 546 | gtt_write(0xc720c, reg32); |
| 547 | } |
| 548 | |
| 549 | /* Setup Panel Power Cycle Delay */ |
| 550 | if (conf->gpu_panel_power_cycle_delay) { |
| 551 | reg32 = gtt_read(0xc7210); |
| 552 | reg32 &= ~0xff; |
| 553 | reg32 |= conf->gpu_panel_power_cycle_delay & 0xff; |
| 554 | gtt_write(0xc7210, reg32); |
| 555 | } |
Duncan Laurie | dd585b8 | 2012-04-09 12:05:18 -0700 | [diff] [blame] | 556 | |
| 557 | /* Enable Backlight if needed */ |
| 558 | if (conf->gpu_cpu_backlight) { |
| 559 | gtt_write(0x48250, (1 << 31)); |
| 560 | gtt_write(0x48254, conf->gpu_cpu_backlight); |
| 561 | } |
| 562 | if (conf->gpu_pch_backlight) { |
| 563 | gtt_write(0xc8250, (1 << 31)); |
| 564 | gtt_write(0xc8254, conf->gpu_pch_backlight); |
| 565 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | static void gma_func0_init(struct device *dev) |
| 569 | { |
| 570 | u32 reg32; |
| 571 | |
| 572 | /* IGD needs to be Bus Master */ |
| 573 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 574 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 575 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 576 | |
| 577 | /* Init graphics power management */ |
| 578 | gma_pm_init_pre_vbios(dev); |
| 579 | |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 580 | #if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 581 | /* PCI Init, will run VBIOS */ |
| 582 | pci_dev_init(dev); |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 583 | #endif |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 584 | |
| 585 | /* Post VBIOS init */ |
| 586 | gma_pm_init_post_vbios(dev); |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 587 | |
| 588 | #if CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT |
| 589 | /* This should probably run before post VBIOS init. */ |
| 590 | printk(BIOS_SPEW, "Initializing VGA without OPROM.\n"); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 591 | u8 *mmiobase; |
| 592 | u32 iobase, physbase, graphics_base; |
Vladimir Serbinenko | 12fcb86 | 2014-02-23 00:09:48 +0100 | [diff] [blame] | 593 | struct northbridge_intel_sandybridge_config *conf = dev->chip_info; |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 594 | iobase = dev->resource_list[2].base; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 595 | mmiobase = res2mmio(&dev->resource_list[0], 0, 0); |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 596 | physbase = pci_read_config32(dev, 0x5c) & ~0xf; |
Aaron Durbin | bb4e79a | 2013-03-26 14:09:47 -0500 | [diff] [blame] | 597 | graphics_base = dev->resource_list[1].base; |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 598 | |
Vladimir Serbinenko | a71bdc3 | 2014-08-30 00:35:39 +0200 | [diff] [blame] | 599 | int lightup_ok = i915lightup_sandy(&conf->gfx, physbase, iobase, mmiobase, graphics_base); |
Vladimir Serbinenko | 1783a3c | 2014-02-23 00:10:35 +0100 | [diff] [blame] | 600 | if (lightup_ok) |
| 601 | gfx_set_init_done(1); |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 602 | #endif |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 606 | { |
| 607 | if (!vendor || !device) { |
| 608 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 609 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 610 | } else { |
| 611 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 612 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | static struct pci_operations gma_pci_ops = { |
| 617 | .set_subsystem = gma_set_subsystem, |
| 618 | }; |
| 619 | |
| 620 | static struct device_operations gma_func0_ops = { |
Vladimir Serbinenko | 30fe612 | 2014-02-05 23:25:28 +0100 | [diff] [blame] | 621 | .read_resources = pci_dev_read_resources, |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 622 | .set_resources = pci_dev_set_resources, |
| 623 | .enable_resources = pci_dev_enable_resources, |
| 624 | .init = gma_func0_init, |
| 625 | .scan_bus = 0, |
| 626 | .enable = 0, |
| 627 | .ops_pci = &gma_pci_ops, |
| 628 | }; |
| 629 | |
Ronald G. Minnich | 69efaa0 | 2013-02-26 10:07:40 -0800 | [diff] [blame] | 630 | static const unsigned short pci_device_ids[] = { 0x0102, 0x0106, 0x010a, 0x0112, |
| 631 | 0x0116, 0x0122, 0x0126, 0x0156, |
| 632 | 0x0166, |
| 633 | 0 }; |
| 634 | |
| 635 | static const struct pci_driver gma __pci_driver = { |
| 636 | .ops = &gma_func0_ops, |
| 637 | .vendor = PCI_VENDOR_ID_INTEL, |
| 638 | .devices = pci_device_ids, |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 639 | }; |