]> err.no Git - linux-2.6/commitdiff
drm: simplify sysfs code for drm
authorDave Airlie <airlied@starflyer.(none)>
Fri, 11 Nov 2005 11:07:35 +0000 (22:07 +1100)
committerDave Airlie <airlied@linux.ie>
Fri, 11 Nov 2005 11:07:35 +0000 (22:07 +1100)
This simplifies the sysfs code for the drm and add a dri_library_name
attribute which can be used by a userspace app to figure out which
library to load.

From: Jon Smirl <jonsmirl@gmail.com>
Signed-off-by: Dave Airlie <airlied@linux.ie>
drivers/char/drm/drmP.h
drivers/char/drm/drm_stub.c
drivers/char/drm/drm_sysfs.c
drivers/char/drm/radeon_drv.c
drivers/char/drm/radeon_drv.h
drivers/char/drm/via_drv.c

index 7fe516160b636d5930534f023f7b483eaaff2983..e9ede8d69e200583257c30942be9ed6124aac798 100644 (file)
@@ -547,6 +547,7 @@ struct drm_driver {
        void (*kernel_context_switch_unlock) (struct drm_device * dev,
                                              drm_lock_t * lock);
        int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
+       int (*dri_library_name) (struct drm_device *dev, char *buf);
 
        /**
         * Called by \c drm_device_is_agp.  Typically used to determine if a
@@ -982,10 +983,8 @@ extern struct drm_sysfs_class *drm_sysfs_create(struct module *owner,
                                                char *name);
 extern void drm_sysfs_destroy(struct drm_sysfs_class *cs);
 extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
-                                                dev_t dev,
-                                                struct device *device,
-                                                const char *fmt, ...);
-extern void drm_sysfs_device_remove(dev_t dev);
+                                                drm_head_t *head);
+extern void drm_sysfs_device_remove(struct class_device *class_dev);
 
 /* Inline replacements for DRM_IOREMAP macros */
 static __inline__ void drm_core_ioremap(struct drm_map *map,
index 8568a6b373a00c4e1d2e603ecb9ccd7d6cfc5e8a..b7f2a851f45c50c2e4389f250e8d0d91ac902d74 100644 (file)
@@ -200,11 +200,7 @@ static int drm_get_head(drm_device_t * dev, drm_head_t * head)
                                goto err_g1;
                        }
 
-                       head->dev_class = drm_sysfs_device_add(drm_class,
-                                                              MKDEV(DRM_MAJOR,
-                                                                    minor),
-                                                              &dev->pdev->dev,
-                                                              "card%d", minor);
+                       head->dev_class = drm_sysfs_device_add(drm_class, head);
                        if (IS_ERR(head->dev_class)) {
                                printk(KERN_ERR
                                       "DRM: Error sysfs_device_add.\n");
@@ -317,10 +313,9 @@ int drm_put_head(drm_head_t * head)
        DRM_DEBUG("release secondary minor %d\n", minor);
 
        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};
 
        drm_heads[minor] = NULL;
 
index 6d3449761914cc3099298d3456c86906ec8cddb3..68e43ddc16aea44fd927cbc9ae6eb532f7d7eb2a 100644 (file)
@@ -15,8 +15,6 @@
 #include <linux/device.h>
 #include <linux/kdev_t.h>
 #include <linux/err.h>
-#include <linux/slab.h>
-#include <linux/string.h>
 
 #include "drm_core.h"
 #include "drmP.h"
@@ -28,15 +26,11 @@ struct drm_sysfs_class {
 #define to_drm_sysfs_class(d) container_of(d, struct drm_sysfs_class, class)
 
 struct simple_dev {
-       struct list_head node;
        dev_t dev;
        struct class_device class_dev;
 };
 #define to_simple_dev(d) container_of(d, struct simple_dev, class_dev)
 
-static LIST_HEAD(simple_dev_list);
-static DEFINE_SPINLOCK(simple_dev_list_lock);
-
 static void release_simple_dev(struct class_device *class_dev)
 {
        struct simple_dev *s_dev = to_simple_dev(class_dev);
@@ -124,6 +118,18 @@ void drm_sysfs_destroy(struct drm_sysfs_class *cs)
        class_unregister(&cs->class);
 }
 
+static ssize_t show_dri(struct class_device *class_device, char *buf)
+{
+       drm_device_t * dev = ((drm_head_t *)class_get_devdata(class_device))->dev;
+       if (dev->driver->dri_library_name)
+               return dev->driver->dri_library_name(dev, buf);
+       return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name);
+}
+
+static struct class_device_attribute class_device_attrs[] = {
+       __ATTR(dri_library_name, S_IRUGO, show_dri, NULL),
+};
+
 /**
  * drm_sysfs_device_add - adds a class device to sysfs for a character driver
  * @cs: pointer to the struct drm_sysfs_class that this device should be registered to.
@@ -138,13 +144,11 @@ void drm_sysfs_destroy(struct drm_sysfs_class *cs)
  * Note: the struct drm_sysfs_class passed to this function must have previously been
  * created with a call to drm_sysfs_create().
  */
-struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, dev_t dev,
-                                         struct device *device,
-                                         const char *fmt, ...)
+struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
+                                         drm_head_t *head)
 {
-       va_list args;
        struct simple_dev *s_dev = NULL;
-       int retval;
+       int i, retval;
 
        if ((cs == NULL) || (IS_ERR(cs))) {
                retval = -ENODEV;
@@ -158,26 +162,23 @@ struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, dev_t dev,
        }
        memset(s_dev, 0x00, sizeof(*s_dev));
 
-       s_dev->dev = dev;
-       s_dev->class_dev.dev = device;
+       s_dev->dev = MKDEV(DRM_MAJOR, head->minor);
+       s_dev->class_dev.dev = &(head->dev->pdev)->dev;
        s_dev->class_dev.class = &cs->class;
 
-       va_start(args, fmt);
-       vsnprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, fmt, args);
-       va_end(args);
+       snprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, "card%d", head->minor);
        retval = class_device_register(&s_dev->class_dev);
        if (retval)
                goto error;
 
        class_device_create_file(&s_dev->class_dev, &cs->attr);
+       class_set_devdata(&s_dev->class_dev, head);
 
-       spin_lock(&simple_dev_list_lock);
-       list_add(&s_dev->node, &simple_dev_list);
-       spin_unlock(&simple_dev_list_lock);
-
+       for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
+               class_device_create_file(&s_dev->class_dev, &class_device_attrs[i]);
        return &s_dev->class_dev;
 
-      error:
+error:
        kfree(s_dev);
        return ERR_PTR(retval);
 }
@@ -189,23 +190,12 @@ struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, dev_t dev,
  * This call unregisters and cleans up a class device that was created with a
  * 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;
-       int found = 0;
-
-       spin_lock(&simple_dev_list_lock);
-       list_for_each_entry(s_dev, &simple_dev_list, node) {
-               if (s_dev->dev == dev) {
-                       found = 1;
-                       break;
-               }
-       }
-       if (found) {
-               list_del(&s_dev->node);
-               spin_unlock(&simple_dev_list_lock);
-               class_device_unregister(&s_dev->class_dev);
-       } else {
-               spin_unlock(&simple_dev_list_lock);
-       }
+       struct simple_dev *s_dev = to_simple_dev(class_dev);
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
+               class_device_remove_file(&s_dev->class_dev, &class_device_attrs[i]);
+       class_device_unregister(&s_dev->class_dev);
 }
index 999d74512362dc1bbf58452db3ffc13554322736..b04ed1b562b9509c7e83635888c8f44baf6ae07b 100644 (file)
@@ -42,6 +42,16 @@ int radeon_no_wb;
 MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers\n");
 module_param_named(no_wb, radeon_no_wb, int, 0444);
 
+static int dri_library_name(struct drm_device *dev, char *buf)
+{
+       drm_radeon_private_t *dev_priv = dev->dev_private;
+       int family = dev_priv->flags & CHIP_FAMILY_MASK;
+
+       return snprintf(buf, PAGE_SIZE, "%s\n",
+                       (family < CHIP_R200) ? "radeon" :
+                       ((family < CHIP_R300) ? "r200" :
+                       "r300"));
+}
 
 static struct pci_device_id pciidlist[] = {
        radeon_PCI_IDS
@@ -61,6 +71,7 @@ static struct drm_driver driver = {
        .lastclose = radeon_driver_lastclose,
        .unload = radeon_driver_unload,
        .vblank_wait = radeon_driver_vblank_wait,
+       .dri_library_name = dri_library_name,
        .irq_preinstall = radeon_driver_irq_preinstall,
        .irq_postinstall = radeon_driver_irq_postinstall,
        .irq_uninstall = radeon_driver_irq_uninstall,
index 3a91d5fc597eb04a2a441eed96e7d7eea97b8d33..c37f2ea2078339484b8e95128fa582f55d4d4663 100644 (file)
@@ -103,8 +103,8 @@ enum radeon_family {
        CHIP_R100,
        CHIP_RS100,
        CHIP_RV100,
-       CHIP_R200,
        CHIP_RV200,
+       CHIP_R200,
        CHIP_RS200,
        CHIP_R250,
        CHIP_RS250,
index 6f3e6b32fa817ee6120a33cb6be3dda64c1fb6c0..e8adebdba127ce02cc1d91f6e053076a373c7b02 100644 (file)
 
 #include "drm_pciids.h"
 
+static int dri_library_name(struct drm_device *dev, char *buf)
+{
+       return snprintf(buf, PAGE_SIZE, "unichrome");
+}
 
 static struct pci_device_id pciidlist[] = {
        viadrv_PCI_IDS
@@ -61,6 +65,7 @@ static struct drm_driver driver = {
        .irq_uninstall = via_driver_irq_uninstall,
        .irq_handler = via_driver_irq_handler,
        .dma_quiescent = via_driver_dma_quiescent,
+       .dri_library_name = dri_library_name,
        .reclaim_buffers = drm_core_reclaim_buffers,
        .get_map_ofs = drm_core_get_map_ofs,
        .get_reg_ofs = drm_core_get_reg_ofs,