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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <string.h>
  19. #include <gpxe/list.h>
  20. #include <gpxe/tables.h>
  21. #include <gpxe/device.h>
  22. /**
  23. * @file
  24. *
  25. * Device model
  26. *
  27. */
  28. static struct root_device root_devices[0] __table_start ( root_devices );
  29. static struct root_device root_devices_end[0] __table_end ( root_devices );
  30. /** Registered root devices */
  31. static LIST_HEAD ( devices );
  32. /**
  33. * Probe a root device
  34. *
  35. * @v rootdev Root device
  36. * @ret rc Return status code
  37. */
  38. static int rootdev_probe ( struct root_device *rootdev ) {
  39. int rc;
  40. DBG ( "Adding %s root bus\n", rootdev->name );
  41. if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 ) {
  42. DBG ( "Failed to add %s root bus: %s\n",
  43. rootdev->name, strerror ( rc ) );
  44. return rc;
  45. }
  46. return 0;
  47. }
  48. /**
  49. * Remove a root device
  50. *
  51. * @v rootdev Root device
  52. */
  53. static void rootdev_remove ( struct root_device *rootdev ) {
  54. rootdev->driver->remove ( rootdev );
  55. DBG ( "Removed %s root bus\n", rootdev->name );
  56. }
  57. /**
  58. * Probe all devices
  59. *
  60. * @ret rc Return status code
  61. *
  62. * This initiates probing for all devices in the system. After this
  63. * call, the device hierarchy will be populated, and all hardware
  64. * should be ready to use.
  65. */
  66. int probe_devices ( void ) {
  67. struct root_device *rootdev;
  68. int rc;
  69. for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
  70. list_add ( &rootdev->dev.siblings, &devices );
  71. INIT_LIST_HEAD ( &rootdev->dev.children );
  72. if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
  73. list_del ( &rootdev->dev.siblings );
  74. }
  75. return 0;
  76. }
  77. /**
  78. * Remove all devices
  79. *
  80. */
  81. void remove_devices ( void ) {
  82. struct root_device *rootdev;
  83. struct root_device *tmp;
  84. list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
  85. rootdev_remove ( rootdev );
  86. list_del ( &rootdev->dev.siblings );
  87. }
  88. }