Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 1 | /* |
| 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 Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | #include <delay.h> |
| 20 | #include <device/device.h> |
| 21 | #include <device/pci.h> |
| 22 | #include <device/pci_ids.h> |
| 23 | #include <string.h> |
| 24 | #include <device/pci_ops.h> |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 25 | #include <commonlib/helpers.h> |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 26 | #include <cbmem.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 27 | |
| 28 | #include "drivers/intel/gma/i915_reg.h" |
| 29 | #include "chip.h" |
| 30 | #include "x4x.h" |
| 31 | #include <drivers/intel/gma/intel_bios.h> |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 32 | #include <drivers/intel/gma/edid.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 33 | #include <drivers/intel/gma/i915.h> |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 34 | #include <drivers/intel/gma/opregion.h> |
Nico Huber | f2dd049 | 2017-10-29 15:42:44 +0100 | [diff] [blame] | 35 | #include <drivers/intel/gma/libgfxinit.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 36 | #include <pc80/vga.h> |
| 37 | #include <pc80/vga_io.h> |
| 38 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 39 | #if IS_ENABLED(CONFIG_SOUTHBRIDGE_INTEL_I82801JX) |
| 40 | #include <southbridge/intel/i82801jx/nvs.h> |
| 41 | #elif IS_ENABLED(CONFIG_SOUTHBRIDGE_INTEL_I82801GX) |
| 42 | #include <southbridge/intel/i82801gx/nvs.h> |
| 43 | #endif |
| 44 | |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 45 | #define BASE_FREQUENCY 96000 |
| 46 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 47 | uintptr_t gma_get_gnvs_aslb(const void *gnvs) |
| 48 | { |
| 49 | const global_nvs_t *gnvs_ptr = gnvs; |
| 50 | return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0); |
| 51 | } |
| 52 | |
| 53 | void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb) |
| 54 | { |
| 55 | global_nvs_t *gnvs_ptr = gnvs; |
| 56 | if (gnvs_ptr) |
| 57 | gnvs_ptr->aslb = aslb; |
| 58 | } |
| 59 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 60 | static void gma_func0_init(struct device *dev) |
| 61 | { |
| 62 | u32 reg32; |
| 63 | |
| 64 | /* IGD needs to be Bus Master */ |
| 65 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 66 | reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO; |
| 67 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 68 | |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 69 | /* configure GMBUSFREQ */ |
Nico Huber | 15b83da | 2019-01-12 15:05:20 +0100 | [diff] [blame] | 70 | pci_update_config16(dev, 0xcc, ~0x1ff, 0xbc); |
Arthur Heymans | de14ea7 | 2016-09-04 16:01:11 +0200 | [diff] [blame] | 71 | |
Stefan Tauner | 3e3bae0 | 2018-09-03 19:02:13 +0200 | [diff] [blame] | 72 | int vga_disable = (pci_read_config16(dev, D0F0_GGC) & 2) >> 1; |
Arthur Heymans | 2e7efe6 | 2017-05-06 18:05:57 +0200 | [diff] [blame] | 73 | |
Arthur Heymans | e809305 | 2018-06-07 19:19:42 +0200 | [diff] [blame] | 74 | if (IS_ENABLED(CONFIG_MAINBOARD_USE_LIBGFXINIT)) { |
Arthur Heymans | e6c8f7e | 2018-08-09 11:31:51 +0200 | [diff] [blame] | 75 | if (vga_disable) { |
| 76 | printk(BIOS_INFO, |
| 77 | "IGD is not decoding legacy VGA MEM and IO: skipping NATIVE graphic init\n"); |
| 78 | } else { |
| 79 | int lightup_ok; |
| 80 | gma_gfxinit(&lightup_ok); |
| 81 | } |
Arthur Heymans | 2e7efe6 | 2017-05-06 18:05:57 +0200 | [diff] [blame] | 82 | } else { |
Damien Zammit | 216fc50 | 2016-01-22 19:13:18 +1100 | [diff] [blame] | 83 | pci_dev_init(dev); |
Arthur Heymans | 2e7efe6 | 2017-05-06 18:05:57 +0200 | [diff] [blame] | 84 | } |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 85 | |
| 86 | intel_gma_restore_opregion(); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 87 | } |
| 88 | |
Arthur Heymans | c80748c | 2017-02-26 23:04:51 +0100 | [diff] [blame] | 89 | static void gma_func0_disable(struct device *dev) |
| 90 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 91 | struct device *dev_host = pcidev_on_root(0, 0); |
Arthur Heymans | c80748c | 2017-02-26 23:04:51 +0100 | [diff] [blame] | 92 | u16 ggc; |
| 93 | |
| 94 | ggc = pci_read_config16(dev_host, D0F0_GGC); |
| 95 | ggc |= (1 << 1); /* VGA cycles to discrete GPU */ |
| 96 | pci_write_config16(dev_host, D0F0_GGC, ggc); |
| 97 | } |
| 98 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 99 | static void gma_set_subsystem(struct device *dev, unsigned int vendor, |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 100 | unsigned int device) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 101 | { |
| 102 | if (!vendor || !device) { |
| 103 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 104 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 105 | } else { |
| 106 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 107 | ((device & 0xffff) << 16) | (vendor & |
| 108 | 0xffff)); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | const struct i915_gpu_controller_info * |
| 113 | intel_gma_get_controller_info(void) |
| 114 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 115 | struct device *dev = pcidev_on_root(0x2, 0); |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 116 | if (!dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 117 | return NULL; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 118 | struct northbridge_intel_x4x_config *chip = dev->chip_info; |
| 119 | return &chip->gfx; |
| 120 | } |
| 121 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 122 | static void gma_ssdt(struct device *device) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 123 | { |
| 124 | const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info(); |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 125 | if (!gfx) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 126 | return; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 127 | |
| 128 | drivers_intel_gma_displays_ssdt_generate(gfx); |
| 129 | } |
| 130 | |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 131 | static unsigned long |
| 132 | gma_write_acpi_tables(struct device *const dev, |
| 133 | unsigned long current, |
| 134 | struct acpi_rsdp *const rsdp) |
| 135 | { |
| 136 | igd_opregion_t *opregion = (igd_opregion_t *)current; |
| 137 | global_nvs_t *gnvs; |
| 138 | |
| 139 | if (intel_gma_init_igd_opregion(opregion) != CB_SUCCESS) |
| 140 | return current; |
| 141 | |
| 142 | current += sizeof(igd_opregion_t); |
| 143 | |
| 144 | /* GNVS has been already set up */ |
| 145 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 146 | if (gnvs) { |
| 147 | /* IGD OpRegion Base Address */ |
| 148 | gma_set_gnvs_aslb(gnvs, (uintptr_t)opregion); |
| 149 | } else { |
| 150 | printk(BIOS_ERR, "Error: GNVS table not found.\n"); |
| 151 | } |
| 152 | |
| 153 | current = acpi_align_current(current); |
| 154 | return current; |
| 155 | } |
| 156 | |
| 157 | static const char *gma_acpi_name(const struct device *dev) |
| 158 | { |
| 159 | return "GFX0"; |
| 160 | } |
| 161 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 162 | static struct pci_operations gma_pci_ops = { |
| 163 | .set_subsystem = gma_set_subsystem, |
| 164 | }; |
| 165 | |
| 166 | static struct device_operations gma_func0_ops = { |
| 167 | .read_resources = pci_dev_read_resources, |
| 168 | .set_resources = pci_dev_set_resources, |
| 169 | .enable_resources = pci_dev_enable_resources, |
| 170 | .acpi_fill_ssdt_generator = gma_ssdt, |
| 171 | .init = gma_func0_init, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 172 | .ops_pci = &gma_pci_ops, |
Arthur Heymans | c80748c | 2017-02-26 23:04:51 +0100 | [diff] [blame] | 173 | .disable = gma_func0_disable, |
Patrick Rudolph | f6aa7d9 | 2017-09-29 18:28:23 +0200 | [diff] [blame] | 174 | .acpi_name = gma_acpi_name, |
| 175 | .write_acpi_tables = gma_write_acpi_tables, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 176 | }; |
| 177 | |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 178 | static const unsigned short pci_device_ids[] = { |
Arthur Heymans | 9e70ce0 | 2016-12-16 15:32:32 +0100 | [diff] [blame] | 179 | 0x2e02, /* Eaglelake */ |
| 180 | 0x2e12, /* Q43/Q45 */ |
| 181 | 0x2e22, /* G43/G45 */ |
| 182 | 0x2e32, /* G41 */ |
| 183 | 0x2e42, /* B43 */ |
| 184 | 0x2e92, /* B43_I */ |
| 185 | 0 |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | static const struct pci_driver gma __pci_driver = { |
| 189 | .ops = &gma_func0_ops, |
| 190 | .vendor = PCI_VENDOR_ID_INTEL, |
| 191 | .devices = pci_device_ids, |
| 192 | }; |