blob: c4e8bf1cdd442f3577d30733867999c238c938e7 [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>
Damien Zammit43a1f782015-08-19 15:16:59 +100019#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100022#include <device/pci_ops.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020023#include <commonlib/helpers.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020024#include <cbmem.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100025#include <drivers/intel/gma/intel_bios.h>
Arthur Heymansde14ea72016-09-04 16:01:11 +020026#include <drivers/intel/gma/edid.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100027#include <drivers/intel/gma/i915.h>
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020028#include <drivers/intel/gma/opregion.h>
Nico Huberf2dd0492017-10-29 15:42:44 +010029#include <drivers/intel/gma/libgfxinit.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100030#include <pc80/vga.h>
31#include <pc80/vga_io.h>
32
Elyes HAOUASbf0970e2019-03-21 11:10:03 +010033#include "chip.h"
34#include "drivers/intel/gma/i915_reg.h"
35#include "x4x.h"
36
Julius Wernercd49cce2019-03-05 16:53:33 -080037#if CONFIG(SOUTHBRIDGE_INTEL_I82801JX)
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020038#include <southbridge/intel/i82801jx/nvs.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080039#elif CONFIG(SOUTHBRIDGE_INTEL_I82801GX)
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020040#include <southbridge/intel/i82801gx/nvs.h>
41#endif
42
Arthur Heymansde14ea72016-09-04 16:01:11 +020043#define BASE_FREQUENCY 96000
44
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020045uintptr_t gma_get_gnvs_aslb(const void *gnvs)
46{
47 const global_nvs_t *gnvs_ptr = gnvs;
48 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
49}
50
51void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
52{
53 global_nvs_t *gnvs_ptr = gnvs;
54 if (gnvs_ptr)
55 gnvs_ptr->aslb = aslb;
56}
57
Damien Zammit43a1f782015-08-19 15:16:59 +100058static void gma_func0_init(struct device *dev)
59{
60 u32 reg32;
61
62 /* IGD needs to be Bus Master */
63 reg32 = pci_read_config32(dev, PCI_COMMAND);
64 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
65 pci_write_config32(dev, PCI_COMMAND, reg32);
66
Arthur Heymansde14ea72016-09-04 16:01:11 +020067 /* configure GMBUSFREQ */
Nico Huber15b83da2019-01-12 15:05:20 +010068 pci_update_config16(dev, 0xcc, ~0x1ff, 0xbc);
Arthur Heymansde14ea72016-09-04 16:01:11 +020069
Stefan Tauner3e3bae02018-09-03 19:02:13 +020070 int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1;
Arthur Heymans2e7efe62017-05-06 18:05:57 +020071
Julius Wernercd49cce2019-03-05 16:53:33 -080072 if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
Arthur Heymanse6c8f7e2018-08-09 11:31:51 +020073 if (vga_disable) {
74 printk(BIOS_INFO,
75 "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n");
76 } else {
77 int lightup_ok;
78 gma_gfxinit(&lightup_ok);
79 }
Arthur Heymans2e7efe62017-05-06 18:05:57 +020080 } else {
Damien Zammit216fc502016-01-22 19:13:18 +110081 pci_dev_init(dev);
Arthur Heymans2e7efe62017-05-06 18:05:57 +020082 }
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +020083
84 intel_gma_restore_opregion();
Damien Zammit43a1f782015-08-19 15:16:59 +100085}
86
Arthur Heymansc80748c2017-02-26 23:04:51 +010087static void gma_func0_disable(struct device *dev)
88{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030089 struct device *dev_host = pcidev_on_root(0, 0);
Arthur Heymansc80748c2017-02-26 23:04:51 +010090 u16 ggc;
91
92 ggc = pci_read_config16(dev_host, D0F0_GGC);
93 ggc |= (1 << 1); /* VGA cycles to discrete GPU */
94 pci_write_config16(dev_host, D0F0_GGC, ggc);
95}
96
Damien Zammit43a1f782015-08-19 15:16:59 +100097const struct i915_gpu_controller_info *
98intel_gma_get_controller_info(void)
99{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300100 struct device *dev = pcidev_on_root(0x2, 0);
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100101 if (!dev)
Damien Zammit43a1f782015-08-19 15:16:59 +1000102 return NULL;
Damien Zammit43a1f782015-08-19 15:16:59 +1000103 struct northbridge_intel_x4x_config *chip = dev->chip_info;
104 return &chip->gfx;
105}
106
Elyes HAOUASfea02e12018-02-08 14:59:03 +0100107static void gma_ssdt(struct device *device)
Damien Zammit43a1f782015-08-19 15:16:59 +1000108{
109 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100110 if (!gfx)
Damien Zammit43a1f782015-08-19 15:16:59 +1000111 return;
Damien Zammit43a1f782015-08-19 15:16:59 +1000112
113 drivers_intel_gma_displays_ssdt_generate(gfx);
114}
115
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200116static unsigned long
117gma_write_acpi_tables(struct device *const dev,
118 unsigned long current,
119 struct acpi_rsdp *const rsdp)
120{
121 igd_opregion_t *opregion = (igd_opregion_t *)current;
122 global_nvs_t *gnvs;
123
124 if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS)
125 return current;
126
127 current += sizeof(igd_opregion_t);
128
129 /* GNVS has been already set up */
130 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
131 if (gnvs) {
132 /* IGD OpRegion Base Address */
133 gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion);
134 } else {
135 printk(BIOS_ERR, "Error: GNVS table not found.\n");
136 }
137
138 current = acpi_align_current(current);
139 return current;
140}
141
142static const char *gma_acpi_name(const struct device *dev)
143{
144 return "GFX0";
145}
146
Damien Zammit43a1f782015-08-19 15:16:59 +1000147static struct pci_operations gma_pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530148 .set_subsystem = pci_dev_set_subsystem,
Damien Zammit43a1f782015-08-19 15:16:59 +1000149};
150
151static struct device_operations gma_func0_ops = {
152 .read_resources = pci_dev_read_resources,
153 .set_resources = pci_dev_set_resources,
154 .enable_resources = pci_dev_enable_resources,
155 .acpi_fill_ssdt_generator = gma_ssdt,
156 .init = gma_func0_init,
Damien Zammit43a1f782015-08-19 15:16:59 +1000157 .ops_pci = &gma_pci_ops,
Arthur Heymansc80748c2017-02-26 23:04:51 +0100158 .disable = gma_func0_disable,
Patrick Rudolphf6aa7d92017-09-29 18:28:23 +0200159 .acpi_name = gma_acpi_name,
160 .write_acpi_tables = gma_write_acpi_tables,
Damien Zammit43a1f782015-08-19 15:16:59 +1000161};
162
Arthur Heymans70a1dda2017-03-09 01:58:24 +0100163static const unsigned short pci_device_ids[] = {
Arthur Heymans9e70ce02016-12-16 15:32:32 +0100164 0x2e02, /* Eaglelake */
165 0x2e12, /* Q43/Q45 */
166 0x2e22, /* G43/G45 */
167 0x2e32, /* G41 */
168 0x2e42, /* B43 */
169 0x2e92, /* B43_I */
170 0
Damien Zammit43a1f782015-08-19 15:16:59 +1000171};
172
173static const struct pci_driver gma __pci_driver = {
174 .ops = &gma_func0_ops,
175 .vendor = PCI_VENDOR_ID_INTEL,
176 .devices = pci_device_ids,
177};