blob: 4c276349559c9ca83a160bdce17b48174668c0e4 [file] [log] [blame]
Damien Zammit43a1f782015-08-19 15:16:59 +10001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Chromium OS Authors
5 * Copyright (C) 2013 Vladimir Serbinenko
6 * Copyright (C) 2015 Damien Zammit <damien@zamaudio.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <arch/io.h>
19#include <console/console.h>
20#include <delay.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <string.h>
25#include <device/pci_ops.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020026#include <commonlib/helpers.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020027#include <cbmem.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100028
29#include "drivers/intel/gma/i915_reg.h"
30#include "chip.h"
31#include "x4x.h"
32#include <drivers/intel/gma/intel_bios.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020033#include <drivers/intel/gma/edid.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100034#include <drivers/intel/gma/i915.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020035#include <drivers/intel/gma/opregion.h>
Nico Huberf2dd0492017-10-29 15:42:44 +010036#include <drivers/intel/gma/libgfxinit.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100037#include <pc80/vga.h>
38#include <pc80/vga_io.h>
39
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020040#if IS_ENABLED(CONFIG_SOUTHBRIDGE_INTEL_I82801JX)
41#include <southbridge/intel/i82801jx/nvs.h>
42#elif IS_ENABLED(CONFIG_SOUTHBRIDGE_INTEL_I82801GX)
43#include <southbridge/intel/i82801gx/nvs.h>
44#endif
45
Arthur Heymansde14ea72016-09-04 16:01:11 +020046#define BASE_FREQUENCY 96000
47
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020048uintptr_t gma_get_gnvs_aslb(const void *gnvs)
49{
50 const global_nvs_t *gnvs_ptr = gnvs;
51 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
52}
53
54void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
55{
56 global_nvs_t *gnvs_ptr = gnvs;
57 if (gnvs_ptr)
58 gnvs_ptr->aslb = aslb;
59}
60
Damien Zammit43a1f782015-08-19 15:16:59 +100061static void gma_func0_init(struct device *dev)
62{
63 u32 reg32;
64
65 /* IGD needs to be Bus Master */
66 reg32 = pci_read_config32(dev, PCI_COMMAND);
67 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
68 pci_write_config32(dev, PCI_COMMAND, reg32);
69
Arthur Heymansde14ea72016-09-04 16:01:11 +020070 /* configure GMBUSFREQ */
Nico Huber15b83da2019-01-12 15:05:20 +010071 pci_update_config16(dev, 0xcc, ~0x1ff, 0xbc);
Arthur Heymansde14ea72016-09-04 16:01:11 +020072
Stefan Tauner3e3bae02018-09-03 19:02:13 +020073 int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1;
Arthur Heymans2e7efe62017-05-06 18:05:57 +020074
Arthur Heymanse8093052018-06-07 19:19:42 +020075 if (IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +020076 if (vga_disable) {
77 printk(BIOS_INFO,
78 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
79 } else {
80 int lightup_ok;
81 gma_gfxinit(&lightup_ok);
82 }
Arthur Heymans2e7efe62017-05-06 18:05:57 +020083 } else {
Damien Zammit216fc502016-01-22 19:13:18 +110084 pci_dev_init(dev);
Arthur Heymans2e7efe62017-05-06 18:05:57 +020085 }
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020086
87 intel_gma_restore_opregion();
Damien Zammit43a1f782015-08-19 15:16:59 +100088}
89
Arthur Heymansc80748c2017-02-26 23:04:51 +010090static void gma_func0_disable(struct device *dev)
91{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030092 struct device *dev_host = pcidev_on_root(0, 0);
Arthur Heymansc80748c2017-02-26 23:04:51 +010093 u16 ggc;
94
95 ggc = pci_read_config16(dev_host, D0F0_GGC);
96 ggc |= (1 << 1); /* VGA cycles to discrete GPU */
97 pci_write_config16(dev_host, D0F0_GGC, ggc);
98}
99
Elyes HAOUASfea02e12018-02-08 14:59:03 +0100100static void gma_set_subsystem(struct device *dev, unsigned int vendor,
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100101 unsigned int device)
Damien Zammit43a1f782015-08-19 15:16:59 +1000102{
103 if (!vendor || !device) {
104 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
105 pci_read_config32(dev, PCI_VENDOR_ID));
106 } else {
107 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
108 ((device & 0xffff) << 16) | (vendor &
109 0xffff));
110 }
111}
112
113const struct i915_gpu_controller_info *
114intel_gma_get_controller_info(void)
115{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300116 struct device *dev = pcidev_on_root(0x2, 0);
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100117 if (!dev)
Damien Zammit43a1f782015-08-19 15:16:59 +1000118 return NULL;
Damien Zammit43a1f782015-08-19 15:16:59 +1000119 struct northbridge_intel_x4x_config *chip = dev->chip_info;
120 return &chip->gfx;
121}
122
Elyes HAOUASfea02e12018-02-08 14:59:03 +0100123static void gma_ssdt(struct device *device)
Damien Zammit43a1f782015-08-19 15:16:59 +1000124{
125 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100126 if (!gfx)
Damien Zammit43a1f782015-08-19 15:16:59 +1000127 return;
Damien Zammit43a1f782015-08-19 15:16:59 +1000128
129 drivers_intel_gma_displays_ssdt_generate(gfx);
130}
131
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200132static unsigned long
133gma_write_acpi_tables(struct device *const dev,
134 unsigned long current,
135 struct acpi_rsdp *const rsdp)
136{
137 igd_opregion_t *opregion = (igd_opregion_t *)current;
138 global_nvs_t *gnvs;
139
140 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
141 return current;
142
143 current += sizeof(igd_opregion_t);
144
145 /* GNVS has been already set up */
146 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
147 if (gnvs) {
148 /* IGD OpRegion Base Address */
149 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
150 } else {
151 printk(BIOS_ERR, "Error: GNVS table not found.\n");
152 }
153
154 current = acpi_align_current(current);
155 return current;
156}
157
158static const char *gma_acpi_name(const struct device *dev)
159{
160 return "GFX0";
161}
162
Damien Zammit43a1f782015-08-19 15:16:59 +1000163static struct pci_operations gma_pci_ops = {
164 .set_subsystem = gma_set_subsystem,
165};
166
167static struct device_operations gma_func0_ops = {
168 .read_resources = pci_dev_read_resources,
169 .set_resources = pci_dev_set_resources,
170 .enable_resources = pci_dev_enable_resources,
171 .acpi_fill_ssdt_generator = gma_ssdt,
172 .init = gma_func0_init,
Damien Zammit43a1f782015-08-19 15:16:59 +1000173 .ops_pci = &gma_pci_ops,
Arthur Heymansc80748c2017-02-26 23:04:51 +0100174 .disable = gma_func0_disable,
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200175 .acpi_name = gma_acpi_name,
176 .write_acpi_tables = gma_write_acpi_tables,
Damien Zammit43a1f782015-08-19 15:16:59 +1000177};
178
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100179static const unsigned short pci_device_ids[] = {
Arthur Heymans9e70ce02016-12-16 15:32:32 +0100180 0x2e02, /* Eaglelake */
181 0x2e12, /* Q43/Q45 */
182 0x2e22, /* G43/G45 */
183 0x2e32, /* G41 */
184 0x2e42, /* B43 */
185 0x2e92, /* B43_I */
186 0
Damien Zammit43a1f782015-08-19 15:16:59 +1000187};
188
189static const struct pci_driver gma __pci_driver = {
190 .ops = &gma_func0_ops,
191 .vendor = PCI_VENDOR_ID_INTEL,
192 .devices = pci_device_ids,
193};