bus.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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. struct list_head * entry, * next;
  349. list_for_each_safe(entry, next, &drv->devices) {
  350. struct device * dev = container_of(entry, struct device, driver_list);
  351. device_release_driver(dev);
  352. }
  353. }
  354. static int device_add_attrs(struct bus_type * bus, struct device * dev)
  355. {
  356. int error = 0;
  357. int i;
  358. if (bus->dev_attrs) {
  359. for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
  360. error = device_create_file(dev,&bus->dev_attrs[i]);
  361. if (error)
  362. goto Err;
  363. }
  364. }
  365. Done:
  366. return error;
  367. Err:
  368. while (--i >= 0)
  369. device_remove_file(dev,&bus->dev_attrs[i]);
  370. goto Done;
  371. }
  372. static void device_remove_attrs(struct bus_type * bus, struct device * dev)
  373. {
  374. int i;
  375. if (bus->dev_attrs) {
  376. for (i = 0; attr_name(bus->dev_attrs[i]); i++)
  377. device_remove_file(dev,&bus->dev_attrs[i]);
  378. }
  379. }
  380. /**
  381. * bus_add_device - add device to bus
  382. * @dev: device being added
  383. *
  384. * - Add the device to its bus's list of devices.
  385. * - Try to attach to driver.
  386. * - Create link to device's physical location.
  387. */
  388. int bus_add_device(struct device * dev)
  389. {
  390. struct bus_type * bus = get_bus(dev->bus);
  391. int error = 0;
  392. if (bus) {
  393. down_write(&dev->bus->subsys.rwsem);
  394. pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
  395. list_add_tail(&dev->bus_list, &dev->bus->devices.list);
  396. device_attach(dev);
  397. up_write(&dev->bus->subsys.rwsem);
  398. device_add_attrs(bus, dev);
  399. sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
  400. sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
  401. }
  402. return error;
  403. }
  404. /**
  405. * bus_remove_device - remove device from bus
  406. * @dev: device to be removed
  407. *
  408. * - Remove symlink from bus's directory.
  409. * - Delete device from bus's list.
  410. * - Detach from its driver.
  411. * - Drop reference taken in bus_add_device().
  412. */
  413. void bus_remove_device(struct device * dev)
  414. {
  415. if (dev->bus) {
  416. sysfs_remove_link(&dev->kobj, "bus");
  417. sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
  418. device_remove_attrs(dev->bus, dev);
  419. down_write(&dev->bus->subsys.rwsem);
  420. pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
  421. device_release_driver(dev);
  422. list_del_init(&dev->bus_list);
  423. up_write(&dev->bus->subsys.rwsem);
  424. put_bus(dev->bus);
  425. }
  426. }
  427. static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
  428. {
  429. int error = 0;
  430. int i;
  431. if (bus->drv_attrs) {
  432. for (i = 0; attr_name(bus->drv_attrs[i]); i++) {
  433. error = driver_create_file(drv, &bus->drv_attrs[i]);
  434. if (error)
  435. goto Err;
  436. }
  437. }
  438. Done:
  439. return error;
  440. Err:
  441. while (--i >= 0)
  442. driver_remove_file(drv, &bus->drv_attrs[i]);
  443. goto Done;
  444. }
  445. static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv)
  446. {
  447. int i;
  448. if (bus->drv_attrs) {
  449. for (i = 0; attr_name(bus->drv_attrs[i]); i++)
  450. driver_remove_file(drv, &bus->drv_attrs[i]);
  451. }
  452. }
  453. /**
  454. * bus_add_driver - Add a driver to the bus.
  455. * @drv: driver.
  456. *
  457. */
  458. int bus_add_driver(struct device_driver * drv)
  459. {
  460. struct bus_type * bus = get_bus(drv->bus);
  461. int error = 0;
  462. if (bus) {
  463. pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
  464. error = kobject_set_name(&drv->kobj, "%s", drv->name);
  465. if (error) {
  466. put_bus(bus);
  467. return error;
  468. }
  469. drv->kobj.kset = &bus->drivers;
  470. if ((error = kobject_register(&drv->kobj))) {
  471. put_bus(bus);
  472. return error;
  473. }
  474. down_write(&bus->subsys.rwsem);
  475. driver_attach(drv);
  476. up_write(&bus->subsys.rwsem);
  477. module_add_driver(drv->owner, drv);
  478. driver_add_attrs(bus, drv);
  479. }
  480. return error;
  481. }
  482. /**
  483. * bus_remove_driver - delete driver from bus's knowledge.
  484. * @drv: driver.
  485. *
  486. * Detach the driver from the devices it controls, and remove
  487. * it from its bus's list of drivers. Finally, we drop the reference
  488. * to the bus we took in bus_add_driver().
  489. */
  490. void bus_remove_driver(struct device_driver * drv)
  491. {
  492. if (drv->bus) {
  493. driver_remove_attrs(drv->bus, drv);
  494. down_write(&drv->bus->subsys.rwsem);
  495. pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
  496. driver_detach(drv);
  497. up_write(&drv->bus->subsys.rwsem);
  498. module_remove_driver(drv);
  499. kobject_unregister(&drv->kobj);
  500. put_bus(drv->bus);
  501. }
  502. }
  503. /* Helper for bus_rescan_devices's iter */
  504. static int bus_rescan_devices_helper(struct device *dev, void *data)
  505. {
  506. int *count = data;
  507. if (!dev->driver && device_attach(dev))
  508. (*count)++;
  509. return 0;
  510. }
  511. /**
  512. * bus_rescan_devices - rescan devices on the bus for possible drivers
  513. * @bus: the bus to scan.
  514. *
  515. * This function will look for devices on the bus with no driver
  516. * attached and rescan it against existing drivers to see if it
  517. * matches any. Calls device_attach(). Returns the number of devices
  518. * that were sucessfully bound to a driver.
  519. */
  520. int bus_rescan_devices(struct bus_type * bus)
  521. {
  522. int count = 0;
  523. down_write(&bus->subsys.rwsem);
  524. __bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
  525. up_write(&bus->subsys.rwsem);
  526. return count;
  527. }
  528. struct bus_type * get_bus(struct bus_type * bus)
  529. {
  530. return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL;
  531. }
  532. void put_bus(struct bus_type * bus)
  533. {
  534. subsys_put(&bus->subsys);
  535. }
  536. /**
  537. * find_bus - locate bus by name.
  538. * @name: name of bus.
  539. *
  540. * Call kset_find_obj() to iterate over list of buses to
  541. * find a bus by name. Return bus if found.
  542. *
  543. * Note that kset_find_obj increments bus' reference count.
  544. */
  545. struct bus_type * find_bus(char * name)
  546. {
  547. struct kobject * k = kset_find_obj(&bus_subsys.kset, name);
  548. return k ? to_bus(k) : NULL;
  549. }
  550. /**
  551. * bus_add_attrs - Add default attributes for this bus.
  552. * @bus: Bus that has just been registered.
  553. */
  554. static int bus_add_attrs(struct bus_type * bus)
  555. {
  556. int error = 0;
  557. int i;
  558. if (bus->bus_attrs) {
  559. for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
  560. if ((error = bus_create_file(bus,&bus->bus_attrs[i])))
  561. goto Err;
  562. }
  563. }
  564. Done:
  565. return error;
  566. Err:
  567. while (--i >= 0)
  568. bus_remove_file(bus,&bus->bus_attrs[i]);
  569. goto Done;
  570. }
  571. static void bus_remove_attrs(struct bus_type * bus)
  572. {
  573. int i;
  574. if (bus->bus_attrs) {
  575. for (i = 0; attr_name(bus->bus_attrs[i]); i++)
  576. bus_remove_file(bus,&bus->bus_attrs[i]);
  577. }
  578. }
  579. /**
  580. * bus_register - register a bus with the system.
  581. * @bus: bus.
  582. *
  583. * Once we have that, we registered the bus with the kobject
  584. * infrastructure, then register the children subsystems it has:
  585. * the devices and drivers that belong to the bus.
  586. */
  587. int bus_register(struct bus_type * bus)
  588. {
  589. int retval;
  590. retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name);
  591. if (retval)
  592. goto out;
  593. subsys_set_kset(bus, bus_subsys);
  594. retval = subsystem_register(&bus->subsys);
  595. if (retval)
  596. goto out;
  597. kobject_set_name(&bus->devices.kobj, "devices");
  598. bus->devices.subsys = &bus->subsys;
  599. retval = kset_register(&bus->devices);
  600. if (retval)
  601. goto bus_devices_fail;
  602. kobject_set_name(&bus->drivers.kobj, "drivers");
  603. bus->drivers.subsys = &bus->subsys;
  604. bus->drivers.ktype = &ktype_driver;
  605. retval = kset_register(&bus->drivers);
  606. if (retval)
  607. goto bus_drivers_fail;
  608. bus_add_attrs(bus);
  609. pr_debug("bus type '%s' registered\n", bus->name);
  610. return 0;
  611. bus_drivers_fail:
  612. kset_unregister(&bus->devices);
  613. bus_devices_fail:
  614. subsystem_unregister(&bus->subsys);
  615. out:
  616. return retval;
  617. }
  618. /**
  619. * bus_unregister - remove a bus from the system
  620. * @bus: bus.
  621. *
  622. * Unregister the child subsystems and the bus itself.
  623. * Finally, we call put_bus() to release the refcount
  624. */
  625. void bus_unregister(struct bus_type * bus)
  626. {
  627. pr_debug("bus %s: unregistering\n", bus->name);
  628. bus_remove_attrs(bus);
  629. kset_unregister(&bus->drivers);
  630. kset_unregister(&bus->devices);
  631. subsystem_unregister(&bus->subsys);
  632. }
  633. int __init buses_init(void)
  634. {
  635. return subsystem_register(&bus_subsys);
  636. }
  637. EXPORT_SYMBOL_GPL(bus_for_each_dev);
  638. EXPORT_SYMBOL_GPL(bus_for_each_drv);
  639. EXPORT_SYMBOL_GPL(driver_probe_device);
  640. EXPORT_SYMBOL_GPL(device_bind_driver);
  641. EXPORT_SYMBOL_GPL(device_release_driver);
  642. EXPORT_SYMBOL_GPL(device_attach);
  643. EXPORT_SYMBOL_GPL(driver_attach);
  644. EXPORT_SYMBOL_GPL(bus_add_device);
  645. EXPORT_SYMBOL_GPL(bus_remove_device);
  646. EXPORT_SYMBOL_GPL(bus_register);
  647. EXPORT_SYMBOL_GPL(bus_unregister);
  648. EXPORT_SYMBOL_GPL(bus_rescan_devices);
  649. EXPORT_SYMBOL_GPL(get_bus);
  650. EXPORT_SYMBOL_GPL(put_bus);
  651. EXPORT_SYMBOL_GPL(find_bus);
  652. EXPORT_SYMBOL_GPL(bus_create_file);
  653. EXPORT_SYMBOL_GPL(bus_remove_file);