aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-07-15 09:12:18 -0400
committerBen Skeggs <bskeggs@redhat.com>2016-07-30 04:19:48 -0400
commit692a17dcc2922a91c6bcf11b3321503a3377b1b1 (patch)
treeb02ef1a91039968996606fb62e542a0c3e24419a
parentcba97805cb69d5b1a1d3bb108872c73b5bf0e205 (diff)
drm/nouveau/acpi: fix lockup with PCIe runtime PM
Since "PCI: Add runtime PM support for PCIe ports", the parent PCIe port can be runtime-suspended which disables power resources via ACPI. This is incompatible with DSM, resulting in a GPU device which is still in D3 and locks up the kernel on resume (on a Clevo P651RA, GTX965M). Mirror the behavior of Windows 8 and newer[1] (as observed via an AMLi debugger trace) and stop using the DSM functions for D3cold when power resources are available on the parent PCIe port. pci_d3cold_disable() is not used because on some machines, the old DSM method is broken. On a Lenovo T440p (GT 730M) memory and disk corruption would occur, but that is fixed with this patch[2]. [1]: https://msdn.microsoft.com/windows/hardware/drivers/bringup/firmware-requirements-for-d3cold [2]: https://github.com/Bumblebee-Project/bbswitch/issues/78#issuecomment-223549072 v2: simply check directly for _PR3. Added affected machines. v3: fixed block comment coding style. Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Peter Wu <peter@lekensteyn.nl> Acked-by: Dave Airlie <airlied@redhat.com Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_acpi.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c
index ad273ad7b591..f2ad17aa33f0 100644
--- a/drivers/gpu/drm/nouveau/nouveau_acpi.c
+++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c
@@ -46,6 +46,7 @@ static struct nouveau_dsm_priv {
46 bool dsm_detected; 46 bool dsm_detected;
47 bool optimus_detected; 47 bool optimus_detected;
48 bool optimus_flags_detected; 48 bool optimus_flags_detected;
49 bool optimus_skip_dsm;
49 acpi_handle dhandle; 50 acpi_handle dhandle;
50 acpi_handle rom_handle; 51 acpi_handle rom_handle;
51} nouveau_dsm_priv; 52} nouveau_dsm_priv;
@@ -212,9 +213,28 @@ static const struct vga_switcheroo_handler nouveau_dsm_handler = {
212 .get_client_id = nouveau_dsm_get_client_id, 213 .get_client_id = nouveau_dsm_get_client_id,
213}; 214};
214 215
216/*
217 * Firmware supporting Windows 8 or later do not use _DSM to put the device into
218 * D3cold, they instead rely on disabling power resources on the parent.
219 */
220static bool nouveau_pr3_present(struct pci_dev *pdev)
221{
222 struct pci_dev *parent_pdev = pci_upstream_bridge(pdev);
223 struct acpi_device *parent_adev;
224
225 if (!parent_pdev)
226 return false;
227
228 parent_adev = ACPI_COMPANION(&parent_pdev->dev);
229 if (!parent_adev)
230 return false;
231
232 return acpi_has_method(parent_adev->handle, "_PR3");
233}
234
215static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out, 235static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out,
216 bool *has_mux, bool *has_opt, 236 bool *has_mux, bool *has_opt,
217 bool *has_opt_flags) 237 bool *has_opt_flags, bool *has_pr3)
218{ 238{
219 acpi_handle dhandle; 239 acpi_handle dhandle;
220 bool supports_mux; 240 bool supports_mux;
@@ -239,6 +259,7 @@ static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out
239 *has_mux = supports_mux; 259 *has_mux = supports_mux;
240 *has_opt = !!optimus_funcs; 260 *has_opt = !!optimus_funcs;
241 *has_opt_flags = optimus_funcs & (1 << NOUVEAU_DSM_OPTIMUS_FLAGS); 261 *has_opt_flags = optimus_funcs & (1 << NOUVEAU_DSM_OPTIMUS_FLAGS);
262 *has_pr3 = false;
242 263
243 if (optimus_funcs) { 264 if (optimus_funcs) {
244 uint32_t result; 265 uint32_t result;
@@ -248,6 +269,8 @@ static void nouveau_dsm_pci_probe(struct pci_dev *pdev, acpi_handle *dhandle_out
248 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled", 269 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
249 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "", 270 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
250 (result & OPTIMUS_HDA_CODEC_MASK) ? "hda bios codec supported" : ""); 271 (result & OPTIMUS_HDA_CODEC_MASK) ? "hda bios codec supported" : "");
272
273 *has_pr3 = nouveau_pr3_present(pdev);
251 } 274 }
252} 275}
253 276
@@ -260,6 +283,7 @@ static bool nouveau_dsm_detect(void)
260 bool has_mux = false; 283 bool has_mux = false;
261 bool has_optimus = false; 284 bool has_optimus = false;
262 bool has_optimus_flags = false; 285 bool has_optimus_flags = false;
286 bool has_power_resources = false;
263 int vga_count = 0; 287 int vga_count = 0;
264 bool guid_valid; 288 bool guid_valid;
265 bool ret = false; 289 bool ret = false;
@@ -275,14 +299,14 @@ static bool nouveau_dsm_detect(void)
275 vga_count++; 299 vga_count++;
276 300
277 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus, 301 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus,
278 &has_optimus_flags); 302 &has_optimus_flags, &has_power_resources);
279 } 303 }
280 304
281 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) { 305 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
282 vga_count++; 306 vga_count++;
283 307
284 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus, 308 nouveau_dsm_pci_probe(pdev, &dhandle, &has_mux, &has_optimus,
285 &has_optimus_flags); 309 &has_optimus_flags, &has_power_resources);
286 } 310 }
287 311
288 /* find the optimus DSM or the old v1 DSM */ 312 /* find the optimus DSM or the old v1 DSM */
@@ -292,8 +316,11 @@ static bool nouveau_dsm_detect(void)
292 &buffer); 316 &buffer);
293 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n", 317 printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
294 acpi_method_name); 318 acpi_method_name);
319 if (has_power_resources)
320 pr_info("nouveau: detected PR support, will not use DSM\n");
295 nouveau_dsm_priv.optimus_detected = true; 321 nouveau_dsm_priv.optimus_detected = true;
296 nouveau_dsm_priv.optimus_flags_detected = has_optimus_flags; 322 nouveau_dsm_priv.optimus_flags_detected = has_optimus_flags;
323 nouveau_dsm_priv.optimus_skip_dsm = has_power_resources;
297 ret = true; 324 ret = true;
298 } else if (vga_count == 2 && has_mux && guid_valid) { 325 } else if (vga_count == 2 && has_mux && guid_valid) {
299 nouveau_dsm_priv.dhandle = dhandle; 326 nouveau_dsm_priv.dhandle = dhandle;
@@ -324,7 +351,7 @@ void nouveau_register_dsm_handler(void)
324void nouveau_switcheroo_optimus_dsm(void) 351void nouveau_switcheroo_optimus_dsm(void)
325{ 352{
326 u32 result = 0; 353 u32 result = 0;
327 if (!nouveau_dsm_priv.optimus_detected) 354 if (!nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.optimus_skip_dsm)
328 return; 355 return;
329 356
330 if (nouveau_dsm_priv.optimus_flags_detected) 357 if (nouveau_dsm_priv.optimus_flags_detected)