blob: 5d3b4a15cf9dd605c5d8476cdff591232078b99b [file] [log] [blame]
Subrata Banikfa7cc782017-11-27 18:23:36 +05301/*
2 * This file is part of the coreboot project.
3 *
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +08004 * Copyright (C) 2017-2018 Intel Corp.
Subrata Banikfa7cc782017-11-27 18:23:36 +05305 *
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 Zhaoeac84ca2018-08-13 09:45:37 -070017#include <assert.h>
Subrata Banikfa7cc782017-11-27 18:23:36 +053018#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020019#include <device/mmio.h>
Subrata Banikfa7cc782017-11-27 18:23:36 +053020#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 Durbin64031672018-04-21 14:45:32 -060026__weak void graphics_soc_init(struct device *dev)
Subrata Banikfa7cc782017-11-27 18:23:36 +053027{
28 /*
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010029 * User needs to implement SoC override in case wishes
Subrata Banikfa7cc782017-11-27 18:23:36 +053030 * to perform certain specific graphics initialization
31 * along with pci_dev_init(dev)
32 */
33 pci_dev_init(dev);
34}
35
36static uintptr_t graphics_get_bar(unsigned long index)
37{
38 struct device *dev = SA_DEV_IGD;
39 struct resource *gm_res;
John Zhaoeac84ca2018-08-13 09:45:37 -070040 assert(dev != NULL);
Subrata Banikfa7cc782017-11-27 18:23:36 +053041
42 /* Check if Graphics PCI device is disabled */
John Zhaoeac84ca2018-08-13 09:45:37 -070043 if (!dev || !dev->enabled)
Subrata Banikfa7cc782017-11-27 18:23:36 +053044 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
53uintptr_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
66static 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
82uint32_t graphics_gtt_read(unsigned long reg)
83{
84 return read32((void *)(graphics_get_gtt_base() + reg));
85}
86
87void graphics_gtt_write(unsigned long reg, uint32_t data)
88{
89 write32((void *)(graphics_get_gtt_base() + reg), data);
90}
91
92void 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
100static 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 Banik6bbc91a2017-12-07 14:55:51 +0530105 .ops_pci = &pci_dev_ops_pci,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530106 .write_acpi_tables = graphics_soc_write_acpi_opregion,
107};
108
109static 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 Zhao34745f62019-02-15 05:36:50 -0800122 PCI_DEVICE_ID_INTEL_WHL_GT1_ULT_1,
Krzysztof Sywulabf7ad372018-07-17 10:45:21 -0700123 PCI_DEVICE_ID_INTEL_WHL_GT2_ULT_1,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530124 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 Sowmyaacc2a482018-01-23 15:27:23 +0530129 PCI_DEVICE_ID_INTEL_KBL_GT2_DT2P2,
Gaggery Tsai8aee7f72018-08-03 11:40:55 -0700130 PCI_DEVICE_ID_INTEL_AML_GT2_ULX,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530131 PCI_DEVICE_ID_INTEL_SKL_GT1_SULTM,
Maxim Polyakov46e68522019-02-25 10:46:18 +0300132 PCI_DEVICE_ID_INTEL_SKL_GT2_DT2P1,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530133 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 praneshe26c4a42018-09-20 03:49:45 +0800138 PCI_DEVICE_ID_INTEL_CFL_H_GT2,
139 PCI_DEVICE_ID_INTEL_CFL_S_GT2,
Aamir Bohra9eac0392018-06-30 12:07:04 +0530140 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 Kanabarf606a2f2019-02-04 16:06:50 +0530156 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 Banikfa7cc782017-11-27 18:23:36 +0530174 0,
175};
176
177static const struct pci_driver graphics_driver __pci_driver = {
178 .ops = &graphics_ops,
179 .vendor = PCI_VENDOR_ID_INTEL,
180 .devices = pci_device_ids,
181};