blob: 41b2c6f2a7332cd02010a536475c3fe2d4784bc3 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy77ff0b12015-05-05 15:07:29 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 */
14
Lee Leahy32471722015-04-20 15:20:28 -070015#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070016#include <console/console.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070017#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
Matt DeVillier132bbe62017-07-01 13:02:47 -050020#include <drivers/intel/gma/opregion.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070021#include <reg_script.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070022#include <soc/gfx.h>
Matt DeVillier132bbe62017-07-01 13:02:47 -050023#include <soc/nvs.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070024#include <soc/pci_devs.h>
25#include <soc/ramstage.h>
26
Lee Leahy77ff0b12015-05-05 15:07:29 -070027static const struct reg_script gpu_pre_vbios_script[] = {
28 /* Make sure GFX is bus master with MMIO access */
29 REG_PCI_OR32(PCI_COMMAND, PCI_COMMAND_MASTER|PCI_COMMAND_MEMORY),
Lee Leahy77ff0b12015-05-05 15:07:29 -070030 REG_SCRIPT_END
31};
32
33static const struct reg_script gfx_post_vbios_script[] = {
Lee Leahy77ff0b12015-05-05 15:07:29 -070034 /* Set Lock bits */
Lee Leahy32471722015-04-20 15:20:28 -070035 REG_PCI_RMW32(GGC, 0xffffffff, GGC_GGCLCK),
36 REG_PCI_RMW32(GSM_BASE, 0xffffffff, GSM_BDSM_LOCK),
37 REG_PCI_RMW32(GTT_BASE, 0xffffffff, GTT_BGSM_LOCK),
Lee Leahy77ff0b12015-05-05 15:07:29 -070038 REG_SCRIPT_END
39};
40
Elyes HAOUASb13fac32018-05-24 22:29:44 +020041static inline void gfx_run_script(struct device *dev,
42 const struct reg_script *ops)
Lee Leahy77ff0b12015-05-05 15:07:29 -070043{
44 reg_script_run_on_dev(dev, ops);
45}
46
Elyes HAOUASb13fac32018-05-24 22:29:44 +020047static void gfx_pre_vbios_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070048{
Elyes HAOUASa342f392018-10-17 10:56:26 +020049 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070050 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070051 printk(BIOS_INFO, "GFX: Pre VBIOS Init\n");
52 gfx_run_script(dev, gpu_pre_vbios_script);
53}
54
Elyes HAOUASb13fac32018-05-24 22:29:44 +020055static void gfx_post_vbios_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070056{
Elyes HAOUASa342f392018-10-17 10:56:26 +020057 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070058 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070059 printk(BIOS_INFO, "GFX: Post VBIOS Init\n");
60 gfx_run_script(dev, gfx_post_vbios_script);
61}
62
Elyes HAOUASb13fac32018-05-24 22:29:44 +020063static void gfx_init(struct device *dev)
Lee Leahy77ff0b12015-05-05 15:07:29 -070064{
Elyes HAOUASa342f392018-10-17 10:56:26 +020065 printk(BIOS_SPEW, "%s/%s (%s)\n",
Lee Leahy32471722015-04-20 15:20:28 -070066 __FILE__, __func__, dev_name(dev));
67
Julius Wernercd49cce2019-03-05 16:53:33 -080068 if (!CONFIG(RUN_FSP_GOP)) {
Matt DeVilliera9492a62018-06-20 00:40:48 -050069 /* Pre VBIOS Init */
70 gfx_pre_vbios_init(dev);
Lee Leahy77ff0b12015-05-05 15:07:29 -070071
Matt DeVilliera9492a62018-06-20 00:40:48 -050072 /* Run VBIOS */
73 pci_dev_init(dev);
Lee Leahy77ff0b12015-05-05 15:07:29 -070074
Matt DeVilliera9492a62018-06-20 00:40:48 -050075 /* Post VBIOS Init */
76 gfx_post_vbios_init(dev);
77 }
Matt DeVillier132bbe62017-07-01 13:02:47 -050078 intel_gma_restore_opregion();
79}
80
81uintptr_t gma_get_gnvs_aslb(const void *gnvs)
82{
83 const global_nvs_t *gnvs_ptr = gnvs;
84 return (uintptr_t)(gnvs_ptr ? gnvs_ptr->aslb : 0);
85}
86
87void gma_set_gnvs_aslb(void *gnvs, uintptr_t aslb)
88{
89 global_nvs_t *gnvs_ptr = gnvs;
90 if (gnvs_ptr)
91 gnvs_ptr->aslb = aslb;
Lee Leahy77ff0b12015-05-05 15:07:29 -070092}
93
94static struct device_operations gfx_device_ops = {
Nico Huber1ef80142015-11-05 23:27:06 +010095 .read_resources = pci_dev_read_resources,
Lee Leahy77ff0b12015-05-05 15:07:29 -070096 .set_resources = pci_dev_set_resources,
97 .enable_resources = pci_dev_enable_resources,
98 .init = gfx_init,
99 .ops_pci = &soc_pci_ops,
100};
101
102static const struct pci_driver gfx_driver __pci_driver = {
103 .ops = &gfx_device_ops,
104 .vendor = PCI_VENDOR_ID_INTEL,
105 .device = GFX_DEVID,
106};