blob: 1680b1e2a1694aa890fdef64d74c942e1bdc7290 [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Stefan Reinauer00636b02012-04-04 00:08:51 +02003
4#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02005#include <device/mmio.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02006#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +02007#include <bootmode.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02008#include <delay.h>
9#include <device/device.h>
10#include <device/pci.h>
11#include <device/pci_ids.h>
Ronald G. Minnich69efaa02013-02-26 10:07:40 -080012#include <device/pci_ops.h>
Nico Huber18228162017-06-08 16:31:57 +020013#include <drivers/intel/gma/libgfxinit.h>
Patrick Rudolph281ccca2017-04-12 16:55:32 +020014#include <southbridge/intel/bd82x6x/nvs.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050015#include <drivers/intel/gma/opregion.h>
Patrick Rudolphda9302a2019-03-24 17:01:41 +010016#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolph281ccca2017-04-12 16:55:32 +020017#include <cbmem.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020018#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020019
20#include "chip.h"
21#include "sandybridge.h"
Patrick Rudolph45a0dbc2017-03-30 17:07:42 +020022#include "gma.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020023
Duncan Lauriedd585b82012-04-09 12:05:18 -070024struct gt_powermeter {
25 u16 reg;
26 u32 value;
27};
28
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070029static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070030 { 0xa200, 0xcc000000 },
31 { 0xa204, 0x07000040 },
32 { 0xa208, 0x0000fe00 },
33 { 0xa20c, 0x00000000 },
34 { 0xa210, 0x17000000 },
35 { 0xa214, 0x00000021 },
36 { 0xa218, 0x0817fe19 },
37 { 0xa21c, 0x00000000 },
38 { 0xa220, 0x00000000 },
39 { 0xa224, 0xcc000000 },
40 { 0xa228, 0x07000040 },
41 { 0xa22c, 0x0000fe00 },
42 { 0xa230, 0x00000000 },
43 { 0xa234, 0x17000000 },
44 { 0xa238, 0x00000021 },
45 { 0xa23c, 0x0817fe19 },
46 { 0xa240, 0x00000000 },
47 { 0xa244, 0x00000000 },
48 { 0xa248, 0x8000421e },
Angel Pons7c49cb82020-03-16 23:17:32 +010049 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -070050};
51
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070052static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070053 { 0xa200, 0x330000a6 },
54 { 0xa204, 0x402d0031 },
55 { 0xa208, 0x00165f83 },
56 { 0xa20c, 0xf1000000 },
57 { 0xa210, 0x00000000 },
58 { 0xa214, 0x00160016 },
59 { 0xa218, 0x002a002b },
60 { 0xa21c, 0x00000000 },
61 { 0xa220, 0x00000000 },
62 { 0xa224, 0x330000a6 },
63 { 0xa228, 0x402d0031 },
64 { 0xa22c, 0x00165f83 },
65 { 0xa230, 0xf1000000 },
66 { 0xa234, 0x00000000 },
67 { 0xa238, 0x00160016 },
68 { 0xa23c, 0x002a002b },
69 { 0xa240, 0x00000000 },
70 { 0xa244, 0x00000000 },
71 { 0xa248, 0x8000421e },
Angel Pons7c49cb82020-03-16 23:17:32 +010072 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -070073};
74
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070075static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070076 { 0xa800, 0x00000000 },
77 { 0xa804, 0x00021c00 },
78 { 0xa808, 0x00000403 },
79 { 0xa80c, 0x02001700 },
80 { 0xa810, 0x05000200 },
81 { 0xa814, 0x00000000 },
82 { 0xa818, 0x00690500 },
83 { 0xa81c, 0x0000007f },
84 { 0xa820, 0x01002501 },
85 { 0xa824, 0x00000300 },
86 { 0xa828, 0x01000331 },
87 { 0xa82c, 0x0000000c },
88 { 0xa830, 0x00010016 },
89 { 0xa834, 0x01100101 },
90 { 0xa838, 0x00010103 },
91 { 0xa83c, 0x00041300 },
92 { 0xa840, 0x00000b30 },
93 { 0xa844, 0x00000000 },
94 { 0xa848, 0x7f000000 },
95 { 0xa84c, 0x05000008 },
96 { 0xa850, 0x00000001 },
97 { 0xa854, 0x00000004 },
98 { 0xa858, 0x00000007 },
99 { 0xa85c, 0x00000000 },
100 { 0xa860, 0x00010000 },
101 { 0xa248, 0x0000221e },
102 { 0xa900, 0x00000000 },
103 { 0xa904, 0x00001c00 },
104 { 0xa908, 0x00000000 },
105 { 0xa90c, 0x06000000 },
106 { 0xa910, 0x09000200 },
107 { 0xa914, 0x00000000 },
108 { 0xa918, 0x00590000 },
109 { 0xa91c, 0x00000000 },
110 { 0xa920, 0x04002501 },
111 { 0xa924, 0x00000100 },
112 { 0xa928, 0x03000410 },
113 { 0xa92c, 0x00000000 },
114 { 0xa930, 0x00020000 },
115 { 0xa934, 0x02070106 },
116 { 0xa938, 0x00010100 },
117 { 0xa93c, 0x00401c00 },
118 { 0xa940, 0x00000000 },
119 { 0xa944, 0x00000000 },
120 { 0xa948, 0x10000e00 },
121 { 0xa94c, 0x02000004 },
122 { 0xa950, 0x00000001 },
123 { 0xa954, 0x00000004 },
124 { 0xa960, 0x00060000 },
125 { 0xaa3c, 0x00001c00 },
126 { 0xaa54, 0x00000004 },
127 { 0xaa60, 0x00060000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100128 { 0 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700129};
130
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700131static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700132 { 0xa800, 0x20000000 },
133 { 0xa804, 0x000e3800 },
134 { 0xa808, 0x00000806 },
135 { 0xa80c, 0x0c002f00 },
136 { 0xa810, 0x0c000800 },
137 { 0xa814, 0x00000000 },
138 { 0xa818, 0x00d20d00 },
139 { 0xa81c, 0x000000ff },
140 { 0xa820, 0x03004b02 },
141 { 0xa824, 0x00000600 },
142 { 0xa828, 0x07000773 },
143 { 0xa82c, 0x00000000 },
144 { 0xa830, 0x00020032 },
145 { 0xa834, 0x1520040d },
146 { 0xa838, 0x00020105 },
147 { 0xa83c, 0x00083700 },
148 { 0xa840, 0x000016ff },
149 { 0xa844, 0x00000000 },
150 { 0xa848, 0xff000000 },
151 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700152 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700153 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700154 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700155 { 0xa85c, 0x00000000 },
156 { 0xa860, 0x00020000 },
157 { 0xa248, 0x0000221e },
158 { 0xa900, 0x00000000 },
159 { 0xa904, 0x00003800 },
160 { 0xa908, 0x00000000 },
161 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700162 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700163 { 0xa914, 0x00000000 },
164 { 0xa918, 0x00b20000 },
165 { 0xa91c, 0x00000000 },
166 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700167 { 0xa924, 0x00000300 },
168 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700169 { 0xa92c, 0x00000000 },
170 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700171 { 0xa934, 0x15150406 },
172 { 0xa938, 0x00020300 },
173 { 0xa93c, 0x00903900 },
174 { 0xa940, 0x00000000 },
175 { 0xa944, 0x00000000 },
176 { 0xa948, 0x20001b00 },
177 { 0xa94c, 0x0a000010 },
178 { 0xa950, 0x00000000 },
179 { 0xa954, 0x00000008 },
180 { 0xa960, 0x00110000 },
181 { 0xaa3c, 0x00003900 },
182 { 0xaa54, 0x00000008 },
183 { 0xaa60, 0x00110000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100184 { 0 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700185};
186
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700187static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700188 { 0xa800, 0x00000000 },
189 { 0xa804, 0x00030400 },
190 { 0xa808, 0x00000806 },
191 { 0xa80c, 0x0c002f00 },
192 { 0xa810, 0x0c000300 },
193 { 0xa814, 0x00000000 },
194 { 0xa818, 0x00d20d00 },
195 { 0xa81c, 0x000000ff },
196 { 0xa820, 0x03004b02 },
197 { 0xa824, 0x00000600 },
198 { 0xa828, 0x07000773 },
199 { 0xa82c, 0x00000000 },
200 { 0xa830, 0x00020032 },
201 { 0xa834, 0x1520040d },
202 { 0xa838, 0x00020105 },
203 { 0xa83c, 0x00083700 },
204 { 0xa840, 0x000016ff },
205 { 0xa844, 0x00000000 },
206 { 0xa848, 0xff000000 },
207 { 0xa84c, 0x0a000010 },
208 { 0xa850, 0x00000001 },
209 { 0xa854, 0x00000008 },
210 { 0xa858, 0x00000008 },
211 { 0xa85c, 0x00000000 },
212 { 0xa860, 0x00020000 },
213 { 0xa248, 0x0000221e },
214 { 0xa900, 0x00000000 },
215 { 0xa904, 0x00003800 },
216 { 0xa908, 0x00000000 },
217 { 0xa90c, 0x0c000000 },
218 { 0xa910, 0x12000800 },
219 { 0xa914, 0x00000000 },
220 { 0xa918, 0x00b20000 },
221 { 0xa91c, 0x00000000 },
222 { 0xa920, 0x08004b02 },
223 { 0xa924, 0x00000300 },
224 { 0xa928, 0x01000820 },
225 { 0xa92c, 0x00000000 },
226 { 0xa930, 0x00030000 },
227 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700228 { 0xa938, 0x00020300 },
229 { 0xa93c, 0x00903900 },
230 { 0xa940, 0x00000000 },
231 { 0xa944, 0x00000000 },
232 { 0xa948, 0x20001b00 },
233 { 0xa94c, 0x0a000010 },
234 { 0xa950, 0x00000000 },
235 { 0xa954, 0x00000008 },
236 { 0xa960, 0x00110000 },
237 { 0xaa3c, 0x00003900 },
238 { 0xaa54, 0x00000008 },
239 { 0xaa60, 0x00110000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100240 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700241};
242
Angel Pons7c49cb82020-03-16 23:17:32 +0100243/*
244 * Some VGA option roms are used for several chipsets but they only have one PCI ID in their
245 * header. If we encounter such an option rom, we need to do the mapping ourselves.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200246 */
247
248u32 map_oprom_vendev(u32 vendev)
249{
Nico Huber23b93dd2017-07-29 01:46:23 +0200250 u32 new_vendev = vendev;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200251
252 switch (vendev) {
Nico Huber23b93dd2017-07-29 01:46:23 +0200253 case 0x80860102: /* SNB GT1 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100254 case 0x8086010a: /* SNB GT1 Server */
Nico Huber23b93dd2017-07-29 01:46:23 +0200255 case 0x80860112: /* SNB GT2 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100256 case 0x80860116: /* SNB GT2 Mobile */
Nico Huber23b93dd2017-07-29 01:46:23 +0200257 case 0x80860122: /* SNB GT2 Desktop >=1.3GHz */
Angel Pons7c49cb82020-03-16 23:17:32 +0100258 case 0x80860126: /* SNB GT2 Mobile >=1.3GHz */
Nico Huber23b93dd2017-07-29 01:46:23 +0200259 case 0x80860152: /* IVB GT1 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100260 case 0x80860156: /* IVB GT1 Mobile */
Nico Huber23b93dd2017-07-29 01:46:23 +0200261 case 0x80860162: /* IVB GT2 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100262 case 0x80860166: /* IVB GT2 Mobile */
263 case 0x8086016a: /* IVB GT2 Server */
264 new_vendev = 0x80860106;/* SNB GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200265 break;
266 }
267
268 return new_vendev;
269}
270
271static struct resource *gtt_res = NULL;
272
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200273u32 gtt_read(u32 reg)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200274{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800275 return read32(res2mmio(gtt_res, reg, 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200276}
277
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200278void gtt_write(u32 reg, u32 data)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200279{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800280 write32(res2mmio(gtt_res, reg, 0), data);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200281}
282
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700283static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700284{
285 for (; pm && pm->reg; pm++)
286 gtt_write(pm->reg, pm->value);
287}
288
Stefan Reinauer00636b02012-04-04 00:08:51 +0200289#define GTT_RETRY 1000
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200290int gtt_poll(u32 reg, u32 mask, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200291{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530292 unsigned int try = GTT_RETRY;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200293 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
Stefan Reinauer00636b02012-04-04 00:08:51 +0200319static 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);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700332 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200333 } else {
334 gtt_write(0xa180, 1 << 5);
335 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700336 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200337 }
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 */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200348 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] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700354 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200355 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200356 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700357 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
358 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200359 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700360 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
361 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200362 }
363 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700364 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700365
Duncan Laurie8508cff2012-04-12 16:02:43 -0700366 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700367 /* GT1 SKU */
368 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
369 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700370 } else {
371 /* GT2 SKU */
372 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
373 tdp /= (1 << unit);
374
375 if (tdp <= 17) {
376 /* <=17W ULV */
Angel Pons7c49cb82020-03-16 23:17:32 +0100377 printk(BIOS_DEBUG, "IVB GT2 17W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700378 gtt_write_powermeter(ivb_pm_gt2_17w);
379 } else if ((tdp >= 25) && (tdp <= 35)) {
380 /* 25W-35W */
Angel Pons7c49cb82020-03-16 23:17:32 +0100381 printk(BIOS_DEBUG, "IVB GT2 25W-35W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700382 gtt_write_powermeter(ivb_pm_gt2_35w);
383 } else {
384 /* All others */
Angel Pons7c49cb82020-03-16 23:17:32 +0100385 printk(BIOS_DEBUG, "IVB GT2 35W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700386 gtt_write_powermeter(ivb_pm_gt2_35w);
387 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700388 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200389 }
390
391 /* 3: Gear ratio map */
392 gtt_write(0xa004, 0x00000010);
393
394 /* 4: GFXPAUSE */
395 gtt_write(0xa000, 0x00070020);
396
397 /* 5: Dynamic EU trip control */
398 gtt_write(0xa080, 0x00000004);
399
400 /* 6: ECO bits */
401 reg32 = gtt_read(0xa180);
402 reg32 |= (1 << 26) | (1 << 31);
403 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
404 if (bridge_silicon_revision() >= SNB_STEP_D1)
405 reg32 |= (1 << 20);
406 gtt_write(0xa180, reg32);
407
408 /* 6a: for SnB step D2+ only */
409 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
410 (bridge_silicon_revision() >= SNB_STEP_D2)) {
411 reg32 = gtt_read(0x9400);
412 reg32 |= (1 << 7);
413 gtt_write(0x9400, reg32);
414
415 reg32 = gtt_read(0x941c);
416 reg32 &= 0xf;
417 reg32 |= (1 << 1);
418 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700419 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200420 }
421
422 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
423 reg32 = gtt_read(0x907c);
424 reg32 |= (1 << 16);
425 gtt_write(0x907c, reg32);
426
427 /* 6b: Clocking reset controls */
428 gtt_write(0x9424, 0x00000001);
429 } else {
430 /* 6b: Clocking reset controls */
431 gtt_write(0x9424, 0x00000000);
432 }
433
434 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700435 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
436 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
437 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
438 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
439 gtt_write(0x138124, 0x8000000a);
440 gtt_poll(0x138124, (1 << 31), (0 << 31));
441 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200442
443 /* 8 */
444 gtt_write(0xa090, 0x00000000); /* RC Control */
445 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
446 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
447 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
448 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
449 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
450
451 /* 9 */
452 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
453 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
454 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
455
456 /* 10 */
457 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
458 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
459 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
460 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
461 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
462
463 /* 11 */
464 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
465 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
466 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
467 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
468 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
469 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
470 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
471
472 /* 11a: Enable Render Standby (RC6) */
473 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700474 /*
475 * IvyBridge should also support DeepRenderStandby.
476 *
477 * Unfortunately it does not work reliably on all SKUs so
478 * disable it here and it can be enabled by the kernel.
479 */
480 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200481 } else {
482 gtt_write(0xa090, 0x88040000); /* HW RC Control */
483 }
484
485 /* 12: Normal Frequency Request */
Felix Held6b6c94b2017-11-25 00:45:23 +0100486 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 */
487 /* only the lower 7 bits are used and shifted left by 25 */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200488 reg32 = MCHBAR32(0x5998);
489 reg32 >>= 16;
Felix Held6b6c94b2017-11-25 00:45:23 +0100490 reg32 &= 0x7f;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200491 reg32 <<= 25;
492 gtt_write(0xa008, reg32);
493
494 /* 13: RP Control */
495 gtt_write(0xa024, 0x00000592);
496
497 /* 14: Enable PM Interrupts */
498 gtt_write(0x4402c, 0x03000076);
499
500 /* Clear 0x6c024 [8:6] */
501 reg32 = gtt_read(0x6c024);
502 reg32 &= ~0x000001c0;
503 gtt_write(0x6c024, reg32);
Nico Huber07e206a2016-10-19 15:20:17 +0200504
505 /* Initialize DP buffer translation with recommended defaults */
506 gtt_write(0xe4f00, 0x0100030c);
507 gtt_write(0xe4f04, 0x00b8230c);
508 gtt_write(0xe4f08, 0x06f8930c);
509 gtt_write(0xe4f0c, 0x05f8e38e);
510 gtt_write(0xe4f10, 0x00b8030c);
511 gtt_write(0xe4f14, 0x0b78830c);
512 gtt_write(0xe4f18, 0x09f8d3cf);
513 gtt_write(0xe4f1c, 0x01e8030c);
514 gtt_write(0xe4f20, 0x09f863cf);
515 gtt_write(0xe4f24, 0x0ff803cf);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200516}
517
518static void gma_pm_init_post_vbios(struct device *dev)
519{
520 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
521 u32 reg32;
522
523 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
524
525 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700526 if (bridge_silicon_revision() < IVB_STEP_C0) {
527 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700528 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700529 } else {
530 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700531 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
532 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700533 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200534
535 /* 16: SW RC Control */
536 gtt_write(0xa094, 0x00060000);
537
538 /* Setup Digital Port Hotplug */
539 reg32 = gtt_read(0xc4030);
540 if (!reg32) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100541 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200542 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
543 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
544 gtt_write(0xc4030, reg32);
545 }
546
547 /* Setup Panel Power On Delays */
548 reg32 = gtt_read(0xc7208);
549 if (!reg32) {
550 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
551 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
552 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
553 gtt_write(0xc7208, reg32);
554 }
555
556 /* Setup Panel Power Off Delays */
557 reg32 = gtt_read(0xc720c);
558 if (!reg32) {
559 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
560 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
561 gtt_write(0xc720c, reg32);
562 }
563
564 /* Setup Panel Power Cycle Delay */
565 if (conf->gpu_panel_power_cycle_delay) {
566 reg32 = gtt_read(0xc7210);
567 reg32 &= ~0xff;
568 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
569 gtt_write(0xc7210, reg32);
570 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700571
572 /* Enable Backlight if needed */
573 if (conf->gpu_cpu_backlight) {
574 gtt_write(0x48250, (1 << 31));
575 gtt_write(0x48254, conf->gpu_cpu_backlight);
576 }
577 if (conf->gpu_pch_backlight) {
578 gtt_write(0xc8250, (1 << 31));
579 gtt_write(0xc8254, conf->gpu_pch_backlight);
580 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200581}
582
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200583/* Enable SCI to ACPI _GPE._L06 */
584static void gma_enable_swsci(void)
585{
586 u16 reg16;
587
Angel Pons7c49cb82020-03-16 23:17:32 +0100588 /* Clear DMISCI status */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200589 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
590 reg16 &= DMISCI_STS;
591 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
592
Angel Pons7c49cb82020-03-16 23:17:32 +0100593 /* Clear ACPI TCO status */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200594 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
595
Angel Pons7c49cb82020-03-16 23:17:32 +0100596 /* Enable ACPI TCO SCIs */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200597 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
598 reg16 |= TCOSCI_EN;
599 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
600}
601
Stefan Reinauer00636b02012-04-04 00:08:51 +0200602static void gma_func0_init(struct device *dev)
603{
604 u32 reg32;
605
606 /* IGD needs to be Bus Master */
607 reg32 = pci_read_config32(dev, PCI_COMMAND);
608 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
609 pci_write_config32(dev, PCI_COMMAND, reg32);
610
611 /* Init graphics power management */
612 gma_pm_init_pre_vbios(dev);
613
Nico Huberd1b99d22019-05-30 15:11:42 +0200614 if (!CONFIG(MAINBOARD_USE_LIBGFXINIT))
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700615 /* PCI Init, will run VBIOS */
616 pci_dev_init(dev);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200617
618 /* Post VBIOS init */
619 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800620
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200621 int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1;
622
Patrick Rudolphde4a1a02017-06-20 19:13:33 +0200623 /* Running graphics init on S3 breaks Linux drm driver. */
624 if (!acpi_is_wakeup_s3() &&
Julius Wernercd49cce2019-03-05 16:53:33 -0800625 CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200626 if (vga_disable) {
627 printk(BIOS_INFO,
628 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
Nico Huber88c64872016-10-05 18:02:01 +0200629 } else {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200630 /* This should probably run before post VBIOS init. */
631 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200632 int lightup_ok;
Arthur Heymansa6be58f2018-07-18 16:43:43 +0200633 gma_gfxinit(&lightup_ok);
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200634 if (lightup_ok)
635 gfx_set_init_done(1);
Nico Huber88c64872016-10-05 18:02:01 +0200636 }
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700637 }
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200638
639 gma_enable_swsci();
640 intel_gma_restore_opregion();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200641}
642
Angel Pons7c49cb82020-03-16 23:17:32 +0100643const struct i915_gpu_controller_info *intel_gma_get_controller_info(void)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100644{
Angel Pons7c49cb82020-03-16 23:17:32 +0100645 struct device *dev = pcidev_on_root(2, 0);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100646 if (!dev) {
647 return NULL;
648 }
649 struct northbridge_intel_sandybridge_config *chip = dev->chip_info;
650 return &chip->gfx;
651}
652
Elyes HAOUASab8743c2018-02-09 08:21:40 +0100653static void gma_ssdt(struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100654{
655 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
656 if (!gfx) {
657 return;
658 }
659
660 drivers_intel_gma_displays_ssdt_generate(gfx);
661}
662
Angel Pons7c49cb82020-03-16 23:17:32 +0100663static unsigned long gma_write_acpi_tables(struct device *const dev, unsigned long current,
664 struct acpi_rsdp *const rsdp)
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200665{
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200666 igd_opregion_t *opregion = (igd_opregion_t *)current;
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200667 global_nvs_t *gnvs;
668
Matt DeVillierebe08e02017-07-14 13:28:42 -0500669 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200670 return current;
671
672 current += sizeof(igd_opregion_t);
673
674 /* GNVS has been already set up */
675 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
676 if (gnvs) {
677 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200678 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200679 } else {
680 printk(BIOS_ERR, "Error: GNVS table not found.\n");
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200681 }
682
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200683 current = acpi_align_current(current);
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200684 return current;
685}
686
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600687static const char *gma_acpi_name(const struct device *dev)
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200688{
689 return "GFX0";
690}
691
Angel Pons7c49cb82020-03-16 23:17:32 +0100692/* Called by PCI set_vga_bridge function */
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200693static void gma_func0_disable(struct device *dev)
694{
695 u16 reg16;
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300696 struct device *dev_host = pcidev_on_root(0, 0);
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200697
698 reg16 = pci_read_config16(dev_host, GGC);
Angel Pons7c49cb82020-03-16 23:17:32 +0100699 reg16 |= (1 << 1); /* Disable VGA decode */
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200700 pci_write_config16(dev_host, GGC, reg16);
701
702 dev->enabled = 0;
703}
704
Stefan Reinauer00636b02012-04-04 00:08:51 +0200705static struct pci_operations gma_pci_ops = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100706 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200707};
708
709static struct device_operations gma_func0_ops = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100710 .read_resources = pci_dev_read_resources,
711 .set_resources = pci_dev_set_resources,
712 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100713 .acpi_fill_ssdt_generator = gma_ssdt,
Angel Pons7c49cb82020-03-16 23:17:32 +0100714 .init = gma_func0_init,
715 .scan_bus = NULL,
716 .enable = NULL,
717 .disable = gma_func0_disable,
718 .ops_pci = &gma_pci_ops,
719 .acpi_name = gma_acpi_name,
720 .write_acpi_tables = gma_write_acpi_tables,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200721};
722
Angel Pons7c49cb82020-03-16 23:17:32 +0100723static const unsigned short pci_device_ids[] = {
724 0x0102, 0x0106, 0x010a, 0x0112,
725 0x0116, 0x0122, 0x0126, 0x0156,
726 0x0166, 0x0162, 0x016a, 0x0152,
727 0
728};
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800729
730static const struct pci_driver gma __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100731 .ops = &gma_func0_ops,
732 .vendor = PCI_VENDOR_ID_INTEL,
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800733 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200734};