pci_hotplug_core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. int retval = 0;
  409. if (has_power_file(slot) == 0) {
  410. retval = sysfs_create_file(&slot->kobj, &hotplug_slot_attr_power.attr);
  411. if (retval)
  412. goto exit_power;
  413. }
  414. if (has_attention_file(slot) == 0) {
  415. retval = sysfs_create_file(&slot->kobj,
  416. &hotplug_slot_attr_attention.attr);
  417. if (retval)
  418. goto exit_attention;
  419. }
  420. if (has_latch_file(slot) == 0) {
  421. retval = sysfs_create_file(&slot->kobj,
  422. &hotplug_slot_attr_latch.attr);
  423. if (retval)
  424. goto exit_latch;
  425. }
  426. if (has_adapter_file(slot) == 0) {
  427. retval = sysfs_create_file(&slot->kobj,
  428. &hotplug_slot_attr_presence.attr);
  429. if (retval)
  430. goto exit_adapter;
  431. }
  432. if (has_address_file(slot) == 0) {
  433. retval = sysfs_create_file(&slot->kobj,
  434. &hotplug_slot_attr_address.attr);
  435. if (retval)
  436. goto exit_address;
  437. }
  438. if (has_max_bus_speed_file(slot) == 0) {
  439. retval = sysfs_create_file(&slot->kobj,
  440. &hotplug_slot_attr_max_bus_speed.attr);
  441. if (retval)
  442. goto exit_max_speed;
  443. }
  444. if (has_cur_bus_speed_file(slot) == 0) {
  445. retval = sysfs_create_file(&slot->kobj,
  446. &hotplug_slot_attr_cur_bus_speed.attr);
  447. if (retval)
  448. goto exit_cur_speed;
  449. }
  450. if (has_test_file(slot) == 0) {
  451. retval = sysfs_create_file(&slot->kobj,
  452. &hotplug_slot_attr_test.attr);
  453. if (retval)
  454. goto exit_test;
  455. }
  456. goto exit;
  457. exit_test:
  458. if (has_cur_bus_speed_file(slot) == 0)
  459. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);
  460. exit_cur_speed:
  461. if (has_max_bus_speed_file(slot) == 0)
  462. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);
  463. exit_max_speed:
  464. if (has_address_file(slot) == 0)
  465. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);
  466. exit_address:
  467. if (has_adapter_file(slot) == 0)
  468. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);
  469. exit_adapter:
  470. if (has_latch_file(slot) == 0)
  471. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);
  472. exit_latch:
  473. if (has_attention_file(slot) == 0)
  474. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_attention.attr);
  475. exit_attention:
  476. if (has_power_file(slot) == 0)
  477. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
  478. exit_power:
  479. exit:
  480. return retval;
  481. }
  482. static void fs_remove_slot (struct hotplug_slot *slot)
  483. {
  484. if (has_power_file(slot) == 0)
  485. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_power.attr);
  486. if (has_attention_file(slot) == 0)
  487. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_attention.attr);
  488. if (has_latch_file(slot) == 0)
  489. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_latch.attr);
  490. if (has_adapter_file(slot) == 0)
  491. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_presence.attr);
  492. if (has_address_file(slot) == 0)
  493. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_address.attr);
  494. if (has_max_bus_speed_file(slot) == 0)
  495. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_max_bus_speed.attr);
  496. if (has_cur_bus_speed_file(slot) == 0)
  497. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_cur_bus_speed.attr);
  498. if (has_test_file(slot) == 0)
  499. sysfs_remove_file(&slot->kobj, &hotplug_slot_attr_test.attr);
  500. }
  501. static struct hotplug_slot *get_slot_from_name (const char *name)
  502. {
  503. struct hotplug_slot *slot;
  504. struct list_head *tmp;
  505. list_for_each (tmp, &pci_hotplug_slot_list) {
  506. slot = list_entry (tmp, struct hotplug_slot, slot_list);
  507. if (strcmp(slot->name, name) == 0)
  508. return slot;
  509. }
  510. return NULL;
  511. }
  512. /**
  513. * pci_hp_register - register a hotplug_slot with the PCI hotplug subsystem
  514. * @slot: pointer to the &struct hotplug_slot to register
  515. *
  516. * Registers a hotplug slot with the pci hotplug subsystem, which will allow
  517. * userspace interaction to the slot.
  518. *
  519. * Returns 0 if successful, anything else for an error.
  520. */
  521. int pci_hp_register (struct hotplug_slot *slot)
  522. {
  523. int result;
  524. if (slot == NULL)
  525. return -ENODEV;
  526. if ((slot->info == NULL) || (slot->ops == NULL))
  527. return -EINVAL;
  528. if (slot->release == NULL) {
  529. dbg("Why are you trying to register a hotplug slot"
  530. "without a proper release function?\n");
  531. return -EINVAL;
  532. }
  533. kobject_set_name(&slot->kobj, "%s", slot->name);
  534. kobj_set_kset_s(slot, pci_hotplug_slots_subsys);
  535. /* this can fail if we have already registered a slot with the same name */
  536. if (kobject_register(&slot->kobj)) {
  537. err("Unable to register kobject");
  538. return -EINVAL;
  539. }
  540. list_add (&slot->slot_list, &pci_hotplug_slot_list);
  541. result = fs_add_slot (slot);
  542. dbg ("Added slot %s to the list\n", slot->name);
  543. return result;
  544. }
  545. /**
  546. * pci_hp_deregister - deregister a hotplug_slot with the PCI hotplug subsystem
  547. * @slot: pointer to the &struct hotplug_slot to deregister
  548. *
  549. * The @slot must have been registered with the pci hotplug subsystem
  550. * previously with a call to pci_hp_register().
  551. *
  552. * Returns 0 if successful, anything else for an error.
  553. */
  554. int pci_hp_deregister (struct hotplug_slot *slot)
  555. {
  556. struct hotplug_slot *temp;
  557. if (slot == NULL)
  558. return -ENODEV;
  559. temp = get_slot_from_name (slot->name);
  560. if (temp != slot) {
  561. return -ENODEV;
  562. }
  563. list_del (&slot->slot_list);
  564. fs_remove_slot (slot);
  565. dbg ("Removed slot %s from the list\n", slot->name);
  566. kobject_unregister(&slot->kobj);
  567. return 0;
  568. }
  569. /**
  570. * pci_hp_change_slot_info - changes the slot's information structure in the core
  571. * @slot: pointer to the slot whose info has changed
  572. * @info: pointer to the info copy into the slot's info structure
  573. *
  574. * @slot must have been registered with the pci
  575. * hotplug subsystem previously with a call to pci_hp_register().
  576. *
  577. * Returns 0 if successful, anything else for an error.
  578. */
  579. int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
  580. struct hotplug_slot_info *info)
  581. {
  582. int retval;
  583. if ((slot == NULL) || (info == NULL))
  584. return -ENODEV;
  585. /*
  586. * check all fields in the info structure, and update timestamps
  587. * for the files referring to the fields that have now changed.
  588. */
  589. if ((has_power_file(slot) == 0) &&
  590. (slot->info->power_status != info->power_status)) {
  591. retval = sysfs_update_file(&slot->kobj,
  592. &hotplug_slot_attr_power.attr);
  593. if (retval)
  594. return retval;
  595. }
  596. if ((has_attention_file(slot) == 0) &&
  597. (slot->info->attention_status != info->attention_status)) {
  598. retval = sysfs_update_file(&slot->kobj,
  599. &hotplug_slot_attr_attention.attr);
  600. if (retval)
  601. return retval;
  602. }
  603. if ((has_latch_file(slot) == 0) &&
  604. (slot->info->latch_status != info->latch_status)) {
  605. retval = sysfs_update_file(&slot->kobj,
  606. &hotplug_slot_attr_latch.attr);
  607. if (retval)
  608. return retval;
  609. }
  610. if ((has_adapter_file(slot) == 0) &&
  611. (slot->info->adapter_status != info->adapter_status)) {
  612. retval = sysfs_update_file(&slot->kobj,
  613. &hotplug_slot_attr_presence.attr);
  614. if (retval)
  615. return retval;
  616. }
  617. if ((has_address_file(slot) == 0) &&
  618. (slot->info->address != info->address)) {
  619. retval = sysfs_update_file(&slot->kobj,
  620. &hotplug_slot_attr_address.attr);
  621. if (retval)
  622. return retval;
  623. }
  624. if ((has_max_bus_speed_file(slot) == 0) &&
  625. (slot->info->max_bus_speed != info->max_bus_speed)) {
  626. retval = sysfs_update_file(&slot->kobj,
  627. &hotplug_slot_attr_max_bus_speed.attr);
  628. if (retval)
  629. return retval;
  630. }
  631. if ((has_cur_bus_speed_file(slot) == 0) &&
  632. (slot->info->cur_bus_speed != info->cur_bus_speed)) {
  633. retval = sysfs_update_file(&slot->kobj,
  634. &hotplug_slot_attr_cur_bus_speed.attr);
  635. if (retval)
  636. return retval;
  637. }
  638. memcpy (slot->info, info, sizeof (struct hotplug_slot_info));
  639. return 0;
  640. }
  641. static int __init pci_hotplug_init (void)
  642. {
  643. int result;
  644. kset_set_kset_s(&pci_hotplug_slots_subsys, pci_bus_type.subsys);
  645. result = subsystem_register(&pci_hotplug_slots_subsys);
  646. if (result) {
  647. err("Register subsys with error %d\n", result);
  648. goto exit;
  649. }
  650. result = cpci_hotplug_init(debug);
  651. if (result) {
  652. err ("cpci_hotplug_init with error %d\n", result);
  653. goto err_subsys;
  654. }
  655. info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
  656. goto exit;
  657. err_subsys:
  658. subsystem_unregister(&pci_hotplug_slots_subsys);
  659. exit:
  660. return result;
  661. }
  662. static void __exit pci_hotplug_exit (void)
  663. {
  664. cpci_hotplug_exit();
  665. subsystem_unregister(&pci_hotplug_slots_subsys);
  666. }
  667. module_init(pci_hotplug_init);
  668. module_exit(pci_hotplug_exit);
  669. MODULE_AUTHOR(DRIVER_AUTHOR);
  670. MODULE_DESCRIPTION(DRIVER_DESC);
  671. MODULE_LICENSE("GPL");
  672. module_param(debug, bool, 0644);
  673. MODULE_PARM_DESC(debug, "Debugging mode enabled or not");
  674. EXPORT_SYMBOL_GPL(pci_hotplug_slots_subsys);
  675. EXPORT_SYMBOL_GPL(pci_hp_register);
  676. EXPORT_SYMBOL_GPL(pci_hp_deregister);
  677. EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);