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)
18 cd = device_create_drvdata(dca_class, dca->cd,
19 MKDEV(0, slot + 1), NULL,
20 "requester%d", req_count++);
26 void dca_sysfs_remove_req(struct dca_provider *dca, int slot)
28 device_destroy(dca_class, MKDEV(0, slot + 1));
31 int dca_sysfs_add_provider(struct dca_provider *dca, struct device *dev)
37 if (!idr_pre_get(&dca_idr, GFP_KERNEL))
39 spin_lock(&dca_idr_lock);
40 err = idr_get_new(&dca_idr, dca, &dca->id);
41 spin_unlock(&dca_idr_lock);
51 cd = device_create_drvdata(dca_class, dev, MKDEV(0, 0), NULL,
54 spin_lock(&dca_idr_lock);
55 idr_remove(&dca_idr, dca->id);
56 spin_unlock(&dca_idr_lock);
63 void dca_sysfs_remove_provider(struct dca_provider *dca)
65 device_unregister(dca->cd);
67 spin_lock(&dca_idr_lock);
68 idr_remove(&dca_idr, dca->id);
69 spin_unlock(&dca_idr_lock);
72 int __init dca_sysfs_init(void)
75 spin_lock_init(&dca_idr_lock);
77 dca_class = class_create(THIS_MODULE, "dca");
78 if (IS_ERR(dca_class)) {
79 idr_destroy(&dca_idr);
80 return PTR_ERR(dca_class);
85 void __exit dca_sysfs_exit(void)
87 class_destroy(dca_class);
88 idr_destroy(&dca_idr);