1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
6 #include <linux/kernel.h>
7 #include <linux/spinlock.h>
8 #include <linux/device.h>
10 #include <linux/kdev_t.h>
11 #include <linux/err.h>
12 #include <linux/dca.h>
13 #include <linux/gfp.h>
14 #include <linux/export.h>
16 static struct class *dca_class
;
17 static struct idr dca_idr
;
18 static spinlock_t dca_idr_lock
;
20 int dca_sysfs_add_req(struct dca_provider
*dca
, struct device
*dev
, int slot
)
25 cd
= device_create(dca_class
, dca
->cd
, MKDEV(0, slot
+ 1), NULL
,
26 "requester%d", req_count
++);
27 return PTR_ERR_OR_ZERO(cd
);
30 void dca_sysfs_remove_req(struct dca_provider
*dca
, int slot
)
32 device_destroy(dca_class
, MKDEV(0, slot
+ 1));
35 int dca_sysfs_add_provider(struct dca_provider
*dca
, struct device
*dev
)
40 idr_preload(GFP_KERNEL
);
41 spin_lock(&dca_idr_lock
);
43 ret
= idr_alloc(&dca_idr
, dca
, 0, 0, GFP_NOWAIT
);
47 spin_unlock(&dca_idr_lock
);
52 cd
= device_create(dca_class
, dev
, MKDEV(0, 0), NULL
, "dca%d", dca
->id
);
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
);