blob: 9ff68d1e7df5c944fdf557ca9333ae0d44808616 [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer00636b02012-04-04 00:08:51 +02002
3#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02005#include <console/console.h>
Kyösti Mälkkiab56b3b2013-11-28 16:44:51 +02006#include <bootmode.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +02007#include <delay.h>
8#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
Ronald G. Minnich69efaa02013-02-26 10:07:40 -080011#include <device/pci_ops.h>
Nico Huber18228162017-06-08 16:31:57 +020012#include <drivers/intel/gma/libgfxinit.h>
Patrick Rudolph281ccca2017-04-12 16:55:32 +020013#include <southbridge/intel/bd82x6x/nvs.h>
Matt DeVillierebe08e02017-07-14 13:28:42 -050014#include <drivers/intel/gma/opregion.h>
Patrick Rudolphda9302a2019-03-24 17:01:41 +010015#include <southbridge/intel/bd82x6x/pch.h>
Patrick Rudolph281ccca2017-04-12 16:55:32 +020016#include <cbmem.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020017#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020018
19#include "chip.h"
20#include "sandybridge.h"
Patrick Rudolph45a0dbc2017-03-30 17:07:42 +020021#include "gma.h"
Stefan Reinauer00636b02012-04-04 00:08:51 +020022
Duncan Lauriedd585b82012-04-09 12:05:18 -070023struct gt_powermeter {
24 u16 reg;
25 u32 value;
26};
27
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070028static const struct gt_powermeter snb_pm_gt1[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070029 { 0xa200, 0xcc000000 },
30 { 0xa204, 0x07000040 },
31 { 0xa208, 0x0000fe00 },
32 { 0xa20c, 0x00000000 },
33 { 0xa210, 0x17000000 },
34 { 0xa214, 0x00000021 },
35 { 0xa218, 0x0817fe19 },
36 { 0xa21c, 0x00000000 },
37 { 0xa220, 0x00000000 },
38 { 0xa224, 0xcc000000 },
39 { 0xa228, 0x07000040 },
40 { 0xa22c, 0x0000fe00 },
41 { 0xa230, 0x00000000 },
42 { 0xa234, 0x17000000 },
43 { 0xa238, 0x00000021 },
44 { 0xa23c, 0x0817fe19 },
45 { 0xa240, 0x00000000 },
46 { 0xa244, 0x00000000 },
47 { 0xa248, 0x8000421e },
Angel Pons7c49cb82020-03-16 23:17:32 +010048 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -070049};
50
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070051static const struct gt_powermeter snb_pm_gt2[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -070052 { 0xa200, 0x330000a6 },
53 { 0xa204, 0x402d0031 },
54 { 0xa208, 0x00165f83 },
55 { 0xa20c, 0xf1000000 },
56 { 0xa210, 0x00000000 },
57 { 0xa214, 0x00160016 },
58 { 0xa218, 0x002a002b },
59 { 0xa21c, 0x00000000 },
60 { 0xa220, 0x00000000 },
61 { 0xa224, 0x330000a6 },
62 { 0xa228, 0x402d0031 },
63 { 0xa22c, 0x00165f83 },
64 { 0xa230, 0xf1000000 },
65 { 0xa234, 0x00000000 },
66 { 0xa238, 0x00160016 },
67 { 0xa23c, 0x002a002b },
68 { 0xa240, 0x00000000 },
69 { 0xa244, 0x00000000 },
70 { 0xa248, 0x8000421e },
Angel Pons7c49cb82020-03-16 23:17:32 +010071 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -070072};
73
Stefan Reinauer4c8027a2012-09-07 10:53:56 -070074static const struct gt_powermeter ivb_pm_gt1[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -070075 { 0xa800, 0x00000000 },
76 { 0xa804, 0x00021c00 },
77 { 0xa808, 0x00000403 },
78 { 0xa80c, 0x02001700 },
79 { 0xa810, 0x05000200 },
80 { 0xa814, 0x00000000 },
81 { 0xa818, 0x00690500 },
82 { 0xa81c, 0x0000007f },
83 { 0xa820, 0x01002501 },
84 { 0xa824, 0x00000300 },
85 { 0xa828, 0x01000331 },
86 { 0xa82c, 0x0000000c },
87 { 0xa830, 0x00010016 },
88 { 0xa834, 0x01100101 },
89 { 0xa838, 0x00010103 },
90 { 0xa83c, 0x00041300 },
91 { 0xa840, 0x00000b30 },
92 { 0xa844, 0x00000000 },
93 { 0xa848, 0x7f000000 },
94 { 0xa84c, 0x05000008 },
95 { 0xa850, 0x00000001 },
96 { 0xa854, 0x00000004 },
97 { 0xa858, 0x00000007 },
98 { 0xa85c, 0x00000000 },
99 { 0xa860, 0x00010000 },
100 { 0xa248, 0x0000221e },
101 { 0xa900, 0x00000000 },
102 { 0xa904, 0x00001c00 },
103 { 0xa908, 0x00000000 },
104 { 0xa90c, 0x06000000 },
105 { 0xa910, 0x09000200 },
106 { 0xa914, 0x00000000 },
107 { 0xa918, 0x00590000 },
108 { 0xa91c, 0x00000000 },
109 { 0xa920, 0x04002501 },
110 { 0xa924, 0x00000100 },
111 { 0xa928, 0x03000410 },
112 { 0xa92c, 0x00000000 },
113 { 0xa930, 0x00020000 },
114 { 0xa934, 0x02070106 },
115 { 0xa938, 0x00010100 },
116 { 0xa93c, 0x00401c00 },
117 { 0xa940, 0x00000000 },
118 { 0xa944, 0x00000000 },
119 { 0xa948, 0x10000e00 },
120 { 0xa94c, 0x02000004 },
121 { 0xa950, 0x00000001 },
122 { 0xa954, 0x00000004 },
123 { 0xa960, 0x00060000 },
124 { 0xaa3c, 0x00001c00 },
125 { 0xaa54, 0x00000004 },
126 { 0xaa60, 0x00060000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100127 { 0 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700128};
129
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700130static const struct gt_powermeter ivb_pm_gt2_17w[] = {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700131 { 0xa800, 0x20000000 },
132 { 0xa804, 0x000e3800 },
133 { 0xa808, 0x00000806 },
134 { 0xa80c, 0x0c002f00 },
135 { 0xa810, 0x0c000800 },
136 { 0xa814, 0x00000000 },
137 { 0xa818, 0x00d20d00 },
138 { 0xa81c, 0x000000ff },
139 { 0xa820, 0x03004b02 },
140 { 0xa824, 0x00000600 },
141 { 0xa828, 0x07000773 },
142 { 0xa82c, 0x00000000 },
143 { 0xa830, 0x00020032 },
144 { 0xa834, 0x1520040d },
145 { 0xa838, 0x00020105 },
146 { 0xa83c, 0x00083700 },
147 { 0xa840, 0x000016ff },
148 { 0xa844, 0x00000000 },
149 { 0xa848, 0xff000000 },
150 { 0xa84c, 0x0a000010 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700151 { 0xa850, 0x00000002 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700152 { 0xa854, 0x00000008 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700153 { 0xa858, 0x0000000f },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700154 { 0xa85c, 0x00000000 },
155 { 0xa860, 0x00020000 },
156 { 0xa248, 0x0000221e },
157 { 0xa900, 0x00000000 },
158 { 0xa904, 0x00003800 },
159 { 0xa908, 0x00000000 },
160 { 0xa90c, 0x0c000000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700161 { 0xa910, 0x12000800 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700162 { 0xa914, 0x00000000 },
163 { 0xa918, 0x00b20000 },
164 { 0xa91c, 0x00000000 },
165 { 0xa920, 0x08004b02 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700166 { 0xa924, 0x00000300 },
167 { 0xa928, 0x01000820 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700168 { 0xa92c, 0x00000000 },
169 { 0xa930, 0x00030000 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700170 { 0xa934, 0x15150406 },
171 { 0xa938, 0x00020300 },
172 { 0xa93c, 0x00903900 },
173 { 0xa940, 0x00000000 },
174 { 0xa944, 0x00000000 },
175 { 0xa948, 0x20001b00 },
176 { 0xa94c, 0x0a000010 },
177 { 0xa950, 0x00000000 },
178 { 0xa954, 0x00000008 },
179 { 0xa960, 0x00110000 },
180 { 0xaa3c, 0x00003900 },
181 { 0xaa54, 0x00000008 },
182 { 0xaa60, 0x00110000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100183 { 0 },
Duncan Laurie8508cff2012-04-12 16:02:43 -0700184};
185
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700186static const struct gt_powermeter ivb_pm_gt2_35w[] = {
Duncan Laurie8508cff2012-04-12 16:02:43 -0700187 { 0xa800, 0x00000000 },
188 { 0xa804, 0x00030400 },
189 { 0xa808, 0x00000806 },
190 { 0xa80c, 0x0c002f00 },
191 { 0xa810, 0x0c000300 },
192 { 0xa814, 0x00000000 },
193 { 0xa818, 0x00d20d00 },
194 { 0xa81c, 0x000000ff },
195 { 0xa820, 0x03004b02 },
196 { 0xa824, 0x00000600 },
197 { 0xa828, 0x07000773 },
198 { 0xa82c, 0x00000000 },
199 { 0xa830, 0x00020032 },
200 { 0xa834, 0x1520040d },
201 { 0xa838, 0x00020105 },
202 { 0xa83c, 0x00083700 },
203 { 0xa840, 0x000016ff },
204 { 0xa844, 0x00000000 },
205 { 0xa848, 0xff000000 },
206 { 0xa84c, 0x0a000010 },
207 { 0xa850, 0x00000001 },
208 { 0xa854, 0x00000008 },
209 { 0xa858, 0x00000008 },
210 { 0xa85c, 0x00000000 },
211 { 0xa860, 0x00020000 },
212 { 0xa248, 0x0000221e },
213 { 0xa900, 0x00000000 },
214 { 0xa904, 0x00003800 },
215 { 0xa908, 0x00000000 },
216 { 0xa90c, 0x0c000000 },
217 { 0xa910, 0x12000800 },
218 { 0xa914, 0x00000000 },
219 { 0xa918, 0x00b20000 },
220 { 0xa91c, 0x00000000 },
221 { 0xa920, 0x08004b02 },
222 { 0xa924, 0x00000300 },
223 { 0xa928, 0x01000820 },
224 { 0xa92c, 0x00000000 },
225 { 0xa930, 0x00030000 },
226 { 0xa934, 0x15150406 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700227 { 0xa938, 0x00020300 },
228 { 0xa93c, 0x00903900 },
229 { 0xa940, 0x00000000 },
230 { 0xa944, 0x00000000 },
231 { 0xa948, 0x20001b00 },
232 { 0xa94c, 0x0a000010 },
233 { 0xa950, 0x00000000 },
234 { 0xa954, 0x00000008 },
235 { 0xa960, 0x00110000 },
236 { 0xaa3c, 0x00003900 },
237 { 0xaa54, 0x00000008 },
238 { 0xaa60, 0x00110000 },
Angel Pons7c49cb82020-03-16 23:17:32 +0100239 { 0 },
Duncan Lauriedd585b82012-04-09 12:05:18 -0700240};
241
Angel Pons7c49cb82020-03-16 23:17:32 +0100242/*
243 * Some VGA option roms are used for several chipsets but they only have one PCI ID in their
244 * header. If we encounter such an option rom, we need to do the mapping ourselves.
Stefan Reinauer00636b02012-04-04 00:08:51 +0200245 */
246
247u32 map_oprom_vendev(u32 vendev)
248{
Nico Huber23b93dd2017-07-29 01:46:23 +0200249 u32 new_vendev = vendev;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200250
251 switch (vendev) {
Nico Huber23b93dd2017-07-29 01:46:23 +0200252 case 0x80860102: /* SNB GT1 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100253 case 0x8086010a: /* SNB GT1 Server */
Nico Huber23b93dd2017-07-29 01:46:23 +0200254 case 0x80860112: /* SNB GT2 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100255 case 0x80860116: /* SNB GT2 Mobile */
Nico Huber23b93dd2017-07-29 01:46:23 +0200256 case 0x80860122: /* SNB GT2 Desktop >=1.3GHz */
Angel Pons7c49cb82020-03-16 23:17:32 +0100257 case 0x80860126: /* SNB GT2 Mobile >=1.3GHz */
Nico Huber23b93dd2017-07-29 01:46:23 +0200258 case 0x80860152: /* IVB GT1 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100259 case 0x80860156: /* IVB GT1 Mobile */
Nico Huber23b93dd2017-07-29 01:46:23 +0200260 case 0x80860162: /* IVB GT2 Desktop */
Angel Pons7c49cb82020-03-16 23:17:32 +0100261 case 0x80860166: /* IVB GT2 Mobile */
262 case 0x8086016a: /* IVB GT2 Server */
263 new_vendev = 0x80860106;/* SNB GT1 Mobile */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200264 break;
265 }
266
267 return new_vendev;
268}
269
270static struct resource *gtt_res = NULL;
271
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200272u32 gtt_read(u32 reg)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200273{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800274 return read32(res2mmio(gtt_res, reg, 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200275}
276
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200277void gtt_write(u32 reg, u32 data)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200278{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800279 write32(res2mmio(gtt_res, reg, 0), data);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200280}
281
Stefan Reinauer4c8027a2012-09-07 10:53:56 -0700282static inline void gtt_write_powermeter(const struct gt_powermeter *pm)
Duncan Lauriedd585b82012-04-09 12:05:18 -0700283{
284 for (; pm && pm->reg; pm++)
285 gtt_write(pm->reg, pm->value);
286}
287
Stefan Reinauer00636b02012-04-04 00:08:51 +0200288#define GTT_RETRY 1000
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +0200289int gtt_poll(u32 reg, u32 mask, u32 value)
Stefan Reinauer00636b02012-04-04 00:08:51 +0200290{
Subrata Banikb1434fc2019-03-15 22:20:41 +0530291 unsigned int try = GTT_RETRY;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200292 u32 data;
293
294 while (try--) {
295 data = gtt_read(reg);
296 if ((data & mask) == value)
297 return 1;
298 udelay(10);
299 }
300
301 printk(BIOS_ERR, "GT init timeout\n");
302 return 0;
303}
304
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200305uintptr_t gma_get_gnvs_aslb(const void *gnvs)
306{
307 const global_nvs_t *gnvs_ptr = gnvs;
308 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
309}
310
311void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
312{
313 global_nvs_t *gnvs_ptr = gnvs;
314 if (gnvs_ptr)
315 gnvs_ptr->aslb = aslb;
316}
317
Stefan Reinauer00636b02012-04-04 00:08:51 +0200318static void gma_pm_init_pre_vbios(struct device *dev)
319{
320 u32 reg32;
321
322 printk(BIOS_DEBUG, "GT Power Management Init\n");
323
324 gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
325 if (!gtt_res || !gtt_res->base)
326 return;
327
328 if (bridge_silicon_revision() < IVB_STEP_C0) {
329 /* 1: Enable force wake */
330 gtt_write(0xa18c, 0x00000001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700331 gtt_poll(0x130090, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200332 } else {
333 gtt_write(0xa180, 1 << 5);
334 gtt_write(0xa188, 0xffff0001);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700335 gtt_poll(0x130040, (1 << 0), (1 << 0));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200336 }
337
338 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
339 /* 1d: Set GTT+0x42004 [15:14]=11 (SnB C1+) */
340 reg32 = gtt_read(0x42004);
341 reg32 |= (1 << 14) | (1 << 15);
342 gtt_write(0x42004, reg32);
343 }
344
345 if (bridge_silicon_revision() >= IVB_STEP_A0) {
346 /* Display Reset Acknowledge Settings */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200347 reg32 = gtt_read(0x45010);
348 reg32 |= (1 << 1) | (1 << 0);
349 gtt_write(0x45010, reg32);
350 }
351
352 /* 2: Get GT SKU from GTT+0x911c[13] */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700353 reg32 = gtt_read(0x911c);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200354 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
Stefan Reinauer00636b02012-04-04 00:08:51 +0200355 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700356 printk(BIOS_DEBUG, "SNB GT1 Power Meter Weights\n");
357 gtt_write_powermeter(snb_pm_gt1);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200358 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700359 printk(BIOS_DEBUG, "SNB GT2 Power Meter Weights\n");
360 gtt_write_powermeter(snb_pm_gt2);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200361 }
362 } else {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700363 u32 unit = MCHBAR32(0x5938) & 0xf;
Duncan Lauriedd585b82012-04-09 12:05:18 -0700364
Duncan Laurie8508cff2012-04-12 16:02:43 -0700365 if (reg32 & (1 << 13)) {
Duncan Lauriedd585b82012-04-09 12:05:18 -0700366 /* GT1 SKU */
367 printk(BIOS_DEBUG, "IVB GT1 Power Meter Weights\n");
368 gtt_write_powermeter(ivb_pm_gt1);
Duncan Laurie8508cff2012-04-12 16:02:43 -0700369 } else {
370 /* GT2 SKU */
371 u32 tdp = MCHBAR32(0x5930) & 0x7fff;
372 tdp /= (1 << unit);
373
374 if (tdp <= 17) {
375 /* <=17W ULV */
Angel Pons7c49cb82020-03-16 23:17:32 +0100376 printk(BIOS_DEBUG, "IVB GT2 17W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700377 gtt_write_powermeter(ivb_pm_gt2_17w);
378 } else if ((tdp >= 25) && (tdp <= 35)) {
379 /* 25W-35W */
Angel Pons7c49cb82020-03-16 23:17:32 +0100380 printk(BIOS_DEBUG, "IVB GT2 25W-35W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700381 gtt_write_powermeter(ivb_pm_gt2_35w);
382 } else {
383 /* All others */
Angel Pons7c49cb82020-03-16 23:17:32 +0100384 printk(BIOS_DEBUG, "IVB GT2 35W Power Meter Weights\n");
Duncan Laurie8508cff2012-04-12 16:02:43 -0700385 gtt_write_powermeter(ivb_pm_gt2_35w);
386 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700387 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200388 }
389
390 /* 3: Gear ratio map */
391 gtt_write(0xa004, 0x00000010);
392
393 /* 4: GFXPAUSE */
394 gtt_write(0xa000, 0x00070020);
395
396 /* 5: Dynamic EU trip control */
397 gtt_write(0xa080, 0x00000004);
398
399 /* 6: ECO bits */
400 reg32 = gtt_read(0xa180);
401 reg32 |= (1 << 26) | (1 << 31);
402 /* (bit 20=1 for SNB step D1+ / IVB A0+) */
403 if (bridge_silicon_revision() >= SNB_STEP_D1)
404 reg32 |= (1 << 20);
405 gtt_write(0xa180, reg32);
406
407 /* 6a: for SnB step D2+ only */
408 if (((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) &&
409 (bridge_silicon_revision() >= SNB_STEP_D2)) {
410 reg32 = gtt_read(0x9400);
411 reg32 |= (1 << 7);
412 gtt_write(0x9400, reg32);
413
414 reg32 = gtt_read(0x941c);
415 reg32 &= 0xf;
416 reg32 |= (1 << 1);
417 gtt_write(0x941c, reg32);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700418 gtt_poll(0x941c, (1 << 1), (0 << 1));
Stefan Reinauer00636b02012-04-04 00:08:51 +0200419 }
420
421 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
422 reg32 = gtt_read(0x907c);
423 reg32 |= (1 << 16);
424 gtt_write(0x907c, reg32);
425
426 /* 6b: Clocking reset controls */
427 gtt_write(0x9424, 0x00000001);
428 } else {
429 /* 6b: Clocking reset controls */
430 gtt_write(0x9424, 0x00000000);
431 }
432
433 /* 7 */
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700434 if (gtt_poll(0x138124, (1 << 31), (0 << 31))) {
435 gtt_write(0x138128, 0x00000029); /* Mailbox Data */
436 gtt_write(0x138124, 0x80000004); /* Mailbox Cmd for RC6 VID */
437 if (gtt_poll(0x138124, (1 << 31), (0 << 31)))
438 gtt_write(0x138124, 0x8000000a);
439 gtt_poll(0x138124, (1 << 31), (0 << 31));
440 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200441
442 /* 8 */
443 gtt_write(0xa090, 0x00000000); /* RC Control */
444 gtt_write(0xa098, 0x03e80000); /* RC1e Wake Rate Limit */
445 gtt_write(0xa09c, 0x0028001e); /* RC6/6p Wake Rate Limit */
446 gtt_write(0xa0a0, 0x0000001e); /* RC6pp Wake Rate Limit */
447 gtt_write(0xa0a8, 0x0001e848); /* RC Evaluation Interval */
448 gtt_write(0xa0ac, 0x00000019); /* RC Idle Hysteresis */
449
450 /* 9 */
451 gtt_write(0x2054, 0x0000000a); /* Render Idle Max Count */
452 gtt_write(0x12054,0x0000000a); /* Video Idle Max Count */
453 gtt_write(0x22054,0x0000000a); /* Blitter Idle Max Count */
454
455 /* 10 */
456 gtt_write(0xa0b0, 0x00000000); /* Unblock Ack to Busy */
457 gtt_write(0xa0b4, 0x000003e8); /* RC1e Threshold */
458 gtt_write(0xa0b8, 0x0000c350); /* RC6 Threshold */
459 gtt_write(0xa0bc, 0x000186a0); /* RC6p Threshold */
460 gtt_write(0xa0c0, 0x0000fa00); /* RC6pp Threshold */
461
462 /* 11 */
463 gtt_write(0xa010, 0x000f4240); /* RP Down Timeout */
464 gtt_write(0xa014, 0x12060000); /* RP Interrupt Limits */
465 gtt_write(0xa02c, 0x00015f90); /* RP Up Threshold */
466 gtt_write(0xa030, 0x000186a0); /* RP Down Threshold */
467 gtt_write(0xa068, 0x000186a0); /* RP Up EI */
468 gtt_write(0xa06c, 0x000493e0); /* RP Down EI */
469 gtt_write(0xa070, 0x0000000a); /* RP Idle Hysteresis */
470
471 /* 11a: Enable Render Standby (RC6) */
472 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700473 /*
474 * IvyBridge should also support DeepRenderStandby.
475 *
476 * Unfortunately it does not work reliably on all SKUs so
477 * disable it here and it can be enabled by the kernel.
478 */
479 gtt_write(0xa090, 0x88040000); /* HW RC Control */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200480 } else {
481 gtt_write(0xa090, 0x88040000); /* HW RC Control */
482 }
483
484 /* 12: Normal Frequency Request */
Felix Held6b6c94b2017-11-25 00:45:23 +0100485 /* RPNFREQ_VAL comes from MCHBAR 0x5998 23:16 */
486 /* only the lower 7 bits are used and shifted left by 25 */
Stefan Reinauer00636b02012-04-04 00:08:51 +0200487 reg32 = MCHBAR32(0x5998);
488 reg32 >>= 16;
Felix Held6b6c94b2017-11-25 00:45:23 +0100489 reg32 &= 0x7f;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200490 reg32 <<= 25;
491 gtt_write(0xa008, reg32);
492
493 /* 13: RP Control */
494 gtt_write(0xa024, 0x00000592);
495
496 /* 14: Enable PM Interrupts */
497 gtt_write(0x4402c, 0x03000076);
498
499 /* Clear 0x6c024 [8:6] */
500 reg32 = gtt_read(0x6c024);
501 reg32 &= ~0x000001c0;
502 gtt_write(0x6c024, reg32);
Nico Huber07e206a2016-10-19 15:20:17 +0200503
504 /* Initialize DP buffer translation with recommended defaults */
505 gtt_write(0xe4f00, 0x0100030c);
506 gtt_write(0xe4f04, 0x00b8230c);
507 gtt_write(0xe4f08, 0x06f8930c);
508 gtt_write(0xe4f0c, 0x05f8e38e);
509 gtt_write(0xe4f10, 0x00b8030c);
510 gtt_write(0xe4f14, 0x0b78830c);
511 gtt_write(0xe4f18, 0x09f8d3cf);
512 gtt_write(0xe4f1c, 0x01e8030c);
513 gtt_write(0xe4f20, 0x09f863cf);
514 gtt_write(0xe4f24, 0x0ff803cf);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200515}
516
517static void gma_pm_init_post_vbios(struct device *dev)
518{
519 struct northbridge_intel_sandybridge_config *conf = dev->chip_info;
520 u32 reg32;
521
522 printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
523
524 /* 15: Deassert Force Wake */
Duncan Lauriedd585b82012-04-09 12:05:18 -0700525 if (bridge_silicon_revision() < IVB_STEP_C0) {
526 gtt_write(0xa18c, gtt_read(0xa18c) & ~1);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700527 gtt_poll(0x130090, (1 << 0), (0 << 0));
Duncan Lauriedd585b82012-04-09 12:05:18 -0700528 } else {
529 gtt_write(0xa188, 0x1fffe);
Duncan Laurieda83a5f2012-05-25 10:04:17 -0700530 if (gtt_poll(0x130040, (1 << 0), (0 << 0)))
531 gtt_write(0xa188, gtt_read(0xa188) | 1);
Duncan Lauriedd585b82012-04-09 12:05:18 -0700532 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200533
534 /* 16: SW RC Control */
535 gtt_write(0xa094, 0x00060000);
536
537 /* Setup Digital Port Hotplug */
538 reg32 = gtt_read(0xc4030);
539 if (!reg32) {
Angel Pons7c49cb82020-03-16 23:17:32 +0100540 reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
Stefan Reinauer00636b02012-04-04 00:08:51 +0200541 reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
542 reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
543 gtt_write(0xc4030, reg32);
544 }
545
546 /* Setup Panel Power On Delays */
547 reg32 = gtt_read(0xc7208);
548 if (!reg32) {
549 reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
550 reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
551 reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
552 gtt_write(0xc7208, reg32);
553 }
554
555 /* Setup Panel Power Off Delays */
556 reg32 = gtt_read(0xc720c);
557 if (!reg32) {
558 reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
559 reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
560 gtt_write(0xc720c, reg32);
561 }
562
563 /* Setup Panel Power Cycle Delay */
564 if (conf->gpu_panel_power_cycle_delay) {
565 reg32 = gtt_read(0xc7210);
566 reg32 &= ~0xff;
567 reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
568 gtt_write(0xc7210, reg32);
569 }
Duncan Lauriedd585b82012-04-09 12:05:18 -0700570
571 /* Enable Backlight if needed */
572 if (conf->gpu_cpu_backlight) {
573 gtt_write(0x48250, (1 << 31));
574 gtt_write(0x48254, conf->gpu_cpu_backlight);
575 }
576 if (conf->gpu_pch_backlight) {
577 gtt_write(0xc8250, (1 << 31));
578 gtt_write(0xc8254, conf->gpu_pch_backlight);
579 }
Stefan Reinauer00636b02012-04-04 00:08:51 +0200580}
581
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200582/* Enable SCI to ACPI _GPE._L06 */
583static void gma_enable_swsci(void)
584{
585 u16 reg16;
586
Angel Pons7c49cb82020-03-16 23:17:32 +0100587 /* Clear DMISCI status */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200588 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
589 reg16 &= DMISCI_STS;
590 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
591
Angel Pons7c49cb82020-03-16 23:17:32 +0100592 /* Clear ACPI TCO status */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200593 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
594
Angel Pons7c49cb82020-03-16 23:17:32 +0100595 /* Enable ACPI TCO SCIs */
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200596 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
597 reg16 |= TCOSCI_EN;
598 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
599}
600
Stefan Reinauer00636b02012-04-04 00:08:51 +0200601static void gma_func0_init(struct device *dev)
602{
603 u32 reg32;
604
605 /* IGD needs to be Bus Master */
606 reg32 = pci_read_config32(dev, PCI_COMMAND);
607 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
608 pci_write_config32(dev, PCI_COMMAND, reg32);
609
610 /* Init graphics power management */
611 gma_pm_init_pre_vbios(dev);
612
Nico Huberd1b99d22019-05-30 15:11:42 +0200613 if (!CONFIG(MAINBOARD_USE_LIBGFXINIT))
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700614 /* PCI Init, will run VBIOS */
615 pci_dev_init(dev);
Stefan Reinauer00636b02012-04-04 00:08:51 +0200616
617 /* Post VBIOS init */
618 gma_pm_init_post_vbios(dev);
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800619
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200620 int vga_disable = (pci_read_config16(dev, GGC) & 2) >> 1;
621
Patrick Rudolphde4a1a02017-06-20 19:13:33 +0200622 /* Running graphics init on S3 breaks Linux drm driver. */
623 if (!acpi_is_wakeup_s3() &&
Julius Wernercd49cce2019-03-05 16:53:33 -0800624 CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200625 if (vga_disable) {
626 printk(BIOS_INFO,
627 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
Nico Huber88c64872016-10-05 18:02:01 +0200628 } else {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200629 /* This should probably run before post VBIOS init. */
630 printk(BIOS_SPEW, "Initializing VGA without OPROM.\n");
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200631 int lightup_ok;
Arthur Heymansa6be58f2018-07-18 16:43:43 +0200632 gma_gfxinit(&lightup_ok);
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +0200633 if (lightup_ok)
634 gfx_set_init_done(1);
Nico Huber88c64872016-10-05 18:02:01 +0200635 }
Alexandru Gagniuc96470942015-09-07 03:06:31 -0700636 }
Patrick Rudolph76b93fe2017-06-20 17:55:40 +0200637
638 gma_enable_swsci();
639 intel_gma_restore_opregion();
Stefan Reinauer00636b02012-04-04 00:08:51 +0200640}
641
Furquan Shaikh7536a392020-04-24 21:59:21 -0700642static void gma_generate_ssdt(const struct device *device)
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100643{
Matt DeVillier348f9f02020-03-30 19:30:18 -0500644 const struct northbridge_intel_sandybridge_config *chip = device->chip_info;
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100645
Matt DeVillier348f9f02020-03-30 19:30:18 -0500646 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100647}
648
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700649static unsigned long gma_write_acpi_tables(const struct device *const dev,
650 unsigned long current,
Angel Pons7c49cb82020-03-16 23:17:32 +0100651 struct acpi_rsdp *const rsdp)
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200652{
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200653 igd_opregion_t *opregion = (igd_opregion_t *)current;
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200654 global_nvs_t *gnvs;
655
Matt DeVillierebe08e02017-07-14 13:28:42 -0500656 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200657 return current;
658
659 current += sizeof(igd_opregion_t);
660
661 /* GNVS has been already set up */
662 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
663 if (gnvs) {
664 /* IGD OpRegion Base Address */
Patrick Rudolph19c2ad82017-06-30 14:52:01 +0200665 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200666 } else {
667 printk(BIOS_ERR, "Error: GNVS table not found.\n");
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200668 }
669
Patrick Rudolph402e9c12017-05-18 18:26:30 +0200670 current = acpi_align_current(current);
Patrick Rudolph281ccca2017-04-12 16:55:32 +0200671 return current;
672}
673
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600674static const char *gma_acpi_name(const struct device *dev)
Patrick Rudolph3e47fc92017-06-07 09:44:07 +0200675{
676 return "GFX0";
677}
678
Angel Pons7c49cb82020-03-16 23:17:32 +0100679/* Called by PCI set_vga_bridge function */
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200680static void gma_func0_disable(struct device *dev)
681{
682 u16 reg16;
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300683 struct device *dev_host = pcidev_on_root(0, 0);
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200684
685 reg16 = pci_read_config16(dev_host, GGC);
Angel Pons7c49cb82020-03-16 23:17:32 +0100686 reg16 |= (1 << 1); /* Disable VGA decode */
Patrick Rudolphe11f6c32015-10-15 15:35:12 +0200687 pci_write_config16(dev_host, GGC, reg16);
688
689 dev->enabled = 0;
690}
691
Stefan Reinauer00636b02012-04-04 00:08:51 +0200692static struct pci_operations gma_pci_ops = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100693 .set_subsystem = pci_dev_set_subsystem,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200694};
695
696static struct device_operations gma_func0_ops = {
Nico Huber68680dd2020-03-31 17:34:52 +0200697 .read_resources = pci_dev_read_resources,
698 .set_resources = pci_dev_set_resources,
699 .enable_resources = pci_dev_enable_resources,
Matt DeVillier348f9f02020-03-30 19:30:18 -0500700 .acpi_fill_ssdt = gma_generate_ssdt,
Nico Huber68680dd2020-03-31 17:34:52 +0200701 .init = gma_func0_init,
Nico Huber68680dd2020-03-31 17:34:52 +0200702 .disable = gma_func0_disable,
703 .ops_pci = &gma_pci_ops,
704 .acpi_name = gma_acpi_name,
705 .write_acpi_tables = gma_write_acpi_tables,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200706};
707
Angel Pons7c49cb82020-03-16 23:17:32 +0100708static const unsigned short pci_device_ids[] = {
709 0x0102, 0x0106, 0x010a, 0x0112,
710 0x0116, 0x0122, 0x0126, 0x0156,
711 0x0166, 0x0162, 0x016a, 0x0152,
712 0
713};
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800714
715static const struct pci_driver gma __pci_driver = {
Angel Pons7c49cb82020-03-16 23:17:32 +0100716 .ops = &gma_func0_ops,
717 .vendor = PCI_VENDOR_ID_INTEL,
Ronald G. Minnich69efaa02013-02-26 10:07:40 -0800718 .devices = pci_device_ids,
Stefan Reinauer00636b02012-04-04 00:08:51 +0200719};