pci_hotplug_core.c 18 KB

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