bus.c 18 KB

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