Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 4 | * Copyright (C) 2017-2018 Intel Corp. |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 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. |
| 15 | */ |
| 16 | |
John Zhao | eac84ca | 2018-08-13 09:45:37 -0700 | [diff] [blame] | 17 | #include <assert.h> |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 18 | #include <console/console.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 19 | #include <device/mmio.h> |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 20 | #include <device/pci.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <intelblocks/graphics.h> |
| 23 | #include <soc/pci_devs.h> |
| 24 | |
| 25 | /* SoC Overrides */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 26 | __weak void graphics_soc_init(struct device *dev) |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 27 | { |
| 28 | /* |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 29 | * User needs to implement SoC override in case wishes |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 30 | * to perform certain specific graphics initialization |
| 31 | * along with pci_dev_init(dev) |
| 32 | */ |
| 33 | pci_dev_init(dev); |
| 34 | } |
| 35 | |
| 36 | static uintptr_t graphics_get_bar(unsigned long index) |
| 37 | { |
| 38 | struct device *dev = SA_DEV_IGD; |
| 39 | struct resource *gm_res; |
John Zhao | eac84ca | 2018-08-13 09:45:37 -0700 | [diff] [blame] | 40 | assert(dev != NULL); |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 41 | |
| 42 | /* Check if Graphics PCI device is disabled */ |
John Zhao | eac84ca | 2018-08-13 09:45:37 -0700 | [diff] [blame] | 43 | if (!dev || !dev->enabled) |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 44 | return 0; |
| 45 | |
| 46 | gm_res = find_resource(dev, index); |
| 47 | if (!gm_res) |
| 48 | return 0; |
| 49 | |
| 50 | return gm_res->base; |
| 51 | } |
| 52 | |
| 53 | uintptr_t graphics_get_memory_base(void) |
| 54 | { |
| 55 | /* |
| 56 | * GFX PCI config space offset 0x18 know as Graphics |
| 57 | * Memory Range Address (GMADR) |
| 58 | */ |
| 59 | uintptr_t memory_base = graphics_get_bar(PCI_BASE_ADDRESS_2); |
| 60 | if (!memory_base) |
| 61 | die("GMADR is not programmed!"); |
| 62 | |
| 63 | return memory_base; |
| 64 | } |
| 65 | |
| 66 | static uintptr_t graphics_get_gtt_base(void) |
| 67 | { |
| 68 | /* |
| 69 | * GFX PCI config space offset 0x10 know as Graphics |
| 70 | * Translation Table Memory Mapped Range Address |
| 71 | * (GTTMMADR) |
| 72 | */ |
| 73 | static uintptr_t gtt_base; |
| 74 | if (!gtt_base) { |
| 75 | gtt_base = graphics_get_bar(PCI_BASE_ADDRESS_0); |
| 76 | if (!gtt_base) |
| 77 | die("GTTMMADR is not programmed!"); |
| 78 | } |
| 79 | return gtt_base; |
| 80 | } |
| 81 | |
| 82 | uint32_t graphics_gtt_read(unsigned long reg) |
| 83 | { |
| 84 | return read32((void *)(graphics_get_gtt_base() + reg)); |
| 85 | } |
| 86 | |
| 87 | void graphics_gtt_write(unsigned long reg, uint32_t data) |
| 88 | { |
| 89 | write32((void *)(graphics_get_gtt_base() + reg), data); |
| 90 | } |
| 91 | |
| 92 | void graphics_gtt_rmw(unsigned long reg, uint32_t andmask, uint32_t ormask) |
| 93 | { |
| 94 | uint32_t val = graphics_gtt_read(reg); |
| 95 | val &= andmask; |
| 96 | val |= ormask; |
| 97 | graphics_gtt_write(reg, val); |
| 98 | } |
| 99 | |
| 100 | static const struct device_operations graphics_ops = { |
| 101 | .read_resources = pci_dev_read_resources, |
| 102 | .set_resources = pci_dev_set_resources, |
| 103 | .enable_resources = pci_dev_enable_resources, |
| 104 | .init = graphics_soc_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 105 | .ops_pci = &pci_dev_ops_pci, |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 106 | .write_acpi_tables = graphics_soc_write_acpi_opregion, |
| 107 | }; |
| 108 | |
| 109 | static const unsigned short pci_device_ids[] = { |
| 110 | PCI_DEVICE_ID_INTEL_APL_IGD_HD_505, |
| 111 | PCI_DEVICE_ID_INTEL_APL_IGD_HD_500, |
| 112 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_1, |
| 113 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_2, |
| 114 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_3, |
| 115 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_4, |
| 116 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_1, |
| 117 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_2, |
| 118 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_3, |
| 119 | PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_4, |
| 120 | PCI_DEVICE_ID_INTEL_GLK_IGD, |
| 121 | PCI_DEVICE_ID_INTEL_GLK_IGD_EU12, |
Lijian Zhao | 34745f6 | 2019-02-15 05:36:50 -0800 | [diff] [blame] | 122 | PCI_DEVICE_ID_INTEL_WHL_GT1_ULT_1, |
Krzysztof Sywula | bf7ad37 | 2018-07-17 10:45:21 -0700 | [diff] [blame] | 123 | PCI_DEVICE_ID_INTEL_WHL_GT2_ULT_1, |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 124 | PCI_DEVICE_ID_INTEL_KBL_GT1_SULTM, |
| 125 | PCI_DEVICE_ID_INTEL_KBL_GT2_SULXM, |
| 126 | PCI_DEVICE_ID_INTEL_KBL_GT2_SULTM, |
| 127 | PCI_DEVICE_ID_INTEL_KBL_GT2_SULTMR, |
| 128 | PCI_DEVICE_ID_INTEL_KBL_GT2_SHALM, |
V Sowmya | acc2a48 | 2018-01-23 15:27:23 +0530 | [diff] [blame] | 129 | PCI_DEVICE_ID_INTEL_KBL_GT2_DT2P2, |
Gaggery Tsai | 8aee7f7 | 2018-08-03 11:40:55 -0700 | [diff] [blame] | 130 | PCI_DEVICE_ID_INTEL_AML_GT2_ULX, |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 131 | PCI_DEVICE_ID_INTEL_SKL_GT1_SULTM, |
Maxim Polyakov | 46e6852 | 2019-02-25 10:46:18 +0300 | [diff] [blame^] | 132 | PCI_DEVICE_ID_INTEL_SKL_GT2_DT2P1, |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 133 | PCI_DEVICE_ID_INTEL_SKL_GT2_SULXM, |
| 134 | PCI_DEVICE_ID_INTEL_SKL_GT2_SULTM, |
| 135 | PCI_DEVICE_ID_INTEL_SKL_GT2_SHALM, |
| 136 | PCI_DEVICE_ID_INTEL_SKL_GT2_SWKSM, |
| 137 | PCI_DEVICE_ID_INTEL_SKL_GT4_SHALM, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 138 | PCI_DEVICE_ID_INTEL_CFL_H_GT2, |
| 139 | PCI_DEVICE_ID_INTEL_CFL_S_GT2, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 140 | PCI_DEVICE_ID_INTEL_ICL_GT0_ULT, |
| 141 | PCI_DEVICE_ID_INTEL_ICL_GT0_5_ULT, |
| 142 | PCI_DEVICE_ID_INTEL_ICL_GT1_ULT, |
| 143 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_0, |
| 144 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_1, |
| 145 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_1, |
| 146 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_2, |
| 147 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_2, |
| 148 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_3, |
| 149 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_3, |
| 150 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_4, |
| 151 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_4, |
| 152 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_5, |
| 153 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_5, |
| 154 | PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_6, |
| 155 | PCI_DEVICE_ID_INTEL_ICL_GT3_ULT, |
Ronak Kanabar | f606a2f | 2019-02-04 16:06:50 +0530 | [diff] [blame] | 156 | PCI_DEVICE_ID_INTEL_CML_GT1_ULT_1, |
| 157 | PCI_DEVICE_ID_INTEL_CML_GT1_ULT_2, |
| 158 | PCI_DEVICE_ID_INTEL_CML_GT2_ULT_1, |
| 159 | PCI_DEVICE_ID_INTEL_CML_GT2_ULT_2, |
| 160 | PCI_DEVICE_ID_INTEL_CML_GT1_ULT_3, |
| 161 | PCI_DEVICE_ID_INTEL_CML_GT1_ULT_4, |
| 162 | PCI_DEVICE_ID_INTEL_CML_GT2_ULT_3, |
| 163 | PCI_DEVICE_ID_INTEL_CML_GT2_ULT_4, |
| 164 | PCI_DEVICE_ID_INTEL_CML_GT1_ULX_1, |
| 165 | PCI_DEVICE_ID_INTEL_CML_GT2_ULX_1, |
| 166 | PCI_DEVICE_ID_INTEL_CML_GT1_S_1, |
| 167 | PCI_DEVICE_ID_INTEL_CML_GT1_S_2, |
| 168 | PCI_DEVICE_ID_INTEL_CML_GT2_S_1, |
| 169 | PCI_DEVICE_ID_INTEL_CML_GT2_S_2, |
| 170 | PCI_DEVICE_ID_INTEL_CML_GT1_H_1, |
| 171 | PCI_DEVICE_ID_INTEL_CML_GT1_H_2, |
| 172 | PCI_DEVICE_ID_INTEL_CML_GT2_H_1, |
| 173 | PCI_DEVICE_ID_INTEL_CML_GT2_H_2, |
Subrata Banik | fa7cc78 | 2017-11-27 18:23:36 +0530 | [diff] [blame] | 174 | 0, |
| 175 | }; |
| 176 | |
| 177 | static const struct pci_driver graphics_driver __pci_driver = { |
| 178 | .ops = &graphics_ops, |
| 179 | .vendor = PCI_VENDOR_ID_INTEL, |
| 180 | .devices = pci_device_ids, |
| 181 | }; |