pci_hotplug_core.c 18 KB

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