blob: b7847c05fc27f1703c172df1620001d38bf83865 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <stdint.h>
23#include <stddef.h>
24#include <arch/io.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010025#include <device/pci_def.h>
26#include <console/console.h>
Vladimir Serbinenko084ed452014-08-16 10:51:06 +020027#include <pc80/mc146818rtc.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010028
29#include "gm45.h"
30
31/* TODO: Chipset supports Protected Audio Video Path (PAVP) */
32
33/* TODO: We could pass DVMT structure in GetBIOSData() SCI interface */
34
35/* The PEG settings have to be set before ASPM is setup on DMI. */
36static void enable_igd(const sysinfo_t *const sysinfo, const int no_peg)
37{
38 const device_t mch_dev = PCI_DEV(0, 0, 0);
39 const device_t peg_dev = PCI_DEV(0, 1, 0);
40 const device_t igd_dev = PCI_DEV(0, 2, 0);
41
42 u16 reg16;
43 u32 reg32;
44
45 printk(BIOS_DEBUG, "Enabling IGD.\n");
46
47 /* HSync/VSync */
48 MCHBAR8(0xbd0 + 3) = 0x5a;
49 MCHBAR8(0xbd0 + 4) = 0x5a;
50
51 static const u16 display_clock_from_f0_and_vco[][4] = {
52 /* VCO 2666 VCO 3200 VCO 4000 VCO 5333 */
53 { 222, 228, 222, 222, },
54 { 333, 320, 333, 333, },
55 };
56 const int f0_12 = (pci_read_config16(igd_dev, 0xf0) >> 12) & 1;
57 const int vco = raminit_read_vco_index();
58 reg16 = pci_read_config16(igd_dev, 0xcc);
59 reg16 &= 0xfc00;
60 reg16 |= display_clock_from_f0_and_vco[f0_12][vco];
61 pci_write_config16(igd_dev, 0xcc, reg16);
62
Patrick Georgi2efc8802012-11-06 11:03:53 +010063 reg16 = pci_read_config16(mch_dev, D0F0_GGC);
64 reg16 &= 0xf00f;
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +020065 reg16 |= sysinfo->ggc;
Patrick Georgi2efc8802012-11-06 11:03:53 +010066 pci_write_config16(mch_dev, D0F0_GGC, reg16);
67
68 if ((sysinfo->gfx_type != GMCH_GL40) &&
69 (sysinfo->gfx_type != GMCH_GS40) &&
70 (sysinfo->gfx_type != GMCH_GL43)) {
71 const u32 deven = pci_read_config32(mch_dev, D0F0_DEVEN);
72 if (!(deven & 2))
73 /* Enable PEG temporarily to access D1:F0. */
74 pci_write_config32(mch_dev, D0F0_DEVEN, deven | 2);
75
76 /* Some IGD related settings on D1:F0. */
77 reg16 = pci_read_config16(peg_dev, 0xa08);
78 reg16 &= ~(1 << 15);
79 pci_write_config16(peg_dev, 0xa08, reg16);
80
81 reg16 = pci_read_config16(peg_dev, 0xa84);
82 reg16 |= (1 << 8);
83 pci_write_config16(peg_dev, 0xa84, reg16);
84
85 reg16 = pci_read_config16(peg_dev, 0xb00);
86 reg16 |= (3 << 8) | (7 << 3);
87 pci_write_config16(peg_dev, 0xb00, reg16);
88
89 reg32 = pci_read_config32(peg_dev, 0xb14);
90 reg32 &= ~(1 << 17);
91 pci_write_config32(peg_dev, 0xb14, reg32);
92
93 if (!(deven & 2) || no_peg) {
94 /* Disable PEG finally. */
95 printk(BIOS_DEBUG, "Finally disabling "
96 "PEG in favor of IGD.\n");
97 MCHBAR8(0xc14) |= (1 << 5) | (1 << 0);
98
99 reg32 = pci_read_config32(peg_dev, 0x200);
100 reg32 |= (1 << 18);
101 pci_write_config32(peg_dev, 0x200, reg32);
102 reg16 = pci_read_config16(peg_dev, 0x224);
103 reg16 |= (1 << 8);
104 pci_write_config16(peg_dev, 0x224, reg16);
105 reg32 = pci_read_config32(peg_dev, 0x200);
106 reg32 &= ~(1 << 18);
107 pci_write_config32(peg_dev, 0x200, reg32);
108 while (pci_read_config32(peg_dev, 0x214) & 0x000f0000);
109
110 pci_write_config32(mch_dev, D0F0_DEVEN, deven & ~2);
111 MCHBAR8(0xc14) &= ~((1 << 5) | (1 << 0));
112 }
113 }
114}
115
116static void disable_igd(const sysinfo_t *const sysinfo)
117{
118 const device_t mch_dev = PCI_DEV(0, 0, 0);
119
120 printk(BIOS_DEBUG, "Disabling IGD.\n");
121
122 u16 reg16;
123
124 reg16 = pci_read_config16(mch_dev, D0F0_GGC);
125 reg16 &= 0xff0f; /* Disable Graphics Stolen Memory. */
126 reg16 |= 0x0002; /* Disable IGD. */
127 pci_write_config16(mch_dev, D0F0_GGC, reg16);
128 MCHBAR8(0xf10) |= (1 << 0);
129
130 if (!(pci_read_config8(mch_dev, D0F0_CAPID0 + 4) & (1 << (33 - 32)))) {
131 MCHBAR16(0x1190) |= (1 << 14);
132 MCHBAR16(0x119e) = (MCHBAR16(0x119e) & ~(7 << 13)) | (4 << 13);
133 MCHBAR16(0x119e) |= (1 << 12);
134 }
135}
136
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200137void init_igd(const sysinfo_t *const sysinfo)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100138{
139 const device_t mch_dev = PCI_DEV(0, 0, 0);
140
141 const u8 capid = pci_read_config8(mch_dev, D0F0_CAPID0 + 4);
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200142 if (!sysinfo->enable_igd || (capid & (1 << (33 - 32))))
Patrick Georgi2efc8802012-11-06 11:03:53 +0100143 disable_igd(sysinfo);
144 else
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200145 enable_igd(sysinfo, !sysinfo->enable_peg);
146}
147
148void igd_compute_ggc(sysinfo_t *const sysinfo)
149{
150 const device_t mch_dev = PCI_DEV(0, 0, 0);
151
152 const u32 capid = pci_read_config32(mch_dev, D0F0_CAPID0 + 4);
153 if (!sysinfo->enable_igd || (capid & (1 << (33 - 32))))
154 sysinfo->ggc = 0x0002;
155 else {
156 u8 gfxsize;
157
158 /* Graphics Stolen Memory: 2MB GTT (0x0300) when VT-d disabled,
159 2MB GTT + 2MB shadow GTT (0x0b00) else. */
160 if (get_option(&gfxsize, "gfx_uma_size") != CB_SUCCESS) {
161 /* 0 for 32MB */
162 gfxsize = 0;
163 }
164 sysinfo->ggc = 0x0300 | ((gfxsize + 5) << 4);
165 if (!(capid & (1 << (48 - 32))))
166 sysinfo->ggc |= 0x0800;
167 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100168}