aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/drm_sysfs.c
diff options
context:
space:
mode:
authorDave Airlie <airlied@redhat.com>2008-04-21 02:47:32 -0400
committerDave Airlie <airlied@linux.ie>2008-04-26 03:55:07 -0400
commit2c14f28be2a3f2a2e9861b156d64fbe2bc7000c3 (patch)
treedbf55c07d1b245a45330e0d879833df29954fe12 /drivers/char/drm/drm_sysfs.c
parent7b832b56bd971348329c3f4c753ca0abfdf3a3d1 (diff)
drm: reorganise minor number handling using backported modesetting code.
rips out the head crap and replaces it with an idr and drm_minor structure Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/char/drm/drm_sysfs.c')
-rw-r--r--drivers/char/drm/drm_sysfs.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index 05ed5043254f..7a1d9a782ddb 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -19,7 +19,7 @@
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) 22#define to_drm_minor(d) container_of(d, struct drm_minor, kdev)
23 23
24/** 24/**
25 * drm_sysfs_suspend - DRM class suspend hook 25 * drm_sysfs_suspend - DRM class suspend hook
@@ -31,7 +31,8 @@
31 */ 31 */
32static int drm_sysfs_suspend(struct device *dev, pm_message_t state) 32static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
33{ 33{
34 struct drm_device *drm_dev = to_drm_device(dev); 34 struct drm_minor *drm_minor = to_drm_minor(dev);
35 struct drm_device *drm_dev = drm_minor->dev;
35 36
36 printk(KERN_ERR "%s\n", __FUNCTION__); 37 printk(KERN_ERR "%s\n", __FUNCTION__);
37 38
@@ -50,7 +51,8 @@ static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
50 */ 51 */
51static int drm_sysfs_resume(struct device *dev) 52static int drm_sysfs_resume(struct device *dev)
52{ 53{
53 struct drm_device *drm_dev = to_drm_device(dev); 54 struct drm_minor *drm_minor = to_drm_minor(dev);
55 struct drm_device *drm_dev = drm_minor->dev;
54 56
55 if (drm_dev->driver->resume) 57 if (drm_dev->driver->resume)
56 return drm_dev->driver->resume(drm_dev); 58 return drm_dev->driver->resume(drm_dev);
@@ -120,10 +122,11 @@ void drm_sysfs_destroy(void)
120static ssize_t show_dri(struct device *device, struct device_attribute *attr, 122static ssize_t show_dri(struct device *device, struct device_attribute *attr,
121 char *buf) 123 char *buf)
122{ 124{
123 struct drm_device *dev = to_drm_device(device); 125 struct drm_minor *drm_minor = to_drm_minor(device);
124 if (dev->driver->dri_library_name) 126 struct drm_device *drm_dev = drm_minor->dev;
125 return dev->driver->dri_library_name(dev, buf); 127 if (drm_dev->driver->dri_library_name)
126 return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name); 128 return drm_dev->driver->dri_library_name(drm_dev, buf);
129 return snprintf(buf, PAGE_SIZE, "%s\n", drm_dev->driver->pci_driver.name);
127} 130}
128 131
129static struct device_attribute device_attrs[] = { 132static struct device_attribute device_attrs[] = {
@@ -152,25 +155,28 @@ static void drm_sysfs_device_release(struct device *dev)
152 * as the parent for the Linux device, and make sure it has a file containing 155 * as the parent for the Linux device, and make sure it has a file containing
153 * the driver we're using (for userspace compatibility). 156 * the driver we're using (for userspace compatibility).
154 */ 157 */
155int drm_sysfs_device_add(struct drm_device *dev, struct drm_head *head) 158int drm_sysfs_device_add(struct drm_minor *minor)
156{ 159{
157 int err; 160 int err;
158 int i, j; 161 int i, j;
162 char *minor_str;
159 163
160 dev->dev.parent = &dev->pdev->dev; 164 minor->kdev.parent = &minor->dev->pdev->dev;
161 dev->dev.class = drm_class; 165 minor->kdev.class = drm_class;
162 dev->dev.release = drm_sysfs_device_release; 166 minor->kdev.release = drm_sysfs_device_release;
163 dev->dev.devt = head->device; 167 minor->kdev.devt = minor->device;
164 snprintf(dev->dev.bus_id, BUS_ID_SIZE, "card%d", head->minor); 168 minor_str = "card%d";
165 169
166 err = device_register(&dev->dev); 170 snprintf(minor->kdev.bus_id, BUS_ID_SIZE, minor_str, minor->index);
171
172 err = device_register(&minor->kdev);
167 if (err) { 173 if (err) {
168 DRM_ERROR("device add failed: %d\n", err); 174 DRM_ERROR("device add failed: %d\n", err);
169 goto err_out; 175 goto err_out;
170 } 176 }
171 177
172 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { 178 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
173 err = device_create_file(&dev->dev, &device_attrs[i]); 179 err = device_create_file(&minor->kdev, &device_attrs[i]);
174 if (err) 180 if (err)
175 goto err_out_files; 181 goto err_out_files;
176 } 182 }
@@ -180,8 +186,8 @@ int drm_sysfs_device_add(struct drm_device *dev, struct drm_head *head)
180err_out_files: 186err_out_files:
181 if (i > 0) 187 if (i > 0)
182 for (j = 0; j < i; j++) 188 for (j = 0; j < i; j++)
183 device_remove_file(&dev->dev, &device_attrs[i]); 189 device_remove_file(&minor->kdev, &device_attrs[i]);
184 device_unregister(&dev->dev); 190 device_unregister(&minor->kdev);
185err_out: 191err_out:
186 192
187 return err; 193 return err;
@@ -194,11 +200,11 @@ err_out:
194 * This call unregisters and cleans up a class device that was created with a 200 * This call unregisters and cleans up a class device that was created with a
195 * call to drm_sysfs_device_add() 201 * call to drm_sysfs_device_add()
196 */ 202 */
197void drm_sysfs_device_remove(struct drm_device *dev) 203void drm_sysfs_device_remove(struct drm_minor *minor)
198{ 204{
199 int i; 205 int i;
200 206
201 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) 207 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
202 device_remove_file(&dev->dev, &device_attrs[i]); 208 device_remove_file(&minor->kdev, &device_attrs[i]);
203 device_unregister(&dev->dev); 209 device_unregister(&minor->kdev);
204} 210}