diff options
author | Dave Airlie <airlied@starflyer.(none)> | 2005-11-11 06:07:35 -0500 |
---|---|---|
committer | Dave Airlie <airlied@linux.ie> | 2005-11-11 06:07:35 -0500 |
commit | 732052ed3e7539d87136dd833be523747af3fb3e (patch) | |
tree | 7989d3062e50f3edc2a206148c6e776f88e7a2c1 /drivers | |
parent | e96e33eeb8b876c7ec009c557ca5269328eceda0 (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/drm/drmP.h | 7 | ||||
-rw-r--r-- | drivers/char/drm/drm_stub.c | 11 | ||||
-rw-r--r-- | drivers/char/drm/drm_sysfs.c | 68 | ||||
-rw-r--r-- | drivers/char/drm/radeon_drv.c | 11 | ||||
-rw-r--r-- | drivers/char/drm/radeon_drv.h | 2 | ||||
-rw-r--r-- | drivers/char/drm/via_drv.c | 5 |
6 files changed, 52 insertions, 52 deletions
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h index 7fe516160b63..e9ede8d69e20 100644 --- a/drivers/char/drm/drmP.h +++ b/drivers/char/drm/drmP.h | |||
@@ -547,6 +547,7 @@ struct drm_driver { | |||
547 | void (*kernel_context_switch_unlock) (struct drm_device * dev, | 547 | void (*kernel_context_switch_unlock) (struct drm_device * dev, |
548 | drm_lock_t * lock); | 548 | drm_lock_t * lock); |
549 | int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence); | 549 | int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence); |
550 | int (*dri_library_name) (struct drm_device *dev, char *buf); | ||
550 | 551 | ||
551 | /** | 552 | /** |
552 | * Called by \c drm_device_is_agp. Typically used to determine if a | 553 | * 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, | |||
982 | char *name); | 983 | char *name); |
983 | extern void drm_sysfs_destroy(struct drm_sysfs_class *cs); | 984 | extern void drm_sysfs_destroy(struct drm_sysfs_class *cs); |
984 | extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, | 985 | extern struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, |
985 | dev_t dev, | 986 | drm_head_t *head); |
986 | struct device *device, | 987 | extern void drm_sysfs_device_remove(struct class_device *class_dev); |
987 | const char *fmt, ...); | ||
988 | extern void drm_sysfs_device_remove(dev_t dev); | ||
989 | 988 | ||
990 | /* Inline replacements for DRM_IOREMAP macros */ | 989 | /* Inline replacements for DRM_IOREMAP macros */ |
991 | static __inline__ void drm_core_ioremap(struct drm_map *map, | 990 | static __inline__ void drm_core_ioremap(struct drm_map *map, |
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c index 8568a6b373a0..b7f2a851f45c 100644 --- a/drivers/char/drm/drm_stub.c +++ b/drivers/char/drm/drm_stub.c | |||
@@ -200,11 +200,7 @@ static int drm_get_head(drm_device_t * dev, drm_head_t * head) | |||
200 | goto err_g1; | 200 | goto err_g1; |
201 | } | 201 | } |
202 | 202 | ||
203 | head->dev_class = drm_sysfs_device_add(drm_class, | 203 | head->dev_class = drm_sysfs_device_add(drm_class, head); |
204 | MKDEV(DRM_MAJOR, | ||
205 | minor), | ||
206 | &dev->pdev->dev, | ||
207 | "card%d", minor); | ||
208 | if (IS_ERR(head->dev_class)) { | 204 | if (IS_ERR(head->dev_class)) { |
209 | printk(KERN_ERR | 205 | printk(KERN_ERR |
210 | "DRM: Error sysfs_device_add.\n"); | 206 | "DRM: Error sysfs_device_add.\n"); |
@@ -317,10 +313,9 @@ int drm_put_head(drm_head_t * head) | |||
317 | DRM_DEBUG("release secondary minor %d\n", minor); | 313 | DRM_DEBUG("release secondary minor %d\n", minor); |
318 | 314 | ||
319 | drm_proc_cleanup(minor, drm_proc_root, head->dev_root); | 315 | drm_proc_cleanup(minor, drm_proc_root, head->dev_root); |
320 | drm_sysfs_device_remove(MKDEV(DRM_MAJOR, head->minor)); | 316 | drm_sysfs_device_remove(head->dev_class); |
321 | 317 | ||
322 | *head = (drm_head_t) { | 318 | *head = (drm_head_t) {.dev = NULL}; |
323 | .dev = NULL}; | ||
324 | 319 | ||
325 | drm_heads[minor] = NULL; | 320 | drm_heads[minor] = NULL; |
326 | 321 | ||
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c index 6d3449761914..68e43ddc16ae 100644 --- a/drivers/char/drm/drm_sysfs.c +++ b/drivers/char/drm/drm_sysfs.c | |||
@@ -15,8 +15,6 @@ | |||
15 | #include <linux/device.h> | 15 | #include <linux/device.h> |
16 | #include <linux/kdev_t.h> | 16 | #include <linux/kdev_t.h> |
17 | #include <linux/err.h> | 17 | #include <linux/err.h> |
18 | #include <linux/slab.h> | ||
19 | #include <linux/string.h> | ||
20 | 18 | ||
21 | #include "drm_core.h" | 19 | #include "drm_core.h" |
22 | #include "drmP.h" | 20 | #include "drmP.h" |
@@ -28,15 +26,11 @@ struct drm_sysfs_class { | |||
28 | #define to_drm_sysfs_class(d) container_of(d, struct drm_sysfs_class, class) | 26 | #define to_drm_sysfs_class(d) container_of(d, struct drm_sysfs_class, class) |
29 | 27 | ||
30 | struct simple_dev { | 28 | struct simple_dev { |
31 | struct list_head node; | ||
32 | dev_t dev; | 29 | dev_t dev; |
33 | struct class_device class_dev; | 30 | struct class_device class_dev; |
34 | }; | 31 | }; |
35 | #define to_simple_dev(d) container_of(d, struct simple_dev, class_dev) | 32 | #define to_simple_dev(d) container_of(d, struct simple_dev, class_dev) |
36 | 33 | ||
37 | static LIST_HEAD(simple_dev_list); | ||
38 | static DEFINE_SPINLOCK(simple_dev_list_lock); | ||
39 | |||
40 | static void release_simple_dev(struct class_device *class_dev) | 34 | static void release_simple_dev(struct class_device *class_dev) |
41 | { | 35 | { |
42 | struct simple_dev *s_dev = to_simple_dev(class_dev); | 36 | struct simple_dev *s_dev = to_simple_dev(class_dev); |
@@ -124,6 +118,18 @@ void drm_sysfs_destroy(struct drm_sysfs_class *cs) | |||
124 | class_unregister(&cs->class); | 118 | class_unregister(&cs->class); |
125 | } | 119 | } |
126 | 120 | ||
121 | static ssize_t show_dri(struct class_device *class_device, char *buf) | ||
122 | { | ||
123 | drm_device_t * dev = ((drm_head_t *)class_get_devdata(class_device))->dev; | ||
124 | if (dev->driver->dri_library_name) | ||
125 | return dev->driver->dri_library_name(dev, buf); | ||
126 | return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name); | ||
127 | } | ||
128 | |||
129 | static struct class_device_attribute class_device_attrs[] = { | ||
130 | __ATTR(dri_library_name, S_IRUGO, show_dri, NULL), | ||
131 | }; | ||
132 | |||
127 | /** | 133 | /** |
128 | * drm_sysfs_device_add - adds a class device to sysfs for a character driver | 134 | * drm_sysfs_device_add - adds a class device to sysfs for a character driver |
129 | * @cs: pointer to the struct drm_sysfs_class that this device should be registered to. | 135 | * @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) | |||
138 | * Note: the struct drm_sysfs_class passed to this function must have previously been | 144 | * Note: the struct drm_sysfs_class passed to this function must have previously been |
139 | * created with a call to drm_sysfs_create(). | 145 | * created with a call to drm_sysfs_create(). |
140 | */ | 146 | */ |
141 | struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, dev_t dev, | 147 | struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, |
142 | struct device *device, | 148 | drm_head_t *head) |
143 | const char *fmt, ...) | ||
144 | { | 149 | { |
145 | va_list args; | ||
146 | struct simple_dev *s_dev = NULL; | 150 | struct simple_dev *s_dev = NULL; |
147 | int retval; | 151 | int i, retval; |
148 | 152 | ||
149 | if ((cs == NULL) || (IS_ERR(cs))) { | 153 | if ((cs == NULL) || (IS_ERR(cs))) { |
150 | retval = -ENODEV; | 154 | retval = -ENODEV; |
@@ -158,26 +162,23 @@ struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, dev_t dev, | |||
158 | } | 162 | } |
159 | memset(s_dev, 0x00, sizeof(*s_dev)); | 163 | memset(s_dev, 0x00, sizeof(*s_dev)); |
160 | 164 | ||
161 | s_dev->dev = dev; | 165 | s_dev->dev = MKDEV(DRM_MAJOR, head->minor); |
162 | s_dev->class_dev.dev = device; | 166 | s_dev->class_dev.dev = &(head->dev->pdev)->dev; |
163 | s_dev->class_dev.class = &cs->class; | 167 | s_dev->class_dev.class = &cs->class; |
164 | 168 | ||
165 | va_start(args, fmt); | 169 | snprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, "card%d", head->minor); |
166 | vsnprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, fmt, args); | ||
167 | va_end(args); | ||
168 | retval = class_device_register(&s_dev->class_dev); | 170 | retval = class_device_register(&s_dev->class_dev); |
169 | if (retval) | 171 | if (retval) |
170 | goto error; | 172 | goto error; |
171 | 173 | ||
172 | class_device_create_file(&s_dev->class_dev, &cs->attr); | 174 | class_device_create_file(&s_dev->class_dev, &cs->attr); |
175 | class_set_devdata(&s_dev->class_dev, head); | ||
173 | 176 | ||
174 | spin_lock(&simple_dev_list_lock); | 177 | for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) |
175 | list_add(&s_dev->node, &simple_dev_list); | 178 | class_device_create_file(&s_dev->class_dev, &class_device_attrs[i]); |
176 | spin_unlock(&simple_dev_list_lock); | ||
177 | |||
178 | return &s_dev->class_dev; | 179 | return &s_dev->class_dev; |
179 | 180 | ||
180 | error: | 181 | error: |
181 | kfree(s_dev); | 182 | kfree(s_dev); |
182 | return ERR_PTR(retval); | 183 | return ERR_PTR(retval); |
183 | } | 184 | } |
@@ -189,23 +190,12 @@ struct class_device *drm_sysfs_device_add(struct drm_sysfs_class *cs, dev_t dev, | |||
189 | * This call unregisters and cleans up a class device that was created with a | 190 | * This call unregisters and cleans up a class device that was created with a |
190 | * call to drm_sysfs_device_add() | 191 | * call to drm_sysfs_device_add() |
191 | */ | 192 | */ |
192 | void drm_sysfs_device_remove(dev_t dev) | 193 | void drm_sysfs_device_remove(struct class_device *class_dev) |
193 | { | 194 | { |
194 | struct simple_dev *s_dev = NULL; | 195 | struct simple_dev *s_dev = to_simple_dev(class_dev); |
195 | int found = 0; | 196 | int i; |
196 | 197 | ||
197 | spin_lock(&simple_dev_list_lock); | 198 | for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) |
198 | list_for_each_entry(s_dev, &simple_dev_list, node) { | 199 | class_device_remove_file(&s_dev->class_dev, &class_device_attrs[i]); |
199 | if (s_dev->dev == dev) { | 200 | class_device_unregister(&s_dev->class_dev); |
200 | found = 1; | ||
201 | break; | ||
202 | } | ||
203 | } | ||
204 | if (found) { | ||
205 | list_del(&s_dev->node); | ||
206 | spin_unlock(&simple_dev_list_lock); | ||
207 | class_device_unregister(&s_dev->class_dev); | ||
208 | } else { | ||
209 | spin_unlock(&simple_dev_list_lock); | ||
210 | } | ||
211 | } | 201 | } |
diff --git a/drivers/char/drm/radeon_drv.c b/drivers/char/drm/radeon_drv.c index 999d74512362..b04ed1b562b9 100644 --- a/drivers/char/drm/radeon_drv.c +++ b/drivers/char/drm/radeon_drv.c | |||
@@ -42,6 +42,16 @@ int radeon_no_wb; | |||
42 | MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers\n"); | 42 | MODULE_PARM_DESC(no_wb, "Disable AGP writeback for scratch registers\n"); |
43 | module_param_named(no_wb, radeon_no_wb, int, 0444); | 43 | module_param_named(no_wb, radeon_no_wb, int, 0444); |
44 | 44 | ||
45 | static int dri_library_name(struct drm_device *dev, char *buf) | ||
46 | { | ||
47 | drm_radeon_private_t *dev_priv = dev->dev_private; | ||
48 | int family = dev_priv->flags & CHIP_FAMILY_MASK; | ||
49 | |||
50 | return snprintf(buf, PAGE_SIZE, "%s\n", | ||
51 | (family < CHIP_R200) ? "radeon" : | ||
52 | ((family < CHIP_R300) ? "r200" : | ||
53 | "r300")); | ||
54 | } | ||
45 | 55 | ||
46 | static struct pci_device_id pciidlist[] = { | 56 | static struct pci_device_id pciidlist[] = { |
47 | radeon_PCI_IDS | 57 | radeon_PCI_IDS |
@@ -61,6 +71,7 @@ static struct drm_driver driver = { | |||
61 | .lastclose = radeon_driver_lastclose, | 71 | .lastclose = radeon_driver_lastclose, |
62 | .unload = radeon_driver_unload, | 72 | .unload = radeon_driver_unload, |
63 | .vblank_wait = radeon_driver_vblank_wait, | 73 | .vblank_wait = radeon_driver_vblank_wait, |
74 | .dri_library_name = dri_library_name, | ||
64 | .irq_preinstall = radeon_driver_irq_preinstall, | 75 | .irq_preinstall = radeon_driver_irq_preinstall, |
65 | .irq_postinstall = radeon_driver_irq_postinstall, | 76 | .irq_postinstall = radeon_driver_irq_postinstall, |
66 | .irq_uninstall = radeon_driver_irq_uninstall, | 77 | .irq_uninstall = radeon_driver_irq_uninstall, |
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h index 3a91d5fc597e..c37f2ea20783 100644 --- a/drivers/char/drm/radeon_drv.h +++ b/drivers/char/drm/radeon_drv.h | |||
@@ -103,8 +103,8 @@ enum radeon_family { | |||
103 | CHIP_R100, | 103 | CHIP_R100, |
104 | CHIP_RS100, | 104 | CHIP_RS100, |
105 | CHIP_RV100, | 105 | CHIP_RV100, |
106 | CHIP_R200, | ||
107 | CHIP_RV200, | 106 | CHIP_RV200, |
107 | CHIP_R200, | ||
108 | CHIP_RS200, | 108 | CHIP_RS200, |
109 | CHIP_R250, | 109 | CHIP_R250, |
110 | CHIP_RS250, | 110 | CHIP_RS250, |
diff --git a/drivers/char/drm/via_drv.c b/drivers/char/drm/via_drv.c index 6f3e6b32fa81..e8adebdba127 100644 --- a/drivers/char/drm/via_drv.c +++ b/drivers/char/drm/via_drv.c | |||
@@ -29,6 +29,10 @@ | |||
29 | 29 | ||
30 | #include "drm_pciids.h" | 30 | #include "drm_pciids.h" |
31 | 31 | ||
32 | static int dri_library_name(struct drm_device *dev, char *buf) | ||
33 | { | ||
34 | return snprintf(buf, PAGE_SIZE, "unichrome"); | ||
35 | } | ||
32 | 36 | ||
33 | static struct pci_device_id pciidlist[] = { | 37 | static struct pci_device_id pciidlist[] = { |
34 | viadrv_PCI_IDS | 38 | viadrv_PCI_IDS |
@@ -61,6 +65,7 @@ static struct drm_driver driver = { | |||
61 | .irq_uninstall = via_driver_irq_uninstall, | 65 | .irq_uninstall = via_driver_irq_uninstall, |
62 | .irq_handler = via_driver_irq_handler, | 66 | .irq_handler = via_driver_irq_handler, |
63 | .dma_quiescent = via_driver_dma_quiescent, | 67 | .dma_quiescent = via_driver_dma_quiescent, |
68 | .dri_library_name = dri_library_name, | ||
64 | .reclaim_buffers = drm_core_reclaim_buffers, | 69 | .reclaim_buffers = drm_core_reclaim_buffers, |
65 | .get_map_ofs = drm_core_get_map_ofs, | 70 | .get_map_ofs = drm_core_get_map_ofs, |
66 | .get_reg_ofs = drm_core_get_reg_ofs, | 71 | .get_reg_ofs = drm_core_get_reg_ofs, |