blob: 2c045e6fd14decc71610fe3d5007ba2092c8ebf4 [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
Damien Zammit43a1f782015-08-19 15:16:59 +100018#include <console/console.h>
19#include <delay.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100023#include <device/pci_ops.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020024#include <commonlib/helpers.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020025#include <cbmem.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100026
27#include "drivers/intel/gma/i915_reg.h"
28#include "chip.h"
29#include "x4x.h"
30#include <drivers/intel/gma/intel_bios.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020031#include <drivers/intel/gma/edid.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100032#include <drivers/intel/gma/i915.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020033#include <drivers/intel/gma/opregion.h>
Nico Huberf2dd0492017-10-29 15:42:44 +010034#include <drivers/intel/gma/libgfxinit.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100035#include <pc80/vga.h>
36#include <pc80/vga_io.h>
37
Julius Wernercd49cce2019-03-05 16:53:33 -080038#if CONFIG(SOUTHBRIDGE_INTEL_I82801JX)
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020039#include <southbridge/intel/i82801jx/nvs.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080040#elif CONFIG(SOUTHBRIDGE_INTEL_I82801GX)
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020041#include <southbridge/intel/i82801gx/nvs.h>
42#endif
43
Arthur Heymansde14ea72016-09-04 16:01:11 +020044#define BASE_FREQUENCY 96000
45
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020046uintptr_t gma_get_gnvs_aslb(const void *gnvs)
47{
48 const global_nvs_t *gnvs_ptr = gnvs;
49 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
50}
51
52void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
53{
54 global_nvs_t *gnvs_ptr = gnvs;
55 if (gnvs_ptr)
56 gnvs_ptr->aslb = aslb;
57}
58
Damien Zammit43a1f782015-08-19 15:16:59 +100059static void gma_func0_init(struct device *dev)
60{
61 u32 reg32;
62
63 /* IGD needs to be Bus Master */
64 reg32 = pci_read_config32(dev, PCI_COMMAND);
65 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
66 pci_write_config32(dev, PCI_COMMAND, reg32);
67
Arthur Heymansde14ea72016-09-04 16:01:11 +020068 /* configure GMBUSFREQ */
Nico Huber15b83da2019-01-12 15:05:20 +010069 pci_update_config16(dev, 0xcc, ~0x1ff, 0xbc);
Arthur Heymansde14ea72016-09-04 16:01:11 +020070
Stefan Tauner3e3bae02018-09-03 19:02:13 +020071 int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1;
Arthur Heymans2e7efe62017-05-06 18:05:57 +020072
Julius Wernercd49cce2019-03-05 16:53:33 -080073 if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +020074 if (vga_disable) {
75 printk(BIOS_INFO,
76 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
77 } else {
78 int lightup_ok;
79 gma_gfxinit(&lightup_ok);
80 }
Arthur Heymans2e7efe62017-05-06 18:05:57 +020081 } else {
Damien Zammit216fc502016-01-22 19:13:18 +110082 pci_dev_init(dev);
Arthur Heymans2e7efe62017-05-06 18:05:57 +020083 }
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020084
85 intel_gma_restore_opregion();
Damien Zammit43a1f782015-08-19 15:16:59 +100086}
87
Arthur Heymansc80748c2017-02-26 23:04:51 +010088static void gma_func0_disable(struct device *dev)
89{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030090 struct device *dev_host = pcidev_on_root(0, 0);
Arthur Heymansc80748c2017-02-26 23:04:51 +010091 u16 ggc;
92
93 ggc = pci_read_config16(dev_host, D0F0_GGC);
94 ggc |= (1 << 1); /* VGA cycles to discrete GPU */
95 pci_write_config16(dev_host, D0F0_GGC, ggc);
96}
97
Elyes HAOUASfea02e12018-02-08 14:59:03 +010098static void gma_set_subsystem(struct device *dev, unsigned int vendor,
Arthur Heymans70a1dda2017-03-09 01:58:24 +010099 unsigned int device)
Damien Zammit43a1f782015-08-19 15:16:59 +1000100{
101 if (!vendor || !device) {
102 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
103 pci_read_config32(dev, PCI_VENDOR_ID));
104 } else {
105 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
106 ((device & 0xffff) << 16) | (vendor &
107 0xffff));
108 }
109}
110
111const struct i915_gpu_controller_info *
112intel_gma_get_controller_info(void)
113{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300114 struct device *dev = pcidev_on_root(0x2, 0);
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100115 if (!dev)
Damien Zammit43a1f782015-08-19 15:16:59 +1000116 return NULL;
Damien Zammit43a1f782015-08-19 15:16:59 +1000117 struct northbridge_intel_x4x_config *chip = dev->chip_info;
118 return &chip->gfx;
119}
120
Elyes HAOUASfea02e12018-02-08 14:59:03 +0100121static void gma_ssdt(struct device *device)
Damien Zammit43a1f782015-08-19 15:16:59 +1000122{
123 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100124 if (!gfx)
Damien Zammit43a1f782015-08-19 15:16:59 +1000125 return;
Damien Zammit43a1f782015-08-19 15:16:59 +1000126
127 drivers_intel_gma_displays_ssdt_generate(gfx);
128}
129
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200130static unsigned long
131gma_write_acpi_tables(struct device *const dev,
132 unsigned long current,
133 struct acpi_rsdp *const rsdp)
134{
135 igd_opregion_t *opregion = (igd_opregion_t *)current;
136 global_nvs_t *gnvs;
137
138 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
139 return current;
140
141 current += sizeof(igd_opregion_t);
142
143 /* GNVS has been already set up */
144 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
145 if (gnvs) {
146 /* IGD OpRegion Base Address */
147 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
148 } else {
149 printk(BIOS_ERR, "Error: GNVS table not found.\n");
150 }
151
152 current = acpi_align_current(current);
153 return current;
154}
155
156static const char *gma_acpi_name(const struct device *dev)
157{
158 return "GFX0";
159}
160
Damien Zammit43a1f782015-08-19 15:16:59 +1000161static struct pci_operations gma_pci_ops = {
162 .set_subsystem = gma_set_subsystem,
163};
164
165static struct device_operations gma_func0_ops = {
166 .read_resources = pci_dev_read_resources,
167 .set_resources = pci_dev_set_resources,
168 .enable_resources = pci_dev_enable_resources,
169 .acpi_fill_ssdt_generator = gma_ssdt,
170 .init = gma_func0_init,
Damien Zammit43a1f782015-08-19 15:16:59 +1000171 .ops_pci = &gma_pci_ops,
Arthur Heymansc80748c2017-02-26 23:04:51 +0100172 .disable = gma_func0_disable,
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200173 .acpi_name = gma_acpi_name,
174 .write_acpi_tables = gma_write_acpi_tables,
Damien Zammit43a1f782015-08-19 15:16:59 +1000175};
176
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100177static const unsigned short pci_device_ids[] = {
Arthur Heymans9e70ce02016-12-16 15:32:32 +0100178 0x2e02, /* Eaglelake */
179 0x2e12, /* Q43/Q45 */
180 0x2e22, /* G43/G45 */
181 0x2e32, /* G41 */
182 0x2e42, /* B43 */
183 0x2e92, /* B43_I */
184 0
Damien Zammit43a1f782015-08-19 15:16:59 +1000185};
186
187static const struct pci_driver gma __pci_driver = {
188 .ops = &gma_func0_ops,
189 .vendor = PCI_VENDOR_ID_INTEL,
190 .devices = pci_device_ids,
191};