aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/drm_sysfs.c
diff options
context:
space:
mode:
authorJesse Barnes <jesse.barnes@intel.com>2007-11-21 23:02:38 -0500
committerDave Airlie <airlied@redhat.com>2008-02-07 00:09:38 -0500
commite8b962b6df50b74afed14af7f7a7d569b3ba70ac (patch)
tree4b40becefb49018a4b02a217673e44637040f4f6 /drivers/char/drm/drm_sysfs.c
parent8b40958032fd236194de57d29be9cf2c1f2643ee (diff)
drm: update DRM sysfs support
Make DRM devices use real Linux devices instead of class devices, which are going away. While we're at it, clean up some of the interfaces to take struct drm_device * or struct device * and use the global drm_class where needed instead of passing it around. Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char/drm/drm_sysfs.c')
-rw-r--r--drivers/char/drm/drm_sysfs.c151
1 files changed, 102 insertions, 49 deletions
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index cf4349b00b07..6f8623ce045e 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -19,6 +19,45 @@
19#include "drm_core.h" 19#include "drm_core.h"
20#include "drmP.h" 20#include "drmP.h"
21 21
22#define to_drm_device(d) container_of(d, struct drm_device, dev)
23
24/**
25 * drm_sysfs_suspend - DRM class suspend hook
26 * @dev: Linux device to suspend
27 * @state: power state to enter
28 *
29 * Just figures out what the actual struct drm_device associated with
30 * @dev is and calls its suspend hook, if present.
31 */
32static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
33{
34 struct drm_device *drm_dev = to_drm_device(dev);
35
36 printk(KERN_ERR "%s\n", __FUNCTION__);
37
38 if (drm_dev->driver->suspend)
39 return drm_dev->driver->suspend(drm_dev);
40
41 return 0;
42}
43
44/**
45 * drm_sysfs_resume - DRM class resume hook
46 * @dev: Linux device to resume
47 *
48 * Just figures out what the actual struct drm_device associated with
49 * @dev is and calls its resume hook, if present.
50 */
51static int drm_sysfs_resume(struct device *dev)
52{
53 struct drm_device *drm_dev = to_drm_device(dev);
54
55 if (drm_dev->driver->resume)
56 return drm_dev->driver->resume(drm_dev);
57
58 return 0;
59}
60
22/* Display the version of drm_core. This doesn't work right in current design */ 61/* Display the version of drm_core. This doesn't work right in current design */
23static ssize_t version_show(struct class *dev, char *buf) 62static ssize_t version_show(struct class *dev, char *buf)
24{ 63{
@@ -33,7 +72,7 @@ static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
33 * @owner: pointer to the module that is to "own" this struct drm_sysfs_class 72 * @owner: pointer to the module that is to "own" this struct drm_sysfs_class
34 * @name: pointer to a string for the name of this class. 73 * @name: pointer to a string for the name of this class.
35 * 74 *
36 * This is used to create a struct drm_sysfs_class pointer that can then be used 75 * This is used to create DRM class pointer that can then be used
37 * in calls to drm_sysfs_device_add(). 76 * in calls to drm_sysfs_device_add().
38 * 77 *
39 * Note, the pointer created here is to be destroyed when finished by making a 78 * Note, the pointer created here is to be destroyed when finished by making a
@@ -50,6 +89,9 @@ struct class *drm_sysfs_create(struct module *owner, char *name)
50 goto err_out; 89 goto err_out;
51 } 90 }
52 91
92 class->suspend = drm_sysfs_suspend;
93 class->resume = drm_sysfs_resume;
94
53 err = class_create_file(class, &class_attr_version); 95 err = class_create_file(class, &class_attr_version);
54 if (err) 96 if (err)
55 goto err_out_class; 97 goto err_out_class;
@@ -63,94 +105,105 @@ err_out:
63} 105}
64 106
65/** 107/**
66 * drm_sysfs_destroy - destroys a struct drm_sysfs_class structure 108 * drm_sysfs_destroy - destroys DRM class
67 * @cs: pointer to the struct drm_sysfs_class that is to be destroyed
68 * 109 *
69 * Note, the pointer to be destroyed must have been created with a call to 110 * Destroy the DRM device class.
70 * drm_sysfs_create().
71 */ 111 */
72void drm_sysfs_destroy(struct class *class) 112void drm_sysfs_destroy(void)
73{ 113{
74 if ((class == NULL) || (IS_ERR(class))) 114 if ((drm_class == NULL) || (IS_ERR(drm_class)))
75 return; 115 return;
76 116 class_remove_file(drm_class, &class_attr_version);
77 class_remove_file(class, &class_attr_version); 117 class_destroy(drm_class);
78 class_destroy(class);
79} 118}
80 119
81static ssize_t show_dri(struct class_device *class_device, char *buf) 120static ssize_t show_dri(struct device *device, struct device_attribute *attr,
121 char *buf)
82{ 122{
83 struct drm_device * dev = ((struct drm_head *)class_get_devdata(class_device))->dev; 123 struct drm_device *dev = to_drm_device(device);
84 if (dev->driver->dri_library_name) 124 if (dev->driver->dri_library_name)
85 return dev->driver->dri_library_name(dev, buf); 125 return dev->driver->dri_library_name(dev, buf);
86 return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name); 126 return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name);
87} 127}
88 128
89static struct class_device_attribute class_device_attrs[] = { 129static struct device_attribute device_attrs[] = {
90 __ATTR(dri_library_name, S_IRUGO, show_dri, NULL), 130 __ATTR(dri_library_name, S_IRUGO, show_dri, NULL),
91}; 131};
92 132
93/** 133/**
134 * drm_sysfs_device_release - do nothing
135 * @dev: Linux device
136 *
137 * Normally, this would free the DRM device associated with @dev, along
138 * with cleaning up any other stuff. But we do that in the DRM core, so
139 * this function can just return and hope that the core does its job.
140 */
141static void drm_sysfs_device_release(struct device *dev)
142{
143 return;
144}
145
146/**
94 * drm_sysfs_device_add - adds a class device to sysfs for a character driver 147 * drm_sysfs_device_add - adds a class device to sysfs for a character driver
95 * @cs: pointer to the struct class that this device should be registered to. 148 * @dev: DRM device to be added
96 * @dev: the dev_t for the device to be added. 149 * @head: DRM head in question
97 * @device: a pointer to a struct device that is assiociated with this class device.
98 * @fmt: string for the class device's name
99 * 150 *
100 * A struct class_device will be created in sysfs, registered to the specified 151 * Add a DRM device to the DRM's device model class. We use @dev's PCI device
101 * class. A "dev" file will be created, showing the dev_t for the device. The 152 * as the parent for the Linux device, and make sure it has a file containing
102 * pointer to the struct class_device will be returned from the call. Any further 153 * the driver we're using (for userspace compatibility).
103 * sysfs files that might be required can be created using this pointer.
104 * Note: the struct class passed to this function must have previously been
105 * created with a call to drm_sysfs_create().
106 */ 154 */
107struct class_device *drm_sysfs_device_add(struct class *cs, struct drm_head *head) 155int drm_sysfs_device_add(struct drm_device *dev, struct drm_head *head)
108{ 156{
109 struct class_device *class_dev; 157 int err;
110 int i, j, err; 158 int i, j;
111 159
112 class_dev = class_device_create(cs, NULL, 160 dev->dev.parent = &dev->pdev->dev;
113 MKDEV(DRM_MAJOR, head->minor), 161 dev->dev.class = drm_class;
114 &(head->dev->pdev)->dev, 162 dev->dev.release = drm_sysfs_device_release;
115 "card%d", head->minor); 163 /*
116 if (IS_ERR(class_dev)) { 164 * This will actually add the major:minor file so that udev
117 err = PTR_ERR(class_dev); 165 * will create the device node. We don't want to do that just
166 * yet...
167 */
168 /* dev->dev.devt = head->device; */
169 snprintf(dev->dev.bus_id, BUS_ID_SIZE, "card%d", head->minor);
170
171 err = device_register(&dev->dev);
172 if (err) {
173 DRM_ERROR("device add failed: %d\n", err);
118 goto err_out; 174 goto err_out;
119 } 175 }
120 176
121 class_set_devdata(class_dev, head); 177 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
122 178 err = device_create_file(&dev->dev, &device_attrs[i]);
123 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
124 err = class_device_create_file(class_dev,
125 &class_device_attrs[i]);
126 if (err) 179 if (err)
127 goto err_out_files; 180 goto err_out_files;
128 } 181 }
129 182
130 return class_dev; 183 return 0;
131 184
132err_out_files: 185err_out_files:
133 if (i > 0) 186 if (i > 0)
134 for (j = 0; j < i; j++) 187 for (j = 0; j < i; j++)
135 class_device_remove_file(class_dev, 188 device_remove_file(&dev->dev, &device_attrs[i]);
136 &class_device_attrs[i]); 189 device_unregister(&dev->dev);
137 class_device_unregister(class_dev);
138err_out: 190err_out:
139 return ERR_PTR(err); 191
192 return err;
140} 193}
141 194
142/** 195/**
143 * drm_sysfs_device_remove - removes a class device that was created with drm_sysfs_device_add() 196 * drm_sysfs_device_remove - remove DRM device
144 * @dev: the dev_t of the device that was previously registered. 197 * @dev: DRM device to remove
145 * 198 *
146 * This call unregisters and cleans up a class device that was created with a 199 * This call unregisters and cleans up a class device that was created with a
147 * call to drm_sysfs_device_add() 200 * call to drm_sysfs_device_add()
148 */ 201 */
149void drm_sysfs_device_remove(struct class_device *class_dev) 202void drm_sysfs_device_remove(struct drm_device *dev)
150{ 203{
151 int i; 204 int i;
152 205
153 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 206 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
154 class_device_remove_file(class_dev, &class_device_attrs[i]); 207 device_remove_file(&dev->dev, &device_attrs[i]);
155 class_device_unregister(class_dev); 208 device_unregister(&dev->dev);
156} 209}