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

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