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