blob: dd59a050260fe81035bd42193b1c5613d8c70b84 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Kristen Carlson Accardifb5f4d72006-09-29 10:30:27 -070024 * Send feedback to <kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 *
26 */
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/module.h>
29#include <linux/moduleparam.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/list.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070033#include <linux/kobject.h>
34#include <linux/sysfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/pagemap.h>
36#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/init.h>
38#include <linux/mount.h>
39#include <linux/namei.h>
40#include <linux/pci.h>
Greg Kroah-Hartman7a54f252006-10-13 20:05:19 -070041#include <linux/pci_hotplug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#define MY_NAME "pci_hotplug"
45
46#define dbg(fmt, arg...) do { if (debug) printk(KERN_DEBUG "%s: %s: " fmt , MY_NAME , __FUNCTION__ , ## arg); } while (0)
47#define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg)
48#define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg)
49#define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg)
50
51
52/* local variables */
53static int debug;
54
55#define DRIVER_VERSION "0.5"
56#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Scott Murray <scottm@somanetworks.com>"
57#define DRIVER_DESC "PCI Hot Plug PCI Core"
58
59
60//////////////////////////////////////////////////////////////////
61
62static LIST_HEAD(pci_hotplug_slot_list);
63
Greg Kroah-Hartman81ace5c2007-10-29 23:22:26 -050064struct kset *pci_hotplug_slots_kset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66static ssize_t hotplug_slot_attr_show(struct kobject *kobj,
67 struct attribute *attr, char *buf)
68{
69 struct hotplug_slot *slot = to_hotplug_slot(kobj);
70 struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr);
Dmitry Torokhovfc7e4822005-04-29 01:26:27 -050071 return attribute->show ? attribute->show(slot, buf) : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
74static ssize_t hotplug_slot_attr_store(struct kobject *kobj,
75 struct attribute *attr, const char *buf, size_t len)
76{
77 struct hotplug_slot *slot = to_hotplug_slot(kobj);
78 struct hotplug_slot_attribute *attribute = to_hotplug_attr(attr);
Dmitry Torokhovfc7e4822005-04-29 01:26:27 -050079 return attribute->store ? attribute->store(slot, buf, len) : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82static struct sysfs_ops hotplug_slot_sysfs_ops = {
83 .show = hotplug_slot_attr_show,
84 .store = hotplug_slot_attr_store,
85};
86
87static void hotplug_slot_release(struct kobject *kobj)
88{
89 struct hotplug_slot *slot = to_hotplug_slot(kobj);
90 if (slot->release)
91 slot->release(slot);
92}
93
94static struct kobj_type hotplug_slot_ktype = {
95 .sysfs_ops = &hotplug_slot_sysfs_ops,
96 .release = &hotplug_slot_release,
97};
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* these strings match up with the values in pci_bus_speed */
100static char *pci_bus_speed_strings[] = {
101 "33 MHz PCI", /* 0x00 */
102 "66 MHz PCI", /* 0x01 */
103 "66 MHz PCIX", /* 0x02 */
104 "100 MHz PCIX", /* 0x03 */
105 "133 MHz PCIX", /* 0x04 */
106 NULL, /* 0x05 */
107 NULL, /* 0x06 */
108 NULL, /* 0x07 */
109 NULL, /* 0x08 */
110 "66 MHz PCIX 266", /* 0x09 */
111 "100 MHz PCIX 266", /* 0x0a */
112 "133 MHz PCIX 266", /* 0x0b */
113 NULL, /* 0x0c */
114 NULL, /* 0x0d */
115 NULL, /* 0x0e */
116 NULL, /* 0x0f */
117 NULL, /* 0x10 */
118 "66 MHz PCIX 533", /* 0x11 */
119 "100 MHz PCIX 533", /* 0x12 */
120 "133 MHz PCIX 533", /* 0x13 */
121 "25 GBps PCI-E", /* 0x14 */
122};
123
124#ifdef CONFIG_HOTPLUG_PCI_CPCI
125extern int cpci_hotplug_init(int debug);
126extern void cpci_hotplug_exit(void);
127#else
128static inline int cpci_hotplug_init(int debug) { return 0; }
129static inline void cpci_hotplug_exit(void) { }
130#endif
131
132/* Weee, fun with macros... */
133#define GET_STATUS(name,type) \
134static int get_##name (struct hotplug_slot *slot, type *value) \
135{ \
136 struct hotplug_slot_ops *ops = slot->ops; \
137 int retval = 0; \
138 if (try_module_get(ops->owner)) { \
139 if (ops->get_##name) \
Alex Chiang41ece382007-10-12 16:20:32 -0700140 retval = ops->get_##name(slot, value); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 else \
142 *value = slot->info->name; \
143 module_put(ops->owner); \
144 } \
145 return retval; \
146}
147
148GET_STATUS(power_status, u8)
149GET_STATUS(attention_status, u8)
150GET_STATUS(latch_status, u8)
151GET_STATUS(adapter_status, u8)
152GET_STATUS(address, u32)
153GET_STATUS(max_bus_speed, enum pci_bus_speed)
154GET_STATUS(cur_bus_speed, enum pci_bus_speed)
155
156static ssize_t power_read_file (struct hotplug_slot *slot, char *buf)
157{
158 int retval;
159 u8 value;
160
161 retval = get_power_status (slot, &value);
162 if (retval)
163 goto exit;
164 retval = sprintf (buf, "%d\n", value);
165exit:
166 return retval;
167}
168
169static ssize_t power_write_file (struct hotplug_slot *slot, const char *buf,
170 size_t count)
171{
172 unsigned long lpower;
173 u8 power;
174 int retval = 0;
175
176 lpower = simple_strtoul (buf, NULL, 10);
177 power = (u8)(lpower & 0xff);
178 dbg ("power = %d\n", power);
179
180 if (!try_module_get(slot->ops->owner)) {
181 retval = -ENODEV;
182 goto exit;
183 }
184 switch (power) {
185 case 0:
186 if (slot->ops->disable_slot)
187 retval = slot->ops->disable_slot(slot);
188 break;
189
190 case 1:
191 if (slot->ops->enable_slot)
192 retval = slot->ops->enable_slot(slot);
193 break;
194
195 default:
196 err ("Illegal value specified for power\n");
197 retval = -EINVAL;
198 }
199 module_put(slot->ops->owner);
200
201exit:
202 if (retval)
203 return retval;
204 return count;
205}
206
207static struct hotplug_slot_attribute hotplug_slot_attr_power = {
208 .attr = {.name = "power", .mode = S_IFREG | S_IRUGO | S_IWUSR},
209 .show = power_read_file,
210 .store = power_write_file
211};
212
213static ssize_t attention_read_file (struct hotplug_slot *slot, char *buf)
214{
215 int retval;
216 u8 value;
217
218 retval = get_attention_status (slot, &value);
219 if (retval)
220 goto exit;
221 retval = sprintf (buf, "%d\n", value);
222
223exit:
224 return retval;
225}
226
227static ssize_t attention_write_file (struct hotplug_slot *slot, const char *buf,
228 size_t count)
229{
230 unsigned long lattention;
231 u8 attention;
232 int retval = 0;
233
234 lattention = simple_strtoul (buf, NULL, 10);
235 attention = (u8)(lattention & 0xff);
236 dbg (" - attention = %d\n", attention);
237
238 if (!try_module_get(slot->ops->owner)) {
239 retval = -ENODEV;
240 goto exit;
241 }
242 if (slot->ops->set_attention_status)
243 retval = slot->ops->set_attention_status(slot, attention);
244 module_put(slot->ops->owner);
245
246exit:
247 if (retval)
248 return retval;
249 return count;
250}
251
252static struct hotplug_slot_attribute hotplug_slot_attr_attention = {
253 .attr = {.name = "attention", .mode = S_IFREG | S_IRUGO | S_IWUSR},
254 .show = attention_read_file,
255 .store = attention_write_file
256};
257
258static ssize_t latch_read_file (struct hotplug_slot *slot, char *buf)
259{
260 int retval;
261 u8 value;
262
263 retval = get_latch_status (slot, &value);
264 if (retval)
265 goto exit;
266 retval = sprintf (buf, "%d\n", value);
267
268exit:
269 return retval;
270}
271
272static struct hotplug_slot_attribute hotplug_slot_attr_latch = {
273 .attr = {.name = "latch", .mode = S_IFREG | S_IRUGO},
274 .show = latch_read_file,
275};
276
277static ssize_t presence_read_file (struct hotplug_slot *slot, char *buf)
278{
279 int retval;
280 u8 value;
281
282 retval = get_adapter_status (slot, &value);
283 if (retval)
284 goto exit;
285 retval = sprintf (buf, "%d\n", value);
286
287exit:
288 return retval;
289}
290
291static struct hotplug_slot_attribute hotplug_slot_attr_presence = {
292 .attr = {.name = "adapter", .mode = S_IFREG | S_IRUGO},
293 .show = presence_read_file,
294};
295
296static ssize_t address_read_file (struct hotplug_slot *slot, char *buf)
297{
298 int retval;
299 u32 address;
300
301 retval = get_address (slot, &address);
302 if (retval)
303 goto exit;
304 retval = sprintf (buf, "%04x:%02x:%02x\n",
305 (address >> 16) & 0xffff,
306 (address >> 8) & 0xff,
307 address & 0xff);
308
309exit:
310 return retval;
311}
312
313static struct hotplug_slot_attribute hotplug_slot_attr_address = {
314 .attr = {.name = "address", .mode = S_IFREG | S_IRUGO},
315 .show = address_read_file,
316};
317
318static char *unknown_speed = "Unknown bus speed";
319
320static ssize_t max_bus_speed_read_file (struct hotplug_slot *slot, char *buf)
321{
322 char *speed_string;
323 int retval;
324 enum pci_bus_speed value;
325
326 retval = get_max_bus_speed (slot, &value);
327 if (retval)
328 goto exit;
329
330 if (value == PCI_SPEED_UNKNOWN)
331 speed_string = unknown_speed;
332 else
333 speed_string = pci_bus_speed_strings[value];
334
335 retval = sprintf (buf, "%s\n", speed_string);
336
337exit:
338 return retval;
339}
340
341static struct hotplug_slot_attribute hotplug_slot_attr_max_bus_speed = {
342 .attr = {.name = "max_bus_speed", .mode = S_IFREG | S_IRUGO},
343 .show = max_bus_speed_read_file,
344};
345
346static ssize_t cur_bus_speed_read_file (struct hotplug_slot *slot, char *buf)
347{
348 char *speed_string;
349 int retval;
350 enum pci_bus_speed value;
351
352 retval = get_cur_bus_speed (slot, &value);
353 if (retval)
354 goto exit;
355
356 if (value == PCI_SPEED_UNKNOWN)
357 speed_string = unknown_speed;
358 else
359 speed_string = pci_bus_speed_strings[value];
360
361 retval = sprintf (buf, "%s\n", speed_string);
362
363exit:
364 return retval;
365}
366
367static struct hotplug_slot_attribute hotplug_slot_attr_cur_bus_speed = {
368 .attr = {.name = "cur_bus_speed", .mode = S_IFREG | S_IRUGO},
369 .show = cur_bus_speed_read_file,
370};
371
372static ssize_t test_write_file (struct hotplug_slot *slot, const char *buf,
373 size_t count)
374{
375 unsigned long ltest;
376 u32 test;
377 int retval = 0;
378
379 ltest = simple_strtoul (buf, NULL, 10);
380 test = (u32)(ltest & 0xffffffff);
381 dbg ("test = %d\n", test);
382
383 if (!try_module_get(slot->ops->owner)) {
384 retval = -ENODEV;
385 goto exit;
386 }
387 if (slot->ops->hardware_test)
388 retval = slot->ops->hardware_test(slot, test);
389 module_put(slot->ops->owner);
390
391exit:
392 if (retval)
393 return retval;
394 return count;
395}
396
397static struct hotplug_slot_attribute hotplug_slot_attr_test = {
398 .attr = {.name = "test", .mode = S_IFREG | S_IRUGO | S_IWUSR},
399 .store = test_write_file
400};
401
402static int has_power_file (struct hotplug_slot *slot)
403{
404 if ((!slot) || (!slot->ops))
405 return -ENODEV;
406 if ((slot->ops->enable_slot) ||
407 (slot->ops->disable_slot) ||
408 (slot->ops->get_power_status))
409 return 0;
410 return -ENOENT;
411}
412
413static int has_attention_file (struct hotplug_slot *slot)
414{
415 if ((!slot) || (!slot->ops))
416 return -ENODEV;
417 if ((slot->ops->set_attention_status) ||
418 (slot->ops->get_attention_status))
419 return 0;
420 return -ENOENT;
421}
422
423static int has_latch_file (struct hotplug_slot *slot)
424{
425 if ((!slot) || (!slot->ops))
426 return -ENODEV;
427 if (slot->ops->get_latch_status)
428 return 0;
429 return -ENOENT;
430}
431
432static int has_adapter_file (struct hotplug_slot *slot)
433{
434 if ((!slot) || (!slot->ops))
435 return -ENODEV;
436 if (slot->ops->get_adapter_status)
437 return 0;
438 return -ENOENT;
439}
440
441static int has_address_file (struct hotplug_slot *slot)
442{
443 if ((!slot) || (!slot->ops))
444 return -ENODEV;
445 if (slot->ops->get_address)
446 return 0;
447 return -ENOENT;
448}
449
450static int has_max_bus_speed_file (struct hotplug_slot *slot)
451{
452 if ((!slot) || (!slot->ops))
453 return -ENODEV;
454 if (slot->ops->get_max_bus_speed)
455 return 0;
456 return -ENOENT;
457}
458
459static int has_cur_bus_speed_file (struct hotplug_slot *slot)
460{
461 if ((!slot) || (!slot->ops))
462 return -ENODEV;
463 if (slot->ops->get_cur_bus_speed)
464 return 0;
465 return -ENOENT;
466}
467
468static int has_test_file (struct hotplug_slot *slot)
469{
470 if ((!slot) || (!slot->ops))
471 return -ENODEV;
472 if (slot->ops->hardware_test)
473 return 0;
474 return -ENOENT;
475}
476
477static int fs_add_slot (struct hotplug_slot *slot)
478{
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700479 int retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700481 if (has_power_file(slot) == 0) {
482 retval = sysfs_create_file(&slot->kobj, &hotplug_slot_attr_power.attr);
483 if (retval)
484 goto exit_power;
485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700487 if (has_attention_file(slot) == 0) {
488 retval = sysfs_create_file(&slot->kobj,
489 &hotplug_slot_attr_attention.attr);
490 if (retval)
491 goto exit_attention;
492 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700494 if (has_latch_file(slot) == 0) {
495 retval = sysfs_create_file(&slot->kobj,
496 &hotplug_slot_attr_latch.attr);
497 if (retval)
498 goto exit_latch;
499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700501 if (has_adapter_file(slot) == 0) {
502 retval = sysfs_create_file(&slot->kobj,
503 &hotplug_slot_attr_presence.attr);
504 if (retval)
505 goto exit_adapter;
506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700508 if (has_address_file(slot) == 0) {
509 retval = sysfs_create_file(&slot->kobj,
510 &hotplug_slot_attr_address.attr);
511 if (retval)
512 goto exit_address;
513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700515 if (has_max_bus_speed_file(slot) == 0) {
516 retval = sysfs_create_file(&slot->kobj,
517 &hotplug_slot_attr_max_bus_speed.attr);
518 if (retval)
519 goto exit_max_speed;
520 }
521
522 if (has_cur_bus_speed_file(slot) == 0) {
523 retval = sysfs_create_file(&slot->kobj,
524 &hotplug_slot_attr_cur_bus_speed.attr);
525 if (retval)
526 goto exit_cur_speed;
527 }
528
529 if (has_test_file(slot) == 0) {
530 retval = sysfs_create_file(&slot->kobj,
531 &hotplug_slot_attr_test.attr);
532 if (retval)
533 goto exit_test;
534 }
535
536 goto exit;
537
538exit_test:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 if (has_cur_bus_speed_file(slot) == 0)
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700540 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700542exit_cur_speed:
543 if (has_max_bus_speed_file(slot) == 0)
544 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700546exit_max_speed:
547 if (has_address_file(slot) == 0)
548 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);
549
550exit_address:
551 if (has_adapter_file(slot) == 0)
552 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);
553
554exit_adapter:
555 if (has_latch_file(slot) == 0)
556 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);
557
558exit_latch:
559 if (has_attention_file(slot) == 0)
560 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_attention.attr);
561
562exit_attention:
563 if (has_power_file(slot) == 0)
564 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
565exit_power:
566exit:
567 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568}
569
570static void fs_remove_slot (struct hotplug_slot *slot)
571{
572 if (has_power_file(slot) == 0)
573 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
574
575 if (has_attention_file(slot) == 0)
576 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_attention.attr);
577
578 if (has_latch_file(slot) == 0)
579 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);
580
581 if (has_adapter_file(slot) == 0)
582 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);
583
584 if (has_address_file(slot) == 0)
585 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);
586
587 if (has_max_bus_speed_file(slot) == 0)
588 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);
589
590 if (has_cur_bus_speed_file(slot) == 0)
591 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);
592
593 if (has_test_file(slot) == 0)
594 sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_test.attr);
595}
596
597static struct hotplug_slot *get_slot_from_name (const char *name)
598{
599 struct hotplug_slot *slot;
600 struct list_head *tmp;
601
602 list_for_each (tmp, &pci_hotplug_slot_list) {
603 slot = list_entry (tmp, struct hotplug_slot, slot_list);
604 if (strcmp(slot->name, name) == 0)
605 return slot;
606 }
607 return NULL;
608}
609
610/**
611 * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem
612 * @slot: pointer to the &struct hotplug_slot to register
613 *
614 * Registers a hotplug slot with the pci hotplug subsystem, which will allow
615 * userspace interaction to the slot.
616 *
617 * Returns 0 if successful, anything else for an error.
618 */
619int pci_hp_register (struct hotplug_slot *slot)
620{
621 int result;
622
623 if (slot == NULL)
624 return -ENODEV;
625 if ((slot->info == NULL) || (slot->ops == NULL))
626 return -EINVAL;
627 if (slot->release == NULL) {
Joe Perchesa6f29a92007-11-19 17:48:29 -0800628 dbg("Why are you trying to register a hotplug slot "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 "without a proper release function?\n");
630 return -EINVAL;
631 }
632
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* this can fail if we have already registered a slot with the same name */
Greg Kroah-Hartman64dbcac2007-12-17 15:54:39 -0400634 slot->kobj.kset = pci_hotplug_slots_kset;
635 result = kobject_init_and_add(&slot->kobj, &hotplug_slot_ktype, NULL,
636 "%s", slot->name);
637 if (result) {
638 err("Unable to register kobject '%s'", slot->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 return -EINVAL;
640 }
Greg Kroah-Hartman64dbcac2007-12-17 15:54:39 -0400641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 list_add (&slot->slot_list, &pci_hotplug_slot_list);
643
644 result = fs_add_slot (slot);
Greg Kroah-Hartman64dbcac2007-12-17 15:54:39 -0400645 kobject_uevent(&slot->kobj, KOBJ_ADD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 dbg ("Added slot %s to the list\n", slot->name);
647 return result;
648}
649
650/**
651 * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem
652 * @slot: pointer to the &struct hotplug_slot to deregister
653 *
654 * The @slot must have been registered with the pci hotplug subsystem
655 * previously with a call to pci_hp_register().
656 *
657 * Returns 0 if successful, anything else for an error.
658 */
659int pci_hp_deregister (struct hotplug_slot *slot)
660{
661 struct hotplug_slot *temp;
662
663 if (slot == NULL)
664 return -ENODEV;
665
666 temp = get_slot_from_name (slot->name);
667 if (temp != slot) {
668 return -ENODEV;
669 }
670 list_del (&slot->slot_list);
671
672 fs_remove_slot (slot);
673 dbg ("Removed slot %s from the list\n", slot->name);
Greg Kroah-Hartmanc10997f2007-12-20 08:13:05 -0800674 kobject_put(&slot->kobj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 return 0;
676}
677
678/**
679 * pci_hp_change_slot_info - changes the slot's information structure in the core
680 * @slot: pointer to the slot whose info has changed
681 * @info: pointer to the info copy into the slot's info structure
682 *
683 * @slot must have been registered with the pci
684 * hotplug subsystem previously with a call to pci_hp_register().
685 *
686 * Returns 0 if successful, anything else for an error.
687 */
Greg Kroah-Hartman660a0e82006-08-28 11:43:25 -0700688int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
689 struct hotplug_slot_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 if ((slot == NULL) || (info == NULL))
692 return -ENODEV;
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 memcpy (slot->info, info, sizeof (struct hotplug_slot_info));
695
696 return 0;
697}
698
699static int __init pci_hotplug_init (void)
700{
701 int result;
Greg Kroah-Hartman0fed80f2007-11-01 19:41:16 -0700702 struct kset *pci_bus_kset;
703
704 pci_bus_kset = bus_get_kset(&pci_bus_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Greg Kroah-Hartman81ace5c2007-10-29 23:22:26 -0500706 pci_hotplug_slots_kset = kset_create_and_add("slots", NULL,
Greg Kroah-Hartman0fed80f2007-11-01 19:41:16 -0700707 &pci_bus_kset->kobj);
Greg Kroah-Hartman81ace5c2007-10-29 23:22:26 -0500708 if (!pci_hotplug_slots_kset) {
709 result = -ENOMEM;
710 err("Register subsys error\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 goto exit;
712 }
713 result = cpci_hotplug_init(debug);
714 if (result) {
715 err ("cpci_hotplug_init with error %d\n", result);
716 goto err_subsys;
717 }
718
719 info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
720 goto exit;
Greg Kroah-Hartman81ace5c2007-10-29 23:22:26 -0500721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722err_subsys:
Greg Kroah-Hartman81ace5c2007-10-29 23:22:26 -0500723 kset_unregister(pci_hotplug_slots_kset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724exit:
725 return result;
726}
727
728static void __exit pci_hotplug_exit (void)
729{
730 cpci_hotplug_exit();
Greg Kroah-Hartman81ace5c2007-10-29 23:22:26 -0500731 kset_unregister(pci_hotplug_slots_kset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732}
733
734module_init(pci_hotplug_init);
735module_exit(pci_hotplug_exit);
736
737MODULE_AUTHOR(DRIVER_AUTHOR);
738MODULE_DESCRIPTION(DRIVER_DESC);
739MODULE_LICENSE("GPL");
740module_param(debug, bool, 0644);
741MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
742
Greg Kroah-Hartman81ace5c2007-10-29 23:22:26 -0500743EXPORT_SYMBOL_GPL(pci_hotplug_slots_kset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744EXPORT_SYMBOL_GPL(pci_hp_register);
745EXPORT_SYMBOL_GPL(pci_hp_deregister);
746EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);