Skip to contentSkip to conversation

fb fix + laptop gpu switching support

PATCH New Dave Airlie 1 participant 5 messages Feb 25, 2010

Subsystems (7)
lore
Share & tools
lore

Dave Airlie

author maintainer
#0 lore raw

The first patch is a trivial change to the fb handover code.

The second adds initial support framework for laptops with GPU switching features, it has some changes to fb code, along with changes to dri drivers.

I'm happy to deal with these patches via drm-2.6 for this merge window if nobody has any objections.

Dave.

author maintainer
#1 lore raw

PATCH 1/2 fb: for framebuffer handover don't exit the loop early.

From: Dave Airlie <[email protected]>

An offb machine has been seen in the fields which adds two offb nodes, so continue scanning the list after removing one.

---
 drivers/video/fbmem.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/video/fbmem.c +0 -1
index 99bbd28..a15b44e 100644
@@ -1513,7 +1513,6 @@ register_framebuffer(struct fb_info *fb_info)
 				       fb_info->fix.id,
 				       registered_fb[i]->fix.id);
 				unregister_framebuffer(registered_fb[i]);
-				break;
 			}
 		}
 	}
Signature · 1 line
1.6.5.2
author maintainer
#2 lore raw

PATCH 2/2 vga switch: hi my name is race condition

From: Dave Airlie <[email protected]>

This adds a delayed switch mode, and also changes the debugfs file to accept different parameters.
It also adds switch blocking by the drm if any devices are in use

echo:
DIS - immediate change to discrete
IGD - immediate change to IGD
DDIS - delayed change to discrete
DIGD - delayed change to IGD
ON - turn on not in use
OFF - turn off not in use

no more PCI IDs.

---
 drivers/gpu/drm/i915/i915_dma.c              |   16 ++++-
 drivers/gpu/drm/nouveau/nouveau_state.c      |   14 +++-
 drivers/gpu/drm/radeon/r600_audio.c          |    3 +
 drivers/gpu/drm/radeon/radeon.h              |    2 +
 drivers/gpu/drm/radeon/radeon_atpx_handler.c |    2 +
 drivers/gpu/drm/radeon/radeon_device.c       |   26 ++++++-
 drivers/gpu/drm/radeon/radeon_kms.c          |    3 +
 drivers/gpu/vga/vga_switcheroo.c             |  108 ++++++++++++++++++++++---
 include/linux/vga_switcheroo.h               |    5 +-
 9 files changed, 162 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +15 -1
index 2e70292..3fb32fd 100644
@@ -1202,6 +1202,17 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_
 	}
 }
 
+static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
+{
+	struct drm_device *dev = pci_get_drvdata(pdev);
+	bool can_switch;
+
+	spin_lock(&dev->count_lock);
+	can_switch = (dev->open_count = 0);
+	spin_unlock(&dev->count_lock);
+	return can_switch;
+}
+
 static int i915_load_modeset_init(struct drm_device *dev,
 				  unsigned long prealloc_start,
 				  unsigned long prealloc_size,
@@ -1271,7 +1282,9 @@ static int i915_load_modeset_init(struct drm_device *dev,
 	if (ret)
 		goto destroy_ringbuffer;
 
-	ret = vga_switcheroo_register_client(dev->pdev, i915_switcheroo_set_state);
+	ret = vga_switcheroo_register_client(dev->pdev,
+					     i915_switcheroo_set_state,
+					     i915_switcheroo_can_switch);
 	if (ret)
 		goto destroy_ringbuffer;
 
@@ -1624,6 +1637,7 @@ void i915_driver_lastclose(struct drm_device * dev)
 
 	if (!dev_priv || drm_core_check_feature(dev, DRIVER_MODESET)) {
 		drm_fb_helper_restore();
+		vga_switcheroo_process_delayed_switch();
 		return;
 	}
 
drivers/gpu/drm/nouveau/nouveau_state.c +13 -1
index 940fdd3..afddcca 100644
@@ -377,6 +377,17 @@ static void nouveau_switcheroo_set_state (struct pci_dev *pdev,
 	}
 }
 
+static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
+{
+	struct drm_device *dev = pci_get_drvdata(pdev);
+	bool can_switch;
+
+	spin_lock(&dev->count_lock);
+	can_switch = (dev->open_count = 0);
+	spin_unlock(&dev->count_lock);
+	return can_switch;
+}
+
 int
 nouveau_card_init(struct drm_device *dev)
 {
@@ -390,7 +401,8 @@ nouveau_card_init(struct drm_device *dev)
 		return 0;
 
 	vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode);
-	vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state);
+	vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state,
+				       nouveau_switcheroo_can_switch);
 
 	/* Initialise internal driver API hooks */
 	ret = nouveau_init_engine_ptrs(dev);
drivers/gpu/drm/radeon/r600_audio.c +3 -0
index 99e2c38..e880cd8 100644
@@ -163,6 +163,9 @@ int r600_audio_init(struct radeon_device *rdev)
 	rdev->audio_status_bits = 0;
 	rdev->audio_category_code = 0;
 
+	if (!radeon_audio)
+		return 0;
+
 	setup_timer(
 		&rdev->audio_timer,
 		r600_audio_update_hdmi,
drivers/gpu/drm/radeon/radeon.h +2 -0
index f7df1a7..694c453 100644
@@ -829,6 +829,8 @@ struct radeon_device {
 	int			audio_bits_per_sample;
 	uint8_t			audio_status_bits;
 	uint8_t			audio_category_code;
+
+	bool powered_down;
 };
 
 int radeon_device_init(struct radeon_device *rdev,
drivers/gpu/drm/radeon/radeon_atpx_handler.c +2 -0
index 808d980..c614794 100644
@@ -3,6 +3,8 @@
  * Author : Dave Airlie <[email protected]>
  * 
  * Licensed under GPLv2
+ *
+ * ATPX support for both Intel/ATI
  */
 
 #include <linux/vga_switcheroo.h>
drivers/gpu/drm/radeon/radeon_device.c +25 -1
index 3ad4aba..a9b87b4 100644
@@ -620,16 +620,33 @@ void radeon_check_arguments(struct radeon_device *rdev)
 static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
+	struct radeon_device *rdev = dev->dev_private;
 	pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
 	if (state = VGA_SWITCHEROO_ON) {
 		printk(KERN_ERR "VGA switched radeon on\n");
 		radeon_resume_kms(dev);
+		r600_audio_init(rdev);
 	} else {
 		printk(KERN_ERR "VGA switched radeon off\n");
+		r600_audio_fini(rdev);
 		radeon_suspend_kms(dev, pmm);
 	}
+	/* don't suspend or resume card normally */
+	rdev->powered_down = true;
+}
+
+static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
+{
+	struct drm_device *dev = pci_get_drvdata(pdev);
+	bool can_switch;
+
+	spin_lock(&dev->count_lock);
+	can_switch = (dev->open_count = 0);
+	spin_unlock(&dev->count_lock);
+	return can_switch;
 }
 
+
 int radeon_device_init(struct radeon_device *rdev,
 		       struct drm_device *ddev,
 		       struct pci_dev *pdev,
@@ -709,7 +726,9 @@ int radeon_device_init(struct radeon_device *rdev,
 	/* this will fail for cards that aren't VGA class devices, just
 	 * ignore it */
 	vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode);
-	vga_switcheroo_register_client(rdev->pdev, radeon_switcheroo_set_state);
+	vga_switcheroo_register_client(rdev->pdev,
+				       radeon_switcheroo_set_state,
+				       radeon_switcheroo_can_switch);
 
 	r = radeon_init(rdev);
 	if (r)
@@ -764,6 +783,8 @@ int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
 	}
 	rdev = dev->dev_private;
 
+	if (rdev->powered_down)
+		return 0;
 	/* unpin the front buffers */
 	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
 		struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb);
@@ -809,6 +830,9 @@ int radeon_resume_kms(struct drm_device *dev)
 {
 	struct radeon_device *rdev = dev->dev_private;
 
+	if (rdev->powered_down)
+		return 0;
+
 	acquire_console_sem();
 	pci_set_power_state(dev->pdev, PCI_D0);
 	pci_restore_state(dev->pdev);
drivers/gpu/drm/radeon/radeon_kms.c +3 -0
index f23b056..5db7af6 100644
@@ -30,6 +30,8 @@
 #include "radeon.h"
 #include "radeon_drm.h"
 
+#include <linux/vga_switcheroo.h>
+
 int radeon_driver_unload_kms(struct drm_device *dev)
 {
 	struct radeon_device *rdev = dev->dev_private;
@@ -136,6 +138,7 @@ int radeon_driver_firstopen_kms(struct drm_device *dev)
 
 void radeon_driver_lastclose_kms(struct drm_device *dev)
 {
+	vga_switcheroo_process_delayed_switch();
 }
 
 int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
drivers/gpu/vga/vga_switcheroo.c +95 -13

163 lines not on this page · raw message

include/linux/vga_switcheroo.h +4 -1
index 694cfc5..fc30f82 100644
@@ -29,7 +29,8 @@ enum vga_switcheroo_client_id {
 
 void vga_switcheroo_unregister_client(struct pci_dev *dev);
 int vga_switcheroo_register_client(struct pci_dev *dev,
-				   void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state));
+				   void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state),
+				   bool (*can_switch)(struct pci_dev *dev));
 
 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
 				  struct fb_info *info);
@@ -45,3 +46,5 @@ struct vga_switcheroo_handler {
 
 int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler);
 void vga_switcheroo_unregister_handler(void);
+
+int vga_switcheroo_process_delayed_switch(void);
Signature · 1 line
1.6.5.2
author maintainer
#3 lore raw

PATCH 2/2 vga switch: hi my name is race condition

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

This adds a delayed switch mode, and also changes the debugfs file to accept different parameters.
It also adds switch blocking by the drm if any devices are in use

echo:
DIS - immediate change to discrete
IGD - immediate change to IGD
DDIS - delayed change to discrete
DIGD - delayed change to IGD
ON - turn on not in use
OFF - turn off not in use

no more PCI IDs.

---
 drivers/gpu/drm/i915/i915_dma.c              |   16 ++++-
 drivers/gpu/drm/nouveau/nouveau_state.c      |   14 +++-
 drivers/gpu/drm/radeon/r600_audio.c          |    3 +
 drivers/gpu/drm/radeon/radeon.h              |    2 +
 drivers/gpu/drm/radeon/radeon_atpx_handler.c |    2 +
 drivers/gpu/drm/radeon/radeon_device.c       |   26 ++++++-
 drivers/gpu/drm/radeon/radeon_kms.c          |    3 +
 drivers/gpu/vga/vga_switcheroo.c             |  108 ++++++++++++++++++++++---
 include/linux/vga_switcheroo.h               |    5 +-
 9 files changed, 162 insertions(+), 17 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +15 -1
index 2e70292..3fb32fd 100644
@@ -1202,6 +1202,17 @@ static void i915_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_
 	}
 }
 
+static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
+{
+	struct drm_device *dev = pci_get_drvdata(pdev);
+	bool can_switch;
+
+	spin_lock(&dev->count_lock);
+	can_switch = (dev->open_count == 0);
+	spin_unlock(&dev->count_lock);
+	return can_switch;
+}
+
 static int i915_load_modeset_init(struct drm_device *dev,
 				  unsigned long prealloc_start,
 				  unsigned long prealloc_size,
@@ -1271,7 +1282,9 @@ static int i915_load_modeset_init(struct drm_device *dev,
 	if (ret)
 		goto destroy_ringbuffer;
 
-	ret = vga_switcheroo_register_client(dev->pdev, i915_switcheroo_set_state);
+	ret = vga_switcheroo_register_client(dev->pdev,
+					     i915_switcheroo_set_state,
+					     i915_switcheroo_can_switch);
 	if (ret)
 		goto destroy_ringbuffer;
 
@@ -1624,6 +1637,7 @@ void i915_driver_lastclose(struct drm_device * dev)
 
 	if (!dev_priv || drm_core_check_feature(dev, DRIVER_MODESET)) {
 		drm_fb_helper_restore();
+		vga_switcheroo_process_delayed_switch();
 		return;
 	}
 
drivers/gpu/drm/nouveau/nouveau_state.c +13 -1
index 940fdd3..afddcca 100644
@@ -377,6 +377,17 @@ static void nouveau_switcheroo_set_state (struct pci_dev *pdev,
 	}
 }
 
+static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
+{
+	struct drm_device *dev = pci_get_drvdata(pdev);
+	bool can_switch;
+
+	spin_lock(&dev->count_lock);
+	can_switch = (dev->open_count == 0);
+	spin_unlock(&dev->count_lock);
+	return can_switch;
+}
+
 int
 nouveau_card_init(struct drm_device *dev)
 {
@@ -390,7 +401,8 @@ nouveau_card_init(struct drm_device *dev)
 		return 0;
 
 	vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode);
-	vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state);
+	vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state,
+				       nouveau_switcheroo_can_switch);
 
 	/* Initialise internal driver API hooks */
 	ret = nouveau_init_engine_ptrs(dev);
drivers/gpu/drm/radeon/r600_audio.c +3 -0
index 99e2c38..e880cd8 100644
@@ -163,6 +163,9 @@ int r600_audio_init(struct radeon_device *rdev)
 	rdev->audio_status_bits = 0;
 	rdev->audio_category_code = 0;
 
+	if (!radeon_audio)
+		return 0;
+
 	setup_timer(
 		&rdev->audio_timer,
 		r600_audio_update_hdmi,
drivers/gpu/drm/radeon/radeon.h +2 -0
index f7df1a7..694c453 100644
@@ -829,6 +829,8 @@ struct radeon_device {
 	int			audio_bits_per_sample;
 	uint8_t			audio_status_bits;
 	uint8_t			audio_category_code;
+
+	bool powered_down;
 };
 
 int radeon_device_init(struct radeon_device *rdev,
drivers/gpu/drm/radeon/radeon_atpx_handler.c +2 -0
index 808d980..c614794 100644
@@ -3,6 +3,8 @@
  * Author : Dave Airlie <[email protected]>
  * 
  * Licensed under GPLv2
+ *
+ * ATPX support for both Intel/ATI
  */
 
 #include <linux/vga_switcheroo.h>
drivers/gpu/drm/radeon/radeon_device.c +25 -1
index 3ad4aba..a9b87b4 100644
@@ -620,16 +620,33 @@ void radeon_check_arguments(struct radeon_device *rdev)
 static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
+	struct radeon_device *rdev = dev->dev_private;
 	pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
 	if (state == VGA_SWITCHEROO_ON) {
 		printk(KERN_ERR "VGA switched radeon on\n");
 		radeon_resume_kms(dev);
+		r600_audio_init(rdev);
 	} else {
 		printk(KERN_ERR "VGA switched radeon off\n");
+		r600_audio_fini(rdev);
 		radeon_suspend_kms(dev, pmm);
 	}
+	/* don't suspend or resume card normally */
+	rdev->powered_down = true;
+}
+
+static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
+{
+	struct drm_device *dev = pci_get_drvdata(pdev);
+	bool can_switch;
+
+	spin_lock(&dev->count_lock);
+	can_switch = (dev->open_count == 0);
+	spin_unlock(&dev->count_lock);
+	return can_switch;
 }
 
+
 int radeon_device_init(struct radeon_device *rdev,
 		       struct drm_device *ddev,
 		       struct pci_dev *pdev,
@@ -709,7 +726,9 @@ int radeon_device_init(struct radeon_device *rdev,
 	/* this will fail for cards that aren't VGA class devices, just
 	 * ignore it */
 	vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode);
-	vga_switcheroo_register_client(rdev->pdev, radeon_switcheroo_set_state);
+	vga_switcheroo_register_client(rdev->pdev,
+				       radeon_switcheroo_set_state,
+				       radeon_switcheroo_can_switch);
 
 	r = radeon_init(rdev);
 	if (r)
@@ -764,6 +783,8 @@ int radeon_suspend_kms(struct drm_device *dev, pm_message_t state)
 	}
 	rdev = dev->dev_private;
 
+	if (rdev->powered_down)
+		return 0;
 	/* unpin the front buffers */
 	list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
 		struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->fb);
@@ -809,6 +830,9 @@ int radeon_resume_kms(struct drm_device *dev)
 {
 	struct radeon_device *rdev = dev->dev_private;
 
+	if (rdev->powered_down)
+		return 0;
+
 	acquire_console_sem();
 	pci_set_power_state(dev->pdev, PCI_D0);
 	pci_restore_state(dev->pdev);
drivers/gpu/drm/radeon/radeon_kms.c +3 -0
index f23b056..5db7af6 100644
@@ -30,6 +30,8 @@
 #include "radeon.h"
 #include "radeon_drm.h"
 
+#include <linux/vga_switcheroo.h>
+
 int radeon_driver_unload_kms(struct drm_device *dev)
 {
 	struct radeon_device *rdev = dev->dev_private;
@@ -136,6 +138,7 @@ int radeon_driver_firstopen_kms(struct drm_device *dev)
 
 void radeon_driver_lastclose_kms(struct drm_device *dev)
 {
+	vga_switcheroo_process_delayed_switch();
 }
 
 int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
drivers/gpu/vga/vga_switcheroo.c +95 -13

163 lines not on this page · raw message

include/linux/vga_switcheroo.h +4 -1
index 694cfc5..fc30f82 100644
@@ -29,7 +29,8 @@ enum vga_switcheroo_client_id {
 
 void vga_switcheroo_unregister_client(struct pci_dev *dev);
 int vga_switcheroo_register_client(struct pci_dev *dev,
-				   void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state));
+				   void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state),
+				   bool (*can_switch)(struct pci_dev *dev));
 
 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
 				  struct fb_info *info);
@@ -45,3 +46,5 @@ struct vga_switcheroo_handler {
 
 int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler);
 void vga_switcheroo_unregister_handler(void);
+
+int vga_switcheroo_process_delayed_switch(void);
Signature · 10 lines
1.6.5.2


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--
author maintainer
#4 lore raw

PATCH 1/2 fb: for framebuffer handover don't exit the loop early.

In reply to Dave Airlie

From: Dave Airlie <[email protected]>

An offb machine has been seen in the fields which adds two offb nodes, so continue scanning the list after removing one.

---
 drivers/video/fbmem.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
drivers/video/fbmem.c +0 -1
index 99bbd28..a15b44e 100644
@@ -1513,7 +1513,6 @@ register_framebuffer(struct fb_info *fb_info)
 				       fb_info->fix.id,
 				       registered_fb[i]->fix.id);
 				unregister_framebuffer(registered_fb[i]);
-				break;
 			}
 		}
 	}
Signature · 10 lines
1.6.5.2


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--