2828#include <linux/device.h>
2929#include <linux/dca.h>
3030
31- MODULE_LICENSE ( "GPL" );
31+ #define DCA_VERSION "1.4"
3232
33- /* For now we're assuming a single, global, DCA provider for the system. */
33+ MODULE_VERSION (DCA_VERSION );
34+ MODULE_LICENSE ("GPL" );
35+ MODULE_AUTHOR ("Intel Corporation" );
3436
3537static DEFINE_SPINLOCK (dca_lock );
3638
37- static struct dca_provider * global_dca = NULL ;
39+ static LIST_HEAD (dca_providers );
40+
41+ static struct dca_provider * dca_find_provider_by_dev (struct device * dev )
42+ {
43+ struct dca_provider * dca , * ret = NULL ;
44+
45+ list_for_each_entry (dca , & dca_providers , node ) {
46+ if ((!dev ) || (dca -> ops -> dev_managed (dca , dev ))) {
47+ ret = dca ;
48+ break ;
49+ }
50+ }
51+
52+ return ret ;
53+ }
3854
3955/**
4056 * dca_add_requester - add a dca client to the list
4157 * @dev - the device that wants dca service
4258 */
4359int dca_add_requester (struct device * dev )
4460{
45- int err , slot ;
61+ struct dca_provider * dca ;
62+ int err , slot = - ENODEV ;
4663
47- if (!global_dca )
48- return - ENODEV ;
64+ if (!dev )
65+ return - EFAULT ;
4966
5067 spin_lock (& dca_lock );
51- slot = global_dca -> ops -> add_requester (global_dca , dev );
52- spin_unlock (& dca_lock );
53- if (slot < 0 )
68+
69+ /* check if the requester has not been added already */
70+ dca = dca_find_provider_by_dev (dev );
71+ if (dca ) {
72+ spin_unlock (& dca_lock );
73+ return - EEXIST ;
74+ }
75+
76+ list_for_each_entry (dca , & dca_providers , node ) {
77+ slot = dca -> ops -> add_requester (dca , dev );
78+ if (slot >= 0 )
79+ break ;
80+ }
81+ if (slot < 0 ) {
82+ spin_unlock (& dca_lock );
5483 return slot ;
84+ }
5585
56- err = dca_sysfs_add_req (global_dca , dev , slot );
86+ err = dca_sysfs_add_req (dca , dev , slot );
5787 if (err ) {
58- spin_lock (& dca_lock );
59- global_dca -> ops -> remove_requester (global_dca , dev );
88+ dca -> ops -> remove_requester (dca , dev );
6089 spin_unlock (& dca_lock );
6190 return err ;
6291 }
6392
93+ spin_unlock (& dca_lock );
6494 return 0 ;
6595}
6696EXPORT_SYMBOL_GPL (dca_add_requester );
@@ -71,30 +101,78 @@ EXPORT_SYMBOL_GPL(dca_add_requester);
71101 */
72102int dca_remove_requester (struct device * dev )
73103{
104+ struct dca_provider * dca ;
74105 int slot ;
75- if (!global_dca )
76- return - ENODEV ;
106+
107+ if (!dev )
108+ return - EFAULT ;
77109
78110 spin_lock (& dca_lock );
79- slot = global_dca -> ops -> remove_requester (global_dca , dev );
80- spin_unlock (& dca_lock );
81- if (slot < 0 )
111+ dca = dca_find_provider_by_dev (dev );
112+ if (!dca ) {
113+ spin_unlock (& dca_lock );
114+ return - ENODEV ;
115+ }
116+ slot = dca -> ops -> remove_requester (dca , dev );
117+ if (slot < 0 ) {
118+ spin_unlock (& dca_lock );
82119 return slot ;
120+ }
83121
84- dca_sysfs_remove_req (global_dca , slot );
122+ dca_sysfs_remove_req (dca , slot );
123+
124+ spin_unlock (& dca_lock );
85125 return 0 ;
86126}
87127EXPORT_SYMBOL_GPL (dca_remove_requester );
88128
89129/**
90- * dca_get_tag - return the dca tag for the given cpu
130+ * dca_common_get_tag - return the dca tag (serves both new and old api)
131+ * @dev - the device that wants dca service
91132 * @cpu - the cpuid as returned by get_cpu()
92133 */
93- u8 dca_get_tag ( int cpu )
134+ u8 dca_common_get_tag ( struct device * dev , int cpu )
94135{
95- if (!global_dca )
136+ struct dca_provider * dca ;
137+ u8 tag ;
138+
139+ spin_lock (& dca_lock );
140+
141+ dca = dca_find_provider_by_dev (dev );
142+ if (!dca ) {
143+ spin_unlock (& dca_lock );
96144 return - ENODEV ;
97- return global_dca -> ops -> get_tag (global_dca , cpu );
145+ }
146+ tag = dca -> ops -> get_tag (dca , dev , cpu );
147+
148+ spin_unlock (& dca_lock );
149+ return tag ;
150+ }
151+
152+ /**
153+ * dca3_get_tag - return the dca tag to the requester device
154+ * for the given cpu (new api)
155+ * @dev - the device that wants dca service
156+ * @cpu - the cpuid as returned by get_cpu()
157+ */
158+ u8 dca3_get_tag (struct device * dev , int cpu )
159+ {
160+ if (!dev )
161+ return - EFAULT ;
162+
163+ return dca_common_get_tag (dev , cpu );
164+ }
165+ EXPORT_SYMBOL_GPL (dca3_get_tag );
166+
167+ /**
168+ * dca_get_tag - return the dca tag for the given cpu (old api)
169+ * @cpu - the cpuid as returned by get_cpu()
170+ */
171+ u8 dca_get_tag (int cpu )
172+ {
173+ struct device * dev = NULL ;
174+
175+ return dca_common_get_tag (dev , cpu );
98176}
99177EXPORT_SYMBOL_GPL (dca_get_tag );
100178
@@ -140,12 +218,10 @@ int register_dca_provider(struct dca_provider *dca, struct device *dev)
140218{
141219 int err ;
142220
143- if (global_dca )
144- return - EEXIST ;
145221 err = dca_sysfs_add_provider (dca , dev );
146222 if (err )
147223 return err ;
148- global_dca = dca ;
224+ list_add ( & dca -> node , & dca_providers ) ;
149225 blocking_notifier_call_chain (& dca_provider_chain ,
150226 DCA_PROVIDER_ADD , NULL );
151227 return 0 ;
@@ -158,11 +234,9 @@ EXPORT_SYMBOL_GPL(register_dca_provider);
158234 */
159235void unregister_dca_provider (struct dca_provider * dca )
160236{
161- if (!global_dca )
162- return ;
163237 blocking_notifier_call_chain (& dca_provider_chain ,
164238 DCA_PROVIDER_REMOVE , NULL );
165- global_dca = NULL ;
239+ list_del ( & dca -> node ) ;
166240 dca_sysfs_remove_provider (dca );
167241}
168242EXPORT_SYMBOL_GPL (unregister_dca_provider );
@@ -187,6 +261,7 @@ EXPORT_SYMBOL_GPL(dca_unregister_notify);
187261
188262static int __init dca_init (void )
189263{
264+ printk (KERN_ERR "dca service started, version %s\n" , DCA_VERSION );
190265 return dca_sysfs_init ();
191266}
192267
0 commit comments