pci_hotplug_core.c 20 KB

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