bus.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /*
  2. * bus.c - bus driver management
  3. *
  4. * Copyright (c) 2002-3 Patrick Mochel
  5. * Copyright (c) 2002-3 Open Source Development Labs
  6. *
  7. * This file is released under the GPLv2
  8. *
  9. */
  10. #include <linux/config.h>
  11. #include <linux/device.h>
  12. #include <linux/module.h>
  13. #include <linux/errno.h>
  14. #include <linux/init.h>
  15. #include <linux/string.h>
  16. #include "base.h"
  17. #include "power/power.h"
  18. #define to_dev(node) container_of(node, struct device, bus_list)
  19. #define to_drv(node) container_of(node, struct device_driver, kobj.entry)
  20. #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
  21. #define to_bus(obj) container_of(obj, struct bus_type, subsys.kset.kobj)
  22. /*
  23. * sysfs bindings for drivers
  24. */
  25. #define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr)
  26. #define to_driver(obj) container_of(obj, struct device_driver, kobj)
  27. static ssize_t
  28. drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
  29. {
  30. struct driver_attribute * drv_attr = to_drv_attr(attr);
  31. struct device_driver * drv = to_driver(kobj);
  32. ssize_t ret = 0;
  33. if (drv_attr->show)
  34. ret = drv_attr->show(drv, buf);
  35. return ret;
  36. }
  37. static ssize_t
  38. drv_attr_store(struct kobject * kobj, struct attribute * attr,
  39. const char * buf, size_t count)
  40. {
  41. struct driver_attribute * drv_attr = to_drv_attr(attr);
  42. struct device_driver * drv = to_driver(kobj);
  43. ssize_t ret = 0;
  44. if (drv_attr->store)
  45. ret = drv_attr->store(drv, buf, count);
  46. return ret;
  47. }
  48. static struct sysfs_ops driver_sysfs_ops = {
  49. .show = drv_attr_show,
  50. .store = drv_attr_store,
  51. };
  52. static void driver_release(struct kobject * kobj)
  53. {
  54. struct device_driver * drv = to_driver(kobj);
  55. complete(&drv->unloaded);
  56. }
  57. static struct kobj_type ktype_driver = {
  58. .sysfs_ops = &driver_sysfs_ops,
  59. .release = driver_release,
  60. };
  61. /*
  62. * sysfs bindings for buses
  63. */
  64. static ssize_t
  65. bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
  66. {
  67. struct bus_attribute * bus_attr = to_bus_attr(attr);
  68. struct bus_type * bus = to_bus(kobj);
  69. ssize_t ret = 0;
  70. if (bus_attr->show)
  71. ret = bus_attr->show(bus, buf);
  72. return ret;
  73. }
  74. static ssize_t
  75. bus_attr_store(struct kobject * kobj, struct attribute * attr,
  76. const char * buf, size_t count)
  77. {
  78. struct bus_attribute * bus_attr = to_bus_attr(attr);
  79. struct bus_type * bus = to_bus(kobj);
  80. ssize_t ret = 0;
  81. if (bus_attr->store)
  82. ret = bus_attr->store(bus, buf, count);
  83. return ret;
  84. }
  85. static struct sysfs_ops bus_sysfs_ops = {
  86. .show = bus_attr_show,
  87. .store = bus_attr_store,
  88. };
  89. int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
  90. {
  91. int error;
  92. if (get_bus(bus)) {
  93. error = sysfs_create_file(&bus->subsys.kset.kobj, &attr->attr);
  94. put_bus(bus);
  95. } else
  96. error = -EINVAL;
  97. return error;
  98. }
  99. void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr)
  100. {
  101. if (get_bus(bus)) {
  102. sysfs_remove_file(&bus->subsys.kset.kobj, &attr->attr);
  103. put_bus(bus);
  104. }
  105. }
  106. static struct kobj_type ktype_bus = {
  107. .sysfs_ops = &bus_sysfs_ops,
  108. };
  109. decl_subsys(bus, &ktype_bus, NULL);
  110. static int __bus_for_each_dev(struct bus_type *bus, struct device *start,
  111. void *data, int (*fn)(struct device *, void *))
  112. {
  113. struct list_head *head;
  114. struct device *dev;
  115. int error = 0;
  116. if (!(bus = get_bus(bus)))
  117. return -EINVAL;
  118. head = &bus->devices.list;
  119. dev = list_prepare_entry(start, head, bus_list);
  120. list_for_each_entry_continue(dev, head, bus_list) {
  121. get_device(dev);
  122. error = fn(dev, data);
  123. put_device(dev);
  124. if (error)
  125. break;
  126. }
  127. put_bus(bus);
  128. return error;
  129. }
  130. static int __bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
  131. void * data, int (*fn)(struct device_driver *, void *))
  132. {
  133. struct list_head *head;
  134. struct device_driver *drv;
  135. int error = 0;
  136. if (!(bus = get_bus(bus)))
  137. return -EINVAL;
  138. head = &bus->drivers.list;
  139. drv = list_prepare_entry(start, head, kobj.entry);
  140. list_for_each_entry_continue(drv, head, kobj.entry) {
  141. get_driver(drv);
  142. error = fn(drv, data);
  143. put_driver(drv);
  144. if (error)
  145. break;
  146. }
  147. put_bus(bus);
  148. return error;
  149. }
  150. /**
  151. * bus_for_each_dev - device iterator.
  152. * @bus: bus type.
  153. * @start: device to start iterating from.
  154. * @data: data for the callback.
  155. * @fn: function to be called for each device.
  156. *
  157. * Iterate over @bus's list of devices, and call @fn for each,
  158. * passing it @data. If @start is not NULL, we use that device to
  159. * begin iterating from.
  160. *
  161. * We check the return of @fn each time. If it returns anything
  162. * other than 0, we break out and return that value.
  163. *
  164. * NOTE: The device that returns a non-zero value is not retained
  165. * in any way, nor is its refcount incremented. If the caller needs
  166. * to retain this data, it should do, and increment the reference
  167. * count in the supplied callback.
  168. */
  169. int bus_for_each_dev(struct bus_type * bus, struct device * start,
  170. void * data, int (*fn)(struct device *, void *))
  171. {
  172. int ret;
  173. down_read(&bus->subsys.rwsem);
  174. ret = __bus_for_each_dev(bus, start, data, fn);
  175. up_read(&bus->subsys.rwsem);
  176. return ret;
  177. }
  178. /**
  179. * bus_for_each_drv - driver iterator
  180. * @bus: bus we're dealing with.
  181. * @start: driver to start iterating on.
  182. * @data: data to pass to the callback.
  183. * @fn: function to call for each driver.
  184. *
  185. * This is nearly identical to the device iterator above.
  186. * We iterate over each driver that belongs to @bus, and call
  187. * @fn for each. If @fn returns anything but 0, we break out
  188. * and return it. If @start is not NULL, we use it as the head
  189. * of the list.
  190. *
  191. * NOTE: we don't return the driver that returns a non-zero
  192. * value, nor do we leave the reference count incremented for that
  193. * driver. If the caller needs to know that info, it must set it
  194. * in the callback. It must also be sure to increment the refcount
  195. * so it doesn't disappear before returning to the caller.
  196. */
  197. int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
  198. void * data, int (*fn)(struct device_driver *, void *))
  199. {
  200. int ret;
  201. down_read(&bus->subsys.rwsem);
  202. ret = __bus_for_each_drv(bus, start, data, fn);
  203. up_read(&bus->subsys.rwsem);
  204. return ret;
  205. }
  206. /**
  207. * device_bind_driver - bind a driver to one device.
  208. * @dev: device.
  209. *
  210. * Allow manual attachment of a driver to a device.
  211. * Caller must have already set @dev->driver.
  212. *
  213. * Note that this does not modify the bus reference count
  214. * nor take the bus's rwsem. Please verify those are accounted
  215. * for before calling this. (It is ok to call with no other effort
  216. * from a driver's probe() method.)
  217. */
  218. void device_bind_driver(struct device * dev)
  219. {
  220. pr_debug("bound device '%s' to driver '%s'\n",
  221. dev->bus_id, dev->driver->name);
  222. list_add_tail(&dev->driver_list, &dev->driver->devices);
  223. sysfs_create_link(&dev->driver->kobj, &dev->kobj,
  224. kobject_name(&dev->kobj));
  225. sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver");
  226. }
  227. /**
  228. * driver_probe_device - attempt to bind device & driver.
  229. * @drv: driver.
  230. * @dev: device.
  231. *
  232. * First, we call the bus's match function, if one present, which
  233. * should compare the device IDs the driver supports with the
  234. * device IDs of the device. Note we don't do this ourselves
  235. * because we don't know the format of the ID structures, nor what
  236. * is to be considered a match and what is not.
  237. *
  238. * If we find a match, we call @drv->probe(@dev) if it exists, and
  239. * call device_bind_driver() above.
  240. */
  241. int driver_probe_device(struct device_driver * drv, struct device * dev)
  242. {
  243. if (drv->bus->match && !drv->bus->match(dev, drv))
  244. return -ENODEV;
  245. dev->driver = drv;
  246. if (drv->probe) {
  247. int error = drv->probe(dev);
  248. if (error) {
  249. dev->driver = NULL;
  250. return error;
  251. }
  252. }
  253. device_bind_driver(dev);
  254. return 0;
  255. }
  256. /**
  257. * device_attach - try to attach device to a driver.
  258. * @dev: device.
  259. *
  260. * Walk the list of drivers that the bus has and call
  261. * driver_probe_device() for each pair. If a compatible
  262. * pair is found, break out and return.
  263. */
  264. int device_attach(struct device * dev)
  265. {
  266. struct bus_type * bus = dev->bus;
  267. struct list_head * entry;
  268. int error;
  269. if (dev->driver) {
  270. device_bind_driver(dev);
  271. return 1;
  272. }
  273. if (bus->match) {
  274. list_for_each(entry, &bus->drivers.list) {
  275. struct device_driver * drv = to_drv(entry);
  276. error = driver_probe_device(drv, dev);
  277. if (!error)
  278. /* success, driver matched */
  279. return 1;
  280. if (error != -ENODEV && error != -ENXIO)
  281. /* driver matched but the probe failed */
  282. printk(KERN_WARNING
  283. "%s: probe of %s failed with error %d\n",
  284. drv->name, dev->bus_id, error);
  285. }
  286. }
  287. return 0;
  288. }
  289. /**
  290. * driver_attach - try to bind driver to devices.
  291. * @drv: driver.
  292. *
  293. * Walk the list of devices that the bus has on it and try to
  294. * match the driver with each one. If driver_probe_device()
  295. * returns 0 and the @dev->driver is set, we've found a
  296. * compatible pair.
  297. *
  298. * Note that we ignore the -ENODEV error from driver_probe_device(),
  299. * since it's perfectly valid for a driver not to bind to any devices.
  300. */
  301. void driver_attach(struct device_driver * drv)
  302. {
  303. struct bus_type * bus = drv->bus;
  304. struct list_head * entry;
  305. int error;
  306. if (!bus->match)
  307. return;
  308. list_for_each(entry, &bus->devices.list) {
  309. struct device * dev = container_of(entry, struct device, bus_list);
  310. if (!dev->driver) {
  311. error = driver_probe_device(drv, dev);
  312. if (error && (error != -ENODEV))
  313. /* driver matched but the probe failed */
  314. printk(KERN_WARNING
  315. "%s: probe of %s failed with error %d\n",
  316. drv->name, dev->bus_id, error);
  317. }
  318. }
  319. }
  320. /**
  321. * device_release_driver - manually detach device from driver.
  322. * @dev: device.
  323. *
  324. * Manually detach device from driver.
  325. * Note that this is called without incrementing the bus
  326. * reference count nor taking the bus's rwsem. Be sure that
  327. * those are accounted for before calling this function.
  328. */
  329. void device_release_driver(struct device * dev)
  330. {
  331. struct device_driver * drv = dev->driver;
  332. if (drv) {
  333. sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
  334. sysfs_remove_link(&dev->kobj, "driver");
  335. list_del_init(&dev->driver_list);
  336. device_detach_shutdown(dev);
  337. if (drv->remove)
  338. drv->remove(dev);
  339. dev->driver = NULL;
  340. }
  341. }
  342. /**
  343. * driver_detach - detach driver from all devices it controls.
  344. * @drv: driver.
  345. */
  346. static void driver_detach(struct device_driver * drv)
  347. {
  348. while (!list_empty(&drv->devices)) {
  349. struct device * dev = container_of(drv->devices.next, struct device, driver_list);
  350. device_release_driver(dev);
  351. }
  352. }
  353. static int device_add_attrs(struct bus_type * bus, struct device * dev)
  354. {
  355. int error = 0;
  356. int i;
  357. if (bus->dev_attrs) {
  358. for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
  359. error = device_create_file(dev,&bus->dev_attrs[i]);
  360. if (error)
  361. goto Err;
  362. }
  363. }
  364. Done:
  365. return error;
  366. Err:
  367. while (--i >= 0)
  368. device_remove_file(dev,&bus->dev_attrs[i]);
  369. goto Done;
  370. }
  371. static void device_remove_attrs(struct bus_type * bus, struct device * dev)
  372. {
  373. int i;
  374. if (bus->dev_attrs) {
  375. for (i = 0; attr_name(bus->dev_attrs[i]); i++)
  376. device_remove_file(dev,&bus->dev_attrs[i]);
  377. }
  378. }
  379. /**
  380. * bus_add_device - add device to bus
  381. * @dev: device being added
  382. *
  383. * - Add the device to its bus's list of devices.
  384. * - Try to attach to driver.
  385. * - Create link to device's physical location.
  386. */
  387. int bus_add_device(struct device * dev)
  388. {
  389. struct bus_type * bus = get_bus(dev->bus);
  390. int error = 0;
  391. if (bus) {
  392. down_write(&dev->bus->subsys.rwsem);
  393. pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
  394. list_add_tail(&dev->bus_list, &dev->bus->devices.list);
  395. device_attach(dev);
  396. up_write(&dev->bus->subsys.rwsem);
  397. device_add_attrs(bus, dev);
  398. sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
  399. sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
  400. }
  401. return error;
  402. }
  403. /**
  404. * bus_remove_device - remove device from bus
  405. * @dev: device to be removed
  406. *
  407. * - Remove symlink from bus's directory.
  408. * - Delete device from bus's list.
  409. * - Detach from its driver.
  410. * - Drop reference taken in bus_add_device().
  411. */
  412. void bus_remove_device(struct device * dev)
  413. {
  414. if (dev->bus) {
  415. sysfs_remove_link(&dev->kobj, "bus");
  416. sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
  417. device_remove_attrs(dev->bus, dev);
  418. down_write(&dev->bus->subsys.rwsem);
  419. pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
  420. device_release_driver(dev);
  421. list_del_init(&dev->bus_list);
  422. up_write(&dev->bus->subsys.rwsem);
  423. put_bus(dev->bus);
  424. }
  425. }
  426. static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
  427. {
  428. int error = 0;
  429. int i;
  430. if (bus->drv_attrs) {
  431. for (i = 0; attr_name(bus->drv_attrs[i]); i++) {
  432. error = driver_create_file(drv, &bus->drv_attrs[i]);
  433. if (error)
  434. goto Err;
  435. }
  436. }
  437. Done:
  438. return error;
  439. Err:
  440. while (--i >= 0)
  441. driver_remove_file(drv, &bus->drv_attrs[i]);
  442. goto Done;
  443. }
  444. static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv)
  445. {
  446. int i;
  447. if (bus->drv_attrs) {
  448. for (i = 0; attr_name(bus->drv_attrs[i]); i++)
  449. driver_remove_file(drv, &bus->drv_attrs[i]);
  450. }
  451. }
  452. /**
  453. * bus_add_driver - Add a driver to the bus.
  454. * @drv: driver.
  455. *
  456. */
  457. int bus_add_driver(struct device_driver * drv)
  458. {
  459. struct bus_type * bus = get_bus(drv->bus);
  460. int error = 0;
  461. if (bus) {
  462. pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
  463. error = kobject_set_name(&drv->kobj, "%s", drv->name);
  464. if (error) {
  465. put_bus(bus);
  466. return error;
  467. }
  468. drv->kobj.kset = &bus->drivers;
  469. if ((error = kobject_register(&drv->kobj))) {
  470. put_bus(bus);
  471. return error;
  472. }
  473. down_write(&bus->subsys.rwsem);
  474. driver_attach(drv);
  475. up_write(&bus->subsys.rwsem);
  476. module_add_driver(drv->owner, drv);
  477. driver_add_attrs(bus, drv);
  478. }
  479. return error;
  480. }
  481. /**
  482. * bus_remove_driver - delete driver from bus's knowledge.
  483. * @drv: driver.
  484. *
  485. * Detach the driver from the devices it controls, and remove
  486. * it from its bus's list of drivers. Finally, we drop the reference
  487. * to the bus we took in bus_add_driver().
  488. */
  489. void bus_remove_driver(struct device_driver * drv)
  490. {
  491. if (drv->bus) {
  492. driver_remove_attrs(drv->bus, drv);
  493. down_write(&drv->bus->subsys.rwsem);
  494. pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
  495. driver_detach(drv);
  496. up_write(&drv->bus->subsys.rwsem);
  497. module_remove_driver(drv);
  498. kobject_unregister(&drv->kobj);
  499. put_bus(drv->bus);
  500. }
  501. }
  502. /* Helper for bus_rescan_devices's iter */
  503. static int bus_rescan_devices_helper(struct device *dev, void *data)
  504. {
  505. int *count = data;
  506. if (!dev->driver && device_attach(dev))
  507. (*count)++;
  508. return 0;
  509. }
  510. /**
  511. * bus_rescan_devices - rescan devices on the bus for possible drivers
  512. * @bus: the bus to scan.
  513. *
  514. * This function will look for devices on the bus with no driver
  515. * attached and rescan it against existing drivers to see if it
  516. * matches any. Calls device_attach(). Returns the number of devices
  517. * that were sucessfully bound to a driver.
  518. */
  519. int bus_rescan_devices(struct bus_type * bus)
  520. {
  521. int count = 0;
  522. down_write(&bus->subsys.rwsem);
  523. __bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
  524. up_write(&bus->subsys.rwsem);
  525. return count;
  526. }
  527. struct bus_type * get_bus(struct bus_type * bus)
  528. {
  529. return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL;
  530. }
  531. void put_bus(struct bus_type * bus)
  532. {
  533. subsys_put(&bus->subsys);
  534. }
  535. /**
  536. * find_bus - locate bus by name.
  537. * @name: name of bus.
  538. *
  539. * Call kset_find_obj() to iterate over list of buses to
  540. * find a bus by name. Return bus if found.
  541. *
  542. * Note that kset_find_obj increments bus' reference count.
  543. */
  544. struct bus_type * find_bus(char * name)
  545. {
  546. struct kobject * k = kset_find_obj(&bus_subsys.kset, name);
  547. return k ? to_bus(k) : NULL;
  548. }
  549. /**
  550. * bus_add_attrs - Add default attributes for this bus.
  551. * @bus: Bus that has just been registered.
  552. */
  553. static int bus_add_attrs(struct bus_type * bus)
  554. {
  555. int error = 0;
  556. int i;
  557. if (bus->bus_attrs) {
  558. for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
  559. if ((error = bus_create_file(bus,&bus->bus_attrs[i])))
  560. goto Err;
  561. }
  562. }
  563. Done:
  564. return error;
  565. Err:
  566. while (--i >= 0)
  567. bus_remove_file(bus,&bus->bus_attrs[i]);
  568. goto Done;
  569. }
  570. static void bus_remove_attrs(struct bus_type * bus)
  571. {
  572. int i;
  573. if (bus->bus_attrs) {
  574. for (i = 0; attr_name(bus->bus_attrs[i]); i++)
  575. bus_remove_file(bus,&bus->bus_attrs[i]);
  576. }
  577. }
  578. /**
  579. * bus_register - register a bus with the system.
  580. * @bus: bus.
  581. *
  582. * Once we have that, we registered the bus with the kobject
  583. * infrastructure, then register the children subsystems it has:
  584. * the devices and drivers that belong to the bus.
  585. */
  586. int bus_register(struct bus_type * bus)
  587. {
  588. int retval;
  589. retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name);
  590. if (retval)
  591. goto out;
  592. subsys_set_kset(bus, bus_subsys);
  593. retval = subsystem_register(&bus->subsys);
  594. if (retval)
  595. goto out;
  596. kobject_set_name(&bus->devices.kobj, "devices");
  597. bus->devices.subsys = &bus->subsys;
  598. retval = kset_register(&bus->devices);
  599. if (retval)
  600. goto bus_devices_fail;
  601. kobject_set_name(&bus->drivers.kobj, "drivers");
  602. bus->drivers.subsys = &bus->subsys;
  603. bus->drivers.ktype = &ktype_driver;
  604. retval = kset_register(&bus->drivers);
  605. if (retval)
  606. goto bus_drivers_fail;
  607. bus_add_attrs(bus);
  608. pr_debug("bus type '%s' registered\n", bus->name);
  609. return 0;
  610. bus_drivers_fail:
  611. kset_unregister(&bus->devices);
  612. bus_devices_fail:
  613. subsystem_unregister(&bus->subsys);
  614. out:
  615. return retval;
  616. }
  617. /**
  618. * bus_unregister - remove a bus from the system
  619. * @bus: bus.
  620. *
  621. * Unregister the child subsystems and the bus itself.
  622. * Finally, we call put_bus() to release the refcount
  623. */
  624. void bus_unregister(struct bus_type * bus)
  625. {
  626. pr_debug("bus %s: unregistering\n", bus->name);
  627. bus_remove_attrs(bus);
  628. kset_unregister(&bus->drivers);
  629. kset_unregister(&bus->devices);
  630. subsystem_unregister(&bus->subsys);
  631. }
  632. int __init buses_init(void)
  633. {
  634. return subsystem_register(&bus_subsys);
  635. }
  636. EXPORT_SYMBOL_GPL(bus_for_each_dev);
  637. EXPORT_SYMBOL_GPL(bus_for_each_drv);
  638. EXPORT_SYMBOL_GPL(driver_probe_device);
  639. EXPORT_SYMBOL_GPL(device_bind_driver);
  640. EXPORT_SYMBOL_GPL(device_release_driver);
  641. EXPORT_SYMBOL_GPL(device_attach);
  642. EXPORT_SYMBOL_GPL(driver_attach);
  643. EXPORT_SYMBOL_GPL(bus_add_device);
  644. EXPORT_SYMBOL_GPL(bus_remove_device);
  645. EXPORT_SYMBOL_GPL(bus_register);
  646. EXPORT_SYMBOL_GPL(bus_unregister);
  647. EXPORT_SYMBOL_GPL(bus_rescan_devices);
  648. EXPORT_SYMBOL_GPL(get_bus);
  649. EXPORT_SYMBOL_GPL(put_bus);
  650. EXPORT_SYMBOL_GPL(find_bus);
  651. EXPORT_SYMBOL_GPL(bus_create_file);
  652. EXPORT_SYMBOL_GPL(bus_remove_file);