blob: 4ed60e1f01dbaa367d6ccda97fc35f7bab0f5c49 [file] [log] [blame]
Jani Nikula707d26d2019-08-07 15:04:15 +03001// SPDX-License-Identifier: MIT
2/*
3 * Copyright 2019 Intel Corporation.
4 */
5
6#include "i915_drv.h"
7#include "intel_pch.h"
8
9/* Map PCH device id to PCH type, or PCH_NONE if unknown. */
10static enum intel_pch
11intel_pch_type(const struct drm_i915_private *dev_priv, unsigned short id)
12{
13 switch (id) {
14 case INTEL_PCH_IBX_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030015 drm_dbg_kms(&dev_priv->drm, "Found Ibex Peak PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030016 WARN_ON(!IS_GEN(dev_priv, 5));
17 return PCH_IBX;
18 case INTEL_PCH_CPT_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030019 drm_dbg_kms(&dev_priv->drm, "Found CougarPoint PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030020 WARN_ON(!IS_GEN(dev_priv, 6) && !IS_IVYBRIDGE(dev_priv));
21 return PCH_CPT;
22 case INTEL_PCH_PPT_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030023 drm_dbg_kms(&dev_priv->drm, "Found PantherPoint PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030024 WARN_ON(!IS_GEN(dev_priv, 6) && !IS_IVYBRIDGE(dev_priv));
25 /* PantherPoint is CPT compatible */
26 return PCH_CPT;
27 case INTEL_PCH_LPT_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030028 drm_dbg_kms(&dev_priv->drm, "Found LynxPoint PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030029 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
30 WARN_ON(IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv));
31 return PCH_LPT;
32 case INTEL_PCH_LPT_LP_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030033 drm_dbg_kms(&dev_priv->drm, "Found LynxPoint LP PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030034 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
35 WARN_ON(!IS_HSW_ULT(dev_priv) && !IS_BDW_ULT(dev_priv));
36 return PCH_LPT;
37 case INTEL_PCH_WPT_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030038 drm_dbg_kms(&dev_priv->drm, "Found WildcatPoint PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030039 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
40 WARN_ON(IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv));
41 /* WildcatPoint is LPT compatible */
42 return PCH_LPT;
43 case INTEL_PCH_WPT_LP_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030044 drm_dbg_kms(&dev_priv->drm, "Found WildcatPoint LP PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030045 WARN_ON(!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv));
46 WARN_ON(!IS_HSW_ULT(dev_priv) && !IS_BDW_ULT(dev_priv));
47 /* WildcatPoint is LPT compatible */
48 return PCH_LPT;
49 case INTEL_PCH_SPT_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030050 drm_dbg_kms(&dev_priv->drm, "Found SunrisePoint PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030051 WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv));
52 return PCH_SPT;
53 case INTEL_PCH_SPT_LP_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030054 drm_dbg_kms(&dev_priv->drm, "Found SunrisePoint LP PCH\n");
James Ausmusa201b002019-10-17 12:42:03 -070055 WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv) &&
56 !IS_COFFEELAKE(dev_priv));
Jani Nikula707d26d2019-08-07 15:04:15 +030057 return PCH_SPT;
58 case INTEL_PCH_KBP_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030059 drm_dbg_kms(&dev_priv->drm, "Found Kaby Lake PCH (KBP)\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030060 WARN_ON(!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv) &&
61 !IS_COFFEELAKE(dev_priv));
62 /* KBP is SPT compatible */
63 return PCH_SPT;
64 case INTEL_PCH_CNP_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030065 drm_dbg_kms(&dev_priv->drm, "Found Cannon Lake PCH (CNP)\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030066 WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv));
67 return PCH_CNP;
68 case INTEL_PCH_CNP_LP_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030069 drm_dbg_kms(&dev_priv->drm,
70 "Found Cannon Lake LP PCH (CNP-LP)\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030071 WARN_ON(!IS_CANNONLAKE(dev_priv) && !IS_COFFEELAKE(dev_priv));
72 return PCH_CNP;
73 case INTEL_PCH_CMP_DEVICE_ID_TYPE:
Matt Roper8698ba52019-09-16 16:32:51 -070074 case INTEL_PCH_CMP2_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030075 drm_dbg_kms(&dev_priv->drm, "Found Comet Lake PCH (CMP)\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030076 WARN_ON(!IS_COFFEELAKE(dev_priv));
77 /* CometPoint is CNP Compatible */
78 return PCH_CNP;
Imre Deak50a50652019-11-12 12:46:08 +020079 case INTEL_PCH_CMP_V_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030080 drm_dbg_kms(&dev_priv->drm, "Found Comet Lake V PCH (CMP-V)\n");
Imre Deak50a50652019-11-12 12:46:08 +020081 WARN_ON(!IS_COFFEELAKE(dev_priv));
82 /* Comet Lake V PCH is based on KBP, which is SPT compatible */
83 return PCH_SPT;
Jani Nikula707d26d2019-08-07 15:04:15 +030084 case INTEL_PCH_ICP_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030085 drm_dbg_kms(&dev_priv->drm, "Found Ice Lake PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030086 WARN_ON(!IS_ICELAKE(dev_priv));
87 return PCH_ICP;
88 case INTEL_PCH_MCC_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030089 drm_dbg_kms(&dev_priv->drm, "Found Mule Creek Canyon PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030090 WARN_ON(!IS_ELKHARTLAKE(dev_priv));
91 return PCH_MCC;
92 case INTEL_PCH_TGP_DEVICE_ID_TYPE:
James Ausmus6cf6e592019-11-05 16:55:26 -080093 case INTEL_PCH_TGP2_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030094 drm_dbg_kms(&dev_priv->drm, "Found Tiger Lake LP PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +030095 WARN_ON(!IS_TIGERLAKE(dev_priv));
96 return PCH_TGP;
Matt Roper943682e2019-10-15 09:28:54 -070097 case INTEL_PCH_JSP_DEVICE_ID_TYPE:
98 case INTEL_PCH_JSP2_DEVICE_ID_TYPE:
Wambui Karuga0f699582020-01-07 18:13:29 +030099 drm_dbg_kms(&dev_priv->drm, "Found Jasper Lake PCH\n");
Matt Roper943682e2019-10-15 09:28:54 -0700100 WARN_ON(!IS_ELKHARTLAKE(dev_priv));
101 return PCH_JSP;
Jani Nikula707d26d2019-08-07 15:04:15 +0300102 default:
103 return PCH_NONE;
104 }
105}
106
107static bool intel_is_virt_pch(unsigned short id,
108 unsigned short svendor, unsigned short sdevice)
109{
110 return (id == INTEL_PCH_P2X_DEVICE_ID_TYPE ||
111 id == INTEL_PCH_P3X_DEVICE_ID_TYPE ||
112 (id == INTEL_PCH_QEMU_DEVICE_ID_TYPE &&
113 svendor == PCI_SUBVENDOR_ID_REDHAT_QUMRANET &&
114 sdevice == PCI_SUBDEVICE_ID_QEMU));
115}
116
117static unsigned short
118intel_virt_detect_pch(const struct drm_i915_private *dev_priv)
119{
120 unsigned short id = 0;
121
122 /*
123 * In a virtualized passthrough environment we can be in a
124 * setup where the ISA bridge is not able to be passed through.
125 * In this case, a south bridge can be emulated and we have to
126 * make an educated guess as to which PCH is really there.
127 */
128
129 if (IS_TIGERLAKE(dev_priv))
130 id = INTEL_PCH_TGP_DEVICE_ID_TYPE;
131 else if (IS_ELKHARTLAKE(dev_priv))
132 id = INTEL_PCH_MCC_DEVICE_ID_TYPE;
133 else if (IS_ICELAKE(dev_priv))
134 id = INTEL_PCH_ICP_DEVICE_ID_TYPE;
135 else if (IS_CANNONLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
136 id = INTEL_PCH_CNP_DEVICE_ID_TYPE;
137 else if (IS_KABYLAKE(dev_priv) || IS_SKYLAKE(dev_priv))
138 id = INTEL_PCH_SPT_DEVICE_ID_TYPE;
139 else if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
140 id = INTEL_PCH_LPT_LP_DEVICE_ID_TYPE;
141 else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
142 id = INTEL_PCH_LPT_DEVICE_ID_TYPE;
143 else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
144 id = INTEL_PCH_CPT_DEVICE_ID_TYPE;
145 else if (IS_GEN(dev_priv, 5))
146 id = INTEL_PCH_IBX_DEVICE_ID_TYPE;
147
148 if (id)
Wambui Karuga0f699582020-01-07 18:13:29 +0300149 drm_dbg_kms(&dev_priv->drm, "Assuming PCH ID %04x\n", id);
Jani Nikula707d26d2019-08-07 15:04:15 +0300150 else
Wambui Karuga0f699582020-01-07 18:13:29 +0300151 drm_dbg_kms(&dev_priv->drm, "Assuming no PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +0300152
153 return id;
154}
155
156void intel_detect_pch(struct drm_i915_private *dev_priv)
157{
158 struct pci_dev *pch = NULL;
159
160 /*
161 * The reason to probe ISA bridge instead of Dev31:Fun0 is to
162 * make graphics device passthrough work easy for VMM, that only
163 * need to expose ISA bridge to let driver know the real hardware
164 * underneath. This is a requirement from virtualization team.
165 *
166 * In some virtualized environments (e.g. XEN), there is irrelevant
167 * ISA bridge in the system. To work reliably, we should scan trhough
168 * all the ISA bridge devices and check for the first match, instead
169 * of only checking the first one.
170 */
171 while ((pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, pch))) {
172 unsigned short id;
173 enum intel_pch pch_type;
174
175 if (pch->vendor != PCI_VENDOR_ID_INTEL)
176 continue;
177
178 id = pch->device & INTEL_PCH_DEVICE_ID_MASK;
179
180 pch_type = intel_pch_type(dev_priv, id);
181 if (pch_type != PCH_NONE) {
182 dev_priv->pch_type = pch_type;
183 dev_priv->pch_id = id;
184 break;
185 } else if (intel_is_virt_pch(id, pch->subsystem_vendor,
186 pch->subsystem_device)) {
187 id = intel_virt_detect_pch(dev_priv);
188 pch_type = intel_pch_type(dev_priv, id);
189
190 /* Sanity check virtual PCH id */
191 if (WARN_ON(id && pch_type == PCH_NONE))
192 id = 0;
193
194 dev_priv->pch_type = pch_type;
195 dev_priv->pch_id = id;
196 break;
197 }
198 }
199
200 /*
201 * Use PCH_NOP (PCH but no South Display) for PCH platforms without
202 * display.
203 */
204 if (pch && !HAS_DISPLAY(dev_priv)) {
Wambui Karuga0f699582020-01-07 18:13:29 +0300205 drm_dbg_kms(&dev_priv->drm,
206 "Display disabled, reverting to NOP PCH\n");
Jani Nikula707d26d2019-08-07 15:04:15 +0300207 dev_priv->pch_type = PCH_NOP;
208 dev_priv->pch_id = 0;
209 }
210
211 if (!pch)
Wambui Karuga0f699582020-01-07 18:13:29 +0300212 drm_dbg_kms(&dev_priv->drm, "No PCH found.\n");
Jani Nikula707d26d2019-08-07 15:04:15 +0300213
214 pci_dev_put(pch);
215}