]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/pci/hotplug/pci_hotplug_core.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[mirror_ubuntu-artful-kernel.git] / drivers / pci / hotplug / pci_hotplug_core.c
CommitLineData
1da177e4
LT
1/*
2 * PCI HotPlug Controller Core
3 *
4 * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2001-2002 IBM Corp.
6 *
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
17 * NON INFRINGEMENT. See the GNU General Public License for more
18 * details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
fb5f4d7a 24 * Send feedback to <kristen.c.accardi@intel.com>
1da177e4
LT
25 *
26 */
27
1da177e4
LT
28#include <linux/module.h>
29#include <linux/moduleparam.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/list.h>
7a54f25c
GKH
33#include <linux/kobject.h>
34#include <linux/sysfs.h>
1da177e4
LT
35#include <linux/pagemap.h>
36#include <linux/slab.h>
1da177e4
LT
37#include <linux/init.h>
38#include <linux/mount.h>
39#include <linux/namei.h>
95cb9093 40#include <linux/mutex.h>
1da177e4 41#include <linux/pci.h>
7a54f25c 42#include <linux/pci_hotplug.h>
1da177e4 43#include <asm/uaccess.h>
f46753c5 44#include "../pci.h"
1da177e4
LT
45
46#define MY_NAME "pci_hotplug"
47
66bef8c0 48#define dbg(fmt, arg...) do { if (debug) printk(KERN_DEBUG "%s: %s: " fmt , MY_NAME , __func__ , ## arg); } while (0)
1da177e4
LT
49#define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg)
50#define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg)
51#define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg)
52
53
54/* local variables */
55static int debug;
56
57#define DRIVER_VERSION "0.5"
58#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Scott Murray <scottm@somanetworks.com>"
59#define DRIVER_DESC "PCI Hot Plug PCI Core"
60
61
62//////////////////////////////////////////////////////////////////
63
64static LIST_HEAD(pci_hotplug_slot_list);
95cb9093 65static DEFINE_MUTEX(pci_hp_mutex);
1da177e4 66
1da177e4
LT
67/* these strings match up with the values in pci_bus_speed */
68static char *pci_bus_speed_strings[] = {
69 "33 MHz PCI", /* 0x00 */
70 "66 MHz PCI", /* 0x01 */
17d67152
SA
71 "66 MHz PCI-X", /* 0x02 */
72 "100 MHz PCI-X", /* 0x03 */
73 "133 MHz PCI-X", /* 0x04 */
1da177e4
LT
74 NULL, /* 0x05 */
75 NULL, /* 0x06 */
76 NULL, /* 0x07 */
77 NULL, /* 0x08 */
17d67152
SA
78 "66 MHz PCI-X 266", /* 0x09 */
79 "100 MHz PCI-X 266", /* 0x0a */
80 "133 MHz PCI-X 266", /* 0x0b */
1da177e4
LT
81 NULL, /* 0x0c */
82 NULL, /* 0x0d */
83 NULL, /* 0x0e */
84 NULL, /* 0x0f */
85 NULL, /* 0x10 */
17d67152
SA
86 "66 MHz PCI-X 533", /* 0x11 */
87 "100 MHz PCI-X 533", /* 0x12 */
88 "133 MHz PCI-X 533", /* 0x13 */
89 "2.5 GT/s PCIe", /* 0x14 */
90 "5.0 GT/s PCIe", /* 0x15 */
1da177e4
LT
91};
92
93#ifdef CONFIG_HOTPLUG_PCI_CPCI
94extern int cpci_hotplug_init(int debug);
95extern void cpci_hotplug_exit(void);
96#else
97static inline int cpci_hotplug_init(int debug) { return 0; }
98static inline void cpci_hotplug_exit(void) { }
99#endif
100
101/* Weee, fun with macros... */
102#define GET_STATUS(name,type) \
103static int get_##name (struct hotplug_slot *slot, type *value) \
104{ \
105 struct hotplug_slot_ops *ops = slot->ops; \
106 int retval = 0; \
bd1d9855 107 if (!try_module_get(ops->owner)) \
c8761fe8
ZY
108 return -ENODEV; \
109 if (ops->get_##name) \
110 retval = ops->get_##name(slot, value); \
111 else \
112 *value = slot->info->name; \
113 module_put(ops->owner); \
1da177e4
LT
114 return retval; \
115}
116
117GET_STATUS(power_status, u8)
118GET_STATUS(attention_status, u8)
119GET_STATUS(latch_status, u8)
120GET_STATUS(adapter_status, u8)
1da177e4
LT
121GET_STATUS(max_bus_speed, enum pci_bus_speed)
122GET_STATUS(cur_bus_speed, enum pci_bus_speed)
123
f46753c5 124static ssize_t power_read_file(struct pci_slot *slot, char *buf)
1da177e4
LT
125{
126 int retval;
127 u8 value;
128
f46753c5 129 retval = get_power_status(slot->hotplug, &value);
1da177e4
LT
130 if (retval)
131 goto exit;
132 retval = sprintf (buf, "%d\n", value);
133exit:
134 return retval;
135}
136
f46753c5 137static ssize_t power_write_file(struct pci_slot *pci_slot, const char *buf,
1da177e4
LT
138 size_t count)
139{
f46753c5 140 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4
LT
141 unsigned long lpower;
142 u8 power;
143 int retval = 0;
144
145 lpower = simple_strtoul (buf, NULL, 10);
146 power = (u8)(lpower & 0xff);
147 dbg ("power = %d\n", power);
148
149 if (!try_module_get(slot->ops->owner)) {
150 retval = -ENODEV;
151 goto exit;
152 }
153 switch (power) {
154 case 0:
155 if (slot->ops->disable_slot)
156 retval = slot->ops->disable_slot(slot);
157 break;
158
159 case 1:
160 if (slot->ops->enable_slot)
161 retval = slot->ops->enable_slot(slot);
162 break;
163
164 default:
165 err ("Illegal value specified for power\n");
166 retval = -EINVAL;
167 }
168 module_put(slot->ops->owner);
169
170exit:
171 if (retval)
172 return retval;
173 return count;
174}
175
f46753c5 176static struct pci_slot_attribute hotplug_slot_attr_power = {
1da177e4
LT
177 .attr = {.name = "power", .mode = S_IFREG | S_IRUGO | S_IWUSR},
178 .show = power_read_file,
179 .store = power_write_file
180};
181
f46753c5 182static ssize_t attention_read_file(struct pci_slot *slot, char *buf)
1da177e4
LT
183{
184 int retval;
185 u8 value;
186
f46753c5 187 retval = get_attention_status(slot->hotplug, &value);
1da177e4
LT
188 if (retval)
189 goto exit;
f46753c5 190 retval = sprintf(buf, "%d\n", value);
1da177e4
LT
191
192exit:
193 return retval;
194}
195
f46753c5 196static ssize_t attention_write_file(struct pci_slot *slot, const char *buf,
1da177e4
LT
197 size_t count)
198{
f46753c5 199 struct hotplug_slot_ops *ops = slot->hotplug->ops;
1da177e4
LT
200 unsigned long lattention;
201 u8 attention;
202 int retval = 0;
203
204 lattention = simple_strtoul (buf, NULL, 10);
205 attention = (u8)(lattention & 0xff);
206 dbg (" - attention = %d\n", attention);
207
f46753c5 208 if (!try_module_get(ops->owner)) {
1da177e4
LT
209 retval = -ENODEV;
210 goto exit;
211 }
f46753c5
AC
212 if (ops->set_attention_status)
213 retval = ops->set_attention_status(slot->hotplug, attention);
214 module_put(ops->owner);
1da177e4
LT
215
216exit:
217 if (retval)
218 return retval;
219 return count;
220}
221
f46753c5 222static struct pci_slot_attribute hotplug_slot_attr_attention = {
1da177e4
LT
223 .attr = {.name = "attention", .mode = S_IFREG | S_IRUGO | S_IWUSR},
224 .show = attention_read_file,
225 .store = attention_write_file
226};
227
f46753c5 228static ssize_t latch_read_file(struct pci_slot *slot, char *buf)
1da177e4
LT
229{
230 int retval;
231 u8 value;
232
f46753c5 233 retval = get_latch_status(slot->hotplug, &value);
1da177e4
LT
234 if (retval)
235 goto exit;
236 retval = sprintf (buf, "%d\n", value);
237
238exit:
239 return retval;
240}
241
f46753c5 242static struct pci_slot_attribute hotplug_slot_attr_latch = {
1da177e4
LT
243 .attr = {.name = "latch", .mode = S_IFREG | S_IRUGO},
244 .show = latch_read_file,
245};
246
f46753c5 247static ssize_t presence_read_file(struct pci_slot *slot, char *buf)
1da177e4
LT
248{
249 int retval;
250 u8 value;
251
f46753c5 252 retval = get_adapter_status(slot->hotplug, &value);
1da177e4
LT
253 if (retval)
254 goto exit;
255 retval = sprintf (buf, "%d\n", value);
256
257exit:
258 return retval;
259}
260
f46753c5 261static struct pci_slot_attribute hotplug_slot_attr_presence = {
1da177e4
LT
262 .attr = {.name = "adapter", .mode = S_IFREG | S_IRUGO},
263 .show = presence_read_file,
264};
265
1da177e4
LT
266static char *unknown_speed = "Unknown bus speed";
267
f46753c5 268static ssize_t max_bus_speed_read_file(struct pci_slot *slot, char *buf)
1da177e4
LT
269{
270 char *speed_string;
271 int retval;
272 enum pci_bus_speed value;
273
f46753c5 274 retval = get_max_bus_speed(slot->hotplug, &value);
1da177e4
LT
275 if (retval)
276 goto exit;
277
278 if (value == PCI_SPEED_UNKNOWN)
279 speed_string = unknown_speed;
280 else
281 speed_string = pci_bus_speed_strings[value];
282
283 retval = sprintf (buf, "%s\n", speed_string);
284
285exit:
286 return retval;
287}
288
f46753c5 289static struct pci_slot_attribute hotplug_slot_attr_max_bus_speed = {
1da177e4
LT
290 .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO},
291 .show = max_bus_speed_read_file,
292};
293
f46753c5 294static ssize_t cur_bus_speed_read_file(struct pci_slot *slot, char *buf)
1da177e4
LT
295{
296 char *speed_string;
297 int retval;
298 enum pci_bus_speed value;
299
f46753c5 300 retval = get_cur_bus_speed(slot->hotplug, &value);
1da177e4
LT
301 if (retval)
302 goto exit;
303
304 if (value == PCI_SPEED_UNKNOWN)
305 speed_string = unknown_speed;
306 else
307 speed_string = pci_bus_speed_strings[value];
308
309 retval = sprintf (buf, "%s\n", speed_string);
310
311exit:
312 return retval;
313}
314
f46753c5 315static struct pci_slot_attribute hotplug_slot_attr_cur_bus_speed = {
1da177e4
LT
316 .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO},
317 .show = cur_bus_speed_read_file,
318};
319
f46753c5 320static ssize_t test_write_file(struct pci_slot *pci_slot, const char *buf,
1da177e4
LT
321 size_t count)
322{
f46753c5 323 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4
LT
324 unsigned long ltest;
325 u32 test;
326 int retval = 0;
327
328 ltest = simple_strtoul (buf, NULL, 10);
329 test = (u32)(ltest & 0xffffffff);
330 dbg ("test = %d\n", test);
331
332 if (!try_module_get(slot->ops->owner)) {
333 retval = -ENODEV;
334 goto exit;
335 }
336 if (slot->ops->hardware_test)
337 retval = slot->ops->hardware_test(slot, test);
338 module_put(slot->ops->owner);
339
340exit:
341 if (retval)
342 return retval;
343 return count;
344}
345
f46753c5 346static struct pci_slot_attribute hotplug_slot_attr_test = {
1da177e4
LT
347 .attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR},
348 .store = test_write_file
349};
350
498a8faf 351static bool has_power_file(struct pci_slot *pci_slot)
1da177e4 352{
f46753c5 353 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4 354 if ((!slot) || (!slot->ops))
498a8faf 355 return false;
1da177e4
LT
356 if ((slot->ops->enable_slot) ||
357 (slot->ops->disable_slot) ||
358 (slot->ops->get_power_status))
498a8faf
KK
359 return true;
360 return false;
1da177e4
LT
361}
362
498a8faf 363static bool has_attention_file(struct pci_slot *pci_slot)
1da177e4 364{
f46753c5 365 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4 366 if ((!slot) || (!slot->ops))
498a8faf 367 return false;
1da177e4
LT
368 if ((slot->ops->set_attention_status) ||
369 (slot->ops->get_attention_status))
498a8faf
KK
370 return true;
371 return false;
1da177e4
LT
372}
373
498a8faf 374static bool has_latch_file(struct pci_slot *pci_slot)
1da177e4 375{
f46753c5 376 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4 377 if ((!slot) || (!slot->ops))
498a8faf 378 return false;
1da177e4 379 if (slot->ops->get_latch_status)
498a8faf
KK
380 return true;
381 return false;
1da177e4
LT
382}
383
498a8faf 384static bool has_adapter_file(struct pci_slot *pci_slot)
1da177e4 385{
f46753c5 386 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4 387 if ((!slot) || (!slot->ops))
498a8faf 388 return false;
1da177e4 389 if (slot->ops->get_adapter_status)
498a8faf
KK
390 return true;
391 return false;
1da177e4
LT
392}
393
498a8faf 394static bool has_max_bus_speed_file(struct pci_slot *pci_slot)
1da177e4 395{
f46753c5 396 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4 397 if ((!slot) || (!slot->ops))
498a8faf 398 return false;
1da177e4 399 if (slot->ops->get_max_bus_speed)
498a8faf
KK
400 return true;
401 return false;
1da177e4
LT
402}
403
498a8faf 404static bool has_cur_bus_speed_file(struct pci_slot *pci_slot)
1da177e4 405{
f46753c5 406 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4 407 if ((!slot) || (!slot->ops))
498a8faf 408 return false;
1da177e4 409 if (slot->ops->get_cur_bus_speed)
498a8faf
KK
410 return true;
411 return false;
1da177e4
LT
412}
413
498a8faf 414static bool has_test_file(struct pci_slot *pci_slot)
1da177e4 415{
f46753c5 416 struct hotplug_slot *slot = pci_slot->hotplug;
1da177e4 417 if ((!slot) || (!slot->ops))
498a8faf 418 return false;
1da177e4 419 if (slot->ops->hardware_test)
498a8faf
KK
420 return true;
421 return false;
1da177e4
LT
422}
423
f46753c5 424static int fs_add_slot(struct pci_slot *slot)
1da177e4 425{
660a0e8f 426 int retval = 0;
1da177e4 427
c825bc94
KK
428 /* Create symbolic link to the hotplug driver module */
429 pci_hp_create_module_link(slot);
430
498a8faf
KK
431 if (has_power_file(slot)) {
432 retval = sysfs_create_file(&slot->kobj,
433 &hotplug_slot_attr_power.attr);
660a0e8f
GKH
434 if (retval)
435 goto exit_power;
436 }
1da177e4 437
498a8faf 438 if (has_attention_file(slot)) {
660a0e8f
GKH
439 retval = sysfs_create_file(&slot->kobj,
440 &hotplug_slot_attr_attention.attr);
441 if (retval)
442 goto exit_attention;
443 }
1da177e4 444
498a8faf 445 if (has_latch_file(slot)) {
660a0e8f
GKH
446 retval = sysfs_create_file(&slot->kobj,
447 &hotplug_slot_attr_latch.attr);
448 if (retval)
449 goto exit_latch;
450 }
1da177e4 451
498a8faf 452 if (has_adapter_file(slot)) {
660a0e8f
GKH
453 retval = sysfs_create_file(&slot->kobj,
454 &hotplug_slot_attr_presence.attr);
455 if (retval)
456 goto exit_adapter;
457 }
1da177e4 458
498a8faf 459 if (has_max_bus_speed_file(slot)) {
660a0e8f 460 retval = sysfs_create_file(&slot->kobj,
498a8faf 461 &hotplug_slot_attr_max_bus_speed.attr);
660a0e8f
GKH
462 if (retval)
463 goto exit_max_speed;
464 }
465
498a8faf 466 if (has_cur_bus_speed_file(slot)) {
660a0e8f 467 retval = sysfs_create_file(&slot->kobj,
498a8faf 468 &hotplug_slot_attr_cur_bus_speed.attr);
660a0e8f
GKH
469 if (retval)
470 goto exit_cur_speed;
471 }
472
498a8faf 473 if (has_test_file(slot)) {
660a0e8f
GKH
474 retval = sysfs_create_file(&slot->kobj,
475 &hotplug_slot_attr_test.attr);
476 if (retval)
477 goto exit_test;
478 }
479
480 goto exit;
481
482exit_test:
498a8faf
KK
483 if (has_cur_bus_speed_file(slot))
484 sysfs_remove_file(&slot->kobj,
485 &hotplug_slot_attr_cur_bus_speed.attr);
660a0e8f 486exit_cur_speed:
498a8faf
KK
487 if (has_max_bus_speed_file(slot))
488 sysfs_remove_file(&slot->kobj,
489 &hotplug_slot_attr_max_bus_speed.attr);
660a0e8f 490exit_max_speed:
498a8faf
KK
491 if (has_adapter_file(slot))
492 sysfs_remove_file(&slot->kobj,
493 &hotplug_slot_attr_presence.attr);
660a0e8f 494exit_adapter:
498a8faf 495 if (has_latch_file(slot))
660a0e8f 496 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);
660a0e8f 497exit_latch:
498a8faf
KK
498 if (has_attention_file(slot))
499 sysfs_remove_file(&slot->kobj,
500 &hotplug_slot_attr_attention.attr);
660a0e8f 501exit_attention:
498a8faf 502 if (has_power_file(slot))
660a0e8f
GKH
503 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
504exit_power:
c825bc94 505 pci_hp_remove_module_link(slot);
660a0e8f
GKH
506exit:
507 return retval;
1da177e4
LT
508}
509
f46753c5 510static void fs_remove_slot(struct pci_slot *slot)
1da177e4 511{
498a8faf 512 if (has_power_file(slot))
1da177e4
LT
513 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
514
498a8faf
KK
515 if (has_attention_file(slot))
516 sysfs_remove_file(&slot->kobj,
517 &hotplug_slot_attr_attention.attr);
1da177e4 518
498a8faf 519 if (has_latch_file(slot))
1da177e4
LT
520 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);
521
498a8faf
KK
522 if (has_adapter_file(slot))
523 sysfs_remove_file(&slot->kobj,
524 &hotplug_slot_attr_presence.attr);
1da177e4 525
498a8faf
KK
526 if (has_max_bus_speed_file(slot))
527 sysfs_remove_file(&slot->kobj,
528 &hotplug_slot_attr_max_bus_speed.attr);
1da177e4 529
498a8faf
KK
530 if (has_cur_bus_speed_file(slot))
531 sysfs_remove_file(&slot->kobj,
532 &hotplug_slot_attr_cur_bus_speed.attr);
1da177e4 533
498a8faf 534 if (has_test_file(slot))
1da177e4 535 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_test.attr);
c825bc94
KK
536
537 pci_hp_remove_module_link(slot);
1da177e4
LT
538}
539
540static struct hotplug_slot *get_slot_from_name (const char *name)
541{
542 struct hotplug_slot *slot;
543 struct list_head *tmp;
544
545 list_for_each (tmp, &pci_hotplug_slot_list) {
546 slot = list_entry (tmp, struct hotplug_slot, slot_list);
58319b80 547 if (strcmp(hotplug_slot_name(slot), name) == 0)
95cb9093 548 return slot;
1da177e4 549 }
95cb9093 550 return NULL;
1da177e4
LT
551}
552
553/**
c825bc94 554 * __pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem
65b943f6 555 * @bus: bus this slot is on
1da177e4 556 * @slot: pointer to the &struct hotplug_slot to register
c825bc94 557 * @devnr: device number
1359f270 558 * @name: name registered with kobject core
503998ca
RD
559 * @owner: caller module owner
560 * @mod_name: caller module name
1da177e4
LT
561 *
562 * Registers a hotplug slot with the pci hotplug subsystem, which will allow
563 * userspace interaction to the slot.
564 *
565 * Returns 0 if successful, anything else for an error.
566 */
c825bc94
KK
567int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
568 int devnr, const char *name,
569 struct module *owner, const char *mod_name)
1da177e4
LT
570{
571 int result;
f46753c5 572 struct pci_slot *pci_slot;
1da177e4
LT
573
574 if (slot == NULL)
575 return -ENODEV;
576 if ((slot->info == NULL) || (slot->ops == NULL))
577 return -EINVAL;
578 if (slot->release == NULL) {
a6f29a98 579 dbg("Why are you trying to register a hotplug slot "
1da177e4
LT
580 "without a proper release function?\n");
581 return -EINVAL;
582 }
583
c825bc94
KK
584 slot->ops->owner = owner;
585 slot->ops->mod_name = mod_name;
95cb9093 586
c825bc94 587 mutex_lock(&pci_hp_mutex);
8344b568
AC
588 /*
589 * No problems if we call this interface from both ACPI_PCI_SLOT
590 * driver and call it here again. If we've already created the
591 * pci_slot, the interface will simply bump the refcount.
592 */
c825bc94 593 pci_slot = pci_create_slot(bus, devnr, name, slot);
95cb9093
KK
594 if (IS_ERR(pci_slot)) {
595 result = PTR_ERR(pci_slot);
5fe6cc60 596 goto out;
1da177e4 597 }
64dbcac3 598
f46753c5
AC
599 slot->pci_slot = pci_slot;
600 pci_slot->hotplug = slot;
601
f46753c5 602 list_add(&slot->slot_list, &pci_hotplug_slot_list);
f46753c5
AC
603
604 result = fs_add_slot(pci_slot);
605 kobject_uevent(&pci_slot->kobj, KOBJ_ADD);
1359f270 606 dbg("Added slot %s to the list\n", name);
95cb9093
KK
607out:
608 mutex_unlock(&pci_hp_mutex);
1da177e4
LT
609 return result;
610}
611
612/**
613 * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem
65b943f6 614 * @hotplug: pointer to the &struct hotplug_slot to deregister
1da177e4
LT
615 *
616 * The @slot must have been registered with the pci hotplug subsystem
617 * previously with a call to pci_hp_register().
618 *
619 * Returns 0 if successful, anything else for an error.
620 */
f46753c5 621int pci_hp_deregister(struct hotplug_slot *hotplug)
1da177e4
LT
622{
623 struct hotplug_slot *temp;
f46753c5 624 struct pci_slot *slot;
1da177e4 625
f46753c5 626 if (!hotplug)
1da177e4
LT
627 return -ENODEV;
628
95cb9093 629 mutex_lock(&pci_hp_mutex);
58319b80 630 temp = get_slot_from_name(hotplug_slot_name(hotplug));
95cb9093
KK
631 if (temp != hotplug) {
632 mutex_unlock(&pci_hp_mutex);
1da177e4 633 return -ENODEV;
95cb9093 634 }
1da177e4 635
f46753c5 636 list_del(&hotplug->slot_list);
f46753c5
AC
637
638 slot = hotplug->pci_slot;
639 fs_remove_slot(slot);
58319b80 640 dbg("Removed slot %s from the list\n", hotplug_slot_name(hotplug));
f46753c5
AC
641
642 hotplug->release(hotplug);
643 slot->hotplug = NULL;
644 pci_destroy_slot(slot);
95cb9093 645 mutex_unlock(&pci_hp_mutex);
f46753c5 646
1da177e4
LT
647 return 0;
648}
649
650/**
651 * pci_hp_change_slot_info - changes the slot's information structure in the core
65b943f6 652 * @hotplug: pointer to the slot whose info has changed
1da177e4
LT
653 * @info: pointer to the info copy into the slot's info structure
654 *
655 * @slot must have been registered with the pci
656 * hotplug subsystem previously with a call to pci_hp_register().
657 *
658 * Returns 0 if successful, anything else for an error.
659 */
f46753c5 660int __must_check pci_hp_change_slot_info(struct hotplug_slot *hotplug,
660a0e8f 661 struct hotplug_slot_info *info)
1da177e4 662{
f46753c5
AC
663 struct pci_slot *slot;
664 if (!hotplug || !info)
1da177e4 665 return -ENODEV;
f46753c5 666 slot = hotplug->pci_slot;
1da177e4 667
f46753c5 668 memcpy(hotplug->info, info, sizeof(struct hotplug_slot_info));
1da177e4
LT
669
670 return 0;
671}
672
673static int __init pci_hotplug_init (void)
674{
675 int result;
0fed80f7 676
1da177e4
LT
677 result = cpci_hotplug_init(debug);
678 if (result) {
679 err ("cpci_hotplug_init with error %d\n", result);
f46753c5 680 goto err_cpci;
1da177e4
LT
681 }
682
683 info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
81ace5cd 684
f46753c5 685err_cpci:
1da177e4
LT
686 return result;
687}
688
689static void __exit pci_hotplug_exit (void)
690{
691 cpci_hotplug_exit();
1da177e4
LT
692}
693
694module_init(pci_hotplug_init);
695module_exit(pci_hotplug_exit);
696
697MODULE_AUTHOR(DRIVER_AUTHOR);
698MODULE_DESCRIPTION(DRIVER_DESC);
699MODULE_LICENSE("GPL");
700module_param(debug, bool, 0644);
701MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
702
c825bc94 703EXPORT_SYMBOL_GPL(__pci_hp_register);
1da177e4
LT
704EXPORT_SYMBOL_GPL(pci_hp_deregister);
705EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);