Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1 | /* |
| 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 Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <stddef.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 19 | #include <device/pci_ops.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 20 | #include <device/pci_def.h> |
| 21 | #include <console/console.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 22 | #include <option.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 23 | |
| 24 | #include "gm45.h" |
| 25 | |
| 26 | /* TODO: Chipset supports Protected Audio Video Path (PAVP) */ |
| 27 | |
| 28 | /* TODO: We could pass DVMT structure in GetBIOSData() SCI interface */ |
| 29 | |
| 30 | /* The PEG settings have to be set before ASPM is setup on DMI. */ |
| 31 | static void enable_igd(const sysinfo_t *const sysinfo, const int no_peg) |
| 32 | { |
Furquan Shaikh | 25f75b2 | 2016-08-29 22:51:41 -0700 | [diff] [blame] | 33 | const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0); |
| 34 | const pci_devfn_t peg_dev = PCI_DEV(0, 1, 0); |
| 35 | const pci_devfn_t igd_dev = PCI_DEV(0, 2, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 36 | |
| 37 | u16 reg16; |
| 38 | u32 reg32; |
| 39 | |
| 40 | printk(BIOS_DEBUG, "Enabling IGD.\n"); |
| 41 | |
| 42 | /* HSync/VSync */ |
| 43 | MCHBAR8(0xbd0 + 3) = 0x5a; |
| 44 | MCHBAR8(0xbd0 + 4) = 0x5a; |
| 45 | |
| 46 | static const u16 display_clock_from_f0_and_vco[][4] = { |
| 47 | /* VCO 2666 VCO 3200 VCO 4000 VCO 5333 */ |
| 48 | { 222, 228, 222, 222, }, |
| 49 | { 333, 320, 333, 333, }, |
| 50 | }; |
| 51 | const int f0_12 = (pci_read_config16(igd_dev, 0xf0) >> 12) & 1; |
| 52 | const int vco = raminit_read_vco_index(); |
| 53 | reg16 = pci_read_config16(igd_dev, 0xcc); |
| 54 | reg16 &= 0xfc00; |
| 55 | reg16 |= display_clock_from_f0_and_vco[f0_12][vco]; |
| 56 | pci_write_config16(igd_dev, 0xcc, reg16); |
| 57 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 58 | reg16 = pci_read_config16(mch_dev, D0F0_GGC); |
| 59 | reg16 &= 0xf00f; |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 60 | reg16 |= sysinfo->ggc; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 61 | pci_write_config16(mch_dev, D0F0_GGC, reg16); |
| 62 | |
| 63 | if ((sysinfo->gfx_type != GMCH_GL40) && |
| 64 | (sysinfo->gfx_type != GMCH_GS40) && |
| 65 | (sysinfo->gfx_type != GMCH_GL43)) { |
| 66 | const u32 deven = pci_read_config32(mch_dev, D0F0_DEVEN); |
| 67 | if (!(deven & 2)) |
| 68 | /* Enable PEG temporarily to access D1:F0. */ |
| 69 | pci_write_config32(mch_dev, D0F0_DEVEN, deven | 2); |
| 70 | |
| 71 | /* Some IGD related settings on D1:F0. */ |
| 72 | reg16 = pci_read_config16(peg_dev, 0xa08); |
| 73 | reg16 &= ~(1 << 15); |
| 74 | pci_write_config16(peg_dev, 0xa08, reg16); |
| 75 | |
| 76 | reg16 = pci_read_config16(peg_dev, 0xa84); |
| 77 | reg16 |= (1 << 8); |
| 78 | pci_write_config16(peg_dev, 0xa84, reg16); |
| 79 | |
| 80 | reg16 = pci_read_config16(peg_dev, 0xb00); |
| 81 | reg16 |= (3 << 8) | (7 << 3); |
| 82 | pci_write_config16(peg_dev, 0xb00, reg16); |
| 83 | |
| 84 | reg32 = pci_read_config32(peg_dev, 0xb14); |
| 85 | reg32 &= ~(1 << 17); |
| 86 | pci_write_config32(peg_dev, 0xb14, reg32); |
| 87 | |
| 88 | if (!(deven & 2) || no_peg) { |
| 89 | /* Disable PEG finally. */ |
| 90 | printk(BIOS_DEBUG, "Finally disabling " |
| 91 | "PEG in favor of IGD.\n"); |
| 92 | MCHBAR8(0xc14) |= (1 << 5) | (1 << 0); |
| 93 | |
| 94 | reg32 = pci_read_config32(peg_dev, 0x200); |
| 95 | reg32 |= (1 << 18); |
| 96 | pci_write_config32(peg_dev, 0x200, reg32); |
| 97 | reg16 = pci_read_config16(peg_dev, 0x224); |
| 98 | reg16 |= (1 << 8); |
| 99 | pci_write_config16(peg_dev, 0x224, reg16); |
| 100 | reg32 = pci_read_config32(peg_dev, 0x200); |
| 101 | reg32 &= ~(1 << 18); |
| 102 | pci_write_config32(peg_dev, 0x200, reg32); |
| 103 | while (pci_read_config32(peg_dev, 0x214) & 0x000f0000); |
| 104 | |
| 105 | pci_write_config32(mch_dev, D0F0_DEVEN, deven & ~2); |
| 106 | MCHBAR8(0xc14) &= ~((1 << 5) | (1 << 0)); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | static void disable_igd(const sysinfo_t *const sysinfo) |
| 112 | { |
Furquan Shaikh | 25f75b2 | 2016-08-29 22:51:41 -0700 | [diff] [blame] | 113 | const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 114 | |
| 115 | printk(BIOS_DEBUG, "Disabling IGD.\n"); |
| 116 | |
| 117 | u16 reg16; |
| 118 | |
| 119 | reg16 = pci_read_config16(mch_dev, D0F0_GGC); |
| 120 | reg16 &= 0xff0f; /* Disable Graphics Stolen Memory. */ |
| 121 | reg16 |= 0x0002; /* Disable IGD. */ |
| 122 | pci_write_config16(mch_dev, D0F0_GGC, reg16); |
| 123 | MCHBAR8(0xf10) |= (1 << 0); |
| 124 | |
| 125 | if (!(pci_read_config8(mch_dev, D0F0_CAPID0 + 4) & (1 << (33 - 32)))) { |
| 126 | MCHBAR16(0x1190) |= (1 << 14); |
| 127 | MCHBAR16(0x119e) = (MCHBAR16(0x119e) & ~(7 << 13)) | (4 << 13); |
| 128 | MCHBAR16(0x119e) |= (1 << 12); |
| 129 | } |
Patrick Rudolph | bb1af99 | 2017-01-21 10:43:52 +0100 | [diff] [blame] | 130 | |
| 131 | /* Hide IGD. */ |
| 132 | u32 deven = pci_read_config32(mch_dev, D0F0_DEVEN); |
| 133 | deven &= ~(3 << 3); |
| 134 | pci_write_config32(mch_dev, D0F0_DEVEN, deven); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 137 | void init_igd(const sysinfo_t *const sysinfo) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 138 | { |
Furquan Shaikh | 25f75b2 | 2016-08-29 22:51:41 -0700 | [diff] [blame] | 139 | const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 140 | |
| 141 | const u8 capid = pci_read_config8(mch_dev, D0F0_CAPID0 + 4); |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 142 | if (!sysinfo->enable_igd || (capid & (1 << (33 - 32)))) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 143 | disable_igd(sysinfo); |
| 144 | else |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 145 | enable_igd(sysinfo, !sysinfo->enable_peg); |
| 146 | } |
| 147 | |
| 148 | void igd_compute_ggc(sysinfo_t *const sysinfo) |
| 149 | { |
Furquan Shaikh | 25f75b2 | 2016-08-29 22:51:41 -0700 | [diff] [blame] | 150 | const pci_devfn_t mch_dev = PCI_DEV(0, 0, 0); |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 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 { |
Elyes HAOUAS | 2119d0b | 2020-02-16 10:01:33 +0100 | [diff] [blame^] | 156 | /* 4 for 32MB, default if not set in CMOS */ |
Arthur Heymans | d65ff22 | 2017-06-13 20:57:05 +0200 | [diff] [blame] | 157 | u8 gfxsize = 4; |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 158 | |
| 159 | /* Graphics Stolen Memory: 2MB GTT (0x0300) when VT-d disabled, |
| 160 | 2MB GTT + 2MB shadow GTT (0x0b00) else. */ |
Arthur Heymans | d65ff22 | 2017-06-13 20:57:05 +0200 | [diff] [blame] | 161 | get_option(&gfxsize, "gfx_uma_size"); |
Elyes HAOUAS | 2119d0b | 2020-02-16 10:01:33 +0100 | [diff] [blame^] | 162 | /* Handle invalid CMOS settings */ |
Arthur Heymans | d65ff22 | 2017-06-13 20:57:05 +0200 | [diff] [blame] | 163 | /* Only allow settings between 32MB and 352MB */ |
| 164 | gfxsize = MIN(MAX(gfxsize, 4), 12); |
| 165 | |
Arthur Heymans | 7afcfe0 | 2016-05-19 15:34:49 +0200 | [diff] [blame] | 166 | sysinfo->ggc = 0x0300 | ((gfxsize + 1) << 4); |
Vladimir Serbinenko | 56ae8a0 | 2014-08-16 10:59:02 +0200 | [diff] [blame] | 167 | if (!(capid & (1 << (48 - 32)))) |
| 168 | sysinfo->ggc |= 0x0800; |
| 169 | } |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 170 | } |