printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / southbridge / amd / rs690 / rs690_gfx.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /*
21  *  for rs690 internal graphics device
22  *  device id of internal grphics:
23  *      RS690M/T: 0x791f
24  *    RS690:       0x791e
25  */
26 #include <console/console.h>
27 #include <device/device.h>
28 #include <device/pci.h>
29 #include <device/pci_ids.h>
30 #include <device/pci_ops.h>
31 #include <delay.h>
32 #include "rs690.h"
33
34 #define CLK_CNTL_INDEX  0x8
35 #define CLK_CNTL_DATA   0xC
36
37 static u32 clkind_read(device_t dev, u32 index)
38 {
39         u32     gfx_bar2 = pci_read_config32(dev, 0x18) & ~0xF;
40
41         *(u32*)(gfx_bar2+CLK_CNTL_INDEX) = index & 0x7F;
42         return *(u32*)(gfx_bar2+CLK_CNTL_DATA);
43 }
44
45 static void clkind_write(device_t dev, u32 index, u32 data)
46 {
47         u32     gfx_bar2 = pci_read_config32(dev, 0x18) & ~0xF;
48         /* printk(BIOS_INFO, "gfx bar 2 %02x\n", gfx_bar2); */
49
50         *(u32*)(gfx_bar2+CLK_CNTL_INDEX) = index | 1<<7;
51         *(u32*)(gfx_bar2+CLK_CNTL_DATA)  = data;
52 }
53
54 /*
55 * pci_dev_read_resources thinks it is a IO type.
56 * We have to force it to mem type.
57 */
58 static void rs690_gfx_read_resources(device_t dev)
59 {
60         printk(BIOS_INFO, "rs690_gfx_read_resources.\n");
61
62         /* The initial value of 0x24 is 0xFFFFFFFF, which is confusing.
63            Even if we write 0xFFFFFFFF into it, it will be 0xFFF00000,
64            which tells us it is a memory address base.
65          */
66         pci_write_config32(dev, 0x24, 0x00000000);
67
68         /* Get the normal pci resources of this device */
69         pci_dev_read_resources(dev);
70         compact_resources(dev);
71 }
72
73 static void internal_gfx_pci_dev_init(struct device *dev)
74 {
75         u16 deviceid, vendorid;
76         struct southbridge_amd_rs690_config *cfg =
77             (struct southbridge_amd_rs690_config *)dev->chip_info;
78         deviceid = pci_read_config16(dev, PCI_DEVICE_ID);
79         vendorid = pci_read_config16(dev, PCI_VENDOR_ID);
80         printk(BIOS_INFO, "internal_gfx_pci_dev_init device=%x, vendor=%x.\n",
81              deviceid, vendorid);
82
83         pci_dev_init(dev);
84
85         /* clk ind */
86         clkind_write(dev, 0x08, 0x01);
87         clkind_write(dev, 0x0C, 0x22);
88         clkind_write(dev, 0x0F, 0x0);
89         clkind_write(dev, 0x11, 0x0);
90         clkind_write(dev, 0x12, 0x0);
91         clkind_write(dev, 0x14, 0x0);
92         clkind_write(dev, 0x15, 0x0);
93         clkind_write(dev, 0x16, 0x0);
94         clkind_write(dev, 0x17, 0x0);
95         clkind_write(dev, 0x18, 0x0);
96         clkind_write(dev, 0x19, 0x0);
97         clkind_write(dev, 0x1A, 0x0);
98         clkind_write(dev, 0x1B, 0x0);
99         clkind_write(dev, 0x1C, 0x0);
100         clkind_write(dev, 0x1D, 0x0);
101         clkind_write(dev, 0x1E, 0x0);
102         clkind_write(dev, 0x26, 0x0);
103         clkind_write(dev, 0x27, 0x0);
104         clkind_write(dev, 0x28, 0x0);
105         clkind_write(dev, 0x5C, 0x0);
106 }
107
108
109 /*
110 * Set registers in RS690 and CPU to enable the internal GFX.
111 * Please refer to CIM source code and BKDG.
112 */
113 static void rs690_internal_gfx_enable(device_t dev)
114 {
115         u32 l_dword;
116         int i;
117         device_t k8_f0 = 0, k8_f2 = 0;
118         device_t nb_dev = dev_find_slot(0, 0);
119
120         printk(BIOS_INFO, "rs690_internal_gfx_enable dev=0x%p, nb_dev=0x%p.\n", dev,
121                     nb_dev);
122
123         /* set APERTURE_SIZE, 128M. */
124         l_dword = pci_read_config32(nb_dev, 0x8c);
125         printk(BIOS_INFO, "nb_dev, 0x8c=0x%x\n", l_dword);
126         l_dword &= 0xffffff8f;
127         pci_write_config32(nb_dev, 0x8c, l_dword);
128
129         /* set TOM */
130         rs690_set_tom(nb_dev);
131
132         /* LPC DMA Deadlock workaround? */
133         k8_f0 = dev_find_slot(0, PCI_DEVFN(0x18, 0));
134         l_dword = pci_read_config32(k8_f0, 0x68);
135         l_dword &= ~(1 << 22);
136         l_dword |= (1 << 21);
137         pci_write_config32(k8_f0, 0x68, l_dword);
138
139         /* Enable 64bit mode. */
140         set_nbmc_enable_bits(nb_dev, 0x5f, 0, 1 << 9);
141         set_nbmc_enable_bits(nb_dev, 0xb0, 0, 1 << 8);
142
143         /* 64bit Latency. */
144         set_nbmc_enable_bits(nb_dev, 0x5f, 0x7c00, 0x800);
145
146         /* UMA dual channel control register. */
147         nbmc_write_index(nb_dev, 0x86, 0x3d);
148
149         /* check the setting later!! */
150         set_htiu_enable_bits(nb_dev, 0x07, 1 << 7, 0);
151
152         /* UMA mode, powerdown memory PLL. */
153         set_nbmc_enable_bits(nb_dev, 0x74, 0, 1 << 31);
154
155         /* Copy CPU DDR Controller to NB MC. */
156         /* Why K8_MC_REG80 is special? */
157         k8_f2 = dev_find_slot(0, PCI_DEVFN(0x18, 2));
158         for (i = 0; i <= (0x80 - 0x40) / 4; i++) {
159                 l_dword = pci_read_config32(k8_f2, 0x40 + i * 4);
160                 nbmc_write_index(nb_dev, 0x63 + i, l_dword);
161         }
162
163         /* Set K8 MC for UMA, Family F. */
164         l_dword = pci_read_config32(k8_f2, 0xa0);
165         l_dword |= 0x2c;
166         pci_write_config32(k8_f2, 0xa0, l_dword);
167         l_dword = pci_read_config32(k8_f2, 0x94);
168         l_dword &= 0xf0ffffff;
169         l_dword |= 0x07000000;
170         pci_write_config32(k8_f2, 0x94, l_dword);
171
172         /* set FB size and location. */
173         nbmc_write_index(nb_dev, 0x1b, 0x00);
174         l_dword = nbmc_read_index(nb_dev, 0x1c);
175         l_dword &= 0xffff0;
176         l_dword |= 0x400 << 20;
177         l_dword |= 0x4;
178         nbmc_write_index(nb_dev, 0x1c, l_dword);
179         l_dword = nbmc_read_index(nb_dev, 0x1d);
180         l_dword &= 0xfffff000;
181         l_dword |= 0x0400;
182         nbmc_write_index(nb_dev, 0x1d, l_dword);
183         nbmc_write_index(nb_dev, 0x100, 0x3fff3800);
184
185         /* Program MC table. */
186         set_nbmc_enable_bits(nb_dev, 0x00, 0, 1 << 31);
187         l_dword = nbmc_read_index(nb_dev, 0x91);
188         l_dword |= 0x5;
189         nbmc_write_index(nb_dev, 0x91, l_dword);
190         set_nbmc_enable_bits(nb_dev, 0xb1, 0, 1 << 6);
191         set_nbmc_enable_bits(nb_dev, 0xc3, 0, 1);
192
193         /* TODO: the optimization of voltage and frequency */
194 }
195
196 static struct pci_operations lops_pci = {
197         .set_subsystem = pci_dev_set_subsystem,
198 };
199
200 static struct device_operations pcie_ops = {
201         .read_resources = rs690_gfx_read_resources,
202         .set_resources = pci_dev_set_resources,
203         .enable_resources = pci_dev_enable_resources,
204         .init = internal_gfx_pci_dev_init,      /* The option ROM initializes the device. rs690_gfx_init, */
205         .scan_bus = 0,
206         .enable = rs690_internal_gfx_enable,
207         .ops_pci = &lops_pci,
208 };
209
210 /*
211  * The dev id of 690G is 791E, while the id of 690M, 690T is 791F.
212  * We should list both of them here.
213  * */
214 static const struct pci_driver pcie_driver_690t __pci_driver = {
215         .ops = &pcie_ops,
216         .vendor = PCI_VENDOR_ID_ATI,
217         .device = PCI_DEVICE_ID_ATI_RS690MT_INT_GFX,
218 };
219
220 static const struct pci_driver pcie_driver_690 __pci_driver = {
221         .ops = &pcie_ops,
222         .vendor = PCI_VENDOR_ID_ATI,
223         .device = PCI_DEVICE_ID_ATI_RS690_INT_GFX,
224 };
225
226 /* step 12 ~ step 14 from rpr */
227 static void single_port_configuration(device_t nb_dev, device_t dev)
228 {
229         u8 result, width;
230         u32 reg32;
231         struct southbridge_amd_rs690_config *cfg =
232             (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
233
234         printk(BIOS_INFO, "rs690_gfx_init single_port_configuration.\n");
235
236         /* step 12 training, releases hold training for GFX port 0 (device 2) */
237         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 4, 0<<4);
238         PcieReleasePortTraining(nb_dev, dev, 2);
239         result = PcieTrainPort(nb_dev, dev, 2);
240         printk(BIOS_INFO, "rs690_gfx_init single_port_configuration step12.\n");
241
242         /* step 13 Power Down Control */
243         /* step 13.1 Enables powering down transmitter and receiver pads along with PLL macros. */
244         set_pcie_enable_bits(nb_dev, 0x40, 1 << 0, 1 << 0);
245
246         /* step 13.a Link Training was NOT successful */
247         if (!result) {
248                 set_nbmisc_enable_bits(nb_dev, 0x8, 0, 0x3 << 4); /* prevent from training. */
249                 set_nbmisc_enable_bits(nb_dev, 0xc, 0, 0x3 << 2); /* hide the GFX bridge. */
250                 if (cfg->gfx_tmds)
251                         nbpcie_ind_write_index(nb_dev, 0x65, 0xccf0f0);
252                 else {
253                         nbpcie_ind_write_index(nb_dev, 0x65, 0xffffffff);
254                         set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 3, 1 << 3);
255                 }
256         } else {                /* step 13.b Link Training was successful */
257
258                 reg32 = nbpcie_p_read_index(dev, 0xa2);
259                 width = (reg32 >> 4) & 0x7;
260                 printk(BIOS_DEBUG, "GFX LC_LINK_WIDTH = 0x%x.\n", width);
261                 switch (width) {
262                 case 1:
263                 case 2:
264                         nbpcie_ind_write_index(nb_dev, 0x65,
265                                                cfg->gfx_lane_reversal ? 0x7f7f : 0xccfefe);
266                         break;
267                 case 4:
268                         nbpcie_ind_write_index(nb_dev, 0x65,
269                                                cfg->gfx_lane_reversal ? 0x3f3f : 0xccfcfc);
270                         break;
271                 case 8:
272                         nbpcie_ind_write_index(nb_dev, 0x65,
273                                                cfg->gfx_lane_reversal ? 0x0f0f : 0xccf0f0);
274                         break;
275                 }
276         }
277         printk(BIOS_INFO, "rs690_gfx_init single_port_configuration step13.\n");
278
279         /* step 14 Reset Enumeration Timer, disables the shortening of the enumeration timer */
280         set_pcie_enable_bits(dev, 0x70, 1 << 19, 0 << 19);
281         printk(BIOS_INFO, "rs690_gfx_init single_port_configuration step14.\n");
282 }
283
284 /* step 15 ~ step 18 from rpr */
285 static void dual_port_configuration(device_t nb_dev, device_t dev)
286 {
287         u8 result, width;
288         u32 reg32;
289         struct southbridge_amd_rs690_config *cfg =
290                     (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
291
292         /* step 15: Training for Device 2 */
293         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 4, 0 << 4);
294         /* Releases hold training for GFX port 0 (device 2) */
295         PcieReleasePortTraining(nb_dev, dev, 2);
296         /* PCIE Link Training Sequence */
297         result = PcieTrainPort(nb_dev, dev, 2);
298
299         /* step 16: Power Down Control for Device 2 */
300         /* step 16.a Link Training was NOT successful */
301         if (!result) {
302                 /* Powers down all lanes for port A */
303                 nbpcie_ind_write_index(nb_dev, 0x65, 0x0f0f);
304         } else {                /* step 16.b Link Training was successful */
305
306                 reg32 = nbpcie_p_read_index(dev, 0xa2);
307                 width = (reg32 >> 4) & 0x7;
308                 printk(BIOS_DEBUG, "GFX LC_LINK_WIDTH = 0x%x.\n", width);
309                 switch (width) {
310                 case 1:
311                 case 2:
312                         nbpcie_ind_write_index(nb_dev, 0x65,
313                                                cfg->gfx_lane_reversal ? 0x0707 : 0x0e0e);
314                         break;
315                 case 4:
316                         nbpcie_ind_write_index(nb_dev, 0x65,
317                                                cfg->gfx_lane_reversal ? 0x0303 : 0x0c0c);
318                         break;
319                 }
320         }
321
322         /* step 17: Training for Device 3 */
323         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 5, 0 << 5);
324         /* Releases hold training for GFX port 0 (device 3) */
325         PcieReleasePortTraining(nb_dev, dev, 3);
326         /* PCIE Link Training Sequence */
327         result = PcieTrainPort(nb_dev, dev, 3);
328
329         /*step 18: Power Down Control for Device 3 */
330         /* step 18.a Link Training was NOT successful */
331         if (!result) {
332                 /* Powers down all lanes for port B and PLL1 */
333                 nbpcie_ind_write_index(nb_dev, 0x65, 0xccf0f0);
334         } else {                /* step 18.b Link Training was successful */
335
336                 reg32 = nbpcie_p_read_index(dev, 0xa2);
337                 width = (reg32 >> 4) & 0x7;
338                 printk(BIOS_DEBUG, "GFX LC_LINK_WIDTH = 0x%x.\n", width);
339                 switch (width) {
340                 case 1:
341                 case 2:
342                         nbpcie_ind_write_index(nb_dev, 0x65,
343                                                cfg->gfx_lane_reversal ? 0x7070 : 0xe0e0);
344                         break;
345                 case 4:
346                         nbpcie_ind_write_index(nb_dev, 0x65,
347                                                cfg->gfx_lane_reversal ? 0x3030 : 0xc0c0);
348                         break;
349                 }
350         }
351 }
352
353
354 /* For single port GFX configuration Only
355 * width:
356 *       000 = x16
357 *       001 = x1
358 *       010 = x2
359 *       011 = x4
360 *       100 = x8
361 *       101 = x12 (not supported)
362 *       110 = x16
363 */
364 static void dynamic_link_width_control(device_t nb_dev, device_t dev, u8 width)
365 {
366         u32 reg32;
367         device_t sb_dev;
368         struct southbridge_amd_rs690_config *cfg =
369             (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
370
371         /* step 5.9.1.1 */
372         reg32 = nbpcie_p_read_index(dev, 0xa2);
373
374         /* step 5.9.1.2 */
375         set_pcie_enable_bits(nb_dev, 0x40, 1 << 0, 1 << 0);
376         /* step 5.9.1.3 */
377         set_pcie_enable_bits(dev, 0xa2, 3 << 0, width << 0);
378         /* step 5.9.1.4 */
379         set_pcie_enable_bits(dev, 0xa2, 1 << 8, 1 << 8);
380         /* step 5.9.2.4 */
381         if (0 == cfg->gfx_reconfiguration)
382                 set_pcie_enable_bits(dev, 0xa2, 1 << 11, 1 << 11);
383
384         /* step 5.9.1.5 */
385         do {
386                 reg32 = nbpcie_p_read_index(dev, 0xa2);
387         }
388         while (reg32 & 0x100);
389
390         /* step 5.9.1.6 */
391         sb_dev = dev_find_slot(0, PCI_DEVFN(8, 0));
392         do {
393                 reg32 = pci_ext_read_config32(nb_dev, sb_dev,
394                                           PCIE_VC0_RESOURCE_STATUS);
395         } while (reg32 & VC_NEGOTIATION_PENDING);
396
397         /* step 5.9.1.7 */
398         reg32 = nbpcie_p_read_index(dev, 0xa2);
399         if (((reg32 & 0x70) >> 4) != 0x6) {
400                 /* the unused lanes should be powered off. */
401         }
402
403         /* step 5.9.1.8 */
404         set_pcie_enable_bits(nb_dev, 0x40, 1 << 0, 0 << 0);
405 }
406
407 /*
408 * GFX Core initialization, dev2, dev3
409 */
410 void rs690_gfx_init(device_t nb_dev, device_t dev, u32 port)
411 {
412         u16 reg16;
413         struct southbridge_amd_rs690_config *cfg =
414             (struct southbridge_amd_rs690_config *)nb_dev->chip_info;
415
416         printk(BIOS_INFO, "rs690_gfx_init, nb_dev=0x%p, dev=0x%p, port=0x%x.\n",
417                     nb_dev, dev, port);
418
419         /* step 0, REFCLK_SEL, skip A11 revision */
420         set_nbmisc_enable_bits(nb_dev, 0x6a, 1 << 9,
421                                cfg->gfx_dev2_dev3 ? 1 << 9 : 0 << 9);
422         printk(BIOS_INFO, "rs690_gfx_init step0.\n");
423
424         /* step 1, lane reversal (only need if CMOS option is enabled) */
425         if (cfg->gfx_lane_reversal) {
426                 set_nbmisc_enable_bits(nb_dev, 0x33, 1 << 2, 1 << 2);
427                 if (cfg->gfx_dual_slot)
428                         set_nbmisc_enable_bits(nb_dev, 0x33, 1 << 3, 1 << 3);
429         }
430         printk(BIOS_INFO, "rs690_gfx_init step1.\n");
431
432         /* step 1.1, dual-slot gfx configuration (only need if CMOS option is enabled) */
433         /* AMD calls the configuration CrossFire */
434         if (cfg->gfx_dual_slot)
435                 set_nbmisc_enable_bits(nb_dev, 0x0, 0xf << 8, 5 << 8);
436         printk(BIOS_INFO, "rs690_gfx_init step2.\n");
437
438         /* step 2, TMDS, (only need if CMOS option is enabled) */
439         if (cfg->gfx_tmds) {
440         }
441
442         /* step 3, GFX overclocking, (only need if CMOS option is enabled) */
443         /* skip */
444
445         /* step 4, reset the GFX link */
446         /* step 4.1 asserts both calibration reset and global reset */
447         set_nbmisc_enable_bits(nb_dev, 0x8, 0x3 << 14, 0x3 << 14);
448
449         /* step 4.2 de-asserts calibration reset */
450         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 14, 0 << 14);
451
452         /* step 4.3 wait for at least 200us */
453         udelay(200);
454
455         /* step 4.4 de-asserts global reset */
456         set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 15, 0 << 15);
457
458         /* step 4.5 asserts both calibration reset and global reset */
459         /* a weird step in RPR, don't do that */
460         /* set_nbmisc_enable_bits(nb_dev, 0x8, 0x3 << 14, 0x3 << 14); */
461
462         /* step 4.6 bring external GFX device out of reset, wait for 1ms */
463         mdelay(1);
464         printk(BIOS_INFO, "rs690_gfx_init step4.\n");
465
466         /* step 5 program PCIE memory mapped configuration space */
467         /* done by enable_pci_bar3() before */
468
469         /* step 6 SBIOS compile flags */
470         if (cfg->gfx_tmds) {
471                 /* step 6.2.2 Clock-Muxing Control */
472                 /* step 6.2.2.1 */
473                 set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 16, 1 << 16);
474
475                 /* step 6.2.2.2 */
476                 set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 8, 1 << 8);
477                 set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 10, 1 << 10);
478
479                 /* step 6.2.2.3 */
480                 set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 26, 1 << 26);
481
482                 /* step 6.2.3 Lane-Muxing Control */
483                 /* step 6.2.3.1 */
484                 set_nbmisc_enable_bits(nb_dev, 0x37, 0x3 << 8, 0x2 << 8);
485
486                 /* step 6.2.4 Received Data Control */
487                 /* step 6.2.4.1 */
488                 set_pcie_enable_bits(nb_dev, 0x40, 0x3 << 16, 0x2 << 16);
489
490                 /* step 6.2.4.2 */
491                 set_pcie_enable_bits(nb_dev, 0x40, 0x3 << 18, 0x3 << 18);
492
493                 /* step 6.2.4.3 */
494                 set_pcie_enable_bits(nb_dev, 0x40, 0x3 << 20, 0x0 << 20);
495
496                 /* step 6.2.4.4 */
497                 set_pcie_enable_bits(nb_dev, 0x40, 0x3 << 22, 0x1 << 22);
498
499                 /* step 6.2.5 PLL Power Down Control */
500                 /* step 6.2.5.1 */
501                 set_nbmisc_enable_bits(nb_dev, 0x35, 0x3 << 6, 0x0 << 6);
502
503                 /* step 6.2.6 Driving Strength Control */
504                 /* step 6.2.6.1 */
505                 set_nbmisc_enable_bits(nb_dev, 0x34, 0x1 << 24, 0x0 << 24);
506
507                 /* step 6.2.6.2 */
508                 set_nbmisc_enable_bits(nb_dev, 0x35, 0x3 << 2, 0x3 << 2);
509         }
510
511         printk(BIOS_INFO, "rs690_gfx_init step6.\n");
512
513         /* step 7 compliance state, (only need if CMOS option is enabled) */
514         /* the compliance stete is just for test. refer to 4.2.5.2 of PCIe specification */
515         if (cfg->gfx_compliance) {
516                 /* force compliance */
517                 set_nbmisc_enable_bits(nb_dev, 0x32, 1 << 6, 1 << 6);
518                 /* release hold training for device 2. GFX initialization is done. */
519                 set_nbmisc_enable_bits(nb_dev, 0x8, 1 << 4, 0 << 4);
520                 dynamic_link_width_control(nb_dev, dev, cfg->gfx_link_width);
521                 printk(BIOS_INFO, "rs690_gfx_init step7.\n");
522                 return;
523         }
524
525         /* step 8 common initialization */
526         /* step 8.1 sets RCB timeout to be 25ms */
527         set_pcie_enable_bits(dev, 0x70, 7 << 16, 3 << 16);
528         printk(BIOS_INFO, "rs690_gfx_init step8.1.\n");
529
530         /* step 8.2 disables slave ordering logic */
531         set_pcie_enable_bits(nb_dev, 0x20, 1 << 8, 1 << 8);
532         printk(BIOS_INFO, "rs690_gfx_init step8.2.\n");
533
534         /* step 8.3 sets DMA payload size to 64 bytes */
535         set_pcie_enable_bits(nb_dev, 0x10, 7 << 10, 4 << 10);
536         printk(BIOS_INFO, "rs690_gfx_init step8.3.\n");
537
538         /* step 8.4 if the LTSSM could not see all 8 TS1 during Polling Active, it can still
539          * time out and go back to Detect Idle.*/
540         set_pcie_enable_bits(dev, 0x02, 1 << 14, 1 << 14);
541         printk(BIOS_INFO, "rs690_gfx_init step8.4.\n");
542
543         /* step 8.5 shortens the enumeration timer */
544         set_pcie_enable_bits(dev, 0x70, 1 << 19, 1 << 19);
545         printk(BIOS_INFO, "rs690_gfx_init step8.5.\n");
546
547         /* step 8.6 blocks DMA traffic during C3 state */
548         set_pcie_enable_bits(dev, 0x10, 1 << 0, 0 << 0);
549         printk(BIOS_INFO, "rs690_gfx_init step8.6.\n");
550
551         /* step 8.7 Do not gate the electrical idle form the PHY
552          * step 8.8 Enables the escape from L1L23 */
553         set_pcie_enable_bits(dev, 0xa0, 3 << 30, 3 << 30);
554         printk(BIOS_INFO, "rs690_gfx_init step8.8.\n");
555
556         /* step 8.9 Setting this register to 0x1 will workaround a PCI Compliance failure reported by Vista DTM.
557          * SLOT_IMPLEMENTED@PCIE_CAP */
558         reg16 = pci_read_config16(dev, 0x5a);
559         reg16 |= 0x100;
560         pci_write_config16(dev, 0x5a, reg16);
561         printk(BIOS_INFO, "rs690_gfx_init step8.9.\n");
562
563         /* step 8.10 Setting this register to 0x1 will hide the Advanced Error Rporting Capabilities in the PCIE Brider.
564          * This will workaround several failures reported by the PCI Compliance test under Vista DTM. */
565         set_nbmisc_enable_bits(nb_dev, 0x33, 1 << 31, 0 << 31);
566         printk(BIOS_INFO, "rs690_gfx_init step8.10.\n");
567
568         /* step 8.11 Sets REGS_DLP_IGNORE_IN_L1_EN to ignore DLLPs during L1 so that txclk can be turned off. */
569         set_pcie_enable_bits(nb_dev, 0x02, 1 << 0, 1 << 0);
570         printk(BIOS_INFO, "rs690_gfx_init step8.11.\n");
571
572         /* step 8.12 Sets REGS_LC_DONT_GO_TO_L0S_IF_L1_ARMED to prevent lc to go to from L0 to Rcv_L0s if L1 is armed. */
573         set_pcie_enable_bits(nb_dev, 0x02, 1 << 6, 1 << 6);
574         printk(BIOS_INFO, "rs690_gfx_init step8.12.\n");
575
576         /* step 8.13 Sets CMGOOD_OVERRIDE. */
577         set_nbmisc_enable_bits(nb_dev, 0x6a, 1 << 17, 1 << 17);
578         printk(BIOS_INFO, "rs690_gfx_init step8.13.\n");
579
580         /* step 9 Enable TLP Flushing, for non-AMD GFX devices and Hot-Plug devices only. */
581         /* skip */
582
583         /* step 10 Optional Features, only needed if CMOS option is enabled. */
584         /* step 10.a: L0s */
585         /* enabling L0s in the RS690 GFX port(s) */
586         set_pcie_enable_bits(nb_dev, 0xF9, 3 << 13, 2 << 13);
587         set_pcie_enable_bits(dev, 0xA0, 0xf << 8, 8 << 8);
588         reg16 = pci_read_config16(dev, 0x68);
589         reg16 |= 1 << 0;
590         /* L0s is intended as a power saving state */
591         /* pci_write_config16(dev, 0x68, reg16); */
592
593         /* enabling L0s in the External GFX Device(s) */
594
595         /* step 10.b: active state power management (ASPM L1) */
596         /* TO DO */
597
598         /* step 10.c: turning off PLL During L1/L23 */
599         set_pcie_enable_bits(nb_dev, 0x40, 1 << 3, 1 << 3);
600         set_pcie_enable_bits(nb_dev, 0x40, 1 << 9, 1 << 9);
601
602         /* step 10.d: TXCLK clock gating */
603         set_nbmisc_enable_bits(nb_dev, 0x7, 3, 3);
604         set_nbmisc_enable_bits(nb_dev, 0x7, 1 << 22, 1 << 22);
605         set_pcie_enable_bits(nb_dev, 0x11, 0xf << 4, 0xc << 4);
606
607         /* step 10.e: LCLK clock gating, done in rs690_config_misc_clk() */
608
609         /* step 11 Poll GPIO to determine whether it is single-port or dual-port configuration.
610          * While details will be added later in the document, for now assue the single-port configuration. */
611         /* skip */
612
613         /* Single-port/Dual-port configureation. */
614         switch (cfg->gfx_dual_slot) {
615         case 0:
616                 single_port_configuration(nb_dev, dev);
617                 break;
618         case 1:
619                 dual_port_configuration(nb_dev, dev);
620                 break;
621         default:
622                 printk(BIOS_INFO, "Incorrect configuration of external gfx slot.\n");
623                 break;
624         }
625 }