drm: simplify sysfs code for drm
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>
This commit is contained in:
@@ -547,6 +547,7 @@ struct drm_driver {
|
|||||||
void (*kernel_context_switch_unlock) (struct drm_device * dev,
|
void (*kernel_context_switch_unlock) (struct drm_device * dev,
|
||||||
drm_lock_t * lock);
|
drm_lock_t * lock);
|
||||||
int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
|
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
|
* 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);
|
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,
|
||||||
dev_t dev,
|
drm_head_t *head);
|
||||||
struct device *device,
|
extern void drm_sysfs_device_remove(struct class_device *class_dev);
|
||||||
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,
|
||||||
|
@@ -200,11 +200,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);
|
||||||
MKDEV(DRM_MAJOR,
|
|
||||||
minor),
|
|
||||||
&dev->pdev->dev,
|
|
||||||
"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");
|
||||||
@@ -317,10 +313,9 @@ 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) {
|
*head = (drm_head_t) {.dev = NULL};
|
||||||
.dev = NULL};
|
|
||||||
|
|
||||||
drm_heads[minor] = NULL;
|
drm_heads[minor] = NULL;
|
||||||
|
|
||||||
|
@@ -15,8 +15,6 @@
|
|||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/kdev_t.h>
|
#include <linux/kdev_t.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/slab.h>
|
|
||||||
#include <linux/string.h>
|
|
||||||
|
|
||||||
#include "drm_core.h"
|
#include "drm_core.h"
|
||||||
#include "drmP.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)
|
#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 DEFINE_SPINLOCK(simple_dev_list_lock);
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -124,6 +118,18 @@ void drm_sysfs_destroy(struct drm_sysfs_class *cs)
|
|||||||
class_unregister(&cs->class);
|
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
|
* 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.
|
* @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
|
* 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, dev_t dev,
|
struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs,
|
||||||
struct device *device,
|
drm_head_t *head)
|
||||||
const char *fmt, ...)
|
|
||||||
{
|
{
|
||||||
va_list args;
|
|
||||||
struct simple_dev *s_dev = NULL;
|
struct simple_dev *s_dev = NULL;
|
||||||
int retval;
|
int i, retval;
|
||||||
|
|
||||||
if ((cs == NULL) || (IS_ERR(cs))) {
|
if ((cs == NULL) || (IS_ERR(cs))) {
|
||||||
retval = -ENODEV;
|
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));
|
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 = &(head->dev->pdev)->dev;
|
||||||
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);
|
||||||
|
class_set_devdata(&s_dev->class_dev, head);
|
||||||
|
|
||||||
spin_lock(&simple_dev_list_lock);
|
for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
|
||||||
list_add(&s_dev->node, &simple_dev_list);
|
class_device_create_file(&s_dev->class_dev, &class_device_attrs[i]);
|
||||||
spin_unlock(&simple_dev_list_lock);
|
|
||||||
|
|
||||||
return &s_dev->class_dev;
|
return &s_dev->class_dev;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
kfree(s_dev);
|
kfree(s_dev);
|
||||||
return ERR_PTR(retval);
|
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
|
* 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 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) {
|
class_device_unregister(&s_dev->class_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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,16 @@ int radeon_no_wb;
|
|||||||
MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers\n");
|
MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers\n");
|
||||||
module_param_named(no_wb, radeon_no_wb, int, 0444);
|
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[] = {
|
static struct pci_device_id pciidlist[] = {
|
||||||
radeon_PCI_IDS
|
radeon_PCI_IDS
|
||||||
@@ -61,6 +71,7 @@ static struct drm_driver driver = {
|
|||||||
.lastclose = radeon_driver_lastclose,
|
.lastclose = radeon_driver_lastclose,
|
||||||
.unload = radeon_driver_unload,
|
.unload = radeon_driver_unload,
|
||||||
.vblank_wait = radeon_driver_vblank_wait,
|
.vblank_wait = radeon_driver_vblank_wait,
|
||||||
|
.dri_library_name = dri_library_name,
|
||||||
.irq_preinstall = radeon_driver_irq_preinstall,
|
.irq_preinstall = radeon_driver_irq_preinstall,
|
||||||
.irq_postinstall = radeon_driver_irq_postinstall,
|
.irq_postinstall = radeon_driver_irq_postinstall,
|
||||||
.irq_uninstall = radeon_driver_irq_uninstall,
|
.irq_uninstall = radeon_driver_irq_uninstall,
|
||||||
|
@@ -103,8 +103,8 @@ enum radeon_family {
|
|||||||
CHIP_R100,
|
CHIP_R100,
|
||||||
CHIP_RS100,
|
CHIP_RS100,
|
||||||
CHIP_RV100,
|
CHIP_RV100,
|
||||||
CHIP_R200,
|
|
||||||
CHIP_RV200,
|
CHIP_RV200,
|
||||||
|
CHIP_R200,
|
||||||
CHIP_RS200,
|
CHIP_RS200,
|
||||||
CHIP_R250,
|
CHIP_R250,
|
||||||
CHIP_RS250,
|
CHIP_RS250,
|
||||||
|
@@ -29,6 +29,10 @@
|
|||||||
|
|
||||||
#include "drm_pciids.h"
|
#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[] = {
|
static struct pci_device_id pciidlist[] = {
|
||||||
viadrv_PCI_IDS
|
viadrv_PCI_IDS
|
||||||
@@ -61,6 +65,7 @@ static struct drm_driver driver = {
|
|||||||
.irq_uninstall = via_driver_irq_uninstall,
|
.irq_uninstall = via_driver_irq_uninstall,
|
||||||
.irq_handler = via_driver_irq_handler,
|
.irq_handler = via_driver_irq_handler,
|
||||||
.dma_quiescent = via_driver_dma_quiescent,
|
.dma_quiescent = via_driver_dma_quiescent,
|
||||||
|
.dri_library_name = dri_library_name,
|
||||||
.reclaim_buffers = drm_core_reclaim_buffers,
|
.reclaim_buffers = drm_core_reclaim_buffers,
|
||||||
.get_map_ofs = drm_core_get_map_ofs,
|
.get_map_ofs = drm_core_get_map_ofs,
|
||||||
.get_reg_ofs = drm_core_get_reg_ofs,
|
.get_reg_ofs = drm_core_get_reg_ofs,
|
||||||
|
Reference in New Issue
Block a user