Skip to contentSkip to conversation

full suspend/resume support for i915 DRM driver

RFC In review Jesse Barnes 7 participants 18 messages Oct 18, 2007 – Oct 27, 2007

lore
Share & tools
lore
#0 lore raw

RFC 1/1 full suspend/resume support for i915 DRM driver

We seem to see a lot of bug reports along the lines of, "my machine resumes but I can't see X" or, "I can see X but only with a bright flashlight", etc. These sorts of problems are due to the fact that the X server isn't designed to do full state save/restore, and none of the available kernel drivers do it on its behalf.

Since intelfb and the rest of the Intel drivers are fairly incompatible, this patch makes the DRM bind to the PCI device so it can register real suspend/resume handlers. Those handlers take care of saving and restoring enough state for X to come back reliably on at least one of my problematic test machines, but text mode still has trouble (still debugging VGA state save/restore, including trying to save/restore actual VRAM contents for possible hibernate support).

How does this approach look? Is a new DRM driver flag a good thing for similar situations with other drivers? Thoughts?

Thanks,
Jesse

linux-core/Kconfig +4 -1
index 2d02c76..5e73fc7 100644
@@ -50,7 +50,7 @@ config DRM_I810
 
 choice
 	prompt "Intel 830M, 845G, 852GM, 855GM, 865G"
-	depends on DRM && AGP && AGP_INTEL
+	depends on DRM && AGP && AGP_INTEL && !FB_INTEL
 	optional
 
 config DRM_I915
@@ -60,6 +60,9 @@ config DRM_I915
 	  852GM, 855GM, 865G, 915G, 915GM, 945G, 945GM and 965G integrated 
 	  graphics.  If M is selected, the module will be called i915.  
 	  AGP support is required for this driver to work.
+
+	  Note that this driver is incompatible with the Intel framebuffer
+	  driver.
 	
 endchoice
 
linux-core/drmP.h +1 -0
index f8ca3f4..36ce266 100644
@@ -106,6 +106,7 @@ struct drm_file;
 #define DRIVER_DMA_QUEUE   0x200
 #define DRIVER_FB_DMA      0x400
 #define DRIVER_IRQ_VBL2    0x800
+#define DRIVER_BIND_PCI    0x1000
 
 
 /*@}*/
linux-core/drm_drv.c +3 -2
index a09fa96..4d11707 100644
@@ -340,9 +340,10 @@ int drm_init(struct drm_driver *driver,
 		}
 	}
 
-	if (!drm_fb_loaded)
+	if (!drm_fb_loaded || (driver->driver_features & DRIVER_BIND_PCI)) {
+		printk(KERN_ERR "DRM binding to PCI device\n");
 		return pci_register_driver(&driver->pci_driver);
-	else {
+	} else {
 		for (i = 0; pciidlist[i].vendor != 0; i++) {
 			pid = &pciidlist[i];
 
linux-core/i915_drv.c +618 -1

637 lines not on this page · raw message

shared-core/i915_dma.c +0 -11
index 7209a8d..b8370be 100644
@@ -31,17 +31,6 @@
 #include "i915_drm.h"
 #include "i915_drv.h"
 
-#define IS_I965G(dev)  (dev->pci_device == 0x2972 || \
-			dev->pci_device == 0x2982 || \
-			dev->pci_device == 0x2992 || \
-			dev->pci_device == 0x29A2 || \
-			dev->pci_device == 0x2A02 || \
-			dev->pci_device == 0x2A12)
-
-#define IS_G33(dev)    (dev->pci_device == 0x29C2 || \
-		   	dev->pci_device == 0x29B2 || \
-			dev->pci_device == 0x29D2) 
-
 /* Really want an OS-independent resettable timer.  Would like to have
  * this loop run for (eg) 3 sec, but have the timer reset every time
  * the head pointer changes, so that EBUSY only happens if the ring
shared-core/i915_drv.h +662 -0

684 lines not on this page · raw message

#1 lore raw
Quoted 14 lines · Jesse Barnes

We seem to see a lot of bug reports along the lines of, "my machine resumes but I can't see X" or, "I can see X but only with a bright flashlight", etc. These sorts of problems are due to the fact that the X server isn't designed to do full state save/restore, and none of the available kernel drivers do it on its behalf.

Since intelfb and the rest of the Intel drivers are fairly incompatible, this patch makes the DRM bind to the PCI device so it can register real suspend/resume handlers. Those handlers take care of saving and restoring enough state for X to come back reliably on at least one of my problematic test machines, but text mode still has trouble (still debugging VGA state save/restore, including trying to save/restore actual VRAM contents for possible hibernate support).

Quoted 2 lines

How does this approach look? Is a new DRM driver flag a good thing for similar situations with other drivers? Thoughts?

Here's an updated one that actually works fully on my 965 based test platform. It should also work on other 9xx platforms, but note that it lacks TV out and SDVO state save/restore, so I don't expect those to work. I also haven't tested on 8xx platforms, but a similar approach should work, so I'd welcome additions to support those chipsets.

Dave can you take a look at the new flag and also see what you think about supporting suspend/resume in the event X hasn't started yet? There's some #if 0'd code to support that case, but I haven't tested it.

Thanks,
Jesse

linux-core/Kconfig +4 -1
index 2d02c76..5e73fc7 100644
@@ -50,7 +50,7 @@ config DRM_I810
 
 choice
 	prompt "Intel 830M, 845G, 852GM, 855GM, 865G"
-	depends on DRM && AGP && AGP_INTEL
+	depends on DRM && AGP && AGP_INTEL && !FB_INTEL
 	optional
 
 config DRM_I915
@@ -60,6 +60,9 @@ config DRM_I915
 	  852GM, 855GM, 865G, 915G, 915GM, 945G, 945GM and 965G integrated 
 	  graphics.  If M is selected, the module will be called i915.  
 	  AGP support is required for this driver to work.
+
+	  Note that this driver is incompatible with the Intel framebuffer
+	  driver.
 	
 endchoice
 
linux-core/drmP.h +1 -0
index f8ca3f4..36ce266 100644
@@ -106,6 +106,7 @@ struct drm_file;
 #define DRIVER_DMA_QUEUE   0x200
 #define DRIVER_FB_DMA      0x400
 #define DRIVER_IRQ_VBL2    0x800
+#define DRIVER_BIND_PCI    0x1000
 
 
 /*@}*/
linux-core/drm_drv.c +3 -2
index a09fa96..4d11707 100644
@@ -340,9 +340,10 @@ int drm_init(struct drm_driver *driver,
 		}
 	}
 
-	if (!drm_fb_loaded)
+	if (!drm_fb_loaded || (driver->driver_features & DRIVER_BIND_PCI)) {
+		printk(KERN_ERR "DRM binding to PCI device\n");
 		return pci_register_driver(&driver->pci_driver);
-	else {
+	} else {
 		for (i = 0; pciidlist[i].vendor != 0; i++) {
 			pid = &pciidlist[i];
 
linux-core/i915_drv.c +498 -1

517 lines not on this page · raw message

shared-core/i915_dma.c +0 -11
index 7209a8d..b8370be 100644
@@ -31,17 +31,6 @@
 #include "i915_drm.h"
 #include "i915_drv.h"
 
-#define IS_I965G(dev)  (dev->pci_device == 0x2972 || \
-			dev->pci_device == 0x2982 || \
-			dev->pci_device == 0x2992 || \
-			dev->pci_device == 0x29A2 || \
-			dev->pci_device == 0x2A02 || \
-			dev->pci_device == 0x2A12)
-
-#define IS_G33(dev)    (dev->pci_device == 0x29C2 || \
-		   	dev->pci_device == 0x29B2 || \
-			dev->pci_device == 0x29D2) 
-
 /* Really want an OS-independent resettable timer.  Would like to have
  * this loop run for (eg) 3 sec, but have the timer reset every time
  * the head pointer changes, so that EBUSY only happens if the ring
shared-core/i915_drv.h +662 -0

684 lines not on this page · raw message

#2 lore raw
Quoted 4 lines · Jesse Barnes

Dave can you take a look at the new flag and also see what you think about supporting suspend/resume in the event X hasn't started yet? There's some #if 0'd code to support that case, but I haven't tested it.

Ok Dave, this one's been updated with support for suspend/resume with or without X running (iow I removed the requirement that X initialize the driver, which DRM drivers usually have).

Hope it looks alright, it could definitely use testing on more machines though...

Jesse

linux-core/Kconfig +4 -1
index 2d02c76..5e73fc7 100644
@@ -50,7 +50,7 @@ config DRM_I810
 
 choice
 	prompt "Intel 830M, 845G, 852GM, 855GM, 865G"
-	depends on DRM && AGP && AGP_INTEL
+	depends on DRM && AGP && AGP_INTEL && !FB_INTEL
 	optional
 
 config DRM_I915
@@ -60,6 +60,9 @@ config DRM_I915
 	  852GM, 855GM, 865G, 915G, 915GM, 945G, 945GM and 965G integrated 
 	  graphics.  If M is selected, the module will be called i915.  
 	  AGP support is required for this driver to work.
+
+	  Note that this driver is incompatible with the Intel framebuffer
+	  driver.
 	
 endchoice
 
linux-core/drmP.h +1 -0
index f8ca3f4..36ce266 100644
@@ -106,6 +106,7 @@ struct drm_file;
 #define DRIVER_DMA_QUEUE   0x200
 #define DRIVER_FB_DMA      0x400
 #define DRIVER_IRQ_VBL2    0x800
+#define DRIVER_BIND_PCI    0x1000
 
 
 /*@}*/
linux-core/drm_drv.c +5 -4
index a09fa96..3d14fb4 100644
@@ -340,9 +340,10 @@ int drm_init(struct drm_driver *driver,
 		}
 	}
 
-	if (!drm_fb_loaded)
+	if (!drm_fb_loaded || (driver->driver_features & DRIVER_BIND_PCI)) {
+		printk(KERN_INFO "DRM binding to PCI device\n");
 		return pci_register_driver(&driver->pci_driver);
-	else {
+	} else {
 		for (i = 0; pciidlist[i].vendor != 0; i++) {
 			pid = &pciidlist[i];
 
@@ -394,7 +395,7 @@ static void drm_cleanup(struct drm_device * dev)
 	drm_mm_takedown(&dev->offset_manager);
 	drm_ht_remove(&dev->object_hash);
 
-	if (!drm_fb_loaded)
+	if (!drm_fb_loaded || (dev->driver->driver_features & DRIVER_BIND_PCI))
 		pci_disable_device(dev->pdev);
 
 	drm_ctxbitmap_cleanup(dev);
@@ -427,7 +428,7 @@ void drm_exit(struct drm_driver *driver)
 	struct drm_head *head;
 
 	DRM_DEBUG("\n");
-	if (drm_fb_loaded) {
+	if (drm_fb_loaded && !(driver->driver_features & DRIVER_BIND_PCI)) {
 		for (i = 0; i < drm_cards_limit; i++) {
 			head = drm_heads[i];
 			if (!head)
linux-core/drm_stub.c +4 -4
index 07ea91e..e504865 100644
@@ -230,7 +230,7 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
 	if (!dev)
 		return -ENOMEM;
 
-	if (!drm_fb_loaded) {
+	if (!drm_fb_loaded || (driver->driver_features & DRIVER_BIND_PCI)) {
 		pci_set_drvdata(pdev, dev);
 		ret = pci_request_regions(pdev, driver->pci_driver.name);
 		if (ret)
@@ -256,13 +256,13 @@ int drm_get_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
 	return 0;
 
  err_g3:
-	if (!drm_fb_loaded)
+	if (!drm_fb_loaded || (driver->driver_features & DRIVER_BIND_PCI))
 		pci_disable_device(pdev);
  err_g2:
-	if (!drm_fb_loaded)
+	if (!drm_fb_loaded || (driver->driver_features & DRIVER_BIND_PCI))
 		pci_release_regions(pdev);
  err_g1:
-	if (!drm_fb_loaded)
+	if (!drm_fb_loaded || (driver->driver_features & DRIVER_BIND_PCI))
 		pci_set_drvdata(pdev, NULL);
 
 	drm_free(dev, sizeof(*dev), DRM_MEM_STUB);
linux-core/i915_drv.c +458 -1

478 lines not on this page · raw message

shared-core/i915_dma.c +27 -21

107 lines not on this page · raw message

shared-core/i915_drv.h +663 -0

691 lines not on this page · raw message

#3 lore raw
Quoted 20 lines · Jesse Barnes
Quoted 4 lines · Jesse Barnes

Dave can you take a look at the new flag and also see what you think about supporting suspend/resume in the event X hasn't started yet? There's some #if 0'd code to support that case, but I haven't tested it.

Ok Dave, this one's been updated with support for suspend/resume with or without X running (iow I removed the requirement that X initialize the driver, which DRM drivers usually have).

Hope it looks alright, it could definitely use testing on more machines though...

Jesse

linux-core/Kconfig +0 -0
index 2d02c76..5e73fc7 100644

linux-core/Kconfig config DRM_I810 · line 54

Quoted 7 lines
linux-core/Kconfig +1 -1
@@ -50,7 +50,7 @@ config DRM_I810
 
 choice
 	prompt "Intel 830M, 845G, 852GM, 855GM, 865G"
-	depends on DRM && AGP && AGP_INTEL
+	depends on DRM && AGP && AGP_INTEL && !FB_INTEL
 	optional
...

This sounds like a bad regression.

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#4 lore raw
Quoted 6 lines · Adrian Bunk
Quoted 6 lines
linux-core/Kconfig +0 -0
index 2d02c76..5e73fc7 100644
@@ -50,7 +50,7 @@ config DRM_I810
 
Quoted 8 lines

linux-core/Kconfig config DRM_I810 · line 54

Quoted 6 lines
linux-core/Kconfig +1 -1
 choice
 	prompt "Intel 830M, 845G, 852GM, 855GM, 865G"
-	depends on DRM && AGP && AGP_INTEL
+	depends on DRM && AGP && AGP_INTEL && !FB_INTEL
 	optional
...

This sounds like a bad regression.

Well it's really documenting existing behavior. Unless you're very careful, running custom applications, the Intel FB and DRM drivers will conflict. IMO this is a long overdue change, but Dave has some custom stuff that requires both drivers so he'd rather not see it go in, so I'm fine with dropping this part.

Jesse

#5 lore raw
In reply to Jesse Barnes

Hi!

Quoted 14 lines

We seem to see a lot of bug reports along the lines of, "my machine resumes but I can't see X" or, "I can see X but only with a bright flashlight", etc. These sorts of problems are due to the fact that the X server isn't designed to do full state save/restore, and none of the available kernel drivers do it on its behalf.

Since intelfb and the rest of the Intel drivers are fairly incompatible, this patch makes the DRM bind to the PCI device so it can register real suspend/resume handlers. Those handlers take care of saving and restoring enough state for X to come back reliably on at least one of my problematic test machines, but text mode still has trouble (still debugging VGA state save/restore, including trying to save/restore actual VRAM contents for possible hibernate support).

Quoted 2 lines

How does this approach look? Is a new DRM driver flag a good thing for similar situations with other drivers? Thoughts?

Looks okay to me... from very quick look.

linux-core/i915_drv.c static struct drm_bo_driver i915_bo_driver = { · line 98

Quoted 5 lines
linux-core/i915_drv.c +5 -0
+	if (!i915_pipe_enabled(dev, pipe))
+		return;
+
+	if (pipe == PIPE_A)
+		array = dev_priv->savePaletteA;

coding style, we probably want save_palette_A.

Review

Quoted 1 line
(quoted diff) +1 -0
+	unsigned long reg = pipe == PIPE_A ? PALETTE_A : PALETTE_B;

Uff. Mixing = and == and ? in one expression is evil.

I think I seen some #if 0 code.... just remove that.

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw
Quoted 21 lines · Pavel Machek

Hi!

Quoted 14 lines

We seem to see a lot of bug reports along the lines of, "my machine resumes but I can't see X" or, "I can see X but only with a bright flashlight", etc. These sorts of problems are due to the fact that the X server isn't designed to do full state save/restore, and none of the available kernel drivers do it on its behalf.

Since intelfb and the rest of the Intel drivers are fairly incompatible, this patch makes the DRM bind to the PCI device so it can register real suspend/resume handlers. Those handlers take care of saving and restoring enough state for X to come back reliably on at least one of my problematic test machines, but text mode still has trouble (still debugging VGA state save/restore, including trying to save/restore actual VRAM contents for possible hibernate support).

Quoted 2 lines

How does this approach look? Is a new DRM driver flag a good thing for similar situations with other drivers? Thoughts?

Looks okay to me... from very quick look.

Quoted 7 lines

linux-core/i915_drv.c static struct drm_bo_driver i915_bo_driver = { · line 98

Quoted 5 lines
linux-core/i915_drv.c +5 -0
+	if (!i915_pipe_enabled(dev, pipe))
+		return;
+
+	if (pipe == PIPE_A)
+		array = dev_priv->savePaletteA;

coding style, we probably want save_palette_A.

Yeah, I tried not to pull over uglies from the X code but I guess I forgot this bit. I should also update the copyright.

Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	unsigned long reg = pipe == PIPE_A ? PALETTE_A : PALETTE_B;

Uff. Mixing = and == and ? in one expression is evil.

I could put parens around it if you think that would help, or just move it to a new line...

Quoted 1 line

I think I seen some #if 0 code.... just remove that.

Oh I left some in there? Yeah I'll remove it.

Thanks,
Jesse

#7 lore raw
Quoted 33 lines · Jesse Barnes
Quoted 21 lines · Pavel Machek

Hi!

Quoted 14 lines

We seem to see a lot of bug reports along the lines of, "my machine resumes but I can't see X" or, "I can see X but only with a bright flashlight", etc. These sorts of problems are due to the fact that the X server isn't designed to do full state save/restore, and none of the available kernel drivers do it on its behalf.

Since intelfb and the rest of the Intel drivers are fairly incompatible, this patch makes the DRM bind to the PCI device so it can register real suspend/resume handlers. Those handlers take care of saving and restoring enough state for X to come back reliably on at least one of my problematic test machines, but text mode still has trouble (still debugging VGA state save/restore, including trying to save/restore actual VRAM contents for possible hibernate support).

Quoted 2 lines

How does this approach look? Is a new DRM driver flag a good thing for similar situations with other drivers? Thoughts?

Looks okay to me... from very quick look.

Quoted 7 lines

linux-core/i915_drv.c static struct drm_bo_driver i915_bo_driver = { · line 98

Quoted 5 lines
linux-core/i915_drv.c +5 -0
+	if (!i915_pipe_enabled(dev, pipe))
+		return;
+
+	if (pipe == PIPE_A)
+		array = dev_priv->savePaletteA;

coding style, we probably want save_palette_A.

Yeah, I tried not to pull over uglies from the X code but I guess I forgot this bit. I should also update the copyright.

Quoted 6 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	unsigned long reg = pipe == PIPE_A ? PALETTE_A : PALETTE_B;

Uff. Mixing = and == and ? in one expression is evil.

I could put parens around it if you think that would help, or just move it to a new line...

I'd use parens around "pipe == PIPE_A".

Greetings,
Rafael

#8 lore raw

Ok, here's yet another version that uses the device model for the suspend/resume, rather than pci hooks.

Greg, DRM desperately needs review of its device model usage, can you take a look at this patch and the current drm_sysfs.c code? Right now, we're mixing class_devices and regular devices (the latter seem to be required for suspend/resume to work correctly), but this seems wrong. Any ideas? Should we just rip out the class_device stuff and create full-on DRM device nodes?

This one also includes the feedback from Pavel & Rafael, along with some fixes that were causing crashes during module unload or X startup.

Thanks,
Jesse

linux-core/Kconfig +0 -0
linux-core/drmP.h +5 -1
index d0ab2c9..39fce95 100644
@@ -619,6 +619,8 @@ struct drm_driver {
 	void (*postclose) (struct drm_device *, struct drm_file *);
 	void (*lastclose) (struct drm_device *);
 	int (*unload) (struct drm_device *);
+	int (*suspend) (struct drm_device *);
+	int (*resume) (struct drm_device *);
 	int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
 	void (*dma_ready) (struct drm_device *);
 	int (*dma_quiescent) (struct drm_device *);
@@ -697,6 +699,7 @@ struct drm_head {
  * may contain multiple heads.
  */
 struct drm_device {
+	struct device dev;		/**< Linux device */
 	char *unique;			/**< Unique identifier: e.g., busid */
 	int unique_len;			/**< Length of unique field */
 	char *devname;			/**< For /proc/interrupts */
@@ -1164,7 +1167,8 @@ extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
 struct drm_sysfs_class;
 extern struct class *drm_sysfs_create(struct module *owner, char *name);
 extern void drm_sysfs_destroy(struct class *cs);
-extern struct class_device *drm_sysfs_device_add(struct class *cs,
+extern struct class_device *drm_sysfs_device_add(struct drm_device *dev,
+						 struct class *cs,
 						 struct drm_head * head);
 extern void drm_sysfs_device_remove(struct class_device *class_dev);
 
linux-core/drm_drv.c +0 -0
linux-core/drm_stub.c +2 -1
index 9e140ac..b0b1001 100644
@@ -183,7 +183,8 @@ static int drm_get_head(struct drm_device * dev, struct drm_head * head)
 				goto err_g1;
 			}
 
-			head->dev_class = drm_sysfs_device_add(drm_class, head);
+			head->dev_class = drm_sysfs_device_add(dev, drm_class,
+							       head);
 			if (IS_ERR(head->dev_class)) {
 				printk(KERN_ERR
 				       "DRM: Error sysfs_device_add.\n");
linux-core/drm_sysfs.c +45 -4

98 lines not on this page · raw message

linux-core/i915_drv.c +455 -0

470 lines not on this page · raw message

shared-core/i915_dma.c +58 -54

207 lines not on this page · raw message

shared-core/i915_drv.h +663 -0

691 lines not on this page · raw message

#9 lore raw
Quoted 9 lines · Jesse Barnes

Ok, here's yet another version that uses the device model for the suspend/resume, rather than pci hooks.

Greg, DRM desperately needs review of its device model usage, can you take a look at this patch and the current drm_sysfs.c code? Right now, we're mixing class_devices and regular devices (the latter seem to be required for suspend/resume to work correctly), but this seems wrong. Any ideas? Should we just rip out the class_device stuff and create full-on DRM device nodes?

The class_device stuff is already ripped out in the latest -mm trees and I will be forwarding that change on for 2.6.25 after 2.6.24 is out. So yes, it should be taken away :)

But converting from class_device to struct device does not mean you use a "device node". But you could if you want to :)

Other than that, the driver model usage isn't the best, but I think the majority of the major issues are fixed up now, especially with the removal of class_device. Is there anything specific you are curious about?

thanks,

greg k-h

#10 lore raw
Quoted 11 lines · Greg KH
Quoted 9 lines · Jesse Barnes

Ok, here's yet another version that uses the device model for the suspend/resume, rather than pci hooks.

Greg, DRM desperately needs review of its device model usage, can you take a look at this patch and the current drm_sysfs.c code? Right now, we're mixing class_devices and regular devices (the latter seem to be required for suspend/resume to work correctly), but this seems wrong. Any ideas? Should we just rip out the class_device stuff and create full-on DRM device nodes?

Quoted 6 lines

The class_device stuff is already ripped out in the latest -mm trees and I will be forwarding that change on for 2.6.25 after 2.6.24 is out. So yes, it should be taken away :)

But converting from class_device to struct device does not mean you use a "device node". But you could if you want to :)

Yeah, bad choice of words. :)

To retain compatibility, we need to have directories under the DRM class dir (/sys/class/drm) for each card (e.g. card0) that contains a file describing which graphics driver is bound to the device. For class devices, we could just add an attributes structure to the device. Can we do the same with regular, non-class devices?

Thanks,
Jesse

#11 lore raw
Quoted 19 lines · Jesse Barnes
Quoted 11 lines · Greg KH
Quoted 9 lines · Jesse Barnes

Ok, here's yet another version that uses the device model for the suspend/resume, rather than pci hooks.

Greg, DRM desperately needs review of its device model usage, can you take a look at this patch and the current drm_sysfs.c code? Right now, we're mixing class_devices and regular devices (the latter seem to be required for suspend/resume to work correctly), but this seems wrong. Any ideas? Should we just rip out the class_device stuff and create full-on DRM device nodes?

Quoted 6 lines

The class_device stuff is already ripped out in the latest -mm trees and I will be forwarding that change on for 2.6.25 after 2.6.24 is out. So yes, it should be taken away :)

But converting from class_device to struct device does not mean you use a "device node". But you could if you want to :)

Quoted 7 lines

Yeah, bad choice of words. :)

To retain compatibility, we need to have directories under the DRM class dir (/sys/class/drm) for each card (e.g. card0) that contains a file describing which graphics driver is bound to the device. For class devices, we could just add an attributes structure to the device. Can we do the same with regular, non-class devices?

The conversion is already queued in Greg's tree, and in -mm:
http://git.kernel.org/?p=linux/kernel/git/gregkh/patches.git;a=blob;f=driver/drm-convert-from-class_device-to-device-in-drivers-char-drm.patch;h=f993183d1cb017f981cc2232d17930af40459bd8;hb=HEAD

/sys/class/drm will look the same as with the class_device's, only if !CONFIG_SYSFS_DEPRECATED, there will be symlinks instead of directories, otherwise the same pathes, like for all other (converted) classes too.

Thanks,
Kay

#12 lore raw
Quoted 4 lines · Kay Sievers

The conversion is already queued in Greg's tree, and in -mm:
http://git.kernel.org/?p=linux/kernel/git/gregkh/patches.git;a=blob;f
=driver/drm-convert-from-class_device-to-device-in-drivers-char-drm.pa tch;h=f993183d1cb017f981cc2232d17930af40459bd8;hb=HEAD

Hm, I've done it slightly differently, by adding an actual device to the drm_device structure... I'll post it once I've cleaned it up a little more.

Quoted 4 lines

/sys/class/drm will look the same as with the class_device's, only if !CONFIG_SYSFS_DEPRECATED, there will be symlinks instead of directories, otherwise the same pathes, like for all other (converted) classes too.

Ok, thanks.

Jesse

#13 lore raw
Quoted 9 lines · Jesse Barnes
Quoted 4 lines · Kay Sievers

The conversion is already queued in Greg's tree, and in -mm:
http://git.kernel.org/?p=linux/kernel/git/gregkh/patches.git;a=blob;f
=driver/drm-convert-from-class_device-to-device-in-drivers-char-drm.pa tch;h=f993183d1cb017f981cc2232d17930af40459bd8;hb=HEAD

Hm, I've done it slightly differently, by adding an actual device to the drm_device structure... I'll post it once I've cleaned it up a little more.

Sure, as long as "struct class_device" is no longer used in the code, and you don't embed two "struct device" device structures in a single object, all should be fine.
We plan to remove "struct class_device" soon from the kernel. :)

Thanks,
Kay

#14 lore raw

Re: fixing up DRM device model usage

In reply to Kay Sievers
Quoted 34 lines · Kay Sievers
Quoted 20 lines · Jesse Barnes
Quoted 12 lines · Greg KH
Quoted 10 lines · Jesse Barnes

Ok, here's yet another version that uses the device model for the suspend/resume, rather than pci hooks.

Greg, DRM desperately needs review of its device model usage, can you take a look at this patch and the current drm_sysfs.c code? Right now, we're mixing class_devices and regular devices (the latter seem to be required for suspend/resume to work correctly), but this seems wrong. Any ideas? Should we just rip out the class_device stuff and create full-on DRM device nodes?

Quoted 6 lines

The class_device stuff is already ripped out in the latest -mm trees and I will be forwarding that change on for 2.6.25 after 2.6.24 is out. So yes, it should be taken away :)

But converting from class_device to struct device does not mean you use a "device node". But you could if you want to :)

Quoted 7 lines

Yeah, bad choice of words. :)

To retain compatibility, we need to have directories under the DRM class dir (/sys/class/drm) for each card (e.g. card0) that contains a file describing which graphics driver is bound to the device. For class devices, we could just add an attributes structure to the device. Can we do the same with regular, non-class devices?

The conversion is already queued in Greg's tree, and in -mm:
http://git.kernel.org/?p=linux/kernel/git/gregkh/patches.git;a=blob;f
=driver/drm-convert-from-class_device-to-device-in-drivers-char-drm.pa tch;h=f993183d1cb017f981cc2232d17930af40459bd8;hb=HEAD

Quoted 4 lines

/sys/class/drm will look the same as with the class_device's, only if !CONFIG_SYSFS_DEPRECATED, there will be symlinks instead of directories, otherwise the same pathes, like for all other (converted) classes too.

How does this conversion look? It retains directory compatibility with the old scheme, but I'm not sure about the dev->dev.parent value. I'm using the PCI device corresponding to the DRM device as the parent, but maybe I don't need one at all?

Dave, the drm_head stuff is a bit funky; it seems like a partially implemented feature? I wonder if we should rip that out too, just to keep things simple...

Thanks,
Jesse

linux-core/Kconfig +0 -0
linux-core/drmP.h +6 -4
index d0ab2c9..82a3a23 100644
@@ -619,6 +619,8 @@ struct drm_driver {
 	void (*postclose) (struct drm_device *, struct drm_file *);
 	void (*lastclose) (struct drm_device *);
 	int (*unload) (struct drm_device *);
+	int (*suspend) (struct drm_device *);
+	int (*resume) (struct drm_device *);
 	int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
 	void (*dma_ready) (struct drm_device *);
 	int (*dma_quiescent) (struct drm_device *);
@@ -697,6 +699,7 @@ struct drm_head {
  * may contain multiple heads.
  */
 struct drm_device {
+	struct device dev;		/**< Linux device */
 	char *unique;			/**< Unique identifier: e.g., busid */
 	int unique_len;			/**< Length of unique field */
 	char *devname;			/**< For /proc/interrupts */
@@ -1163,10 +1166,9 @@ extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
 			       /* sysfs support (drm_sysfs.c) */
 struct drm_sysfs_class;
 extern struct class *drm_sysfs_create(struct module *owner, char *name);
-extern void drm_sysfs_destroy(struct class *cs);
-extern struct class_device *drm_sysfs_device_add(struct class *cs,
-						 struct drm_head * head);
-extern void drm_sysfs_device_remove(struct class_device *class_dev);
+extern void drm_sysfs_destroy(void);
+extern int drm_sysfs_device_add(struct drm_device *dev, struct drm_head * head);
+extern void drm_sysfs_device_remove(struct drm_device *dev);
 
 /*
  * Basic memory manager support (drm_mm.c)
linux-core/drm_drv.c +2 -2
index fe2b120..47d1765 100644
@@ -519,7 +519,7 @@ static int __init drm_core_init(void)
 		 CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
 	return 0;
 err_p3:
-	drm_sysfs_destroy(drm_class);
+	drm_sysfs_destroy();
 err_p2:
 	unregister_chrdev(DRM_MAJOR, "drm");
 	drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
@@ -530,7 +530,7 @@ err_p1:
 static void __exit drm_core_exit(void)
 {
 	remove_proc_entry("dri", NULL);
-	drm_sysfs_destroy(drm_class);
+	drm_sysfs_destroy();
 
 	unregister_chrdev(DRM_MAJOR, "drm");
 
linux-core/drm_stub.c +3 -4
index 9e140ac..1d88d37 100644
@@ -183,11 +183,10 @@ static int drm_get_head(struct drm_device * dev, struct drm_head * head)
 				goto err_g1;
 			}
 
-			head->dev_class = drm_sysfs_device_add(drm_class, head);
-			if (IS_ERR(head->dev_class)) {
+			ret = drm_sysfs_device_add(dev, head);
+			if (ret) {
 				printk(KERN_ERR
 				       "DRM: Error sysfs_device_add.\n");
-				ret = PTR_ERR(head->dev_class);
 				goto err_g2;
 			}
 			*heads = head;
@@ -316,7 +315,7 @@ int drm_put_head(struct drm_head * head)
 	DRM_DEBUG("release secondary minor %d\n", minor);
 
 	drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
-	drm_sysfs_device_remove(head->dev_class);
+	drm_sysfs_device_remove(head->dev);
 
 	*head = (struct drm_head){.dev = NULL};
 
linux-core/drm_sysfs.c +92 -49

205 lines not on this page · raw message

#15 lore raw

Re: fixing up DRM device model usage

Quoted 35 lines · Jesse Barnes
Quoted 34 lines · Kay Sievers
Quoted 20 lines · Jesse Barnes
Quoted 12 lines · Greg KH
Quoted 10 lines · Jesse Barnes

Ok, here's yet another version that uses the device model for the suspend/resume, rather than pci hooks.

Greg, DRM desperately needs review of its device model usage, can you take a look at this patch and the current drm_sysfs.c code? Right now, we're mixing class_devices and regular devices (the latter seem to be required for suspend/resume to work correctly), but this seems wrong. Any ideas? Should we just rip out the class_device stuff and create full-on DRM device nodes?

Quoted 6 lines

The class_device stuff is already ripped out in the latest -mm trees and I will be forwarding that change on for 2.6.25 after 2.6.24 is out. So yes, it should be taken away :)

But converting from class_device to struct device does not mean you use a "device node". But you could if you want to :)

Quoted 7 lines

Yeah, bad choice of words. :)

To retain compatibility, we need to have directories under the DRM class dir (/sys/class/drm) for each card (e.g. card0) that contains a file describing which graphics driver is bound to the device. For class devices, we could just add an attributes structure to the device. Can we do the same with regular, non-class devices?

The conversion is already queued in Greg's tree, and in -mm:
http://git.kernel.org/?p=linux/kernel/git/gregkh/patches.git;a=blob;f
=driver/drm-convert-from-class_device-to-device-in-drivers-char-drm.pa tch;h=f993183d1cb017f981cc2232d17930af40459bd8;hb=HEAD

Quoted 6 lines
Quoted 4 lines

/sys/class/drm will look the same as with the class_device's, only if !CONFIG_SYSFS_DEPRECATED, there will be symlinks instead of directories, otherwise the same pathes, like for all other (converted) classes too.

How does this conversion look?

Seems fine, at a first look. You moved the device structure into the object where it belongs, instead of allocating one, and saving the pointer. You should really considering changing the core to do the free()ing of your object with the embedded devices release function, that is called when the last reference to the object is gone, instead of "hoping the best". :) But if the drm core does that properly, it might work, sure.

The open coded: device_create_file(&dev->dev, &device_attrs[i]) should probably replaced by passing the array to the class, and the core will do that for you.

Do you assign the dev_t: MKDEV(DRM_MAJOR, head->minor) somewhere? You need to put it in dev->devt, if you want a device node created by userspace.

Quoted 2 lines

It retains directory compatibility with
the old scheme, but I'm not sure about the dev->dev.parent value.

You should use the same value as the old code:
&(head->dev->pdev)->dev
and assign it as the parent, seems right..

Quoted 2 lines

I'm using the PCI device corresponding to the DRM device as the parent, but maybe I don't need one at all?

Keep it, you want to express the relationship in sysfs, so that a "device" link is created, or that the device directory lives as a child below the parent device. Seems fine so far.

Quoted 3 lines

Dave, the drm_head stuff is a bit funky; it seems like a partially implemented feature? I wonder if we should rip that out too, just to keep things simple...

Hehe, that's always a solution. :)

Kay

#16 lore raw

Re: fixing up DRM device model usage

Quoted 9 lines · Kay Sievers
Quoted 1 line

How does this conversion look?

Seems fine, at a first look. You moved the device structure into the object where it belongs, instead of allocating one, and saving the pointer. You should really considering changing the core to do the free()ing of your object with the embedded devices release function, that is called when the last reference to the object is gone, instead of "hoping the best". :) But if the drm core does that properly, it might work, sure.

Yeah, but that'll require other changes to the DRM. Maybe I can tackle that as part of the refactoring I'm doing for some other work.

Quoted 3 lines

The open coded: device_create_file(&dev->dev, &device_attrs[i]) should probably replaced by passing the array to the class, and the core will do that for you.

You mean just set drm_class->dev_attrs = device_attrs? I didn't see in the core device model code where that would create the files...

Quoted 3 lines

Do you assign the dev_t: MKDEV(DRM_MAJOR, head->minor) somewhere? You need to put it in dev->devt, if you want a device node created by userspace.

Yeah, that's part of the drm_head structure. I'll go ahead and assign it to dev->devt too.

Quoted 7 lines
Quoted 2 lines

It retains directory compatibility with
the old scheme, but I'm not sure about the dev->dev.parent value.

You should use the same value as the old code:
&(head->dev->pdev)->dev
and assign it as the parent, seems right..

Quoted 6 lines
Quoted 2 lines

I'm using the PCI device corresponding to the DRM device as the parent, but maybe I don't need one at all?

Keep it, you want to express the relationship in sysfs, so that a "device" link is created, or that the device directory lives as a child below the parent device. Seems fine so far.

Ok, sounds good.

Quoted 6 lines
Quoted 4 lines

Dave, the drm_head stuff is a bit funky; it seems like a partially implemented feature? I wonder if we should rip that out too, just to keep things simple...

Hehe, that's always a solution. :)

Yeah, removing code is nearly always a win. :)

Thanks,
Jesse

linux-core/drmP.h +6 -4
index d0ab2c9..82a3a23 100644
@@ -619,6 +619,8 @@ struct drm_driver {
 	void (*postclose) (struct drm_device *, struct drm_file *);
 	void (*lastclose) (struct drm_device *);
 	int (*unload) (struct drm_device *);
+	int (*suspend) (struct drm_device *);
+	int (*resume) (struct drm_device *);
 	int (*dma_ioctl) (struct drm_device *dev, void *data, struct drm_file *file_priv);
 	void (*dma_ready) (struct drm_device *);
 	int (*dma_quiescent) (struct drm_device *);
@@ -697,6 +699,7 @@ struct drm_head {
  * may contain multiple heads.
  */
 struct drm_device {
+	struct device dev;		/**< Linux device */
 	char *unique;			/**< Unique identifier: e.g., busid */
 	int unique_len;			/**< Length of unique field */
 	char *devname;			/**< For /proc/interrupts */
@@ -1163,10 +1166,9 @@ extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t *dmah);
 			       /* sysfs support (drm_sysfs.c) */
 struct drm_sysfs_class;
 extern struct class *drm_sysfs_create(struct module *owner, char *name);
-extern void drm_sysfs_destroy(struct class *cs);
-extern struct class_device *drm_sysfs_device_add(struct class *cs,
-						 struct drm_head * head);
-extern void drm_sysfs_device_remove(struct class_device *class_dev);
+extern void drm_sysfs_destroy(void);
+extern int drm_sysfs_device_add(struct drm_device *dev, struct drm_head * head);
+extern void drm_sysfs_device_remove(struct drm_device *dev);
 
 /*
  * Basic memory manager support (drm_mm.c)
linux-core/drm_drv.c +2 -2
index fe2b120..47d1765 100644
@@ -519,7 +519,7 @@ static int __init drm_core_init(void)
 		 CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
 	return 0;
 err_p3:
-	drm_sysfs_destroy(drm_class);
+	drm_sysfs_destroy();
 err_p2:
 	unregister_chrdev(DRM_MAJOR, "drm");
 	drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
@@ -530,7 +530,7 @@ err_p1:
 static void __exit drm_core_exit(void)
 {
 	remove_proc_entry("dri", NULL);
-	drm_sysfs_destroy(drm_class);
+	drm_sysfs_destroy();
 
 	unregister_chrdev(DRM_MAJOR, "drm");
 
linux-core/drm_stub.c +3 -4
index 9e140ac..1d88d37 100644
@@ -183,11 +183,10 @@ static int drm_get_head(struct drm_device * dev, struct drm_head * head)
 				goto err_g1;
 			}
 
-			head->dev_class = drm_sysfs_device_add(drm_class, head);
-			if (IS_ERR(head->dev_class)) {
+			ret = drm_sysfs_device_add(dev, head);
+			if (ret) {
 				printk(KERN_ERR
 				       "DRM: Error sysfs_device_add.\n");
-				ret = PTR_ERR(head->dev_class);
 				goto err_g2;
 			}
 			*heads = head;
@@ -316,7 +315,7 @@ int drm_put_head(struct drm_head * head)
 	DRM_DEBUG("release secondary minor %d\n", minor);
 
 	drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
-	drm_sysfs_device_remove(head->dev_class);
+	drm_sysfs_device_remove(head->dev);
 
 	*head = (struct drm_head){.dev = NULL};
 
linux-core/drm_sysfs.c +97 -49

210 lines not on this page · raw message

#17 lore raw

Re: fixing up DRM device model usage

Quoted 8 lines · Jesse Barnes
Quoted 3 lines · Kay Sievers

The open coded: device_create_file(&dev->dev, &device_attrs[i]) should probably replaced by passing the array to the class, and the core will do that for you.

You mean just set drm_class->dev_attrs = device_attrs? I didn't see in the core device model code where that would create the files...

Yeah, it is in device_add_attrs() in drivers/base/core.c.

Kay