pci_hotplug_core.c 18 KB

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