blob: ff8820cf288d3b0bf6ab1971e5dd8a94dbc3d6f5 [file] [log] [blame]
Damien Zammit43a1f782015-08-19 15:16:59 +10001/*
2 * This file is part of the coreboot project.
3 *
Damien Zammit43a1f782015-08-19 15:16:59 +10004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
Damien Zammit43a1f782015-08-19 15:16:59 +100015#include <console/console.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100016#include <device/device.h>
17#include <device/pci.h>
18#include <device/pci_ids.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100019#include <device/pci_ops.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020020#include <commonlib/helpers.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020021#include <cbmem.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100022#include <drivers/intel/gma/intel_bios.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020023#include <drivers/intel/gma/edid.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100024#include <drivers/intel/gma/i915.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020025#include <drivers/intel/gma/opregion.h>
Nico Huberf2dd0492017-10-29 15:42:44 +010026#include <drivers/intel/gma/libgfxinit.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100027#include <pc80/vga.h>
Elyes HAOUAS51401c32019-05-15 21:09:30 +020028#include <types.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100029
Elyes HAOUASbf0970e2019-03-21 11:10:03 +010030#include "chip.h"
31#include "drivers/intel/gma/i915_reg.h"
32#include "x4x.h"
33
Julius Wernercd49cce2019-03-05 16:53:33 -080034#if CONFIG(SOUTHBRIDGE_INTEL_I82801JX)
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020035#include <southbridge/intel/i82801jx/nvs.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080036#elif CONFIG(SOUTHBRIDGE_INTEL_I82801GX)
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020037#include <southbridge/intel/i82801gx/nvs.h>
38#endif
39
Arthur Heymansde14ea72016-09-04 16:01:11 +020040#define BASE_FREQUENCY 96000
41
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020042uintptr_t gma_get_gnvs_aslb(const void *gnvs)
43{
44 const global_nvs_t *gnvs_ptr = gnvs;
45 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
46}
47
48void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
49{
50 global_nvs_t *gnvs_ptr = gnvs;
51 if (gnvs_ptr)
52 gnvs_ptr->aslb = aslb;
53}
54
Damien Zammit43a1f782015-08-19 15:16:59 +100055static void gma_func0_init(struct device *dev)
56{
57 u32 reg32;
58
59 /* IGD needs to be Bus Master */
60 reg32 = pci_read_config32(dev, PCI_COMMAND);
61 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
62 pci_write_config32(dev, PCI_COMMAND, reg32);
63
Arthur Heymansde14ea72016-09-04 16:01:11 +020064 /* configure GMBUSFREQ */
Nico Huber15b83da2019-01-12 15:05:20 +010065 pci_update_config16(dev, 0xcc, ~0x1ff, 0xbc);
Arthur Heymansde14ea72016-09-04 16:01:11 +020066
Stefan Tauner3e3bae02018-09-03 19:02:13 +020067 int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1;
Arthur Heymans2e7efe62017-05-06 18:05:57 +020068
Julius Wernercd49cce2019-03-05 16:53:33 -080069 if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +020070 if (vga_disable) {
71 printk(BIOS_INFO,
72 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
73 } else {
74 int lightup_ok;
75 gma_gfxinit(&lightup_ok);
76 }
Arthur Heymans2e7efe62017-05-06 18:05:57 +020077 } else {
Damien Zammit216fc502016-01-22 19:13:18 +110078 pci_dev_init(dev);
Arthur Heymans2e7efe62017-05-06 18:05:57 +020079 }
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020080
81 intel_gma_restore_opregion();
Damien Zammit43a1f782015-08-19 15:16:59 +100082}
83
Arthur Heymansc80748c2017-02-26 23:04:51 +010084static void gma_func0_disable(struct device *dev)
85{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030086 struct device *dev_host = pcidev_on_root(0, 0);
Arthur Heymansc80748c2017-02-26 23:04:51 +010087 u16 ggc;
88
89 ggc = pci_read_config16(dev_host, D0F0_GGC);
90 ggc |= (1 << 1); /* VGA cycles to discrete GPU */
91 pci_write_config16(dev_host, D0F0_GGC, ggc);
92}
93
Damien Zammit43a1f782015-08-19 15:16:59 +100094const struct i915_gpu_controller_info *
95intel_gma_get_controller_info(void)
96{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030097 struct device *dev = pcidev_on_root(0x2, 0);
Arthur Heymans70a1dda2017-03-09 01:58:24 +010098 if (!dev)
Damien Zammit43a1f782015-08-19 15:16:59 +100099 return NULL;
Damien Zammit43a1f782015-08-19 15:16:59 +1000100 struct northbridge_intel_x4x_config *chip = dev->chip_info;
101 return &chip->gfx;
102}
103
Elyes HAOUASfea02e12018-02-08 14:59:03 +0100104static void gma_ssdt(struct device *device)
Damien Zammit43a1f782015-08-19 15:16:59 +1000105{
106 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100107 if (!gfx)
Damien Zammit43a1f782015-08-19 15:16:59 +1000108 return;
Damien Zammit43a1f782015-08-19 15:16:59 +1000109
110 drivers_intel_gma_displays_ssdt_generate(gfx);
111}
112
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200113static unsigned long
114gma_write_acpi_tables(struct device *const dev,
115 unsigned long current,
116 struct acpi_rsdp *const rsdp)
117{
118 igd_opregion_t *opregion = (igd_opregion_t *)current;
119 global_nvs_t *gnvs;
120
121 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
122 return current;
123
124 current += sizeof(igd_opregion_t);
125
126 /* GNVS has been already set up */
127 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
128 if (gnvs) {
129 /* IGD OpRegion Base Address */
130 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
131 } else {
132 printk(BIOS_ERR, "Error: GNVS table not found.\n");
133 }
134
135 current = acpi_align_current(current);
136 return current;
137}
138
139static const char *gma_acpi_name(const struct device *dev)
140{
141 return "GFX0";
142}
143
Damien Zammit43a1f782015-08-19 15:16:59 +1000144static struct pci_operations gma_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530145 .set_subsystem = pci_dev_set_subsystem,
Damien Zammit43a1f782015-08-19 15:16:59 +1000146};
147
148static struct device_operations gma_func0_ops = {
149 .read_resources = pci_dev_read_resources,
150 .set_resources = pci_dev_set_resources,
151 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200152 .acpi_fill_ssdt = gma_ssdt,
Damien Zammit43a1f782015-08-19 15:16:59 +1000153 .init = gma_func0_init,
Damien Zammit43a1f782015-08-19 15:16:59 +1000154 .ops_pci = &gma_pci_ops,
Arthur Heymansc80748c2017-02-26 23:04:51 +0100155 .disable = gma_func0_disable,
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200156 .acpi_name = gma_acpi_name,
157 .write_acpi_tables = gma_write_acpi_tables,
Damien Zammit43a1f782015-08-19 15:16:59 +1000158};
159
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100160static const unsigned short pci_device_ids[] = {
Arthur Heymans9e70ce02016-12-16 15:32:32 +0100161 0x2e02, /* Eaglelake */
162 0x2e12, /* Q43/Q45 */
163 0x2e22, /* G43/G45 */
164 0x2e32, /* G41 */
165 0x2e42, /* B43 */
166 0x2e92, /* B43_I */
167 0
Damien Zammit43a1f782015-08-19 15:16:59 +1000168};
169
170static const struct pci_driver gma __pci_driver = {
171 .ops = &gma_func0_ops,
172 .vendor = PCI_VENDOR_ID_INTEL,
173 .devices = pci_device_ids,
174};