ACPI: Fix acpi_pm_device_sleep_state()
[pv_ops_mirror.git] / drivers / dca / dca-core.c
blobbf5b92f86df7e07ca3813a4e127f21c7b92f9bff
1 /*
2 * Copyright(c) 2007 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)
7 * any later version.
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
12 * more details.
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.
23 * This driver supports an interface for DCA clients and providers to meet.
26 #include <linux/kernel.h>
27 #include <linux/notifier.h>
28 #include <linux/device.h>
29 #include <linux/dca.h>
31 MODULE_LICENSE("GPL");
33 /* For now we're assuming a single, global, DCA provider for the system. */
35 static DEFINE_SPINLOCK(dca_lock);
37 static struct dca_provider *global_dca = NULL;
39 /**
40 * dca_add_requester - add a dca client to the list
41 * @dev - the device that wants dca service
43 int dca_add_requester(struct device *dev)
45 int err, slot;
47 if (!global_dca)
48 return -ENODEV;
50 spin_lock(&dca_lock);
51 slot = global_dca->ops->add_requester(global_dca, dev);
52 spin_unlock(&dca_lock);
53 if (slot < 0)
54 return slot;
56 err = dca_sysfs_add_req(global_dca, dev, slot);
57 if (err) {
58 spin_lock(&dca_lock);
59 global_dca->ops->remove_requester(global_dca, dev);
60 spin_unlock(&dca_lock);
61 return err;
64 return 0;
66 EXPORT_SYMBOL_GPL(dca_add_requester);
68 /**
69 * dca_remove_requester - remove a dca client from the list
70 * @dev - the device that wants dca service
72 int dca_remove_requester(struct device *dev)
74 int slot;
75 if (!global_dca)
76 return -ENODEV;
78 spin_lock(&dca_lock);
79 slot = global_dca->ops->remove_requester(global_dca, dev);
80 spin_unlock(&dca_lock);
81 if (slot < 0)
82 return slot;
84 dca_sysfs_remove_req(global_dca, slot);
85 return 0;
87 EXPORT_SYMBOL_GPL(dca_remove_requester);
89 /**
90 * dca_get_tag - return the dca tag for the given cpu
91 * @cpu - the cpuid as returned by get_cpu()
93 u8 dca_get_tag(int cpu)
95 if (!global_dca)
96 return -ENODEV;
97 return global_dca->ops->get_tag(global_dca, cpu);
99 EXPORT_SYMBOL_GPL(dca_get_tag);
102 * alloc_dca_provider - get data struct for describing a dca provider
103 * @ops - pointer to struct of dca operation function pointers
104 * @priv_size - size of extra mem to be added for provider's needs
106 struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size)
108 struct dca_provider *dca;
109 int alloc_size;
111 alloc_size = (sizeof(*dca) + priv_size);
112 dca = kzalloc(alloc_size, GFP_KERNEL);
113 if (!dca)
114 return NULL;
115 dca->ops = ops;
117 return dca;
119 EXPORT_SYMBOL_GPL(alloc_dca_provider);
122 * free_dca_provider - release the dca provider data struct
123 * @ops - pointer to struct of dca operation function pointers
124 * @priv_size - size of extra mem to be added for provider's needs
126 void free_dca_provider(struct dca_provider *dca)
128 kfree(dca);
130 EXPORT_SYMBOL_GPL(free_dca_provider);
132 static BLOCKING_NOTIFIER_HEAD(dca_provider_chain);
135 * register_dca_provider - register a dca provider
136 * @dca - struct created by alloc_dca_provider()
137 * @dev - device providing dca services
139 int register_dca_provider(struct dca_provider *dca, struct device *dev)
141 int err;
143 if (global_dca)
144 return -EEXIST;
145 err = dca_sysfs_add_provider(dca, dev);
146 if (err)
147 return err;
148 global_dca = dca;
149 blocking_notifier_call_chain(&dca_provider_chain,
150 DCA_PROVIDER_ADD, NULL);
151 return 0;
153 EXPORT_SYMBOL_GPL(register_dca_provider);
156 * unregister_dca_provider - remove a dca provider
157 * @dca - struct created by alloc_dca_provider()
159 void unregister_dca_provider(struct dca_provider *dca)
161 if (!global_dca)
162 return;
163 blocking_notifier_call_chain(&dca_provider_chain,
164 DCA_PROVIDER_REMOVE, NULL);
165 global_dca = NULL;
166 dca_sysfs_remove_provider(dca);
168 EXPORT_SYMBOL_GPL(unregister_dca_provider);
171 * dca_register_notify - register a client's notifier callback
173 void dca_register_notify(struct notifier_block *nb)
175 blocking_notifier_chain_register(&dca_provider_chain, nb);
177 EXPORT_SYMBOL_GPL(dca_register_notify);
180 * dca_unregister_notify - remove a client's notifier callback
182 void dca_unregister_notify(struct notifier_block *nb)
184 blocking_notifier_chain_unregister(&dca_provider_chain, nb);
186 EXPORT_SYMBOL_GPL(dca_unregister_notify);
188 static int __init dca_init(void)
190 return dca_sysfs_init();
193 static void __exit dca_exit(void)
195 dca_sysfs_exit();
198 module_init(dca_init);
199 module_exit(dca_exit);