pci_hotplug_core.c 20 KB

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