1 #include <linux/kernel.h>
2 #include <linux/spinlock.h>
3 #include <linux/device.h>
5 #include <linux/kdev_t.h>
9 static struct class *dca_class;
10 static struct idr dca_idr;
11 static spinlock_t dca_idr_lock;
13 int dca_sysfs_add_req(struct dca_provider *dca, struct device *dev, int slot)
17 cd = device_create(dca_class, dca->cd, MKDEV(0, slot + 1),
24 void dca_sysfs_remove_req(struct dca_provider *dca, int slot)
26 device_destroy(dca_class, MKDEV(0, slot + 1));
29 int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
35 if (!idr_pre_get(&dca_idr, GFP_KERNEL))
37 spin_lock(&dca_idr_lock);
38 err = idr_get_new(&dca_idr, dca, &dca->id);
39 spin_unlock(&dca_idr_lock);
49 cd = device_create(dca_class, dev, MKDEV(0, 0), "dca%d", dca->id);
51 spin_lock(&dca_idr_lock);
52 idr_remove(&dca_idr, dca->id);
53 spin_unlock(&dca_idr_lock);
60 void dca_sysfs_remove_provider(struct dca_provider *dca)
62 device_unregister(dca->cd);
64 spin_lock(&dca_idr_lock);
65 idr_remove(&dca_idr, dca->id);
66 spin_unlock(&dca_idr_lock);
69 int __init dca_sysfs_init(void)
72 spin_lock_init(&dca_idr_lock);
74 dca_class = class_create(THIS_MODULE, "dca");
75 if (IS_ERR(dca_class)) {
76 idr_destroy(&dca_idr);
77 return PTR_ERR(dca_class);
82 void __exit dca_sysfs_exit(void)
84 class_destroy(dca_class);
85 idr_destroy(&dca_idr);