Skip to contentSkip to conversation

Prepare nouveau for other switcheroo handlers

PATCH New Andreas Heider 1 participant 4 messages Mar 23, 2012 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Prepare nouveau for other switcheroo handlers

While working on a vga_switcheroo handler for Apple's Macbook Pros I stumbled upon a few bugs regarding the usage of nouveau with other switcheroo handlers and module unloading, here are my fixes for them.

Andreas Heider (3):
drm/nouveau: Initialize has_optimus drm/nouveau: Check dsm on switcheroo unregister drm/nouveau: Unregister switcheroo client on exit

 drivers/gpu/drm/nouveau/nouveau_acpi.c  |    5 +++--
 drivers/gpu/drm/nouveau/nouveau_state.c |    2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)

--
1.7.9.1

#2 lore raw

PATCH 1/3 drm/nouveau: Initialize has_optimus

In reply to a message not in the archive

During dsm detection it is possible that has_optimus is read uninitialized, which can lead to optimus being detected erroneously. This patch initialized has_optimus with 0.

---
 drivers/gpu/drm/nouveau/nouveau_acpi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/gpu/drm/nouveau/nouveau_acpi.c +1 -1
index 7814a76..284bd25 100644
@@ -270,7 +270,7 @@ static bool nouveau_dsm_detect(void)
 	struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
 	struct pci_dev *pdev = NULL;
 	int has_dsm = 0;
-	int has_optimus;
+	int has_optimus = 0;
 	int vga_count = 0;
 	bool guid_valid;
 	int retval;
Signature · 1 line
1.7.9.1
#3 lore raw

PATCH 2/3 drm/nouveau: Check dsm on switcheroo unregister

In reply to a message not in the archive

Currently vga_switcheroo_unregister_handler is called unconditionally when nouveau is unloaded, even when nouveau never registered a handler. This interferes with other switcheroo handlers, as vga_switcheroo doesn't check who called unregister_handler, but simply unregisters the current handler. This patch adds a check so unregister is only called if a handler was registered by nouveau before.

---
 drivers/gpu/drm/nouveau/nouveau_acpi.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/gpu/drm/nouveau/nouveau_acpi.c +2 -1
index 284bd25..fc841e8 100644
@@ -338,7 +338,8 @@ void nouveau_switcheroo_optimus_dsm(void)
 
 void nouveau_unregister_dsm_handler(void)
 {
-	vga_switcheroo_unregister_handler();
+	if (nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.dsm_detected)
+		vga_switcheroo_unregister_handler();
 }
 
 /* retrieve the ROM in 4k blocks */
Signature · 1 line
1.7.9.1
#4 lore raw

PATCH 3/3 drm/nouveau: Unregister switcheroo client on exit

In reply to a message not in the archive

Currently nouveau only registers as a vga_switcheroo client, but never unregisters. This patch adds the necessary unregister calls.

---
 drivers/gpu/drm/nouveau/nouveau_state.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/gpu/drm/nouveau/nouveau_state.c +2 -0
index 9da6a74..2e11361 100644
@@ -912,6 +912,7 @@ out_bios:
 out_display_early:
 	engine->display.late_takedown(dev);
 out:
+	vga_switcheroo_unregister_client(dev->pdev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
 	return ret;
 }
@@ -969,6 +970,7 @@ static void nouveau_card_takedown(struct drm_device *dev)
 
 	nouveau_irq_fini(dev);
 
+	vga_switcheroo_unregister_client(dev->pdev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
 }
 
Signature · 1 line
1.7.9.1