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)
 
   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.
 
  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;
 
  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)
 
  51         slot = global_dca->ops->add_requester(global_dca, dev);
 
  52         spin_unlock(&dca_lock);
 
  56         err = dca_sysfs_add_req(global_dca, dev, slot);
 
  59                 global_dca->ops->remove_requester(global_dca, dev);
 
  60                 spin_unlock(&dca_lock);
 
  66 EXPORT_SYMBOL_GPL(dca_add_requester);
 
  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)
 
  79         slot = global_dca->ops->remove_requester(global_dca, dev);
 
  80         spin_unlock(&dca_lock);
 
  84         dca_sysfs_remove_req(global_dca, slot);
 
  87 EXPORT_SYMBOL_GPL(dca_remove_requester);
 
  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)
 
  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;
 
 111         alloc_size = (sizeof(*dca) + priv_size);
 
 112         dca = kzalloc(alloc_size, GFP_KERNEL);
 
 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)
 
 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)
 
 145         err = dca_sysfs_add_provider(dca, dev);
 
 149         blocking_notifier_call_chain(&dca_provider_chain,
 
 150                                      DCA_PROVIDER_ADD, NULL);
 
 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)
 
 163         blocking_notifier_call_chain(&dca_provider_chain,
 
 164                                      DCA_PROVIDER_REMOVE, 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)
 
 198 module_init(dca_init);
 
 199 module_exit(dca_exit);