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_drvdata(dca_class
, dca
->cd
,
18 MKDEV(0, slot
+ 1), NULL
,
25 void dca_sysfs_remove_req(struct dca_provider
*dca
, int slot
)
27 device_destroy(dca_class
, MKDEV(0, slot
+ 1));
30 int dca_sysfs_add_provider(struct dca_provider
*dca
, struct device
*dev
)
36 if (!idr_pre_get(&dca_idr
, GFP_KERNEL
))
38 spin_lock(&dca_idr_lock
);
39 err
= idr_get_new(&dca_idr
, dca
, &dca
->id
);
40 spin_unlock(&dca_idr_lock
);
50 cd
= device_create_drvdata(dca_class
, dev
, MKDEV(0, 0), NULL
,
53 spin_lock(&dca_idr_lock
);
54 idr_remove(&dca_idr
, dca
->id
);
55 spin_unlock(&dca_idr_lock
);
62 void dca_sysfs_remove_provider(struct dca_provider
*dca
)
64 device_unregister(dca
->cd
);
66 spin_lock(&dca_idr_lock
);
67 idr_remove(&dca_idr
, dca
->id
);
68 spin_unlock(&dca_idr_lock
);
71 int __init
dca_sysfs_init(void)
74 spin_lock_init(&dca_idr_lock
);
76 dca_class
= class_create(THIS_MODULE
, "dca");
77 if (IS_ERR(dca_class
)) {
78 idr_destroy(&dca_idr
);
79 return PTR_ERR(dca_class
);
84 void __exit
dca_sysfs_exit(void)
86 class_destroy(dca_class
);
87 idr_destroy(&dca_idr
);