Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 3 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 4 | #include <console/console.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 9 | #include <commonlib/helpers.h> |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 10 | #include <cbmem.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 11 | #include <drivers/intel/gma/intel_bios.h> |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 12 | #include <drivers/intel/gma/edid.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 13 | #include <drivers/intel/gma/i915.h> |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 14 | #include <drivers/intel/gma/opregion.h> |
Nico Huber | f2dd049 | 2017-10-29 15:42:44 +0100 | [diff] [blame] | 15 | #include <drivers/intel/gma/libgfxinit.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 16 | #include <pc80/vga.h> |
Elyes HAOUAS | 51401c3 | 2019-05-15 21:09:30 +0200 | [diff] [blame] | 17 | #include <types.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 18 | |
Elyes HAOUAS | bf0970e | 2019-03-21 11:10:03 +0100 | [diff] [blame] | 19 | #include "chip.h" |
| 20 | #include "drivers/intel/gma/i915_reg.h" |
| 21 | #include "x4x.h" |
| 22 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 23 | #if CONFIG(SOUTHBRIDGE_INTEL_I82801JX) |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 24 | #include <southbridge/intel/i82801jx/nvs.h> |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 25 | #elif CONFIG(SOUTHBRIDGE_INTEL_I82801GX) |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 26 | #include <southbridge/intel/i82801gx/nvs.h> |
| 27 | #endif |
| 28 | |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 29 | #define BASE_FREQUENCY 96000 |
| 30 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 31 | uintptr_t gma_get_gnvs_aslb(const void *gnvs) |
| 32 | { |
| 33 | const global_nvs_t *gnvs_ptr = gnvs; |
| 34 | return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0); |
| 35 | } |
| 36 | |
| 37 | void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb) |
| 38 | { |
| 39 | global_nvs_t *gnvs_ptr = gnvs; |
| 40 | if (gnvs_ptr) |
| 41 | gnvs_ptr->aslb = aslb; |
| 42 | } |
| 43 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 44 | static void gma_func0_init(struct device *dev) |
| 45 | { |
| 46 | u32 reg32; |
| 47 | |
| 48 | /* IGD needs to be Bus Master */ |
| 49 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 50 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 51 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 52 | |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 53 | /* configure GMBUSFREQ */ |
Nico Huber | 15b83da | 2019-01-12 15:05:20 +0100 | [diff] [blame] | 54 | pci_update_config16(dev, 0xcc, ~0x1ff, 0xbc); |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 55 | |
Stefan Tauner | 3e3bae0 | 2018-09-03 19:02:13 +0200 | [diff] [blame] | 56 | int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1; |
Arthur Heymans | 2e7efe6 | 2017-05-06 18:05:57 +0200 | [diff] [blame] | 57 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 58 | if (CONFIG(MAINBOARD_USE_LIBGFXINIT)) { |
Arthur Heymans | e6c8f7e | 2018-08-09 11:31:51 +0200 | [diff] [blame] | 59 | if (vga_disable) { |
| 60 | printk(BIOS_INFO, |
| 61 | "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n"); |
| 62 | } else { |
| 63 | int lightup_ok; |
| 64 | gma_gfxinit(&lightup_ok); |
| 65 | } |
Arthur Heymans | 2e7efe6 | 2017-05-06 18:05:57 +0200 | [diff] [blame] | 66 | } else { |
Damien Zammit | 216fc50 | 2016-01-22 19:13:18 +1100 | [diff] [blame] | 67 | pci_dev_init(dev); |
Arthur Heymans | 2e7efe6 | 2017-05-06 18:05:57 +0200 | [diff] [blame] | 68 | } |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 69 | |
| 70 | intel_gma_restore_opregion(); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 71 | } |
| 72 | |
Arthur Heymans | c80748c | 2017-02-26 23:04:51 +0100 | [diff] [blame] | 73 | static void gma_func0_disable(struct device *dev) |
| 74 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 75 | struct device *dev_host = pcidev_on_root(0, 0); |
Arthur Heymans | c80748c | 2017-02-26 23:04:51 +0100 | [diff] [blame] | 76 | u16 ggc; |
| 77 | |
| 78 | ggc = pci_read_config16(dev_host, D0F0_GGC); |
| 79 | ggc |= (1 << 1); /* VGA cycles to discrete GPU */ |
| 80 | pci_write_config16(dev_host, D0F0_GGC, ggc); |
| 81 | } |
| 82 | |
Matt DeVillier | 33f89ee | 2020-03-30 22:16:37 -0500 | [diff] [blame] | 83 | static void gma_generate_ssdt(struct device *device) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 84 | { |
Matt DeVillier | 33f89ee | 2020-03-30 22:16:37 -0500 | [diff] [blame] | 85 | const struct northbridge_intel_x4x_config *chip = device->chip_info; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 86 | |
Matt DeVillier | 33f89ee | 2020-03-30 22:16:37 -0500 | [diff] [blame] | 87 | drivers_intel_gma_displays_ssdt_generate(&chip->gfx); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 88 | } |
| 89 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 90 | static unsigned long |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 91 | gma_write_acpi_tables(const struct device *const dev, |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 92 | unsigned long current, |
| 93 | struct acpi_rsdp *const rsdp) |
| 94 | { |
| 95 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
| 96 | global_nvs_t *gnvs; |
| 97 | |
| 98 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
| 99 | return current; |
| 100 | |
| 101 | current += sizeof(igd_opregion_t); |
| 102 | |
| 103 | /* GNVS has been already set up */ |
| 104 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 105 | if (gnvs) { |
| 106 | /* IGD OpRegion Base Address */ |
| 107 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
| 108 | } else { |
| 109 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
| 110 | } |
| 111 | |
| 112 | current = acpi_align_current(current); |
| 113 | return current; |
| 114 | } |
| 115 | |
| 116 | static const char *gma_acpi_name(const struct device *dev) |
| 117 | { |
| 118 | return "GFX0"; |
| 119 | } |
| 120 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 121 | static struct pci_operations gma_pci_ops = { |
Subrata Banik | 4a0f071 | 2019-03-20 14:29:47 +0530 | [diff] [blame] | 122 | .set_subsystem = pci_dev_set_subsystem, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | static struct device_operations gma_func0_ops = { |
Matt DeVillier | 33f89ee | 2020-03-30 22:16:37 -0500 | [diff] [blame] | 126 | .read_resources = pci_dev_read_resources, |
| 127 | .set_resources = pci_dev_set_resources, |
| 128 | .enable_resources = pci_dev_enable_resources, |
| 129 | .acpi_fill_ssdt = gma_generate_ssdt, |
| 130 | .init = gma_func0_init, |
| 131 | .ops_pci = &gma_pci_ops, |
| 132 | .disable = gma_func0_disable, |
| 133 | .acpi_name = gma_acpi_name, |
| 134 | .write_acpi_tables = gma_write_acpi_tables, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 135 | }; |
| 136 | |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 137 | static const unsigned short pci_device_ids[] = { |
Arthur Heymans | 9e70ce0 | 2016-12-16 15:32:32 +0100 | [diff] [blame] | 138 | 0x2e02, /* Eaglelake */ |
| 139 | 0x2e12, /* Q43/Q45 */ |
| 140 | 0x2e22, /* G43/G45 */ |
| 141 | 0x2e32, /* G41 */ |
| 142 | 0x2e42, /* B43 */ |
| 143 | 0x2e92, /* B43_I */ |
| 144 | 0 |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | static const struct pci_driver gma __pci_driver = { |
| 148 | .ops = &gma_func0_ops, |
| 149 | .vendor = PCI_VENDOR_ID_INTEL, |
| 150 | .devices = pci_device_ids, |
| 151 | }; |