blob: b0e2ba991643d85c17f141e257294e9a6eeef1fa [file] [log] [blame]
Patrick Georgi2efc8802012-11-06 11:03:53 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * 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.
Patrick Georgi2efc8802012-11-06 11:03:53 +010015 */
16
17#include <stdint.h>
18#include <stddef.h>
19#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010021#include <device/pci_def.h>
22#include <console/console.h>
Vladimir Serbinenko084ed452014-08-16 10:51:06 +020023#include <pc80/mc146818rtc.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010024
25#include "gm45.h"
26
27/* TODO: Chipset supports Protected Audio Video Path (PAVP) */
28
29/* TODO: We could pass DVMT structure in GetBIOSData() SCI interface */
30
31/* The PEG settings have to be set before ASPM is setup on DMI. */
32static void enable_igd(const sysinfo_t *const sysinfo, const int no_peg)
33{
Furquan Shaikh25f75b22016-08-29 22:51:41 -070034 const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0);
35 const pci_devfn_t peg_dev = PCI_DEV(0, 1, 0);
36 const pci_devfn_t igd_dev = PCI_DEV(0, 2, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010037
38 u16 reg16;
39 u32 reg32;
40
41 printk(BIOS_DEBUG, "Enabling IGD.\n");
42
43 /* HSync/VSync */
44 MCHBAR8(0xbd0 + 3) = 0x5a;
45 MCHBAR8(0xbd0 + 4) = 0x5a;
46
47 static const u16 display_clock_from_f0_and_vco[][4] = {
48 /* VCO 2666 VCO 3200 VCO 4000 VCO 5333 */
49 { 222, 228, 222, 222, },
50 { 333, 320, 333, 333, },
51 };
52 const int f0_12 = (pci_read_config16(igd_dev, 0xf0) >> 12) & 1;
53 const int vco = raminit_read_vco_index();
54 reg16 = pci_read_config16(igd_dev, 0xcc);
55 reg16 &= 0xfc00;
56 reg16 |= display_clock_from_f0_and_vco[f0_12][vco];
57 pci_write_config16(igd_dev, 0xcc, reg16);
58
Patrick Georgi2efc8802012-11-06 11:03:53 +010059 reg16 = pci_read_config16(mch_dev, D0F0_GGC);
60 reg16 &= 0xf00f;
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +020061 reg16 |= sysinfo->ggc;
Patrick Georgi2efc8802012-11-06 11:03:53 +010062 pci_write_config16(mch_dev, D0F0_GGC, reg16);
63
64 if ((sysinfo->gfx_type != GMCH_GL40) &&
65 (sysinfo->gfx_type != GMCH_GS40) &&
66 (sysinfo->gfx_type != GMCH_GL43)) {
67 const u32 deven = pci_read_config32(mch_dev, D0F0_DEVEN);
68 if (!(deven & 2))
69 /* Enable PEG temporarily to access D1:F0. */
70 pci_write_config32(mch_dev, D0F0_DEVEN, deven | 2);
71
72 /* Some IGD related settings on D1:F0. */
73 reg16 = pci_read_config16(peg_dev, 0xa08);
74 reg16 &= ~(1 << 15);
75 pci_write_config16(peg_dev, 0xa08, reg16);
76
77 reg16 = pci_read_config16(peg_dev, 0xa84);
78 reg16 |= (1 << 8);
79 pci_write_config16(peg_dev, 0xa84, reg16);
80
81 reg16 = pci_read_config16(peg_dev, 0xb00);
82 reg16 |= (3 << 8) | (7 << 3);
83 pci_write_config16(peg_dev, 0xb00, reg16);
84
85 reg32 = pci_read_config32(peg_dev, 0xb14);
86 reg32 &= ~(1 << 17);
87 pci_write_config32(peg_dev, 0xb14, reg32);
88
89 if (!(deven & 2) || no_peg) {
90 /* Disable PEG finally. */
91 printk(BIOS_DEBUG, "Finally disabling "
92 "PEG in favor of IGD.\n");
93 MCHBAR8(0xc14) |= (1 << 5) | (1 << 0);
94
95 reg32 = pci_read_config32(peg_dev, 0x200);
96 reg32 |= (1 << 18);
97 pci_write_config32(peg_dev, 0x200, reg32);
98 reg16 = pci_read_config16(peg_dev, 0x224);
99 reg16 |= (1 << 8);
100 pci_write_config16(peg_dev, 0x224, reg16);
101 reg32 = pci_read_config32(peg_dev, 0x200);
102 reg32 &= ~(1 << 18);
103 pci_write_config32(peg_dev, 0x200, reg32);
104 while (pci_read_config32(peg_dev, 0x214) & 0x000f0000);
105
106 pci_write_config32(mch_dev, D0F0_DEVEN, deven & ~2);
107 MCHBAR8(0xc14) &= ~((1 << 5) | (1 << 0));
108 }
109 }
110}
111
112static void disable_igd(const sysinfo_t *const sysinfo)
113{
Furquan Shaikh25f75b22016-08-29 22:51:41 -0700114 const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100115
116 printk(BIOS_DEBUG, "Disabling IGD.\n");
117
118 u16 reg16;
119
120 reg16 = pci_read_config16(mch_dev, D0F0_GGC);
121 reg16 &= 0xff0f; /* Disable Graphics Stolen Memory. */
122 reg16 |= 0x0002; /* Disable IGD. */
123 pci_write_config16(mch_dev, D0F0_GGC, reg16);
124 MCHBAR8(0xf10) |= (1 << 0);
125
126 if (!(pci_read_config8(mch_dev, D0F0_CAPID0 + 4) & (1 << (33 - 32)))) {
127 MCHBAR16(0x1190) |= (1 << 14);
128 MCHBAR16(0x119e) = (MCHBAR16(0x119e) & ~(7 << 13)) | (4 << 13);
129 MCHBAR16(0x119e) |= (1 << 12);
130 }
Patrick Rudolphbb1af992017-01-21 10:43:52 +0100131
132 /* Hide IGD. */
133 u32 deven = pci_read_config32(mch_dev, D0F0_DEVEN);
134 deven &= ~(3 << 3);
135 pci_write_config32(mch_dev, D0F0_DEVEN, deven);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100136}
137
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200138void init_igd(const sysinfo_t *const sysinfo)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100139{
Furquan Shaikh25f75b22016-08-29 22:51:41 -0700140 const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100141
142 const u8 capid = pci_read_config8(mch_dev, D0F0_CAPID0 + 4);
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200143 if (!sysinfo->enable_igd || (capid & (1 << (33 - 32))))
Patrick Georgi2efc8802012-11-06 11:03:53 +0100144 disable_igd(sysinfo);
145 else
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200146 enable_igd(sysinfo, !sysinfo->enable_peg);
147}
148
149void igd_compute_ggc(sysinfo_t *const sysinfo)
150{
Furquan Shaikh25f75b22016-08-29 22:51:41 -0700151 const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0);
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200152
153 const u32 capid = pci_read_config32(mch_dev, D0F0_CAPID0 + 4);
154 if (!sysinfo->enable_igd || (capid & (1 << (33 - 32))))
155 sysinfo->ggc = 0x0002;
156 else {
Arthur Heymansd65ff222017-06-13 20:57:05 +0200157 /* 4 for 32MB, default if not set in cmos */
158 u8 gfxsize = 4;
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200159
160 /* Graphics Stolen Memory: 2MB GTT (0x0300) when VT-d disabled,
161 2MB GTT + 2MB shadow GTT (0x0b00) else. */
Arthur Heymansd65ff222017-06-13 20:57:05 +0200162 get_option(&gfxsize, "gfx_uma_size");
Arthur Heymans7afcfe02016-05-19 15:34:49 +0200163 /* Handle invalid cmos settings */
Arthur Heymansd65ff222017-06-13 20:57:05 +0200164 /* Only allow settings between 32MB and 352MB */
165 gfxsize = MIN(MAX(gfxsize, 4), 12);
166
Arthur Heymans7afcfe02016-05-19 15:34:49 +0200167 sysinfo->ggc = 0x0300 | ((gfxsize + 1) << 4);
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200168 if (!(capid & (1 << (48 - 32))))
169 sysinfo->ggc |= 0x0800;
170 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100171}