You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

device.c 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <gpxe/list.h>
  19. #include <gpxe/tables.h>
  20. #include <gpxe/device.h>
  21. /**
  22. * @file
  23. *
  24. * Device model
  25. *
  26. */
  27. static struct root_device root_devices[0] __table_start ( root_devices );
  28. static struct root_device root_devices_end[0] __table_end ( root_devices );
  29. /** Registered root devices */
  30. static LIST_HEAD ( devices );
  31. /**
  32. * Register a root device
  33. *
  34. * @v rootdev Root device
  35. * @ret rc Return status code
  36. *
  37. * Calls the root device driver's probe() method, and adds it to the
  38. * list of registered root devices if successful.
  39. */
  40. static int register_rootdev ( struct root_device *rootdev ) {
  41. int rc;
  42. DBG ( "Registering %s root bus\n", rootdev->name );
  43. if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 )
  44. return rc;
  45. list_add ( &rootdev->dev.siblings, &devices );
  46. return 0;
  47. }
  48. /**
  49. * Unregister a root device
  50. *
  51. * @v rootdev Root device
  52. */
  53. static void unregister_rootdev ( struct root_device *rootdev ) {
  54. rootdev->driver->remove ( rootdev );
  55. list_del ( &rootdev->dev.siblings );
  56. DBG ( "Unregistered %s root bus\n", rootdev->name );
  57. }
  58. /**
  59. * Probe all devices
  60. *
  61. * @ret rc Return status code
  62. *
  63. * This initiates probing for all devices in the system. After this
  64. * call, the device hierarchy will be populated, and all hardware
  65. * should be ready to use.
  66. */
  67. int probe_devices ( void ) {
  68. struct root_device *rootdev;
  69. for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
  70. register_rootdev ( rootdev );
  71. }
  72. return 0;
  73. }
  74. /**
  75. * Remove all devices
  76. *
  77. */
  78. void remove_devices ( void ) {
  79. struct root_device *rootdev;
  80. struct root_device *tmp;
  81. list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
  82. unregister_rootdev ( rootdev );
  83. }
  84. }