2 * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59
16 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * The full GNU General Public License is included in this distribution in the
19 * file called COPYING.
22 #include <linux/kernel.h>
23 #include <linux/spinlock.h>
24 #include <linux/device.h>
25 #include <linux/idr.h>
26 #include <linux/kdev_t.h>
27 #include <linux/err.h>
28 #include <linux/dca.h>
29 #include <linux/gfp.h>
30 #include <linux/export.h>
32 static struct class *dca_class
;
33 static struct idr dca_idr
;
34 static spinlock_t dca_idr_lock
;
36 int dca_sysfs_add_req(struct dca_provider
*dca
, struct device
*dev
, int slot
)
41 cd
= device_create(dca_class
, dca
->cd
, MKDEV(0, slot
+ 1), NULL
,
42 "requester%d", req_count
++);
48 void dca_sysfs_remove_req(struct dca_provider
*dca
, int slot
)
50 device_destroy(dca_class
, MKDEV(0, slot
+ 1));
53 int dca_sysfs_add_provider(struct dca_provider
*dca
, struct device
*dev
)
59 if (!idr_pre_get(&dca_idr
, GFP_KERNEL
))
61 spin_lock(&dca_idr_lock
);
62 err
= idr_get_new(&dca_idr
, dca
, &dca
->id
);
63 spin_unlock(&dca_idr_lock
);
73 cd
= device_create(dca_class
, dev
, MKDEV(0, 0), NULL
, "dca%d", dca
->id
);
75 spin_lock(&dca_idr_lock
);
76 idr_remove(&dca_idr
, dca
->id
);
77 spin_unlock(&dca_idr_lock
);
84 void dca_sysfs_remove_provider(struct dca_provider
*dca
)
86 device_unregister(dca
->cd
);
88 spin_lock(&dca_idr_lock
);
89 idr_remove(&dca_idr
, dca
->id
);
90 spin_unlock(&dca_idr_lock
);
93 int __init
dca_sysfs_init(void)
96 spin_lock_init(&dca_idr_lock
);
98 dca_class
= class_create(THIS_MODULE
, "dca");
99 if (IS_ERR(dca_class
)) {
100 idr_destroy(&dca_idr
);
101 return PTR_ERR(dca_class
);
106 void __exit
dca_sysfs_exit(void)
108 class_destroy(dca_class
);
109 idr_destroy(&dca_idr
);