Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2013 Google Inc. |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 17 | #include "chip.h" |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 18 | #include <arch/io.h> |
| 19 | #include <console/console.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 20 | #include <device/device.h> |
| 21 | #include <device/pci.h> |
| 22 | #include <device/pci_ids.h> |
| 23 | #include <reg_script.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 24 | #include <soc/gfx.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 25 | #include <soc/pci_devs.h> |
| 26 | #include <soc/ramstage.h> |
| 27 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 28 | static const struct reg_script gpu_pre_vbios_script[] = { |
| 29 | /* Make sure GFX is bus master with MMIO access */ |
| 30 | REG_PCI_OR32(PCI_COMMAND, PCI_COMMAND_MASTER|PCI_COMMAND_MEMORY), |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 31 | REG_SCRIPT_END |
| 32 | }; |
| 33 | |
| 34 | static const struct reg_script gfx_post_vbios_script[] = { |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 35 | /* Set Lock bits */ |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 36 | REG_PCI_RMW32(GGC, 0xffffffff, GGC_GGCLCK), |
| 37 | REG_PCI_RMW32(GSM_BASE, 0xffffffff, GSM_BDSM_LOCK), |
| 38 | REG_PCI_RMW32(GTT_BASE, 0xffffffff, GTT_BGSM_LOCK), |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 39 | REG_SCRIPT_END |
| 40 | }; |
| 41 | |
| 42 | static inline void gfx_run_script(device_t dev, const struct reg_script *ops) |
| 43 | { |
| 44 | reg_script_run_on_dev(dev, ops); |
| 45 | } |
| 46 | |
| 47 | static void gfx_pre_vbios_init(device_t dev) |
| 48 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 49 | printk(BIOS_SPEW, "%s/%s ( %s )\n", |
| 50 | __FILE__, __func__, dev_name(dev)); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 51 | printk(BIOS_INFO, "GFX: Pre VBIOS Init\n"); |
| 52 | gfx_run_script(dev, gpu_pre_vbios_script); |
| 53 | } |
| 54 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 55 | static void gfx_post_vbios_init(device_t dev) |
| 56 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 57 | printk(BIOS_SPEW, "%s/%s ( %s )\n", |
| 58 | __FILE__, __func__, dev_name(dev)); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 59 | printk(BIOS_INFO, "GFX: Post VBIOS Init\n"); |
| 60 | gfx_run_script(dev, gfx_post_vbios_script); |
| 61 | } |
| 62 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 63 | static void gfx_init(device_t dev) |
| 64 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 65 | printk(BIOS_SPEW, "%s/%s ( %s )\n", |
| 66 | __FILE__, __func__, dev_name(dev)); |
| 67 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 68 | /* Pre VBIOS Init */ |
| 69 | gfx_pre_vbios_init(dev); |
| 70 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 71 | /* Run VBIOS */ |
| 72 | pci_dev_init(dev); |
| 73 | |
| 74 | /* Post VBIOS Init */ |
| 75 | gfx_post_vbios_init(dev); |
| 76 | } |
| 77 | |
| 78 | static struct device_operations gfx_device_ops = { |
Nico Huber | 1ef8014 | 2015-11-05 23:27:06 +0100 | [diff] [blame^] | 79 | .read_resources = pci_dev_read_resources, |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 80 | .set_resources = pci_dev_set_resources, |
| 81 | .enable_resources = pci_dev_enable_resources, |
| 82 | .init = gfx_init, |
| 83 | .ops_pci = &soc_pci_ops, |
| 84 | }; |
| 85 | |
| 86 | static const struct pci_driver gfx_driver __pci_driver = { |
| 87 | .ops = &gfx_device_ops, |
| 88 | .vendor = PCI_VENDOR_ID_INTEL, |
| 89 | .device = GFX_DEVID, |
| 90 | }; |