Simplify the sysfs code

main
Jon Smirl 2005-07-03 18:07:03 +00:00
parent d41af11ee3
commit 04fea06002
3 changed files with 15 additions and 48 deletions

View File

@ -988,11 +988,8 @@ extern struct drm_sysfs_class *drm_sysfs_create(struct module *owner,
char *name); char *name);
extern void drm_sysfs_destroy(struct drm_sysfs_class *cs); extern void drm_sysfs_destroy(struct drm_sysfs_class *cs);
extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
drm_head_t * head, drm_head_t * head);
dev_t dev, extern void drm_sysfs_device_remove(struct class_device *class_dev);
struct device *device,
const char *fmt, ...);
extern void drm_sysfs_device_remove(dev_t dev);
/* Inline replacements for DRM_IOREMAP macros */ /* Inline replacements for DRM_IOREMAP macros */
static __inline__ void drm_core_ioremap(struct drm_map *map, static __inline__ void drm_core_ioremap(struct drm_map *map,

View File

@ -165,10 +165,7 @@ static int drm_get_head(drm_device_t * dev, drm_head_t * head)
goto err_g1; goto err_g1;
} }
head->dev_class = drm_sysfs_device_add(drm_class, head->dev_class = drm_sysfs_device_add(drm_class, head);
head, MKDEV(DRM_MAJOR, minor),
DRM_PCI_DEV(dev->pdev),
"card%d", minor);
if (IS_ERR(head->dev_class)) { if (IS_ERR(head->dev_class)) {
printk(KERN_ERR printk(KERN_ERR
"DRM: Error sysfs_device_add.\n"); "DRM: Error sysfs_device_add.\n");
@ -292,7 +289,7 @@ int drm_put_head(drm_head_t * head)
DRM_DEBUG("release secondary minor %d\n", minor); DRM_DEBUG("release secondary minor %d\n", minor);
drm_proc_cleanup(minor, drm_proc_root, head->dev_root); drm_proc_cleanup(minor, drm_proc_root, head->dev_root);
drm_sysfs_device_remove(MKDEV(DRM_MAJOR, head->minor)); drm_sysfs_device_remove(head->dev_class);
*head = (drm_head_t){.dev = NULL}; *head = (drm_head_t){.dev = NULL};

View File

@ -26,15 +26,11 @@ struct drm_sysfs_class {
#define to_drm_sysfs_class(d) container_of(d, struct drm_sysfs_class, class) #define to_drm_sysfs_class(d) container_of(d, struct drm_sysfs_class, class)
struct simple_dev { struct simple_dev {
struct list_head node;
dev_t dev; dev_t dev;
struct class_device class_dev; struct class_device class_dev;
}; };
#define to_simple_dev(d) container_of(d, struct simple_dev, class_dev) #define to_simple_dev(d) container_of(d, struct simple_dev, class_dev)
static LIST_HEAD(simple_dev_list);
static spinlock_t simple_dev_list_lock = SPIN_LOCK_UNLOCKED;
static void release_simple_dev(struct class_device *class_dev) static void release_simple_dev(struct class_device *class_dev)
{ {
struct simple_dev *s_dev = to_simple_dev(class_dev); struct simple_dev *s_dev = to_simple_dev(class_dev);
@ -148,11 +144,9 @@ static struct class_device_attribute class_device_attrs[] = {
* Note: the struct drm_sysfs_class passed to this function must have previously been * Note: the struct drm_sysfs_class passed to this function must have previously been
* created with a call to drm_sysfs_create(). * created with a call to drm_sysfs_create().
*/ */
struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, struct class_device *drm_sysfs_device_add(
drm_head_t * head, dev_t dev, struct drm_sysfs_class *cs, drm_head_t * head)
struct device *device, const char *fmt, ...)
{ {
va_list args;
struct simple_dev *s_dev = NULL; struct simple_dev *s_dev = NULL;
int i, retval; int i, retval;
@ -168,23 +162,16 @@ struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
} }
memset(s_dev, 0x00, sizeof(*s_dev)); memset(s_dev, 0x00, sizeof(*s_dev));
s_dev->dev = dev; s_dev->dev = MKDEV(DRM_MAJOR, head->minor);
s_dev->class_dev.dev = device; s_dev->class_dev.dev = DRM_PCI_DEV(head->dev->pdev);
s_dev->class_dev.class = &cs->class; s_dev->class_dev.class = &cs->class;
va_start(args, fmt); snprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, "card%d", head->minor);
vsnprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, fmt, args);
va_end(args);
retval = class_device_register(&s_dev->class_dev); retval = class_device_register(&s_dev->class_dev);
if (retval) if (retval)
goto error; goto error;
class_device_create_file(&s_dev->class_dev, &cs->attr); class_device_create_file(&s_dev->class_dev, &cs->attr);
spin_lock(&simple_dev_list_lock);
list_add(&s_dev->node, &simple_dev_list);
spin_unlock(&simple_dev_list_lock);
class_set_devdata(&s_dev->class_dev, head); class_set_devdata(&s_dev->class_dev, head);
for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
@ -204,27 +191,13 @@ error:
* This call unregisters and cleans up a class device that was created with a * This call unregisters and cleans up a class device that was created with a
* call to drm_sysfs_device_add() * call to drm_sysfs_device_add()
*/ */
void drm_sysfs_device_remove(dev_t dev) void drm_sysfs_device_remove(struct class_device *class_dev)
{ {
struct simple_dev *s_dev = NULL; struct simple_dev *s_dev = to_simple_dev(class_dev);
int i, found = 0; int i;
spin_lock(&simple_dev_list_lock); for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
list_for_each_entry(s_dev, &simple_dev_list, node) { class_device_remove_file(&s_dev->class_dev, &class_device_attrs[i]);
if (s_dev->dev == dev) {
found = 1;
break;
}
}
if (found) {
list_del(&s_dev->node);
spin_unlock(&simple_dev_list_lock);
for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) class_device_unregister(&s_dev->class_dev);
class_device_remove_file(&s_dev->class_dev, &class_device_attrs[i]);
class_device_unregister(&s_dev->class_dev);
} else {
spin_unlock(&simple_dev_list_lock);
}
} }