bus.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  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 = -EIO;
  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 = -EIO;
  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. int error = 0;
  244. if (drv->bus->match && !drv->bus->match(dev, drv))
  245. return -ENODEV;
  246. down(&dev->sem);
  247. dev->driver = drv;
  248. if (drv->probe) {
  249. error = drv->probe(dev);
  250. if (error) {
  251. dev->driver = NULL;
  252. up(&dev->sem);
  253. return error;
  254. }
  255. }
  256. up(&dev->sem);
  257. device_bind_driver(dev);
  258. return 0;
  259. }
  260. /**
  261. * device_attach - try to attach device to a driver.
  262. * @dev: device.
  263. *
  264. * Walk the list of drivers that the bus has and call
  265. * driver_probe_device() for each pair. If a compatible
  266. * pair is found, break out and return.
  267. */
  268. int device_attach(struct device * dev)
  269. {
  270. struct bus_type * bus = dev->bus;
  271. struct list_head * entry;
  272. int error;
  273. if (dev->driver) {
  274. device_bind_driver(dev);
  275. return 1;
  276. }
  277. if (bus->match) {
  278. list_for_each(entry, &bus->drivers.list) {
  279. struct device_driver * drv = to_drv(entry);
  280. error = driver_probe_device(drv, dev);
  281. if (!error)
  282. /* success, driver matched */
  283. return 1;
  284. if (error != -ENODEV && error != -ENXIO)
  285. /* driver matched but the probe failed */
  286. printk(KERN_WARNING
  287. "%s: probe of %s failed with error %d\n",
  288. drv->name, dev->bus_id, error);
  289. }
  290. }
  291. return 0;
  292. }
  293. /**
  294. * driver_attach - try to bind driver to devices.
  295. * @drv: driver.
  296. *
  297. * Walk the list of devices that the bus has on it and try to
  298. * match the driver with each one. If driver_probe_device()
  299. * returns 0 and the @dev->driver is set, we've found a
  300. * compatible pair.
  301. *
  302. * Note that we ignore the -ENODEV error from driver_probe_device(),
  303. * since it's perfectly valid for a driver not to bind to any devices.
  304. */
  305. void driver_attach(struct device_driver * drv)
  306. {
  307. struct bus_type * bus = drv->bus;
  308. struct list_head * entry;
  309. int error;
  310. if (!bus->match)
  311. return;
  312. list_for_each(entry, &bus->devices.list) {
  313. struct device * dev = container_of(entry, struct device, bus_list);
  314. if (!dev->driver) {
  315. error = driver_probe_device(drv, dev);
  316. if (error && (error != -ENODEV))
  317. /* driver matched but the probe failed */
  318. printk(KERN_WARNING
  319. "%s: probe of %s failed with error %d\n",
  320. drv->name, dev->bus_id, error);
  321. }
  322. }
  323. }
  324. /**
  325. * device_release_driver - manually detach device from driver.
  326. * @dev: device.
  327. *
  328. * Manually detach device from driver.
  329. * Note that this is called without incrementing the bus
  330. * reference count nor taking the bus's rwsem. Be sure that
  331. * those are accounted for before calling this function.
  332. */
  333. void device_release_driver(struct device * dev)
  334. {
  335. struct device_driver * drv;
  336. down(&dev->sem);
  337. drv = dev->driver;
  338. if (drv) {
  339. sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
  340. sysfs_remove_link(&dev->kobj, "driver");
  341. list_del_init(&dev->driver_list);
  342. if (drv->remove)
  343. drv->remove(dev);
  344. dev->driver = NULL;
  345. }
  346. up(&dev->sem);
  347. }
  348. /**
  349. * driver_detach - detach driver from all devices it controls.
  350. * @drv: driver.
  351. */
  352. static void driver_detach(struct device_driver * drv)
  353. {
  354. while (!list_empty(&drv->devices)) {
  355. struct device * dev = container_of(drv->devices.next, struct device, driver_list);
  356. device_release_driver(dev);
  357. }
  358. }
  359. static int device_add_attrs(struct bus_type * bus, struct device * dev)
  360. {
  361. int error = 0;
  362. int i;
  363. if (bus->dev_attrs) {
  364. for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
  365. error = device_create_file(dev,&bus->dev_attrs[i]);
  366. if (error)
  367. goto Err;
  368. }
  369. }
  370. Done:
  371. return error;
  372. Err:
  373. while (--i >= 0)
  374. device_remove_file(dev,&bus->dev_attrs[i]);
  375. goto Done;
  376. }
  377. static void device_remove_attrs(struct bus_type * bus, struct device * dev)
  378. {
  379. int i;
  380. if (bus->dev_attrs) {
  381. for (i = 0; attr_name(bus->dev_attrs[i]); i++)
  382. device_remove_file(dev,&bus->dev_attrs[i]);
  383. }
  384. }
  385. /**
  386. * bus_add_device - add device to bus
  387. * @dev: device being added
  388. *
  389. * - Add the device to its bus's list of devices.
  390. * - Try to attach to driver.
  391. * - Create link to device's physical location.
  392. */
  393. int bus_add_device(struct device * dev)
  394. {
  395. struct bus_type * bus = get_bus(dev->bus);
  396. int error = 0;
  397. if (bus) {
  398. down_write(&dev->bus->subsys.rwsem);
  399. pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
  400. list_add_tail(&dev->bus_list, &dev->bus->devices.list);
  401. device_attach(dev);
  402. up_write(&dev->bus->subsys.rwsem);
  403. device_add_attrs(bus, dev);
  404. sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
  405. sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus");
  406. }
  407. return error;
  408. }
  409. /**
  410. * bus_remove_device - remove device from bus
  411. * @dev: device to be removed
  412. *
  413. * - Remove symlink from bus's directory.
  414. * - Delete device from bus's list.
  415. * - Detach from its driver.
  416. * - Drop reference taken in bus_add_device().
  417. */
  418. void bus_remove_device(struct device * dev)
  419. {
  420. if (dev->bus) {
  421. sysfs_remove_link(&dev->kobj, "bus");
  422. sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
  423. device_remove_attrs(dev->bus, dev);
  424. down_write(&dev->bus->subsys.rwsem);
  425. pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
  426. device_release_driver(dev);
  427. list_del_init(&dev->bus_list);
  428. up_write(&dev->bus->subsys.rwsem);
  429. put_bus(dev->bus);
  430. }
  431. }
  432. static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
  433. {
  434. int error = 0;
  435. int i;
  436. if (bus->drv_attrs) {
  437. for (i = 0; attr_name(bus->drv_attrs[i]); i++) {
  438. error = driver_create_file(drv, &bus->drv_attrs[i]);
  439. if (error)
  440. goto Err;
  441. }
  442. }
  443. Done:
  444. return error;
  445. Err:
  446. while (--i >= 0)
  447. driver_remove_file(drv, &bus->drv_attrs[i]);
  448. goto Done;
  449. }
  450. static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv)
  451. {
  452. int i;
  453. if (bus->drv_attrs) {
  454. for (i = 0; attr_name(bus->drv_attrs[i]); i++)
  455. driver_remove_file(drv, &bus->drv_attrs[i]);
  456. }
  457. }
  458. /**
  459. * bus_add_driver - Add a driver to the bus.
  460. * @drv: driver.
  461. *
  462. */
  463. int bus_add_driver(struct device_driver * drv)
  464. {
  465. struct bus_type * bus = get_bus(drv->bus);
  466. int error = 0;
  467. if (bus) {
  468. pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
  469. error = kobject_set_name(&drv->kobj, "%s", drv->name);
  470. if (error) {
  471. put_bus(bus);
  472. return error;
  473. }
  474. drv->kobj.kset = &bus->drivers;
  475. if ((error = kobject_register(&drv->kobj))) {
  476. put_bus(bus);
  477. return error;
  478. }
  479. down_write(&bus->subsys.rwsem);
  480. driver_attach(drv);
  481. up_write(&bus->subsys.rwsem);
  482. module_add_driver(drv->owner, drv);
  483. driver_add_attrs(bus, drv);
  484. }
  485. return error;
  486. }
  487. /**
  488. * bus_remove_driver - delete driver from bus's knowledge.
  489. * @drv: driver.
  490. *
  491. * Detach the driver from the devices it controls, and remove
  492. * it from its bus's list of drivers. Finally, we drop the reference
  493. * to the bus we took in bus_add_driver().
  494. */
  495. void bus_remove_driver(struct device_driver * drv)
  496. {
  497. if (drv->bus) {
  498. driver_remove_attrs(drv->bus, drv);
  499. down_write(&drv->bus->subsys.rwsem);
  500. pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
  501. driver_detach(drv);
  502. up_write(&drv->bus->subsys.rwsem);
  503. module_remove_driver(drv);
  504. kobject_unregister(&drv->kobj);
  505. put_bus(drv->bus);
  506. }
  507. }
  508. /* Helper for bus_rescan_devices's iter */
  509. static int bus_rescan_devices_helper(struct device *dev, void *data)
  510. {
  511. int *count = data;
  512. if (!dev->driver && device_attach(dev))
  513. (*count)++;
  514. return 0;
  515. }
  516. /**
  517. * bus_rescan_devices - rescan devices on the bus for possible drivers
  518. * @bus: the bus to scan.
  519. *
  520. * This function will look for devices on the bus with no driver
  521. * attached and rescan it against existing drivers to see if it
  522. * matches any. Calls device_attach(). Returns the number of devices
  523. * that were sucessfully bound to a driver.
  524. */
  525. int bus_rescan_devices(struct bus_type * bus)
  526. {
  527. int count = 0;
  528. down_write(&bus->subsys.rwsem);
  529. __bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
  530. up_write(&bus->subsys.rwsem);
  531. return count;
  532. }
  533. struct bus_type * get_bus(struct bus_type * bus)
  534. {
  535. return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL;
  536. }
  537. void put_bus(struct bus_type * bus)
  538. {
  539. subsys_put(&bus->subsys);
  540. }
  541. /**
  542. * find_bus - locate bus by name.
  543. * @name: name of bus.
  544. *
  545. * Call kset_find_obj() to iterate over list of buses to
  546. * find a bus by name. Return bus if found.
  547. *
  548. * Note that kset_find_obj increments bus' reference count.
  549. */
  550. struct bus_type * find_bus(char * name)
  551. {
  552. struct kobject * k = kset_find_obj(&bus_subsys.kset, name);
  553. return k ? to_bus(k) : NULL;
  554. }
  555. /**
  556. * bus_add_attrs - Add default attributes for this bus.
  557. * @bus: Bus that has just been registered.
  558. */
  559. static int bus_add_attrs(struct bus_type * bus)
  560. {
  561. int error = 0;
  562. int i;
  563. if (bus->bus_attrs) {
  564. for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
  565. if ((error = bus_create_file(bus,&bus->bus_attrs[i])))
  566. goto Err;
  567. }
  568. }
  569. Done:
  570. return error;
  571. Err:
  572. while (--i >= 0)
  573. bus_remove_file(bus,&bus->bus_attrs[i]);
  574. goto Done;
  575. }
  576. static void bus_remove_attrs(struct bus_type * bus)
  577. {
  578. int i;
  579. if (bus->bus_attrs) {
  580. for (i = 0; attr_name(bus->bus_attrs[i]); i++)
  581. bus_remove_file(bus,&bus->bus_attrs[i]);
  582. }
  583. }
  584. /**
  585. * bus_register - register a bus with the system.
  586. * @bus: bus.
  587. *
  588. * Once we have that, we registered the bus with the kobject
  589. * infrastructure, then register the children subsystems it has:
  590. * the devices and drivers that belong to the bus.
  591. */
  592. int bus_register(struct bus_type * bus)
  593. {
  594. int retval;
  595. retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name);
  596. if (retval)
  597. goto out;
  598. subsys_set_kset(bus, bus_subsys);
  599. retval = subsystem_register(&bus->subsys);
  600. if (retval)
  601. goto out;
  602. kobject_set_name(&bus->devices.kobj, "devices");
  603. bus->devices.subsys = &bus->subsys;
  604. retval = kset_register(&bus->devices);
  605. if (retval)
  606. goto bus_devices_fail;
  607. kobject_set_name(&bus->drivers.kobj, "drivers");
  608. bus->drivers.subsys = &bus->subsys;
  609. bus->drivers.ktype = &ktype_driver;
  610. retval = kset_register(&bus->drivers);
  611. if (retval)
  612. goto bus_drivers_fail;
  613. bus_add_attrs(bus);
  614. pr_debug("bus type '%s' registered\n", bus->name);
  615. return 0;
  616. bus_drivers_fail:
  617. kset_unregister(&bus->devices);
  618. bus_devices_fail:
  619. subsystem_unregister(&bus->subsys);
  620. out:
  621. return retval;
  622. }
  623. /**
  624. * bus_unregister - remove a bus from the system
  625. * @bus: bus.
  626. *
  627. * Unregister the child subsystems and the bus itself.
  628. * Finally, we call put_bus() to release the refcount
  629. */
  630. void bus_unregister(struct bus_type * bus)
  631. {
  632. pr_debug("bus %s: unregistering\n", bus->name);
  633. bus_remove_attrs(bus);
  634. kset_unregister(&bus->drivers);
  635. kset_unregister(&bus->devices);
  636. subsystem_unregister(&bus->subsys);
  637. }
  638. int __init buses_init(void)
  639. {
  640. return subsystem_register(&bus_subsys);
  641. }
  642. EXPORT_SYMBOL_GPL(bus_for_each_dev);
  643. EXPORT_SYMBOL_GPL(bus_for_each_drv);
  644. EXPORT_SYMBOL_GPL(driver_probe_device);
  645. EXPORT_SYMBOL_GPL(device_bind_driver);
  646. EXPORT_SYMBOL_GPL(device_release_driver);
  647. EXPORT_SYMBOL_GPL(device_attach);
  648. EXPORT_SYMBOL_GPL(driver_attach);
  649. EXPORT_SYMBOL_GPL(bus_add_device);
  650. EXPORT_SYMBOL_GPL(bus_remove_device);
  651. EXPORT_SYMBOL_GPL(bus_register);
  652. EXPORT_SYMBOL_GPL(bus_unregister);
  653. EXPORT_SYMBOL_GPL(bus_rescan_devices);
  654. EXPORT_SYMBOL_GPL(get_bus);
  655. EXPORT_SYMBOL_GPL(put_bus);
  656. EXPORT_SYMBOL_GPL(find_bus);
  657. EXPORT_SYMBOL_GPL(bus_create_file);
  658. EXPORT_SYMBOL_GPL(bus_remove_file);