bus.c 18 KB

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