blob: 9de5126034fb771bee36f142e74995469994c789 [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Lee Leahy32471722015-04-20 15:20:28 -07003#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -07004#include <console/console.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -07005#include <device/device.h>
6#include <device/pci.h>
7#include <device/pci_ids.h>
Matt DeVillier132bbe62017-07-01 13:02:47 -05008#include <drivers/intel/gma/opregion.h>
Matt DeVillier8ff2ecd2020-03-29 16:58:48 -05009#include <drivers/intel/gma/i915.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070010#include <reg_script.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070011#include <soc/gfx.h>
Matt DeVillier132bbe62017-07-01 13:02:47 -050012#include <soc/nvs.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070013#include <soc/pci_devs.h>
14#include <soc/ramstage.h>
15
Lee Leahy77ff0b12015-05-05 15:07:29 -070016static const struct reg_script gpu_pre_vbios_script[] = {
17 /* Make sure GFX is bus master with MMIO access */
18 REG_PCI_OR32(PCI_COMMAND, PCI_COMMAND_MASTER|PCI_COMMAND_MEMORY),
Lee Leahy77ff0b12015-05-05 15:07:29 -070019 REG_SCRIPT_END
20};
21
22static const struct reg_script gfx_post_vbios_script[] = {
Lee Leahy77ff0b12015-05-05 15:07:29 -070023 /* Set Lock bits */
Angel Ponsaee7ab22020-03-19 00:31:58 +010024 REG_PCI_RMW32(GGC, 0xffffffff, GGC_GGCLCK),
Lee Leahy32471722015-04-20 15:20:28 -070025 REG_PCI_RMW32(GSM_BASE, 0xffffffff, GSM_BDSM_LOCK),
26 REG_PCI_RMW32(GTT_BASE, 0xffffffff, GTT_BGSM_LOCK),
Lee Leahy77ff0b12015-05-05 15:07:29 -070027 REG_SCRIPT_END
28};
29
Angel Ponsaee7ab22020-03-19 00:31:58 +010030static inline void gfx_run_script(struct device *dev, const struct reg_script *ops)
Lee Leahy77ff0b12015-05-05 15:07:29 -070031{
32 reg_script_run_on_dev(dev, ops);
33}
34
Elyes HAOUASb13fac32018-05-24 22:29:44 +020035static void gfx_pre_vbios_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070036{
Angel Ponsaee7ab22020-03-19 00:31:58 +010037 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070038 printk(BIOS_INFO, "GFX: Pre VBIOS Init\n");
39 gfx_run_script(dev, gpu_pre_vbios_script);
40}
41
Elyes HAOUASb13fac32018-05-24 22:29:44 +020042static void gfx_post_vbios_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070043{
Angel Ponsaee7ab22020-03-19 00:31:58 +010044 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070045 printk(BIOS_INFO, "GFX: Post VBIOS Init\n");
46 gfx_run_script(dev, gfx_post_vbios_script);
47}
48
Elyes HAOUASb13fac32018-05-24 22:29:44 +020049static void gfx_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070050{
Angel Ponsaee7ab22020-03-19 00:31:58 +010051 printk(BIOS_SPEW, "%s/%s (%s)\n", __FILE__, __func__, dev_name(dev));
Lee Leahy32471722015-04-20 15:20:28 -070052
Julius Wernercd49cce2019-03-05 16:53:33 -080053 if (!CONFIG(RUN_FSP_GOP)) {
Matt DeVilliera9492a62018-06-20 00:40:48 -050054 /* Pre VBIOS Init */
55 gfx_pre_vbios_init(dev);
Lee Leahy77ff0b12015-05-05 15:07:29 -070056
Matt DeVilliera9492a62018-06-20 00:40:48 -050057 /* Run VBIOS */
58 pci_dev_init(dev);
Lee Leahy77ff0b12015-05-05 15:07:29 -070059
Matt DeVilliera9492a62018-06-20 00:40:48 -050060 /* Post VBIOS Init */
61 gfx_post_vbios_init(dev);
62 }
Matt DeVillier132bbe62017-07-01 13:02:47 -050063 intel_gma_restore_opregion();
64}
65
66uintptr_t gma_get_gnvs_aslb(const void *gnvs)
67{
68 const global_nvs_t *gnvs_ptr = gnvs;
69 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
70}
71
72void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
73{
74 global_nvs_t *gnvs_ptr = gnvs;
75 if (gnvs_ptr)
76 gnvs_ptr->aslb = aslb;
Lee Leahy77ff0b12015-05-05 15:07:29 -070077}
78
Furquan Shaikh7536a392020-04-24 21:59:21 -070079static void gma_generate_ssdt(const struct device *dev)
Matt DeVillier8ff2ecd2020-03-29 16:58:48 -050080{
81 const struct soc_intel_braswell_config *chip = dev->chip_info;
82
83 drivers_intel_gma_displays_ssdt_generate(&chip->gfx);
84}
85
Lee Leahy77ff0b12015-05-05 15:07:29 -070086static struct device_operations gfx_device_ops = {
Nico Huber1ef80142015-11-05 23:27:06 +010087 .read_resources = pci_dev_read_resources,
Lee Leahy77ff0b12015-05-05 15:07:29 -070088 .set_resources = pci_dev_set_resources,
89 .enable_resources = pci_dev_enable_resources,
90 .init = gfx_init,
91 .ops_pci = &soc_pci_ops,
Matt DeVillier8ff2ecd2020-03-29 16:58:48 -050092 .acpi_fill_ssdt = gma_generate_ssdt,
Lee Leahy77ff0b12015-05-05 15:07:29 -070093};
94
95static const struct pci_driver gfx_driver __pci_driver = {
96 .ops = &gfx_device_ops,
97 .vendor = PCI_VENDOR_ID_INTEL,
98 .device = GFX_DEVID,
99};