blob: 8eebd1241c076b51c769db28b3dedb5ba62bde19 [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>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <intelblocks/graphics.h>
22#include <soc/pci_devs.h>
23
24/* SoC Overrides */
Aaron Durbin64031672018-04-21 14:45:32 -060025__weak void graphics_soc_init(struct device *dev)
Subrata Banikfa7cc782017-11-27 18:23:36 +053026{
27 /*
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010028 * User needs to implement SoC override in case wishes
Subrata Banikfa7cc782017-11-27 18:23:36 +053029 * to perform certain specific graphics initialization
30 * along with pci_dev_init(dev)
31 */
32 pci_dev_init(dev);
33}
34
35static uintptr_t graphics_get_bar(unsigned long index)
36{
37 struct device *dev = SA_DEV_IGD;
38 struct resource *gm_res;
John Zhaoeac84ca2018-08-13 09:45:37 -070039 assert(dev != NULL);
Subrata Banikfa7cc782017-11-27 18:23:36 +053040
41 /* Check if Graphics PCI device is disabled */
John Zhaoeac84ca2018-08-13 09:45:37 -070042 if (!dev || !dev->enabled)
Subrata Banikfa7cc782017-11-27 18:23:36 +053043 return 0;
44
45 gm_res = find_resource(dev, index);
46 if (!gm_res)
47 return 0;
48
49 return gm_res->base;
50}
51
52uintptr_t graphics_get_memory_base(void)
53{
54 /*
55 * GFX PCI config space offset 0x18 know as Graphics
56 * Memory Range Address (GMADR)
57 */
58 uintptr_t memory_base = graphics_get_bar(PCI_BASE_ADDRESS_2);
59 if (!memory_base)
60 die("GMADR is not programmed!");
61
62 return memory_base;
63}
64
65static uintptr_t graphics_get_gtt_base(void)
66{
67 /*
68 * GFX PCI config space offset 0x10 know as Graphics
69 * Translation Table Memory Mapped Range Address
70 * (GTTMMADR)
71 */
72 static uintptr_t gtt_base;
73 if (!gtt_base) {
74 gtt_base = graphics_get_bar(PCI_BASE_ADDRESS_0);
75 if (!gtt_base)
76 die("GTTMMADR is not programmed!");
77 }
78 return gtt_base;
79}
80
81uint32_t graphics_gtt_read(unsigned long reg)
82{
83 return read32((void *)(graphics_get_gtt_base() + reg));
84}
85
86void graphics_gtt_write(unsigned long reg, uint32_t data)
87{
88 write32((void *)(graphics_get_gtt_base() + reg), data);
89}
90
91void graphics_gtt_rmw(unsigned long reg, uint32_t andmask, uint32_t ormask)
92{
93 uint32_t val = graphics_gtt_read(reg);
94 val &= andmask;
95 val |= ormask;
96 graphics_gtt_write(reg, val);
97}
98
99static const struct device_operations graphics_ops = {
100 .read_resources = pci_dev_read_resources,
101 .set_resources = pci_dev_set_resources,
102 .enable_resources = pci_dev_enable_resources,
103 .init = graphics_soc_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530104 .ops_pci = &pci_dev_ops_pci,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530105 .write_acpi_tables = graphics_soc_write_acpi_opregion,
106};
107
108static const unsigned short pci_device_ids[] = {
109 PCI_DEVICE_ID_INTEL_APL_IGD_HD_505,
110 PCI_DEVICE_ID_INTEL_APL_IGD_HD_500,
111 PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_1,
112 PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_2,
113 PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_3,
114 PCI_DEVICE_ID_INTEL_CNL_GT2_ULX_4,
115 PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_1,
116 PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_2,
117 PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_3,
118 PCI_DEVICE_ID_INTEL_CNL_GT2_ULT_4,
119 PCI_DEVICE_ID_INTEL_GLK_IGD,
120 PCI_DEVICE_ID_INTEL_GLK_IGD_EU12,
Lijian Zhao34745f62019-02-15 05:36:50 -0800121 PCI_DEVICE_ID_INTEL_WHL_GT1_ULT_1,
Krzysztof Sywulabf7ad372018-07-17 10:45:21 -0700122 PCI_DEVICE_ID_INTEL_WHL_GT2_ULT_1,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530123 PCI_DEVICE_ID_INTEL_KBL_GT1_SULTM,
124 PCI_DEVICE_ID_INTEL_KBL_GT2_SULXM,
125 PCI_DEVICE_ID_INTEL_KBL_GT2_SULTM,
126 PCI_DEVICE_ID_INTEL_KBL_GT2_SULTMR,
127 PCI_DEVICE_ID_INTEL_KBL_GT2_SHALM,
V Sowmyaacc2a482018-01-23 15:27:23 +0530128 PCI_DEVICE_ID_INTEL_KBL_GT2_DT2P2,
Gaggery Tsai8aee7f72018-08-03 11:40:55 -0700129 PCI_DEVICE_ID_INTEL_AML_GT2_ULX,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530130 PCI_DEVICE_ID_INTEL_SKL_GT1_SULTM,
131 PCI_DEVICE_ID_INTEL_SKL_GT2_SULXM,
132 PCI_DEVICE_ID_INTEL_SKL_GT2_SULTM,
133 PCI_DEVICE_ID_INTEL_SKL_GT2_SHALM,
134 PCI_DEVICE_ID_INTEL_SKL_GT2_SWKSM,
135 PCI_DEVICE_ID_INTEL_SKL_GT4_SHALM,
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +0800136 PCI_DEVICE_ID_INTEL_CFL_H_GT2,
137 PCI_DEVICE_ID_INTEL_CFL_S_GT2,
Aamir Bohra9eac0392018-06-30 12:07:04 +0530138 PCI_DEVICE_ID_INTEL_ICL_GT0_ULT,
139 PCI_DEVICE_ID_INTEL_ICL_GT0_5_ULT,
140 PCI_DEVICE_ID_INTEL_ICL_GT1_ULT,
141 PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_0,
142 PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_1,
143 PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_1,
144 PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_2,
145 PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_2,
146 PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_3,
147 PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_3,
148 PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_4,
149 PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_4,
150 PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_5,
151 PCI_DEVICE_ID_INTEL_ICL_GT2_ULT_5,
152 PCI_DEVICE_ID_INTEL_ICL_GT2_ULX_6,
153 PCI_DEVICE_ID_INTEL_ICL_GT3_ULT,
Subrata Banikfa7cc782017-11-27 18:23:36 +0530154 0,
155};
156
157static const struct pci_driver graphics_driver __pci_driver = {
158 .ops = &graphics_ops,
159 .vendor = PCI_VENDOR_ID_INTEL,
160 .devices = pci_device_ids,
161};