blob: 1005288fee6371f758b1becf63537fd06ed5d7c1 [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>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020017#include <device/mmio.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020018#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +020019#include <bootmode.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020020#include <delay.h>
21#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>
Nico Huber18228162017-06-08 16:31:57 +020025#include <drivers/intel/gma/libgfxinit.h>
Patrick Rudolph281ccca2017-04-12 16:55:32 +020026#include <southbridge/intel/bd82x6x/nvs.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050027#include <drivers/intel/gma/opregion.h>
Patrick Rudolphda9302a2019-03-24 17:01:41 +010028#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolph281ccca2017-04-12 16:55:32 +020029#include <cbmem.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020030#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020031
32#include "chip.h"
33#include "sandybridge.h"
Patrick Rudolph45a0dbc2017-03-30 17:07:42 +020034#include "gma.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020035
Duncan Lauriedd585b82012-04-09 12:05:18 -070036struct gt_powermeter {
37 u16 reg;
38 u32 value;
39};
40
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070041static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070042 { 0xa200, 0xcc000000 },
43 { 0xa204, 0x07000040 },
44 { 0xa208, 0x0000fe00 },
45 { 0xa20c, 0x00000000 },
46 { 0xa210, 0x17000000 },
47 { 0xa214, 0x00000021 },
48 { 0xa218, 0x0817fe19 },
49 { 0xa21c, 0x00000000 },
50 { 0xa220, 0x00000000 },
51 { 0xa224, 0xcc000000 },
52 { 0xa228, 0x07000040 },
53 { 0xa22c, 0x0000fe00 },
54 { 0xa230, 0x00000000 },
55 { 0xa234, 0x17000000 },
56 { 0xa238, 0x00000021 },
57 { 0xa23c, 0x0817fe19 },
58 { 0xa240, 0x00000000 },
59 { 0xa244, 0x00000000 },
60 { 0xa248, 0x8000421e },
61 { 0 }
62};
63
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070064static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070065 { 0xa200, 0x330000a6 },
66 { 0xa204, 0x402d0031 },
67 { 0xa208, 0x00165f83 },
68 { 0xa20c, 0xf1000000 },
69 { 0xa210, 0x00000000 },
70 { 0xa214, 0x00160016 },
71 { 0xa218, 0x002a002b },
72 { 0xa21c, 0x00000000 },
73 { 0xa220, 0x00000000 },
74 { 0xa224, 0x330000a6 },
75 { 0xa228, 0x402d0031 },
76 { 0xa22c, 0x00165f83 },
77 { 0xa230, 0xf1000000 },
78 { 0xa234, 0x00000000 },
79 { 0xa238, 0x00160016 },
80 { 0xa23c, 0x002a002b },
81 { 0xa240, 0x00000000 },
82 { 0xa244, 0x00000000 },
83 { 0xa248, 0x8000421e },
84 { 0 }
85};
86
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070087static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070088 { 0xa800, 0x00000000 },
89 { 0xa804, 0x00021c00 },
90 { 0xa808, 0x00000403 },
91 { 0xa80c, 0x02001700 },
92 { 0xa810, 0x05000200 },
93 { 0xa814, 0x00000000 },
94 { 0xa818, 0x00690500 },
95 { 0xa81c, 0x0000007f },
96 { 0xa820, 0x01002501 },
97 { 0xa824, 0x00000300 },
98 { 0xa828, 0x01000331 },
99 { 0xa82c, 0x0000000c },
100 { 0xa830, 0x00010016 },
101 { 0xa834, 0x01100101 },
102 { 0xa838, 0x00010103 },
103 { 0xa83c, 0x00041300 },
104 { 0xa840, 0x00000b30 },
105 { 0xa844, 0x00000000 },
106 { 0xa848, 0x7f000000 },
107 { 0xa84c, 0x05000008 },
108 { 0xa850, 0x00000001 },
109 { 0xa854, 0x00000004 },
110 { 0xa858, 0x00000007 },
111 { 0xa85c, 0x00000000 },
112 { 0xa860, 0x00010000 },
113 { 0xa248, 0x0000221e },
114 { 0xa900, 0x00000000 },
115 { 0xa904, 0x00001c00 },
116 { 0xa908, 0x00000000 },
117 { 0xa90c, 0x06000000 },
118 { 0xa910, 0x09000200 },
119 { 0xa914, 0x00000000 },
120 { 0xa918, 0x00590000 },
121 { 0xa91c, 0x00000000 },
122 { 0xa920, 0x04002501 },
123 { 0xa924, 0x00000100 },
124 { 0xa928, 0x03000410 },
125 { 0xa92c, 0x00000000 },
126 { 0xa930, 0x00020000 },
127 { 0xa934, 0x02070106 },
128 { 0xa938, 0x00010100 },
129 { 0xa93c, 0x00401c00 },
130 { 0xa940, 0x00000000 },
131 { 0xa944, 0x00000000 },
132 { 0xa948, 0x10000e00 },
133 { 0xa94c, 0x02000004 },
134 { 0xa950, 0x00000001 },
135 { 0xa954, 0x00000004 },
136 { 0xa960, 0x00060000 },
137 { 0xaa3c, 0x00001c00 },
138 { 0xaa54, 0x00000004 },
139 { 0xaa60, 0x00060000 },
140 { 0 }
141};
142
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700143static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700144 { 0xa800, 0x20000000 },
145 { 0xa804, 0x000e3800 },
146 { 0xa808, 0x00000806 },
147 { 0xa80c, 0x0c002f00 },
148 { 0xa810, 0x0c000800 },
149 { 0xa814, 0x00000000 },
150 { 0xa818, 0x00d20d00 },
151 { 0xa81c, 0x000000ff },
152 { 0xa820, 0x03004b02 },
153 { 0xa824, 0x00000600 },
154 { 0xa828, 0x07000773 },
155 { 0xa82c, 0x00000000 },
156 { 0xa830, 0x00020032 },
157 { 0xa834, 0x1520040d },
158 { 0xa838, 0x00020105 },
159 { 0xa83c, 0x00083700 },
160 { 0xa840, 0x000016ff },
161 { 0xa844, 0x00000000 },
162 { 0xa848, 0xff000000 },
163 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700164 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700165 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700166 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700167 { 0xa85c, 0x00000000 },
168 { 0xa860, 0x00020000 },
169 { 0xa248, 0x0000221e },
170 { 0xa900, 0x00000000 },
171 { 0xa904, 0x00003800 },
172 { 0xa908, 0x00000000 },
173 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700174 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700175 { 0xa914, 0x00000000 },
176 { 0xa918, 0x00b20000 },
177 { 0xa91c, 0x00000000 },
178 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700179 { 0xa924, 0x00000300 },
180 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700181 { 0xa92c, 0x00000000 },
182 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700183 { 0xa934, 0x15150406 },
184 { 0xa938, 0x00020300 },
185 { 0xa93c, 0x00903900 },
186 { 0xa940, 0x00000000 },
187 { 0xa944, 0x00000000 },
188 { 0xa948, 0x20001b00 },
189 { 0xa94c, 0x0a000010 },
190 { 0xa950, 0x00000000 },
191 { 0xa954, 0x00000008 },
192 { 0xa960, 0x00110000 },
193 { 0xaa3c, 0x00003900 },
194 { 0xaa54, 0x00000008 },
195 { 0xaa60, 0x00110000 },
196 { 0 }
197};
198
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700199static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700200 { 0xa800, 0x00000000 },
201 { 0xa804, 0x00030400 },
202 { 0xa808, 0x00000806 },
203 { 0xa80c, 0x0c002f00 },
204 { 0xa810, 0x0c000300 },
205 { 0xa814, 0x00000000 },
206 { 0xa818, 0x00d20d00 },
207 { 0xa81c, 0x000000ff },
208 { 0xa820, 0x03004b02 },
209 { 0xa824, 0x00000600 },
210 { 0xa828, 0x07000773 },
211 { 0xa82c, 0x00000000 },
212 { 0xa830, 0x00020032 },
213 { 0xa834, 0x1520040d },
214 { 0xa838, 0x00020105 },
215 { 0xa83c, 0x00083700 },
216 { 0xa840, 0x000016ff },
217 { 0xa844, 0x00000000 },
218 { 0xa848, 0xff000000 },
219 { 0xa84c, 0x0a000010 },
220 { 0xa850, 0x00000001 },
221 { 0xa854, 0x00000008 },
222 { 0xa858, 0x00000008 },
223 { 0xa85c, 0x00000000 },
224 { 0xa860, 0x00020000 },
225 { 0xa248, 0x0000221e },
226 { 0xa900, 0x00000000 },
227 { 0xa904, 0x00003800 },
228 { 0xa908, 0x00000000 },
229 { 0xa90c, 0x0c000000 },
230 { 0xa910, 0x12000800 },
231 { 0xa914, 0x00000000 },
232 { 0xa918, 0x00b20000 },
233 { 0xa91c, 0x00000000 },
234 { 0xa920, 0x08004b02 },
235 { 0xa924, 0x00000300 },
236 { 0xa928, 0x01000820 },
237 { 0xa92c, 0x00000000 },
238 { 0xa930, 0x00030000 },
239 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700240 { 0xa938, 0x00020300 },
241 { 0xa93c, 0x00903900 },
242 { 0xa940, 0x00000000 },
243 { 0xa944, 0x00000000 },
244 { 0xa948, 0x20001b00 },
245 { 0xa94c, 0x0a000010 },
246 { 0xa950, 0x00000000 },
247 { 0xa954, 0x00000008 },
248 { 0xa960, 0x00110000 },
249 { 0xaa3c, 0x00003900 },
250 { 0xaa54, 0x00000008 },
251 { 0xaa60, 0x00110000 },
252 { 0 }
253};
254
Stefan Reinauer00636b02012-04-04 00:08:51 +0200255/* some vga option roms are used for several chipsets but they only have one
256 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -0700257 * the mapping ourselves
Stefan Reinauer00636b02012-04-04 00:08:51 +0200258 */
259
260u32 map_oprom_vendev(u32 vendev)
261{
Nico Huber23b93dd2017-07-29 01:46:23 +0200262 u32 new_vendev = vendev;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200263
264 switch (vendev) {
Nico Huber23b93dd2017-07-29 01:46:23 +0200265 case 0x80860102: /* SNB GT1 Desktop */
266 case 0x8086010a: /* SNB GT1 Server */
267 case 0x80860112: /* SNB GT2 Desktop */
268 case 0x80860116: /* SNB GT2 Mobile */
269 case 0x80860122: /* SNB GT2 Desktop >=1.3GHz */
270 case 0x80860126: /* SNB GT2 Mobile >=1.3GHz */
271 case 0x80860152: /* IVB GT1 Desktop */
272 case 0x80860156: /* IVB GT1 Mobile */
273 case 0x80860162: /* IVB GT2 Desktop */
274 case 0x80860166: /* IVB GT2 Mobile */
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000275 case 0x8086016a: /* IVB GT2 Server */
Nico Huber23b93dd2017-07-29 01:46:23 +0200276 new_vendev = 0x80860106;/* SNB GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200277 break;
278 }
279
280 return new_vendev;
281}
282
283static struct resource *gtt_res = NULL;
284
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200285u32 gtt_read(u32 reg)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200286{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800287 return read32(res2mmio(gtt_res, reg, 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200288}
289
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200290void gtt_write(u32 reg, u32 data)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200291{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800292 write32(res2mmio(gtt_res, reg, 0), data);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200293}
294
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700295static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700296{
297 for (; pm && pm->reg; pm++)
298 gtt_write(pm->reg, pm->value);
299}
300
Stefan Reinauer00636b02012-04-04 00:08:51 +0200301#define GTT_RETRY 1000
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200302int gtt_poll(u32 reg, u32 mask, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200303{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530304 unsigned int try = GTT_RETRY;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200305 u32 data;
306
307 while (try--) {
308 data = gtt_read(reg);
309 if ((data & mask) == value)
310 return 1;
311 udelay(10);
312 }
313
314 printk(BIOS_ERR, "GT init timeout\n");
315 return 0;
316}
317
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200318uintptr_t gma_get_gnvs_aslb(const void *gnvs)
319{
320 const global_nvs_t *gnvs_ptr = gnvs;
321 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
322}
323
324void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
325{
326 global_nvs_t *gnvs_ptr = gnvs;
327 if (gnvs_ptr)
328 gnvs_ptr->aslb = aslb;
329}
330
Stefan Reinauer00636b02012-04-04 00:08:51 +0200331static void gma_pm_init_pre_vbios(struct device *dev)
332{
333 u32 reg32;
334
335 printk(BIOS_DEBUG, "GT Power Management Init\n");
336
337 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
338 if (!gtt_res || !gtt_res->base)
339 return;
340
341 if (bridge_silicon_revision() < IVB_STEP_C0) {
342 /* 1: Enable force wake */
343 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700344 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200345 } else {
346 gtt_write(0xa180, 1 << 5);
347 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700348 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200349 }
350
351 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
352 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
353 reg32 = gtt_read(0x42004);
354 reg32 |= (1 << 14) | (1 << 15);
355 gtt_write(0x42004, reg32);
356 }
357
358 if (bridge_silicon_revision() >= IVB_STEP_A0) {
359 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200360 reg32 = gtt_read(0x45010);
361 reg32 |= (1 << 1) | (1 << 0);
362 gtt_write(0x45010, reg32);
363 }
364
365 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700366 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200367 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200368 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700369 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
370 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200371 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700372 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
373 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200374 }
375 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700376 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700377
Duncan Laurie8508cff2012-04-12 16:02:43 -0700378 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700379 /* GT1 SKU */
380 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
381 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700382 } else {
383 /* GT2 SKU */
384 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
385 tdp /= (1 << unit);
386
387 if (tdp <= 17) {
388 /* <=17W ULV */
389 printk(BIOS_DEBUG, "IVB GT2 17W "
390 "Power Meter Weights\n");
391 gtt_write_powermeter(ivb_pm_gt2_17w);
392 } else if ((tdp >= 25) && (tdp <= 35)) {
393 /* 25W-35W */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700394 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
Duncan Laurie8508cff2012-04-12 16:02:43 -0700395 "Power Meter Weights\n");
396 gtt_write_powermeter(ivb_pm_gt2_35w);
397 } else {
398 /* All others */
399 printk(BIOS_DEBUG, "IVB GT2 35W "
400 "Power Meter Weights\n");
401 gtt_write_powermeter(ivb_pm_gt2_35w);
402 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700403 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200404 }
405
406 /* 3: Gear ratio map */
407 gtt_write(0xa004, 0x00000010);
408
409 /* 4: GFXPAUSE */
410 gtt_write(0xa000, 0x00070020);
411
412 /* 5: Dynamic EU trip control */
413 gtt_write(0xa080, 0x00000004);
414
415 /* 6: ECO bits */
416 reg32 = gtt_read(0xa180);
417 reg32 |= (1 << 26) | (1 << 31);
418 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
419 if (bridge_silicon_revision() >= SNB_STEP_D1)
420 reg32 |= (1 << 20);
421 gtt_write(0xa180, reg32);
422
423 /* 6a: for SnB step D2+ only */
424 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
425 (bridge_silicon_revision() >= SNB_STEP_D2)) {
426 reg32 = gtt_read(0x9400);
427 reg32 |= (1 << 7);
428 gtt_write(0x9400, reg32);
429
430 reg32 = gtt_read(0x941c);
431 reg32 &= 0xf;
432 reg32 |= (1 << 1);
433 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700434 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200435 }
436
437 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
438 reg32 = gtt_read(0x907c);
439 reg32 |= (1 << 16);
440 gtt_write(0x907c, reg32);
441
442 /* 6b: Clocking reset controls */
443 gtt_write(0x9424, 0x00000001);
444 } else {
445 /* 6b: Clocking reset controls */
446 gtt_write(0x9424, 0x00000000);
447 }
448
449 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700450 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
451 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
452 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
453 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
454 gtt_write(0x138124, 0x8000000a);
455 gtt_poll(0x138124, (1 << 31), (0 << 31));
456 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200457
458 /* 8 */
459 gtt_write(0xa090, 0x00000000); /* RC Control */
460 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
461 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
462 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
463 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
464 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
465
466 /* 9 */
467 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
468 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
469 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
470
471 /* 10 */
472 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
473 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
474 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
475 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
476 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
477
478 /* 11 */
479 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
480 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
481 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
482 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
483 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
484 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
485 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
486
487 /* 11a: Enable Render Standby (RC6) */
488 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700489 /*
490 * IvyBridge should also support DeepRenderStandby.
491 *
492 * Unfortunately it does not work reliably on all SKUs so
493 * disable it here and it can be enabled by the kernel.
494 */
495 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200496 } else {
497 gtt_write(0xa090, 0x88040000); /* HW RC Control */
498 }
499
500 /* 12: Normal Frequency Request */
Felix Held6b6c94b2017-11-25 00:45:23 +0100501 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 */
502 /* only the lower 7 bits are used and shifted left by 25 */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200503 reg32 = MCHBAR32(0x5998);
504 reg32 >>= 16;
Felix Held6b6c94b2017-11-25 00:45:23 +0100505 reg32 &= 0x7f;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200506 reg32 <<= 25;
507 gtt_write(0xa008, reg32);
508
509 /* 13: RP Control */
510 gtt_write(0xa024, 0x00000592);
511
512 /* 14: Enable PM Interrupts */
513 gtt_write(0x4402c, 0x03000076);
514
515 /* Clear 0x6c024 [8:6] */
516 reg32 = gtt_read(0x6c024);
517 reg32 &= ~0x000001c0;
518 gtt_write(0x6c024, reg32);
Nico Huber07e206a2016-10-19 15:20:17 +0200519
520 /* Initialize DP buffer translation with recommended defaults */
521 gtt_write(0xe4f00, 0x0100030c);
522 gtt_write(0xe4f04, 0x00b8230c);
523 gtt_write(0xe4f08, 0x06f8930c);
524 gtt_write(0xe4f0c, 0x05f8e38e);
525 gtt_write(0xe4f10, 0x00b8030c);
526 gtt_write(0xe4f14, 0x0b78830c);
527 gtt_write(0xe4f18, 0x09f8d3cf);
528 gtt_write(0xe4f1c, 0x01e8030c);
529 gtt_write(0xe4f20, 0x09f863cf);
530 gtt_write(0xe4f24, 0x0ff803cf);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200531}
532
533static void gma_pm_init_post_vbios(struct device *dev)
534{
535 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
536 u32 reg32;
537
538 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
539
540 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700541 if (bridge_silicon_revision() < IVB_STEP_C0) {
542 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700543 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700544 } else {
545 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700546 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
547 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700548 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200549
550 /* 16: SW RC Control */
551 gtt_write(0xa094, 0x00060000);
552
553 /* Setup Digital Port Hotplug */
554 reg32 = gtt_read(0xc4030);
555 if (!reg32) {
556 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
557 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
558 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
559 gtt_write(0xc4030, reg32);
560 }
561
562 /* Setup Panel Power On Delays */
563 reg32 = gtt_read(0xc7208);
564 if (!reg32) {
565 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
566 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
567 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
568 gtt_write(0xc7208, reg32);
569 }
570
571 /* Setup Panel Power Off Delays */
572 reg32 = gtt_read(0xc720c);
573 if (!reg32) {
574 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
575 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
576 gtt_write(0xc720c, reg32);
577 }
578
579 /* Setup Panel Power Cycle Delay */
580 if (conf->gpu_panel_power_cycle_delay) {
581 reg32 = gtt_read(0xc7210);
582 reg32 &= ~0xff;
583 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
584 gtt_write(0xc7210, reg32);
585 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700586
587 /* Enable Backlight if needed */
588 if (conf->gpu_cpu_backlight) {
589 gtt_write(0x48250, (1 << 31));
590 gtt_write(0x48254, conf->gpu_cpu_backlight);
591 }
592 if (conf->gpu_pch_backlight) {
593 gtt_write(0xc8250, (1 << 31));
594 gtt_write(0xc8254, conf->gpu_pch_backlight);
595 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200596}
597
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200598/* Enable SCI to ACPI _GPE._L06 */
599static void gma_enable_swsci(void)
600{
601 u16 reg16;
602
603 /* clear DMISCI status */
604 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
605 reg16 &= DMISCI_STS;
606 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
607
608 /* clear acpi tco status */
609 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
610
611 /* enable acpi tco scis */
612 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
613 reg16 |= TCOSCI_EN;
614 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
615}
616
Stefan Reinauer00636b02012-04-04 00:08:51 +0200617static void gma_func0_init(struct device *dev)
618{
619 u32 reg32;
620
621 /* IGD needs to be Bus Master */
622 reg32 = pci_read_config32(dev, PCI_COMMAND);
623 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
624 pci_write_config32(dev, PCI_COMMAND, reg32);
625
626 /* Init graphics power management */
627 gma_pm_init_pre_vbios(dev);
628
Julius Wernercd49cce2019-03-05 16:53:33 -0800629 if (!CONFIG(MAINBOARD_DO_NATIVE_VGA_INIT))
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700630 /* PCI Init, will run VBIOS */
631 pci_dev_init(dev);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200632
633 /* Post VBIOS init */
634 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800635
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200636 int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1;
637
Patrick Rudolphde4a1a02017-06-20 19:13:33 +0200638 /* Running graphics init on S3 breaks Linux drm driver. */
639 if (!acpi_is_wakeup_s3() &&
Julius Wernercd49cce2019-03-05 16:53:33 -0800640 CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200641 if (vga_disable) {
642 printk(BIOS_INFO,
643 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
Nico Huber88c64872016-10-05 18:02:01 +0200644 } else {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200645 /* This should probably run before post VBIOS init. */
646 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200647 int lightup_ok;
Arthur Heymansa6be58f2018-07-18 16:43:43 +0200648 gma_gfxinit(&lightup_ok);
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200649 if (lightup_ok)
650 gfx_set_init_done(1);
Nico Huber88c64872016-10-05 18:02:01 +0200651 }
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700652 }
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200653
654 gma_enable_swsci();
655 intel_gma_restore_opregion();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200656}
657
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100658const struct i915_gpu_controller_info *
659intel_gma_get_controller_info(void)
660{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300661 struct device *dev = pcidev_on_root(0x2, 0);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100662 if (!dev) {
663 return NULL;
664 }
665 struct northbridge_intel_sandybridge_config *chip = dev->chip_info;
666 return &chip->gfx;
667}
668
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100669static void gma_ssdt(struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100670{
671 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
672 if (!gfx) {
673 return;
674 }
675
676 drivers_intel_gma_displays_ssdt_generate(gfx);
677}
678
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200679static unsigned long
680gma_write_acpi_tables(struct device *const dev,
681 unsigned long current,
682 struct acpi_rsdp *const rsdp)
683{
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200684 igd_opregion_t *opregion = (igd_opregion_t *)current;
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200685 global_nvs_t *gnvs;
686
Matt DeVillierebe08e02017-07-14 13:28:42 -0500687 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200688 return current;
689
690 current += sizeof(igd_opregion_t);
691
692 /* GNVS has been already set up */
693 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
694 if (gnvs) {
695 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200696 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200697 } else {
698 printk(BIOS_ERR, "Error: GNVS table not found.\n");
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200699 }
700
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200701 current = acpi_align_current(current);
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200702 return current;
703}
704
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600705static const char *gma_acpi_name(const struct device *dev)
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200706{
707 return "GFX0";
708}
709
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200710/* called by pci set_vga_bridge function */
711static void gma_func0_disable(struct device *dev)
712{
713 u16 reg16;
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300714 struct device *dev_host = pcidev_on_root(0, 0);
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200715
716 reg16 = pci_read_config16(dev_host, GGC);
717 reg16 |= (1 << 1); /* disable VGA decode */
718 pci_write_config16(dev_host, GGC, reg16);
719
720 dev->enabled = 0;
721}
722
Stefan Reinauer00636b02012-04-04 00:08:51 +0200723static struct pci_operations gma_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530724 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200725};
726
727static struct device_operations gma_func0_ops = {
Vladimir Serbinenko30fe6122014-02-05 23:25:28 +0100728 .read_resources = pci_dev_read_resources,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200729 .set_resources = pci_dev_set_resources,
730 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100731 .acpi_fill_ssdt_generator = gma_ssdt,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200732 .init = gma_func0_init,
733 .scan_bus = 0,
734 .enable = 0,
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200735 .disable = gma_func0_disable,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200736 .ops_pci = &gma_pci_ops,
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200737 .acpi_name = gma_acpi_name,
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200738 .write_acpi_tables = gma_write_acpi_tables,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200739};
740
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800741static const unsigned short pci_device_ids[] = { 0x0102, 0x0106, 0x010a, 0x0112,
742 0x0116, 0x0122, 0x0126, 0x0156,
Vagiz Trakhanov1dd448c2017-09-28 14:42:11 +0000743 0x0166, 0x0162, 0x016a, 0x0152,
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800744 0 };
745
746static const struct pci_driver gma __pci_driver = {
747 .ops = &gma_func0_ops,
748 .vendor = PCI_VENDOR_ID_INTEL,
749 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200750};