blob: 651b07cf881dd42b8ce37c1acbd829f78bc2b2d8 [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
Matt DeVillier33f89ee2020-03-30 22:16:37 -050094static void gma_generate_ssdt(struct device *device)
Damien Zammit43a1f782015-08-19 15:16:59 +100095{
Matt DeVillier33f89ee2020-03-30 22:16:37 -050096 const struct northbridge_intel_x4x_config *chip = device->chip_info;
Damien Zammit43a1f782015-08-19 15:16:59 +100097
Matt DeVillier33f89ee2020-03-30 22:16:37 -050098 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
Damien Zammit43a1f782015-08-19 15:16:59 +100099}
100
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200101static unsigned long
102gma_write_acpi_tables(struct device *const dev,
103 unsigned long current,
104 struct acpi_rsdp *const rsdp)
105{
106 igd_opregion_t *opregion = (igd_opregion_t *)current;
107 global_nvs_t *gnvs;
108
109 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
110 return current;
111
112 current += sizeof(igd_opregion_t);
113
114 /* GNVS has been already set up */
115 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
116 if (gnvs) {
117 /* IGD OpRegion Base Address */
118 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
119 } else {
120 printk(BIOS_ERR, "Error: GNVS table not found.\n");
121 }
122
123 current = acpi_align_current(current);
124 return current;
125}
126
127static const char *gma_acpi_name(const struct device *dev)
128{
129 return "GFX0";
130}
131
Damien Zammit43a1f782015-08-19 15:16:59 +1000132static struct pci_operations gma_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530133 .set_subsystem = pci_dev_set_subsystem,
Damien Zammit43a1f782015-08-19 15:16:59 +1000134};
135
136static struct device_operations gma_func0_ops = {
Matt DeVillier33f89ee2020-03-30 22:16:37 -0500137 .read_resources = pci_dev_read_resources,
138 .set_resources = pci_dev_set_resources,
139 .enable_resources = pci_dev_enable_resources,
140 .acpi_fill_ssdt = gma_generate_ssdt,
141 .init = gma_func0_init,
142 .ops_pci = &gma_pci_ops,
143 .disable = gma_func0_disable,
144 .acpi_name = gma_acpi_name,
145 .write_acpi_tables = gma_write_acpi_tables,
Damien Zammit43a1f782015-08-19 15:16:59 +1000146};
147
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100148static const unsigned short pci_device_ids[] = {
Arthur Heymans9e70ce02016-12-16 15:32:32 +0100149 0x2e02, /* Eaglelake */
150 0x2e12, /* Q43/Q45 */
151 0x2e22, /* G43/G45 */
152 0x2e32, /* G41 */
153 0x2e42, /* B43 */
154 0x2e92, /* B43_I */
155 0
Damien Zammit43a1f782015-08-19 15:16:59 +1000156};
157
158static const struct pci_driver gma __pci_driver = {
159 .ops = &gma_func0_ops,
160 .vendor = PCI_VENDOR_ID_INTEL,
161 .devices = pci_device_ids,
162};