Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 1 | /* |
Maciej Sosnowski | 211a22c | 2009-02-26 11:05:43 +0100 | [diff] [blame] | 2 | * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved. |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called COPYING. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This driver supports an interface for DCA clients and providers to meet. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/notifier.h> |
| 28 | #include <linux/device.h> |
| 29 | #include <linux/dca.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 31 | |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 32 | #define DCA_VERSION "1.12.1" |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 33 | |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 34 | MODULE_VERSION(DCA_VERSION); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | MODULE_AUTHOR("Intel Corporation"); |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 37 | |
| 38 | static DEFINE_SPINLOCK(dca_lock); |
| 39 | |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 40 | static LIST_HEAD(dca_domains); |
| 41 | |
Sosnowski, Maciej | 4e8cec2 | 2010-09-16 06:02:26 +0000 | [diff] [blame] | 42 | static BLOCKING_NOTIFIER_HEAD(dca_provider_chain); |
| 43 | |
| 44 | static int dca_providers_blocked; |
| 45 | |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 46 | static struct pci_bus *dca_pci_rc_from_dev(struct device *dev) |
| 47 | { |
| 48 | struct pci_dev *pdev = to_pci_dev(dev); |
| 49 | struct pci_bus *bus = pdev->bus; |
| 50 | |
| 51 | while (bus->parent) |
| 52 | bus = bus->parent; |
| 53 | |
| 54 | return bus; |
| 55 | } |
| 56 | |
| 57 | static struct dca_domain *dca_allocate_domain(struct pci_bus *rc) |
| 58 | { |
| 59 | struct dca_domain *domain; |
| 60 | |
| 61 | domain = kzalloc(sizeof(*domain), GFP_NOWAIT); |
| 62 | if (!domain) |
| 63 | return NULL; |
| 64 | |
| 65 | INIT_LIST_HEAD(&domain->dca_providers); |
| 66 | domain->pci_rc = rc; |
| 67 | |
| 68 | return domain; |
| 69 | } |
| 70 | |
| 71 | static void dca_free_domain(struct dca_domain *domain) |
| 72 | { |
| 73 | list_del(&domain->node); |
| 74 | kfree(domain); |
| 75 | } |
| 76 | |
Sosnowski, Maciej | 4e8cec2 | 2010-09-16 06:02:26 +0000 | [diff] [blame] | 77 | static int dca_provider_ioat_ver_3_0(struct device *dev) |
| 78 | { |
| 79 | struct pci_dev *pdev = to_pci_dev(dev); |
| 80 | |
| 81 | return ((pdev->vendor == PCI_VENDOR_ID_INTEL) && |
| 82 | ((pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG0) || |
| 83 | (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG1) || |
| 84 | (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG2) || |
| 85 | (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG3) || |
| 86 | (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG4) || |
| 87 | (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG5) || |
| 88 | (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG6) || |
| 89 | (pdev->device == PCI_DEVICE_ID_INTEL_IOAT_TBG7))); |
| 90 | } |
| 91 | |
| 92 | static void unregister_dca_providers(void) |
| 93 | { |
| 94 | struct dca_provider *dca, *_dca; |
| 95 | struct list_head unregistered_providers; |
| 96 | struct dca_domain *domain; |
| 97 | unsigned long flags; |
| 98 | |
| 99 | blocking_notifier_call_chain(&dca_provider_chain, |
| 100 | DCA_PROVIDER_REMOVE, NULL); |
| 101 | |
| 102 | INIT_LIST_HEAD(&unregistered_providers); |
| 103 | |
| 104 | spin_lock_irqsave(&dca_lock, flags); |
| 105 | |
| 106 | if (list_empty(&dca_domains)) { |
| 107 | spin_unlock_irqrestore(&dca_lock, flags); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | /* at this point only one domain in the list is expected */ |
| 112 | domain = list_first_entry(&dca_domains, struct dca_domain, node); |
Sosnowski, Maciej | 4e8cec2 | 2010-09-16 06:02:26 +0000 | [diff] [blame] | 113 | |
| 114 | list_for_each_entry_safe(dca, _dca, &domain->dca_providers, node) { |
| 115 | list_del(&dca->node); |
| 116 | list_add(&dca->node, &unregistered_providers); |
| 117 | } |
| 118 | |
| 119 | dca_free_domain(domain); |
| 120 | |
| 121 | spin_unlock_irqrestore(&dca_lock, flags); |
| 122 | |
| 123 | list_for_each_entry_safe(dca, _dca, &unregistered_providers, node) { |
| 124 | dca_sysfs_remove_provider(dca); |
| 125 | list_del(&dca->node); |
| 126 | } |
| 127 | } |
| 128 | |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 129 | static struct dca_domain *dca_find_domain(struct pci_bus *rc) |
| 130 | { |
| 131 | struct dca_domain *domain; |
| 132 | |
| 133 | list_for_each_entry(domain, &dca_domains, node) |
| 134 | if (domain->pci_rc == rc) |
| 135 | return domain; |
| 136 | |
| 137 | return NULL; |
| 138 | } |
| 139 | |
| 140 | static struct dca_domain *dca_get_domain(struct device *dev) |
| 141 | { |
| 142 | struct pci_bus *rc; |
| 143 | struct dca_domain *domain; |
| 144 | |
| 145 | rc = dca_pci_rc_from_dev(dev); |
| 146 | domain = dca_find_domain(rc); |
| 147 | |
| 148 | if (!domain) { |
Sosnowski, Maciej | 4e8cec2 | 2010-09-16 06:02:26 +0000 | [diff] [blame] | 149 | if (dca_provider_ioat_ver_3_0(dev) && !list_empty(&dca_domains)) { |
| 150 | dca_providers_blocked = 1; |
| 151 | } else { |
| 152 | domain = dca_allocate_domain(rc); |
| 153 | if (domain) |
| 154 | list_add(&domain->node, &dca_domains); |
| 155 | } |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | return domain; |
| 159 | } |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 160 | |
| 161 | static struct dca_provider *dca_find_provider_by_dev(struct device *dev) |
| 162 | { |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 163 | struct dca_provider *dca; |
| 164 | struct pci_bus *rc; |
| 165 | struct dca_domain *domain; |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 166 | |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 167 | if (dev) { |
| 168 | rc = dca_pci_rc_from_dev(dev); |
| 169 | domain = dca_find_domain(rc); |
| 170 | if (!domain) |
| 171 | return NULL; |
| 172 | } else { |
| 173 | if (!list_empty(&dca_domains)) |
| 174 | domain = list_first_entry(&dca_domains, |
| 175 | struct dca_domain, |
| 176 | node); |
| 177 | else |
| 178 | return NULL; |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 181 | list_for_each_entry(dca, &domain->dca_providers, node) |
| 182 | if ((!dev) || (dca->ops->dev_managed(dca, dev))) |
| 183 | return dca; |
| 184 | |
| 185 | return NULL; |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 186 | } |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * dca_add_requester - add a dca client to the list |
| 190 | * @dev - the device that wants dca service |
| 191 | */ |
| 192 | int dca_add_requester(struct device *dev) |
| 193 | { |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 194 | struct dca_provider *dca; |
| 195 | int err, slot = -ENODEV; |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 196 | unsigned long flags; |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 197 | struct pci_bus *pci_rc; |
| 198 | struct dca_domain *domain; |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 199 | |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 200 | if (!dev) |
| 201 | return -EFAULT; |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 202 | |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 203 | spin_lock_irqsave(&dca_lock, flags); |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 204 | |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 205 | /* check if the requester has not been added already */ |
| 206 | dca = dca_find_provider_by_dev(dev); |
| 207 | if (dca) { |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 208 | spin_unlock_irqrestore(&dca_lock, flags); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 209 | return -EEXIST; |
| 210 | } |
| 211 | |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 212 | pci_rc = dca_pci_rc_from_dev(dev); |
| 213 | domain = dca_find_domain(pci_rc); |
| 214 | if (!domain) { |
| 215 | spin_unlock_irqrestore(&dca_lock, flags); |
| 216 | return -ENODEV; |
| 217 | } |
| 218 | |
| 219 | list_for_each_entry(dca, &domain->dca_providers, node) { |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 220 | slot = dca->ops->add_requester(dca, dev); |
| 221 | if (slot >= 0) |
| 222 | break; |
| 223 | } |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 224 | |
| 225 | spin_unlock_irqrestore(&dca_lock, flags); |
| 226 | |
| 227 | if (slot < 0) |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 228 | return slot; |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 229 | |
| 230 | err = dca_sysfs_add_req(dca, dev, slot); |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 231 | if (err) { |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 232 | spin_lock_irqsave(&dca_lock, flags); |
| 233 | if (dca == dca_find_provider_by_dev(dev)) |
| 234 | dca->ops->remove_requester(dca, dev); |
| 235 | spin_unlock_irqrestore(&dca_lock, flags); |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 236 | return err; |
| 237 | } |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | EXPORT_SYMBOL_GPL(dca_add_requester); |
| 242 | |
| 243 | /** |
| 244 | * dca_remove_requester - remove a dca client from the list |
| 245 | * @dev - the device that wants dca service |
| 246 | */ |
| 247 | int dca_remove_requester(struct device *dev) |
| 248 | { |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 249 | struct dca_provider *dca; |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 250 | int slot; |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 251 | unsigned long flags; |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 252 | |
| 253 | if (!dev) |
| 254 | return -EFAULT; |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 255 | |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 256 | spin_lock_irqsave(&dca_lock, flags); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 257 | dca = dca_find_provider_by_dev(dev); |
| 258 | if (!dca) { |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 259 | spin_unlock_irqrestore(&dca_lock, flags); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 260 | return -ENODEV; |
| 261 | } |
| 262 | slot = dca->ops->remove_requester(dca, dev); |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 263 | spin_unlock_irqrestore(&dca_lock, flags); |
| 264 | |
| 265 | if (slot < 0) |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 266 | return slot; |
| 267 | |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 268 | dca_sysfs_remove_req(dca, slot); |
| 269 | |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | EXPORT_SYMBOL_GPL(dca_remove_requester); |
| 273 | |
| 274 | /** |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 275 | * dca_common_get_tag - return the dca tag (serves both new and old api) |
| 276 | * @dev - the device that wants dca service |
| 277 | * @cpu - the cpuid as returned by get_cpu() |
| 278 | */ |
| 279 | u8 dca_common_get_tag(struct device *dev, int cpu) |
| 280 | { |
| 281 | struct dca_provider *dca; |
| 282 | u8 tag; |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 283 | unsigned long flags; |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 284 | |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 285 | spin_lock_irqsave(&dca_lock, flags); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 286 | |
| 287 | dca = dca_find_provider_by_dev(dev); |
| 288 | if (!dca) { |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 289 | spin_unlock_irqrestore(&dca_lock, flags); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 290 | return -ENODEV; |
| 291 | } |
| 292 | tag = dca->ops->get_tag(dca, dev, cpu); |
| 293 | |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 294 | spin_unlock_irqrestore(&dca_lock, flags); |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 295 | return tag; |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * dca3_get_tag - return the dca tag to the requester device |
| 300 | * for the given cpu (new api) |
| 301 | * @dev - the device that wants dca service |
| 302 | * @cpu - the cpuid as returned by get_cpu() |
| 303 | */ |
| 304 | u8 dca3_get_tag(struct device *dev, int cpu) |
| 305 | { |
| 306 | if (!dev) |
| 307 | return -EFAULT; |
| 308 | |
| 309 | return dca_common_get_tag(dev, cpu); |
| 310 | } |
| 311 | EXPORT_SYMBOL_GPL(dca3_get_tag); |
| 312 | |
| 313 | /** |
| 314 | * dca_get_tag - return the dca tag for the given cpu (old api) |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 315 | * @cpu - the cpuid as returned by get_cpu() |
| 316 | */ |
| 317 | u8 dca_get_tag(int cpu) |
| 318 | { |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 319 | struct device *dev = NULL; |
| 320 | |
| 321 | return dca_common_get_tag(dev, cpu); |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 322 | } |
| 323 | EXPORT_SYMBOL_GPL(dca_get_tag); |
| 324 | |
| 325 | /** |
| 326 | * alloc_dca_provider - get data struct for describing a dca provider |
| 327 | * @ops - pointer to struct of dca operation function pointers |
| 328 | * @priv_size - size of extra mem to be added for provider's needs |
| 329 | */ |
| 330 | struct dca_provider *alloc_dca_provider(struct dca_ops *ops, int priv_size) |
| 331 | { |
| 332 | struct dca_provider *dca; |
| 333 | int alloc_size; |
| 334 | |
| 335 | alloc_size = (sizeof(*dca) + priv_size); |
| 336 | dca = kzalloc(alloc_size, GFP_KERNEL); |
| 337 | if (!dca) |
| 338 | return NULL; |
| 339 | dca->ops = ops; |
| 340 | |
| 341 | return dca; |
| 342 | } |
| 343 | EXPORT_SYMBOL_GPL(alloc_dca_provider); |
| 344 | |
| 345 | /** |
| 346 | * free_dca_provider - release the dca provider data struct |
| 347 | * @ops - pointer to struct of dca operation function pointers |
| 348 | * @priv_size - size of extra mem to be added for provider's needs |
| 349 | */ |
| 350 | void free_dca_provider(struct dca_provider *dca) |
| 351 | { |
| 352 | kfree(dca); |
| 353 | } |
| 354 | EXPORT_SYMBOL_GPL(free_dca_provider); |
| 355 | |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 356 | /** |
| 357 | * register_dca_provider - register a dca provider |
| 358 | * @dca - struct created by alloc_dca_provider() |
| 359 | * @dev - device providing dca services |
| 360 | */ |
| 361 | int register_dca_provider(struct dca_provider *dca, struct device *dev) |
| 362 | { |
| 363 | int err; |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 364 | unsigned long flags; |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 365 | struct dca_domain *domain; |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 366 | |
Sosnowski, Maciej | 4e8cec2 | 2010-09-16 06:02:26 +0000 | [diff] [blame] | 367 | spin_lock_irqsave(&dca_lock, flags); |
| 368 | if (dca_providers_blocked) { |
| 369 | spin_unlock_irqrestore(&dca_lock, flags); |
| 370 | return -ENODEV; |
| 371 | } |
| 372 | spin_unlock_irqrestore(&dca_lock, flags); |
| 373 | |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 374 | err = dca_sysfs_add_provider(dca, dev); |
| 375 | if (err) |
| 376 | return err; |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 377 | |
| 378 | spin_lock_irqsave(&dca_lock, flags); |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 379 | domain = dca_get_domain(dev); |
| 380 | if (!domain) { |
Sosnowski, Maciej | 4e8cec2 | 2010-09-16 06:02:26 +0000 | [diff] [blame] | 381 | if (dca_providers_blocked) { |
| 382 | spin_unlock_irqrestore(&dca_lock, flags); |
| 383 | dca_sysfs_remove_provider(dca); |
| 384 | unregister_dca_providers(); |
| 385 | } else { |
| 386 | spin_unlock_irqrestore(&dca_lock, flags); |
| 387 | } |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 388 | return -ENODEV; |
| 389 | } |
| 390 | list_add(&dca->node, &domain->dca_providers); |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 391 | spin_unlock_irqrestore(&dca_lock, flags); |
| 392 | |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 393 | blocking_notifier_call_chain(&dca_provider_chain, |
| 394 | DCA_PROVIDER_ADD, NULL); |
| 395 | return 0; |
| 396 | } |
| 397 | EXPORT_SYMBOL_GPL(register_dca_provider); |
| 398 | |
| 399 | /** |
| 400 | * unregister_dca_provider - remove a dca provider |
| 401 | * @dca - struct created by alloc_dca_provider() |
| 402 | */ |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 403 | void unregister_dca_provider(struct dca_provider *dca, struct device *dev) |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 404 | { |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 405 | unsigned long flags; |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 406 | struct pci_bus *pci_rc; |
| 407 | struct dca_domain *domain; |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 408 | |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 409 | blocking_notifier_call_chain(&dca_provider_chain, |
| 410 | DCA_PROVIDER_REMOVE, NULL); |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 411 | |
| 412 | spin_lock_irqsave(&dca_lock, flags); |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 413 | |
Maciej Sosnowski | 7f1b358 | 2008-07-22 17:30:57 -0700 | [diff] [blame] | 414 | list_del(&dca->node); |
Maciej Sosnowski | 1a5aeee | 2009-09-10 15:05:58 +0200 | [diff] [blame] | 415 | |
| 416 | pci_rc = dca_pci_rc_from_dev(dev); |
| 417 | domain = dca_find_domain(pci_rc); |
| 418 | if (list_empty(&domain->dca_providers)) |
| 419 | dca_free_domain(domain); |
| 420 | |
Maciej Sosnowski | eb4400e | 2009-02-02 23:26:57 -0800 | [diff] [blame] | 421 | spin_unlock_irqrestore(&dca_lock, flags); |
| 422 | |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 423 | dca_sysfs_remove_provider(dca); |
| 424 | } |
| 425 | EXPORT_SYMBOL_GPL(unregister_dca_provider); |
| 426 | |
| 427 | /** |
| 428 | * dca_register_notify - register a client's notifier callback |
| 429 | */ |
| 430 | void dca_register_notify(struct notifier_block *nb) |
| 431 | { |
| 432 | blocking_notifier_chain_register(&dca_provider_chain, nb); |
| 433 | } |
| 434 | EXPORT_SYMBOL_GPL(dca_register_notify); |
| 435 | |
| 436 | /** |
| 437 | * dca_unregister_notify - remove a client's notifier callback |
| 438 | */ |
| 439 | void dca_unregister_notify(struct notifier_block *nb) |
| 440 | { |
| 441 | blocking_notifier_chain_unregister(&dca_provider_chain, nb); |
| 442 | } |
| 443 | EXPORT_SYMBOL_GPL(dca_unregister_notify); |
| 444 | |
| 445 | static int __init dca_init(void) |
| 446 | { |
Stephen Hemminger | 084dac5 | 2009-09-13 09:07:37 -0700 | [diff] [blame] | 447 | pr_info("dca service started, version %s\n", DCA_VERSION); |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 448 | return dca_sysfs_init(); |
| 449 | } |
| 450 | |
| 451 | static void __exit dca_exit(void) |
| 452 | { |
| 453 | dca_sysfs_exit(); |
| 454 | } |
| 455 | |
Dan Williams | 652afc2 | 2009-01-06 11:38:22 -0700 | [diff] [blame] | 456 | arch_initcall(dca_init); |
Shannon Nelson | 7589670 | 2007-10-16 01:27:41 -0700 | [diff] [blame] | 457 | module_exit(dca_exit); |
| 458 | |