blob: 868a961fb8ba081fba83dc77ba527753353c34f1 [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
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.
Stefan Reinauer00636b02012-04-04 00:08:51 +020014 */
15
16#include <arch/io.h>
17#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020018#include <bootmode.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020019#include <delay.h>
Vladimir Serbinenkof2e206a2014-02-23 00:13:56 +010020#include <string.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020021#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
Ronald G. Minnich69efaa02013-02-26 10:07:40 -080024#include <device/pci_ops.h>
25#include <cpu/x86/msr.h>
26#include <cpu/x86/mtrr.h>
Patrick Rudolph281ccca2017-04-12 16:55:32 +020027#include <southbridge/intel/bd82x6x/nvs.h>
28#include <cbmem.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020029
30#include "chip.h"
31#include "sandybridge.h"
Patrick Rudolph45a0dbc2017-03-30 17:07:42 +020032#include "gma.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020033
Duncan Lauriedd585b82012-04-09 12:05:18 -070034struct gt_powermeter {
35 u16 reg;
36 u32 value;
37};
38
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070039static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070040 { 0xa200, 0xcc000000 },
41 { 0xa204, 0x07000040 },
42 { 0xa208, 0x0000fe00 },
43 { 0xa20c, 0x00000000 },
44 { 0xa210, 0x17000000 },
45 { 0xa214, 0x00000021 },
46 { 0xa218, 0x0817fe19 },
47 { 0xa21c, 0x00000000 },
48 { 0xa220, 0x00000000 },
49 { 0xa224, 0xcc000000 },
50 { 0xa228, 0x07000040 },
51 { 0xa22c, 0x0000fe00 },
52 { 0xa230, 0x00000000 },
53 { 0xa234, 0x17000000 },
54 { 0xa238, 0x00000021 },
55 { 0xa23c, 0x0817fe19 },
56 { 0xa240, 0x00000000 },
57 { 0xa244, 0x00000000 },
58 { 0xa248, 0x8000421e },
59 { 0 }
60};
61
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070062static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070063 { 0xa200, 0x330000a6 },
64 { 0xa204, 0x402d0031 },
65 { 0xa208, 0x00165f83 },
66 { 0xa20c, 0xf1000000 },
67 { 0xa210, 0x00000000 },
68 { 0xa214, 0x00160016 },
69 { 0xa218, 0x002a002b },
70 { 0xa21c, 0x00000000 },
71 { 0xa220, 0x00000000 },
72 { 0xa224, 0x330000a6 },
73 { 0xa228, 0x402d0031 },
74 { 0xa22c, 0x00165f83 },
75 { 0xa230, 0xf1000000 },
76 { 0xa234, 0x00000000 },
77 { 0xa238, 0x00160016 },
78 { 0xa23c, 0x002a002b },
79 { 0xa240, 0x00000000 },
80 { 0xa244, 0x00000000 },
81 { 0xa248, 0x8000421e },
82 { 0 }
83};
84
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070085static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070086 { 0xa800, 0x00000000 },
87 { 0xa804, 0x00021c00 },
88 { 0xa808, 0x00000403 },
89 { 0xa80c, 0x02001700 },
90 { 0xa810, 0x05000200 },
91 { 0xa814, 0x00000000 },
92 { 0xa818, 0x00690500 },
93 { 0xa81c, 0x0000007f },
94 { 0xa820, 0x01002501 },
95 { 0xa824, 0x00000300 },
96 { 0xa828, 0x01000331 },
97 { 0xa82c, 0x0000000c },
98 { 0xa830, 0x00010016 },
99 { 0xa834, 0x01100101 },
100 { 0xa838, 0x00010103 },
101 { 0xa83c, 0x00041300 },
102 { 0xa840, 0x00000b30 },
103 { 0xa844, 0x00000000 },
104 { 0xa848, 0x7f000000 },
105 { 0xa84c, 0x05000008 },
106 { 0xa850, 0x00000001 },
107 { 0xa854, 0x00000004 },
108 { 0xa858, 0x00000007 },
109 { 0xa85c, 0x00000000 },
110 { 0xa860, 0x00010000 },
111 { 0xa248, 0x0000221e },
112 { 0xa900, 0x00000000 },
113 { 0xa904, 0x00001c00 },
114 { 0xa908, 0x00000000 },
115 { 0xa90c, 0x06000000 },
116 { 0xa910, 0x09000200 },
117 { 0xa914, 0x00000000 },
118 { 0xa918, 0x00590000 },
119 { 0xa91c, 0x00000000 },
120 { 0xa920, 0x04002501 },
121 { 0xa924, 0x00000100 },
122 { 0xa928, 0x03000410 },
123 { 0xa92c, 0x00000000 },
124 { 0xa930, 0x00020000 },
125 { 0xa934, 0x02070106 },
126 { 0xa938, 0x00010100 },
127 { 0xa93c, 0x00401c00 },
128 { 0xa940, 0x00000000 },
129 { 0xa944, 0x00000000 },
130 { 0xa948, 0x10000e00 },
131 { 0xa94c, 0x02000004 },
132 { 0xa950, 0x00000001 },
133 { 0xa954, 0x00000004 },
134 { 0xa960, 0x00060000 },
135 { 0xaa3c, 0x00001c00 },
136 { 0xaa54, 0x00000004 },
137 { 0xaa60, 0x00060000 },
138 { 0 }
139};
140
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700141static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700142 { 0xa800, 0x20000000 },
143 { 0xa804, 0x000e3800 },
144 { 0xa808, 0x00000806 },
145 { 0xa80c, 0x0c002f00 },
146 { 0xa810, 0x0c000800 },
147 { 0xa814, 0x00000000 },
148 { 0xa818, 0x00d20d00 },
149 { 0xa81c, 0x000000ff },
150 { 0xa820, 0x03004b02 },
151 { 0xa824, 0x00000600 },
152 { 0xa828, 0x07000773 },
153 { 0xa82c, 0x00000000 },
154 { 0xa830, 0x00020032 },
155 { 0xa834, 0x1520040d },
156 { 0xa838, 0x00020105 },
157 { 0xa83c, 0x00083700 },
158 { 0xa840, 0x000016ff },
159 { 0xa844, 0x00000000 },
160 { 0xa848, 0xff000000 },
161 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700162 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700163 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700164 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700165 { 0xa85c, 0x00000000 },
166 { 0xa860, 0x00020000 },
167 { 0xa248, 0x0000221e },
168 { 0xa900, 0x00000000 },
169 { 0xa904, 0x00003800 },
170 { 0xa908, 0x00000000 },
171 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700172 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700173 { 0xa914, 0x00000000 },
174 { 0xa918, 0x00b20000 },
175 { 0xa91c, 0x00000000 },
176 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700177 { 0xa924, 0x00000300 },
178 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700179 { 0xa92c, 0x00000000 },
180 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700181 { 0xa934, 0x15150406 },
182 { 0xa938, 0x00020300 },
183 { 0xa93c, 0x00903900 },
184 { 0xa940, 0x00000000 },
185 { 0xa944, 0x00000000 },
186 { 0xa948, 0x20001b00 },
187 { 0xa94c, 0x0a000010 },
188 { 0xa950, 0x00000000 },
189 { 0xa954, 0x00000008 },
190 { 0xa960, 0x00110000 },
191 { 0xaa3c, 0x00003900 },
192 { 0xaa54, 0x00000008 },
193 { 0xaa60, 0x00110000 },
194 { 0 }
195};
196
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700197static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700198 { 0xa800, 0x00000000 },
199 { 0xa804, 0x00030400 },
200 { 0xa808, 0x00000806 },
201 { 0xa80c, 0x0c002f00 },
202 { 0xa810, 0x0c000300 },
203 { 0xa814, 0x00000000 },
204 { 0xa818, 0x00d20d00 },
205 { 0xa81c, 0x000000ff },
206 { 0xa820, 0x03004b02 },
207 { 0xa824, 0x00000600 },
208 { 0xa828, 0x07000773 },
209 { 0xa82c, 0x00000000 },
210 { 0xa830, 0x00020032 },
211 { 0xa834, 0x1520040d },
212 { 0xa838, 0x00020105 },
213 { 0xa83c, 0x00083700 },
214 { 0xa840, 0x000016ff },
215 { 0xa844, 0x00000000 },
216 { 0xa848, 0xff000000 },
217 { 0xa84c, 0x0a000010 },
218 { 0xa850, 0x00000001 },
219 { 0xa854, 0x00000008 },
220 { 0xa858, 0x00000008 },
221 { 0xa85c, 0x00000000 },
222 { 0xa860, 0x00020000 },
223 { 0xa248, 0x0000221e },
224 { 0xa900, 0x00000000 },
225 { 0xa904, 0x00003800 },
226 { 0xa908, 0x00000000 },
227 { 0xa90c, 0x0c000000 },
228 { 0xa910, 0x12000800 },
229 { 0xa914, 0x00000000 },
230 { 0xa918, 0x00b20000 },
231 { 0xa91c, 0x00000000 },
232 { 0xa920, 0x08004b02 },
233 { 0xa924, 0x00000300 },
234 { 0xa928, 0x01000820 },
235 { 0xa92c, 0x00000000 },
236 { 0xa930, 0x00030000 },
237 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700238 { 0xa938, 0x00020300 },
239 { 0xa93c, 0x00903900 },
240 { 0xa940, 0x00000000 },
241 { 0xa944, 0x00000000 },
242 { 0xa948, 0x20001b00 },
243 { 0xa94c, 0x0a000010 },
244 { 0xa950, 0x00000000 },
245 { 0xa954, 0x00000008 },
246 { 0xa960, 0x00110000 },
247 { 0xaa3c, 0x00003900 },
248 { 0xaa54, 0x00000008 },
249 { 0xaa60, 0x00110000 },
250 { 0 }
251};
252
Stefan Reinauer00636b02012-04-04 00:08:51 +0200253/* some vga option roms are used for several chipsets but they only have one
254 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -0700255 * the mapping ourselves
Stefan Reinauer00636b02012-04-04 00:08:51 +0200256 */
257
258u32 map_oprom_vendev(u32 vendev)
259{
260 u32 new_vendev=vendev;
261
262 switch (vendev) {
Martin Rothe9dfdd92012-04-26 16:04:18 -0600263 case 0x80860102: /* GT1 Desktop */
264 case 0x8086010a: /* GT1 Server */
265 case 0x80860112: /* GT2 Desktop */
266 case 0x80860116: /* GT2 Mobile */
267 case 0x80860122: /* GT2 Desktop >=1.3GHz */
268 case 0x80860126: /* GT2 Mobile >=1.3GHz */
Stefan Reinauer816e9d12013-01-14 10:25:43 -0800269 case 0x80860156: /* IVB */
Martin Rothe9dfdd92012-04-26 16:04:18 -0600270 case 0x80860166: /* IVB */
271 new_vendev=0x80860106; /* GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200272 break;
273 }
274
275 return new_vendev;
276}
277
278static struct resource *gtt_res = NULL;
279
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200280u32 gtt_read(u32 reg)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200281{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800282 return read32(res2mmio(gtt_res, reg, 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200283}
284
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200285void gtt_write(u32 reg, u32 data)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200286{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800287 write32(res2mmio(gtt_res, reg, 0), data);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200288}
289
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700290static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700291{
292 for (; pm && pm->reg; pm++)
293 gtt_write(pm->reg, pm->value);
294}
295
Stefan Reinauer00636b02012-04-04 00:08:51 +0200296#define GTT_RETRY 1000
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200297int gtt_poll(u32 reg, u32 mask, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200298{
299 unsigned try = GTT_RETRY;
300 u32 data;
301
302 while (try--) {
303 data = gtt_read(reg);
304 if ((data & mask) == value)
305 return 1;
306 udelay(10);
307 }
308
309 printk(BIOS_ERR, "GT init timeout\n");
310 return 0;
311}
312
313static void gma_pm_init_pre_vbios(struct device *dev)
314{
315 u32 reg32;
316
317 printk(BIOS_DEBUG, "GT Power Management Init\n");
318
319 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
320 if (!gtt_res || !gtt_res->base)
321 return;
322
323 if (bridge_silicon_revision() < IVB_STEP_C0) {
324 /* 1: Enable force wake */
325 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700326 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200327 } else {
328 gtt_write(0xa180, 1 << 5);
329 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700330 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200331 }
332
333 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
334 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
335 reg32 = gtt_read(0x42004);
336 reg32 |= (1 << 14) | (1 << 15);
337 gtt_write(0x42004, reg32);
338 }
339
340 if (bridge_silicon_revision() >= IVB_STEP_A0) {
341 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200342 reg32 = gtt_read(0x45010);
343 reg32 |= (1 << 1) | (1 << 0);
344 gtt_write(0x45010, reg32);
345 }
346
347 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700348 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200349 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200350 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700351 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
352 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200353 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700354 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
355 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200356 }
357 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700358 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700359
Duncan Laurie8508cff2012-04-12 16:02:43 -0700360 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700361 /* GT1 SKU */
362 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
363 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700364 } else {
365 /* GT2 SKU */
366 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
367 tdp /= (1 << unit);
368
369 if (tdp <= 17) {
370 /* <=17W ULV */
371 printk(BIOS_DEBUG, "IVB GT2 17W "
372 "Power Meter Weights\n");
373 gtt_write_powermeter(ivb_pm_gt2_17w);
374 } else if ((tdp >= 25) && (tdp <= 35)) {
375 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700376 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700377 "Power Meter Weights\n");
378 gtt_write_powermeter(ivb_pm_gt2_35w);
379 } else {
380 /* All others */
381 printk(BIOS_DEBUG, "IVB GT2 35W "
382 "Power Meter Weights\n");
383 gtt_write_powermeter(ivb_pm_gt2_35w);
384 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700385 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200386 }
387
388 /* 3: Gear ratio map */
389 gtt_write(0xa004, 0x00000010);
390
391 /* 4: GFXPAUSE */
392 gtt_write(0xa000, 0x00070020);
393
394 /* 5: Dynamic EU trip control */
395 gtt_write(0xa080, 0x00000004);
396
397 /* 6: ECO bits */
398 reg32 = gtt_read(0xa180);
399 reg32 |= (1 << 26) | (1 << 31);
400 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
401 if (bridge_silicon_revision() >= SNB_STEP_D1)
402 reg32 |= (1 << 20);
403 gtt_write(0xa180, reg32);
404
405 /* 6a: for SnB step D2+ only */
406 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
407 (bridge_silicon_revision() >= SNB_STEP_D2)) {
408 reg32 = gtt_read(0x9400);
409 reg32 |= (1 << 7);
410 gtt_write(0x9400, reg32);
411
412 reg32 = gtt_read(0x941c);
413 reg32 &= 0xf;
414 reg32 |= (1 << 1);
415 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700416 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200417 }
418
419 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
420 reg32 = gtt_read(0x907c);
421 reg32 |= (1 << 16);
422 gtt_write(0x907c, reg32);
423
424 /* 6b: Clocking reset controls */
425 gtt_write(0x9424, 0x00000001);
426 } else {
427 /* 6b: Clocking reset controls */
428 gtt_write(0x9424, 0x00000000);
429 }
430
431 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700432 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
433 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
434 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
435 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
436 gtt_write(0x138124, 0x8000000a);
437 gtt_poll(0x138124, (1 << 31), (0 << 31));
438 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200439
440 /* 8 */
441 gtt_write(0xa090, 0x00000000); /* RC Control */
442 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
443 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
444 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
445 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
446 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
447
448 /* 9 */
449 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
450 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
451 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
452
453 /* 10 */
454 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
455 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
456 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
457 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
458 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
459
460 /* 11 */
461 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
462 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
463 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
464 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
465 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
466 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
467 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
468
469 /* 11a: Enable Render Standby (RC6) */
470 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700471 /*
472 * IvyBridge should also support DeepRenderStandby.
473 *
474 * Unfortunately it does not work reliably on all SKUs so
475 * disable it here and it can be enabled by the kernel.
476 */
477 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200478 } else {
479 gtt_write(0xa090, 0x88040000); /* HW RC Control */
480 }
481
482 /* 12: Normal Frequency Request */
483 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 (8 bits!? use 7) */
484 reg32 = MCHBAR32(0x5998);
485 reg32 >>= 16;
486 reg32 &= 0xef;
487 reg32 <<= 25;
488 gtt_write(0xa008, reg32);
489
490 /* 13: RP Control */
491 gtt_write(0xa024, 0x00000592);
492
493 /* 14: Enable PM Interrupts */
494 gtt_write(0x4402c, 0x03000076);
495
496 /* Clear 0x6c024 [8:6] */
497 reg32 = gtt_read(0x6c024);
498 reg32 &= ~0x000001c0;
499 gtt_write(0x6c024, reg32);
Nico Huber07e206a2016-10-19 15:20:17 +0200500
501 /* Initialize DP buffer translation with recommended defaults */
502 gtt_write(0xe4f00, 0x0100030c);
503 gtt_write(0xe4f04, 0x00b8230c);
504 gtt_write(0xe4f08, 0x06f8930c);
505 gtt_write(0xe4f0c, 0x05f8e38e);
506 gtt_write(0xe4f10, 0x00b8030c);
507 gtt_write(0xe4f14, 0x0b78830c);
508 gtt_write(0xe4f18, 0x09f8d3cf);
509 gtt_write(0xe4f1c, 0x01e8030c);
510 gtt_write(0xe4f20, 0x09f863cf);
511 gtt_write(0xe4f24, 0x0ff803cf);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200512}
513
514static void gma_pm_init_post_vbios(struct device *dev)
515{
516 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
517 u32 reg32;
518
519 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
520
521 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700522 if (bridge_silicon_revision() < IVB_STEP_C0) {
523 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700524 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700525 } else {
526 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700527 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
528 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700529 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200530
531 /* 16: SW RC Control */
532 gtt_write(0xa094, 0x00060000);
533
534 /* Setup Digital Port Hotplug */
535 reg32 = gtt_read(0xc4030);
536 if (!reg32) {
537 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
538 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
539 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
540 gtt_write(0xc4030, reg32);
541 }
542
543 /* Setup Panel Power On Delays */
544 reg32 = gtt_read(0xc7208);
545 if (!reg32) {
546 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
547 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
548 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
549 gtt_write(0xc7208, reg32);
550 }
551
552 /* Setup Panel Power Off Delays */
553 reg32 = gtt_read(0xc720c);
554 if (!reg32) {
555 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
556 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
557 gtt_write(0xc720c, reg32);
558 }
559
560 /* Setup Panel Power Cycle Delay */
561 if (conf->gpu_panel_power_cycle_delay) {
562 reg32 = gtt_read(0xc7210);
563 reg32 &= ~0xff;
564 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
565 gtt_write(0xc7210, reg32);
566 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700567
568 /* Enable Backlight if needed */
569 if (conf->gpu_cpu_backlight) {
570 gtt_write(0x48250, (1 << 31));
571 gtt_write(0x48254, conf->gpu_cpu_backlight);
572 }
573 if (conf->gpu_pch_backlight) {
574 gtt_write(0xc8250, (1 << 31));
575 gtt_write(0xc8254, conf->gpu_pch_backlight);
576 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200577}
578
579static void gma_func0_init(struct device *dev)
580{
581 u32 reg32;
582
583 /* IGD needs to be Bus Master */
584 reg32 = pci_read_config32(dev, PCI_COMMAND);
585 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
586 pci_write_config32(dev, PCI_COMMAND, reg32);
587
588 /* Init graphics power management */
589 gma_pm_init_pre_vbios(dev);
590
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700591 if (!IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT))
592 /* PCI Init, will run VBIOS */
593 pci_dev_init(dev);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200594
595 /* Post VBIOS init */
596 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800597
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700598 if (IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)) {
599 /* This should probably run before post VBIOS init. */
600 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
601 u8 *mmiobase;
602 u32 iobase, physbase, graphics_base;
603 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
604 iobase = dev->resource_list[2].base;
605 mmiobase = res2mmio(&dev->resource_list[0], 0, 0);
606 physbase = pci_read_config32(dev, 0x5c) & ~0xf;
607 graphics_base = dev->resource_list[1].base;
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800608
Nico Huber88c64872016-10-05 18:02:01 +0200609 int lightup_ok;
610 if (IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
611 gma_gfxinit((uintptr_t)mmiobase, graphics_base,
612 physbase, &lightup_ok);
613 } else {
614 lightup_ok = i915lightup_sandy(&conf->gfx, physbase,
615 iobase, mmiobase, graphics_base);
616 }
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700617 if (lightup_ok)
618 gfx_set_init_done(1);
619 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200620}
621
622static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
623{
624 if (!vendor || !device) {
625 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
626 pci_read_config32(dev, PCI_VENDOR_ID));
627 } else {
628 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
629 ((device & 0xffff) << 16) | (vendor & 0xffff));
630 }
631}
632
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100633const struct i915_gpu_controller_info *
634intel_gma_get_controller_info(void)
635{
636 device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
637 if (!dev) {
638 return NULL;
639 }
640 struct northbridge_intel_sandybridge_config *chip = dev->chip_info;
641 return &chip->gfx;
642}
643
Alexander Couzens5eea4582015-04-12 22:18:55 +0200644static void gma_ssdt(device_t device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100645{
646 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
647 if (!gfx) {
648 return;
649 }
650
651 drivers_intel_gma_displays_ssdt_generate(gfx);
652}
653
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200654static unsigned long
655gma_write_acpi_tables(struct device *const dev,
656 unsigned long current,
657 struct acpi_rsdp *const rsdp)
658{
659 igd_opregion_t *opregion;
660 global_nvs_t *gnvs;
661
662 // FIXME: Replace by common VBT implementation writing to current
663 opregion = igd_make_opregion();
664 if (opregion) {
665 /* GNVS has been already set up */
666 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
667 if (gnvs) {
668 /* IGD OpRegion Base Address */
669 gnvs->aslb = (u32)(uintptr_t)opregion;
670 } else {
671 printk(BIOS_ERR, "Error: GNVS table not found.\n");
672 }
673 }
674
675 return current;
676}
677
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200678/* called by pci set_vga_bridge function */
679static void gma_func0_disable(struct device *dev)
680{
681 u16 reg16;
682 device_t dev_host = dev_find_slot(0, PCI_DEVFN(0,0));
683
684 reg16 = pci_read_config16(dev_host, GGC);
685 reg16 |= (1 << 1); /* disable VGA decode */
686 pci_write_config16(dev_host, GGC, reg16);
687
688 dev->enabled = 0;
689}
690
Stefan Reinauer00636b02012-04-04 00:08:51 +0200691static struct pci_operations gma_pci_ops = {
692 .set_subsystem = gma_set_subsystem,
693};
694
695static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100696 .read_resources = pci_dev_read_resources,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200697 .set_resources = pci_dev_set_resources,
698 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100699 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200700 .init = gma_func0_init,
701 .scan_bus = 0,
702 .enable = 0,
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200703 .disable = gma_func0_disable,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200704 .ops_pci = &gma_pci_ops,
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200705 .write_acpi_tables = gma_write_acpi_tables,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200706};
707
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800708static const unsigned short pci_device_ids[] = { 0x0102, 0x0106, 0x010a, 0x0112,
709 0x0116, 0x0122, 0x0126, 0x0156,
Damien Zammit3162a1d2015-07-13 16:10:52 +1000710 0x0166, 0x0162, 0x0152,
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800711 0 };
712
713static const struct pci_driver gma __pci_driver = {
714 .ops = &gma_func0_ops,
715 .vendor = PCI_VENDOR_ID_INTEL,
716 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200717};