blob: 8c0117f531d1eba1d06ead47992a6eb4f8ee13e0 [file] [log] [blame]
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Chromium OS Authors
5 * Copyright (C) 2013 Vladimir Serbinenko
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010015 */
16
17#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020018#include <device/mmio.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010019#include <console/console.h>
20#include <delay.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010024#include <device/pci_ops.h>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010025#include <drivers/intel/gma/edid.h>
26#include <drivers/intel/gma/i915.h>
Patrick Rudolph5c820262017-05-17 19:39:12 +020027#include <drivers/intel/gma/intel_bios.h>
Nico Huber18228162017-06-08 16:31:57 +020028#include <drivers/intel/gma/libgfxinit.h>
Vladimir Serbinenko13157302014-02-19 22:18:08 +010029#include <pc80/vga.h>
30#include <pc80/vga_io.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020031#include <southbridge/intel/ibexpeak/nvs.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050032#include <drivers/intel/gma/opregion.h>
Patrick Rudolph2be28402017-04-12 16:54:55 +020033#include <cbmem.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010034
35#include "chip.h"
36#include "nehalem.h"
37
38struct gt_powermeter {
39 u16 reg;
40 u32 value;
41};
42
43static const struct gt_powermeter snb_pm_gt1[] = {
44 {0xa200, 0xcc000000},
45 {0xa204, 0x07000040},
46 {0xa208, 0x0000fe00},
47 {0xa20c, 0x00000000},
48 {0xa210, 0x17000000},
49 {0xa214, 0x00000021},
50 {0xa218, 0x0817fe19},
51 {0xa21c, 0x00000000},
52 {0xa220, 0x00000000},
53 {0xa224, 0xcc000000},
54 {0xa228, 0x07000040},
55 {0xa22c, 0x0000fe00},
56 {0xa230, 0x00000000},
57 {0xa234, 0x17000000},
58 {0xa238, 0x00000021},
59 {0xa23c, 0x0817fe19},
60 {0xa240, 0x00000000},
61 {0xa244, 0x00000000},
62 {0xa248, 0x8000421e},
63 {0}
64};
65
66static const struct gt_powermeter snb_pm_gt2[] = {
67 {0xa200, 0x330000a6},
68 {0xa204, 0x402d0031},
69 {0xa208, 0x00165f83},
70 {0xa20c, 0xf1000000},
71 {0xa210, 0x00000000},
72 {0xa214, 0x00160016},
73 {0xa218, 0x002a002b},
74 {0xa21c, 0x00000000},
75 {0xa220, 0x00000000},
76 {0xa224, 0x330000a6},
77 {0xa228, 0x402d0031},
78 {0xa22c, 0x00165f83},
79 {0xa230, 0xf1000000},
80 {0xa234, 0x00000000},
81 {0xa238, 0x00160016},
82 {0xa23c, 0x002a002b},
83 {0xa240, 0x00000000},
84 {0xa244, 0x00000000},
85 {0xa248, 0x8000421e},
86 {0}
87};
88
89static const struct gt_powermeter ivb_pm_gt1[] = {
90 {0xa800, 0x00000000},
91 {0xa804, 0x00021c00},
92 {0xa808, 0x00000403},
93 {0xa80c, 0x02001700},
94 {0xa810, 0x05000200},
95 {0xa814, 0x00000000},
96 {0xa818, 0x00690500},
97 {0xa81c, 0x0000007f},
98 {0xa820, 0x01002501},
99 {0xa824, 0x00000300},
100 {0xa828, 0x01000331},
101 {0xa82c, 0x0000000c},
102 {0xa830, 0x00010016},
103 {0xa834, 0x01100101},
104 {0xa838, 0x00010103},
105 {0xa83c, 0x00041300},
106 {0xa840, 0x00000b30},
107 {0xa844, 0x00000000},
108 {0xa848, 0x7f000000},
109 {0xa84c, 0x05000008},
110 {0xa850, 0x00000001},
111 {0xa854, 0x00000004},
112 {0xa858, 0x00000007},
113 {0xa85c, 0x00000000},
114 {0xa860, 0x00010000},
115 {0xa248, 0x0000221e},
116 {0xa900, 0x00000000},
117 {0xa904, 0x00001c00},
118 {0xa908, 0x00000000},
119 {0xa90c, 0x06000000},
120 {0xa910, 0x09000200},
121 {0xa914, 0x00000000},
122 {0xa918, 0x00590000},
123 {0xa91c, 0x00000000},
124 {0xa920, 0x04002501},
125 {0xa924, 0x00000100},
126 {0xa928, 0x03000410},
127 {0xa92c, 0x00000000},
128 {0xa930, 0x00020000},
129 {0xa934, 0x02070106},
130 {0xa938, 0x00010100},
131 {0xa93c, 0x00401c00},
132 {0xa940, 0x00000000},
133 {0xa944, 0x00000000},
134 {0xa948, 0x10000e00},
135 {0xa94c, 0x02000004},
136 {0xa950, 0x00000001},
137 {0xa954, 0x00000004},
138 {0xa960, 0x00060000},
139 {0xaa3c, 0x00001c00},
140 {0xaa54, 0x00000004},
141 {0xaa60, 0x00060000},
142 {0}
143};
144
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100145static const struct gt_powermeter ivb_pm_gt2_17w[] = {
146 {0xa800, 0x20000000},
147 {0xa804, 0x000e3800},
148 {0xa808, 0x00000806},
149 {0xa80c, 0x0c002f00},
150 {0xa810, 0x0c000800},
151 {0xa814, 0x00000000},
152 {0xa818, 0x00d20d00},
153 {0xa81c, 0x000000ff},
154 {0xa820, 0x03004b02},
155 {0xa824, 0x00000600},
156 {0xa828, 0x07000773},
157 {0xa82c, 0x00000000},
158 {0xa830, 0x00020032},
159 {0xa834, 0x1520040d},
160 {0xa838, 0x00020105},
161 {0xa83c, 0x00083700},
162 {0xa840, 0x000016ff},
163 {0xa844, 0x00000000},
164 {0xa848, 0xff000000},
165 {0xa84c, 0x0a000010},
166 {0xa850, 0x00000002},
167 {0xa854, 0x00000008},
168 {0xa858, 0x0000000f},
169 {0xa85c, 0x00000000},
170 {0xa860, 0x00020000},
171 {0xa248, 0x0000221e},
172 {0xa900, 0x00000000},
173 {0xa904, 0x00003800},
174 {0xa908, 0x00000000},
175 {0xa90c, 0x0c000000},
176 {0xa910, 0x12000800},
177 {0xa914, 0x00000000},
178 {0xa918, 0x00b20000},
179 {0xa91c, 0x00000000},
180 {0xa920, 0x08004b02},
181 {0xa924, 0x00000300},
182 {0xa928, 0x01000820},
183 {0xa92c, 0x00000000},
184 {0xa930, 0x00030000},
185 {0xa934, 0x15150406},
186 {0xa938, 0x00020300},
187 {0xa93c, 0x00903900},
188 {0xa940, 0x00000000},
189 {0xa944, 0x00000000},
190 {0xa948, 0x20001b00},
191 {0xa94c, 0x0a000010},
192 {0xa950, 0x00000000},
193 {0xa954, 0x00000008},
194 {0xa960, 0x00110000},
195 {0xaa3c, 0x00003900},
196 {0xaa54, 0x00000008},
197 {0xaa60, 0x00110000},
198 {0}
199};
200
201static const struct gt_powermeter ivb_pm_gt2_35w[] = {
202 {0xa800, 0x00000000},
203 {0xa804, 0x00030400},
204 {0xa808, 0x00000806},
205 {0xa80c, 0x0c002f00},
206 {0xa810, 0x0c000300},
207 {0xa814, 0x00000000},
208 {0xa818, 0x00d20d00},
209 {0xa81c, 0x000000ff},
210 {0xa820, 0x03004b02},
211 {0xa824, 0x00000600},
212 {0xa828, 0x07000773},
213 {0xa82c, 0x00000000},
214 {0xa830, 0x00020032},
215 {0xa834, 0x1520040d},
216 {0xa838, 0x00020105},
217 {0xa83c, 0x00083700},
218 {0xa840, 0x000016ff},
219 {0xa844, 0x00000000},
220 {0xa848, 0xff000000},
221 {0xa84c, 0x0a000010},
222 {0xa850, 0x00000001},
223 {0xa854, 0x00000008},
224 {0xa858, 0x00000008},
225 {0xa85c, 0x00000000},
226 {0xa860, 0x00020000},
227 {0xa248, 0x0000221e},
228 {0xa900, 0x00000000},
229 {0xa904, 0x00003800},
230 {0xa908, 0x00000000},
231 {0xa90c, 0x0c000000},
232 {0xa910, 0x12000800},
233 {0xa914, 0x00000000},
234 {0xa918, 0x00b20000},
235 {0xa91c, 0x00000000},
236 {0xa920, 0x08004b02},
237 {0xa924, 0x00000300},
238 {0xa928, 0x01000820},
239 {0xa92c, 0x00000000},
240 {0xa930, 0x00030000},
241 {0xa934, 0x15150406},
242 {0xa938, 0x00020300},
243 {0xa93c, 0x00903900},
244 {0xa940, 0x00000000},
245 {0xa944, 0x00000000},
246 {0xa948, 0x20001b00},
247 {0xa94c, 0x0a000010},
248 {0xa950, 0x00000000},
249 {0xa954, 0x00000008},
250 {0xa960, 0x00110000},
251 {0xaa3c, 0x00003900},
252 {0xaa54, 0x00000008},
253 {0xaa60, 0x00110000},
254 {0}
255};
256
257/* some vga option roms are used for several chipsets but they only have one
258 * PCI ID in their header. If we encounter such an option rom, we need to do
Martin Roth128c1042016-11-18 09:29:03 -0700259 * the mapping ourselves
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100260 */
261
262u32 map_oprom_vendev(u32 vendev)
263{
264 u32 new_vendev = vendev;
265
Martin Roth128c1042016-11-18 09:29:03 -0700266 /* none currently. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100267
268 return new_vendev;
269}
270
271static struct resource *gtt_res = NULL;
272
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700273u32 gtt_read(u32 reg)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100274{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800275 return read32(res2mmio(gtt_res, reg, 0));
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100276}
277
Furquan Shaikh77f48cd2013-08-19 10:16:50 -0700278void gtt_write(u32 reg, u32 data)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100279{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800280 write32(res2mmio(gtt_res, reg, 0), data);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100281}
282
283static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
284{
285 for (; pm && pm->reg; pm++)
286 gtt_write(pm->reg, pm->value);
287}
288
289#define GTT_RETRY 1000
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700290int gtt_poll(u32 reg, u32 mask, u32 value)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100291{
292 unsigned try = GTT_RETRY;
293 u32 data;
294
295 while (try--) {
296 data = gtt_read(reg);
297 if ((data & mask) == value)
298 return 1;
299 udelay(10);
300 }
301
302 printk(BIOS_ERR, "GT init timeout\n");
303 return 0;
304}
305
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200306uintptr_t gma_get_gnvs_aslb(const void *gnvs)
307{
308 const global_nvs_t *gnvs_ptr = gnvs;
309 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
310}
311
312void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
313{
314 global_nvs_t *gnvs_ptr = gnvs;
315 if (gnvs_ptr)
316 gnvs_ptr->aslb = aslb;
317}
318
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100319static void gma_pm_init_pre_vbios(struct device *dev)
320{
321 u32 reg32;
322
323 printk(BIOS_DEBUG, "GT Power Management Init\n");
324
325 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
326 if (!gtt_res || !gtt_res->base)
327 return;
328
329 if (bridge_silicon_revision() < IVB_STEP_C0) {
330 /* 1: Enable force wake */
331 gtt_write(0xa18c, 0x00000001);
332 gtt_poll(0x130090, (1 << 0), (1 << 0));
333 } else {
334 gtt_write(0xa180, 1 << 5);
335 gtt_write(0xa188, 0xffff0001);
336 gtt_poll(0x130040, (1 << 0), (1 << 0));
337 }
338
339 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
340 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
341 reg32 = gtt_read(0x42004);
342 reg32 |= (1 << 14) | (1 << 15);
343 gtt_write(0x42004, reg32);
344 }
345
346 if (bridge_silicon_revision() >= IVB_STEP_A0) {
347 /* Display Reset Acknowledge Settings */
348 reg32 = gtt_read(0x45010);
349 reg32 |= (1 << 1) | (1 << 0);
350 gtt_write(0x45010, reg32);
351 }
352
353 /* 2: Get GT SKU from GTT+0x911c[13] */
354 reg32 = gtt_read(0x911c);
355 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
356 if (reg32 & (1 << 13)) {
357 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
358 gtt_write_powermeter(snb_pm_gt1);
359 } else {
360 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
361 gtt_write_powermeter(snb_pm_gt2);
362 }
363 } else {
364 u32 unit = MCHBAR32(0x5938) & 0xf;
365
366 if (reg32 & (1 << 13)) {
367 /* GT1 SKU */
368 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
369 gtt_write_powermeter(ivb_pm_gt1);
370 } else {
371 /* GT2 SKU */
372 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
373 tdp /= (1 << unit);
374
375 if (tdp <= 17) {
376 /* <=17W ULV */
377 printk(BIOS_DEBUG, "IVB GT2 17W "
378 "Power Meter Weights\n");
379 gtt_write_powermeter(ivb_pm_gt2_17w);
380 } else if ((tdp >= 25) && (tdp <= 35)) {
381 /* 25W-35W */
382 printk(BIOS_DEBUG, "IVB GT2 25W-35W "
383 "Power Meter Weights\n");
384 gtt_write_powermeter(ivb_pm_gt2_35w);
385 } else {
386 /* All others */
387 printk(BIOS_DEBUG, "IVB GT2 35W "
388 "Power Meter Weights\n");
389 gtt_write_powermeter(ivb_pm_gt2_35w);
390 }
391 }
392 }
393
394 /* 3: Gear ratio map */
395 gtt_write(0xa004, 0x00000010);
396
397 /* 4: GFXPAUSE */
398 gtt_write(0xa000, 0x00070020);
399
400 /* 5: Dynamic EU trip control */
401 gtt_write(0xa080, 0x00000004);
402
403 /* 6: ECO bits */
404 reg32 = gtt_read(0xa180);
405 reg32 |= (1 << 26) | (1 << 31);
406 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
407 if (bridge_silicon_revision() >= SNB_STEP_D1)
408 reg32 |= (1 << 20);
409 gtt_write(0xa180, reg32);
410
411 /* 6a: for SnB step D2+ only */
412 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
413 (bridge_silicon_revision() >= SNB_STEP_D2)) {
414 reg32 = gtt_read(0x9400);
415 reg32 |= (1 << 7);
416 gtt_write(0x9400, reg32);
417
418 reg32 = gtt_read(0x941c);
419 reg32 &= 0xf;
420 reg32 |= (1 << 1);
421 gtt_write(0x941c, reg32);
422 gtt_poll(0x941c, (1 << 1), (0 << 1));
423 }
424
425 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
426 reg32 = gtt_read(0x907c);
427 reg32 |= (1 << 16);
428 gtt_write(0x907c, reg32);
429
430 /* 6b: Clocking reset controls */
431 gtt_write(0x9424, 0x00000001);
432 } else {
433 /* 6b: Clocking reset controls */
434 gtt_write(0x9424, 0x00000000);
435 }
436
437 /* 7 */
438 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
439 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
440 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
441 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
442 gtt_write(0x138124, 0x8000000a);
443 gtt_poll(0x138124, (1 << 31), (0 << 31));
444 }
445
446 /* 8 */
447 gtt_write(0xa090, 0x00000000); /* RC Control */
448 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
449 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
450 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
451 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
452 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
453
454 /* 9 */
455 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
456 gtt_write(0x12054, 0x0000000a); /* Video Idle Max Count */
457 gtt_write(0x22054, 0x0000000a); /* Blitter Idle Max Count */
458
459 /* 10 */
460 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
461 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
462 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
463 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
464 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
465
466 /* 11 */
467 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
468 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
469 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
470 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
471 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
472 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
473 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
474
475 /* 11a: Enable Render Standby (RC6) */
476 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
477 /*
478 * IvyBridge should also support DeepRenderStandby.
479 *
480 * Unfortunately it does not work reliably on all SKUs so
481 * disable it here and it can be enabled by the kernel.
482 */
483 gtt_write(0xa090, 0x88040000); /* HW RC Control */
484 } else {
485 gtt_write(0xa090, 0x88040000); /* HW RC Control */
486 }
487
488 /* 12: Normal Frequency Request */
Felix Held6b6c94b2017-11-25 00:45:23 +0100489 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 */
490 /* only the lower 7 bits are used and shifted left by 25 */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100491 reg32 = MCHBAR32(0x5998);
492 reg32 >>= 16;
Felix Held6b6c94b2017-11-25 00:45:23 +0100493 reg32 &= 0x7f;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100494 reg32 <<= 25;
495 gtt_write(0xa008, reg32);
496
497 /* 13: RP Control */
498 gtt_write(0xa024, 0x00000592);
499
500 /* 14: Enable PM Interrupts */
501 gtt_write(0x4402c, 0x03000076);
502
503 /* Clear 0x6c024 [8:6] */
504 reg32 = gtt_read(0x6c024);
505 reg32 &= ~0x000001c0;
506 gtt_write(0x6c024, reg32);
507}
508
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100509static void gma_pm_init_post_vbios(struct device *dev)
510{
511 struct northbridge_intel_nehalem_config *conf = dev->chip_info;
512 u32 reg32;
513
514 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
515
516 /* 15: Deassert Force Wake */
517 if (bridge_silicon_revision() < IVB_STEP_C0) {
518 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
519 gtt_poll(0x130090, (1 << 0), (0 << 0));
520 } else {
521 gtt_write(0xa188, 0x1fffe);
522 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
523 gtt_write(0xa188, gtt_read(0xa188) | 1);
524 }
525
526 /* 16: SW RC Control */
527 gtt_write(0xa094, 0x00060000);
528
529 /* Setup Digital Port Hotplug */
530 reg32 = gtt_read(0xc4030);
531 if (!reg32) {
532 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
533 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
534 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
535 gtt_write(0xc4030, reg32);
536 }
537
538 /* Setup Panel Power On Delays */
539 reg32 = gtt_read(0xc7208);
540 if (!reg32) {
541 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
542 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
543 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
544 gtt_write(0xc7208, reg32);
545 }
546
547 /* Setup Panel Power Off Delays */
548 reg32 = gtt_read(0xc720c);
549 if (!reg32) {
550 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
551 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
552 gtt_write(0xc720c, reg32);
553 }
554
555 /* Setup Panel Power Cycle Delay */
556 if (conf->gpu_panel_power_cycle_delay) {
557 reg32 = gtt_read(0xc7210);
558 reg32 &= ~0xff;
559 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
560 gtt_write(0xc7210, reg32);
561 }
562
563 /* Enable Backlight if needed */
564 if (conf->gpu_cpu_backlight) {
565 gtt_write(0x48250, (1 << 31));
566 gtt_write(0x48254, conf->gpu_cpu_backlight);
567 }
568 if (conf->gpu_pch_backlight) {
569 gtt_write(0xc8250, (1 << 31));
570 gtt_write(0xc8254, conf->gpu_pch_backlight);
571 }
572}
573
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200574/* Enable SCI to ACPI _GPE._L06 */
575static void gma_enable_swsci(void)
576{
577 u16 reg16;
578
579 /* clear DMISCI status */
580 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
581 reg16 &= DMISCI_STS;
582 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
583
584 /* clear acpi tco status */
585 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
586
587 /* enable acpi tco scis */
588 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
589 reg16 |= TCOSCI_EN;
590 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
591}
592
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100593static void gma_func0_init(struct device *dev)
594{
595 u32 reg32;
596
597 /* IGD needs to be Bus Master */
598 reg32 = pci_read_config32(dev, PCI_COMMAND);
599 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
600 pci_write_config32(dev, PCI_COMMAND, reg32);
601
602 /* Init graphics power management */
603 gma_pm_init_pre_vbios(dev);
604
Julius Wernercd49cce2019-03-05 16:53:33 -0800605 if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200606 struct northbridge_intel_nehalem_config *conf = dev->chip_info;
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200607 int lightup_ok;
608 printk(BIOS_SPEW, "Initializing VGA without OPROM.");
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100609
Arthur Heymans4c2f26c2018-07-17 16:59:38 +0200610 gma_gfxinit(&lightup_ok);
Nico Huberd4ebeaf2017-05-22 13:49:22 +0200611 /* Linux relies on VBT for panel info. */
612 generate_fake_intel_oprom(&conf->gfx, dev,
613 "$VBT IRONLAKE-MOBILE");
614 } else {
615 /* PCI Init, will run VBIOS */
616 pci_dev_init(dev);
Vladimir Serbinenko13157302014-02-19 22:18:08 +0100617 }
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100618
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100619 /* Post VBIOS init */
620 gma_pm_init_post_vbios(dev);
Patrick Rudolph64a702f2017-06-20 18:28:56 +0200621
622 gma_enable_swsci();
623 intel_gma_restore_opregion();
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100624}
625
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100626static void gma_read_resources(struct device *dev)
627{
628 pci_dev_read_resources(dev);
629
630 struct resource *res;
631
632 /* Set the graphics memory to write combining. */
633 res = find_resource(dev, PCI_BASE_ADDRESS_2);
634 if (res == NULL) {
635 printk(BIOS_DEBUG, "gma: memory resource not found.\n");
636 return;
637 }
638 res->flags |= IORESOURCE_RESERVE | IORESOURCE_FIXED | IORESOURCE_ASSIGNED;
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200639 pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001);
640 pci_write_config32(dev, PCI_BASE_ADDRESS_2 + 4, 0);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100641 res->base = (resource_t) 0xd0000000;
642 res->size = (resource_t) 0x10000000;
643}
644
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100645const struct i915_gpu_controller_info *
646intel_gma_get_controller_info(void)
647{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300648 struct device *dev = pcidev_on_root(0x2, 0);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100649 if (!dev) {
650 return NULL;
651 }
652 struct northbridge_intel_nehalem_config *chip = dev->chip_info;
653 return &chip->gfx;
654}
655
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100656static void gma_ssdt(struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100657{
658 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
659 if (!gfx) {
660 return;
661 }
662
663 drivers_intel_gma_displays_ssdt_generate(gfx);
664}
665
Patrick Rudolph2be28402017-04-12 16:54:55 +0200666static unsigned long
667gma_write_acpi_tables(struct device *const dev,
668 unsigned long current,
669 struct acpi_rsdp *const rsdp)
670{
Patrick Rudolph5c820262017-05-17 19:39:12 +0200671 igd_opregion_t *opregion = (igd_opregion_t *)current;
Patrick Rudolph2be28402017-04-12 16:54:55 +0200672 global_nvs_t *gnvs;
673
Matt DeVillierebe08e02017-07-14 13:28:42 -0500674 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolph5c820262017-05-17 19:39:12 +0200675 return current;
676
677 current += sizeof(igd_opregion_t);
678
679 /* GNVS has been already set up */
680 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
681 if (gnvs) {
682 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200683 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Patrick Rudolph5c820262017-05-17 19:39:12 +0200684 } else {
685 printk(BIOS_ERR, "Error: GNVS table not found.\n");
Patrick Rudolph2be28402017-04-12 16:54:55 +0200686 }
687
Patrick Rudolph5c820262017-05-17 19:39:12 +0200688 current = acpi_align_current(current);
Patrick Rudolph2be28402017-04-12 16:54:55 +0200689 return current;
690}
691
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100692static struct pci_operations gma_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530693 .set_subsystem = pci_dev_set_subsystem,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100694};
695
696static struct device_operations gma_func0_ops = {
697 .read_resources = gma_read_resources,
698 .set_resources = pci_dev_set_resources,
699 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100700 .acpi_fill_ssdt_generator = gma_ssdt,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100701 .init = gma_func0_init,
702 .scan_bus = 0,
703 .enable = 0,
704 .ops_pci = &gma_pci_ops,
Patrick Rudolph2be28402017-04-12 16:54:55 +0200705 .write_acpi_tables = gma_write_acpi_tables,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100706};
707
Elyes HAOUAScf5430f2016-09-13 21:27:22 +0200708static const unsigned short pci_device_ids[] = {
709 0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100710 0x0116, 0x0122, 0x0126, 0x0156,
711 0x0166,
712 0
713};
714
715static const struct pci_driver gma __pci_driver = {
716 .ops = &gma_func0_ops,
717 .vendor = PCI_VENDOR_ID_INTEL,
718 .devices = pci_device_ids,
719};